26 Oct, 2020

1 commit

  • Use a more generic form for __section that requires quotes to avoid
    complications with clang and gcc differences.

    Remove the quote operator # from compiler_attributes.h __section macro.

    Convert all unquoted __section(foo) uses to quoted __section("foo").
    Also convert __attribute__((section("foo"))) uses to __section("foo")
    even if the __attribute__ has multiple list entry forms.

    Conversion done using the script at:

    https://lore.kernel.org/lkml/75393e5ddc272dc7403de74d645e6c6e0f4e70eb.camel@perches.com/2-convert_section.pl

    Signed-off-by: Joe Perches
    Reviewed-by: Nick Desaulniers
    Reviewed-by: Miguel Ojeda
    Signed-off-by: Linus Torvalds

    Joe Perches
     

14 Oct, 2020

1 commit

  • When enabling CONFIG_TRIM_UNUSED_KSYMS, the linker will warn about the
    orphan sections:

    (".discard.ksym") is being placed in '".discard.ksym"'

    repeatedly when linking vmlinux. This is because the stringification
    operator, `#`, in the preprocessor escapes strings. GCC and Clang differ
    in how they treat section names that contain \".

    The portable solution is to not use a string literal with the preprocessor
    stringification operator.

    Fixes: commit bbda5ec671d3 ("kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS")
    Reported-by: kbuild test robot
    Suggested-by: Kees Cook
    Signed-off-by: Nick Desaulniers
    Signed-off-by: Andrew Morton
    Reviewed-by: Kees Cook
    Cc: Nathan Chancellor
    Cc: Masahiro Yamada
    Cc: Matthias Maennich
    Cc: Jessica Yu
    Cc: Greg Kroah-Hartman
    Cc: Will Deacon
    Link: https://bugs.llvm.org/show_bug.cgi?id=42950
    Link: https://github.com/ClangBuiltLinux/linux/issues/1166
    Link: https://lkml.kernel.org/r/20200929190701.398762-1-ndesaulniers@google.com
    Signed-off-by: Linus Torvalds

    Nick Desaulniers
     

16 Dec, 2019

1 commit

  • Commit c3a6cf19e695 ("export: avoid code duplication in
    include/linux/export.h") refactors export.h quite nicely, but introduces
    a slight increase in memory usage due to using the empty string ""
    instead of NULL to indicate that an exported symbol has no namespace. As
    mentioned in that commit, this meant an increase of 1 byte per exported
    symbol without a namespace. For example, if a kernel configuration has
    about 10k exported symbols, this would mean that the size of
    __ksymtab_strings would increase by roughly 10kB.

    We can alleviate this situation by utilizing the SHF_MERGE and
    SHF_STRING section flags. SHF_MERGE|SHF_STRING indicate to the linker
    that the data in the section are null-terminated strings that can be
    merged to eliminate duplication. More specifically, from the binutils
    documentation - "for sections with both M and S, a string which is a
    suffix of a larger string is considered a duplicate. Thus "def" will be
    merged with "abcdef"; A reference to the first "def" will be changed to
    a reference to "abcdef"+3". Thus, all the empty strings would be merged
    as well as any strings that can be merged according to the cited method
    above. For example, "memset" and "__memset" would be merged to just
    "__memset" in __ksymtab_strings.

    As of v5.4-rc5, the following statistics were gathered with x86
    defconfig with approximately 10.7k exported symbols.

    Size of __ksymtab_strings in vmlinux:
    -------------------------------------
    v5.4-rc5: 213834 bytes
    v5.4-rc5 with commit c3a6cf19e695: 224455 bytes
    v5.4-rc5 with this patch: 205759 bytes

    So, we already see memory savings of ~8kB compared to vanilla -rc5 and
    savings of nearly 18.7kB compared to -rc5 with commit c3a6cf19e695 on top.

    Unfortunately, as of this writing, strings will not get deduplicated for
    kernel modules, as ld does not do the deduplication for
    SHF_MERGE|SHF_STRINGS sections for relocatable files (ld -r), which
    kernel modules are. A patch for ld is currently being worked on to
    hopefully allow for string deduplication in relocatable files in the
    future.

    Suggested-by: Rasmus Villemoes
    Reviewed-by: Masahiro Yamada
    Reviewed-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Jessica Yu
     

06 Dec, 2019

1 commit

  • Pull modules updates from Jessica Yu:
    "Summary of modules changes for the 5.5 merge window:

    - Refactor include/linux/export.h and remove code duplication between
    EXPORT_SYMBOL and EXPORT_SYMBOL_NS to make it more readable.

    The most notable change is that no namespace is represented by an
    empty string "" rather than NULL.

    - Fix a module load/unload race where waiter(s) trying to load the
    same module weren't being woken up when a module finally goes away"

    * tag 'modules-for-v5.5' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux:
    kernel/module.c: wakeup processes in module_wq on module unload
    moduleparam: fix parameter description mismatch
    export: avoid code duplication in include/linux/export.h

    Linus Torvalds
     

14 Nov, 2019

1 commit

  • Commit b24413180f56 ("License cleanup: add SPDX GPL-2.0 license
    identifier to files with no license") took care of a lot of files
    without any license information.

    These headers were not processed by the tool perhaps because they
    contain "GPL" in the code.

    I do not see any license boilerplate in them, so they fall back to
    GPL version 2 only, which is the project default.

    Signed-off-by: Masahiro Yamada
    Link: https://lore.kernel.org/r/20191018045053.8424-1-yamada.masahiro@socionext.com
    Signed-off-by: Greg Kroah-Hartman

    Masahiro Yamada
     

28 Oct, 2019

1 commit

  • include/linux/export.h has lots of code duplication between
    EXPORT_SYMBOL and EXPORT_SYMBOL_NS.

    To improve the maintainability and readability, unify the
    implementation.

    When the symbol has no namespace, pass the empty string "" to
    the 'ns' parameter.

    The drawback of this change is, it grows the code size.
    When the symbol has no namespace, sym->namespace was previously
    NULL, but it is now an empty string "". So, it increases 1 byte
    for every no namespace EXPORT_SYMBOL.

    A typical kernel configuration has 10K exported symbols, so it
    increases 10KB in rough estimation.

    I did not come up with a good idea to refactor it without increasing
    the code size.

    I am not sure how big a deal it is, but at least include/linux/export.h
    looks nicer.

    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Masahiro Yamada
    [maennich: rebase on top of 3 fixes for the namespace feature]
    Signed-off-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Masahiro Yamada
     

18 Oct, 2019

1 commit

  • The introduction of Symbol Namespaces changed the naming schema of the
    __ksymtab entries from __kysmtab__symbol to __ksymtab_NAMESPACE.symbol.

    That caused some breakages in tools that depend on the name layout in
    either the binaries(vmlinux,*.ko) or in System.map. E.g. kmod's depmod
    would not be able to read System.map without a patch to support symbol
    namespaces. A warning reported by depmod for namespaced symbols would
    look like

    depmod: WARNING: [...]/uas.ko needs unknown symbol usb_stor_adjust_quirks

    In order to address this issue, revert to the original naming scheme and
    rather read the __kstrtabns_ entries and their corresponding
    values from __ksymtab_strings to update the namespace values for
    symbols. After having read all symbols and handled them in
    handle_modversions(), the symbols are created. In a second pass, read
    the __kstrtabns_ entries and update the namespaces accordingly.

    Fixes: 8651ec01daed ("module: add support for symbol namespaces.")
    Reported-by: Stefan Wahren
    Suggested-by: Masahiro Yamada
    Acked-by: Will Deacon
    Reviewed-by: Greg Kroah-Hartman
    Reviewed-by: Masahiro Yamada
    Signed-off-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Matthias Maennich
     

08 Oct, 2019

2 commits

  • The module namespace produces __strtab_ns_ symbols to store
    namespace strings, but it does not guarantee the name uniqueness.
    This is a potential problem because we have exported symbols starting
    with "ns_".

    For example, kernel/capability.c exports the following symbols:

    EXPORT_SYMBOL(ns_capable);
    EXPORT_SYMBOL(capable);

    Assume a situation where those are converted as follows:

    EXPORT_SYMBOL_NS(ns_capable, some_namespace);
    EXPORT_SYMBOL_NS(capable, some_namespace);

    The former expands to "__kstrtab_ns_capable" and "__kstrtab_ns_ns_capable",
    and the latter to "__kstrtab_capable" and "__kstrtab_ns_capable".
    Then, we have the duplicated "__kstrtab_ns_capable".

    To ensure the uniqueness, rename "__kstrtab_ns_*" to "__kstrtabns_*".

    Reviewed-by: Matthias Maennich
    Signed-off-by: Masahiro Yamada
    Signed-off-by: Jessica Yu

    Masahiro Yamada
     
  • Currently, EXPORT_SYMBOL_NS(_GPL) constructs the kernel symbol as
    follows:

    __ksymtab_SYMBOL.NAMESPACE

    The sym_extract_namespace() in modpost allocates memory for the part
    SYMBOL.NAMESPACE when '.' is contained. One problem is that the pointer
    returned by strdup() is lost because the symbol name will be copied to
    malloc'ed memory by alloc_symbol(). No one will keep track of the
    pointer of strdup'ed memory.

    sym->namespace still points to the NAMESPACE part. So, you can free it
    with complicated code like this:

    free(sym->namespace - strlen(sym->name) - 1);

    It complicates memory free.

    To fix it elegantly, I swapped the order of the symbol and the
    namespace as follows:

    __ksymtab_NAMESPACE.SYMBOL

    then, simplified sym_extract_namespace() so that it allocates memory
    only for the NAMESPACE part.

    I prefer this order because it is intuitive and also matches to major
    languages. For example, NAMESPACE::NAME in C++, MODULE.NAME in Python.

    Reviewed-by: Matthias Maennich
    Signed-off-by: Masahiro Yamada
    Signed-off-by: Jessica Yu

    Masahiro Yamada
     

23 Sep, 2019

1 commit

  • Pull modules updates from Jessica Yu:
    "The main bulk of this pull request introduces a new exported symbol
    namespaces feature. The number of exported symbols is increasingly
    growing with each release (we're at about 31k exports as of 5.3-rc7)
    and we currently have no way of visualizing how these symbols are
    "clustered" or making sense of this huge export surface.

    Namespacing exported symbols allows kernel developers to more
    explicitly partition and categorize exported symbols, as well as more
    easily limiting the availability of namespaced symbols to other parts
    of the kernel. For starters, we have introduced the USB_STORAGE
    namespace to demonstrate the API's usage. I have briefly summarized
    the feature and its main motivations in the tag below.

    Summary:

    - Introduce exported symbol namespaces.

    This new feature allows subsystem maintainers to partition and
    categorize their exported symbols into explicit namespaces. Module
    authors are now required to import the namespaces they need.

    Some of the main motivations of this feature include: allowing
    kernel developers to better manage the export surface, allow
    subsystem maintainers to explicitly state that usage of some
    exported symbols should only be limited to certain users (think:
    inter-module or inter-driver symbols, debugging symbols, etc), as
    well as more easily limiting the availability of namespaced symbols
    to other parts of the kernel.

    With the module import requirement, it is also easier to spot the
    misuse of exported symbols during patch review.

    Two new macros are introduced: EXPORT_SYMBOL_NS() and
    EXPORT_SYMBOL_NS_GPL(). The API is thoroughly documented in
    Documentation/kbuild/namespaces.rst.

    - Some small code and kbuild cleanups here and there"

    * tag 'modules-for-v5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux:
    module: Remove leftover '#undef' from export header
    module: remove unneeded casts in cmp_name()
    module: move CONFIG_UNUSED_SYMBOLS to the sub-menu of MODULES
    module: remove redundant 'depends on MODULES'
    module: Fix link failure due to invalid relocation on namespace offset
    usb-storage: export symbols in USB_STORAGE namespace
    usb-storage: remove single-use define for debugging
    docs: Add documentation for Symbol Namespaces
    scripts: Coccinelle script for namespace dependencies.
    modpost: add support for generating namespace dependencies
    export: allow definition default namespaces in Makefiles or sources
    module: add config option MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS
    modpost: add support for symbol namespaces
    module: add support for symbol namespaces.
    export: explicitly align struct kernel_symbol
    module: support reading multiple values per modinfo tag

    Linus Torvalds
     

14 Sep, 2019

1 commit

  • Arnd Bergmann reported false-positive modpost warnings detected by his
    randconfig testing of linux-next.

    Actually, this happens under the combination of CONFIG_MODVERSIONS
    and CONFIG_TRIM_UNUSED_KSYMS since commit 15bfc2348d54 ("modpost:
    check for static EXPORT_SYMBOL* functions").

    For example, arch/arm/config/multi_v7_defconfig + CONFIG_MODVERSIONS
    + CONFIG_TRIM_UNUSED_KSYMS produces the following false-positives:

    WARNING: "__lshrdi3" [vmlinux] is a static (unknown)
    WARNING: "__ashrdi3" [vmlinux] is a static (unknown)
    WARNING: "__aeabi_lasr" [vmlinux] is a static (unknown)
    WARNING: "__aeabi_llsr" [vmlinux] is a static (unknown)
    WARNING: "ftrace_set_clr_event" [vmlinux] is a static (unknown)
    WARNING: "__muldi3" [vmlinux] is a static (unknown)
    WARNING: "__aeabi_ulcmp" [vmlinux] is a static (unknown)
    WARNING: "__ucmpdi2" [vmlinux] is a static (unknown)
    WARNING: "__aeabi_lmul" [vmlinux] is a static (unknown)
    WARNING: "__bswapsi2" [vmlinux] is a static (unknown)
    WARNING: "__bswapdi2" [vmlinux] is a static (unknown)
    WARNING: "__ashldi3" [vmlinux] is a static (unknown)
    WARNING: "__aeabi_llsl" [vmlinux] is a static (unknown)

    The root cause of the problem is not in the modpost, but in the
    implementation of CONFIG_TRIM_UNUSED_KSYMS.

    If there is at least one untrimmed symbol in the file, genksyms is
    invoked to calculate CRC of *all* the exported symbols in that file
    even if some of them have been trimmed due to no caller existing.

    As a result, .tmp_*.ver files contain CRC of trimmed symbols, thus
    unneeded, orphan __crc* symbols are added to objects. It had been
    harmless until recently.

    With commit 15bfc2348d54 ("modpost: check for static EXPORT_SYMBOL*
    functions"), it is now harmful because the bogus __crc* symbols make
    modpost call sym_update_crc() to add the symbols to the hash table,
    but there is no one that clears the ->is_static member.

    I gave Fixes to the first commit that uncovered the issue, but the
    potential problem has long existed since commit f235541699bc
    ("export.h: allow for per-symbol configurable EXPORT_SYMBOL()").

    Fixes: 15bfc2348d54 ("modpost: check for static EXPORT_SYMBOL* functions")
    Reported-by: Arnd Bergmann
    Signed-off-by: Masahiro Yamada
    Tested-by: Arnd Bergmann

    Masahiro Yamada
     

12 Sep, 2019

1 commit

  • Commit 8651ec01daed ("module: add support for symbol namespaces.")
    broke linking for arm64 defconfig:

    | lib/crypto/arc4.o: In function `__ksymtab_arc4_setkey':
    | arc4.c:(___ksymtab+arc4_setkey+0x8): undefined reference to `no symbol'
    | lib/crypto/arc4.o: In function `__ksymtab_arc4_crypt':
    | arc4.c:(___ksymtab+arc4_crypt+0x8): undefined reference to `no symbol'

    This is because the dummy initialisation of the 'namespace_offset' field
    in 'struct kernel_symbol' when using EXPORT_SYMBOL on architectures with
    support for PREL32 locations uses an offset from an absolute address (0)
    in an effort to trick 'offset_to_pointer' into behaving as a NOP,
    allowing non-namespaced symbols to be treated in the same way as those
    belonging to a namespace.

    Unfortunately, place-relative relocations require a symbol reference
    rather than an absolute value and, although x86 appears to get away with
    this due to placing the kernel text at the top of the address space, it
    almost certainly results in a runtime failure if the kernel is relocated
    dynamically as a result of KASLR.

    Rework 'namespace_offset' so that a value of 0, which cannot occur for a
    valid namespaced symbol, indicates that the corresponding symbol does
    not belong to a namespace.

    Cc: Matthias Maennich
    Cc: Jessica Yu
    Cc: Ard Biesheuvel
    Cc: Catalin Marinas
    Fixes: 8651ec01daed ("module: add support for symbol namespaces.")
    Reported-by: kbuild test robot
    Tested-by: Matthias Maennich
    Tested-by: Ard Biesheuvel
    Reviewed-by: Matthias Maennich
    Acked-by: Ard Biesheuvel
    Signed-off-by: Will Deacon
    Signed-off-by: Jessica Yu

    Will Deacon
     

10 Sep, 2019

4 commits

  • The conditional, define(__KERNEL__), was added by commit f235541699bc
    ("export.h: allow for per-symbol configurable EXPORT_SYMBOL()").

    It was needed at that time to avoid the build error of modpost
    with CONFIG_TRIM_UNUSED_KSYMS=y.

    Since commit b2c5cdcfd4bc ("modpost: remove symbol prefix support"),
    modpost no longer includes linux/export.h, thus the define(__KERNEL__)
    is unneeded.

    Signed-off-by: Masahiro Yamada
    Acked-by: Nicolas Pitre

    Masahiro Yamada
     
  • To avoid excessive usage of EXPORT_SYMBOL_NS(sym, MY_NAMESPACE), where
    MY_NAMESPACE will always be the namespace we are exporting to, allow
    exporting all definitions of EXPORT_SYMBOL() and friends by defining
    DEFAULT_SYMBOL_NAMESPACE.

    For example, to export all symbols defined in usb-common into the
    namespace USB_COMMON, add a line like this to drivers/usb/common/Makefile:

    ccflags-y += -DDEFAULT_SYMBOL_NAMESPACE=USB_COMMON

    That is equivalent to changing all EXPORT_SYMBOL(sym) definitions to
    EXPORT_SYMBOL_NS(sym, USB_COMMON). Subsequently all symbol namespaces
    functionality will apply.

    Another way of making use of this feature is to define the namespace
    within source or header files similar to how TRACE_SYSTEM defines are
    used:
    #undef DEFAULT_SYMBOL_NAMESPACE
    #define DEFAULT_SYMBOL_NAMESPACE USB_COMMON

    Please note that, as opposed to TRACE_SYSTEM, DEFAULT_SYMBOL_NAMESPACE
    has to be defined before including include/linux/export.h.

    If DEFAULT_SYMBOL_NAMESPACE is defined, a symbol can still be exported
    to another namespace by using EXPORT_SYMBOL_NS() and friends with
    explicitly specifying the namespace.

    Suggested-by: Arnd Bergmann
    Reviewed-by: Martijn Coenen
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Matthias Maennich
     
  • The EXPORT_SYMBOL_NS() and EXPORT_SYMBOL_NS_GPL() macros can be used to
    export a symbol to a specific namespace. There are no _GPL_FUTURE and
    _UNUSED variants because these are currently unused, and I'm not sure
    they are necessary.

    I didn't add EXPORT_SYMBOL_NS() for ASM exports; this patch sets the
    namespace of ASM exports to NULL by default. In case of relative
    references, it will be relocatable to NULL. If there's a need, this
    should be pretty easy to add.

    A module that wants to use a symbol exported to a namespace must add a
    MODULE_IMPORT_NS() statement to their module code; otherwise, modpost
    will complain when building the module, and the kernel module loader
    will emit an error and fail when loading the module.

    MODULE_IMPORT_NS() adds a modinfo tag 'import_ns' to the module. That
    tag can be observed by the modinfo command, modpost and kernel/module.c
    at the time of loading the module.

    The ELF symbols are renamed to include the namespace with an asm label;
    for example, symbol 'usb_stor_suspend' in namespace USB_STORAGE becomes
    'usb_stor_suspend.USB_STORAGE'. This allows modpost to do namespace
    checking, without having to go through all the effort of parsing ELF and
    relocation records just to get to the struct kernel_symbols.

    On x86_64 I saw no difference in binary size (compression), but at
    runtime this will require a word of memory per export to hold the
    namespace. An alternative could be to store namespaced symbols in their
    own section and use a separate 'struct namespaced_kernel_symbol' for
    that section, at the cost of making the module loader more complex.

    Co-developed-by: Martijn Coenen
    Signed-off-by: Martijn Coenen
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Matthias Maennich
     
  • This change allows growing struct kernel_symbol without wasting bytes to
    alignment. It also concretized the alignment of ksymtab entries if
    relative references are used for ksymtab entries.

    struct kernel_symbol was already implicitly being aligned to the word
    size, except on x86_64 and m68k, where it is aligned to 16 and 2 bytes,
    respectively.

    As far as I can tell there is no requirement for aligning struct
    kernel_symbol to 16 bytes on x86_64, but gcc aligns structs to their
    size, and the linker aligns the custom __ksymtab sections to the largest
    data type contained within, so setting KSYM_ALIGN to 16 was necessary to
    stay consistent with the code generated for non-ASM EXPORT_SYMBOL(). Now
    that non-ASM EXPORT_SYMBOL() explicitly aligns to word size (8),
    KSYM_ALIGN is no longer necessary.

    In case of relative references, the alignment has been changed
    accordingly to not waste space when adding new struct members.

    As for m68k, struct kernel_symbol is aligned to 2 bytes even though the
    structure itself is 8 bytes; using a 4-byte alignment shouldn't hurt.

    I manually verified the output of the __ksymtab sections didn't change
    on x86, x86_64, arm, arm64 and m68k. As expected, the section contents
    didn't change, and the ELF section alignment only changed on x86_64 and
    m68k. Feedback from other archs more than welcome.

    Co-developed-by: Martijn Coenen
    Signed-off-by: Martijn Coenen
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Matthias Maennich
     

01 Dec, 2018

1 commit

  • My main motivation of this commit is to clean up scripts/Kbuild.include
    and scripts/Makefile.build.

    Currently, CONFIG_TRIM_UNUSED_KSYMS works with a tricky gimmick;
    possibly exported symbols are detected by letting $(CPP) replace
    EXPORT_SYMBOL* with a special string '=== __KSYM_*===', which is
    post-processed by sed, and passed to fixdep. The extra preprocessing
    is costly, and hacking cmd_and_fixdep is ugly.

    I came up with a new way to find exported symbols; insert a dummy
    symbol __ksym_marker_* to each potentially exported symbol. Those
    dummy symbols are picked up by $(NM), post-processed by sed, then
    appended to .*.cmd files. I collected the post-process part to a
    new shell script scripts/gen_ksymdeps.sh for readability. The dummy
    symbols are put into the .discard.* section so that the linker
    script rips them off the final vmlinux or modules.

    A nice side-effect is building with CONFIG_TRIM_UNUSED_KSYMS will
    be much faster.

    Signed-off-by: Masahiro Yamada
    Reviewed-by: Nicolas Pitre

    Masahiro Yamada
     

26 Aug, 2018

1 commit

  • Pull more Kbuild updates from Masahiro Yamada:

    - add build_{menu,n,g,x}config targets for compile-testing Kconfig

    - fix and improve recursive dependency detection in Kconfig

    - fix parallel building of menuconfig/nconfig

    - fix syntax error in clang-version.sh

    - suppress distracting log from syncconfig

    - remove obsolete "rpm" target

    - remove VMLINUX_SYMBOL(_STR) macro entirely

    - fix microblaze build with CONFIG_DYNAMIC_FTRACE

    - move compiler test for dead code/data elimination to Kconfig

    - rename well-known LDFLAGS variable to KBUILD_LDFLAGS

    - misc fixes and cleanups

    * tag 'kbuild-v4.19-2' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
    kbuild: rename LDFLAGS to KBUILD_LDFLAGS
    kbuild: pass LDFLAGS to recordmcount.pl
    kbuild: test dead code/data elimination support in Kconfig
    initramfs: move gen_initramfs_list.sh from scripts/ to usr/
    vmlinux.lds.h: remove stale include
    export.h: remove VMLINUX_SYMBOL() and VMLINUX_SYMBOL_STR()
    Coccinelle: remove pci_alloc_consistent semantic to detect in zalloc-simple.cocci
    kbuild: make sorting initramfs contents independent of locale
    kbuild: remove "rpm" target, which is alias of "rpm-pkg"
    kbuild: Fix LOADLIBES rename in Documentation/kbuild/makefiles.txt
    kconfig: suppress "configuration written to .config" for syncconfig
    kconfig: fix "Can't open ..." in parallel build
    kbuild: Add a space after `!` to prevent parsing as file pattern
    scripts: modpost: check memory allocation results
    kconfig: improve the recursive dependency report
    kconfig: report recursive dependency involving 'imply'
    kconfig: error out when seeing recursive dependency
    kconfig: add build-only configurator targets
    scripts/dtc: consolidate include path options in Makefile

    Linus Torvalds
     

23 Aug, 2018

2 commits

  • An ordinary arm64 defconfig build has ~64 KB worth of __ksymtab entries,
    each consisting of two 64-bit fields containing absolute references, to
    the symbol itself and to a char array containing its name, respectively.

    When we build the same configuration with KASLR enabled, we end up with an
    additional ~192 KB of relocations in the .init section, i.e., one 24 byte
    entry for each absolute reference, which all need to be processed at boot
    time.

    Given how the struct kernel_symbol that describes each entry is completely
    local to module.c (except for the references emitted by EXPORT_SYMBOL()
    itself), we can easily modify it to contain two 32-bit relative references
    instead. This reduces the size of the __ksymtab section by 50% for all
    64-bit architectures, and gets rid of the runtime relocations entirely for
    architectures implementing KASLR, either via standard PIE linking (arm64)
    or using custom host tools (x86).

    Note that the binary search involving __ksymtab contents relies on each
    section being sorted by symbol name. This is implemented based on the
    input section names, not the names in the ksymtab entries, so this patch
    does not interfere with that.

    Given that the use of place-relative relocations requires support both in
    the toolchain and in the module loader, we cannot enable this feature for
    all architectures. So make it dependent on whether
    CONFIG_HAVE_ARCH_PREL32_RELOCATIONS is defined.

    Link: http://lkml.kernel.org/r/20180704083651.24360-4-ard.biesheuvel@linaro.org
    Signed-off-by: Ard Biesheuvel
    Acked-by: Jessica Yu
    Acked-by: Michael Ellerman
    Reviewed-by: Will Deacon
    Acked-by: Ingo Molnar
    Cc: Arnd Bergmann
    Cc: Benjamin Herrenschmidt
    Cc: Bjorn Helgaas
    Cc: Catalin Marinas
    Cc: James Morris
    Cc: James Morris
    Cc: Josh Poimboeuf
    Cc: Kees Cook
    Cc: Nicolas Pitre
    Cc: Paul Mackerras
    Cc: Petr Mladek
    Cc: Russell King
    Cc: "Serge E. Hallyn"
    Cc: Sergey Senozhatsky
    Cc: Steven Rostedt
    Cc: Thomas Garnier
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ard Biesheuvel
     
  • To allow existing C code to be incorporated into the decompressor or the
    UEFI stub, introduce a CPP macro that turns all EXPORT_SYMBOL_xxx
    declarations into nops, and #define it in places where such exports are
    undesirable. Note that this gets rid of a rather dodgy redefine of
    linux/export.h's header guard.

    Link: http://lkml.kernel.org/r/20180704083651.24360-3-ard.biesheuvel@linaro.org
    Signed-off-by: Ard Biesheuvel
    Acked-by: Nicolas Pitre
    Acked-by: Michael Ellerman
    Reviewed-by: Will Deacon
    Acked-by: Ingo Molnar
    Cc: Arnd Bergmann
    Cc: Benjamin Herrenschmidt
    Cc: Bjorn Helgaas
    Cc: Catalin Marinas
    Cc: James Morris
    Cc: James Morris
    Cc: Jessica Yu
    Cc: Josh Poimboeuf
    Cc: Kees Cook
    Cc: Paul Mackerras
    Cc: Petr Mladek
    Cc: Russell King
    Cc: "Serge E. Hallyn"
    Cc: Sergey Senozhatsky
    Cc: Steven Rostedt
    Cc: Thomas Garnier
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ard Biesheuvel
     

22 Aug, 2018

1 commit


17 May, 2018

1 commit

  • CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX was selected by BLACKFIN, METAG.
    They were removed by commit 4ba66a976072 ("arch: remove blackfin port"),
    commit bb6fb6dfcc17 ("metag: Remove arch/metag/"), respectively.

    No more architecture enables CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX.
    Clean up the export.h headers. I am keeping VMLINUX_SYMBOL() and
    VMLINUX_SYMBOL_STR() because they are widely used.

    Signed-off-by: Masahiro Yamada
    Reviewed-by: Sam Ravnborg

    Masahiro Yamada
     

04 Feb, 2017

2 commits

  • The previous patch introduced a separate inline asm version of the
    krcrctab declaration template for use with 64-bit architectures, which
    cannot refer to ELF symbols using 32-bit quantities.

    This declaration should be equivalent to the C one for 32-bit
    architectures, but just in case - unify them in a separate patch, which
    can simply be dropped if it turns out to break anything.

    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Linus Torvalds

    Ard Biesheuvel
     
  • The modversion symbol CRCs are emitted as ELF symbols, which allows us
    to easily populate the kcrctab sections by relying on the linker to
    associate each kcrctab slot with the correct value.

    This has a couple of downsides:

    - Given that the CRCs are treated as memory addresses, we waste 4 bytes
    for each CRC on 64 bit architectures,

    - On architectures that support runtime relocation, a R__RELATIVE
    relocation entry is emitted for each CRC value, which identifies it
    as a quantity that requires fixing up based on the actual runtime
    load offset of the kernel. This results in corrupted CRCs unless we
    explicitly undo the fixup (and this is currently being handled in the
    core module code)

    - Such runtime relocation entries take up 24 bytes of __init space
    each, resulting in a x8 overhead in [uncompressed] kernel size for
    CRCs.

    Switching to explicit 32 bit values on 64 bit architectures fixes most
    of these issues, given that 32 bit values are not treated as quantities
    that require fixing up based on the actual runtime load offset. Note
    that on some ELF64 architectures [such as PPC64], these 32-bit values
    are still emitted as [absolute] runtime relocatable quantities, even if
    the value resolves to a build time constant. Since relative relocations
    are always resolved at build time, this patch enables MODULE_REL_CRCS on
    powerpc when CONFIG_RELOCATABLE=y, which turns the absolute CRC
    references into relative references into .rodata where the actual CRC
    value is stored.

    So redefine all CRC fields and variables as u32, and redefine the
    __CRC_SYMBOL() macro for 64 bit builds to emit the CRC reference using
    inline assembler (which is necessary since 64-bit C code cannot use
    32-bit types to hold memory addresses, even if they are ultimately
    resolved using values that do not exceed 0xffffffff). To avoid
    potential problems with legacy 32-bit architectures using legacy
    toolchains, the equivalent C definition of the kcrctab entry is retained
    for 32-bit architectures.

    Note that this mostly reverts commit d4703aefdbc8 ("module: handle ppc64
    relocating kcrctabs when CONFIG_RELOCATABLE=y")

    Acked-by: Rusty Russell
    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Linus Torvalds

    Ard Biesheuvel
     

15 Oct, 2016

1 commit

  • Pull kbuild updates from Michal Marek:

    - EXPORT_SYMBOL for asm source by Al Viro.

    This does bring a regression, because genksyms no longer generates
    checksums for these symbols (CONFIG_MODVERSIONS). Nick Piggin is
    working on a patch to fix this.

    Plus, we are talking about functions like strcpy(), which rarely
    change prototypes.

    - Fixes for PPC fallout of the above by Stephen Rothwell and Nick
    Piggin

    - fixdep speedup by Alexey Dobriyan.

    - preparatory work by Nick Piggin to allow architectures to build with
    -ffunction-sections, -fdata-sections and --gc-sections

    - CONFIG_THIN_ARCHIVES support by Stephen Rothwell

    - fix for filenames with colons in the initramfs source by me.

    * 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild: (22 commits)
    initramfs: Escape colons in depfile
    ppc: there is no clear_pages to export
    powerpc/64: whitelist unresolved modversions CRCs
    kbuild: -ffunction-sections fix for archs with conflicting sections
    kbuild: add arch specific post-link Makefile
    kbuild: allow archs to select link dead code/data elimination
    kbuild: allow architectures to use thin archives instead of ld -r
    kbuild: Regenerate genksyms lexer
    kbuild: genksyms fix for typeof handling
    fixdep: faster CONFIG_ search
    ia64: move exports to definitions
    sparc32: debride memcpy.S a bit
    [sparc] unify 32bit and 64bit string.h
    sparc: move exports to definitions
    ppc: move exports to definitions
    arm: move exports to definitions
    s390: move exports to definitions
    m68k: move exports to definitions
    alpha: move exports to actual definitions
    x86: move exports to actual definitions
    ...

    Linus Torvalds
     

12 Oct, 2016

1 commit

  • Kernel source files need not include explicitly
    because the top Makefile forces to include it with:

    -include $(srctree)/include/linux/kconfig.h

    This commit removes explicit includes except the following:

    * arch/s390/include/asm/facilities_src.h
    * tools/testing/radix-tree/linux/kernel.h

    These two are used for host programs.

    Link: http://lkml.kernel.org/r/1473656164-11929-1-git-send-email-yamada.masahiro@socionext.com
    Signed-off-by: Masahiro Yamada
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Masahiro Yamada
     

09 Sep, 2016

1 commit

  • Introduce LD_DEAD_CODE_DATA_ELIMINATION option for architectures to
    select to build with -ffunction-sections, -fdata-sections, and link
    with --gc-sections. It requires some work (documented) to ensure all
    unreferenced entrypoints are live, and requires toolchain and build
    verification, so it is made a per-arch option for now.

    On a random powerpc64le build, this yelds a significant size saving,
    it boots and runs fine, but there is a lot I haven't tested as yet, so
    these savings may be reduced if there are bugs in the link.

    text data bss dec filename
    11169741 1180744 1923176 14273661 vmlinux
    10445269 1004127 1919707 13369103 vmlinux.dce

    ~700K text, ~170K data, 6% removed from kernel image size.

    Signed-off-by: Nicholas Piggin
    Signed-off-by: Michal Marek

    Nicholas Piggin
     

21 Jun, 2016

1 commit


30 Mar, 2016

2 commits

  • Like with kconfig options, we now have the ability to compile in and
    out individual EXPORT_SYMBOL() declarations based on the content of
    include/generated/autoksyms.h. However we don't want the entire
    world to be rebuilt whenever that file is touched.

    Let's apply the same build dependency trick used for CONFIG_* symbols
    where the time stamp of empty files whose paths matching those symbols
    is used to trigger fine grained rebuilds. In our case the key is the
    symbol name passed to EXPORT_SYMBOL().

    However, unlike config options, we cannot just use fixdep to parse
    the source code for EXPORT_SYMBOL(ksym) because several variants exist
    and parsing them all in a separate tool, and keeping it in synch, is
    not trivially maintainable. Furthermore, there are variants such as

    EXPORT_SYMBOL_GPL(pci_user_read_config_##size);

    that are instanciated via a macro for which we can't easily determine
    the actual exported symbol name(s) short of actually running the
    preprocessor on them.

    Storing the symbol name string in a special ELF section doesn't work
    for targets that output assembly or preprocessed source.

    So the best way is really to leverage the preprocessor by having it
    output actual symbol names anchored by a special sequence that can be
    easily filtered out. Then the list of symbols is simply fed to fixdep
    to be merged with the other dependencies.

    That implies the preprocessor is executed twice for each source file.
    A previous attempt relied on a warning pragma for each EXPORT_SYMBOL()
    instance that was filtered apart from stderr by the build system with
    a sed script during the actual compilation pass. Unfortunately the
    preprocessor/compiler diagnostic output isn't stable between versions
    and this solution, although more efficient, was deemed too fragile.

    Because of the lowercasing performed by fixdep, there might be name
    collisions triggering spurious rebuilds for similar symbols. But this
    shouldn't be a big issue in practice. (This is the case for CONFIG_*
    symbols and I didn't want to be different here, whatever the original
    reason for doing so.)

    To avoid needless build overhead, the exported symbol name gathering is
    performed only when CONFIG_TRIM_UNUSED_KSYMS is selected.

    Signed-off-by: Nicolas Pitre
    Acked-by: Rusty Russell

    Nicolas Pitre
     
  • Similar to include/generated/autoconf.h, include/generated/autoksyms.h
    will contain a list of defines for each EXPORT_SYMBOL() that we want
    active. The format is:

    #define __KSYM_ 1

    This list will be auto-generated with another patch. For now we only
    include the preprocessor magic to automatically create or omit the
    corresponding struct kernel_symbol declaration.

    Given the content of include/generated/autoksyms.h may not be known in
    advance, an empty file is created early on to let the build proceed.

    Signed-off-by: Nicolas Pitre
    Acked-by: Rusty Russell

    Nicolas Pitre
     

16 Jan, 2014

1 commit

  • sparse complains about any __ksymtab symbols with the following:

    warning: symbol '__ksymtab_...' was not declared. Should it be static?

    due to Andi's patch making it non-static.

    Mollify sparse by declaring the symbol extern, otherwise we get
    drowned in sparse warnings for anything that uses EXPORT_SYMBOL
    in the sources, making it easy to miss real warnings.

    Fixes: e0f244c63fc9 ("asmlinkage, module: Make ksymtab [...] __visible")
    Signed-off-by: Johannes Berg
    Acked-by: Andi Kleen
    Signed-off-by: Rusty Russell

    Johannes Berg
     

29 Oct, 2013

1 commit


15 Mar, 2013

1 commit

  • We have CONFIG_SYMBOL_PREFIX, which three archs define to the string
    "_". But Al Viro broke this in "consolidate cond_syscall and
    SYSCALL_ALIAS declarations" (in linux-next), and he's not the first to
    do so.

    Using CONFIG_SYMBOL_PREFIX is awkward, since we usually just want to
    prefix it so something. So various places define helpers which are
    defined to nothing if CONFIG_SYMBOL_PREFIX isn't set:

    1) include/asm-generic/unistd.h defines __SYMBOL_PREFIX.
    2) include/asm-generic/vmlinux.lds.h defines VMLINUX_SYMBOL(sym)
    3) include/linux/export.h defines MODULE_SYMBOL_PREFIX.
    4) include/linux/kernel.h defines SYMBOL_PREFIX (which differs from #7)
    5) kernel/modsign_certificate.S defines ASM_SYMBOL(sym)
    6) scripts/modpost.c defines MODULE_SYMBOL_PREFIX
    7) scripts/Makefile.lib defines SYMBOL_PREFIX on the commandline if
    CONFIG_SYMBOL_PREFIX is set, so that we have a non-string version
    for pasting.

    (arch/h8300/include/asm/linkage.h defines SYMBOL_NAME(), too).

    Let's solve this properly:
    1) No more generic prefix, just CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX.
    2) Make linux/export.h usable from asm.
    3) Define VMLINUX_SYMBOL() and VMLINUX_SYMBOL_STR().
    4) Make everyone use them.

    Signed-off-by: Rusty Russell
    Reviewed-by: James Hogan
    Tested-by: James Hogan (metag)

    Rusty Russell
     

31 Oct, 2011

1 commit

  • A lot of files pull in module.h when all they are really
    looking for is the basic EXPORT_SYMBOL functionality. The
    recent data from Ingo[1] shows that this is one of several
    instances that has a significant impact on compile times,
    and it should be targeted for factoring out (as done here).

    Note that several commonly used header files in include/*
    directly include themselves (some 34 of them!)
    The most commonly used ones of these will have to be made
    independent of module.h before the full benefit of this change
    can be realized.

    We also transition THIS_MODULE from module.h to export.h,
    since there are lots of files with subsystem structs that
    in turn will have a struct module *owner and only be doing:

    .owner = THIS_MODULE;

    and absolutely nothing else modular. So, we also want to have
    the THIS_MODULE definition present in the lightweight header.

    [1] https://lkml.org/lkml/2011/5/23/76

    Signed-off-by: Paul Gortmaker

    Paul Gortmaker