If there are multiple kernel module can drive the same device, what is the rule to choose from them

kernel

both pcnet32 and vmxnet can drive the device.

$ lspci -k
...
02:01.0 Ethernet controller: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 10)
    Subsystem: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
    Flags: bus master, medium devsel, latency 64, IRQ 19
    I/O ports at 2000 [size=128]
    [virtual] Expansion ROM at dc400000 [disabled] [size=64K]
    Kernel driver in use: vmxnet
    Kernel modules: vmxnet, pcnet32

both kernel modules are loaded,

$ lsmod | grep net
pcnet32                32644  0 
vmxnet                 17696  0 
mii                     5212  1 pcnet32

as you see, kernel driver in use is vmxnet. is there any policy/algorithm in kernel how to choose from the candidates?

Best Answer

Short answer: The first module encountered by the kernel is chosen.

Module loading is typically handled by /etc/modules and via udev rules described in /etc/udev/rules.d. Today most Linux distributions uses udev for device handling. There is a rather complex interactions going on between udev, modprobe and the kernel module loader, however I think the author of this presentation explains it very well.

Related Topic