qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [RFC 3/8] virtio: Add API to batch set host notifiers
Date: Wed, 31 Mar 2021 18:21:13 +0200	[thread overview]
Message-ID: <20210331182113.580c8854@bahia.lan> (raw)
In-Reply-To: <YGSLkVHI/JzevSLl@stefanha-x1.localdomain>

[-- Attachment #1: Type: text/plain, Size: 3384 bytes --]

On Wed, 31 Mar 2021 15:47:45 +0100
Stefan Hajnoczi <stefanha@redhat.com> wrote:

> On Tue, Mar 30, 2021 at 04:17:32PM +0200, Greg Kurz wrote:
> > On Tue, 30 Mar 2021 14:55:42 +0100
> > Stefan Hajnoczi <stefanha@redhat.com> wrote:
> > 
> > > On Tue, Mar 30, 2021 at 12:17:40PM +0200, Greg Kurz wrote:
> > > > On Mon, 29 Mar 2021 18:10:57 +0100
> > > > Stefan Hajnoczi <stefanha@redhat.com> wrote:
> > > > > On Thu, Mar 25, 2021 at 04:07:30PM +0100, Greg Kurz wrote:
> > > > > > @@ -315,6 +338,10 @@ static void virtio_bus_unset_and_cleanup_host_notifiers(VirtioBusState *bus,
> > > > > >  
> > > > > >      for (i = 0; i < nvqs; i++) {
> > > > > >          virtio_bus_set_host_notifier(bus, i + n_offset, false);
> > > > > > +    }
> > > > > > +    /* Let address_space_update_ioeventfds() run before closing ioeventfds */
> > > > > 
> > > > > assert(memory_region_transaction_depth == 0)?
> > > > > 
> > > > 
> > > > Hmm... appart from the fact that memory_region_transaction_depth is
> > > > a memory internal thing that shouldn't be exposed here, it seems to
> > > > me that memory_region_transaction_depth can be != 0 when, e.g. when
> > > > batching is used... or I'm missing something ?
> > > > 
> > > > I was actually thinking of adding some asserts for that in the
> > > > memory_region_*_eventfd_full() functions introduced by patch 1.
> > > > 
> > > >     if (!transaction) {
> > > >         memory_region_transaction_begin();
> > > >     }
> > > >     assert(memory_region_transaction_depth != 0);
> > > 
> > > In that case is it safe to call virtio_bus_cleanup_host_notifier()
> > > below? I thought it depends on the transaction committing first.
> > > 
> > 
> > Yes because the transaction ends...
> > 
> > > > 
> > > > > > +    virtio_bus_set_host_notifier_commit(bus);
> > ...                here ^^
> > 
> > > > > > +    for (i = 0; i < nvqs; i++) {
> > > > > >          virtio_bus_cleanup_host_notifier(bus, i + n_offset);
> > > > > >      }
> > > > > >  }
> 
> That contradicts what you said above: "it seems to me that
> memory_region_transaction_depth can be != 0 when, e.g. when batching is
> used".
> 
> If memory_region_transaction_depth can be != 0 when this function is
> entered then memory_region_transaction_commit() will have no effect:
> 
>   void memory_region_transaction_commit(void)
>   {
>       AddressSpace *as;
> 
>       assert(memory_region_transaction_depth);
>       assert(qemu_mutex_iothread_locked());
> 
>       --memory_region_transaction_depth;
>       if (!memory_region_transaction_depth) {

memory_region_transaction_depth should be equal to 1 when
entering the function, not 0... which is the case when
batching.

>           ^--- we won't take this branch!
> 
> So the code after memory_region_transaction_commit() cannot assume that
> anything was actually committed.
> 

Right and nothing in the current code base seems to prevent
memory_region_*_eventfd() to be called within an ongoing
transaction actually. It looks that we might want to fix that
first.

> That's why I asked about adding assert(memory_region_transaction_depth
> == 0) to guarantee that our commit takes effect immediately so that it's
> safe to call virtio_bus_cleanup_host_notifier().
> 

Yes, it was just misplaced and I didn't get the intent at first :)

> Stefan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2021-03-31 16:23 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-25 15:07 [RFC 0/8] virtio: Improve boot time of virtio-scsi-pci and virtio-blk-pci Greg Kurz
2021-03-25 15:07 ` [RFC 1/8] memory: Allow eventfd add/del without starting a transaction Greg Kurz
2021-03-29 17:03   ` Stefan Hajnoczi
2021-03-30  7:47     ` Greg Kurz
2021-03-30 10:16       ` Stefan Hajnoczi
2021-03-25 15:07 ` [RFC 2/8] virtio: Introduce virtio_bus_set_host_notifiers() Greg Kurz
2021-03-29 17:06   ` Stefan Hajnoczi
2021-03-25 15:07 ` [RFC 3/8] virtio: Add API to batch set host notifiers Greg Kurz
2021-03-29 17:10   ` Stefan Hajnoczi
2021-03-30 10:17     ` Greg Kurz
2021-03-30 13:55       ` Stefan Hajnoczi
2021-03-30 14:17         ` Greg Kurz
2021-03-31 14:47           ` Stefan Hajnoczi
2021-03-31 16:21             ` Greg Kurz [this message]
2021-03-25 15:07 ` [RFC 4/8] virtio-pci: Batch add/del ioeventfds in a single MR transaction Greg Kurz
2021-03-29 17:24   ` Stefan Hajnoczi
2021-03-30 10:29     ` Greg Kurz
2021-03-25 15:07 ` [RFC 5/8] virtio-blk: Fix rollback path in virtio_blk_data_plane_start() Greg Kurz
2021-03-29 17:25   ` Stefan Hajnoczi
2021-03-25 15:07 ` [RFC 6/8] virtio-blk: Use virtio_bus_set_host_notifiers() Greg Kurz
2021-03-29 17:26   ` Stefan Hajnoczi
2021-03-25 15:07 ` [RFC 7/8] virtio-scsi: Set host notifiers and callbacks separately Greg Kurz
2021-03-25 15:07 ` [RFC 8/8] virtio-scsi: Use virtio_bus_set_host_notifiers() Greg Kurz
2021-03-29 17:28   ` Stefan Hajnoczi
2021-03-25 17:05 ` [RFC 0/8] virtio: Improve boot time of virtio-scsi-pci and virtio-blk-pci Michael S. Tsirkin
2021-03-25 17:43   ` Stefan Hajnoczi
2021-03-25 20:51     ` Greg Kurz
2021-03-25 18:05   ` Greg Kurz
2021-03-29 17:35 ` Stefan Hajnoczi
2021-03-30 13:15   ` Greg Kurz

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=20210331182113.580c8854@bahia.lan \
    --to=groug@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=fam@euphon.net \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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).