Skip to contentSkip to conversation

s390x: virtio-mem support

PATCH Superseded David Hildenbrand 4 participants 30 messages Oct 8, 2024 – Dec 19, 2024 Arm/Amlogic Meson SoC support

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover s390x: virtio-mem support

Based on current master.

There is really not much left to do on s390x, because virtio-mem already implements most things we need today (e.g., early-migration, unplugged-inaccessible). The biggest part of this series is just doing what we do with virtio-pci, wiring it up in the machine hotplug handler and ... well, messing with the physical memory layout where we can now exceed initial RAM size and have sparsity (memory holes).

I tested a lot of things, including:
* Memory hotplug/unplug
* Device hotplug/unplug
* System resets / reboots
* Migrate to/from file (including storage attributes under KVM)
* Basic live migration
* Basic postcopy live migration

More details on how to use it on s390x -- which is pretty much how we use it on other architectures, except s/virtio-mem-pci/virtio-mem-ccw/ --- is in the last patch.

This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented in the kernel and at [2] once this+kernel part go upstream.

There are not many s390x-specific virtio-mem future work items, except:
* Storage attribute migration might be improved
* We might want to reset storage attributes of unplugged memory (might or might not be required for upcoming page table reclaim in Linux; TBD)

The Linux driver is available at [3].

[1] https://lkml.kernel.org/r/[email protected]
[2] https://gitlab.com/davidhildenbrand/s390x-os-virt-spec
[3] https://lkml.kernel.org/r/[email protected]

v1 -> v2:
* "s390x/s390-virtio-hcall: prepare for more diag500 hypercalls"
- Turn handle_diag_500() into a void function
- Inject PGM_SPECIFICATION from handle_diag_500() directly
* "s390x/s390-virtio-ccw: move setting the maximum guest size from sclp to machine code"
- Move code to a new function to make further changes easier
- Adjust s390_pv_vm_try_disable_async() to stay in sync with the maxram->ram change
* "s390x: introduce s390_get_memory_limit()"
- Store limit in machine
- Move s390_set_memory_limit() from target code into machine code
* "s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT"
- Move handling into a separate function now that we lookup the machine
* "s390x/s390-stattrib-kvm: prepare for memory devices and sparse memory layouts"
- Adjust to s390_get_memory_limit() changes
* "s390x/s390-skeys: prepare for memory devices"
- Adjust to s390_get_memory_limit() changes
* "s390x/pv: prepare for memory devices"
- Use s390_get_memory_limit()
* "s390x: remember the maximum page size"
- Store it in the machine
- Move s390_set_max_pagesize() from target code into machine code
- No need for s390_get_max_pagesize()
* "s390x/virtio-ccw: add support for virtio based memory devices"
- Move machine wire-up code from virtio-mem patch into this patch
- Add stubs to make compilation without virtio-mem work
* "s390x: virtio-mem support"
- Move machine write-up code to previous patch

Cc Paolo Bonzini <[email protected]>
Cc Thomas Huth <[email protected]>
Cc Halil Pasic <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc Eric Farman <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Nina Schoetterl-Glausch <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Ilya Leoshkevich <[email protected]>
Cc Janosch Frank <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Cornelia Huck <[email protected]>

David Hildenbrand (14):
s390x/s390-virtio-ccw: don't crash on weird RAM sizes s390x/s390-virtio-hcall: remove hypercall registration mechanism s390x/s390-virtio-hcall: prepare for more diag500 hypercalls
s390x: rename s390-virtio-hcall* to s390-hypercall* s390x/s390-virtio-ccw: move setting the maximum guest size from sclp
to machine code
s390x: introduce s390_get_memory_limit() s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT s390x/s390-stattrib-kvm: prepare for memory devices and sparse memory
layouts
s390x/s390-skeys: prepare for memory devices s390x/s390-virtio-ccw: prepare for memory devices s390x/pv: prepare for memory devices
s390x: remember the maximum page size
s390x/virtio-ccw: add support for virtio based memory devices
s390x: virtio-mem support

 MAINTAINERS                        |   5 +
 hw/s390x/Kconfig                   |   1 +
 hw/s390x/meson.build               |   6 +-
 hw/s390x/s390-hypercall.c          |  85 +++++++++++
 hw/s390x/s390-hypercall.h          |  25 ++++
 hw/s390x/s390-skeys.c              |   6 +-
 hw/s390x/s390-stattrib-kvm.c       |  67 ++++++---
 hw/s390x/s390-virtio-ccw.c         | 165 ++++++++++++++-------
 hw/s390x/s390-virtio-hcall.c       |  41 ------
 hw/s390x/s390-virtio-hcall.h       |  25 ----
 hw/s390x/sclp.c                    |  17 +--
 hw/s390x/virtio-ccw-md-stubs.c     |  24 +++
 hw/s390x/virtio-ccw-md.c           | 153 +++++++++++++++++++
 hw/s390x/virtio-ccw-md.h           |  44 ++++++
 hw/s390x/virtio-ccw-mem.c          | 226 +++++++++++++++++++++++++++++
 hw/s390x/virtio-ccw-mem.h          |  34 +++++
 hw/virtio/Kconfig                  |   1 +
 hw/virtio/virtio-mem.c             |   4 +-
 include/hw/s390x/s390-virtio-ccw.h |   4 +
 target/s390x/cpu-sysemu.c          |  15 --
 target/s390x/cpu.h                 |   2 -
 target/s390x/kvm/kvm.c             |  18 +--
 target/s390x/kvm/pv.c              |   2 +-
 target/s390x/tcg/misc_helper.c     |   7 +-
 24 files changed, 782 insertions(+), 195 deletions(-)
 create mode 100644 hw/s390x/s390-hypercall.c
 create mode 100644 hw/s390x/s390-hypercall.h
 delete mode 100644 hw/s390x/s390-virtio-hcall.c
 delete mode 100644 hw/s390x/s390-virtio-hcall.h
 create mode 100644 hw/s390x/virtio-ccw-md-stubs.c
 create mode 100644 hw/s390x/virtio-ccw-md.c
 create mode 100644 hw/s390x/virtio-ccw-md.h
 create mode 100644 hw/s390x/virtio-ccw-mem.c
 create mode 100644 hw/s390x/virtio-ccw-mem.h
Signature · 1 line
2.46.1
#1 lore raw

PATCH v2 1/14 s390x/s390-virtio-ccw: don't crash on weird RAM sizes

KVM is not happy when starting a VM with weird RAM sizes:

  # qemu-system-s390x --enable-kvm --nographic -m 1234K
  qemu-system-s390x: kvm_set_user_memory_region: KVM_SET_USER_MEMORY_REGION
    failed, slot=0, start=0x0, size=0x244000: Invalid argument
  kvm_set_phys_mem: error registering slot: Invalid argument
  Aborted (core dumped)

Let's handle that in a better way by rejecting such weird RAM sizes right from the start:

  # qemu-system-s390x --enable-kvm --nographic -m 1234K
  qemu-system-s390x: ram size must be multiples of 1 MiB
---
 hw/s390x/s390-virtio-ccw.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
hw/s390x/s390-virtio-ccw.c +11 -0
index 5aa8d207a3..b88ec8e78a 100644
@@ -180,6 +180,17 @@ static void s390_memory_init(MemoryRegion *ram)
 {
     MemoryRegion *sysmem = get_system_memory();
 
+    if (!QEMU_IS_ALIGNED(memory_region_size(ram), 1 * MiB)) {
+        /*
+         * SCLP cannot possibly expose smaller granularity right now and KVM
+         * cannot handle smaller granularity. As we don't support NUMA, the
+         * region size directly corresponds to machine->ram_size, and the region
+         * is a single RAM memory region.
+         */
+        error_report("ram size must be multiples of 1 MiB");
+        exit(EXIT_FAILURE);
+    }
+
     /* allocate RAM for core */
     memory_region_add_subregion(sysmem, 0, ram);
 
Signature · 1 line
2.46.1
#4 lore raw

PATCH v2 4/14 s390x: rename s390-virtio-hcall* to s390-hypercall*

In reply to David Hildenbrand

Let's make it clearer that we are talking about general QEMU/KVM-specific hypercalls.

---
 hw/s390x/meson.build                               | 2 +-
 hw/s390x/{s390-virtio-hcall.c => s390-hypercall.c} | 2 +-
 hw/s390x/{s390-virtio-hcall.h => s390-hypercall.h} | 6 +++---
 target/s390x/kvm/kvm.c                             | 2 +-
 target/s390x/tcg/misc_helper.c                     | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)
 rename hw/s390x/{s390-virtio-hcall.c => s390-hypercall.c} (97%)
 rename hw/s390x/{s390-virtio-hcall.h => s390-hypercall.h} (86%)
hw/s390x/meson.build +1 -1
index 482fd13420..71ec747f4c 100644
@@ -12,7 +12,7 @@ s390x_ss.add(files(
   's390-pci-inst.c',
   's390-skeys.c',
   's390-stattrib.c',
-  's390-virtio-hcall.c',
+  's390-hypercall.c',
   'sclp.c',
   'sclpcpu.c',
   'sclpquiesce.c',
hw/s390x/s390-hypercall.c renamed from hw/s390x/s390-virtio-hcall.c +1 -1
similarity index 97%
rename from hw/s390x/s390-virtio-hcall.c
rename to hw/s390x/s390-hypercall.c
index 5fb78a719e..f816c2b1ef 100644
@@ -12,7 +12,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "hw/boards.h"
-#include "hw/s390x/s390-virtio-hcall.h"
+#include "hw/s390x/s390-hypercall.h"
 #include "hw/s390x/ioinst.h"
 #include "hw/s390x/css.h"
 #include "virtio-ccw.h"
hw/s390x/s390-hypercall.h renamed from hw/s390x/s390-virtio-hcall.h +3 -3
similarity index 86%
rename from hw/s390x/s390-virtio-hcall.h
rename to hw/s390x/s390-hypercall.h
index dca456b926..2fa81dbfdd 100644
@@ -9,8 +9,8 @@
  * directory.
  */
 
-#ifndef HW_S390_VIRTIO_HCALL_H
-#define HW_S390_VIRTIO_HCALL_H
+#ifndef HW_S390_HYPERCALL_H
+#define HW_S390_HYPERCALL_H
 
 #include "cpu.h"
 
@@ -21,4 +21,4 @@
 
 void handle_diag_500(S390CPU *cpu, uintptr_t ra);
 
-#endif /* HW_S390_VIRTIO_HCALL_H */
+#endif /* HW_S390_HYPERCALL_H */
target/s390x/kvm/kvm.c +1 -1
index a8cbc0e2eb..734d2b9b78 100644
@@ -49,7 +49,7 @@
 #include "hw/s390x/ebcdic.h"
 #include "exec/memattrs.h"
 #include "hw/s390x/s390-virtio-ccw.h"
-#include "hw/s390x/s390-virtio-hcall.h"
+#include "hw/s390x/s390-hypercall.h"
 #include "target/s390x/kvm/pv.h"
 
 #define kvm_vm_check_mem_attr(s, attr) \
target/s390x/tcg/misc_helper.c +1 -1
index 0ab2bf36cf..3732d79185 100644
@@ -36,7 +36,7 @@
 #include "sysemu/cpus.h"
 #include "sysemu/sysemu.h"
 #include "hw/s390x/ebcdic.h"
-#include "hw/s390x/s390-virtio-hcall.h"
+#include "hw/s390x/s390-hypercall.h"
 #include "hw/s390x/sclp.h"
 #include "hw/s390x/s390_flic.h"
 #include "hw/s390x/ioinst.h"
Signature · 1 line
2.46.1
#3 lore raw

PATCH v2 3/14 s390x/s390-virtio-hcall: prepare for more diag500 hypercalls

In reply to David Hildenbrand

Let's generalize, abstracting the virtio bits. diag500 is now a generic hypercall to handle QEMU/KVM specific things. Explicitly specify all already defined subcodes, including legacy ones (so we know what we can use for new hypercalls).

Move the PGM_SPECIFICATION injection into the renamed function handle_diag_500(), so we can turn it into a void function.

We'll rename the files separately, so git properly detects the rename.

---
 hw/s390x/s390-virtio-hcall.c   | 15 ++++++++-------
 hw/s390x/s390-virtio-hcall.h   | 11 ++++++-----
 target/s390x/kvm/kvm.c         | 16 +---------------
 target/s390x/tcg/misc_helper.c |  5 +++--
 4 files changed, 18 insertions(+), 29 deletions(-)
hw/s390x/s390-virtio-hcall.c +8 -7
index ca49e3cd22..5fb78a719e 100644
@@ -1,5 +1,5 @@
 /*
- * Support for virtio hypercalls on s390
+ * Support for QEMU/KVM hypercalls on s390
  *
  * Copyright 2012 IBM Corp.
  * Author(s): Cornelia Huck <[email protected]>
@@ -57,18 +57,19 @@ static int handle_virtio_ccw_notify(uint64_t subch_id, uint64_t data)
     return 0;
 }
 
-int s390_virtio_hypercall(CPUS390XState *env)
+void handle_diag_500(S390CPU *cpu, uintptr_t ra)
 {
+    CPUS390XState *env = &cpu->env;
     const uint64_t subcode = env->regs[1];
 
     switch (subcode) {
-    case KVM_S390_VIRTIO_NOTIFY:
+    case DIAG500_VIRTIO_NOTIFY:
         env->regs[2] = handle_virtio_notify(env->regs[2]);
-        return 0;
-    case KVM_S390_VIRTIO_CCW_NOTIFY:
+        break;
+    case DIAG500_VIRTIO_CCW_NOTIFY:
         env->regs[2] = handle_virtio_ccw_notify(env->regs[2], env->regs[3]);
-        return 0;
+        break;
     default:
-        return -EINVAL;
+        s390_program_interrupt(env, PGM_SPECIFICATION, ra);
     }
 }
hw/s390x/s390-virtio-hcall.h +6 -5
index 3d9fe147d2..dca456b926 100644
@@ -1,5 +1,5 @@
 /*
- * Support for virtio hypercalls on s390x
+ * Support for QEMU/KVM hypercalls on s390x
  *
  * Copyright IBM Corp. 2012, 2017
  * Author(s): Cornelia Huck <[email protected]>
@@ -12,12 +12,13 @@
 #ifndef HW_S390_VIRTIO_HCALL_H
 #define HW_S390_VIRTIO_HCALL_H
 
-#include "standard-headers/asm-s390/virtio-ccw.h"
 #include "cpu.h"
 
-/* The only thing that we need from the old kvm_virtio.h file */
-#define KVM_S390_VIRTIO_NOTIFY 0
+#define DIAG500_VIRTIO_NOTIFY           0 /* legacy, implemented as a NOP */
+#define DIAG500_VIRTIO_RESET            1 /* legacy */
+#define DIAG500_VIRTIO_SET_STATUS       2 /* legacy */
+#define DIAG500_VIRTIO_CCW_NOTIFY       3 /* KVM_S390_VIRTIO_CCW_NOTIFY */
 
-int s390_virtio_hypercall(CPUS390XState *env);
+void handle_diag_500(S390CPU *cpu, uintptr_t ra);
 
 #endif /* HW_S390_VIRTIO_HCALL_H */
target/s390x/kvm/kvm.c +1 -15
index 8ffe0159d8..a8cbc0e2eb 100644
@@ -1491,20 +1491,6 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl)
     return r;
 }
 
-static int handle_hypercall(S390CPU *cpu, struct kvm_run *run)
-{
-    CPUS390XState *env = &cpu->env;
-    int ret;
-
-    ret = s390_virtio_hypercall(env);
-    if (ret == -EINVAL) {
-        kvm_s390_program_interrupt(cpu, PGM_SPECIFICATION);
-        return 0;
-    }
-
-    return ret;
-}
-
 static void kvm_handle_diag_288(S390CPU *cpu, struct kvm_run *run)
 {
     uint64_t r1, r3;
@@ -1601,7 +1587,7 @@ static int handle_diag(S390CPU *cpu, struct kvm_run *run, uint32_t ipb)
         handle_diag_318(cpu, run);
         break;
     case DIAG_KVM_HYPERCALL:
-        r = handle_hypercall(cpu, run);
+        handle_diag_500(cpu, RA_IGNORED);
         break;
     case DIAG_KVM_BREAKPOINT:
         r = handle_sw_breakpoint(cpu, run);
target/s390x/tcg/misc_helper.c +3 -2
index 303f86d363..0ab2bf36cf 100644
@@ -117,10 +117,11 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num)
 
     switch (num) {
     case 0x500:
-        /* KVM hypercall */
+        /* QEMU/KVM hypercall */
         bql_lock();
-        r = s390_virtio_hypercall(env);
+        handle_diag_500(env_archcpu(env), GETPC());
         bql_unlock();
+        r = 0;
         break;
     case 0x44:
         /* yield */
Signature · 1 line
2.46.1
#5 lore raw

PATCH v2 5/14 s390x/s390-virtio-ccw: move setting the maximum guest size from sclp to machine code

In reply to David Hildenbrand

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.

---
 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(-)
hw/s390x/s390-virtio-ccw.c +24 -4
index 77f5d22203..f4c4433b23 100644
@@ -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);
 
     /*
@@ -217,7 +237,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);
hw/s390x/sclp.c +0 -11
index e725dcd5fd..fac09816bf 100644
@@ -381,10 +381,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
@@ -394,14 +391,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)
target/s390x/kvm/pv.c +1 -1
index dde836d21a..424cce75ca 100644
@@ -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;
     }
Signature · 1 line
2.46.1
#6 lore raw

PATCH v2 6/14 s390x: introduce s390_get_memory_limit()

In reply to David Hildenbrand

Let's add s390_get_memory_limit(), to query what has been successfully set via s390_set_memory_limit(). Allow setting the limit only once.

We'll remember the limit in the machine state. Move s390_set_memory_limit() to machine code, merging it into set_memory_limit(), because this really is a machine property.

---
 hw/s390x/s390-virtio-ccw.c         | 22 ++++++++++++++++++----
 include/hw/s390x/s390-virtio-ccw.h |  3 +++
 target/s390x/cpu-sysemu.c          |  8 --------
 target/s390x/cpu.h                 |  1 -
 4 files changed, 21 insertions(+), 13 deletions(-)
hw/s390x/s390-virtio-ccw.c +18 -4
index f4c4433b23..749d46e700 100644
@@ -45,6 +45,7 @@
 #include "migration/blocker.h"
 #include "qapi/visitor.h"
 #include "hw/s390x/cpu-topology.h"
+#include "kvm/kvm_s390x.h"
 #include CONFIG_DEVICES
 
 static Error *pv_mig_blocker;
@@ -121,12 +122,16 @@ static void subsystem_reset(void)
     }
 }
 
-static void set_memory_limit(uint64_t new_limit)
+static void s390_set_memory_limit(S390CcwMachineState *s390ms,
+                                  uint64_t new_limit)
 {
     uint64_t hw_limit;
-    int ret;
+    int ret = 0;
 
-    ret = s390_set_memory_limit(new_limit, &hw_limit);
+    assert(!s390ms->memory_limit && new_limit);
+    if (kvm_enabled()) {
+        ret = kvm_s390_set_mem_limit(new_limit, &hw_limit);
+    }
     if (ret == -E2BIG) {
         error_report("host supports a maximum of %" PRIu64 " GB",
                      hw_limit / GiB);
@@ -135,10 +140,19 @@ static void set_memory_limit(uint64_t new_limit)
         error_report("setting the guest size failed");
         exit(EXIT_FAILURE);
     }
+    s390ms->memory_limit = new_limit;
+}
+
+uint64_t s390_get_memory_limit(S390CcwMachineState *s390ms)
+{
+    /* We expect to be called only after the limit was set. */
+    assert(s390ms->memory_limit);
+    return s390ms->memory_limit;
 }
 
 static void s390_memory_init(MachineState *machine)
 {
+    S390CcwMachineState *s390ms = S390_CCW_MACHINE(machine);
     MemoryRegion *sysmem = get_system_memory();
     MemoryRegion *ram = machine->ram;
     uint64_t ram_size = memory_region_size(ram);
@@ -154,7 +168,7 @@ static void s390_memory_init(MachineState *machine)
         exit(EXIT_FAILURE);
     }
 
-    set_memory_limit(ram_size);
+    s390_set_memory_limit(s390ms, ram_size);
 
     /* Map the initial memory. Must happen after setting the memory limit. */
     memory_region_add_subregion(sysmem, 0, ram);
include/hw/s390x/s390-virtio-ccw.h +3 -0
index 996864a34e..eb04542979 100644
@@ -29,10 +29,13 @@ struct S390CcwMachineState {
     bool dea_key_wrap;
     bool pv;
     uint8_t loadparm[8];
+    uint64_t memory_limit;
 
     SCLPDevice *sclp;
 };
 
+uint64_t s390_get_memory_limit(S390CcwMachineState *s390ms);
+
 #define S390_PTF_REASON_NONE (0x00 << 8)
 #define S390_PTF_REASON_DONE (0x01 << 8)
 #define S390_PTF_REASON_BUSY (0x02 << 8)
target/s390x/cpu-sysemu.c +0 -8
index 1cd30c1d84..3118a25fee 100644
@@ -255,14 +255,6 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu)
     return s390_count_running_cpus();
 }
 
-int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit)
-{
-    if (kvm_enabled()) {
-        return kvm_s390_set_mem_limit(new_limit, hw_limit);
-    }
-    return 0;
-}
-
 void s390_set_max_pagesize(uint64_t pagesize, Error **errp)
 {
     if (kvm_enabled()) {
target/s390x/cpu.h +0 -1
index 5ef61b1f75..b4506539f0 100644
@@ -881,7 +881,6 @@ static inline void s390_do_cpu_load_normal(CPUState *cs, run_on_cpu_data arg)
 
 /* cpu.c */
 void s390_crypto_reset(void);
-int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit);
 void s390_set_max_pagesize(uint64_t pagesize, Error **errp);
 void s390_cmma_reset(void);
 void s390_enable_css_support(S390CPU *cpu);
Signature · 1 line
2.46.1
#8 lore raw

PATCH v2 7/14 s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT

In reply to David Hildenbrand

A guest OS that supports memory hotplug / memory devices must during boot be aware of the maximum possible physical memory address that it might have to handle at a later stage during its runtime.

For example, the maximum possible memory address might be required to prepare the kernel virtual address space accordingly (e.g., select page table hierarchy depth).

On s390x there is currently no such mechanism that is compatible with paravirtualized memory devices, because the whole SCLP interface was designed around the idea of "storage increments" and "standby memory". Paravirtualized memory devices we want to support, such as virtio-mem, have no intersection with any of that, but could co-exist with them in the future if ever needed.

In particular, a guest OS must never detect and use device memory without the help of a proper device driver. Device memory must not be exposed in any firmware-provided memory map (SCLP or diag260 on s390x). For this reason, these memory devices will be places in memory *above* the "maximum storage increment" exposed via SCLP.

Let's provide a new diag500 subcode to query the memory limit determined in s390_memory_init().

---
 hw/s390x/s390-hypercall.c | 12 +++++++++++-
 hw/s390x/s390-hypercall.h |  1 +
 2 files changed, 12 insertions(+), 1 deletion(-)
hw/s390x/s390-hypercall.c +11 -1
index f816c2b1ef..ac1b08b2cd 100644
@@ -11,7 +11,7 @@
 
 #include "qemu/osdep.h"
 #include "cpu.h"
-#include "hw/boards.h"
+#include "hw/s390x/s390-virtio-ccw.h"
 #include "hw/s390x/s390-hypercall.h"
 #include "hw/s390x/ioinst.h"
 #include "hw/s390x/css.h"
@@ -57,6 +57,13 @@ static int handle_virtio_ccw_notify(uint64_t subch_id, uint64_t data)
     return 0;
 }
 
+static uint64_t handle_storage_limit(void)
+{
+    S390CcwMachineState *s390ms = S390_CCW_MACHINE(qdev_get_machine());
+
+    return s390_get_memory_limit(s390ms) - 1;
+}
+
 void handle_diag_500(S390CPU *cpu, uintptr_t ra)
 {
     CPUS390XState *env = &cpu->env;
@@ -69,6 +76,9 @@ void handle_diag_500(S390CPU *cpu, uintptr_t ra)
     case DIAG500_VIRTIO_CCW_NOTIFY:
         env->regs[2] = handle_virtio_ccw_notify(env->regs[2], env->regs[3]);
         break;
+    case DIAG500_STORAGE_LIMIT:
+        env->regs[2] = handle_storage_limit();
+        break;
     default:
         s390_program_interrupt(env, PGM_SPECIFICATION, ra);
     }
hw/s390x/s390-hypercall.h +1 -0
index 2fa81dbfdd..4f07209128 100644
@@ -18,6 +18,7 @@
 #define DIAG500_VIRTIO_RESET            1 /* legacy */
 #define DIAG500_VIRTIO_SET_STATUS       2 /* legacy */
 #define DIAG500_VIRTIO_CCW_NOTIFY       3 /* KVM_S390_VIRTIO_CCW_NOTIFY */
+#define DIAG500_STORAGE_LIMIT           4
 
 void handle_diag_500(S390CPU *cpu, uintptr_t ra);
 
Signature · 1 line
2.46.1
#21 lore raw

PATCH v2 14/14 s390x: virtio-mem support

In reply to David Hildenbrand

Let's add our virtio-mem-ccw proxy device and wire it up. We should be supporting everything (e.g., device unplug, "dynamic-memslots") that we already support for the virtio-pci variant.

With a Linux guest that supports virtio-mem (and has automatic memory onlining properly configured) the following example will work:

1. Start a VM with 4G initial memory and a virtio-mem device with a maximum capacity of 16GB:

   qemu/build/qemu-system-s390x \
    --enable-kvm \
    -m 4G,maxmem=20G \
    -nographic \
    -smp 8 \
    -hda Fedora-Server-KVM-40-1.14.s390x.qcow2 \
    -chardev socket,id=monitor,path=/var/tmp/monitor,server,nowait \
    -mon chardev=monitor,mode=readline \
    -object memory-backend-ram,id=mem0,size=16G,reserve=off \
    -device virtio-mem-ccw,id=vmem0,memdev=mem0,dynamic-memslots=on

2. Query the current size of virtio-mem device:

    (qemu) info memory-devices
    Memory device [virtio-mem]: "vmem0"
      memaddr: 0x100000000
      node: 0
      requested-size: 0
      size: 0
      max-size: 17179869184
      block-size: 1048576
      memdev: /objects/mem0

3. Request to grow it to 8GB (hotplug 8GB):

    (qemu) qom-set vmem0 requested-size 8G
    (qemu) info memory-devices
    Memory device [virtio-mem]: "vmem0"
      memaddr: 0x100000000
      node: 0
      requested-size: 8589934592
      size: 8589934592
      max-size: 17179869184
      block-size: 1048576
      memdev: /objects/mem0

4. Request to grow to 16GB (hotplug another 8GB):

    (qemu) qom-set vmem0 requested-size 16G
    (qemu) info memory-devices
    Memory device [virtio-mem]: "vmem0"
      memaddr: 0x100000000
      node: 0
      requested-size: 17179869184
      size: 17179869184
      max-size: 17179869184
      block-size: 1048576
      memdev: /objects/mem0

5. Try to hotunplug all memory again, shrinking to 0GB:

    (qemu) qom-set vmem0 requested-size 0G
    (qemu) info memory-devices
    Memory device [virtio-mem]: "vmem0"
      memaddr: 0x100000000
      node: 0
      requested-size: 0
      size: 0
      max-size: 17179869184
      block-size: 1048576
      memdev: /objects/mem0

6. If it worked, unplug the device

(qemu) device_del vmem0
(qemu) info memory-devices
(qemu) object_del mem0

7. Hotplug a new device with a smaller capacity and directly size it to 1GB

    (qemu) object_add memory-backend-ram,id=mem0,size=8G,reserve=off
    (qemu) device_add virtio-mem-ccw,id=vmem0,memdev=mem0,\
                      dynamic-memslots=on,requested-size=1G
    (qemu) info memory-devices
    Memory device [virtio-mem]: "vmem0"
      memaddr: 0x100000000
      node: 0
      requested-size: 1073741824
      size: 1073741824
      max-size: 8589934592
      block-size: 1048576
      memdev: /objects/mem0

Trying to use a virtio-mem device backed by hugetlb into a !hugetlb VM correctly results in the error:
... Memory device uses a bigger page size than initial memory

Note that the virtio-mem driver in Linux will supports 1 MiB (pageblock) granularity.

---
 MAINTAINERS               |   2 +
 hw/s390x/Kconfig          |   1 +
 hw/s390x/meson.build      |   1 +
 hw/s390x/virtio-ccw-mem.c | 226 ++++++++++++++++++++++++++++++++++++++
 hw/s390x/virtio-ccw-mem.h |  34 ++++++
 hw/virtio/virtio-mem.c    |   4 +-
 6 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 hw/s390x/virtio-ccw-mem.c
 create mode 100644 hw/s390x/virtio-ccw-mem.h
MAINTAINERS +2 -0
index 1b337f52d1..1a5f6eeaf1 100644
@@ -2339,6 +2339,8 @@ W: https://virtio-mem.gitlab.io/
 F: hw/virtio/virtio-mem.c
 F: hw/virtio/virtio-mem-pci.h
 F: hw/virtio/virtio-mem-pci.c
+F: hw/s390x/virtio-ccw-mem.c
+F: hw/s390x/virtio-ccw-mem.h
 F: include/hw/virtio/virtio-mem.h
 
 virtio-snd
hw/s390x/Kconfig +1 -0
index 3bbf4ae56e..5d57daff77 100644
@@ -15,3 +15,4 @@ config S390_CCW_VIRTIO
     select SCLPCONSOLE
     select VIRTIO_CCW
     select MSI_NONBROKEN
+    select VIRTIO_MEM_SUPPORTED
hw/s390x/meson.build +1 -0
index 28bbe4b06c..094435cd3b 100644
@@ -49,6 +49,7 @@ virtio_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-ccw.c'))
 virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-ccw.c'))
 virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-ccw.c'))
 virtio_ss.add(when: 'CONFIG_VIRTIO_MD', if_true: files('virtio-ccw-md.c'))
+virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-ccw-mem.c'))
 s390x_ss.add_all(when: 'CONFIG_VIRTIO_CCW', if_true: virtio_ss)
 
 s390x_ss.add(when: 'CONFIG_VIRTIO_MD', if_false: files('virtio-ccw-md-stubs.c'))
hw/s390x/virtio-ccw-mem.c new file +226 -0

226 lines not on this page · raw message

hw/s390x/virtio-ccw-mem.h new file +34 -0
new file mode 100644
index 0000000000..738ab2c744
@@ -0,0 +1,34 @@
+/*
+ * Virtio MEM CCW device
+ *
+ * Copyright (C) 2024 Red Hat, Inc.
+ *
+ * Authors:
+ *  David Hildenbrand <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef HW_S390X_VIRTIO_CCW_MEM_H
+#define HW_S390X_VIRTIO_CCW_MEM_H
+
+#include "virtio-ccw-md.h"
+#include "hw/virtio/virtio-mem.h"
+#include "qom/object.h"
+
+typedef struct VirtIOMEMCcw VirtIOMEMCcw;
+
+/*
+ * virtio-mem-ccw: This extends VirtIOMDCcw
+ */
+#define TYPE_VIRTIO_MEM_CCW "virtio-mem-ccw"
+DECLARE_INSTANCE_CHECKER(VirtIOMEMCcw, VIRTIO_MEM_CCW, TYPE_VIRTIO_MEM_CCW)
+
+struct VirtIOMEMCcw {
+    VirtIOMDCcw parent_obj;
+    VirtIOMEM vdev;
+    Notifier size_change_notifier;
+};
+
+#endif /* HW_S390X_VIRTIO_CCW_MEM_H */
hw/virtio/virtio-mem.c +3 -1
index ae1e81d7ba..7885f6babb 100644
@@ -61,6 +61,8 @@ static uint32_t virtio_mem_default_thp_size(void)
     } else if (qemu_real_host_page_size() == 64 * KiB) {
         default_thp_size = 512 * MiB;
     }
+#elif defined(__s390x__)
+    default_thp_size = 1 * MiB;
 #endif
 
     return default_thp_size;
@@ -168,7 +170,7 @@ static bool virtio_mem_has_shared_zeropage(RAMBlock *rb)
  * necessary (as the section size can change). But it's more likely that the
  * section size will rather get smaller and not bigger over time.
  */
-#if defined(TARGET_X86_64) || defined(TARGET_I386)
+#if defined(TARGET_X86_64) || defined(TARGET_I386) || defined(TARGET_S390X)
 #define VIRTIO_MEM_USABLE_EXTENT (2 * (128 * MiB))
 #elif defined(TARGET_ARM)
 #define VIRTIO_MEM_USABLE_EXTENT (2 * (512 * MiB))
Signature · 1 line
2.46.1
#2 lore raw

PATCH v2 2/14 s390x/s390-virtio-hcall: remove hypercall registration mechanism

In reply to David Hildenbrand

Nowadays, we only have a single machine type in QEMU, everything is based on virtio-ccw and the traditional virtio machine does no longer exist. No need to dynamically register diag500 handlers. Move the two existing handlers into s390-virtio-hcall.c.

---
 hw/s390x/s390-virtio-ccw.c   | 58 --------------------------------
 hw/s390x/s390-virtio-hcall.c | 65 +++++++++++++++++++++++++++---------
 hw/s390x/s390-virtio-hcall.h |  2 --
 3 files changed, 49 insertions(+), 76 deletions(-)
hw/s390x/s390-virtio-ccw.c +0 -58
index b88ec8e78a..77f5d22203 100644
@@ -16,11 +16,8 @@
 #include "exec/ram_addr.h"
 #include "exec/confidential-guest-support.h"
 #include "hw/boards.h"
-#include "hw/s390x/s390-virtio-hcall.h"
 #include "hw/s390x/sclp.h"
 #include "hw/s390x/s390_flic.h"
-#include "hw/s390x/ioinst.h"
-#include "hw/s390x/css.h"
 #include "virtio-ccw.h"
 #include "qemu/config-file.h"
 #include "qemu/ctype.h"
@@ -124,58 +121,6 @@ static void subsystem_reset(void)
     }
 }
 
-static int virtio_ccw_hcall_notify(const uint64_t *args)
-{
-    uint64_t subch_id = args[0];
-    uint64_t data = args[1];
-    SubchDev *sch;
-    VirtIODevice *vdev;
-    int cssid, ssid, schid, m;
-    uint16_t vq_idx = data;
-
-    if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
-        return -EINVAL;
-    }
-    sch = css_find_subch(m, cssid, ssid, schid);
-    if (!sch || !css_subch_visible(sch)) {
-        return -EINVAL;
-    }
-
-    vdev = virtio_ccw_get_vdev(sch);
-    if (vq_idx >= VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, vq_idx)) {
-        return -EINVAL;
-    }
-
-    if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFICATION_DATA)) {
-        virtio_queue_set_shadow_avail_idx(virtio_get_queue(vdev, vq_idx),
-                                          (data >> 16) & 0xFFFF);
-    }
-
-    virtio_queue_notify(vdev, vq_idx);
-    return 0;
-}
-
-static int virtio_ccw_hcall_early_printk(const uint64_t *args)
-{
-    uint64_t mem = args[0];
-    MachineState *ms = MACHINE(qdev_get_machine());
-
-    if (mem < ms->ram_size) {
-        /* Early printk */
-        return 0;
-    }
-    return -EINVAL;
-}
-
-static void virtio_ccw_register_hcalls(void)
-{
-    s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
-                                   virtio_ccw_hcall_notify);
-    /* Tolerate early printk. */
-    s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
-                                   virtio_ccw_hcall_early_printk);
-}
-
 static void s390_memory_init(MemoryRegion *ram)
 {
     MemoryRegion *sysmem = get_system_memory();
@@ -302,9 +247,6 @@ static void ccw_init(MachineState *machine)
                               OBJECT(dev));
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
-    /* register hypercalls */
-    virtio_ccw_register_hcalls();
-
     s390_enable_css_support(s390_cpu_addr2state(0));
 
     ret = css_create_css_image(VIRTUAL_CSSID, true);
hw/s390x/s390-virtio-hcall.c +49 -16

80 lines not on this page · raw message

hw/s390x/s390-virtio-hcall.h +0 -2
index 3ae6d6ae3a..3d9fe147d2 100644
@@ -18,8 +18,6 @@
 /* The only thing that we need from the old kvm_virtio.h file */
 #define KVM_S390_VIRTIO_NOTIFY 0
 
-typedef int (*s390_virtio_fn)(const uint64_t *args);
-void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn);
 int s390_virtio_hypercall(CPUS390XState *env);
 
 #endif /* HW_S390_VIRTIO_HCALL_H */
Signature · 1 line
2.46.1
#9 lore raw

PATCH v2 8/14 s390x/s390-stattrib-kvm: prepare for memory devices and sparse memory layouts

In reply to David Hildenbrand

With memory devices, we will have storage attributes for memory that exceeds the initial ram size. Further, we can easily have memory holes, for which there (currently) are no storage attributes.

In particular, with memory holes, KVM_S390_SET_CMMA_BITS will fail to set some storage attributes.

So let's do it like we handle storage keys migration, relying on guest_phys_blocks_append(). However, in contrast to storage key migration, we will handle it on the migration destination.

This is a preparation for virtio-mem support. Note that ever since the "early migration" feature was added (x-early-migration), the state of device blocks (plugged/unplugged) is migrated early such that guest_phys_blocks_append() will properly consider all currently plugged memory blocks and skip any unplugged ones.

In the future, we should try getting rid of the large temporary buffer and also not send any attributes for any memory holes, just so they get ignored on the destination.

---
 hw/s390x/s390-stattrib-kvm.c | 67 +++++++++++++++++++++++-------------
 1 file changed, 43 insertions(+), 24 deletions(-)
hw/s390x/s390-stattrib-kvm.c +43 -24
index eeaa811098..33ec91422a 100644
@@ -10,11 +10,12 @@
  */
 
 #include "qemu/osdep.h"
-#include "hw/boards.h"
+#include "hw/s390x/s390-virtio-ccw.h"
 #include "migration/qemu-file.h"
 #include "hw/s390x/storage-attributes.h"
 #include "qemu/error-report.h"
 #include "sysemu/kvm.h"
+#include "sysemu/memory_mapping.h"
 #include "exec/ram_addr.h"
 #include "kvm/kvm_s390x.h"
 #include "qapi/error.h"
@@ -84,8 +85,8 @@ static int kvm_s390_stattrib_set_stattr(S390StAttribState *sa,
                                         uint8_t *values)
 {
     KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
-    MachineState *machine = MACHINE(qdev_get_machine());
-    unsigned long max = machine->ram_size / TARGET_PAGE_SIZE;
+    S390CcwMachineState *s390ms = S390_CCW_MACHINE(qdev_get_machine());
+    unsigned long max = s390_get_memory_limit(s390ms) / TARGET_PAGE_SIZE;
 
     if (start_gfn + count > max) {
         error_report("Out of memory bounds when setting storage attributes");
@@ -103,39 +104,57 @@ static int kvm_s390_stattrib_set_stattr(S390StAttribState *sa,
 static void kvm_s390_stattrib_synchronize(S390StAttribState *sa)
 {
     KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa);
-    MachineState *machine = MACHINE(qdev_get_machine());
-    unsigned long max = machine->ram_size / TARGET_PAGE_SIZE;
-    /* We do not need to reach the maximum buffer size allowed */
-    unsigned long cx, len = KVM_S390_SKEYS_MAX / 2;
+    S390CcwMachineState *s390ms = S390_CCW_MACHINE(qdev_get_machine());
+    unsigned long max = s390_get_memory_limit(s390ms) / TARGET_PAGE_SIZE;
+    unsigned long start_gfn, end_gfn, pages;
+    GuestPhysBlockList guest_phys_blocks;
+    GuestPhysBlock *block;
     int r;
     struct kvm_s390_cmma_log clog = {
         .flags = 0,
         .mask = ~0ULL,
     };
 
-    if (sas->incoming_buffer) {
-        for (cx = 0; cx + len <= max; cx += len) {
-            clog.start_gfn = cx;
-            clog.count = len;
-            clog.values = (uint64_t)(sas->incoming_buffer + cx);
-            r = kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog);
-            if (r) {
-                error_report("KVM_S390_SET_CMMA_BITS failed: %s", strerror(-r));
-                return;
-            }
-        }
-        if (cx < max) {
-            clog.start_gfn = cx;
-            clog.count = max - cx;
-            clog.values = (uint64_t)(sas->incoming_buffer + cx);
+    if (!sas->incoming_buffer) {
+        return;
+    }
+    guest_phys_blocks_init(&guest_phys_blocks);
+    guest_phys_blocks_append(&guest_phys_blocks);
+
+    QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) {
+        assert(QEMU_IS_ALIGNED(block->target_start, TARGET_PAGE_SIZE));
+        assert(QEMU_IS_ALIGNED(block->target_end, TARGET_PAGE_SIZE));
+
+        start_gfn = block->target_start / TARGET_PAGE_SIZE;
+        end_gfn = block->target_end / TARGET_PAGE_SIZE;
+
+        while (start_gfn < end_gfn) {
+            /* Don't exceed the maximum buffer size. */
+            pages = MIN(end_gfn - start_gfn, KVM_S390_SKEYS_MAX / 2);
+
+            /*
+             * If we ever get guest physical memory beyond the configured
+             * memory limit, something went very wrong.
+             */
+            assert(start_gfn + pages <= max);
+
+            clog.start_gfn = start_gfn;
+            clog.count = pages;
+            clog.values = (uint64_t)(sas->incoming_buffer + start_gfn);
             r = kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog);
             if (r) {
                 error_report("KVM_S390_SET_CMMA_BITS failed: %s", strerror(-r));
+                goto out;
             }
+
+            start_gfn += pages;
         }
-        g_free(sas->incoming_buffer);
-        sas->incoming_buffer = NULL;
     }
+
+out:
+    guest_phys_blocks_free(&guest_phys_blocks);
+    g_free(sas->incoming_buffer);
+    sas->incoming_buffer = NULL;
 }
 
 static int kvm_s390_stattrib_set_migrationmode(S390StAttribState *sa, bool val,
Signature · 1 line
2.46.1
#18 lore raw

PATCH v2 12/14 s390x: remember the maximum page size

In reply to David Hildenbrand

Let's remember the value (successfully) set via s390_set_max_pagesize(). This will be helpful to reject hotplugged memory devices that would exceed this initially set page size.

Handle it just like how we handle s390_get_memory_limit(), storing it in the machine, and moving the handling to machine code.

---
 hw/s390x/s390-virtio-ccw.c         | 12 +++++++++++-
 include/hw/s390x/s390-virtio-ccw.h |  1 +
 target/s390x/cpu-sysemu.c          |  7 -------
 target/s390x/cpu.h                 |  1 -
 4 files changed, 12 insertions(+), 9 deletions(-)
hw/s390x/s390-virtio-ccw.c +11 -1
index 2031c4cf29..65f266a78f 100644
@@ -150,6 +150,16 @@ uint64_t s390_get_memory_limit(S390CcwMachineState *s390ms)
     return s390ms->memory_limit;
 }
 
+static void s390_set_max_pagesize(S390CcwMachineState *s390ms,
+                                  uint64_t pagesize)
+{
+    assert(!s390ms->max_pagesize && pagesize);
+    if (kvm_enabled()) {
+        kvm_s390_set_max_pagesize(pagesize, &error_fatal);
+    }
+    s390ms->max_pagesize = pagesize;
+}
+
 static void s390_memory_init(MachineState *machine)
 {
     S390CcwMachineState *s390ms = S390_CCW_MACHINE(machine);
@@ -198,7 +208,7 @@ static void s390_memory_init(MachineState *machine)
      * Configure the maximum page size. As no memory devices were created
      * yet, this is the page size of initial memory only.
      */
-    s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal);
+    s390_set_max_pagesize(s390ms, qemu_maxrampagesize());
     /* Initialize storage key device */
     s390_skeys_init();
     /* Initialize storage attributes device */
include/hw/s390x/s390-virtio-ccw.h +1 -0
index eb04542979..5a730f5d07 100644
@@ -30,6 +30,7 @@ struct S390CcwMachineState {
     bool pv;
     uint8_t loadparm[8];
     uint64_t memory_limit;
+    uint64_t max_pagesize;
 
     SCLPDevice *sclp;
 };
target/s390x/cpu-sysemu.c +0 -7
index 3118a25fee..706a5c53e2 100644
@@ -255,13 +255,6 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu)
     return s390_count_running_cpus();
 }
 
-void s390_set_max_pagesize(uint64_t pagesize, Error **errp)
-{
-    if (kvm_enabled()) {
-        kvm_s390_set_max_pagesize(pagesize, errp);
-    }
-}
-
 void s390_cmma_reset(void)
 {
     if (kvm_enabled()) {
target/s390x/cpu.h +0 -1
index b4506539f0..5b7992deda 100644
@@ -881,7 +881,6 @@ static inline void s390_do_cpu_load_normal(CPUState *cs, run_on_cpu_data arg)
 
 /* cpu.c */
 void s390_crypto_reset(void);
-void s390_set_max_pagesize(uint64_t pagesize, Error **errp);
 void s390_cmma_reset(void);
 void s390_enable_css_support(S390CPU *cpu);
 void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg);
Signature · 1 line
2.46.1
#17 lore raw

PATCH v2 11/14 s390x/pv: prepare for memory devices

In reply to David Hildenbrand

Let's avoid checking for the maxram_size, and instead rely on the memory limit determined in s390_memory_init(), that might be larger than maxram_size, for example due to alignment purposes.

This check now correctly mimics what the kernel will check in kvm_s390_pv_set_aside(), whereby a VM <= 2 GiB VM would end up using a segment type ASCE.

---
 target/s390x/kvm/pv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/kvm/pv.c +1 -1
index 424cce75ca..fa66607e7b 100644
@@ -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)->ram_size <= 2 * GiB) ||
+    if (s390_get_memory_limit(ms) <= 2 * GiB ||
         !kvm_check_extension(kvm_state, KVM_CAP_S390_PROTECTED_ASYNC_DISABLE)) {
         return false;
     }
Signature · 1 line
2.46.1
#11 lore raw

PATCH v2 9/14 s390x/s390-skeys: prepare for memory devices

In reply to David Hildenbrand

With memory devices, we will have storage keys for memory that exceeds the initial ram size.

The TODO already states that current handling is subopimal, but we won't worry about improving that (TCG-only) thing for now.

---
 hw/s390x/s390-skeys.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/s390x/s390-skeys.c +3 -3
index bf22d6863e..e4297b3b8a 100644
@@ -11,7 +11,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/units.h"
-#include "hw/boards.h"
+#include "hw/s390x/s390-virtio-ccw.h"
 #include "hw/qdev-properties.h"
 #include "hw/s390x/storage-keys.h"
 #include "qapi/error.h"
@@ -251,9 +251,9 @@ static bool qemu_s390_enable_skeys(S390SKeysState *ss)
      *    g_once_init_enter() is good enough.
      */
     if (g_once_init_enter(&initialized)) {
-        MachineState *machine = MACHINE(qdev_get_machine());
+        S390CcwMachineState *s390ms = S390_CCW_MACHINE(qdev_get_machine());
 
-        skeys->key_count = machine->ram_size / TARGET_PAGE_SIZE;
+        skeys->key_count = s390_get_memory_limit(s390ms) / TARGET_PAGE_SIZE;
         skeys->keydata = g_malloc0(skeys->key_count);
         g_once_init_leave(&initialized, 1);
     }
Signature · 1 line
2.46.1
#20 lore raw

PATCH v2 13/14 s390x/virtio-ccw: add support for virtio based memory devices

In reply to David Hildenbrand

Let's implement support for abstract virtio based memory devices, using the virtio-pci implementation as an orientation. Wire them up in the machine hotplug handler, taking care of s390x page size limitations.

As we neither support virtio-mem or virtio-pmem yet, the code is effectively unused. We'll implement support for virtio-mem based on this next.

Note that we won't wire up the virtio-pci variant (should currently be impossible due to lack of support for MSI-X), but we'll add a safety net to reject plugging them in the pre-plug handler.

---
 MAINTAINERS                    |   3 +
 hw/s390x/meson.build           |   3 +
 hw/s390x/s390-virtio-ccw.c     |  47 +++++++++-
 hw/s390x/virtio-ccw-md-stubs.c |  24 ++++++
 hw/s390x/virtio-ccw-md.c       | 153 +++++++++++++++++++++++++++++++++
 hw/s390x/virtio-ccw-md.h       |  44 ++++++++++
 hw/virtio/Kconfig              |   1 +
 7 files changed, 274 insertions(+), 1 deletion(-)
 create mode 100644 hw/s390x/virtio-ccw-md-stubs.c
 create mode 100644 hw/s390x/virtio-ccw-md.c
 create mode 100644 hw/s390x/virtio-ccw-md.h
MAINTAINERS +3 -0
index d7a11fe601..1b337f52d1 100644
@@ -2325,6 +2325,9 @@ F: include/hw/virtio/virtio-crypto.h
 virtio based memory device
 M: David Hildenbrand <[email protected]>
 S: Supported
+F: hw/s390x/virtio-ccw-md.c
+F: hw/s390x/virtio-ccw-md.h
+F: hw/s390x/virtio-ccw-md-stubs.c
 F: hw/virtio/virtio-md-pci.c
 F: include/hw/virtio/virtio-md-pci.h
 F: stubs/virtio-md-pci.c
hw/s390x/meson.build +3 -0
index 71ec747f4c..28bbe4b06c 100644
@@ -48,8 +48,11 @@ endif
 virtio_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-ccw.c'))
 virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-ccw.c'))
 virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-ccw.c'))
+virtio_ss.add(when: 'CONFIG_VIRTIO_MD', if_true: files('virtio-ccw-md.c'))
 s390x_ss.add_all(when: 'CONFIG_VIRTIO_CCW', if_true: virtio_ss)
 
+s390x_ss.add(when: 'CONFIG_VIRTIO_MD', if_false: files('virtio-ccw-md-stubs.c'))
+
 hw_arch += {'s390x': s390x_ss}
 
 hw_s390x_modules = {}
hw/s390x/s390-virtio-ccw.c +46 -1

87 lines not on this page · raw message

hw/s390x/virtio-ccw-md-stubs.c new file +24 -0
new file mode 100644
index 0000000000..e937865550
@@ -0,0 +1,24 @@
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/s390x/virtio-ccw-md.h"
+
+void virtio_ccw_md_pre_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp)
+{
+    error_setg(errp, "virtio based memory devices not supported");
+}
+
+void virtio_ccw_md_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp)
+{
+    error_setg(errp, "virtio based memory devices not supported");
+}
+
+void virtio_ccw_md_unplug_request(VirtIOMDCcw *vmd, MachineState *ms,
+                                  Error **errp)
+{
+    error_setg(errp, "virtio based memory devices not supported");
+}
+
+void virtio_ccw_md_unplug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp)
+{
+    error_setg(errp, "virtio based memory devices not supported");
+}
hw/s390x/virtio-ccw-md.c new file +153 -0

153 lines not on this page · raw message

hw/s390x/virtio-ccw-md.h new file +44 -0

44 lines not on this page · raw message

hw/virtio/Kconfig +1 -0
index 17595ff350..653ddfdfa8 100644
@@ -25,6 +25,7 @@ config VIRTIO_MMIO
 config VIRTIO_CCW
     bool
     select VIRTIO
+    select VIRTIO_MD_SUPPORTED
 
 config VIRTIO_BALLOON
     bool
Signature · 1 line
2.46.1
#13 lore raw

PATCH v2 10/14 s390x/s390-virtio-ccw: prepare for memory devices

In reply to David Hildenbrand

Let's prepare our address space for memory devices if enabled via "maxmem" and if we have CONFIG_MEM_DEVICE enabled at all. Note that CONFIG_MEM_DEVICE will be selected automatically once we add support for devices.

Just like on other architectures, the region container for memory devices is placed directly above our initial memory. For now, we only align the start address of the region up to 1 GiB, but we won't add any additional space to the region for internal alignment purposes; this can be done in the future if really required.

The RAM size returned via SCLP is not modified, as this only covers initial RAM (and standby memory we don't implement) and not memory devices; clarify that in the docs of read_SCP_info(). Existing OSes without support for memory devices will keep working as is, even when memory devices would be attached the VM.

Guest OSs which support memory devices, such as virtio-mem, will consult diag500(), to find out the maximum possible pfn. Guest OSes that don't support memory devices, don't have to be changed and will continue relying on information provided by SCLP.

There are no remaining maxram_size users in s390x code, and the remaining ram_size users only care about initial RAM:
* hw/s390x/ipl.c
* hw/s390x/s390-hypercall.c
* hw/s390x/sclp.c
* target/s390x/kvm/pv.c

---
 hw/s390x/s390-virtio-ccw.c | 23 ++++++++++++++++++++++-
 hw/s390x/sclp.c            |  6 +++++-
 2 files changed, 27 insertions(+), 2 deletions(-)
hw/s390x/s390-virtio-ccw.c +22 -1
index 749d46e700..2031c4cf29 100644
@@ -156,6 +156,7 @@ static void s390_memory_init(MachineState *machine)
     MemoryRegion *sysmem = get_system_memory();
     MemoryRegion *ram = machine->ram;
     uint64_t ram_size = memory_region_size(ram);
+    uint64_t devmem_base, devmem_size;
 
     if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) {
         /*
@@ -168,11 +169,31 @@ static void s390_memory_init(MachineState *machine)
         exit(EXIT_FAILURE);
     }
 
-    s390_set_memory_limit(s390ms, ram_size);
+    devmem_size = 0;
+    devmem_base = ram_size;
+#ifdef CONFIG_MEM_DEVICE
+    if (machine->ram_size < machine->maxram_size) {
+
+        /*
+         * Make sure memory devices have a sane default alignment, even
+         * when weird initial memory sizes are specified.
+         */
+        devmem_base = QEMU_ALIGN_UP(devmem_base, 1 * GiB);
+        devmem_size = machine->maxram_size - machine->ram_size;
+    }
+#endif
+    s390_set_memory_limit(s390ms, devmem_base + devmem_size);
 
     /* Map the initial memory. Must happen after setting the memory limit. */
     memory_region_add_subregion(sysmem, 0, ram);
 
+    /* Initialize address space for memory devices. */
+#ifdef CONFIG_MEM_DEVICE
+    if (devmem_size) {
+        machine_memory_devices_init(machine, devmem_base, devmem_size);
+    }
+#endif /* CONFIG_MEM_DEVICE */
+
     /*
      * Configure the maximum page size. As no memory devices were created
      * yet, this is the page size of initial memory only.
hw/s390x/sclp.c +5 -1
index fac09816bf..fe4216a10d 100644
@@ -162,7 +162,11 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
         read_info->rnsize2 = cpu_to_be32(rnsize);
     }
 
-    /* we don't support standby memory, maxram_size is never exposed */
+    /*
+     * We don't support standby memory. maxram_size is used for sizing the
+     * memory device region, which is not exposed through SCLP but through
+     * diag500.
+     */
     rnmax = machine->ram_size >> sclp->increment_size;
     if (rnmax < 0x10000) {
         read_info->rnmax = cpu_to_be16(rnmax);
Signature · 1 line
2.46.1
Tested-by on the v2 series
#22 lore raw
In reply to David Hildenbrand

This series has been successfully tested in s390x. Booted up a VM including:

/home/qemu/build/qemu-system-s390x \
...
-m 4G,maxmem=20G \
-object memory-backend-ram,id=mem0,size=16G,reserve=off \
-device virtio-mem-ccw,id=vmem0,memdev=mem0,dynamic-memslots=on \
...

Check the memory devices
(qemu) info memory-devices
Memory device [virtio-mem]: "vmem0"
memaddr: 0x100000000
node: 0
requested-size: 0
size: 0
max-size: 17179869184
block-size: 1048576
memdev: /objects/mem0

Hotplug memory to the maximum
(qemu) qom-set vmem0 requested-size 16G
(qemu) info memory-devices
Memory device [virtio-mem]: "vmem0"
memaddr: 0x100000000
node: 0
requested-size: 17179869184
size: 17179869184
max-size: 17179869184
block-size: 1048576
memdev: /objects/mem0

Try to unplug the device, check the error message is correct (qemu) device_del vmem0
Error: virtio-mem device cannot get unplugged while some of its memory is still plugged

Reduce the memory till 0 and device is successfully unplugged (qemu) qom-set vmem0 requested-size 0
(qemu) device_del vmem0
(qemu) object_del mem0

Hotplug again the device
(qemu) object_add memory-backend-ram,id=mem0,size=8G,reserve=off (qemu) device_add virtio-mem-ccw,id=vmem0,memdev=mem0,dynamic-memslots=on,requested-size=1G (qemu) info memory-devices
Memory device [virtio-mem]: "vmem0"
memaddr: 0x100000000
node: 0
requested-size: 1073741824
size: 1073741824
max-size: 8589934592
block-size: 1048576
memdev: /objects/mem0

Finally, add some extra memory and check the memslots (qemu) qom-set vmem0 requested-size 4G
(qemu) info mtree
...

    0000000100000000-00000002ffffffff (prio 0, i/o): virtio-mem
      0000000100000000-000000013fffffff (prio 0, ram): alias memslot-0
@mem0 0000000000000000-000000003fffffff
      0000000140000000-000000017fffffff (prio 0, ram): alias memslot-1
@mem0 0000000040000000-000000007fffffff
      0000000180000000-00000001bfffffff (prio 0, ram): alias memslot-2
@mem0 0000000080000000-00000000bfffffff
      00000001c0000000-00000001ffffffff (prio 0, ram): alias memslot-3

@mem0 00000000c0000000-00000000ffffffff

Quoted 138 lines · David Hildenbrand

Based on current master.

There is really not much left to do on s390x, because virtio-mem already implements most things we need today (e.g., early-migration, unplugged-inaccessible). The biggest part of this series is just doing what we do with virtio-pci, wiring it up in the machine hotplug handler and ... well, messing with the physical memory layout where we can now exceed initial RAM size and have sparsity (memory holes).

I tested a lot of things, including:
* Memory hotplug/unplug
* Device hotplug/unplug
* System resets / reboots
* Migrate to/from file (including storage attributes under KVM)
* Basic live migration
* Basic postcopy live migration

More details on how to use it on s390x -- which is pretty much how we use it on other architectures, except s/virtio-mem-pci/virtio-mem-ccw/ --- is in the last patch.

This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented in the kernel and at [2] once this+kernel part go upstream.

There are not many s390x-specific virtio-mem future work items, except:
* Storage attribute migration might be improved
* We might want to reset storage attributes of unplugged memory (might or might not be required for upcoming page table reclaim in Linux; TBD)

The Linux driver is available at [3].

[1] https://lkml.kernel.org/r/[email protected]
[2] https://gitlab.com/davidhildenbrand/s390x-os-virt-spec
[3] https://lkml.kernel.org/r/[email protected]

v1 -> v2:
* "s390x/s390-virtio-hcall: prepare for more diag500 hypercalls"
- Turn handle_diag_500() into a void function
- Inject PGM_SPECIFICATION from handle_diag_500() directly
* "s390x/s390-virtio-ccw: move setting the maximum guest size from sclp to machine code"
- Move code to a new function to make further changes easier
- Adjust s390_pv_vm_try_disable_async() to stay in sync with the maxram->ram change
* "s390x: introduce s390_get_memory_limit()"
- Store limit in machine
- Move s390_set_memory_limit() from target code into machine code
* "s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT"
- Move handling into a separate function now that we lookup the machine
* "s390x/s390-stattrib-kvm: prepare for memory devices and sparse memory layouts"
- Adjust to s390_get_memory_limit() changes
* "s390x/s390-skeys: prepare for memory devices"
- Adjust to s390_get_memory_limit() changes
* "s390x/pv: prepare for memory devices"
- Use s390_get_memory_limit()
* "s390x: remember the maximum page size"
- Store it in the machine
- Move s390_set_max_pagesize() from target code into machine code
- No need for s390_get_max_pagesize()
* "s390x/virtio-ccw: add support for virtio based memory devices"
- Move machine wire-up code from virtio-mem patch into this patch
- Add stubs to make compilation without virtio-mem work
* "s390x: virtio-mem support"
- Move machine write-up code to previous patch

Cc Paolo Bonzini <[email protected]>
Cc Thomas Huth <[email protected]>
Cc Halil Pasic <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc Eric Farman <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Nina Schoetterl-Glausch <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Ilya Leoshkevich <[email protected]>
Cc Janosch Frank <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Cornelia Huck <[email protected]>

David Hildenbrand (14):
s390x/s390-virtio-ccw: don't crash on weird RAM sizes s390x/s390-virtio-hcall: remove hypercall registration mechanism s390x/s390-virtio-hcall: prepare for more diag500 hypercalls
s390x: rename s390-virtio-hcall* to s390-hypercall* s390x/s390-virtio-ccw: move setting the maximum guest size from sclp
to machine code
s390x: introduce s390_get_memory_limit() s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT s390x/s390-stattrib-kvm: prepare for memory devices and sparse memory
layouts
s390x/s390-skeys: prepare for memory devices s390x/s390-virtio-ccw: prepare for memory devices s390x/pv: prepare for memory devices
s390x: remember the maximum page size
s390x/virtio-ccw: add support for virtio based memory devices
s390x: virtio-mem support

 MAINTAINERS                        |   5 +
 hw/s390x/Kconfig                   |   1 +
 hw/s390x/meson.build               |   6 +-
 hw/s390x/s390-hypercall.c          |  85 +++++++++++
 hw/s390x/s390-hypercall.h          |  25 ++++
 hw/s390x/s390-skeys.c              |   6 +-
 hw/s390x/s390-stattrib-kvm.c       |  67 ++++++---
 hw/s390x/s390-virtio-ccw.c         | 165 ++++++++++++++-------
 hw/s390x/s390-virtio-hcall.c       |  41 ------
 hw/s390x/s390-virtio-hcall.h       |  25 ----
 hw/s390x/sclp.c                    |  17 +--
 hw/s390x/virtio-ccw-md-stubs.c     |  24 +++
 hw/s390x/virtio-ccw-md.c           | 153 +++++++++++++++++++
 hw/s390x/virtio-ccw-md.h           |  44 ++++++
 hw/s390x/virtio-ccw-mem.c          | 226 +++++++++++++++++++++++++++++
 hw/s390x/virtio-ccw-mem.h          |  34 +++++
 hw/virtio/Kconfig                  |   1 +
 hw/virtio/virtio-mem.c             |   4 +-
 include/hw/s390x/s390-virtio-ccw.h |   4 +
 target/s390x/cpu-sysemu.c          |  15 --
 target/s390x/cpu.h                 |   2 -
 target/s390x/kvm/kvm.c             |  18 +--
 target/s390x/kvm/pv.c              |   2 +-
 target/s390x/tcg/misc_helper.c     |   7 +-
 24 files changed, 782 insertions(+), 195 deletions(-)
 create mode 100644 hw/s390x/s390-hypercall.c
 create mode 100644 hw/s390x/s390-hypercall.h
 delete mode 100644 hw/s390x/s390-virtio-hcall.c
 delete mode 100644 hw/s390x/s390-virtio-hcall.h
 create mode 100644 hw/s390x/virtio-ccw-md-stubs.c
 create mode 100644 hw/s390x/virtio-ccw-md.c
 create mode 100644 hw/s390x/virtio-ccw-md.h
 create mode 100644 hw/s390x/virtio-ccw-mem.c
 create mode 100644 hw/s390x/virtio-ccw-mem.h

--
2.46.1

Reviewed-by on v2 6/14
#7 lore raw

Re: [PATCH v2 06/14] s390x: introduce s390_get_memory_limit()

In reply to David Hildenbrand
Quoted 10 lines · David Hildenbrand

Let's add s390_get_memory_limit(), to query what has been successfully set via s390_set_memory_limit(). Allow setting the limit only once.

We'll remember the limit in the machine state. Move s390_set_memory_limit() to machine code, merging it into set_memory_limit(), because this really is a machine property.

---

Reviewed-by on v2 8/14
#10 lore raw

Re: [PATCH v2 08/14] s390x/s390-stattrib-kvm: prepare for memory devices and sparse memory layouts

In reply to David Hildenbrand
Quoted 21 lines · David Hildenbrand

With memory devices, we will have storage attributes for memory that exceeds the initial ram size. Further, we can easily have memory holes, for which there (currently) are no storage attributes.

In particular, with memory holes, KVM_S390_SET_CMMA_BITS will fail to set some storage attributes.

So let's do it like we handle storage keys migration, relying on guest_phys_blocks_append(). However, in contrast to storage key migration, we will handle it on the migration destination.

This is a preparation for virtio-mem support. Note that ever since the "early migration" feature was added (x-early-migration), the state of device blocks (plugged/unplugged) is migrated early such that guest_phys_blocks_append() will properly consider all currently plugged memory blocks and skip any unplugged ones.

In the future, we should try getting rid of the large temporary buffer and also not send any attributes for any memory holes, just so they get ignored on the destination.

Quoted 5 lines
---
  hw/s390x/s390-stattrib-kvm.c | 67 +++++++++++++++++++++++-------------
  1 file changed, 43 insertions(+), 24 deletions(-)
#23 lore raw
In reply to David Hildenbrand
Quoted 30 lines · David Hildenbrand

Based on current master.

There is really not much left to do on s390x, because virtio-mem already implements most things we need today (e.g., early-migration, unplugged-inaccessible). The biggest part of this series is just doing what we do with virtio-pci, wiring it up in the machine hotplug handler and ... well, messing with the physical memory layout where we can now exceed initial RAM size and have sparsity (memory holes).

I tested a lot of things, including:
* Memory hotplug/unplug
* Device hotplug/unplug
* System resets / reboots
* Migrate to/from file (including storage attributes under KVM)
* Basic live migration
* Basic postcopy live migration

More details on how to use it on s390x -- which is pretty much how we use it on other architectures, except s/virtio-mem-pci/virtio-mem-ccw/ --- is in the last patch.

This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented in the kernel and at [2] once this+kernel part go upstream.

There are not many s390x-specific virtio-mem future work items, except:
* Storage attribute migration might be improved
* We might want to reset storage attributes of unplugged memory (might or might not be required for upcoming page table reclaim in Linux; TBD)

Quoted 5 lines

The Linux driver is available at [3].

[1] https://lkml.kernel.org/r/[email protected]
[2] https://gitlab.com/davidhildenbrand/s390x-os-virt-spec
[3] https://lkml.kernel.org/r/[email protected]

Gentle ping (and thanks to Thomas for the review!).

I assume the kernel portion will go upstream in the next merge window. I'd like get the QEMU parts merged soon after that.

9.2 is going to get released in roughly one month, so there is still time.

@Thomas, this is mostly s390x stuff, so I guess it should go through the s390x tree? But I could also take this through my "memory devices" tree.

Signature · 3 lines
Cheers,

David / dhildenb
#24 lore raw
Quoted 37 lines · David Hildenbrand
Quoted 30 lines · David Hildenbrand

Based on current master.

There is really not much left to do on s390x, because virtio-mem already implements most things we need today (e.g., early-migration, unplugged-inaccessible). The biggest part of this series is just doing what we do with virtio-pci, wiring it up in the machine hotplug handler and ... well, messing with the physical memory layout where we can now exceed initial RAM size and have sparsity (memory holes).

I tested a lot of things, including:
* Memory hotplug/unplug
* Device hotplug/unplug
* System resets / reboots
* Migrate to/from file (including storage attributes under KVM)
* Basic live migration
* Basic postcopy live migration

More details on how to use it on s390x -- which is pretty much how we use it on other architectures, except s/virtio-mem-pci/virtio-mem-ccw/ --- is in the last patch.

This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented in the kernel and at [2] once this+kernel part go upstream.

There are not many s390x-specific virtio-mem future work items, except:
* Storage attribute migration might be improved
* We might want to reset storage attributes of unplugged memory (might or might not be required for upcoming page table reclaim in Linux; TBD)

Quoted 5 lines

The Linux driver is available at [3].

[1] https://lkml.kernel.org/r/[email protected]
[2] https://gitlab.com/davidhildenbrand/s390x-os-virt-spec
[3] https://lkml.kernel.org/r/[email protected]

Quoted 6 lines

Gentle ping (and thanks to Thomas for the review!).

I assume the kernel portion will go upstream in the next merge window. I'd like get the QEMU parts merged soon after that.

9.2 is going to get released in roughly one month, so there is still time.

In the meantime, 9.2 was released. I don't have any changes planned. Series still applies to current master, I'll do a quick test tomorrow.

Quoted 4 lines

@Thomas, this is mostly s390x stuff, so I guess it should go through the s390x tree? But I could also take this through my "memory devices" tree.

@Thomas, any thoughts?

Signature · 3 lines
Cheers,

David / dhildenb
#25 lore raw
Quoted 45 lines · David Hildenbrand
Quoted 37 lines · David Hildenbrand
Quoted 30 lines · David Hildenbrand

Based on current master.

There is really not much left to do on s390x, because virtio-mem already implements most things we need today (e.g., early-migration, unplugged-inaccessible). The biggest part of this series is just doing what we do with virtio-pci, wiring it up in the machine hotplug handler and ... well, messing with the physical memory layout where we can now exceed initial RAM size and have sparsity (memory holes).

I tested a lot of things, including:
   * Memory hotplug/unplug
   * Device hotplug/unplug
   * System resets / reboots
   * Migrate to/from file (including storage attributes under KVM)
   * Basic live migration
   * Basic postcopy live migration

More details on how to use it on s390x -- which is pretty much how we use it on other architectures, except s/virtio-mem-pci/virtio-mem-ccw/ --- is in the last patch.

This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented in the kernel and at [2] once this+kernel part go upstream.

There are not many s390x-specific virtio-mem future work items, except:
* Storage attribute migration might be improved
* We might want to reset storage attributes of unplugged memory (might or might not be required for upcoming page table reclaim in Linux; TBD)

Quoted 5 lines

The Linux driver is available at [3].

[1] https://lkml.kernel.org/r/[email protected]
[2] https://gitlab.com/davidhildenbrand/s390x-os-virt-spec
[3] https://lkml.kernel.org/r/[email protected]

Quoted 6 lines

Gentle ping (and thanks to Thomas for the review!).

I assume the kernel portion will go upstream in the next merge window. I'd like get the QEMU parts merged soon after that.

9.2 is going to get released in roughly one month, so there is still time.

Quoted 7 lines

In the meantime, 9.2 was released. I don't have any changes planned. Series still applies to current master, I'll do a quick test tomorrow.

Quoted 3 lines

@Thomas, this is mostly s390x stuff, so I guess it should go through the s390x tree? But I could also take this through my "memory devices" tree.

@Thomas, any thoughts?

I'm fine either way - feel free to put it into your tree, otherwise I'll pick it up likely sometime next week.

Thomas

Reviewed-by on v2 9/14
#12 lore raw

Re: [PATCH v2 09/14] s390x/s390-skeys: prepare for memory devices

In reply to David Hildenbrand
Quoted 27 lines · David Hildenbrand

With memory devices, we will have storage keys for memory that exceeds the initial ram size.

The TODO already states that current handling is subopimal, but we won't worry about improving that (TCG-only) thing for now.

---
  hw/s390x/s390-skeys.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
hw/s390x/s390-skeys.c +1 -1
index bf22d6863e..e4297b3b8a 100644
@@ -11,7 +11,7 @@
 
  #include "qemu/osdep.h"
  #include "qemu/units.h"
-#include "hw/boards.h"
+#include "hw/s390x/s390-virtio-ccw.h"
  #include "hw/qdev-properties.h"
  #include "hw/s390x/storage-keys.h"
  #include "qapi/error.h"
@@ -251,9 +251,9 @@ static bool qemu_s390_enable_skeys(S390SKeysState *ss)
       *    g_once_init_enter() is good enough.

hw/s390x/s390-skeys.c static bool qemu_s390_enable_skeys(S390SKeysState *ss) · line 259

Quoted 10 lines
hw/s390x/s390-skeys.c +2 -2
       */
      if (g_once_init_enter(&initialized)) {
-        MachineState *machine = MACHINE(qdev_get_machine());
+        S390CcwMachineState *s390ms = S390_CCW_MACHINE(qdev_get_machine());
 
-        skeys->key_count = machine->ram_size / TARGET_PAGE_SIZE;
+        skeys->key_count = s390_get_memory_limit(s390ms) / TARGET_PAGE_SIZE;
          skeys->keydata = g_malloc0(skeys->key_count);
          g_once_init_leave(&initialized, 1);
      }
#14 lore raw

Re: [PATCH v2 10/14] s390x/s390-virtio-ccw: prepare for memory devices

In reply to David Hildenbrand
Quoted 54 lines · David Hildenbrand

Let's prepare our address space for memory devices if enabled via "maxmem" and if we have CONFIG_MEM_DEVICE enabled at all. Note that CONFIG_MEM_DEVICE will be selected automatically once we add support for devices.

Just like on other architectures, the region container for memory devices is placed directly above our initial memory. For now, we only align the start address of the region up to 1 GiB, but we won't add any additional space to the region for internal alignment purposes; this can be done in the future if really required.

The RAM size returned via SCLP is not modified, as this only covers initial RAM (and standby memory we don't implement) and not memory devices; clarify that in the docs of read_SCP_info(). Existing OSes without support for memory devices will keep working as is, even when memory devices would be attached the VM.

Guest OSs which support memory devices, such as virtio-mem, will consult diag500(), to find out the maximum possible pfn. Guest OSes that don't support memory devices, don't have to be changed and will continue relying on information provided by SCLP.

There are no remaining maxram_size users in s390x code, and the remaining ram_size users only care about initial RAM:
* hw/s390x/ipl.c
* hw/s390x/s390-hypercall.c
* hw/s390x/sclp.c
* target/s390x/kvm/pv.c

---
  hw/s390x/s390-virtio-ccw.c | 23 ++++++++++++++++++++++-
  hw/s390x/sclp.c            |  6 +++++-
  2 files changed, 27 insertions(+), 2 deletions(-)
hw/s390x/s390-virtio-ccw.c +2 -1
index 749d46e700..2031c4cf29 100644
@@ -156,6 +156,7 @@ static void s390_memory_init(MachineState *machine)
      MemoryRegion *sysmem = get_system_memory();
      MemoryRegion *ram = machine->ram;
      uint64_t ram_size = memory_region_size(ram);
+    uint64_t devmem_base, devmem_size;
 
      if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) {
          /*
@@ -168,11 +169,31 @@ static void s390_memory_init(MachineState *machine)
          exit(EXIT_FAILURE);
      }
 
-    s390_set_memory_limit(s390ms, ram_size);
+    devmem_size = 0;

hw/s390x/s390-virtio-ccw.c static void s390_memory_init(MachineState *machine) · line 182

Quoted 10 lines
hw/s390x/s390-virtio-ccw.c +10 -0
+    devmem_base = ram_size;
+#ifdef CONFIG_MEM_DEVICE
+    if (machine->ram_size < machine->maxram_size) {
+
+        /*
+         * Make sure memory devices have a sane default alignment, even
+         * when weird initial memory sizes are specified.
+         */
+        devmem_base = QEMU_ALIGN_UP(devmem_base, 1 * GiB);
+        devmem_size = machine->maxram_size - machine->ram_size;

Shouldn't that rather be:

           devmem_size = machine->maxram_size - devmem_base;

instead?

Thomas

Quoted 14 lines
hw/s390x/s390-virtio-ccw.c +10 -0
+    }
+#endif
+    s390_set_memory_limit(s390ms, devmem_base + devmem_size);
 
      /* Map the initial memory. Must happen after setting the memory limit. */
      memory_region_add_subregion(sysmem, 0, ram);
 
+    /* Initialize address space for memory devices. */
+#ifdef CONFIG_MEM_DEVICE
+    if (devmem_size) {
+        machine_memory_devices_init(machine, devmem_base, devmem_size);
+    }
+#endif /* CONFIG_MEM_DEVICE */
+
Reviewed-by on v2 12/14
#19 lore raw

Re: [PATCH v2 12/14] s390x: remember the maximum page size

In reply to David Hildenbrand
Quoted 7 lines · David Hildenbrand

Let's remember the value (successfully) set via s390_set_max_pagesize(). This will be helpful to reject hotplugged memory devices that would exceed this initially set page size.

Handle it just like how we handle s390_get_memory_limit(), storing it in the machine, and moving the handling to machine code.

Quoted 8 lines
---
  hw/s390x/s390-virtio-ccw.c         | 12 +++++++++++-
  include/hw/s390x/s390-virtio-ccw.h |  1 +
  target/s390x/cpu-sysemu.c          |  7 -------
  target/s390x/cpu.h                 |  1 -
  4 files changed, 12 insertions(+), 9 deletions(-)
#15 lore raw

Re: [PATCH v2 10/14] s390x/s390-virtio-ccw: prepare for memory devices

In reply to Thomas Huth
Quoted 68 lines · Thomas Huth
Quoted 54 lines · David Hildenbrand

Let's prepare our address space for memory devices if enabled via "maxmem" and if we have CONFIG_MEM_DEVICE enabled at all. Note that CONFIG_MEM_DEVICE will be selected automatically once we add support for devices.

Just like on other architectures, the region container for memory devices is placed directly above our initial memory. For now, we only align the start address of the region up to 1 GiB, but we won't add any additional space to the region for internal alignment purposes; this can be done in the future if really required.

The RAM size returned via SCLP is not modified, as this only covers initial RAM (and standby memory we don't implement) and not memory devices; clarify that in the docs of read_SCP_info(). Existing OSes without support for memory devices will keep working as is, even when memory devices would be attached the VM.

Guest OSs which support memory devices, such as virtio-mem, will consult diag500(), to find out the maximum possible pfn. Guest OSes that don't support memory devices, don't have to be changed and will continue relying on information provided by SCLP.

There are no remaining maxram_size users in s390x code, and the remaining ram_size users only care about initial RAM:
* hw/s390x/ipl.c
* hw/s390x/s390-hypercall.c
* hw/s390x/sclp.c
* target/s390x/kvm/pv.c

---
   hw/s390x/s390-virtio-ccw.c | 23 ++++++++++++++++++++++-
   hw/s390x/sclp.c            |  6 +++++-
   2 files changed, 27 insertions(+), 2 deletions(-)
hw/s390x/s390-virtio-ccw.c +2 -1
index 749d46e700..2031c4cf29 100644
@@ -156,6 +156,7 @@ static void s390_memory_init(MachineState *machine)
       MemoryRegion *sysmem = get_system_memory();
       MemoryRegion *ram = machine->ram;
       uint64_t ram_size = memory_region_size(ram);
+    uint64_t devmem_base, devmem_size;
 
       if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) {
           /*
@@ -168,11 +169,31 @@ static void s390_memory_init(MachineState *machine)
           exit(EXIT_FAILURE);
       }
 
-    s390_set_memory_limit(s390ms, ram_size);
+    devmem_size = 0;

hw/s390x/s390-virtio-ccw.c static void s390_memory_init(MachineState *machine) · line 182

Quoted 10 lines
hw/s390x/s390-virtio-ccw.c +10 -0
+    devmem_base = ram_size;
+#ifdef CONFIG_MEM_DEVICE
+    if (machine->ram_size < machine->maxram_size) {
+
+        /*
+         * Make sure memory devices have a sane default alignment, even
+         * when weird initial memory sizes are specified.
+         */
+        devmem_base = QEMU_ALIGN_UP(devmem_base, 1 * GiB);
+        devmem_size = machine->maxram_size - machine->ram_size;

Shouldn't that rather be:

Quoted 3 lines
             devmem_size = machine->maxram_size - devmem_base;

instead?

For example, having ram_size == 1.5 GiB and maxram_size == 3 GiB means: we want to be able to hotplug 1.5 GiB, which is how we are going to size the region for memory devices.

So we would get

devmem_base = 2 GiB
devmem_size = 1.5 GiB

Instead of with your calculation

devmem_size = 1 GiB

Allowing us to only hotplug 1 GiB of memory.

Thanks for the review!

Signature · 3 lines
Cheers,

David / dhildenb
#26 lore raw
In reply to Thomas Huth
Quoted 50 lines · Thomas Huth
Quoted 49 lines · David Hildenbrand
Quoted 37 lines · David Hildenbrand
Quoted 30 lines · David Hildenbrand

Based on current master.

There is really not much left to do on s390x, because virtio-mem already implements most things we need today (e.g., early-migration, unplugged-inaccessible). The biggest part of this series is just doing what we do with virtio-pci, wiring it up in the machine hotplug handler and ... well, messing with the physical memory layout where we can now exceed initial RAM size and have sparsity (memory holes).

I tested a lot of things, including:
   * Memory hotplug/unplug
   * Device hotplug/unplug
   * System resets / reboots
   * Migrate to/from file (including storage attributes under KVM)
   * Basic live migration
   * Basic postcopy live migration

More details on how to use it on s390x -- which is pretty much how we use it on other architectures, except s/virtio-mem-pci/virtio-mem-ccw/ --- is in the last patch.

This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented in the kernel and at [2] once this+kernel part go upstream.

There are not many s390x-specific virtio-mem future work items, except:
* Storage attribute migration might be improved
* We might want to reset storage attributes of unplugged memory (might or might not be required for upcoming page table reclaim in Linux; TBD)

Quoted 5 lines

The Linux driver is available at [3].

[1] https://lkml.kernel.org/r/[email protected]
[2] https://gitlab.com/davidhildenbrand/s390x-os-virt-spec
[3] https://lkml.kernel.org/r/[email protected]

Quoted 6 lines

Gentle ping (and thanks to Thomas for the review!).

I assume the kernel portion will go upstream in the next merge window. I'd like get the QEMU parts merged soon after that.

9.2 is going to get released in roughly one month, so there is still time.

In the meantime, 9.2 was released. I don't have any changes planned. Series still applies to current master, I'll do a quick test tomorrow.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

@Thomas, this is mostly s390x stuff, so I guess it should go through the s390x tree? But I could also take this through my "memory devices" tree.

@Thomas, any thoughts?

I'm fine either way - feel free to put it into your tree, otherwise I'll pick it up likely sometime next week.

Okay, let me let this sit here for a couple days longer and retest it next week. I can queue it then, as another required patch ("virtio-mem: unplug memory only during system resets, not device resets") still sits in my tree all-lonely. :)

Signature · 3 lines
Cheers,

David / dhildenb
Reviewed-by
#16 lore raw

Re: [PATCH v2 10/14] s390x/s390-virtio-ccw: prepare for memory devices

In reply to David Hildenbrand
Quoted 67 lines · David Hildenbrand
Quoted 66 lines · Thomas Huth
Quoted 52 lines · David Hildenbrand

Let's prepare our address space for memory devices if enabled via "maxmem" and if we have CONFIG_MEM_DEVICE enabled at all. Note that CONFIG_MEM_DEVICE will be selected automatically once we add support for devices.

Just like on other architectures, the region container for memory devices is placed directly above our initial memory. For now, we only align the start address of the region up to 1 GiB, but we won't add any additional space to the region for internal alignment purposes; this can be done in the future if really required.

The RAM size returned via SCLP is not modified, as this only covers initial RAM (and standby memory we don't implement) and not memory devices; clarify that in the docs of read_SCP_info(). Existing OSes without support for memory devices will keep working as is, even when memory devices would be attached the VM.

Guest OSs which support memory devices, such as virtio-mem, will consult diag500(), to find out the maximum possible pfn. Guest OSes that don't support memory devices, don't have to be changed and will continue relying on information provided by SCLP.

There are no remaining maxram_size users in s390x code, and the remaining ram_size users only care about initial RAM:
* hw/s390x/ipl.c
* hw/s390x/s390-hypercall.c
* hw/s390x/sclp.c
* target/s390x/kvm/pv.c

---
   hw/s390x/s390-virtio-ccw.c | 23 ++++++++++++++++++++++- hw/s390x/sclp.c            |  6 +++++-

   2 files changed, 27 insertions(+), 2 deletions(-)
hw/s390x/s390-virtio-ccw.c +2 -1
index 749d46e700..2031c4cf29 100644
@@ -156,6 +156,7 @@ static void s390_memory_init(MachineState *machine)
        MemoryRegion *sysmem = get_system_memory();
        MemoryRegion *ram = machine->ram;
        uint64_t ram_size = memory_region_size(ram);
+    uint64_t devmem_base, devmem_size;
        if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) {
            /*
@@ -168,11 +169,31 @@ static void s390_memory_init(MachineState *machine)
            exit(EXIT_FAILURE);
        }
-    s390_set_memory_limit(s390ms, ram_size);
+    devmem_size = 0;

hw/s390x/s390-virtio-ccw.c static void s390_memory_init(MachineState *machine) · line 181

Quoted 10 lines
hw/s390x/s390-virtio-ccw.c +10 -0
+    devmem_base = ram_size;
+#ifdef CONFIG_MEM_DEVICE
+    if (machine->ram_size < machine->maxram_size) {
+
+        /*
+         * Make sure memory devices have a sane default alignment, even
+         * when weird initial memory sizes are specified.
+         */
+        devmem_base = QEMU_ALIGN_UP(devmem_base, 1 * GiB);
+        devmem_size = machine->maxram_size - machine->ram_size;

Shouldn't that rather be:

Quoted 5 lines
Quoted 3 lines

             devmem_size = machine->maxram_size - devmem_base;

instead?

For example, having ram_size == 1.5 GiB and maxram_size == 3 GiB means: we want to be able to hotplug 1.5 GiB, which is how we are going to size the region for memory devices.

Ah, ok, sorry, I think my mind somehow mixed up maxram_size with the highest possible address in memory ... time for the weekend ;-)

#27 lore raw
In reply to David Hildenbrand

Thanks, queued to

https://github.com/davidhildenbrand/qemu.git mem-next

Quoted 56 lines · David Hildenbrand
Quoted 55 lines · Thomas Huth
Quoted 53 lines · David Hildenbrand
Quoted 37 lines · David Hildenbrand
Quoted 30 lines · David Hildenbrand

Based on current master.

There is really not much left to do on s390x, because virtio-mem already implements most things we need today (e.g., early-migration, unplugged-inaccessible). The biggest part of this series is just doing what we do with virtio-pci, wiring it up in the machine hotplug handler and ... well, messing with the physical memory layout where we can now exceed initial RAM size and have sparsity (memory holes).

I tested a lot of things, including:
   * Memory hotplug/unplug
   * Device hotplug/unplug
   * System resets / reboots
   * Migrate to/from file (including storage attributes under KVM)
   * Basic live migration
   * Basic postcopy live migration

More details on how to use it on s390x -- which is pretty much how we use it on other architectures, except s/virtio-mem-pci/virtio-mem-ccw/ --- is in the last patch.

This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented in the kernel and at [2] once this+kernel part go upstream.

There are not many s390x-specific virtio-mem future work items, except:
* Storage attribute migration might be improved
* We might want to reset storage attributes of unplugged memory (might or might not be required for upcoming page table reclaim in Linux; TBD)

Quoted 5 lines

The Linux driver is available at [3].

[1] https://lkml.kernel.org/r/[email protected]
[2] https://gitlab.com/davidhildenbrand/s390x-os-virt-spec
[3] https://lkml.kernel.org/r/[email protected]

Quoted 6 lines

Gentle ping (and thanks to Thomas for the review!).

I assume the kernel portion will go upstream in the next merge window. I'd like get the QEMU parts merged soon after that.

9.2 is going to get released in roughly one month, so there is still time.

In the meantime, 9.2 was released. I don't have any changes planned. Series still applies to current master, I'll do a quick test tomorrow.

Quoted 3 lines

@Thomas, this is mostly s390x stuff, so I guess it should go through the s390x tree? But I could also take this through my "memory devices" tree.

@Thomas, any thoughts?

Quoted 7 lines
Quoted 2 lines

I'm fine either way - feel free to put it into your tree, otherwise I'll pick it up likely sometime next week.

Okay, let me let this sit here for a couple days longer and retest it next week. I can queue it then, as another required patch ("virtio-mem:
unplug memory only during system resets, not device resets") still sits in my tree all-lonely. :)

Testing revealed no surprised.

Queued to

https://github.com/davidhildenbrand/qemu.git mem-next

Signature · 3 lines
Cheers,

David / dhildenb
#28 lore raw

Am 16.12.24 um 22:18 schrieb David Hildenbrand:

Quoted 68 lines

Thanks, queued to

https://github.com/davidhildenbrand/qemu.git mem-next

Quoted 56 lines · David Hildenbrand
Quoted 55 lines · Thomas Huth
Quoted 53 lines · David Hildenbrand
Quoted 37 lines · David Hildenbrand
Quoted 30 lines · David Hildenbrand

Based on current master.

There is really not much left to do on s390x, because virtio-mem already implements most things we need today (e.g., early-migration, unplugged-inaccessible). The biggest part of this series is just doing what we do with virtio-pci, wiring it up in the machine hotplug handler and ... well, messing with the physical memory layout where we can now exceed initial RAM size and have sparsity (memory holes).

I tested a lot of things, including:
     * Memory hotplug/unplug
     * Device hotplug/unplug
     * System resets / reboots
     * Migrate to/from file (including storage attributes under KVM)
     * Basic live migration
     * Basic postcopy live migration

More details on how to use it on s390x -- which is pretty much how we use it on other architectures, except s/virtio-mem-pci/virtio-mem-ccw/ --- is in the last patch.

This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented in the kernel and at [2] once this+kernel part go upstream.

There are not many s390x-specific virtio-mem future work items, except:
* Storage attribute migration might be improved
* We might want to reset storage attributes of unplugged memory (might or might not be required for upcoming page table reclaim in Linux; TBD)

Quoted 5 lines

The Linux driver is available at [3].

[1] https://lkml.kernel.org/r/[email protected]
[2] https://gitlab.com/davidhildenbrand/s390x-os-virt-spec
[3] https://lkml.kernel.org/r/[email protected]

Quoted 6 lines

Gentle ping (and thanks to Thomas for the review!).

I assume the kernel portion will go upstream in the next merge window. I'd like get the QEMU parts merged soon after that.

9.2 is going to get released in roughly one month, so there is still time.

In the meantime, 9.2 was released. I don't have any changes planned. Series still applies to current master, I'll do a quick test tomorrow.

Quoted 3 lines

@Thomas, this is mostly s390x stuff, so I guess it should go through the s390x tree? But I could also take this through my "memory devices" tree.

@Thomas, any thoughts?

Quoted 7 lines
Quoted 2 lines

I'm fine either way - feel free to put it into your tree, otherwise I'll pick it up likely sometime next week.

Okay, let me let this sit here for a couple days longer and retest it next week. I can queue it then, as another required patch ("virtio-mem:
unplug memory only during system resets, not device resets") still sits in my tree all-lonely. :)

Quoted 5 lines

Testing revealed no surprised.

Queued to

https://github.com/davidhildenbrand/qemu.git mem-next

Thank you for doing it. Awesome work.

#29 lore raw
Quoted 69 lines · Christian Borntraeger

Am 16.12.24 um 22:18 schrieb David Hildenbrand:

Quoted 68 lines

Thanks, queued to

https://github.com/davidhildenbrand/qemu.git mem-next

Quoted 63 lines · David Hildenbrand
Quoted 50 lines · Thomas Huth
Quoted 49 lines · David Hildenbrand
Quoted 37 lines · David Hildenbrand
Quoted 30 lines · David Hildenbrand

Based on current master.

There is really not much left to do on s390x, because virtio-mem already implements most things we need today (e.g., early-migration, unplugged-inaccessible). The biggest part of this series is just doing what we do with virtio-pci, wiring it up in the machine hotplug handler and ... well, messing with the physical memory layout where we can now exceed initial RAM size and have sparsity (memory holes).

I tested a lot of things, including:
     * Memory hotplug/unplug
     * Device hotplug/unplug
     * System resets / reboots
     * Migrate to/from file (including storage attributes under KVM)
     * Basic live migration
     * Basic postcopy live migration

More details on how to use it on s390x -- which is pretty much how we use it on other architectures, except s/virtio-mem-pci/virtio-mem-ccw/ --- is in the last patch.

This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented in the kernel and at [2] once this+kernel part go upstream.

There are not many s390x-specific virtio-mem future work items, except:
* Storage attribute migration might be improved
* We might want to reset storage attributes of unplugged memory (might or might not be required for upcoming page table reclaim in Linux; TBD)

Quoted 5 lines

The Linux driver is available at [3].

[1] https://lkml.kernel.org/r/[email protected]
[2] https://gitlab.com/davidhildenbrand/s390x-os-virt-spec
[3] https://lkml.kernel.org/r/[email protected]

Quoted 6 lines

Gentle ping (and thanks to Thomas for the review!).

I assume the kernel portion will go upstream in the next merge window. I'd like get the QEMU parts merged soon after that.

9.2 is going to get released in roughly one month, so there is still time.

In the meantime, 9.2 was released. I don't have any changes planned. Series still applies to current master, I'll do a quick test tomorrow.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

@Thomas, this is mostly s390x stuff, so I guess it should go through the s390x tree? But I could also take this through my "memory devices" tree.

@Thomas, any thoughts?

I'm fine either way - feel free to put it into your tree, otherwise I'll pick it up likely sometime next week.

Okay, let me let this sit here for a couple days longer and retest it next week. I can queue it then, as another required patch ("virtio-mem:
unplug memory only during system resets, not device resets") still sits in my tree all-lonely. :)

Quoted 7 lines
Quoted 5 lines

Testing revealed no surprised.

Queued to

https://github.com/davidhildenbrand/qemu.git mem-next

Thank you for doing it. Awesome work.

Thanks! ... took a while to figure out how to make all weird configs happy. Sent a v3 ...

Signature · 3 lines
Cheers,

David / dhildenb