Skip to contentSkip to conversation

rtw88: The debugfs interface reads registers from the wrong device

DISCUSSION Bitterblue Smith 3 participants 6 messages Jul 15, 2024 – Jul 30, 2024

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw
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 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
     .....
Quoted 5 lines

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

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.

#2 lore raw
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 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:

Quoted 6 lines
Quoted 2 lines
   # 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.

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?

#3 lore raw
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 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:

Quoted 6 lines
Quoted 2 lines
   # 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.

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.

#5 lore raw
In reply to Ping-Ke Shih
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 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:

Quoted 6 lines
Quoted 2 lines
   # 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.

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