From f32dbb81662b5c74d1a929ff8a58fec6a920a34a Mon Sep 17 00:00:00 2001 From: Pengyuan Date: Mon, 7 Nov 2022 10:11:06 +0800 Subject: [PATCH 7/7] vhost-vdpa: add memslot getter/setter for vhost-vdpa When vhost-vdpa is used as the virtio-net-pci backend on the ARM64 platform, a null pointer access is triggered. #0 0x0000000000000000 in () #1 0x0000aaaaab63bdcc in vhost_dev_used_memslots_is_exceeded (hdev=0xaaaaac632420) at ../hw/virtio/vhost.c:1341 #2 0x0000aaaaab63c420 in vhost_dev_init (hdev=0xaaaaac632420, opaque=0xfffff4321190, backend_type=VHOST_BACKEND_TYPE_VDPA, busyloop_timeout=0, errp=0xfffffffff210) at ../hw/virtio/vhost.c:1461 #3 0x0000aaaaab0d6ad8 in vhost_net_init (options=0xfffffffff290) at ../hw/net/vhost_net.c:247 #4 0x0000aaaaaaf05f40 in vhost_vdpa_add (ncs=0xfffff4321010, be=0xfffff4321190, queue_pair_index=0, nvqs=2) at ../net/vhost-vdpa.c:109 #5 0x0000aaaaaaf06358 in net_vhost_vdpa_init (peer=0x0, device=0xaaaaaba47140 "vhost-vdpa", name=0xaaaaac63a640 "vhost-vdpa0", vdpa_device_fd=12, queue_pair_index=0, nvqs=2, is_datapath=true) at ../net/vhost-vdpa.c:214 #6 0x0000aaaaaaf066ac in net_init_vhost_vdpa (netdev=0xaaaaac6322a0, name=0xaaaaac63a640 "vhost-vdpa0", peer=0x0, errp=0xaaaaac26ea20 ) at ../net/vhost-vdpa.c:291 #7 0x0000aaaaaaef7f94 in net_client_init1 (netdev=0xaaaaac6322a0, is_netdev=true, errp=0xaaaaac26ea20 ) at ../net/net.c:1064 #8 0x0000aaaaaaef8334 in net_client_init (opts=0xaaaaac32bf80, is_netdev=true, errp=0xaaaaac26ea20 ) at ../net/net.c:1162 #9 0x0000aaaaaaef90a4 in net_init_netdev (dummy=0x0, opts=0xaaaaac32bf80, errp=0xaaaaac26ea20 ) at ../net/net.c:1494 #10 0x0000aaaaab97aee0 in qemu_opts_foreach (list=0xaaaaac1038c0 , func=0xaaaaaaef9040 , opaque=0x0, errp=0xaaaaac26ea20 ) at ../util/qemu-option.c:1135 #11 0x0000aaaaaaef93a4 in net_init_clients (errp=0xaaaaac26ea20 ) at ../net/net.c:1567 #12 0x0000aaaaab586f8c in qemu_create_late_backends () at ../softmmu/vl.c:2000 #13 0x0000aaaaab58b234 in qemu_init (argc=37, argv=0xfffffffff848, envp=0xfffffffff978) at ../softmmu/vl.c:3763 #14 0x0000aaaaaae1f7f8 in main (argc=37, argv=0xfffffffff848, envp=0xfffffffff978) at ../softmmu/main.c:50 Fixes: 185d7efe768 ("vhost-user: add separate memslot counter for vhost-user") Signed-off-by:Pengyuan Zhao --- hw/virtio/vhost-vdpa.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index bcaf00e09f..f285edb786 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -24,6 +24,8 @@ #include "trace.h" #include "qemu-common.h" +static unsigned int vhost_vdpa_used_memslots; + /* * Return one past the end of the end of section. Be careful with uint64_t * conversions! @@ -763,6 +765,16 @@ static bool vhost_vdpa_force_iommu(struct vhost_dev *dev) return true; } +static void vhost_vdpa_set_used_memslots(struct vhost_dev *dev) +{ + vhost_vdpa_used_memslots = dev->mem->nregions; +} + +static unsigned int vhost_vdpa_get_used_memslots(void) +{ + return vhost_vdpa_used_memslots; +} + const VhostOps vdpa_ops = { .backend_type = VHOST_BACKEND_TYPE_VDPA, .vhost_backend_init = vhost_vdpa_init, @@ -795,4 +807,6 @@ const VhostOps vdpa_ops = { .vhost_get_device_id = vhost_vdpa_get_device_id, .vhost_vq_get_addr = vhost_vdpa_vq_get_addr, .vhost_force_iommu = vhost_vdpa_force_iommu, + .vhost_set_used_memslots = vhost_vdpa_set_used_memslots, + .vhost_get_used_memslots = vhost_vdpa_get_used_memslots, }; -- 2.27.0