Re: [BUG] usb: cdc-wdm: Missing barriers in ad-hoc lockless buffer
From: Oliver Neukum
Date: Fri Mar 06 2026 - 04:28:50 EST
On 05.03.26 14:26, Gui-Dong Han wrote:
Hi,
Based on my shallow understanding, reordering issues typically happen
between different memory addresses, not within the same one.
Nevertheless, you've found the issue, hence I will ask you :-)
Is that something we can depend on or is that just how it works
on the architectures we are currently running on? If I go to the effort
of checking for reordering effects, I want to do it right in all cases.
The real danger of weak memory architectures lies in accessing
associated variables. For instance, if we write 1 to int a and then 2
to int b, another CPU might observe b == 2 before a == 1. This is
exactly the situation I pointed out in my original report regarding
the lack of barriers between desc->ubuf and desc->length.
Yes. Hence I was looking. The results of a completed IO can be
a) data
b) an error
c) a buffer overflow
thus there must be ordering between recording any of these results
and changing WDM_READ, right?
Honestly, lockless algorithm design is incredibly hard, which is why
drivers should probably just rely on well-tested libraries instead of
rolling their own. I am definitely no expert in this dark art, just
know enough to be dangerous :)
I agree. The issue is that lockless IO is also error handling, not
just the buffer.
Regards
Oliver