diff mbox series

[PULL,14/18] virtio-pci: Add lookup subregion of VirtIOPCIRegion MR

Message ID ffa8a3e3b2e6ff017113b98d500d6a9e05b1560a.1726062663.git.mst@redhat.com (mailing list archive)
State New, archived
Headers show
Series [PULL,01/18] virtio: Allow .get_vhost() without vhost_started | expand

Commit Message

Michael S. Tsirkin Sept. 11, 2024, 1:52 p.m. UTC
From: Gao Shiyuan <gaoshiyuan@baidu.com>

Now virtio_address_space_lookup only lookup common/isr/device/notify
MR and exclude their subregions.

When VHOST_USER_PROTOCOL_F_HOST_NOTIFIER enable, the notify MR has
host-notifier subregions and we need use host-notifier MR to
notify the hardware accelerator directly instead of eventfd notify.

Further more, maybe common/isr/device MR also has subregions in
the future, so need memory_region_find for each MR incluing
their subregions.

Add lookup subregion of VirtIOPCIRegion MR instead of only lookup container MR.

Fixes: a93c8d8 ("virtio-pci: Replace modern_as with direct access to modern_bar")
Co-developed-by: Zuo Boqun <zuoboqun@baidu.com>
Signed-off-by: Gao Shiyuan <gaoshiyuan@baidu.com>
Signed-off-by: Zuo Boqun <zuoboqun@baidu.com>
Message-Id: <20240903120304.97833-1-gaoshiyuan@baidu.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio/virtio-pci.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Peter Xu Sept. 17, 2024, 8:19 p.m. UTC | #1
On Wed, Sep 11, 2024 at 09:52:08AM -0400, Michael S. Tsirkin wrote:
> From: Gao Shiyuan <gaoshiyuan@baidu.com>
> 
> Now virtio_address_space_lookup only lookup common/isr/device/notify
> MR and exclude their subregions.
> 
> When VHOST_USER_PROTOCOL_F_HOST_NOTIFIER enable, the notify MR has
> host-notifier subregions and we need use host-notifier MR to
> notify the hardware accelerator directly instead of eventfd notify.
> 
> Further more, maybe common/isr/device MR also has subregions in
> the future, so need memory_region_find for each MR incluing
> their subregions.
> 
> Add lookup subregion of VirtIOPCIRegion MR instead of only lookup container MR.
> 
> Fixes: a93c8d8 ("virtio-pci: Replace modern_as with direct access to modern_bar")
> Co-developed-by: Zuo Boqun <zuoboqun@baidu.com>
> Signed-off-by: Gao Shiyuan <gaoshiyuan@baidu.com>
> Signed-off-by: Zuo Boqun <zuoboqun@baidu.com>
> Message-Id: <20240903120304.97833-1-gaoshiyuan@baidu.com>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Hi,

QEMU master currently crashes with below cmdlines on my system:

qemu_bin=./qemu-system-x86_64
$qemu_bin -accel kvm -m 4g \
          -name peter-vm,debug-threads=on -msg timestamp=on \
          -nographic -cpu host -smp 4 \
          -device ioh3420,id=pcie.1,chassis=1 \
          -netdev user,id=net0 \
          -device virtio-net-pci,netdev=net0,bus=pcie.1

qemu-system-x86_64: ../hw/virtio/virtio-pci.c:620: virtio_address_space_lookup: Assertion `mrs.mr' failed.

Bisection goes to this patch..

Thanks,
diff mbox series

Patch

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 524b63e5c7..4d832fe845 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -615,8 +615,12 @@  static MemoryRegion *virtio_address_space_lookup(VirtIOPCIProxy *proxy,
         reg = &proxy->regs[i];
         if (*off >= reg->offset &&
             *off + len <= reg->offset + reg->size) {
-            *off -= reg->offset;
-            return &reg->mr;
+            MemoryRegionSection mrs = memory_region_find(&reg->mr,
+                                        *off - reg->offset, len);
+            assert(mrs.mr);
+            *off = mrs.offset_within_region;
+            memory_region_unref(mrs.mr);
+            return mrs.mr;
         }
     }