Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

module: Provide EXPORT_SYMBOL_GPL_FOR_MODULES() helper

Helper macro to more easily limit the export of a symbol to a given
list of modules.

Eg:

EXPORT_SYMBOL_GPL_FOR_MODULES(preempt_notifier_inc, "kvm");

will limit the use of said function to kvm.ko, any other module trying
to use this symbol will refure to load (and get modpost build
failures).

Requested-by: Masahiro Yamada <masahiroy@kernel.org>
Requested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

authored by

Peter Zijlstra and committed by
Masahiro Yamada
707f853d 0267cbf2

+32 -2
+22
Documentation/core-api/symbol-namespaces.rst
··· 28 28 are required to import the namespace. Otherwise the kernel will, depending on 29 29 its configuration, reject loading the module or warn about a missing import. 30 30 31 + Additionally, it is possible to put symbols into a module namespace, strictly 32 + limiting which modules are allowed to use these symbols. 33 + 31 34 2. How to define Symbol Namespaces 32 35 ================================== 33 36 ··· 85 82 86 83 within the corresponding compilation unit before the #include for 87 84 <linux/export.h>. Typically it's placed before the first #include statement. 85 + 86 + 2.3 Using the EXPORT_SYMBOL_GPL_FOR_MODULES() macro 87 + =================================================== 88 + 89 + Symbols exported using this macro are put into a module namespace. This 90 + namespace cannot be imported. 91 + 92 + The macro takes a comma separated list of module names, allowing only those 93 + modules to access this symbol. Simple tail-globs are supported. 94 + 95 + For example: 96 + 97 + EXPORT_SYMBOL_GPL_FOR_MODULES(preempt_notifier_inc, "kvm,kvm-*") 98 + 99 + will limit usage of this symbol to modules whoes name matches the given 100 + patterns. 88 101 89 102 3. How to use Symbols exported in Namespaces 90 103 ============================================ ··· 173 154 You can also run nsdeps for external module builds. A typical usage is:: 174 155 175 156 $ make -C <path_to_kernel_src> M=$PWD nsdeps 157 + 158 + Note: it will happily generate an import statement for the module namespace; 159 + which will not work and generates build and runtime failures.
+10 -2
include/linux/export.h
··· 24 24 .long sym 25 25 #endif 26 26 27 - #define ___EXPORT_SYMBOL(sym, license, ns) \ 27 + /* 28 + * LLVM integrated assembler cam merge adjacent string literals (like 29 + * C and GNU-as) passed to '.ascii', but not to '.asciz' and chokes on: 30 + * 31 + * .asciz "MODULE_" "kvm" ; 32 + */ 33 + #define ___EXPORT_SYMBOL(sym, license, ns...) \ 28 34 .section ".export_symbol","a" ASM_NL \ 29 35 __export_symbol_##sym: ASM_NL \ 30 36 .asciz license ASM_NL \ 31 - .asciz ns ASM_NL \ 37 + .ascii ns "\0" ASM_NL \ 32 38 __EXPORT_SYMBOL_REF(sym) ASM_NL \ 33 39 .previous 34 40 ··· 90 84 #define EXPORT_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "GPL") 91 85 #define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym, "", ns) 92 86 #define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "GPL", ns) 87 + 88 + #define EXPORT_SYMBOL_GPL_FOR_MODULES(sym, mods) __EXPORT_SYMBOL(sym, "GPL", "module:" mods) 93 89 94 90 #endif /* _LINUX_EXPORT_H */