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

modules: sysfs - export: taint, coresize, initsize

Recent tools do not want to use /proc to retrieve module information. A few
values are currently missing from sysfs to replace the information available
in /proc/modules.

This adds /sys/module/*/{coresize,initsize,taint} attributes.

TAINT_PROPRIETARY_MODULE (P) and TAINT_OOT_MODULE (O) flags are both always
shown now, and do no longer exclude each other, also in /proc/modules.

Replace the open-coded sysfs attribute initializers with the __ATTR() macro.

Add the new attributes to Documentation/ABI.

Cc: Lucas De Marchi <lucas.demarchi@profusion.mobi>
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

authored by

Kay Sievers and committed by
Rusty Russell
cca3e707 8487bfd9

+80 -29
+16
Documentation/ABI/testing/sysfs-module
··· 33 33 Beware, non-standard modes are usually not thoroughly tested by 34 34 hardware designers, and the hardware can malfunction when this 35 35 setting differ from default 100. 36 + 37 + What: /sys/module/*/{coresize,initsize} 38 + Date: Jan 2012 39 + KernelVersion:»·3.3 40 + Contact: Kay Sievers <kay.sievers@vrfy.org> 41 + Description: Module size in bytes. 42 + 43 + What: /sys/module/*/taint 44 + Date: Jan 2012 45 + KernelVersion:»·3.3 46 + Contact: Kay Sievers <kay.sievers@vrfy.org> 47 + Description: Module taint flags: 48 + P - proprietary module 49 + O - out-of-tree module 50 + F - force-loaded module 51 + C - staging driver module
+64 -29
kernel/module.c
··· 842 842 return ret; 843 843 } 844 844 845 + static size_t module_flags_taint(struct module *mod, char *buf) 846 + { 847 + size_t l = 0; 848 + 849 + if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE)) 850 + buf[l++] = 'P'; 851 + if (mod->taints & (1 << TAINT_OOT_MODULE)) 852 + buf[l++] = 'O'; 853 + if (mod->taints & (1 << TAINT_FORCED_MODULE)) 854 + buf[l++] = 'F'; 855 + if (mod->taints & (1 << TAINT_CRAP)) 856 + buf[l++] = 'C'; 857 + /* 858 + * TAINT_FORCED_RMMOD: could be added. 859 + * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't 860 + * apply to modules. 861 + */ 862 + return l; 863 + } 864 + 845 865 static inline void print_unload_info(struct seq_file *m, struct module *mod) 846 866 { 847 867 struct module_use *use; ··· 920 900 return sprintf(buffer, "%lu\n", module_refcount(mk->mod)); 921 901 } 922 902 923 - static struct module_attribute refcnt = { 924 - .attr = { .name = "refcnt", .mode = 0444 }, 925 - .show = show_refcnt, 926 - }; 903 + static struct module_attribute modinfo_refcnt = 904 + __ATTR(refcnt, 0444, show_refcnt, NULL); 927 905 928 906 void module_put(struct module *module) 929 907 { ··· 981 963 return sprintf(buffer, "%s\n", state); 982 964 } 983 965 984 - static struct module_attribute initstate = { 985 - .attr = { .name = "initstate", .mode = 0444 }, 986 - .show = show_initstate, 987 - }; 966 + static struct module_attribute modinfo_initstate = 967 + __ATTR(initstate, 0444, show_initstate, NULL); 988 968 989 969 static ssize_t store_uevent(struct module_attribute *mattr, 990 970 struct module_kobject *mk, ··· 995 979 return count; 996 980 } 997 981 998 - struct module_attribute module_uevent = { 999 - .attr = { .name = "uevent", .mode = 0200 }, 1000 - .store = store_uevent, 1001 - }; 982 + struct module_attribute module_uevent = 983 + __ATTR(uevent, 0200, NULL, store_uevent); 984 + 985 + static ssize_t show_coresize(struct module_attribute *mattr, 986 + struct module_kobject *mk, char *buffer) 987 + { 988 + return sprintf(buffer, "%u\n", mk->mod->core_size); 989 + } 990 + 991 + static struct module_attribute modinfo_coresize = 992 + __ATTR(coresize, 0444, show_coresize, NULL); 993 + 994 + static ssize_t show_initsize(struct module_attribute *mattr, 995 + struct module_kobject *mk, char *buffer) 996 + { 997 + return sprintf(buffer, "%u\n", mk->mod->init_size); 998 + } 999 + 1000 + static struct module_attribute modinfo_initsize = 1001 + __ATTR(initsize, 0444, show_initsize, NULL); 1002 + 1003 + static ssize_t show_taint(struct module_attribute *mattr, 1004 + struct module_kobject *mk, char *buffer) 1005 + { 1006 + size_t l; 1007 + 1008 + l = module_flags_taint(mk->mod, buffer); 1009 + buffer[l++] = '\n'; 1010 + return l; 1011 + } 1012 + 1013 + static struct module_attribute modinfo_taint = 1014 + __ATTR(taint, 0444, show_taint, NULL); 1002 1015 1003 1016 static struct module_attribute *modinfo_attrs[] = { 1017 + &module_uevent, 1004 1018 &modinfo_version, 1005 1019 &modinfo_srcversion, 1006 - &initstate, 1007 - &module_uevent, 1020 + &modinfo_initstate, 1021 + &modinfo_coresize, 1022 + &modinfo_initsize, 1023 + &modinfo_taint, 1008 1024 #ifdef CONFIG_MODULE_UNLOAD 1009 - &refcnt, 1025 + &modinfo_refcnt, 1010 1026 #endif 1011 1027 NULL, 1012 1028 }; ··· 3284 3236 mod->state == MODULE_STATE_GOING || 3285 3237 mod->state == MODULE_STATE_COMING) { 3286 3238 buf[bx++] = '('; 3287 - if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE)) 3288 - buf[bx++] = 'P'; 3289 - else if (mod->taints & (1 << TAINT_OOT_MODULE)) 3290 - buf[bx++] = 'O'; 3291 - if (mod->taints & (1 << TAINT_FORCED_MODULE)) 3292 - buf[bx++] = 'F'; 3293 - if (mod->taints & (1 << TAINT_CRAP)) 3294 - buf[bx++] = 'C'; 3295 - /* 3296 - * TAINT_FORCED_RMMOD: could be added. 3297 - * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't 3298 - * apply to modules. 3299 - */ 3300 - 3239 + bx += module_flags_taint(mod, buf + bx); 3301 3240 /* Show a - for module-is-being-unloaded */ 3302 3241 if (mod->state == MODULE_STATE_GOING) 3303 3242 buf[bx++] = '-';