[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 44/56] Support individual region unmap in libvhost-user
From: |
Michael S. Tsirkin |
Subject: |
[PULL 44/56] Support individual region unmap in libvhost-user |
Date: |
Wed, 10 Jun 2020 00:28:11 -0400 |
From: Raphael Norwitz <raphael.norwitz@nutanix.com>
When the VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS protocol feature is
enabled, on memory hot-unplug qemu will transmit memory regions to
remove individually using the new message VHOST_USER_REM_MEM_REG
message. With this change, vhost-user backends build with libvhost-user
can now unmap individual memory regions when receiving the
VHOST_USER_REM_MEM_REG message.
Qemu only sends VHOST_USER_REM_MEM_REG messages when the
VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS feature is negotiated, and
support for that feature has not yet been added in libvhost-user, this
new functionality is not yet used.
Signed-off-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Message-Id: <1588533678-23450-10-git-send-email-raphael.norwitz@nutanix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
contrib/libvhost-user/libvhost-user.h | 1 +
contrib/libvhost-user/libvhost-user.c | 63 +++++++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/contrib/libvhost-user/libvhost-user.h
b/contrib/libvhost-user/libvhost-user.h
index 60ef7fd13e..f8439713a8 100644
--- a/contrib/libvhost-user/libvhost-user.h
+++ b/contrib/libvhost-user/libvhost-user.h
@@ -99,6 +99,7 @@ typedef enum VhostUserRequest {
VHOST_USER_VRING_KICK = 35,
VHOST_USER_GET_MAX_MEM_SLOTS = 36,
VHOST_USER_ADD_MEM_REG = 37,
+ VHOST_USER_REM_MEM_REG = 38,
VHOST_USER_MAX
} VhostUserRequest;
diff --git a/contrib/libvhost-user/libvhost-user.c
b/contrib/libvhost-user/libvhost-user.c
index d8ee7a23a3..386449b697 100644
--- a/contrib/libvhost-user/libvhost-user.c
+++ b/contrib/libvhost-user/libvhost-user.c
@@ -139,6 +139,7 @@ vu_request_to_string(unsigned int req)
REQ(VHOST_USER_VRING_KICK),
REQ(VHOST_USER_GET_MAX_MEM_SLOTS),
REQ(VHOST_USER_ADD_MEM_REG),
+ REQ(VHOST_USER_REM_MEM_REG),
REQ(VHOST_USER_MAX),
};
#undef REQ
@@ -763,6 +764,66 @@ vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) {
}
}
+static inline bool reg_equal(VuDevRegion *vudev_reg,
+ VhostUserMemoryRegion *msg_reg)
+{
+ if (vudev_reg->gpa == msg_reg->guest_phys_addr &&
+ vudev_reg->qva == msg_reg->userspace_addr &&
+ vudev_reg->size == msg_reg->memory_size) {
+ return true;
+ }
+
+ return false;
+}
+
+static bool
+vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) {
+ int i, j;
+ bool found = false;
+ VuDevRegion shadow_regions[VHOST_MEMORY_MAX_NREGIONS] = {};
+ VhostUserMemoryRegion m = vmsg->payload.memreg.region, *msg_region = &m;
+
+ DPRINT("Removing region:\n");
+ DPRINT(" guest_phys_addr: 0x%016"PRIx64"\n",
+ msg_region->guest_phys_addr);
+ DPRINT(" memory_size: 0x%016"PRIx64"\n",
+ msg_region->memory_size);
+ DPRINT(" userspace_addr 0x%016"PRIx64"\n",
+ msg_region->userspace_addr);
+ DPRINT(" mmap_offset 0x%016"PRIx64"\n",
+ msg_region->mmap_offset);
+
+ for (i = 0, j = 0; i < dev->nregions; i++) {
+ if (!reg_equal(&dev->regions[i], msg_region)) {
+ shadow_regions[j].gpa = dev->regions[i].gpa;
+ shadow_regions[j].size = dev->regions[i].size;
+ shadow_regions[j].qva = dev->regions[i].qva;
+ shadow_regions[j].mmap_offset = dev->regions[i].mmap_offset;
+ j++;
+ } else {
+ found = true;
+ VuDevRegion *r = &dev->regions[i];
+ void *m = (void *) (uintptr_t) r->mmap_addr;
+
+ if (m) {
+ munmap(m, r->size + r->mmap_offset);
+ }
+ }
+ }
+
+ if (found) {
+ memcpy(dev->regions, shadow_regions,
+ sizeof(VuDevRegion) * VHOST_MEMORY_MAX_NREGIONS);
+ DPRINT("Successfully removed a region\n");
+ dev->nregions--;
+ vmsg_set_reply_u64(vmsg, 0);
+ } else {
+ vu_panic(dev, "Specified region not found\n");
+ }
+
+ return true;
+}
+
static bool
vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg)
{
@@ -1771,6 +1832,8 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg)
return vu_handle_get_max_memslots(dev, vmsg);
case VHOST_USER_ADD_MEM_REG:
return vu_add_mem_reg(dev, vmsg);
+ case VHOST_USER_REM_MEM_REG:
+ return vu_rem_mem_reg(dev, vmsg);
default:
vmsg_close_fds(vmsg);
vu_panic(dev, "Unhandled request: %d", vmsg->request);
--
MST
- [PULL 32/56] hw/pci/pci_bridge: Use the IEC binary prefix definitions, (continued)
- [PULL 32/56] hw/pci/pci_bridge: Use the IEC binary prefix definitions, Michael S. Tsirkin, 2020/06/10
- [PULL 33/56] hw/pci-host: Use the IEC binary prefix definitions, Michael S. Tsirkin, 2020/06/10
- [PULL 35/56] vhost-user-blk: delay vhost_user_blk_disconnect, Michael S. Tsirkin, 2020/06/10
- [PULL 34/56] char-socket: return -1 in case of disconnect during tcp_chr_write, Michael S. Tsirkin, 2020/06/10
- [PULL 36/56] Add helper to populate vhost-user message regions, Michael S. Tsirkin, 2020/06/10
- [PULL 38/56] Add VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS, Michael S. Tsirkin, 2020/06/10
- [PULL 39/56] Transmit vhost-user memory regions individually, Michael S. Tsirkin, 2020/06/10
- [PULL 40/56] Lift max memory slots limit imposed by vhost-user, Michael S. Tsirkin, 2020/06/10
- [PULL 41/56] Refactor out libvhost-user fault generation logic, Michael S. Tsirkin, 2020/06/10
- [PULL 42/56] Support ram slot configuration in libvhost-user, Michael S. Tsirkin, 2020/06/10
- [PULL 44/56] Support individual region unmap in libvhost-user,
Michael S. Tsirkin <=
- [PULL 45/56] Lift max ram slots limit in libvhost-user, Michael S. Tsirkin, 2020/06/10
- [PULL 46/56] libvhost-user: advertise vring features, Michael S. Tsirkin, 2020/06/10
- [PULL 47/56] hw/pci: Fix crash when running QEMU with "-nic model=rocker", Michael S. Tsirkin, 2020/06/10
- [PULL 48/56] vhost-vsock: add vhost-vsock-common abstraction, Michael S. Tsirkin, 2020/06/10
- [PULL 50/56] virtio: add vhost-user-vsock-pci device, Michael S. Tsirkin, 2020/06/10
- [PULL 55/56] acpi: ged: rename event memory region, Michael S. Tsirkin, 2020/06/10
- [PULL 56/56] Fix parameter type in vhost migration log path, Michael S. Tsirkin, 2020/06/10
- [PULL 03/56] hw/acpi/nvdimm: add a helper to augment SRAT generation, Michael S. Tsirkin, 2020/06/10
- [PULL 30/56] hw/pci-host/prep: Correct RAVEN bus bridge memory region size, Michael S. Tsirkin, 2020/06/10
- [PULL 04/56] tests/acpi: update expected SRAT files, Michael S. Tsirkin, 2020/06/10