rtw88: The debugfs interface reads registers from the wrong device
Hi,
To reproduce the problem, you need a computer with two wifi devices supported by rtw88. It's especially easy to notice the problem if one of the devices is USB and the other is PCI, because the PCI device will have various values in the registers 0x300..0x3ff, but the USB device will have all 0xeaeaeaea there.
1. Let's assume the driver for the PCI device is already loaded. I have RTL8822CE.
2. Mount debugfs:
# mount -t debugfs none /sys/kernel/debug
3. Check page 0x300:
# cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3
00000300 f7138000 33330000 ffffb000 00000000
.....4. Plug the USB device. I used RTL8811CU.
5. Check page 0x300 again:
# cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3
00000300 eaeaeaea eaeaeaea eaeaeaea eaeaeaea
.....6. Bonus: unload rtw88_8821cu and check page 0x300 again to get a null pointer dereference:
# rmmod rtw88_8821cu # cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3
Quoted 30 lines · Bitterblue Smith
Hi,
To reproduce the problem, you need a computer with two wifi devices supported by rtw88. It's especially easy to notice the problem if one of the devices is USB and the other is PCI, because the PCI device will have various values in the registers 0x300..0x3ff, but the USB device will have all
0xeaeaeaeathere.1. Let's assume the driver for the PCI device is already loaded. I have RTL8822CE.
2. Mount debugfs:
# mount -t debugfs none /sys/kernel/debug3. Check page
0x300:# cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3 00000300 f7138000 33330000 ffffb000 00000000 .....4. Plug the USB device. I used RTL8811CU.
5. Check page
0x300again:# cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3 00000300 eaeaeaea eaeaeaea eaeaeaea eaeaeaea .....
Quoted 5 lines
6. Bonus: unload
rtw88_8821cuand check page0x300again to get a null pointer dereference:# rmmod rtw88_8821cu # cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3
I forgot to say: my kernel is 6.9.8-arch1-1 from Arch Linux. The problem also happens with kernel 6.9.8 plus rtw88 from rtw-next.
Quoted 35 lines · Bitterblue Smith
Quoted 33 lines · Bitterblue Smith
Hi,
To reproduce the problem, you need a computer with two wifi devices supported by rtw88. It's especially easy to notice the problem if one of the devices is USB and the other is PCI, because the PCI device will have various values in the registers 0x300..0x3ff, but the USB device will have all
0xeaeaeaeathere.1. Let's assume the driver for the PCI device is already loaded. I have RTL8822CE.
2. Mount debugfs:
# mount -t debugfs none /sys/kernel/debug3. Check page
0x300:# cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3 00000300 f7138000 33330000 ffffb000 00000000 .....4. Plug the USB device. I used RTL8811CU.
5. Check page
0x300again:# cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3 00000300 eaeaeaea eaeaeaea eaeaeaea eaeaeaea .....6. Bonus: unload
rtw88_8821cuand check page0x300again to get a null pointer dereference:
Quoted 6 lines
Quoted 2 lines
# rmmod rtw88_8821cu # cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3I forgot to say: my kernel is 6.9.8-arch1-1 from Arch Linux. The problem also happens with kernel 6.9.8 plus rtw88 from rtw-next.
This limitation is existing since initial driver.
To read a range of large registers area, for example, we need to a range via write operation and store as a private data, and then use read operation with private data to read registers.
The limitation is because the private data is static variable. A possible solution is to duplicate static variable into rtwdev. Not sure if it is worth to adjust codes for debug purpose only.
Another easier solution is to avoid creating debugfs for second adapter. How do you think?
Quoted 48 lines · Ping-Ke Shih
Quoted 34 lines · Bitterblue Smith
Quoted 33 lines · Bitterblue Smith
Hi,
To reproduce the problem, you need a computer with two wifi devices supported by rtw88. It's especially easy to notice the problem if one of the devices is USB and the other is PCI, because the PCI device will have various values in the registers 0x300..0x3ff, but the USB device will have all
0xeaeaeaeathere.1. Let's assume the driver for the PCI device is already loaded. I have RTL8822CE.
2. Mount debugfs:
# mount -t debugfs none /sys/kernel/debug3. Check page
0x300:# cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3 00000300 f7138000 33330000 ffffb000 00000000 .....4. Plug the USB device. I used RTL8811CU.
5. Check page
0x300again:# cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3 00000300 eaeaeaea eaeaeaea eaeaeaea eaeaeaea .....6. Bonus: unload
rtw88_8821cuand check page0x300again to get a null pointer dereference:Quoted 6 lines
Quoted 2 lines
# rmmod rtw88_8821cu # cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3I forgot to say: my kernel is 6.9.8-arch1-1 from Arch Linux. The problem also happens with kernel 6.9.8 plus rtw88 from rtw-next.
This limitation is existing since initial driver.
To read a range of large registers area, for example, we need to a range via write operation and store as a private data, and then use read operation with private data to read registers.
Quoted 7 lines
The limitation is because the private data is static variable. A possible solution is to duplicate static variable into rtwdev. Not sure if it is worth to adjust codes for debug purpose only.
Another easier solution is to avoid creating debugfs for second adapter. How do you think?
Think a little bit further. I will try to duplicate static variables to support multiple adapters.
Quoted 4 lines
Think a little bit further. I will try to duplicate static variables to support multiple adapters.
I sent a patch [1]. Please help to test if it can work in your side.
[1] https://lore.kernel.org/linux-wireless/[email protected]/T/#u
Quoted 54 lines · Ping-Ke Shih
Quoted 52 lines · Ping-Ke Shih
Quoted 34 lines · Bitterblue Smith
Quoted 33 lines · Bitterblue Smith
Hi,
To reproduce the problem, you need a computer with two wifi devices supported by rtw88. It's especially easy to notice the problem if one of the devices is USB and the other is PCI, because the PCI device will have various values in the registers 0x300..0x3ff, but the USB device will have all
0xeaeaeaeathere.1. Let's assume the driver for the PCI device is already loaded. I have RTL8822CE.
2. Mount debugfs:
# mount -t debugfs none /sys/kernel/debug3. Check page
0x300:# cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3 00000300 f7138000 33330000 ffffb000 00000000 .....4. Plug the USB device. I used RTL8811CU.
5. Check page
0x300again:# cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3 00000300 eaeaeaea eaeaeaea eaeaeaea eaeaeaea .....6. Bonus: unload
rtw88_8821cuand check page0x300again to get a null pointer dereference:Quoted 6 lines
Quoted 2 lines
# rmmod rtw88_8821cu # cat /sys/kernel/debug/ieee80211/phy0/rtw88/mac_3I forgot to say: my kernel is 6.9.8-arch1-1 from Arch Linux. The problem also happens with kernel 6.9.8 plus rtw88 from rtw-next.
This limitation is existing since initial driver.
To read a range of large registers area, for example, we need to a range via write operation and store as a private data, and then use read operation with private data to read registers.
The limitation is because the private data is static variable. A possible solution is to duplicate static variable into rtwdev. Not sure if it is worth to adjust codes for debug purpose only.
Quoted 6 lines
Quoted 3 lines
Another easier solution is to avoid creating debugfs for second adapter. How do you think?
Think a little bit further. I will try to duplicate static variables to support multiple adapters.
BTW in drivers all static variables need to be const just because of issues like this. Static non-const variables are a big no.
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches