Safe registration of procfs entries in LKM

Torin Carey torin at
Thu Feb 24 09:12:57 EST 2022


I was wondering how a loadable (and specifically unloadable) kernel
module can safely provide a procfs entry.

The procfs code switched from `struct file_operations`, which has a
`struct module *owner` member to using `struct proc_ops`, which doesn't.
This member allowed the core code to `try_module_get()` the module
before calling the operation, so that we can avoid calling it if the
module is in the process of being removed and increase the module use
count to prevent the module from being unloaded while the open file
description exists.  The procfs code did previously use
`struct file_operations`, but it looks like it didn't honour this member

Does this mean procfs is not meant for loadable modules?


More information about the Kernelnewbies mailing list