Skip to content

Commit cca3e70

Browse files
kaysieversrustyrussell
authored andcommitted
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 <[email protected]> Signed-off-by: Kay Sievers <[email protected]> Signed-off-by: Rusty Russell <[email protected]>
1 parent 8487bfd commit cca3e70

File tree

2 files changed

+80
-29
lines changed

2 files changed

+80
-29
lines changed

Documentation/ABI/testing/sysfs-module

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,19 @@ Description: Maximum time allowed for periodic transfers per microframe (μs)
3333
Beware, non-standard modes are usually not thoroughly tested by
3434
hardware designers, and the hardware can malfunction when this
3535
setting differ from default 100.
36+
37+
What: /sys/module/*/{coresize,initsize}
38+
Date: Jan 2012
39+
KernelVersion:»·3.3
40+
Contact: Kay Sievers <[email protected]>
41+
Description: Module size in bytes.
42+
43+
What: /sys/module/*/taint
44+
Date: Jan 2012
45+
KernelVersion:»·3.3
46+
Contact: Kay Sievers <[email protected]>
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

kernel/module.c

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,26 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
842842
return ret;
843843
}
844844

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+
845865
static inline void print_unload_info(struct seq_file *m, struct module *mod)
846866
{
847867
struct module_use *use;
@@ -900,10 +920,8 @@ static ssize_t show_refcnt(struct module_attribute *mattr,
900920
return sprintf(buffer, "%lu\n", module_refcount(mk->mod));
901921
}
902922

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);
907925

908926
void module_put(struct module *module)
909927
{
@@ -963,10 +981,8 @@ static ssize_t show_initstate(struct module_attribute *mattr,
963981
return sprintf(buffer, "%s\n", state);
964982
}
965983

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);
970986

971987
static ssize_t store_uevent(struct module_attribute *mattr,
972988
struct module_kobject *mk,
@@ -979,18 +995,50 @@ static ssize_t store_uevent(struct module_attribute *mattr,
979995
return count;
980996
}
981997

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);
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);
9861031

9871032
static struct module_attribute *modinfo_attrs[] = {
1033+
&module_uevent,
9881034
&modinfo_version,
9891035
&modinfo_srcversion,
990-
&initstate,
991-
&module_uevent,
1036+
&modinfo_initstate,
1037+
&modinfo_coresize,
1038+
&modinfo_initsize,
1039+
&modinfo_taint,
9921040
#ifdef CONFIG_MODULE_UNLOAD
993-
&refcnt,
1041+
&modinfo_refcnt,
9941042
#endif
9951043
NULL,
9961044
};
@@ -3236,20 +3284,7 @@ static char *module_flags(struct module *mod, char *buf)
32363284
mod->state == MODULE_STATE_GOING ||
32373285
mod->state == MODULE_STATE_COMING) {
32383286
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);
32533288
/* Show a - for module-is-being-unloaded */
32543289
if (mod->state == MODULE_STATE_GOING)
32553290
buf[bx++] = '-';

0 commit comments

Comments
 (0)