[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 06/15] s390x/s390-virtio-ccw: move setting the maximum guest si
From: |
David Hildenbrand |
Subject: |
[PULL v2 06/15] s390x/s390-virtio-ccw: move setting the maximum guest size from sclp to machine code |
Date: |
Sat, 21 Dec 2024 20:22:00 +0100 |
Nowadays, it feels more natural to have that code located in
s390_memory_init(), where we also have direct access to the machine
object.
While at it, use the actual RAM size, not the maximum RAM size which
cannot currently be reached without support for any memory devices.
Consequently update s390_pv_vm_try_disable_async() to rely on the RAM size
as well, to avoid temporary issues while we further rework that
handling.
set_memory_limit() is temporary, we'll merge it with
s390_set_memory_limit() next.
Message-ID: <20241219144115.2820241-6-david@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
hw/s390x/s390-virtio-ccw.c | 28 ++++++++++++++++++++++++----
hw/s390x/sclp.c | 11 -----------
target/s390x/kvm/pv.c | 2 +-
3 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index b0edaa0872..a28e615c5a 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -121,11 +121,29 @@ static void subsystem_reset(void)
}
}
-static void s390_memory_init(MemoryRegion *ram)
+static void set_memory_limit(uint64_t new_limit)
+{
+ uint64_t hw_limit;
+ int ret;
+
+ ret = s390_set_memory_limit(new_limit, &hw_limit);
+ if (ret == -E2BIG) {
+ error_report("host supports a maximum of %" PRIu64 " GB",
+ hw_limit / GiB);
+ exit(EXIT_FAILURE);
+ } else if (ret) {
+ error_report("setting the guest size failed");
+ exit(EXIT_FAILURE);
+ }
+}
+
+static void s390_memory_init(MachineState *machine)
{
MemoryRegion *sysmem = get_system_memory();
+ MemoryRegion *ram = machine->ram;
+ uint64_t ram_size = memory_region_size(ram);
- if (!QEMU_IS_ALIGNED(memory_region_size(ram), 1 * MiB)) {
+ if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) {
/*
* SCLP cannot possibly expose smaller granularity right now and KVM
* cannot handle smaller granularity. As we don't support NUMA, the
@@ -136,7 +154,9 @@ static void s390_memory_init(MemoryRegion *ram)
exit(EXIT_FAILURE);
}
- /* allocate RAM for core */
+ set_memory_limit(ram_size);
+
+ /* Map the initial memory. Must happen after setting the memory limit. */
memory_region_add_subregion(sysmem, 0, ram);
/*
@@ -211,7 +231,7 @@ static void ccw_init(MachineState *machine)
qdev_realize_and_unref(DEVICE(ms->sclp), NULL, &error_fatal);
/* init memory + setup max page size. Required for the CPU model */
- s390_memory_init(machine->ram);
+ s390_memory_init(machine);
/* init CPUs (incl. CPU model) early so s390_has_feature() works */
s390_init_cpus(machine);
diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
index 8757626b5c..73e88ab4eb 100644
--- a/hw/s390x/sclp.c
+++ b/hw/s390x/sclp.c
@@ -376,10 +376,7 @@ void sclp_service_interrupt(uint32_t sccb)
/* qemu object creation and initialization functions */
static void sclp_realize(DeviceState *dev, Error **errp)
{
- MachineState *machine = MACHINE(qdev_get_machine());
SCLPDevice *sclp = SCLP(dev);
- uint64_t hw_limit;
- int ret;
/*
* qdev_device_add searches the sysbus for TYPE_SCLP_EVENTS_BUS. As long
@@ -389,14 +386,6 @@ static void sclp_realize(DeviceState *dev, Error **errp)
if (!sysbus_realize(SYS_BUS_DEVICE(sclp->event_facility), errp)) {
return;
}
-
- ret = s390_set_memory_limit(machine->maxram_size, &hw_limit);
- if (ret == -E2BIG) {
- error_setg(errp, "host supports a maximum of %" PRIu64 " GB",
- hw_limit / GiB);
- } else if (ret) {
- error_setg(errp, "setting the guest size failed");
- }
}
static void sclp_memory_init(SCLPDevice *sclp)
diff --git a/target/s390x/kvm/pv.c b/target/s390x/kvm/pv.c
index dde836d21a..424cce75ca 100644
--- a/target/s390x/kvm/pv.c
+++ b/target/s390x/kvm/pv.c
@@ -133,7 +133,7 @@ bool s390_pv_vm_try_disable_async(S390CcwMachineState *ms)
* If the feature is not present or if the VM is not larger than 2 GiB,
* KVM_PV_ASYNC_CLEANUP_PREPARE fill fail; no point in attempting it.
*/
- if ((MACHINE(ms)->maxram_size <= 2 * GiB) ||
+ if ((MACHINE(ms)->ram_size <= 2 * GiB) ||
!kvm_check_extension(kvm_state, KVM_CAP_S390_PROTECTED_ASYNC_DISABLE))
{
return false;
}
--
2.47.1
- [PULL v2 00/15] Host Memory Backends and Memory devices queue 2024-12-21, David Hildenbrand, 2024/12/21
- [PULL v2 01/15] virtio-mem: unplug memory only during system resets, not device resets, David Hildenbrand, 2024/12/21
- [PULL v2 02/15] s390x/s390-virtio-ccw: don't crash on weird RAM sizes, David Hildenbrand, 2024/12/21
- [PULL v2 03/15] s390x/s390-virtio-hcall: remove hypercall registration mechanism, David Hildenbrand, 2024/12/21
- [PULL v2 04/15] s390x/s390-virtio-hcall: prepare for more diag500 hypercalls, David Hildenbrand, 2024/12/21
- [PULL v2 05/15] s390x: rename s390-virtio-hcall* to s390-hypercall*, David Hildenbrand, 2024/12/21
- [PULL v2 06/15] s390x/s390-virtio-ccw: move setting the maximum guest size from sclp to machine code,
David Hildenbrand <=
- [PULL v2 08/15] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT, David Hildenbrand, 2024/12/21
- [PULL v2 07/15] s390x: introduce s390_get_memory_limit(), David Hildenbrand, 2024/12/21
- [PULL v2 09/15] s390x/s390-stattrib-kvm: prepare for memory devices and sparse memory layouts, David Hildenbrand, 2024/12/21
- [PULL v2 10/15] s390x/s390-skeys: prepare for memory devices, David Hildenbrand, 2024/12/21
- [PULL v2 11/15] s390x/s390-virtio-ccw: prepare for memory devices, David Hildenbrand, 2024/12/21
- [PULL v2 12/15] s390x/pv: prepare for memory devices, David Hildenbrand, 2024/12/21
- [PULL v2 13/15] s390x: remember the maximum page size, David Hildenbrand, 2024/12/21
- [PULL v2 14/15] s390x/virtio-ccw: add support for virtio based memory devices, David Hildenbrand, 2024/12/21
- [PULL v2 15/15] s390x: virtio-mem support, David Hildenbrand, 2024/12/21
- Re: [PULL v2 00/15] Host Memory Backends and Memory devices queue 2024-12-21, Stefan Hajnoczi, 2024/12/22