[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 09/10] memory-device: Refactor memory_device_pre_plug()
From: |
David Hildenbrand |
Subject: |
[PATCH v4 09/10] memory-device: Refactor memory_device_pre_plug() |
Date: |
Fri, 23 Jun 2023 14:45:52 +0200 |
Let's move memory_device_check_addable() and basic checks out of
memory_device_get_free_addr() directly into memory_device_pre_plug().
Separating basic checks from address assignment is cleaner and
prepares for further changes.
As all memory device users now use memory_devices_init(), and that
function enforces that the size is 0, we can drop the check for an empty
region.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
hw/mem/memory-device.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index bb9d7c2a20..00c7755557 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -69,9 +69,10 @@ static int memory_device_used_region_size(Object *obj, void
*opaque)
return 0;
}
-static void memory_device_check_addable(MachineState *ms, uint64_t size,
+static void memory_device_check_addable(MachineState *ms, MemoryRegion *mr,
Error **errp)
{
+ const uint64_t size = memory_region_size(mr);
uint64_t used_region_size = 0;
/* we will need a new memory slot for kvm and vhost */
@@ -101,16 +102,9 @@ static uint64_t memory_device_get_free_addr(MachineState
*ms,
uint64_t align, uint64_t size,
Error **errp)
{
- Error *err = NULL;
GSList *list = NULL, *item;
Range as, new = range_empty;
- if (!ms->device_memory || !memory_region_size(&ms->device_memory->mr)) {
- error_setg(errp, "the configuration is not prepared for memory devices"
- " (e.g., for memory hotplug), consider specifying the"
- " maxmem option");
- return 0;
- }
range_init_nofail(&as, ms->device_memory->base,
memory_region_size(&ms->device_memory->mr));
@@ -122,12 +116,6 @@ static uint64_t memory_device_get_free_addr(MachineState
*ms,
align);
}
- memory_device_check_addable(ms, size, &err);
- if (err) {
- error_propagate(errp, err);
- return 0;
- }
-
if (hint && !QEMU_IS_ALIGNED(*hint, align)) {
error_setg(errp, "address must be aligned to 0x%" PRIx64 " bytes",
align);
@@ -251,11 +239,23 @@ void memory_device_pre_plug(MemoryDeviceState *md,
MachineState *ms,
uint64_t addr, align = 0;
MemoryRegion *mr;
+ if (!ms->device_memory) {
+ error_setg(errp, "the configuration is not prepared for memory devices"
+ " (e.g., for memory hotplug), consider specifying the"
+ " maxmem option");
+ return;
+ }
+
mr = mdc->get_memory_region(md, &local_err);
if (local_err) {
goto out;
}
+ memory_device_check_addable(ms, mr, &local_err);
+ if (local_err) {
+ goto out;
+ }
+
if (legacy_align) {
align = *legacy_align;
} else {
--
2.40.1
- [PATCH v4 00/10] memory-device: Some cleanups, David Hildenbrand, 2023/06/23
- [PATCH v4 01/10] memory-device: Unify enabled vs. supported error messages, David Hildenbrand, 2023/06/23
- [PATCH v4 02/10] memory-device: Introduce machine_memory_devices_init(), David Hildenbrand, 2023/06/23
- [PATCH v4 03/10] hw/arm/virt: Use machine_memory_devices_init(), David Hildenbrand, 2023/06/23
- [PATCH v4 04/10] hw/ppc/spapr: Use machine_memory_devices_init(), David Hildenbrand, 2023/06/23
- [PATCH v4 05/10] hw/loongarch/virt: Use machine_memory_devices_init(), David Hildenbrand, 2023/06/23
- [PATCH v4 06/10] hw/i386/pc: Use machine_memory_devices_init(), David Hildenbrand, 2023/06/23
- [PATCH v4 07/10] hw/i386/acpi-build: Rely on machine->device_memory when building SRAT, David Hildenbrand, 2023/06/23
- [PATCH v4 08/10] hw/i386/pc: Remove PC_MACHINE_DEVMEM_REGION_SIZE, David Hildenbrand, 2023/06/23
- [PATCH v4 09/10] memory-device: Refactor memory_device_pre_plug(),
David Hildenbrand <=
- [PATCH v4 10/10] memory-device: Track used region size in DeviceMemoryState, David Hildenbrand, 2023/06/23
- Re: [PATCH v4 00/10] memory-device: Some cleanups, David Hildenbrand, 2023/06/27