Re: [PATCH net-next v4 1/2] tcp: annotate lockless access to sk->sk_err

From: David Laight

Date: Fri Sep 18 2026 - 08:29:28 EST


On Fri, 18 Sep 2026 10:33:04 +0000
quanyeyang <quanyeyang@xxxxxxxxx> wrote:

> On Friday, September 18th, 2026 at AM 2:51, David Laight <david.laight.linux@xxxxxxxxx> wrote:
>
> > Don't they need annotating with data_race() ?
>
> I think READ_ONCE() is the intended marker here.

If the race is with locked accesses I think you need both.

David

>
> These loads are part of the I/O control flow (stop send/recv/splice),
> not diagnostic or heuristic reads. data_race() would silence KCSAN
> but would not restrict compiler optimizations, so the load could still
> be torn, fused or reissued. READ_ONCE() is a single-copy atomic load
> and pairs with the existing WRITE_ONCE()/xchg() updates of sk_err,
> same as tcp_poll() after e13ec3da05d1.
>
> sock_error() uses data_race() only on the fast-path "is it zero?"
> check, which is then validated by xchg(). That pattern does not
> apply to these peeks.
>
> Quanye
>