Commit cca3e707301862ca9b9327e6a732463982f8cd1b

Authored by Kay Sievers
Committed by Rusty Russell
1 parent 8487bfd954

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>

Showing 2 changed files with 80 additions and 29 deletions Side-by-side Diff

Documentation/ABI/testing/sysfs-module
... ... @@ -33,4 +33,20 @@
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
... ... @@ -842,6 +842,26 @@
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;
... ... @@ -900,10 +920,8 @@
900 920 return sprintf(buffer, "%lu\n", module_refcount(mk->mod));
901 921 }
902 922  
903   -static struct module_attribute refcnt = {
904   - .attr = { .name = "refcnt", .mode = 0444 },
905   - .show = show_refcnt,
906   -};
  923 +static struct module_attribute modinfo_refcnt =
  924 + __ATTR(refcnt, 0444, show_refcnt, NULL);
907 925  
908 926 void module_put(struct module *module)
909 927 {
... ... @@ -963,10 +981,8 @@
963 981 return sprintf(buffer, "%s\n", state);
964 982 }
965 983  
966   -static struct module_attribute initstate = {
967   - .attr = { .name = "initstate", .mode = 0444 },
968   - .show = show_initstate,
969   -};
  984 +static struct module_attribute modinfo_initstate =
  985 + __ATTR(initstate, 0444, show_initstate, NULL);
970 986  
971 987 static ssize_t store_uevent(struct module_attribute *mattr,
972 988 struct module_kobject *mk,
973 989  
974 990  
975 991  
976 992  
... ... @@ -979,18 +995,50 @@
979 995 return count;
980 996 }
981 997  
982   -struct module_attribute module_uevent = {
983   - .attr = { .name = "uevent", .mode = 0200 },
984   - .store = store_uevent,
985   -};
  998 +struct module_attribute module_uevent =
  999 + __ATTR(uevent, 0200, NULL, store_uevent);
986 1000  
  1001 +static ssize_t show_coresize(struct module_attribute *mattr,
  1002 + struct module_kobject *mk, char *buffer)
  1003 +{
  1004 + return sprintf(buffer, "%u\n", mk->mod->core_size);
  1005 +}
  1006 +
  1007 +static struct module_attribute modinfo_coresize =
  1008 + __ATTR(coresize, 0444, show_coresize, NULL);
  1009 +
  1010 +static ssize_t show_initsize(struct module_attribute *mattr,
  1011 + struct module_kobject *mk, char *buffer)
  1012 +{
  1013 + return sprintf(buffer, "%u\n", mk->mod->init_size);
  1014 +}
  1015 +
  1016 +static struct module_attribute modinfo_initsize =
  1017 + __ATTR(initsize, 0444, show_initsize, NULL);
  1018 +
  1019 +static ssize_t show_taint(struct module_attribute *mattr,
  1020 + struct module_kobject *mk, char *buffer)
  1021 +{
  1022 + size_t l;
  1023 +
  1024 + l = module_flags_taint(mk->mod, buffer);
  1025 + buffer[l++] = '\n';
  1026 + return l;
  1027 +}
  1028 +
  1029 +static struct module_attribute modinfo_taint =
  1030 + __ATTR(taint, 0444, show_taint, NULL);
  1031 +
987 1032 static struct module_attribute *modinfo_attrs[] = {
  1033 + &module_uevent,
988 1034 &modinfo_version,
989 1035 &modinfo_srcversion,
990   - &initstate,
991   - &module_uevent,
  1036 + &modinfo_initstate,
  1037 + &modinfo_coresize,
  1038 + &modinfo_initsize,
  1039 + &modinfo_taint,
992 1040 #ifdef CONFIG_MODULE_UNLOAD
993   - &refcnt,
  1041 + &modinfo_refcnt,
994 1042 #endif
995 1043 NULL,
996 1044 };
... ... @@ -3236,20 +3284,7 @@
3236 3284 mod->state == MODULE_STATE_GOING ||
3237 3285 mod->state == MODULE_STATE_COMING) {
3238 3286 buf[bx++] = '(';
3239   - if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE))
3240   - buf[bx++] = 'P';
3241   - else if (mod->taints & (1 << TAINT_OOT_MODULE))
3242   - buf[bx++] = 'O';
3243   - if (mod->taints & (1 << TAINT_FORCED_MODULE))
3244   - buf[bx++] = 'F';
3245   - if (mod->taints & (1 << TAINT_CRAP))
3246   - buf[bx++] = 'C';
3247   - /*
3248   - * TAINT_FORCED_RMMOD: could be added.
3249   - * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
3250   - * apply to modules.
3251   - */
3252   -
  3287 + bx += module_flags_taint(mod, buf + bx);
3253 3288 /* Show a - for module-is-being-unloaded */
3254 3289 if (mod->state == MODULE_STATE_GOING)
3255 3290 buf[bx++] = '-';