linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* rtw88: The debugfs interface reads registers from the wrong device
@ 2024-07-15 11:05 Bitterblue Smith
  2024-07-15 11:26 ` Bitterblue Smith
  0 siblings, 1 reply; 6+ messages in thread
From: Bitterblue Smith @ 2024-07-15 11:05 UTC (permalink / raw)
  To: linux-wireless@vger.kernel.org; +Cc: Ping-Ke Shih

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: rtw88: The debugfs interface reads registers from the wrong device
  2024-07-15 11:05 rtw88: The debugfs interface reads registers from the wrong device Bitterblue Smith
@ 2024-07-15 11:26 ` Bitterblue Smith
  2024-07-16  1:19   ` Ping-Ke Shih
  0 siblings, 1 reply; 6+ messages in thread
From: Bitterblue Smith @ 2024-07-15 11:26 UTC (permalink / raw)
  To: linux-wireless@vger.kernel.org; +Cc: Ping-Ke Shih

On 15/07/2024 14:05, Bitterblue Smith wrote:
> 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

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: rtw88: The debugfs interface reads registers from the wrong device
  2024-07-15 11:26 ` Bitterblue Smith
@ 2024-07-16  1:19   ` Ping-Ke Shih
  2024-07-16  2:56     ` Ping-Ke Shih
  0 siblings, 1 reply; 6+ messages in thread
From: Ping-Ke Shih @ 2024-07-16  1:19 UTC (permalink / raw)
  To: linux-wireless@vger.kernel.org, rtl8821cerfe2@gmail.com

On Mon, 2024-07-15 at 14:26 +0300, Bitterblue Smith wrote:
> 
> On 15/07/2024 14:05, Bitterblue Smith wrote:
> > 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
> 
> 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?



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: rtw88: The debugfs interface reads registers from the wrong device
  2024-07-16  1:19   ` Ping-Ke Shih
@ 2024-07-16  2:56     ` Ping-Ke Shih
  2024-07-18  6:45       ` Ping-Ke Shih
  2024-07-30 16:27       ` Kalle Valo
  0 siblings, 2 replies; 6+ messages in thread
From: Ping-Ke Shih @ 2024-07-16  2:56 UTC (permalink / raw)
  To: linux-wireless@vger.kernel.org, rtl8821cerfe2@gmail.com

On Tue, 2024-07-16 at 01:19 +0000, Ping-Ke Shih wrote:
> On Mon, 2024-07-15 at 14:26 +0300, Bitterblue Smith wrote:
> > On 15/07/2024 14:05, Bitterblue Smith wrote:
> > > 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
> > 
> > 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?
> 

Think a little bit further. I will try to duplicate static variables
to support multiple adapters. 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: rtw88: The debugfs interface reads registers from the wrong device
  2024-07-16  2:56     ` Ping-Ke Shih
@ 2024-07-18  6:45       ` Ping-Ke Shih
  2024-07-30 16:27       ` Kalle Valo
  1 sibling, 0 replies; 6+ messages in thread
From: Ping-Ke Shih @ 2024-07-18  6:45 UTC (permalink / raw)
  To: linux-wireless@vger.kernel.org, rtl8821cerfe2@gmail.com

> 
> 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/20240718064155.38955-1-pkshih@realtek.com/T/#u


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: rtw88: The debugfs interface reads registers from the wrong device
  2024-07-16  2:56     ` Ping-Ke Shih
  2024-07-18  6:45       ` Ping-Ke Shih
@ 2024-07-30 16:27       ` Kalle Valo
  1 sibling, 0 replies; 6+ messages in thread
From: Kalle Valo @ 2024-07-30 16:27 UTC (permalink / raw)
  To: Ping-Ke Shih; +Cc: linux-wireless@vger.kernel.org, rtl8821cerfe2@gmail.com

Ping-Ke Shih <pkshih@realtek.com> writes:

> On Tue, 2024-07-16 at 01:19 +0000, Ping-Ke Shih wrote:
>
>> On Mon, 2024-07-15 at 14:26 +0300, Bitterblue Smith wrote:
>> > On 15/07/2024 14:05, Bitterblue Smith wrote:
>> > > 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
>> > 
>> > 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?
>> 
>
> 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.

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-07-30 16:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-15 11:05 rtw88: The debugfs interface reads registers from the wrong device Bitterblue Smith
2024-07-15 11:26 ` Bitterblue Smith
2024-07-16  1:19   ` Ping-Ke Shih
2024-07-16  2:56     ` Ping-Ke Shih
2024-07-18  6:45       ` Ping-Ke Shih
2024-07-30 16:27       ` Kalle Valo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).