Skip to contentSkip to conversation

vl/s390: fixup ram sizes for compat machines

PATCH/RFC Christian Borntraeger 3 participants 6 messages Mar 31, 2020

lore
Share & tools
lore
#0 lore raw

compat machines did fixup the ram size to match what can be reported via sclp. We need to mimic those for machines 4.2 and older to not fail on inbound migration.

Fixes 3a12fc61af5c ("390x/s390-virtio-ccw: use memdev for RAM")
Cc Igor Mammedov <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
---
 hw/s390x/s390-virtio-ccw.c | 12 ++++++++++++
 hw/s390x/sclp.c            | 10 ----------
 include/hw/boards.h        |  1 +
 softmmu/vl.c               |  3 +++
 4 files changed, 16 insertions(+), 10 deletions(-)
hw/s390x/s390-virtio-ccw.c +12 -0
index 3cf19c99f3..748c08b157 100644
@@ -579,6 +579,17 @@ static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
     s390_cpu_restart(S390_CPU(cs));
 }
 
+#define MAX_STORAGE_INCREMENTS                  1020
+static ram_addr_t s390_align_ram(ram_addr_t sz)
+{
+    /* same logic as in sclp.c */
+    int increment_size = 20;
+    while ((sz >> increment_size) > MAX_STORAGE_INCREMENTS) {
+        increment_size++;
+    }
+    return sz >> increment_size << increment_size;
+}
+
 static void ccw_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -808,6 +819,7 @@ static void ccw_machine_4_2_instance_options(MachineState *machine)
 static void ccw_machine_4_2_class_options(MachineClass *mc)
 {
     ccw_machine_5_0_class_options(mc);
+    mc->machine_align_ram = s390_align_ram;
     compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
 }
 DEFINE_CCW_MACHINE(4_2, "4.2", false);
hw/s390x/sclp.c +0 -10
index d8ae207731..0a6ff2be82 100644
@@ -372,16 +372,6 @@ static void sclp_memory_init(SCLPDevice *sclp)
         increment_size++;
     }
     sclp->increment_size = increment_size;
-
-    /* The core memory area needs to be aligned with the increment size.
-     * In effect, this can cause the user-specified memory size to be rounded
-     * down to align with the nearest increment boundary. */
-    initial_mem = initial_mem >> increment_size << increment_size;
-
-    machine->ram_size = initial_mem;
-    machine->maxram_size = initial_mem;
-    /* let's propagate the changed ram size into the global variable. */
-    ram_size = initial_mem;
 }
 
 static void sclp_init(Object *obj)
include/hw/boards.h +1 -0
index 236d239c19..e3574f4b5f 100644
@@ -218,6 +218,7 @@ struct MachineClass {
                                                          unsigned cpu_index);
     const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
     int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
+    ram_addr_t (*machine_align_ram)(ram_addr_t size);
 };
 
 /**
softmmu/vl.c +3 -0
index 1d33a28340..12b5758d12 100644
@@ -2601,6 +2601,9 @@ static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
     }
 
     sz = QEMU_ALIGN_UP(sz, 8192);
+    if (mc->machine_align_ram) {
+        sz = mc->machine_align_ram(sz);
+    }
     ram_size = sz;
     if (ram_size != sz) {
         error_report("ram size too large");
Signature · 1 line
2.25.1
#1 lore raw
Quoted 86 lines · Christian Borntraeger

compat machines did fixup the ram size to match what can be reported via sclp. We need to mimic those for machines 4.2 and older to not fail on inbound migration.

Fixes 3a12fc61af5c ("390x/s390-virtio-ccw: use memdev for RAM")
Cc Igor Mammedov <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
---
 hw/s390x/s390-virtio-ccw.c | 12 ++++++++++++
 hw/s390x/sclp.c            | 10 ----------
 include/hw/boards.h        |  1 +
 softmmu/vl.c               |  3 +++
 4 files changed, 16 insertions(+), 10 deletions(-)
hw/s390x/s390-virtio-ccw.c +12 -0
index 3cf19c99f3..748c08b157 100644
@@ -579,6 +579,17 @@ static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
     s390_cpu_restart(S390_CPU(cs));
 }
 
+#define MAX_STORAGE_INCREMENTS                  1020
+static ram_addr_t s390_align_ram(ram_addr_t sz)
+{
+    /* same logic as in sclp.c */
+    int increment_size = 20;
+    while ((sz >> increment_size) > MAX_STORAGE_INCREMENTS) {
+        increment_size++;
+    }
+    return sz >> increment_size << increment_size;
+}
+
 static void ccw_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -808,6 +819,7 @@ static void ccw_machine_4_2_instance_options(MachineState *machine)
 static void ccw_machine_4_2_class_options(MachineClass *mc)
 {
     ccw_machine_5_0_class_options(mc);
+    mc->machine_align_ram = s390_align_ram;
     compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
 }
 DEFINE_CCW_MACHINE(4_2, "4.2", false);
hw/s390x/sclp.c +0 -10
index d8ae207731..0a6ff2be82 100644
@@ -372,16 +372,6 @@ static void sclp_memory_init(SCLPDevice *sclp)
         increment_size++;
     }
     sclp->increment_size = increment_size;
-
-    /* The core memory area needs to be aligned with the increment size.
-     * In effect, this can cause the user-specified memory size to be rounded
-     * down to align with the nearest increment boundary. */
-    initial_mem = initial_mem >> increment_size << increment_size;
-
-    machine->ram_size = initial_mem;
-    machine->maxram_size = initial_mem;
-    /* let's propagate the changed ram size into the global variable. */
-    ram_size = initial_mem;
 }
 
 static void sclp_init(Object *obj)
include/hw/boards.h +1 -0
index 236d239c19..e3574f4b5f 100644
@@ -218,6 +218,7 @@ struct MachineClass {
                                                          unsigned cpu_index);
     const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
     int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
+    ram_addr_t (*machine_align_ram)(ram_addr_t size);
 };
 
 /**
softmmu/vl.c +0 -0
index 1d33a28340..12b5758d12 100644

softmmu/vl.c static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size, · line 2609

Quoted 9 lines
softmmu/vl.c +3 -0
@@ -2601,6 +2601,9 @@ static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
     }
 
     sz = QEMU_ALIGN_UP(sz, 8192);
+    if (mc->machine_align_ram) {
+        sz = mc->machine_align_ram(sz);
+    }
     ram_size = sz;
     if (ram_size != sz) {
         error_report("ram size too large");

1. You're missing the maxram changes from my patch.

2. Shouldn't we error out in case ram_size is not aligned in sclp.c (new machines)?

Signature · 3 lines
Thanks,

David / dhildenb
#2 lore raw
Quoted 88 lines · David Hildenbrand
Quoted 87 lines · Christian Borntraeger

compat machines did fixup the ram size to match what can be reported via sclp. We need to mimic those for machines 4.2 and older to not fail on inbound migration.

Fixes 3a12fc61af5c ("390x/s390-virtio-ccw: use memdev for RAM")
Cc Igor Mammedov <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
---
 hw/s390x/s390-virtio-ccw.c | 12 ++++++++++++
 hw/s390x/sclp.c            | 10 ----------
 include/hw/boards.h        |  1 +
 softmmu/vl.c               |  3 +++
 4 files changed, 16 insertions(+), 10 deletions(-)
hw/s390x/s390-virtio-ccw.c +12 -0
index 3cf19c99f3..748c08b157 100644
@@ -579,6 +579,17 @@ static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
     s390_cpu_restart(S390_CPU(cs));
 }
 
+#define MAX_STORAGE_INCREMENTS                  1020
+static ram_addr_t s390_align_ram(ram_addr_t sz)
+{
+    /* same logic as in sclp.c */
+    int increment_size = 20;
+    while ((sz >> increment_size) > MAX_STORAGE_INCREMENTS) {
+        increment_size++;
+    }
+    return sz >> increment_size << increment_size;
+}
+
 static void ccw_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -808,6 +819,7 @@ static void ccw_machine_4_2_instance_options(MachineState *machine)
 static void ccw_machine_4_2_class_options(MachineClass *mc)
 {
     ccw_machine_5_0_class_options(mc);
+    mc->machine_align_ram = s390_align_ram;
     compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
 }
 DEFINE_CCW_MACHINE(4_2, "4.2", false);
hw/s390x/sclp.c +0 -10
index d8ae207731..0a6ff2be82 100644
@@ -372,16 +372,6 @@ static void sclp_memory_init(SCLPDevice *sclp)
         increment_size++;
     }
     sclp->increment_size = increment_size;
-
-    /* The core memory area needs to be aligned with the increment size.
-     * In effect, this can cause the user-specified memory size to be rounded
-     * down to align with the nearest increment boundary. */
-    initial_mem = initial_mem >> increment_size << increment_size;
-
-    machine->ram_size = initial_mem;
-    machine->maxram_size = initial_mem;
-    /* let's propagate the changed ram size into the global variable. */
-    ram_size = initial_mem;
 }
 
 static void sclp_init(Object *obj)
include/hw/boards.h +1 -0
index 236d239c19..e3574f4b5f 100644
@@ -218,6 +218,7 @@ struct MachineClass {
                                                          unsigned cpu_index);
     const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
     int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
+    ram_addr_t (*machine_align_ram)(ram_addr_t size);
 };
 
 /**
softmmu/vl.c +0 -0
index 1d33a28340..12b5758d12 100644
@@ -2601,6 +2601,9 @@ static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
     }
 
Quoted 10 lines

softmmu/vl.c static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size, · line 2609

Quoted 8 lines
softmmu/vl.c +3 -0
     sz = QEMU_ALIGN_UP(sz, 8192);
+    if (mc->machine_align_ram) {
+        sz = mc->machine_align_ram(sz);
+    }
     ram_size = sz;
     if (ram_size != sz) {
         error_report("ram size too large");

1. You're missing the maxram changes from my patch.

Yes, will fixup the remaining things.

Quoted 3 lines

2. Shouldn't we error out in case ram_size is not aligned in sclp.c (new machines)?

I think its perfectly fine to have slightly larger ram than what sclp reports. Maybe a future sclp extension will improve this? (In fact since we no longer have sclp memory hotplug we COULD use more than 1020 increments)

#3 lore raw
Quoted 102 lines · Christian Borntraeger
Quoted 88 lines · David Hildenbrand
Quoted 87 lines · Christian Borntraeger

compat machines did fixup the ram size to match what can be reported via sclp. We need to mimic those for machines 4.2 and older to not fail on inbound migration.

Fixes 3a12fc61af5c ("390x/s390-virtio-ccw: use memdev for RAM")
Cc Igor Mammedov <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
---
 hw/s390x/s390-virtio-ccw.c | 12 ++++++++++++
 hw/s390x/sclp.c            | 10 ----------
 include/hw/boards.h        |  1 +
 softmmu/vl.c               |  3 +++
 4 files changed, 16 insertions(+), 10 deletions(-)
hw/s390x/s390-virtio-ccw.c +12 -0
index 3cf19c99f3..748c08b157 100644
@@ -579,6 +579,17 @@ static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
     s390_cpu_restart(S390_CPU(cs));
 }
 
+#define MAX_STORAGE_INCREMENTS                  1020
+static ram_addr_t s390_align_ram(ram_addr_t sz)
+{
+    /* same logic as in sclp.c */
+    int increment_size = 20;
+    while ((sz >> increment_size) > MAX_STORAGE_INCREMENTS) {
+        increment_size++;
+    }
+    return sz >> increment_size << increment_size;
+}
+
 static void ccw_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -808,6 +819,7 @@ static void ccw_machine_4_2_instance_options(MachineState *machine)
 static void ccw_machine_4_2_class_options(MachineClass *mc)
 {
     ccw_machine_5_0_class_options(mc);
+    mc->machine_align_ram = s390_align_ram;
     compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
 }
 DEFINE_CCW_MACHINE(4_2, "4.2", false);
hw/s390x/sclp.c +0 -10
index d8ae207731..0a6ff2be82 100644
@@ -372,16 +372,6 @@ static void sclp_memory_init(SCLPDevice *sclp)
         increment_size++;
     }
     sclp->increment_size = increment_size;
-
-    /* The core memory area needs to be aligned with the increment size.
-     * In effect, this can cause the user-specified memory size to be rounded
-     * down to align with the nearest increment boundary. */
-    initial_mem = initial_mem >> increment_size << increment_size;
-
-    machine->ram_size = initial_mem;
-    machine->maxram_size = initial_mem;
-    /* let's propagate the changed ram size into the global variable. */
-    ram_size = initial_mem;
 }
 
 static void sclp_init(Object *obj)
include/hw/boards.h +1 -0
index 236d239c19..e3574f4b5f 100644
@@ -218,6 +218,7 @@ struct MachineClass {
                                                          unsigned cpu_index);
     const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
     int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
+    ram_addr_t (*machine_align_ram)(ram_addr_t size);
 };
 
 /**
softmmu/vl.c +0 -0
index 1d33a28340..12b5758d12 100644
@@ -2601,6 +2601,9 @@ static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
     }
 
Quoted 10 lines

softmmu/vl.c static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size, · line 2609

Quoted 8 lines
softmmu/vl.c +3 -0
     sz = QEMU_ALIGN_UP(sz, 8192);
+    if (mc->machine_align_ram) {
+        sz = mc->machine_align_ram(sz);
+    }
     ram_size = sz;
     if (ram_size != sz) {
         error_report("ram size too large");

1. You're missing the maxram changes from my patch.

Quoted 8 lines

Yes, will fixup the remaining things.

Quoted 3 lines

2. Shouldn't we error out in case ram_size is not aligned in sclp.c (new machines)?

I think its perfectly fine to have slightly larger ram than what sclp reports. Maybe a future sclp extension will improve this? (In fact since we no longer have sclp memory hotplug we COULD use more than 1020 increments)

I'd say if the guest cannot detect it *right now*, we should error out (because that's not what the user asked for).

Anyhow, whatever we do, we should add it to the changelog.

Signature · 3 lines
Thanks,

David / dhildenb
#4 lore raw
Quoted 108 lines · David Hildenbrand
Quoted 107 lines · Christian Borntraeger
Quoted 88 lines · David Hildenbrand
Quoted 87 lines · Christian Borntraeger

compat machines did fixup the ram size to match what can be reported via sclp. We need to mimic those for machines 4.2 and older to not fail on inbound migration.

Fixes 3a12fc61af5c ("390x/s390-virtio-ccw: use memdev for RAM")
Cc Igor Mammedov <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
---
 hw/s390x/s390-virtio-ccw.c | 12 ++++++++++++
 hw/s390x/sclp.c            | 10 ----------
 include/hw/boards.h        |  1 +
 softmmu/vl.c               |  3 +++
 4 files changed, 16 insertions(+), 10 deletions(-)
hw/s390x/s390-virtio-ccw.c +12 -0
index 3cf19c99f3..748c08b157 100644
@@ -579,6 +579,17 @@ static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
     s390_cpu_restart(S390_CPU(cs));
 }
 
+#define MAX_STORAGE_INCREMENTS                  1020
+static ram_addr_t s390_align_ram(ram_addr_t sz)
+{
+    /* same logic as in sclp.c */
+    int increment_size = 20;
+    while ((sz >> increment_size) > MAX_STORAGE_INCREMENTS) {
+        increment_size++;
+    }
+    return sz >> increment_size << increment_size;
+}
+
 static void ccw_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -808,6 +819,7 @@ static void ccw_machine_4_2_instance_options(MachineState *machine)
 static void ccw_machine_4_2_class_options(MachineClass *mc)
 {
     ccw_machine_5_0_class_options(mc);
+    mc->machine_align_ram = s390_align_ram;
     compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
 }
 DEFINE_CCW_MACHINE(4_2, "4.2", false);
hw/s390x/sclp.c +0 -10
index d8ae207731..0a6ff2be82 100644
@@ -372,16 +372,6 @@ static void sclp_memory_init(SCLPDevice *sclp)
         increment_size++;
     }
     sclp->increment_size = increment_size;
-
-    /* The core memory area needs to be aligned with the increment size.
-     * In effect, this can cause the user-specified memory size to be rounded
-     * down to align with the nearest increment boundary. */
-    initial_mem = initial_mem >> increment_size << increment_size;
-
-    machine->ram_size = initial_mem;
-    machine->maxram_size = initial_mem;
-    /* let's propagate the changed ram size into the global variable. */
-    ram_size = initial_mem;
 }
 
 static void sclp_init(Object *obj)
include/hw/boards.h +1 -0
index 236d239c19..e3574f4b5f 100644
@@ -218,6 +218,7 @@ struct MachineClass {
                                                          unsigned cpu_index);
     const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
     int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
+    ram_addr_t (*machine_align_ram)(ram_addr_t size);
 };
 
 /**
softmmu/vl.c +0 -0
index 1d33a28340..12b5758d12 100644
@@ -2601,6 +2601,9 @@ static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
     }
 
Quoted 10 lines

softmmu/vl.c static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size, · line 2609

Quoted 8 lines
softmmu/vl.c +3 -0
     sz = QEMU_ALIGN_UP(sz, 8192);
+    if (mc->machine_align_ram) {
+        sz = mc->machine_align_ram(sz);
+    }
     ram_size = sz;
     if (ram_size != sz) {
         error_report("ram size too large");

1. You're missing the maxram changes from my patch.

Yes, will fixup the remaining things.

Quoted 3 lines

2. Shouldn't we error out in case ram_size is not aligned in sclp.c (new machines)?

Quoted 6 lines
Quoted 3 lines

I think its perfectly fine to have slightly larger ram than what sclp reports. Maybe a future sclp extension will improve this? (In fact since we no longer have sclp memory hotplug we COULD use more than 1020 increments)

I'd say if the guest cannot detect it *right now*, we should error out (because that's not what the user asked for).

I am not a big fan for erroring out, but if this is only happending for 5.0 and later this might be ok (as the xml will keep the version).
As an alternative I couldd certainly extend this rounding to ALL machines (including 5.0).

Regarding guest detection. The guest can detect the last memory (by using tprot for example) just not via todays sclp. Let me look into sclp, I think without sclp memory hotplug we can have 64k increments (we did have that before we had memory hotplug IIRC).

Quoted 3 lines

Anyhow, whatever we do, we should add it to the changelog.

#5 lore raw
In reply to Christian Borntraeger
Quoted 16 lines · On Tue, 31 Mar 2020 08:02:38 -0400 Christian Borntraeger…

compat machines did fixup the ram size to match what can be reported via sclp. We need to mimic those for machines 4.2 and older to not fail on inbound migration.

Fixes 3a12fc61af5c ("390x/s390-virtio-ccw: use memdev for RAM")
Cc Igor Mammedov <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
---
 hw/s390x/s390-virtio-ccw.c | 12 ++++++++++++
 hw/s390x/sclp.c            | 10 ----------
 include/hw/boards.h        |  1 +
 softmmu/vl.c               |  3 +++
 4 files changed, 16 insertions(+), 10 deletions(-)

(...)

include/hw/boards.h struct MachineClass { · line 221

Quoted 9 lines
include/hw/boards.h +1 -0
index 236d239c19..e3574f4b5f 100644
@@ -218,6 +218,7 @@ struct MachineClass {
                                                          unsigned cpu_index);
     const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
     int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
+    ram_addr_t (*machine_align_ram)(ram_addr_t size);

Maybe add a comment:

/* For compat machine usage only. Don't use this in new machines. */

?

include/hw/boards.h struct MachineClass { · line 224

Quoted 3 lines
include/hw/boards.h +0 -0
 };
 
 /**

(...)

(Didn't really read the patch yet.)