[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 12/68] libvhost-user: Dynamically allocate memory for memory slots
From: |
Michael S. Tsirkin |
Subject: |
[PULL 12/68] libvhost-user: Dynamically allocate memory for memory slots |
Date: |
Tue, 12 Mar 2024 18:26:04 -0400 |
From: David Hildenbrand <david@redhat.com>
Let's prepare for increasing VHOST_USER_MAX_RAM_SLOTS by dynamically
allocating dev->regions. We don't have any ABI guarantees (not
dynamically linked), so we can simply change the layout of VuDev.
Let's zero out the memory, just as we used to do.
Reviewed-by: Raphael Norwitz <raphael@enfabrica.net>
Acked-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20240214151701.29906-2-david@redhat.com>
Tested-by: Mario Casquero <mcasquer@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
subprojects/libvhost-user/libvhost-user.h | 2 +-
subprojects/libvhost-user/libvhost-user.c | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/subprojects/libvhost-user/libvhost-user.h
b/subprojects/libvhost-user/libvhost-user.h
index c2352904f0..c882b4e3a2 100644
--- a/subprojects/libvhost-user/libvhost-user.h
+++ b/subprojects/libvhost-user/libvhost-user.h
@@ -398,7 +398,7 @@ typedef struct VuDevInflightInfo {
struct VuDev {
int sock;
uint32_t nregions;
- VuDevRegion regions[VHOST_USER_MAX_RAM_SLOTS];
+ VuDevRegion *regions;
VuVirtq *vq;
VuDevInflightInfo inflight_info;
int log_call_fd;
diff --git a/subprojects/libvhost-user/libvhost-user.c
b/subprojects/libvhost-user/libvhost-user.c
index a3b158c671..360c5366d6 100644
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -2171,6 +2171,8 @@ vu_deinit(VuDev *dev)
free(dev->vq);
dev->vq = NULL;
+ free(dev->regions);
+ dev->regions = NULL;
}
bool
@@ -2205,9 +2207,18 @@ vu_init(VuDev *dev,
dev->backend_fd = -1;
dev->max_queues = max_queues;
+ dev->regions = malloc(VHOST_USER_MAX_RAM_SLOTS * sizeof(dev->regions[0]));
+ if (!dev->regions) {
+ DPRINT("%s: failed to malloc mem regions\n", __func__);
+ return false;
+ }
+ memset(dev->regions, 0, VHOST_USER_MAX_RAM_SLOTS *
sizeof(dev->regions[0]));
+
dev->vq = malloc(max_queues * sizeof(dev->vq[0]));
if (!dev->vq) {
DPRINT("%s: failed to malloc virtqueues\n", __func__);
+ free(dev->regions);
+ dev->regions = NULL;
return false;
}
--
MST
- [PULL 00/68] virtio,pc,pci: features, cleanups, fixes, Michael S. Tsirkin, 2024/03/12
- [PULL 03/68] vdpa: factor out vhost_vdpa_net_get_nc_vdpa, Michael S. Tsirkin, 2024/03/12
- [PULL 02/68] vdpa: factor out vhost_vdpa_last_dev, Michael S. Tsirkin, 2024/03/12
- [PULL 04/68] vdpa: add vhost_vdpa_set_address_space_id trace, Michael S. Tsirkin, 2024/03/12
- [PULL 08/68] vdpa: add trace event for vhost_vdpa_net_load_mq, Michael S. Tsirkin, 2024/03/12
- [PULL 05/68] vdpa: add vhost_vdpa_get_vring_base trace for svq mode, Michael S. Tsirkin, 2024/03/12
- [PULL 09/68] vdpa: define SVQ transitioning state for mode switching, Michael S. Tsirkin, 2024/03/12
- [PULL 10/68] vdpa: indicate transitional state for SVQ switching, Michael S. Tsirkin, 2024/03/12
- [PULL 06/68] vdpa: add vhost_vdpa_set_dev_vring_base trace for svq mode, Michael S. Tsirkin, 2024/03/12
- [PULL 07/68] vdpa: add trace events for vhost_vdpa_net_load_cmd, Michael S. Tsirkin, 2024/03/12
- [PULL 12/68] libvhost-user: Dynamically allocate memory for memory slots,
Michael S. Tsirkin <=
- [PULL 01/68] vdpa: add back vhost_vdpa_net_first_nc_vdpa, Michael S. Tsirkin, 2024/03/12
- [PULL 11/68] vdpa: fix network breakage after cancelling migration, Michael S. Tsirkin, 2024/03/12
- [PULL 13/68] libvhost-user: Bump up VHOST_USER_MAX_RAM_SLOTS to 509, Michael S. Tsirkin, 2024/03/12
- [PULL 14/68] libvhost-user: Factor out removing all mem regions, Michael S. Tsirkin, 2024/03/12
- [PULL 15/68] libvhost-user: Merge vu_set_mem_table_exec_postcopy() into vu_set_mem_table_exec(), Michael S. Tsirkin, 2024/03/12
- [PULL 16/68] libvhost-user: Factor out adding a memory region, Michael S. Tsirkin, 2024/03/12
- [PULL 17/68] libvhost-user: No need to check for NULL when unmapping, Michael S. Tsirkin, 2024/03/12
- [PULL 18/68] libvhost-user: Don't zero out memory for memory regions, Michael S. Tsirkin, 2024/03/12
- [PULL 19/68] libvhost-user: Don't search for duplicates when removing memory regions, Michael S. Tsirkin, 2024/03/12
- [PULL 23/68] libvhost-user: Factor out vq usability check, Michael S. Tsirkin, 2024/03/12