All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gao,Shiyuan" via <qemu-devel@nongnu.org>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Tiwei Bie <tiwei.bie@intel.com>, "Zuo,Boqun" <zuoboqun@baidu.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	Jason Wang <jasowang@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH 1/1] virtio-pci: return RAM device MR when set host notifier success
Date: Fri, 16 Aug 2024 12:33:24 +0000	[thread overview]
Message-ID: <da2b25fa238945dcbdc53b91e0519330@baidu.com> (raw)
In-Reply-To: <20240816061647-mutt-send-email-mst@kernel.org>

> > When vhost-user backend register memory region based host notifiers,
> > we should return RAM device MR of notify region MR's subregion in
> > virtio_address_space_lookup.
> >
> > In seabios, it will use virtio PCI Configration Access Capability
> > access notify region when assign notify region above 4GB. This will
> > exit to QEMU and invoke virtio_address_space_write. When vhost-user
> > backend register memory region based host notifiers, return RAM device
> > MR instead of notify region MR is suitable.
>
>
> I can't really parse this.
>

When booting from disk, SeaBIOS will invoke the INT 0x13 interrupt handler
to load the MBR. The interrupt handler will eventually utilize the virtio
block driver in SeaBIOS when the disk is a virtio block device,
and after notifying the backend via `vp_notify`, the MBR will be loaded.

When assign the address of notify region in the modern bar above 4G, the
`vp_notify` in SeaBIOS will use PCI Configuration Access Capability to
write notify region. This will trap into QEMU and be handled by the
host bridge when we don't enable mmconfig. QEMU will call
`virtio_write_config`, and since it writes to the BAR region through
the PCI Configuration Access capability, it will call
`virtio_address_space_write`.

When VHOST_USER_PROTOCOL_F_HOST_NOTIFIER protocol feature has been
successfully negotiated and vhost-user backend registers memory region based
host notifiers, QEMU need write the mmap address instead of eventfd notify
the hardware accelerator at the vhost-user backend.

So virtio_address_space_lookup in virtio_address_space_write need return a
host-notifier subregion of notify MR.


> > --- a/hw/virtio/virtio-pci.c
> > +++ b/hw/virtio/virtio-pci.c
> > @@ -610,13 +610,22 @@ static MemoryRegion *virtio_address_space_lookup(VirtIOPCIProxy *proxy,
> >  {
> >      int i;
> >      VirtIOPCIRegion *reg;
> > +    MemoryRegion *mr, *submr;
> >
> >      for (i = 0; i < ARRAY_SIZE(proxy->regs); ++i) {
> >          reg = &proxy->regs[i];
> >          if (*off >= reg->offset &&
> >              *off + len <= reg->offset + reg->size) {
> >              *off -= reg->offset;
> > -            return &reg->mr;
> > +            mr = &reg->mr;
> > +            QTAILQ_FOREACH(submr, &mr->subregions, subregions_link) {
> > +                if (*off >= submr->addr &&
> > +                    *off + len < submr->addr + submr->size) {
> > +                    *off -= submr->addr;
> > +                    return submr;
> > +                }
> > +            }
> > +            return mr;
> >          }
> >      }
>
> Poking at internals of MR like this is not nice.
> Doesn't memory_region_find work for this?

It seems fine, I’ll try it out.

      parent reply	other threads:[~2024-08-16 12:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-12 12:20 [PATCH 1/1] virtio-pci: return RAM device MR when set host notifier success Gao Shiyuan via
2024-08-16 10:12 ` Gao,Shiyuan via
2024-08-16 10:29 ` Michael S. Tsirkin
2024-08-16 12:12   ` Jason Wang
2024-08-16 12:33   ` Gao,Shiyuan via [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=da2b25fa238945dcbdc53b91e0519330@baidu.com \
    --to=qemu-devel@nongnu.org \
    --cc=gaoshiyuan@baidu.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=tiwei.bie@intel.com \
    --cc=zuoboqun@baidu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.