From: Peter Zijlstra <peterz@infradead.org>
To: Hou Tao <houtao1@huawei.com>
Cc: Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
Alexander Viro <viro@zeniv.linux.org.uk>,
linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
yukuai3@huawei.com, paulmck@kernel.org, will@kernel.org
Subject: Re: [PATCH] block: ensure the memory order between bi_private and bi_status
Date: Fri, 16 Jul 2021 12:19:29 +0200 [thread overview]
Message-ID: <20210716101929.GD4717@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <36a122ea-d18a-9317-aadd-b6b69a6f0283@huawei.com>
On Fri, Jul 16, 2021 at 05:02:33PM +0800, Hou Tao wrote:
> > Cachelines don't guarantee anything, you can get partial forwards.
>
> Could you please point me to any reference ? I can not google
>
> any memory order things by using "partial forwards".
I'm not sure I have references, but there are CPUs that can do, for
example, store forwarding at a granularity below cachelines (ie at
register size).
In such a case a CPU might observe the stored value before it is
committed to memory.
> >>> @@ -224,7 +224,11 @@ static void blkdev_bio_end_io_simple(struct bio *bio)
> >>> {
> >>> struct task_struct *waiter = bio->bi_private;
> >>>
> >>> - WRITE_ONCE(bio->bi_private, NULL);
> >>> + /*
> >>> + * Paired with smp_load_acquire in __blkdev_direct_IO_simple()
> >>> + * to ensure the order between bi_private and bi_xxx
> >>> + */
> > This comment doesn't help me; where are the other stores? Presumably
> > somewhere before this is called, but how does one go about finding them?
>
> Yes, the change log is vague and it will be corrected. The other stores
>
> happen in req_bio_endio() and its callees when the request completes.
Aaah, right. So initially I was wondering if it would make sense to put
the barrier there, but having looked at this a little longer, this
really seems to be about these two DIO methods.
> > The Changelog seems to suggest you only care about bi_css, not bi_xxx in
> > general. In specific you can only care about stores that happen before
> > this; is all of bi_xxx written before here? If not, you have to be more
> > specific.
>
> Actually we care about all bi_xxx which are written in req_bio_endio,
> and all writes to bi_xxx happen before blkdev_bio_end_io_simple().
> Here I just try to use bi_status as one example.
I see req_bio_endio() change bi_status, bi_flags and bi_iter, but afaict
there's more bi_ fields.
> >>> @@ -283,7 +287,8 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
> >>> qc = submit_bio(&bio);
> >>> for (;;) {
> >>> set_current_state(TASK_UNINTERRUPTIBLE);
> >>> - if (!READ_ONCE(bio.bi_private))
> >>> + /* Refer to comments in blkdev_bio_end_io_simple() */
> >>> + if (!smp_load_acquire(&bio.bi_private))
> >>> break;
> >>> if (!(iocb->ki_flags & IOCB_HIPRI) ||
> >>> !blk_poll(bdev_get_queue(bdev), qc, true))
> > That comment there doesn't help me find any relevant later loads and is
> > thus again inadequate.
> >
> > Here the purpose seems to be to ensure the bi_css load happens after the
> > bi_private load, and this again is cheaper done using smp_rmb().
> Yes and thanks again.
> >
> > Also, the implication seems to be -- but is not spelled out anywhere --
> > that if bi_private is !NULL, it is stable.
>
> What is the meaning of "it is stable" ? Do you mean if bi_private is NULL,
> the values of bi_xxx should be ensured ?
With stable I mean that if it is !NULL the value is always the same.
I've read more code and this is indeed the case, specifically, here
bi_private seems to be 'current' and will only be changed to NULL.
next prev parent reply other threads:[~2021-07-16 10:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-01 11:35 [PATCH] block: ensure the memory order between bi_private and bi_status Hou Tao
2021-07-07 6:29 ` Hou Tao
2021-07-13 1:14 ` Hou Tao
2021-07-15 7:01 ` Christoph Hellwig
2021-07-15 8:13 ` Peter Zijlstra
2021-07-16 9:02 ` Hou Tao
2021-07-16 10:19 ` Peter Zijlstra [this message]
2021-07-19 18:09 ` Paul E. McKenney
2021-07-19 18:16 ` Paul E. McKenney
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=20210716101929.GD4717@worktop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=houtao1@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=will@kernel.org \
--cc=yukuai3@huawei.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;
as well as URLs for NNTP newsgroup(s).