3

Many of my modules are missing /sys/module/*/parameters directory and I can't check the module loaded parameters.

# printf "%s\n" /sys/module/*/parameters | wc -l
125
# lsmod | wc -l
151
# comm -13 <(printf "%s\n" /sys/module/*/parameters | xargs dirname | xargs basename -a | sort) <(lsmod | awk '{print $1}' | sort) | fmt
Module aesni_intel at24 blake2b_generic bpf_preload btbcm btintel
btmtk btrfs btrtl crc16 crc32_pclmul crc32c_generic crc32c_intel
crct10dif_pclmul cryptd crypto_simd crypto_user dummy ecdh_generic fat
gf128mul ghash_clmulni_intel i2c_smbus iTCO_vendor_support iTCO_wdt
intel_cstate intel_pmc_bxt intel_rapl_common intel_rapl_msr intel_uncore
ip6_tables ip6t_REJECT ip6table_filter ip6table_mangle ip6table_nat
ip6table_raw ip_tables ipt_REJECT iptable_filter iptable_mangle
iptable_nat iptable_raw irqbypass joydev ledtrig_audio libcrc32c lpc_ich
mac_hid mei mei_hdcp mei_me mei_pxp mei_wdt nf_conntrack_broadcast
nf_conntrack_netlink nf_conntrack_pptp nf_defrag_ipv4 nf_defrag_ipv6
nf_log_syslog nf_nat nf_nat_amanda nf_nat_ftp nf_nat_h323 nf_nat_irc
nf_nat_pptp nf_nat_sip nf_nat_snmp_basic nf_nat_tftp nf_reject_ipv4
nf_reject_ipv6 nfnetlink nfnetlink_log nvidia nvme_common parport
polyval_clmulni polyval_generic ppdev raid6_pq rapl sha512_ssse3
snd_hda_codec_conexant snd_hda_codec_generic snd_hda_core snd_hwdep ts_kmp
tun uas vboxnetadp vboxnetflt vfat vmd x_tables xhci_pci xhci_pci_renesas
xor xt_CT xt_LOG xt_NFLOG xt_addrtype xt_comment xt_conntrack xt_hashlimit
xt_mark xt_multiport xt_tcpudp

Most notably I was interested in:

# lsmod | grep nvidia
nvidia_drm             77824  20
nvidia_modeset       1515520  40 nvidia_drm
nvidia_uvm           2891776  0
video                  69632  1 nvidia_modeset
nvidia              61472768  2179 nvidia_uvm,nvidia_modeset
# ls /sys/module/nvidia/parameters
ls: cannot access '/sys/module/nvidia/parameters': No such file or directory

But also dummy doesn't have parameters, which cmon, it's a dummy:

# modprobe dummy numdummies=12
# lsmod | grep dummy
dummy                  16384  0
root@leonidas /root
# ls /sys/module/dummy/parameters
ls: cannot access '/sys/module/dummy/parameters': No such file or directory
# ip a | grep dummy | wc -l
12

I found https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1774731 about also missing dummy/parameters directory.

How to enable that directory so that I can get kernel module parameters?

0

1 Answer 1

8

In order for modules to have their parameters visible in /sys/module/*/parameters, the module needs to provide a module_param_cb() callback function for each parameter. Those functions will have to "know where to look" for the current setting of the respective parameter, so the sysfs filesystem driver can use them to figure out the parameters and their states on demand.

If the module uses the module_param(name, type, perm) or module_param_named(name, value, type, perm) macros to declare their parameters, the callback function is generated automatically unless perm is specified as 0.

The dummy module declares its module parameter like this:

module_param(numdummies, int, 0);
MODULE_PARM_DESC(numdummies, "Number of dummy pseudo devices");

explicitly specifying the perm as 0, which makes the parameter not visible in sysfs.

The main nvidia module declares its own NV_MODULE_PARAMETER(x) and NV_MODULE_STRING_PARAMETER(x) macros (in common/inc/nv-linux.h within the NVidia driver package), which use module_param() with the perm parameter set to 0:

#define NV_MODULE_PARAMETER(x)          module_param(x, int, 0)
#define NV_MODULE_STRING_PARAMETER(x)   module_param(x, charp, 0)

Other modules in the driver package, like nvidia_modeset, nvidia_drm and nvidia_uvm do use module_param() in a more normal fashion, and those modules do have their parameters in /sys/module/*/parameters as expected.

Apparently, the nvidia module internally handles its parameters as something called "registry keys" (see nvidia/nv-reg.h in the driver package). Perhaps this is some kind of attempt to provide a cross-platform interface for NVidia driver parameters, that is at least in some sense similar between Windows and Linux?

Note also that the nvidia module provides its own /proc/driver/nvidia/params pseudo-file, which provides all the parameters in one virtual file.

So, in a nutshell: I would recommend you to look at /proc/driver/nvidia/params instead and to see if it fits your needs. If not, and if you are willing to build a custom version of the NVidia driver, you might (at your own risk) try changing the definitions of the NV_MODULE_PARAMETER() and NV_MODULE_STRING_PARAMETER() macros to have a perm value other than 0, e.g.:

#define NV_MODULE_PARAMETER(x)          module_param(x, int, 0400)
#define NV_MODULE_STRING_PARAMETER(x)   module_param(x, charp, 0400)

to make all parameters declared this way readable using the /sys/module/*/parameters interface, by the root user only.

If it works, you might then send NVidia an enhancement request.

2
  • Amazing, that's great, amazing answer, thank you. Do you know is there an actual reason (memory usage?) that a module might want to disable /sys/module/*/parameter access, or is this just rather a developer oversight that the last argument is 0 instead of 0400?
    – KamilCuk
    Feb 4, 2023 at 10:44
  • 1
    In a general case, I suppose the kernel developers have made it possible to disable access for a reason, e.g. in case a particular module parameter includes an encryption secret or something like that. In these specific cases of the dummy and nvidia modules, you would have to ask the respective module maintainers for their design choices.
    – telcoM
    Feb 4, 2023 at 10:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .