microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.46k stars 822 forks source link

Feature request: Support for loadable kernel modules #10450

Open pdgendt opened 1 year ago

pdgendt commented 1 year ago

Windows Version

Microsoft Windows [Version 10.0.22621.2215]

WSL Version

1.2.5.0

Are you using WSL 1 or WSL 2?

Kernel Version

5.15.90.1

Distro Version

Ubuntu 22.04

Other Software

No response

Repro Steps

# clone the WSL2 kernel
$ git clone https://github.com/microsoft/WSL2-Linux-Kernel.git
$ cd WSL2-Linux-Kernel
$ git checkout linux-msft-wsl-5.15.90.1

# Set kernel version
$ uname -r
5.15.90.1-microsoft-standard-WSL2

$ export KERNELRELEASE=$(uname -r)

# copy the WSL2 config
$ cp Microsoft/config-wsl .config

# enable driver module (CONFIG_USB_NET_AX88179_178A=m in my case)
$ make menuconfig

# build
$ make KERNELRELEASE=$KERNELRELEASE
$ make KERNELRELEASE=$KERNELRELEASE modules

# install
$ sudo make KERNELRELEASE=$KERNELRELEASE modules_install

# load module
$ modinfo ax88179_178a
filename:       /lib/modules/5.15.90.1-microsoft-standard-WSL2/kernel/drivers/net/usb/ax88179_178a.ko
license:        GPL
description:    ASIX AX88179/178A based USB 3.0/2.0 Gigabit Ethernet Devices
srcversion:     6C1FCF063025567E7E0CF65
alias:          usb:v0711p0179d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v0930p0A13d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v050Dp0128d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v17EFp304Bd*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v04E8pA100d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v0DF6p0072d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v2001p4A00d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v04B4p3610d*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v0B95p178Ad*dc*dsc*dp*ic*isc*ip*in*
alias:          usb:v0B95p1790d*dc*dsc*dp*ic*isc*ip*in*
depends:
retpoline:      Y
intree:         Y
name:           ax88179_178a
vermagic:       5.15.90.1-microsoft-standard-WSL2 SMP mod_unload modversions

$ sudo modprobe ax88179_178a
modprobe: ERROR: could not insert 'ax88179_178a': Invalid argument

$ dmesg # relevant part
[ 1827.985623] BPF:      type_id=1113 bits_offset=0
[ 1827.986241] BPF:
[ 1827.986489] BPF:Invalid name
[ 1827.986693] BPF:

[ 1827.986852] failed to validate module [ax88179_178a] BTF: -22

Expected Behavior

I expect the module to be loaded and useable after modprobe.

Actual Behavior

An error occurs:

$ sudo modprobe ax88179_178a
modprobe: ERROR: could not insert 'ax88179_178a': Invalid argument

$ dmesg # relevant part
[ 1827.985623] BPF:      type_id=1113 bits_offset=0
[ 1827.986241] BPF:
[ 1827.986489] BPF:Invalid name
[ 1827.986693] BPF:

[ 1827.986852] failed to validate module [ax88179_178a] BTF: -22

Diagnostic Logs

No response

pdgendt commented 1 year ago

Same for other USB 3.0 to ethernet adapter, dmesg:

[12429.363197] vhci_hcd vhci_hcd.0: pdev(0) rhport(0) sockfd(3)
[12429.363200] vhci_hcd vhci_hcd.0: devid(458754) speed(5) speed_str(super-speed)
[12429.363220] vhci_hcd vhci_hcd.0: Device attached
[12429.711635] usb 2-1: SetAddress Request (4) to port 0
[12429.711643] usb 2-1: new SuperSpeed USB device number 4 using vhci_hcd
[12429.745247] usb 2-1: New USB device found, idVendor=17ef, idProduct=7205, bcdDevice=30.00
[12429.745250] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=6
[12429.745251] usb 2-1: Product: Thinkpad USB LAN
[12429.745252] usb 2-1: Manufacturer: Lenovo
[12429.745252] usb 2-1: SerialNumber: 10E40D000000
[12429.753826] BPF:[135141] ENUM nce
[12429.754370] BPF:size=4 vlen=11
[12429.754475] BPF:
[12429.754542] BPF:Invalid name
[12429.754641] BPF:

[12429.754740] failed to validate module [r8152] BTF: -22
elsaco commented 1 year ago

@pdgendt to use the new module make sure the booted kernel and the module(s) are from the same build. You already build a new kernel. Add it to .wslconfig and your module will load okay:

dmesg output after inserting the module:

[Thu Sep 7 14:34:20 2023] usbcore: registered new interface driver ax88179_178a

and modprobe output:

elsaco@eleven:~$ sudo modprobe -v ax88179_178a
insmod /lib/modules/5.15.90.4-microsoft-standard-WSL2/kernel/drivers/net/usb/ax88179_178a.ko
elsaco@eleven:~$ lsmod
Module                  Size  Used by
ax88179_178a           28672  0
pdgendt commented 1 year ago

@elsaco thanks for the response, I'll try that out, but I was hoping to be able to do it without replacing the kernel itself. Getting updates from Windows to the WSL subsystem wouldn't affect the kernel anymore, and this would be something I tend to forget 🙃

ghost commented 1 year ago

As elsaco has said, this is by design, until the kernel we ship changes to accommodate this.

qawsed90 commented 11 months ago

This problem does not occur when module building with CBL-Mariner 2.0 on docker. (Note: Module-dependent features must already be enabled in the kernel itself) CONFIG_DEBUG_INFO_BTF is enabled in 5.10.74.3, CONFIG_DEBUG_INFO_BTF_MODULES is enabled in 5.15.57.1 and kernel and modules from a different build, which causes this error. build_wsl_modules.zip containing the Dockerfile and build scripts.