Skip to content
Snippets Groups Projects
  1. Jul 12, 2023
    • Yonghong Song's avatar
      kallsyms: strip LTO-only suffixes from promoted global functions · 8cc32a9b
      Yonghong Song authored
      Commit 6eb4bd92 ("kallsyms: strip LTO suffixes from static functions")
      stripped all function/variable suffixes started with '.' regardless
      of whether those suffixes are generated at LTO mode or not. In fact,
      as far as I know, in LTO mode, when a static function/variable is
      promoted to the global scope, '.llvm.<...>' suffix is added.
      
      The existing mechanism breaks live patch for a LTO kernel even if
      no <symbol>.llvm.<...> symbols are involved. For example, for the following
      kernel symbols:
        $ grep bpf_verifier_vlog /proc/kallsyms
        ffffffff81549f60 t bpf_verifier_vlog
        ffffffff8268b430 d bpf_verifier_vlog._entry
        ffffffff8282a958 d bpf_verifier_vlog._entry_ptr
        ffffffff82e12a1f d bpf_verifier_vlog.__already_done
      'bpf_verifier_vlog' is a static function. '_entry', '_entry_ptr' and
      '__already_done' are static variables used inside 'bpf_verifier_vlog',
      so llvm promotes them to file-level static with prefix 'bpf_verifier_vlog.'.
      Note that the func-level to file-level static function promotion also
      happens without LTO.
      
      Given a symbol name 'bpf_verifier_vlog', with LTO kernel, current mechanism will
      return 4 symbols to live patch subsystem which current live patching
      subsystem cannot handle it. With non-LTO kernel, only one symbol
      is returned.
      
      In [1], we have a lengthy discussion, the suggestion is to separate two
      cases:
        (1). new symbols with suffix which are generated regardless of whether
             LTO is enabled or not, and
        (2). new symbols with suffix generated only when LTO is enabled.
      
      The cleanup_symbol_name() should only remove suffixes for case (2).
      Case (1) should not be changed so it can work uniformly with or without LTO.
      
      This patch removed LTO-only suffix '.llvm.<...>' so live patching and
      tracing should work the same way for non-LTO kernel.
      The cleanup_symbol_name() in scripts/kallsyms.c is also changed to have the same
      filtering pattern so both kernel and kallsyms tool have the same
      expectation on the order of symbols.
      
       [1] https://lore.kernel.org/live-patching/20230615170048.2382735-1-song@kernel.org/T/#u
      
      
      
      Fixes: 6eb4bd92 ("kallsyms: strip LTO suffixes from static functions")
      Reported-by: default avatarSong Liu <song@kernel.org>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Reviewed-by: default avatarZhen Lei <thunder.leizhen@huawei.com>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Acked-by: default avatarSong Liu <song@kernel.org>
      Link: https://lore.kernel.org/r/20230628181926.4102448-1-yhs@fb.com
      
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      8cc32a9b
  2. Jul 04, 2023
  3. Jul 03, 2023
  4. Jun 29, 2023
  5. Jun 28, 2023
    • Masahiro Yamada's avatar
      modpost: define more R_ARM_* for old distributions · f5983dab
      Masahiro Yamada authored
      
      On CentOS 7, the following build error occurs.
      
      scripts/mod/modpost.c: In function 'addend_arm_rel':
      scripts/mod/modpost.c:1312:7: error: 'R_ARM_MOVW_ABS_NC' undeclared (first use in this function); did you mean 'R_ARM_THM_ABS5'?
        case R_ARM_MOVW_ABS_NC:
             ^~~~~~~~~~~~~~~~~
             R_ARM_THM_ABS5
      scripts/mod/modpost.c:1312:7: note: each undeclared identifier is reported only once for each function it appears in
      scripts/mod/modpost.c:1313:7: error: 'R_ARM_MOVT_ABS' undeclared (first use in this function); did you mean 'R_ARM_THM_ABS5'?
        case R_ARM_MOVT_ABS:
             ^~~~~~~~~~~~~~
             R_ARM_THM_ABS5
      scripts/mod/modpost.c:1326:7: error: 'R_ARM_THM_MOVW_ABS_NC' undeclared (first use in this function); did you mean 'R_ARM_THM_ABS5'?
        case R_ARM_THM_MOVW_ABS_NC:
             ^~~~~~~~~~~~~~~~~~~~~
             R_ARM_THM_ABS5
      scripts/mod/modpost.c:1327:7: error: 'R_ARM_THM_MOVT_ABS' undeclared (first use in this function); did you mean 'R_ARM_THM_ABS5'?
        case R_ARM_THM_MOVT_ABS:
             ^~~~~~~~~~~~~~~~~~
             R_ARM_THM_ABS5
      
      Fixes: 12ca2c67 ("modpost: detect section mismatch for R_ARM_{MOVW_ABS_NC,MOVT_ABS}")
      Fixes: cd1824fb ("modpost: detect section mismatch for R_ARM_THM_{MOVW_ABS_NC,MOVT_ABS}")
      Reported-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      f5983dab
  6. Jun 27, 2023
  7. Jun 26, 2023
  8. Jun 25, 2023
  9. Jun 24, 2023
  10. Jun 22, 2023
    • Masahiro Yamada's avatar
      modpost: show offset from symbol for section mismatch warnings · f2346278
      Masahiro Yamada authored
      
      Currently, modpost only shows the symbol names and section names, so it
      repeats the same message if there are multiple relocations in the same
      symbol. It is common the relocation spans across multiple instructions.
      
      It is better to show the offset from the symbol.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      f2346278
    • Masahiro Yamada's avatar
      modpost: merge two similar section mismatch warnings · 78dac1a2
      Masahiro Yamada authored
      
      In case of section mismatch, modpost shows slightly different messages.
      
      For extable section mismatch:
      
       "%s(%s+0x%lx): Section mismatch in reference to the %s:%s\n"
      
      For the other cases:
      
       "%s: section mismatch in reference: %s (section: %s) -> %s (section: %s)\n"
      
      They are similar. Merge them.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      78dac1a2
    • Masahiro Yamada's avatar
      kbuild: implement CONFIG_TRIM_UNUSED_KSYMS without recursion · 5e9e95cc
      Masahiro Yamada authored
      When CONFIG_TRIM_UNUSED_KSYMS is enabled, Kbuild recursively traverses
      the directory tree to determine which EXPORT_SYMBOL to trim. If an
      EXPORT_SYMBOL turns out to be unused by anyone, Kbuild begins the
      second traverse, where some source files are recompiled with their
      EXPORT_SYMBOL() tuned into a no-op.
      
      Linus stated negative opinions about this slowness in commits:
      
       - 5cf0fd59 ("Kbuild: disable TRIM_UNUSED_KSYMS option")
       - a555bdd0 ("Kbuild: enable TRIM_UNUSED_KSYMS again, with some guarding")
      
      We can do this better now. The final data structures of EXPORT_SYMBOL
      are generated by the modpost stage, so modpost can selectively emit
      KSYMTAB entries that are really used by modules.
      
      Commit f73edc89 ("kbuild: unify two modpost invocations") is another
      ground-work to do this in a one-pass algorithm. With the list of modules,
      modpost sets sym->used if it is used by a module. modpost emits KSYMTAB
      only for symbols with sym->used==true.
      
      BTW, Nicolas explained why the trimming was implemented with recursion:
      
        https://lore.kernel.org/all/2o2rpn97-79nq-p7s2-nq5-8p83391473r@syhkavp.arg/
      
      
      
      Actually, we never achieved that level of optimization where the chain
      reaction of trimming comes into play because:
      
       - CONFIG_LTO_CLANG cannot remove any unused symbols
       - CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is enabled only for vmlinux,
         but not modules
      
      If deeper trimming is required, we need to revisit this, but I guess
      that is unlikely to happen.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      5e9e95cc
    • Masahiro Yamada's avatar
      modpost: use null string instead of NULL pointer for default namespace · 700c48b4
      Masahiro Yamada authored
      
      The default namespace is the null string, "".
      
      When set, the null string "" is converted to NULL:
      
        s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL;
      
      When printed, the NULL pointer is get back to the null string:
      
        sym->namespace ?: ""
      
      This saves 1 byte memory allocated for "", but loses the readability.
      
      In kernel-space, we strive to save memory, but modpost is a userspace
      tool used to build the kernel. On modern systems, such small piece of
      memory is not a big deal.
      
      Handle the namespace string as is.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      700c48b4
    • Masahiro Yamada's avatar
      modpost: squash sym_update_namespace() into sym_add_exported() · 6e7611c4
      Masahiro Yamada authored
      
      Pass a set of the name, license, and namespace to sym_add_exported().
      
      sym_update_namespace() is unneeded.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      6e7611c4
    • Masahiro Yamada's avatar
      modpost: check static EXPORT_SYMBOL* by modpost again · 6d62b1c4
      Masahiro Yamada authored
      
      Commit 31cb50b5 ("kbuild: check static EXPORT_SYMBOL* by script
      instead of modpost") moved the static EXPORT_SYMBOL* check from the
      mostpost to a shell script because I thought it must be checked per
      compilation unit to avoid false negatives.
      
      I came up with an idea to do this in modpost, against combined ELF
      files. The relocation entries in ELF will find the correct exported
      symbol even if there exist symbols with the same name in different
      compilation units.
      
      Again, the same 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) {}
      
      Then, modpost can catch it correctly.
      
          MODPOST Module.symvers
        ERROR: modpost: vmlinux: local symbol 'foo' was exported
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      6d62b1c4
    • Masahiro Yamada's avatar
      kbuild: generate KSYMTAB entries by modpost · ddb5cdba
      Masahiro Yamada authored
      
      Commit 7b453719 ("kbuild: link symbol CRCs at final link, removing
      CONFIG_MODULE_REL_CRCS") made modpost output CRCs in the same way
      whether the EXPORT_SYMBOL() is placed in *.c or *.S.
      
      For further cleanups, this commit applies a similar approach to the
      entire data structure of EXPORT_SYMBOL().
      
      The EXPORT_SYMBOL() compilation is split into two stages.
      
      When a source file is compiled, EXPORT_SYMBOL() will be converted into
      a dummy symbol in the .export_symbol section.
      
      For example,
      
          EXPORT_SYMBOL(foo);
          EXPORT_SYMBOL_NS_GPL(bar, BAR_NAMESPACE);
      
      will be encoded into the following assembly code:
      
          .section ".export_symbol","a"
          __export_symbol_foo:
                  .asciz ""                      /* license */
                  .asciz ""                      /* name space */
                  .balign 8
                  .quad foo                      /* symbol reference */
          .previous
      
          .section ".export_symbol","a"
          __export_symbol_bar:
                  .asciz "GPL"                   /* license */
                  .asciz "BAR_NAMESPACE"         /* name space */
                  .balign 8
                  .quad bar                      /* symbol reference */
          .previous
      
      They are mere markers to tell modpost the name, license, and namespace
      of the symbols. They will be dropped from the final vmlinux and modules
      because the *(.export_symbol) will go into /DISCARD/ in the linker script.
      
      Then, modpost extracts all the information about EXPORT_SYMBOL() from the
      .export_symbol section, and generates the final C code:
      
          KSYMTAB_FUNC(foo, "", "");
          KSYMTAB_FUNC(bar, "_gpl", "BAR_NAMESPACE");
      
      KSYMTAB_FUNC() (or KSYMTAB_DATA() if it is data) is expanded to struct
      kernel_symbol that will be linked to the vmlinux or a module.
      
      With this change, EXPORT_SYMBOL() works in the same way for *.c and *.S
      files, providing the following benefits.
      
      [1] Deprecate EXPORT_DATA_SYMBOL()
      
      In the old days, EXPORT_SYMBOL() was only available in C files. To export
      a symbol in *.S, EXPORT_SYMBOL() was placed in a separate *.c file.
      arch/arm/kernel/armksyms.c is one example written in the classic manner.
      
      Commit 22823ab4 ("EXPORT_SYMBOL() for asm") removed this limitation.
      Since then, EXPORT_SYMBOL() can be placed close to the symbol definition
      in *.S files. It was a nice improvement.
      
      However, as that commit mentioned, you need to use EXPORT_DATA_SYMBOL()
      for data objects on some architectures.
      
      In the new approach, modpost checks symbol's type (STT_FUNC or not),
      and outputs KSYMTAB_FUNC() or KSYMTAB_DATA() accordingly.
      
      There are only two users of EXPORT_DATA_SYMBOL:
      
        EXPORT_DATA_SYMBOL_GPL(empty_zero_page)    (arch/ia64/kernel/head.S)
        EXPORT_DATA_SYMBOL(ia64_ivt)               (arch/ia64/kernel/ivt.S)
      
      They are transformed as follows and output into .vmlinux.export.c
      
        KSYMTAB_DATA(empty_zero_page, "_gpl", "");
        KSYMTAB_DATA(ia64_ivt, "", "");
      
      The other EXPORT_SYMBOL users in ia64 assembly are output as
      KSYMTAB_FUNC().
      
      EXPORT_DATA_SYMBOL() is now deprecated.
      
      [2] merge <linux/export.h> and <asm-generic/export.h>
      
      There are two similar header implementations:
      
        include/linux/export.h        for .c files
        include/asm-generic/export.h  for .S files
      
      Ideally, the functionality should be consistent between them, but they
      tend to diverge.
      
      Commit 8651ec01 ("module: add support for symbol namespaces.") did
      not support the namespace for *.S files.
      
      This commit shifts the essential implementation part to C, which supports
      EXPORT_SYMBOL_NS() for *.S files.
      
      <asm/export.h> and <asm-generic/export.h> will remain as a wrapper of
      <linux/export.h> for a while.
      
      They will be removed after #include <asm/export.h> directives are all
      replaced with #include <linux/export.h>.
      
      [3] Implement CONFIG_TRIM_UNUSED_KSYMS in one-pass algorithm (by a later commit)
      
      When CONFIG_TRIM_UNUSED_KSYMS is enabled, Kbuild recursively traverses
      the directory tree to determine which EXPORT_SYMBOL to trim. If an
      EXPORT_SYMBOL turns out to be unused by anyone, Kbuild begins the
      second traverse, where some source files are recompiled with their
      EXPORT_SYMBOL() tuned into a no-op.
      
      We can do this better now; modpost can selectively emit KSYMTAB entries
      that are really used by modules.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      ddb5cdba
  11. Jun 21, 2023
    • Rob Herring's avatar
      kbuild: Support flat DTBs install · 6a1d798f
      Rob Herring authored
      
      In preparation to move Arm .dts files into sub-directories grouped
      by vendor/family, the current flat tree of DTBs generated by
      dtbs_install needs to be maintained. Moving the installed DTBs to
      sub-directories would break various consumers using 'make dtbs_install'.
      
      This is a NOP until sub-directories are introduced.
      
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
      6a1d798f
  12. Jun 19, 2023
  13. Jun 16, 2023
  14. Jun 15, 2023
  15. Jun 14, 2023
  16. Jun 10, 2023
  17. Jun 08, 2023
Loading