[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 08/12] vhost: Respect reserved memslots for memory devices whe
From: |
David Hildenbrand |
Subject: |
[PATCH v1 08/12] vhost: Respect reserved memslots for memory devices when realizing a vhost device |
Date: |
Wed, 27 Oct 2021 14:45:27 +0200 |
Make sure that the current reservations can be fulfilled, otherwise we
might run out of memslots later when memory devices start actually using
the reserved memslots and crash.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
hw/virtio/vhost.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 49a1074097..a8f0d0bdf7 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -23,6 +23,7 @@
#include "standard-headers/linux/vhost_types.h"
#include "hw/virtio/virtio-bus.h"
#include "hw/virtio/virtio-access.h"
+#include "hw/mem/memory-device.h"
#include "migration/blocker.h"
#include "migration/qemu-file-types.h"
#include "sysemu/dma.h"
@@ -1319,7 +1320,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
Error **errp)
{
uint64_t features;
- int i, r, n_initialized_vqs = 0;
+ int i, r, reserved_memslots, backend_memslots, n_initialized_vqs = 0;
hdev->vdev = NULL;
hdev->migration_blocker = NULL;
@@ -1415,9 +1416,13 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
memory_listener_register(&hdev->memory_listener, &address_space_memory);
QLIST_INSERT_HEAD(&vhost_devices, hdev, entry);
- if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev)) {
- error_setg(errp, "vhost backend memory slots limit is less"
- " than current number of present memory slots");
+ reserved_memslots = memory_devices_get_reserved_memslots();
+ backend_memslots = hdev->vhost_ops->vhost_backend_memslots_limit(hdev);
+ if (used_memslots + reserved_memslots > backend_memslots) {
+ error_setg(errp, "vhost backend memory slots limit (%d) is less"
+ " than current number of used (%d) and reserved (%d)"
+ " memory slots", backend_memslots, used_memslots,
+ reserved_memslots);
r = -EINVAL;
goto fail_busyloop;
}
--
2.31.1
- [PATCH v1 00/12] virtio-mem: Expose device memory via multiple memslots, David Hildenbrand, 2021/10/27
- [PATCH v1 01/12] kvm: Return number of free memslots, David Hildenbrand, 2021/10/27
- [PATCH v1 04/12] vhost: Don't merge unmergeable memory sections, David Hildenbrand, 2021/10/27
- [PATCH v1 03/12] memory: Allow for marking memory region aliases unmergeable, David Hildenbrand, 2021/10/27
- [PATCH v1 02/12] vhost: Return number of free memslots, David Hildenbrand, 2021/10/27
- [PATCH v1 05/12] memory-device: Move memory_device_check_addable() directly into memory_device_pre_plug(), David Hildenbrand, 2021/10/27
- [PATCH v1 06/12] memory-device: Generalize memory_device_used_region_size(), David Hildenbrand, 2021/10/27
- [PATCH v1 08/12] vhost: Respect reserved memslots for memory devices when realizing a vhost device,
David Hildenbrand <=
- [PATCH v1 07/12] memory-device: Support memory devices that dynamically consume multiple memslots, David Hildenbrand, 2021/10/27
- [PATCH v1 10/12] virtio-mem: Fix typo in virito_mem_intersect_memory_section() function name, David Hildenbrand, 2021/10/27
- [PATCH v1 11/12] virtio-mem: Set the RamDiscardManager for the RAM memory region earlier, David Hildenbrand, 2021/10/27
- [PATCH v1 12/12] virtio-mem: Expose device memory via multiple memslots, David Hildenbrand, 2021/10/27
- [PATCH v1 09/12] memory: Drop mapping check from memory_region_get_ram_discard_manager(), David Hildenbrand, 2021/10/27