[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230508083929.GT83892@hirez.programming.kicks-ass.net>
Date: Mon, 8 May 2023 10:39:29 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Jonas Oberhauser <jonas.oberhauser@...weicloud.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Jens Axboe <axboe@...nel.dk>, Ingo Molnar <mingo@...hat.com>,
Will Deacon <will@...nel.org>,
Christian Brauner <brauner@...nel.org>,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
Mark Rutland <mark.rutland@....com>
Subject: Re: [GIT PULL] pipe: nonblocking rw for io_uring
On Sun, May 07, 2023 at 04:04:23PM +0200, Jonas Oberhauser wrote:
>
> Am 4/25/2023 um 9:58 PM schrieb Linus Torvalds:
> > Yes, I think Mark is right. It's not that 'old' might be wrong - that
> > doesn't matter because cmpxchg will work it out - it's just that 'new'
> > might not be consistent with the old value we then use.
>
> In the general pattern, besides the potential issue raised by Mark, tearing
> may also be an issue (longer example inspired by a case we met at the end of
> the mail) where 'old' being wrong matters.
There is yet another pattern where it actually matters:
old = READ_ONCE(*ptr);
do {
if (cond(old))
return false;
new = func(old);
} while (!try_cmpxchg(ptr, &old, new));
return true;
In this case we rely on old being 'coherent'. The more obvious case is
where it returns old (also not uncommon), but even if it just checks a
(multi-bit) condition on old you don't want tearing.
Powered by blists - more mailing lists