1. 16 6月, 2023 1 次提交
  2. 14 4月, 2023 3 次提交
    • T
      module: Ignore L0 and rename is_arm_mapping_symbol() · 0a3bf860
      Tiezhu Yang 提交于
      The L0 symbol is generated when build module on LoongArch, ignore it in
      modpost and when looking at module symbols, otherwise we can not see the
      expected call trace.
      
      Now is_arm_mapping_symbol() is not only for ARM, in order to reflect the
      reality, rename is_arm_mapping_symbol() to is_mapping_symbol().
      
      This is related with commit c17a2538 ("mksysmap: Fix the mismatch of
      'L0' symbols in System.map").
      
      (1) Simple test case
      
        [loongson@linux hello]$ cat hello.c
        #include <linux/init.h>
        #include <linux/module.h>
        #include <linux/printk.h>
      
        static void test_func(void)
        {
        	  pr_info("This is a test\n");
      	  dump_stack();
        }
      
        static int __init hello_init(void)
        {
      	  pr_warn("Hello, world\n");
      	  test_func();
      
      	  return 0;
        }
      
        static void __exit hello_exit(void)
        {
      	  pr_warn("Goodbye\n");
        }
      
        module_init(hello_init);
        module_exit(hello_exit);
        MODULE_LICENSE("GPL");
        [loongson@linux hello]$ cat Makefile
        obj-m:=hello.o
      
        ccflags-y += -g -Og
      
        all:
      	  make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules
        clean:
      	  make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) clean
      
      (2) Test environment
      
      system: LoongArch CLFS 5.5
      https://github.com/sunhaiyong1978/CLFS-for-LoongArch/releases/tag/5.0
      It needs to update grub to avoid booting error "invalid magic number".
      
      kernel: 6.3-rc1 with loongson3_defconfig + CONFIG_DYNAMIC_FTRACE=y
      
      (3) Test result
      
      Without this patch:
      
        [root@linux hello]# insmod hello.ko
        [root@linux hello]# dmesg
        ...
        Hello, world
        This is a test
        ...
        Call Trace:
        [<9000000000223728>] show_stack+0x68/0x18c
        [<90000000013374cc>] dump_stack_lvl+0x60/0x88
        [<ffff800002050028>] L0\x01+0x20/0x2c [hello]
        [<ffff800002058028>] L0\x01+0x20/0x30 [hello]
        [<900000000022097c>] do_one_initcall+0x88/0x288
        [<90000000002df890>] do_init_module+0x54/0x200
        [<90000000002e1e18>] __do_sys_finit_module+0xc4/0x114
        [<90000000013382e8>] do_syscall+0x7c/0x94
        [<9000000000221e3c>] handle_syscall+0xbc/0x158
      
      With this patch:
      
        [root@linux hello]# insmod hello.ko
        [root@linux hello]# dmesg
        ...
        Hello, world
        This is a test
        ...
        Call Trace:
        [<9000000000223728>] show_stack+0x68/0x18c
        [<90000000013374cc>] dump_stack_lvl+0x60/0x88
        [<ffff800002050028>] test_func+0x28/0x34 [hello]
        [<ffff800002058028>] hello_init+0x28/0x38 [hello]
        [<900000000022097c>] do_one_initcall+0x88/0x288
        [<90000000002df890>] do_init_module+0x54/0x200
        [<90000000002e1e18>] __do_sys_finit_module+0xc4/0x114
        [<90000000013382e8>] do_syscall+0x7c/0x94
        [<9000000000221e3c>] handle_syscall+0xbc/0x158
      Signed-off-by: NTiezhu Yang <yangtiezhu@loongson.cn>
      Tested-by: Youling Tang <tangyouling@loongson.cn> # for LoongArch
      Signed-off-by: NLuis Chamberlain <mcgrof@kernel.org>
      0a3bf860
    • T
      module: Move is_arm_mapping_symbol() to module_symbol.h · 987d2e0a
      Tiezhu Yang 提交于
      In order to avoid duplicated code, move is_arm_mapping_symbol() to
      include/linux/module_symbol.h, then remove is_arm_mapping_symbol()
      in the other places.
      Signed-off-by: NTiezhu Yang <yangtiezhu@loongson.cn>
      Signed-off-by: NLuis Chamberlain <mcgrof@kernel.org>
      987d2e0a
    • T
      module: Sync code of is_arm_mapping_symbol() · 87e5b1e8
      Tiezhu Yang 提交于
      After commit 2e3a10a1 ("ARM: avoid ARM binutils leaking ELF local
      symbols") and commit d6b73266 ("modpost: fix undefined behavior of
      is_arm_mapping_symbol()"), many differences of is_arm_mapping_symbol()
      exist in kernel/module/kallsyms.c and scripts/mod/modpost.c, just sync
      the code to keep consistent.
      Signed-off-by: NTiezhu Yang <yangtiezhu@loongson.cn>
      Signed-off-by: NLuis Chamberlain <mcgrof@kernel.org>
      87e5b1e8
  3. 23 3月, 2023 1 次提交
  4. 14 12月, 2022 3 次提交
  5. 21 11月, 2022 1 次提交
  6. 21 8月, 2022 1 次提交
    • M
      modpost: fix module versioning when a symbol lacks valid CRC · 5b8a9a8f
      Masahiro Yamada 提交于
      Since commit 7b453719 ("kbuild: link symbol CRCs at final link,
      removing CONFIG_MODULE_REL_CRCS"), module versioning is broken on
      some architectures. Loading a module fails with "disagrees about
      version of symbol module_layout".
      
      On such architectures (e.g. ARCH=sparc build with sparc64_defconfig),
      modpost shows a warning, like follows:
      
        WARNING: modpost: EXPORT symbol "_mcount" [vmlinux] version generation failed, symbol will not be versioned.
        Is "_mcount" prototyped in <asm/asm-prototypes.h>?
      
      Previously, it was a harmless warning (CRC check was just skipped),
      but now wrong CRCs are used for comparison because invalid CRCs are
      just skipped.
      
        $ sparc64-linux-gnu-nm -n vmlinux
          [snip]
        0000000000c2cea0 r __ksymtab__kstrtol
        0000000000c2ceb8 r __ksymtab__kstrtoul
        0000000000c2ced0 r __ksymtab__local_bh_enable
        0000000000c2cee8 r __ksymtab__mcount
        0000000000c2cf00 r __ksymtab__printk
        0000000000c2cf18 r __ksymtab__raw_read_lock
        0000000000c2cf30 r __ksymtab__raw_read_lock_bh
          [snip]
        0000000000c53b34 D __crc__kstrtol
        0000000000c53b38 D __crc__kstrtoul
        0000000000c53b3c D __crc__local_bh_enable
        0000000000c53b40 D __crc__printk
        0000000000c53b44 D __crc__raw_read_lock
        0000000000c53b48 D __crc__raw_read_lock_bh
      
      Please notice __crc__mcount is missing here.
      
      When the module subsystem looks up a CRC that comes after, it results
      in reading out a wrong address. For example, when __crc__printk is
      needed, the module subsystem reads 0xc53b44 instead of 0xc53b40.
      
      All CRC entries must be output for correct index accessing. Invalid
      CRCs will be unused, but are needed to keep the one-to-one mapping
      between __ksymtab_* and __crc_*.
      
      The best is to fix all modpost warnings, but several warnings are still
      remaining on less popular architectures.
      
      Fixes: 7b453719 ("kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS")
      Reported-by: Nmatoro <matoro_mailinglist_kernel@matoro.tk>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      Tested-by: Nmatoro <matoro_mailinglist_kernel@matoro.tk>
      5b8a9a8f
  7. 04 8月, 2022 5 次提交
  8. 03 8月, 2022 2 次提交
    • M
      modpost: use more reliable way to get fromsec in section_rel(a)() · 5419aa2a
      Masahiro Yamada 提交于
      The section name of Rel and Rela starts with ".rel" and ".rela"
      respectively (but, I do not know whether this is specification or
      convention).
      
      For example, ".rela.text" holds relocation entries applied to the
      ".text" section.
      
      So, the code chops the ".rel" or ".rela" prefix to get the name of
      the section to which the relocation applies.
      
      However, I do not like to skip 4 or 5 bytes blindly because it is
      potential memory overrun.
      
      The ELF specification provides a more reliable way to do this.
      
       - The sh_info field holds extra information, whose interpretation
         depends on the section type
      
       - If the section type is SHT_REL or SHT_RELA, the sh_info field holds
         the section header index of the section to which the relocation
         applies.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      5419aa2a
    • M
      modpost: add array range check to sec_name() · 125ed24a
      Masahiro Yamada 提交于
      The section index is always positive, so the argument, secindex, should
      be unsigned.
      
      Also, inserted the array range check.
      
      If sym->st_shndx is a special section index (between SHN_LORESERVE and
      SHN_HIRESERVE), there is no corresponding section header.
      
      For example, if a symbol specifies an absolute value, sym->st_shndx is
      SHN_ABS (=0xfff1).
      
      The current users do not cause the out-of-range access of
      info->sechddrs[], but it is better to avoid such a pitfall.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      125ed24a
  9. 27 7月, 2022 3 次提交
  10. 12 7月, 2022 1 次提交
  11. 20 6月, 2022 1 次提交
  12. 05 6月, 2022 2 次提交
  13. 01 6月, 2022 1 次提交
    • M
      kbuild: check static EXPORT_SYMBOL* by script instead of modpost · 31cb50b5
      Masahiro Yamada 提交于
      The 'static' specifier and EXPORT_SYMBOL() are an odd combination.
      
      Commit 15bfc234 ("modpost: check for static EXPORT_SYMBOL*
      functions") tried to detect it, but this check has false negatives.
      
      Here is the sample code.
      
        Makefile:
      
          obj-y += foo1.o foo2.o
      
        foo1.c:
      
          #include <linux/export.h>
          static void foo(void) {}
          EXPORT_SYMBOL(foo);
      
        foo2.c:
      
          void foo(void) {}
      
      foo1.c exports the static symbol 'foo', but modpost cannot catch it
      because it is fooled by foo2.c, which has a global symbol with the
      same name.
      
      s->is_static is cleared if a global symbol with the same name is found
      somewhere, but EXPORT_SYMBOL() and the global symbol do not necessarily
      belong to the same compilation unit.
      
      This check should be done per compilation unit, but I do not know how
      to do it in modpost. modpost runs against vmlinux.o or modules, which
      merges multiple objects, then forgets their origin.
      
      modpost cannot parse individual objects because they may not be ELF but
      LLVM IR when CONFIG_LTO_CLANG=y.
      
      Add a simple bash script to parse the output from ${NM}. This works for
      CONFIG_LTO_CLANG=y because llvm-nm can dump symbols of LLVM IR files.
      
      Revert 15bfc234.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: NNick Desaulniers <ndesaulniers@google.com>
      Tested-by: NNathan Chancellor <nathan@kernel.org>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      31cb50b5
  14. 29 5月, 2022 1 次提交
    • M
      kbuild: do not create *.prelink.o for Clang LTO or IBT · c25e1c55
      Masahiro Yamada 提交于
      When CONFIG_LTO_CLANG=y, additional intermediate *.prelink.o is created
      for each module. Also, objtool is postponed until LLVM IR is converted
      to ELF.
      
      CONFIG_X86_KERNEL_IBT works in a similar way to postpone objtool until
      objects are merged together.
      
      This commit stops generating *.prelink.o, so the build flow will look
      similar with/without LTO.
      
      The following figures show how the LTO build currently works, and
      how this commit is changing it.
      
      Current build flow
      ==================
      
       [1] single-object module
      
                                            $(LD)
                 $(CC)                     +objtool              $(LD)
          foo.c --------------------> foo.o -----> foo.prelink.o -----> foo.ko
                                    (LLVM IR)          (ELF)       |    (ELF)
                                                                   |
                                                       foo.mod.o --/
                                                       (LLVM IR)
      
       [2] multi-object module
                                            $(LD)
                 $(CC)         $(AR)       +objtool               $(LD)
          foo1.c -----> foo1.o -----> foo.o -----> foo.prelink.o -----> foo.ko
                                 |  (archive)          (ELF)       |    (ELF)
          foo2.c -----> foo2.o --/                                 |
                       (LLVM IR)                       foo.mod.o --/
                                                       (LLVM IR)
      
        One confusion is that foo.o in multi-object module is an archive
        despite of its suffix.
      
      New build flow
      ==============
      
       [1] single-object module
      
        Since there is only one object, there is no need to keep the LLVM IR.
        Use $(CC)+$(LD) to generate an ELF object in one build rule. When LTO
        is disabled, $(LD) is unneeded because $(CC) produces an ELF object.
      
                     $(CC)+$(LD)+objtool              $(LD)
          foo.c ----------------------------> foo.o ---------> foo.ko
                                              (ELF)     |      (ELF)
                                                        |
                                            foo.mod.o --/
                                            (LLVM IR)
      
       [2] multi-object module
      
        Previously, $(AR) was used to combine LLVM IR files into an archive,
        but there was no technical reason to do so. Use $(LD) to merge them
        into a single ELF object.
      
                                     $(LD)
                   $(CC)            +objtool          $(LD)
          foo1.c ---------> foo1.o ---------> foo.o ---------> foo.ko
                                       |      (ELF)     |      (ELF)
          foo2.c ---------> foo2.o ----/                |
                           (LLVM IR)        foo.mod.o --/
                                            (LLVM IR)
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: NNicolas Schier <nicolas@fjasle.eu>
      Tested-by: NNathan Chancellor <nathan@kernel.org>
      Reviewed-by: NSami Tolvanen <samitolvanen@google.com>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      Acked-by: NJosh Poimboeuf <jpoimboe@kernel.org>
      c25e1c55
  15. 27 5月, 2022 5 次提交
  16. 24 5月, 2022 1 次提交
    • M
      kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS · 7b453719
      Masahiro Yamada 提交于
      include/{linux,asm-generic}/export.h defines a weak symbol, __crc_*
      as a placeholder.
      
      Genksyms writes the version CRCs into the linker script, which will be
      used for filling the __crc_* symbols. The linker script format depends
      on CONFIG_MODULE_REL_CRCS. If it is enabled, __crc_* holds the offset
      to the reference of CRC.
      
      It is time to get rid of this complexity.
      
      Now that modpost parses text files (.*.cmd) to collect all the CRCs,
      it can generate C code that will be linked to the vmlinux or modules.
      
      Generate a new C file, .vmlinux.export.c, which contains the CRCs of
      symbols exported by vmlinux. It is compiled and linked to vmlinux in
      scripts/link-vmlinux.sh.
      
      Put the CRCs of symbols exported by modules into the existing *.mod.c
      files. No additional build step is needed for modules. As before,
      *.mod.c are compiled and linked to *.ko in scripts/Makefile.modfinal.
      
      No linker magic is used here. The new C implementation works in the
      same way, whether CONFIG_RELOCATABLE is enabled or not.
      CONFIG_MODULE_REL_CRCS is no longer needed.
      
      Previously, Kbuild invoked additional $(LD) to update the CRCs in
      objects, but this step is unneeded too.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      Tested-by: NNathan Chancellor <nathan@kernel.org>
      Tested-by: NNicolas Schier <nicolas@fjasle.eu>
      Reviewed-by: NNicolas Schier <nicolas@fjasle.eu>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      7b453719
  17. 23 5月, 2022 2 次提交
    • M
      modpost: extract symbol versions from *.cmd files · f292d875
      Masahiro Yamada 提交于
      Currently, CONFIG_MODVERSIONS needs extra link to embed the symbol
      versions into ELF objects. Then, modpost extracts the version CRCs
      from them.
      
      The following figures show how it currently works, and how I am trying
      to change it.
      
      Current implementation
      ======================
                                                                 |----------|
                       embed CRC      -------------------------->| final    |
             $(CC)       $(LD)       /  |---------|              | link for |
             -----> *.o -------> *.o -->| modpost |              | vmlinux  |
            /              /            |         |-- *.mod.c -->| or       |
           / genksyms     /             |---------|              | module   |
        *.c ------> *.symversions                                |----------|
      
      Genksyms outputs the calculated CRCs in the form of linker script
      (*.symversions), which is used by $(LD) to update the object.
      
      If CONFIG_LTO_CLANG=y, the build process is much more complex. Embedding
      the CRCs is postponed until the LLVM bitcode is converted into ELF,
      creating another intermediate *.prelink.o.
      
      However, this complexity is unneeded. There is no reason why we must
      embed version CRCs in objects so early.
      
      There is final link stage for vmlinux (scripts/link-vmlinux.sh) and
      modules (scripts/Makefile.modfinal). We can link CRCs at the very last
      moment.
      
      New implementation
      ==================
                                                                 |----------|
                         --------------------------------------->| final    |
             $(CC)      /    |---------|                         | link for |
             -----> *.o ---->|         |                         | vmlinux  |
            /                | modpost |--- .vmlinux.export.c -->| or       |
           / genksyms        |         |--- *.mod.c ------------>| module   |
        *.c ------> *.cmd -->|---------|                         |----------|
      
      Pass the symbol versions to modpost as separate text data, which are
      available in *.cmd files.
      
      This commit changes modpost to extract CRCs from *.cmd files instead of
      from ELF objects.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: NNicolas Schier <nicolas@fjasle.eu>
      Tested-by: NNathan Chancellor <nathan@kernel.org>
      Reviewed-by: NSami Tolvanen <samitolvanen@google.com>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      f292d875
    • M
      modpost: add sym_find_with_module() helper · 69c4cc99
      Masahiro Yamada 提交于
      find_symbol() returns the first symbol found in the hash table. This
      table is global, so it may return a symbol from an unexpected module.
      
      There is a case where we want to search for a symbol with a given name
      in a specified module.
      
      Add sym_find_with_module(), which receives the module pointer as the
      second argument. It is equivalent to find_module() if NULL is passed
      as the module pointer.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: NNicolas Schier <nicolas@fjasle.eu>
      Tested-by: NNathan Chancellor <nathan@kernel.org>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      69c4cc99
  18. 11 5月, 2022 3 次提交
  19. 08 5月, 2022 3 次提交