From: Ping-Ke Shih <pkshih@realtek.com>
To: Bitterblue Smith <rtl8821cerfe2@gmail.com>,
"lnwgorou@gmail.com" <lnwgorou@gmail.com>,
Jes Sorensen <Jes.Sorensen@gmail.com>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Subject: RE: [PATCH rtw-next] wifi: rtl8xxxu: Allocate the USB control buffer separately
Date: Mon, 9 Nov 2026 02:40:05 +0000 [thread overview]
Message-ID: <0bf816c620d74dd7ac4bebdc2b466c6d@realtek.com> (raw)
In-Reply-To: <72fc9599-3f63-4da9-bc18-aeb09d0f757f@gmail.com>
Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> On 08/11/2026 11:42, Tapparit Rukthawornwong via B4 Relay wrote:
> > From: Tapparit Rukthawornwong <lnwgorou@gmail.com>
> >
> > priv->usb_buf receives the data of every control-IN transfer used for
> > register reads, but it is embedded in struct rtl8xxxu_priv directly
> > after usb_buf_mutex. On CPUs with DMA-incoherent caches the two share a
> > cache line, which Documentation/core-api/dma-api-howto.rst says can
> > corrupt data.
> >
> > This happens in practice. When another task contends for usb_buf_mutex
> > while a read is in flight, the CPU writes to that cache line, and the
> > device's data can be lost when the buffer is unmapped. usb_control_msg()
> > still returns the full length, but the read returns stale buffer
> > contents, typically the value of the previous register write. The driver
> > then writes that value back in a read-modify-write.
> >
> > On an RTL8192EU, a stale read of REG_FPGA0_XA_HSSI_PARM2 (0x824) during a
> > scan is written back, after which the chip stops receiving and does not
> > recover on its own. REG_FPGA0_POWER_SAVE (0x818) also drifts away from
> > its init value without obvious symptoms.
> >
> > Aligning the field inside the struct is not enough: the struct lives in
> > the mac80211 private area, which is only NETDEV_ALIGN (32 byte) aligned.
> > devm_kzalloc() returns ARCH_DMA_MINALIGN aligned memory, so allocate the
> > buffer separately.
> >
> > Tested on a Raspberry Pi 2 (BCM2836, dwc_otg, 32-bit, 6.18.50 with this
> > change backported) with a TP-Link TL-WN823N v2 (RTL8192EU), triggering a
> > scan every 15 seconds:
> >
> > unpatched: 599 scans, 9 receive hangs with 0x824 corrupted, plus
> > 2 other connection failures with 0x824 intact
> > patched: 1200 scans, no failures, 0x818 and 0x824 correct at
> > every check
> >
> > To look at the reads directly, a test build put a sentinel in the buffer
> > before each read and re-read when it came back unchanged. 300 scans per
> > layout:
> >
> > buffer next to the mutex (current): 72 of 193 contended reads stale,
> > 0 of ~260000 uncontended reads
> > buffer in its own cache line: 0 of 214 contended reads stale
> > buffer from devm_kzalloc(): 0 of 270 contended reads stale
> >
> > The re-read always returned the expected value, so the device answered
> > correctly and only the host-side buffer was stale.
> >
> > Signed-off-by: Tapparit Rukthawornwong <lnwgorou@gmail.com>
>
> A similar patch was applied just five days ago.
For the record:
https://patch.msgid.link/20261010-rtl8xxxu-usb-dma-v1-1-e670d9c08fdf@khu.ac.kr
next prev parent reply other threads:[~2026-11-09 2:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 9:42 [PATCH rtw-next] wifi: rtl8xxxu: Allocate the USB control buffer separately Tapparit Rukthawornwong via B4 Relay
2026-11-08 15:35 ` Bitterblue Smith
2026-11-09 2:40 ` Ping-Ke Shih [this message]
2026-11-09 6:23 ` เทพฤทธิ์ รักษ์ถาวรวงศ์
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0bf816c620d74dd7ac4bebdc2b466c6d@realtek.com \
--to=pkshih@realtek.com \
--cc=Jes.Sorensen@gmail.com \
--cc=linux-wireless@vger.kernel.org \
--cc=lnwgorou@gmail.com \
--cc=rtl8821cerfe2@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox