From b6d0531ec7e2ae923395a1d5a80edb7ee51ac204 Mon Sep 17 00:00:00 2001 From: Fabien Dessenne Date: Mon, 2 Dec 2019 10:01:17 +0100 Subject: moduleparam: fix kerneldoc Document missing @arg in xxx_param_cb(). Describe all parameters of module_param_[named_]unsafe() and all *_param_cb() to make ./scripts/kernel-doc happy. Acked-by: Randy Dunlap Tested-by: Randy Dunlap Signed-off-by: Fabien Dessenne Signed-off-by: Jessica Yu --- include/linux/moduleparam.h | 82 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h index e5c3e23919b8..3ef917ff0964 100644 --- a/include/linux/moduleparam.h +++ b/include/linux/moduleparam.h @@ -128,6 +128,9 @@ struct kparam_array /** * module_param_unsafe - same as module_param but taints kernel + * @name: the variable to alter, and exposed parameter name. + * @type: the type of the parameter + * @perm: visibility in sysfs. */ #define module_param_unsafe(name, type, perm) \ module_param_named_unsafe(name, name, type, perm) @@ -150,6 +153,10 @@ struct kparam_array /** * module_param_named_unsafe - same as module_param_named but taints kernel + * @name: a valid C identifier which is the parameter name. + * @value: the actual lvalue to alter. + * @type: the type of the parameter + * @perm: visibility in sysfs. */ #define module_param_named_unsafe(name, value, type, perm) \ param_check_##type(name, &(value)); \ @@ -160,6 +167,7 @@ struct kparam_array * module_param_cb - general callback for a module/cmdline parameter * @name: a valid C identifier which is the parameter name. * @ops: the set & get operations for this parameter. + * @arg: args for @ops * @perm: visibility in sysfs. * * The ops can have NULL set or get functions. @@ -171,36 +179,96 @@ struct kparam_array __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, \ KERNEL_PARAM_FL_UNSAFE) +#define __level_param_cb(name, ops, arg, perm, level) \ + __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0) /** - * _param_cb - general callback for a module/cmdline parameter - * to be evaluated before certain initcall level + * core_param_cb - general callback for a module/cmdline parameter + * to be evaluated before core initcall level * @name: a valid C identifier which is the parameter name. * @ops: the set & get operations for this parameter. + * @arg: args for @ops * @perm: visibility in sysfs. * * The ops can have NULL set or get functions. */ -#define __level_param_cb(name, ops, arg, perm, level) \ - __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0) - #define core_param_cb(name, ops, arg, perm) \ __level_param_cb(name, ops, arg, perm, 1) +/** + * postcore_param_cb - general callback for a module/cmdline parameter + * to be evaluated before postcore initcall level + * @name: a valid C identifier which is the parameter name. + * @ops: the set & get operations for this parameter. + * @arg: args for @ops + * @perm: visibility in sysfs. + * + * The ops can have NULL set or get functions. + */ #define postcore_param_cb(name, ops, arg, perm) \ __level_param_cb(name, ops, arg, perm, 2) +/** + * arch_param_cb - general callback for a module/cmdline parameter + * to be evaluated before arch initcall level + * @name: a valid C identifier which is the parameter name. + * @ops: the set & get operations for this parameter. + * @arg: args for @ops + * @perm: visibility in sysfs. + * + * The ops can have NULL set or get functions. + */ #define arch_param_cb(name, ops, arg, perm) \ __level_param_cb(name, ops, arg, perm, 3) +/** + * subsys_param_cb - general callback for a module/cmdline parameter + * to be evaluated before subsys initcall level + * @name: a valid C identifier which is the parameter name. + * @ops: the set & get operations for this parameter. + * @arg: args for @ops + * @perm: visibility in sysfs. + * + * The ops can have NULL set or get functions. + */ #define subsys_param_cb(name, ops, arg, perm) \ __level_param_cb(name, ops, arg, perm, 4) +/** + * fs_param_cb - general callback for a module/cmdline parameter + * to be evaluated before fs initcall level + * @name: a valid C identifier which is the parameter name. + * @ops: the set & get operations for this parameter. + * @arg: args for @ops + * @perm: visibility in sysfs. + * + * The ops can have NULL set or get functions. + */ #define fs_param_cb(name, ops, arg, perm) \ __level_param_cb(name, ops, arg, perm, 5) +/** + * device_param_cb - general callback for a module/cmdline parameter + * to be evaluated before device initcall level + * @name: a valid C identifier which is the parameter name. + * @ops: the set & get operations for this parameter. + * @arg: args for @ops + * @perm: visibility in sysfs. + * + * The ops can have NULL set or get functions. + */ #define device_param_cb(name, ops, arg, perm) \ __level_param_cb(name, ops, arg, perm, 6) +/** + * late_param_cb - general callback for a module/cmdline parameter + * to be evaluated before late initcall level + * @name: a valid C identifier which is the parameter name. + * @ops: the set & get operations for this parameter. + * @arg: args for @ops + * @perm: visibility in sysfs. + * + * The ops can have NULL set or get functions. + */ #define late_param_cb(name, ops, arg, perm) \ __level_param_cb(name, ops, arg, perm, 7) @@ -263,6 +331,10 @@ static inline void kernel_param_unlock(struct module *mod) /** * core_param_unsafe - same as core_param but taints kernel + * @name: the name of the cmdline and sysfs parameter (often the same as var) + * @var: the variable + * @type: the type of the parameter + * @perm: visibility in sysfs */ #define core_param_unsafe(name, var, type, perm) \ param_check_##type(name, &(var)); \ -- cgit v1.2.3 From ce2b617ce8cbb7ba7a956299061bbc784131333c Mon Sep 17 00:00:00 2001 From: Jessica Yu Date: Tue, 12 Nov 2019 12:35:59 +0100 Subject: export.h: reduce __ksymtab_strings string duplication by using "MS" section flags 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 --- include/asm-generic/export.h | 8 +++++--- include/linux/export.h | 33 +++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h index afddc5442e92..365345f9a9e3 100644 --- a/include/asm-generic/export.h +++ b/include/asm-generic/export.h @@ -27,9 +27,11 @@ .endm /* - * note on .section use: @progbits vs %progbits nastiness doesn't matter, - * since we immediately emit into those sections anyway. + * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE) + * section flag requires it. Use '%progbits' instead of '@progbits' since the + * former apparently works on all arches according to the binutils source. */ + .macro ___EXPORT_SYMBOL name,val,sec #ifdef CONFIG_MODULES .section ___ksymtab\sec+\name,"a" @@ -37,7 +39,7 @@ __ksymtab_\name: __put \val, __kstrtab_\name .previous - .section __ksymtab_strings,"a" + .section __ksymtab_strings,"aMS",%progbits,1 __kstrtab_\name: .asciz "\name" .previous diff --git a/include/linux/export.h b/include/linux/export.h index 627841448293..fceb5e855717 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -82,16 +82,29 @@ struct kernel_symbol { #else -/* For every exported symbol, place a struct in the __ksymtab section */ -#define ___EXPORT_SYMBOL(sym, sec, ns) \ - extern typeof(sym) sym; \ - __CRC_SYMBOL(sym, sec); \ - static const char __kstrtab_##sym[] \ - __attribute__((section("__ksymtab_strings"), used, aligned(1))) \ - = #sym; \ - static const char __kstrtabns_##sym[] \ - __attribute__((section("__ksymtab_strings"), used, aligned(1))) \ - = ns; \ +/* + * For every exported symbol, do the following: + * + * - If applicable, place a CRC entry in the __kcrctab section. + * - Put the name of the symbol and namespace (empty string "" for none) in + * __ksymtab_strings. + * - Place a struct kernel_symbol entry in the __ksymtab section. + * + * note on .section use: we specify progbits since usage of the "M" (SHF_MERGE) + * section flag requires it. Use '%progbits' instead of '@progbits' since the + * former apparently works on all arches according to the binutils source. + */ +#define ___EXPORT_SYMBOL(sym, sec, ns) \ + extern typeof(sym) sym; \ + extern const char __kstrtab_##sym[]; \ + extern const char __kstrtabns_##sym[]; \ + __CRC_SYMBOL(sym, sec); \ + asm(" .section \"__ksymtab_strings\",\"aMS\",%progbits,1 \n" \ + "__kstrtab_" #sym ": \n" \ + " .asciz \"" #sym "\" \n" \ + "__kstrtabns_" #sym ": \n" \ + " .asciz \"" ns "\" \n" \ + " .previous \n"); \ __KSYMTAB_ENTRY(sym, sec) #endif -- cgit v1.2.3 From 6080d608eeff7cb5090a2ddbaf723bfb0ff133fc Mon Sep 17 00:00:00 2001 From: Madhuparna Bhowmik Date: Wed, 22 Jan 2020 22:34:47 +0530 Subject: module.h: Annotate mod_kallsyms with __rcu This patch fixes the following sparse errors: kernel/module.c:3623:9: error: incompatible types in comparison expression kernel/module.c:4060:41: error: incompatible types in comparison expression kernel/module.c:4203:28: error: incompatible types in comparison expression kernel/module.c:4225:41: error: incompatible types in comparison expression Signed-off-by: Madhuparna Bhowmik Signed-off-by: Jessica Yu --- include/linux/module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/module.h b/include/linux/module.h index bd165ba68617..dfdc8863e26a 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -429,7 +429,7 @@ struct module { #ifdef CONFIG_KALLSYMS /* Protected by RCU and/or module_mutex: use rcu_dereference() */ - struct mod_kallsyms *kallsyms; + struct mod_kallsyms __rcu *kallsyms; struct mod_kallsyms core_kallsyms; /* Section attributes */ -- cgit v1.2.3