Merge tag 'modules-for-v5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 22 Sep 2019 17:34:46 +0000 (10:34 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 22 Sep 2019 17:34:46 +0000 (10:34 -0700)
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

1  2 
.gitignore
MAINTAINERS
Makefile
drivers/usb/storage/isd200.c
include/linux/export.h
init/Kconfig
scripts/Makefile.modpost
scripts/mod/modpost.c

diff --cc .gitignore
index ce2c6348d372d0405bab6a47d33d5051d66b379a,9ee63aa2a3fbf53d0534a110f04b8e913dd92078..70580bdd352ccfc5b30ce42c378da860fcfaaccd
  *.lzo
  *.mod
  *.mod.c
+ *.ns_deps
  *.o
  *.o.*
 -*.order
  *.patch
  *.s
  *.so
diff --cc MAINTAINERS
Simple merge
diff --cc Makefile
Simple merge
Simple merge
index 7d8c112a8b61b6423fab5248cab1f0dd7d4b3e73,ef5d015d754a6f2a6ecdb3dcce0676b7cf5e59cc..95f55b7f83a0a28a67898e441c959ae05b32e24f
@@@ -18,6 -18,11 +18,8 @@@ extern struct module __this_module
  #define THIS_MODULE ((struct module *)0)
  #endif
  
 -#ifdef CONFIG_MODULES
 -
+ #define NS_SEPARATOR "."
 -#if defined(__KERNEL__) && !defined(__GENKSYMS__)
  #ifdef CONFIG_MODVERSIONS
  /* Mark the CRC weak since genksyms apparently decides not to
   * generate a checksums for some symbols */
@@@ -71,24 -98,26 +95,35 @@@ struct kernel_symbol 
  };
  #endif
  
- #define ___EXPORT_SYMBOL(sym, sec)    __GENKSYMS_EXPORT_SYMBOL(sym)
 +#ifdef __GENKSYMS__
 +
- /* For every exported symbol, place a struct in the __ksymtab section */
- #define ___EXPORT_SYMBOL(sym, sec)                                    \
++#define ___EXPORT_SYMBOL(sym,sec)     __GENKSYMS_EXPORT_SYMBOL(sym)
++#define ___EXPORT_SYMBOL_NS(sym,sec,ns)       __GENKSYMS_EXPORT_SYMBOL(sym)
 +
 +#else
 +
+ #define ___export_symbol_common(sym, sec)                             \
        extern typeof(sym) sym;                                         \
-       __CRC_SYMBOL(sym, sec)                                          \
+       __CRC_SYMBOL(sym, sec);                                         \
        static const char __kstrtab_##sym[]                             \
        __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
-       = #sym;                                                         \
+       = #sym                                                          \
+ /* For every exported symbol, place a struct in the __ksymtab section */
+ #define ___EXPORT_SYMBOL_NS(sym, sec, ns)                             \
+       ___export_symbol_common(sym, sec);                              \
+       static const char __kstrtab_ns_##sym[]                          \
+       __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
+       = #ns;                                                          \
+       __KSYMTAB_ENTRY_NS(sym, sec, ns)
+ #define ___EXPORT_SYMBOL(sym, sec)                                    \
+       ___export_symbol_common(sym, sec);                              \
        __KSYMTAB_ENTRY(sym, sec)
  
 -#if defined(__DISABLE_EXPORTS)
 +#endif
 +
 +#if !defined(CONFIG_MODULES) || defined(__DISABLE_EXPORTS)
  
  /*
   * Allow symbol exports to be disabled completely so that C code may
  #define __cond_export_sym_1(sym, sec) ___EXPORT_SYMBOL(sym, sec)
  #define __cond_export_sym_0(sym, sec) /* nothing */
  
+ #define __EXPORT_SYMBOL_NS(sym, sec, ns)                              \
+       __ksym_marker(sym);                                             \
+       __cond_export_ns_sym(sym, sec, ns, __is_defined(__KSYM_##sym))
+ #define __cond_export_ns_sym(sym, sec, ns, conf)                      \
+       ___cond_export_ns_sym(sym, sec, ns, conf)
+ #define ___cond_export_ns_sym(sym, sec, ns, enabled)                  \
+       __cond_export_ns_sym_##enabled(sym, sec, ns)
+ #define __cond_export_ns_sym_1(sym, sec, ns) ___EXPORT_SYMBOL_NS(sym, sec, ns)
+ #define __cond_export_ns_sym_0(sym, sec, ns) /* nothing */
  #else
 -#define __EXPORT_SYMBOL_NS ___EXPORT_SYMBOL_NS
 -#define __EXPORT_SYMBOL ___EXPORT_SYMBOL
 -#endif
 +
- #define __EXPORT_SYMBOL(sym, sec)     ___EXPORT_SYMBOL(sym, sec)
++#define __EXPORT_SYMBOL_NS(sym,sec,ns)        ___EXPORT_SYMBOL_NS(sym,sec,ns)
++#define __EXPORT_SYMBOL(sym,sec)      ___EXPORT_SYMBOL(sym,sec)
 +
 +#endif /* CONFIG_MODULES */
  
 -#define EXPORT_SYMBOL(sym) __EXPORT_SYMBOL(sym, "")
 -#define EXPORT_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_gpl")
 -#define EXPORT_SYMBOL_GPL_FUTURE(sym) __EXPORT_SYMBOL(sym, "_gpl_future")
 -#define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL_NS(sym, "", ns)
 -#define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL_NS(sym, "_gpl", ns)
+ #ifdef DEFAULT_SYMBOL_NAMESPACE
+ #undef __EXPORT_SYMBOL
+ #define __EXPORT_SYMBOL(sym, sec)                             \
+       __EXPORT_SYMBOL_NS(sym, sec, DEFAULT_SYMBOL_NAMESPACE)
+ #endif
 +#define EXPORT_SYMBOL(sym)            __EXPORT_SYMBOL(sym, "")
 +#define EXPORT_SYMBOL_GPL(sym)                __EXPORT_SYMBOL(sym, "_gpl")
 +#define EXPORT_SYMBOL_GPL_FUTURE(sym) __EXPORT_SYMBOL(sym, "_gpl_future")
++#define EXPORT_SYMBOL_NS(sym, ns)     __EXPORT_SYMBOL_NS(sym, "", ns)
++#define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL_NS(sym, "_gpl", ns)
  #ifdef CONFIG_UNUSED_SYMBOLS
 -#define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
 -#define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
 +#define EXPORT_UNUSED_SYMBOL(sym)     __EXPORT_SYMBOL(sym, "_unused")
 +#define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
  #else
  #define EXPORT_UNUSED_SYMBOL(sym)
  #define EXPORT_UNUSED_SYMBOL_GPL(sym)
diff --cc init/Kconfig
Simple merge
index 9800a3988f23e7eafd0a47ed0cc2f3d0abe51249,743fe3a2e885f25a9db7987f1c4911e132dec86b..952fff4855467fb9cadeea2c767ffe902f9e9c0e
@@@ -88,13 -99,60 +89,15 @@@ modules := $(sort $(shell cat $(MODORDE
  quiet_cmd_modpost = MODPOST $(words $(modules)) modules
        cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST)
  
 -PHONY += modules-modpost
 -modules-modpost:
 +__modpost:
 +      @$(kecho) '  Building modules, stage 2.'
        $(call cmd,modpost)
 -
 -# Declare generated files as targets for modpost
 -$(modules:.ko=.mod.c): modules-modpost
 -
 -# Step 5), compile all *.mod.c files
 -
 -# modname is set to make c_flags define KBUILD_MODNAME
 -modname = $(notdir $(@:.mod.o=))
 -
 -quiet_cmd_cc_o_c = CC      $@
 -      cmd_cc_o_c = $(CC) $(c_flags) $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE) \
 -                 -c -o $@ $<
 -
 -$(modules:.ko=.mod.o): %.mod.o: %.mod.c FORCE
 -      $(call if_changed_dep,cc_o_c)
 -
 -targets += $(modules:.ko=.mod.o)
 -
 -ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
 -
 -# Step 6), final link of the modules with optional arch pass after final link
 -quiet_cmd_ld_ko_o = LD [M]  $@
 -      cmd_ld_ko_o =                                                     \
 -      $(LD) -r $(KBUILD_LDFLAGS)                                      \
 -                 $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE)             \
 -                 -o $@ $(real-prereqs) ;                                \
 -      $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 -
 -$(modules): %.ko :%.o %.mod.o FORCE
 -      +$(call if_changed,ld_ko_o)
 -
 -targets += $(modules)
 +ifneq ($(KBUILD_MODPOST_NOFINAL),1)
 +      $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
 +endif
  
 -# Add FORCE to the prequisites of a target to force it to be always rebuilt.
 -# ---------------------------------------------------------------------------
 -
 -PHONY += FORCE
 -
 -FORCE:
 -
 -# Read all saved command lines and dependencies for the $(targets) we
 -# may be building above, using $(if_changed{,_dep}). As an
 -# optimization, we don't need to read them if the target does not
 -# exist, we will rebuild anyway in that case.
 -
 -existing-targets := $(wildcard $(sort $(targets)))
 -
 --include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
 -
+ nsdeps: __modpost
  endif
  
  .PHONY: $(PHONY)
index 820eed87fb43bf443a7e3ef801b384600c93793d,be72da25fe7caa0395fbc18209aee7a3755dd4fc..3961941e8e7a9c95062bde8983c88efd001dba6d
@@@ -2379,10 -2440,10 +2453,11 @@@ static void read_dump(const char *fname
                        mod = new_module(modname);
                        mod->skip = 1;
                }
-               s = sym_add_exported(symname, mod, export_no(export));
+               s = sym_add_exported(symname, namespace, mod,
+                                    export_no(export));
                s->kernel    = kernel;
                s->preloaded = 1;
 +              s->is_static = 0;
                sym_update_crc(symname, mod, crc, export_no(export));
        }
        release_file(file, size);