[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 13/32] libvhost-user: handle removal of identical regions
From: |
Michael S. Tsirkin |
Subject: |
[PULL 13/32] libvhost-user: handle removal of identical regions |
Date: |
Fri, 4 Feb 2022 20:43:11 -0500 |
From: Raphael Norwitz <raphael.norwitz@nutanix.com>
Today if QEMU (or any other VMM) has sent multiple copies of the same
region to a libvhost-user based backend and then attempts to remove the
region, only one instance of the region will be removed, leaving stale
copies of the region in dev->regions[].
This change resolves this by having vu_rem_mem_reg() iterate through all
regions in dev->regions[] and delete all matching regions.
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Message-Id: <20220117041050.19718-7-raphael.norwitz@nutanix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
---
subprojects/libvhost-user/libvhost-user.c | 28 +++++++++++++----------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/subprojects/libvhost-user/libvhost-user.c
b/subprojects/libvhost-user/libvhost-user.c
index 2a1fa00a44..0ee43b8e93 100644
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -821,6 +821,7 @@ static bool
vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) {
VhostUserMemoryRegion m = vmsg->payload.memreg.region, *msg_region = &m;
int i;
+ bool found = false;
if (vmsg->fd_num != 1) {
vmsg_close_fds(vmsg);
@@ -856,21 +857,24 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) {
munmap(m, r->size + r->mmap_offset);
}
- break;
+ /*
+ * Shift all affected entries by 1 to close the hole at index i and
+ * zero out the last entry.
+ */
+ memmove(dev->regions + i, dev->regions + i + 1,
+ sizeof(VuDevRegion) * (dev->nregions - i - 1));
+ memset(dev->regions + dev->nregions - 1, 0, sizeof(VuDevRegion));
+ DPRINT("Successfully removed a region\n");
+ dev->nregions--;
+ i--;
+
+ found = true;
+
+ /* Continue the search for eventual duplicates. */
}
}
- if (i < dev->nregions) {
- /*
- * Shift all affected entries by 1 to close the hole at index i and
- * zero out the last entry.
- */
- memmove(dev->regions + i, dev->regions + i + 1,
- sizeof(VuDevRegion) * (dev->nregions - i - 1));
- memset(dev->regions + dev->nregions - 1, 0,
- sizeof(VuDevRegion));
- DPRINT("Successfully removed a region\n");
- dev->nregions--;
+ if (found) {
vmsg_set_reply_u64(vmsg, 0);
} else {
vu_panic(dev, "Specified region not found\n");
--
MST
- [PULL 01/32] cpuid: use unsigned for max cpuid, (continued)
- [PULL 01/32] cpuid: use unsigned for max cpuid, Michael S. Tsirkin, 2022/02/04
- [PULL 02/32] hw/i386: Add the possibility to disable the 'isapc' machine, Michael S. Tsirkin, 2022/02/04
- [PULL 03/32] tests: acpi: manually pad OEM_ID/OEM_TABLE_ID for test_oem_fields() test, Michael S. Tsirkin, 2022/02/04
- [PULL 04/32] tests: acpi: whitelist nvdimm's SSDT and FACP.slic expected blobs, Michael S. Tsirkin, 2022/02/04
- [PULL 05/32] acpi: fix OEM ID/OEM Table ID padding, Michael S. Tsirkin, 2022/02/04
- [PULL 07/32] tests: acpi: test short OEM_ID/OEM_TABLE_ID values in test_oem_fields(), Michael S. Tsirkin, 2022/02/04
- [PULL 10/32] libvhost-user: Simplify VHOST_USER_REM_MEM_REG, Michael S. Tsirkin, 2022/02/04
- [PULL 14/32] libvhost-user: Map shared RAM with MAP_NORESERVE to support virtio-mem with hugetlb, Michael S. Tsirkin, 2022/02/04
- [PULL 12/32] libvhost-user: prevent over-running max RAM slots, Michael S. Tsirkin, 2022/02/04
- [PULL 09/32] libvhost-user: Add vu_add_mem_reg input validation, Michael S. Tsirkin, 2022/02/04
- [PULL 13/32] libvhost-user: handle removal of identical regions,
Michael S. Tsirkin <=
- [PULL 18/32] qmp: add QMP command x-query-virtio-status, Michael S. Tsirkin, 2022/02/04
- [PULL 27/32] ACPI ERST: build the ACPI ERST table, Michael S. Tsirkin, 2022/02/04
- [PULL 23/32] ACPI ERST: bios-tables-test.c steps 1 and 2, Michael S. Tsirkin, 2022/02/04
- [PULL 06/32] tests: acpi: update expected blobs, Michael S. Tsirkin, 2022/02/04
- [PULL 11/32] libvhost-user: fix VHOST_USER_REM_MEM_REG not closing the fd, Michael S. Tsirkin, 2022/02/04
- [PULL 16/32] virtio: add vhost support for virtio devices, Michael S. Tsirkin, 2022/02/04
- [PULL 24/32] ACPI ERST: PCI device_id for ERST, Michael S. Tsirkin, 2022/02/04
- [PULL 22/32] hmp: add virtio commands, Michael S. Tsirkin, 2022/02/04
- [PULL 19/32] qmp: decode feature & status bits in virtio-status, Michael S. Tsirkin, 2022/02/04
- [PULL 26/32] ACPI ERST: support for ACPI ERST feature, Michael S. Tsirkin, 2022/02/04