From: John Levon <levon@movementarian.org>
To: Jinhao Fan <fanjinhao21s@ict.ac.cn>
Cc: Klaus Jensen <its@irrelevant.dk>, Keith Busch <kbusch@kernel.org>,
qemu-devel@nongnu.org
Subject: Re: [PATCH 1/2] hw/nvme: Implement shadow doorbell buffer support
Date: Wed, 15 Jun 2022 12:45:56 +0100 [thread overview]
Message-ID: <YqnGdDaQsLMp2lnA@movementarian.org> (raw)
In-Reply-To: <1B9E7594-8DA6-4F04-A5FC-10CEDA25368A@ict.ac.cn>
On Wed, Jun 15, 2022 at 07:22:22PM +0800, Jinhao Fan wrote:
> >>> Isn't this racy against the driver? Compare
> >>> https://github.com/spdk/spdk/blob/master/lib/nvmf/vfio_user.c#L1317
> >>
> >> QEMU has full memory barriers on dma read/write, so I believe this is
> >> safe?
> >
> > But don't you need to re-read the tail still, for example:
>
> I think we also have a check for concurrent update on the tail. After writing eventidx, we read the tail again. It is here:
>
> @@ -5854,6 +5943,11 @@ static void nvme_process_sq(void *opaque)
> req->status = status;
> nvme_enqueue_req_completion(cq, req);
> }
> +
> + if (n->dbbuf_enabled) {
> + nvme_update_sq_eventidx(sq);
> + nvme_update_sq_tail(sq);
> + }
Ah, and we go around the loop another time in this case.
> > driver device
> >
> > eventidx is 3
> >
> > write 4 to tail
> > read tail of 4
> > write 5 to tail
> > read eventidx of 3
> > nvme_dbbuf_need_event (1)
> >
> > set eventidx to 4
>
> Therefore, at this point, we read the tail of 5.
The driver could still update the tail after the nvme_update_sq_tail() above.
However, the driver ordering (read tail, then eventidx), does mean that it would
then do an mmio write, so yes, this looks safe, thank you.
regards
john
next prev parent reply other threads:[~2022-06-15 11:48 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-08 1:36 [PATCH 0/2] hw/nvme: Add shadow doorbell buffer support Jinhao Fan
2022-06-08 1:36 ` [PATCH 1/2] hw/nvme: Implement " Jinhao Fan
2022-06-08 20:55 ` Klaus Jensen
2022-06-09 1:49 ` Jinhao Fan
2022-06-09 14:29 ` Keith Busch
2022-06-09 15:52 ` John Levon
2022-06-09 17:27 ` Klaus Jensen
2022-06-09 17:50 ` John Levon
2022-06-12 11:40 ` Jinhao Fan
2022-06-13 21:15 ` Keith Busch
2022-06-14 7:24 ` Jinhao Fan
2022-06-14 15:41 ` Keith Busch
2022-06-15 3:58 ` Jinhao Fan
2022-06-15 9:38 ` Klaus Jensen
2022-06-15 14:52 ` Jinhao Fan
2022-06-15 8:48 ` Klaus Jensen
2022-06-15 9:07 ` John Levon
2022-06-15 9:33 ` Klaus Jensen
2022-06-15 10:11 ` John Levon
2022-06-15 11:22 ` Jinhao Fan
2022-06-15 11:45 ` John Levon [this message]
2022-06-08 1:36 ` [PATCH 2/2] hw/nvme: Add trace events for shadow doorbell buffer Jinhao Fan
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=YqnGdDaQsLMp2lnA@movementarian.org \
--to=levon@movementarian.org \
--cc=fanjinhao21s@ict.ac.cn \
--cc=its@irrelevant.dk \
--cc=kbusch@kernel.org \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).