public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Peter Zijlstra' <peterz@infradead.org>,
	Jonas Oberhauser <jonas.oberhauser@huaweicloud.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Jens Axboe <axboe@kernel.dk>, Ingo Molnar <mingo@redhat.com>,
	Will Deacon <will@kernel.org>,
	Christian Brauner <brauner@kernel.org>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Mark Rutland <mark.rutland@arm.com>
Subject: RE: [GIT PULL] pipe: nonblocking rw for io_uring
Date: Mon, 8 May 2023 10:16:53 +0000	[thread overview]
Message-ID: <cdc5a86a8e6549ff90bb09b99d4cb651@AcuMS.aculab.com> (raw)
In-Reply-To: <20230508083929.GT83892@hirez.programming.kicks-ass.net>

From: Peter Zijlstra
> Sent: 08 May 2023 09:39
> 
> 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.

It isn't as though READ_ONCE() is expensive.

For kernel/device driver code, while CSE is useful, you pretty
much always want the compiler to always do loads into local
variables.
It is rather a shame there isn't a compiler option that
avoids these unusual any annoying operations.

Since the current 'rules' seem to require READ_ONCE() and
WRITE_ONCE() be used as pairs, why not make the data 'volatile'?
That ought to be the same as using volatile casts on all accesses.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


      reply	other threads:[~2023-05-08 10:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-21 14:01 [GIT PULL] pipe: nonblocking rw for io_uring Christian Brauner
2023-04-24 21:05 ` Linus Torvalds
2023-04-24 21:22   ` Jens Axboe
2023-04-24 21:37     ` Linus Torvalds
2023-04-24 21:55       ` Jens Axboe
2023-04-24 22:00         ` Linus Torvalds
2023-04-24 22:05           ` Jens Axboe
2023-04-24 22:03         ` Jens Axboe
2023-04-24 21:58       ` Linus Torvalds
2023-04-24 22:07         ` Jens Axboe
2023-04-24 22:44           ` Jens Axboe
2023-04-25  3:16             ` Linus Torvalds
2023-04-25 13:46               ` Jens Axboe
2023-04-25 17:20               ` Linus Torvalds
2023-04-25 19:49                 ` Peter Zijlstra
2023-04-25 19:58                   ` Linus Torvalds
2023-04-25 20:10                     ` Jens Axboe
2023-04-25 20:29                     ` Linus Torvalds
     [not found]                     ` <978690c4-1d25-46e8-3375-45940ec1ea51@huaweicloud.com>
2023-05-08  8:39                       ` Peter Zijlstra
2023-05-08 10:16                         ` David Laight [this message]

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=cdc5a86a8e6549ff90bb09b99d4cb651@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=jonas.oberhauser@huaweicloud.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    --cc=will@kernel.org \
    /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