s390x: virtio-mem support
cover s390x: virtio-mem support
This series is based on:
[PATCH v2] virtio: kconfig: memory devices are PCI only [1]
I finally found the time (IOW forced myself) to finish virtio-mem support on s390x. The last RFC was from 2020, so I won't talk about what changed -- a lot changed in the meantime :)
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 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)
I'll send out the kernel driver bits soon.
[1] https://lkml.kernel.org/r/[email protected]
[2] https://gitlab.com/davidhildenbrand/s390x-os-virt-spec
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 memory devices and sparse memory
layouts
s390x/s390-skeys: prepare for memory devices
s390x/pv: check initial, not maximum RAM size s390x/s390-virtio-ccw: prepare for memory devices
s390x: introduce s390_get_max_pagesize() s390x/virtio-ccw: add support for virtio based memory devices
s390x: virtio-mem support
MAINTAINERS | 4 + hw/s390x/Kconfig | 1 + hw/s390x/meson.build | 4 +- hw/s390x/s390-hypercall.c | 77 +++++++++++ hw/s390x/s390-hypercall.h | 25 ++++ hw/s390x/s390-skeys.c | 4 +- hw/s390x/s390-stattrib-kvm.c | 63 +++++---- hw/s390x/s390-virtio-ccw.c | 143 +++++++++++++-------- hw/s390x/s390-virtio-hcall.c | 41 ------ hw/s390x/s390-virtio-hcall.h | 25 ---- hw/s390x/sclp.c | 17 +-- 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 +- target/s390x/cpu-sysemu.c | 35 ++++- target/s390x/cpu.h | 2 + target/s390x/kvm/kvm.c | 12 +- target/s390x/kvm/pv.c | 2 +- target/s390x/tcg/misc_helper.c | 6 +- 22 files changed, 746 insertions(+), 177 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.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.0
PATCH 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
@@ -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)) { +/* +* The 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.0
Re: [PATCH v1 01/14] s390x/s390-virtio-ccw: don't crash on weird RAM sizes
Quoted 11 lines · David Hildenbrand
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:
Huh, I always assumed that ram is handled in multiples of 1MB in QEMU.
Re: [PATCH v1 01/14] s390x/s390-virtio-ccw: don't crash on weird RAM sizes
Quoted 9 lines · Janosch Frank
Quoted 8 lines · David Hildenbrand
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)
Quoted 5 lines
Quoted 3 lines
Let's handle that in a better way by rejecting such weird RAM sizes right from the start:
Huh, I always assumed that ram is handled in multiples of 1MB in QEMU.
Me as well, I did not dig if that changed at some point ... or why such odd sizes would even be required :)
Thanks!
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v1 01/14] s390x/s390-virtio-ccw: don't crash on weird RAM sizes
Quoted 10 lines · David Hildenbrand
Quoted 9 lines · Janosch Frank
Quoted 8 lines · David Hildenbrand
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)
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Let's handle that in a better way by rejecting such weird RAM sizes right from the start:
Huh, I always assumed that ram is handled in multiples of 1MB in QEMU.
Me as well, I did not dig if that changed at some point ... or why such odd sizes would even be required :)
I guess it's there for some old PC hardware ... Remember, 640K ought to be enough for anybody.
Thomas
Re: [PATCH v1 01/14] s390x/s390-virtio-ccw: don't crash on weird RAM sizes
Quoted 16 lines · Thomas Huth
Quoted 15 lines · David Hildenbrand
Quoted 14 lines · Janosch Frank
Quoted 12 lines · David Hildenbrand
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:
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Huh, I always assumed that ram is handled in multiples of 1MB in QEMU.
Me as well, I did not dig if that changed at some point ... or why such odd sizes would even be required :)
I guess it's there for some old PC hardware ... Remember, 640K ought to be enough for anybody.
True, maybe the "default to MiB" made some of us believe that something smaller is impossible :)
And in fact, I think suffix support was added in
commit 6e1d3c1c855818a6d1399698572afae0d11b872b
Author: Igor Mammedov <[email protected]> Date: Wed Nov 27 01:27:35 2013 +0100
vl: convert -m to QemuOpts
Adds option to -m
"size" - startup memory amount
For compatibility with legacy CLI if suffix-less number is passed, it assumes amount in Mb.
Otherwise user is free to use suffixed number using suffixes b,k/K,M,G
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v1 01/14] s390x/s390-virtio-ccw: don't crash on weird RAM sizes
In reply to David HildenbrandQuoted 11 lines · David Hildenbrand
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:
Quoted 7 lines
# qemu-system-s390x --enable-kvm --nographic -m 1234K qemu-system-s390x: ram size must be multiples of 1 MiBSigned-off-by David Hildenbrand <[email protected]>--- hw/s390x/s390-virtio-ccw.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
Re: [PATCH v1 01/14] s390x/s390-virtio-ccw: don't crash on weird RAM sizes
In reply to David HildenbrandQuoted 11 lines · David Hildenbrand
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:
Quoted 7 lines
# qemu-system-s390x --enable-kvm --nographic -m 1234K qemu-system-s390x: ram size must be multiples of 1 MiBSigned-off-by David Hildenbrand <[email protected]>--- hw/s390x/s390-virtio-ccw.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
TIL. Thanks David!
Re: [PATCH v1 01/14] s390x/s390-virtio-ccw: don't crash on weird RAM sizes
In reply to David HildenbrandQuoted 27 lines · David Hildenbrand
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 MiBSigned-off-by David Hildenbrand <[email protected]>--- hw/s390x/s390-virtio-ccw.c | 11 +++++++++++ 1 file changed, 11 insertions(+)hw/s390x/s390-virtio-ccw.c +0
-0@@ -180,6 +180,17 @@ static void s390_memory_init(MemoryRegion *ram) {MemoryRegion *sysmem =get_system_memory ();
hw/s390x/s390-virtio-ccw.c static void s390_memory_init(MemoryRegion *ram) · line 192
Quoted 10 lines
hw/s390x/s390-virtio-ccw.c +10
-0+if (!QEMU_IS_ALIGNED (memory_region_size (ram),1 * MiB)) { +/* +* The 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 ); + }
I'll switch to
error_setg(&error_fatal, "ram size must be multiples of 1 MiB");
here, to avoid the manual exit().
Please someone shout if I should keep it as is.
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v1 01/14] s390x/s390-virtio-ccw: don't crash on weird RAM sizes
Quoted 42 lines · David Hildenbrand
Quoted 30 lines · David Hildenbrand
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 MiBSigned-off-by David Hildenbrand <[email protected]>---
hw/s390x/s390-virtio-ccw.c| 11 +++++++++++1 file changed, 11 insertions(+)hw/s390x/s390-virtio-ccw.c +3
-0@@ -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)) { + /* +* The SCLP cannot possibly expose smaller granularity right now and KVM
Quoted 8 lines
+ * 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);
+ }I'll switch to
Quoted 5 lines
error_setg(&error_fatal, "ram size must be multiples of 1 MiB");
here, to avoid the manual
exit().Please someone shout if I should keep it as is.
Please keep it, according to include/qapi/error.h:
* Please don't error_setg(&error_fatal, ...), use error_report() and
* exit(), because that's more obvious.
Thanks,
Thomas
Re: [PATCH v1 01/14] s390x/s390-virtio-ccw: don't crash on weird RAM sizes
Quoted 45 lines · Thomas Huth
Quoted 44 lines · David Hildenbrand
Quoted 30 lines · David Hildenbrand
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 MiBSigned-off-by David Hildenbrand <[email protected]>--- hw/s390x/s390-virtio-ccw.c | 11 +++++++++++ 1 file changed, 11 insertions(+)hw/s390x/s390-virtio-ccw.c +3
-0@@ -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)) { + /* +* The SCLP cannot possibly expose smaller granularity right now and KVM
Quoted 8 lines
+ * 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);
+ }I'll switch to
error_setg(&error_fatal, "ram size must be multiples of 1 MiB");
Quoted 9 lines
Quoted 3 lines
here, to avoid the manual
exit().Please someone shout if I should keep it as is.
Please keep it, according to
include/qapi/error.h:* Please don't
error_setg(&error_fatal, ...), useerror_report()and
*exit(), because that's more obvious.
Controversial, but will do. Thanks!
Signature · 3 lines
Cheers, David / dhildenb
PATCH 2/14 s390x/s390-virtio-hcall: remove hypercall registration mechanism
In reply to David HildenbrandNowadays, 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
@@ -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
@@ -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.0
Re: [PATCH v1 02/14] s390x/s390-virtio-hcall: remove hypercall registration mechanism
Quoted 11 lines · 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.Signed-off-by David Hildenbrand <[email protected]>--- 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(-)
PATCH 3/14 s390x/s390-virtio-hcall: prepare for more diag500 hypercalls
In reply to David HildenbrandLet'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).
We'll rename the files separately, so git properly detects the rename.
--- hw/s390x/s390-virtio-hcall.c | 8 ++++---- hw/s390x/s390-virtio-hcall.h | 11 ++++++----- target/s390x/kvm/kvm.c | 10 ++-------- target/s390x/tcg/misc_helper.c | 4 ++-- 4 files changed, 14 insertions(+), 19 deletions(-)
hw/s390x/s390-virtio-hcall.c +4 -4
@@ -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,15 +57,15 @@ static int handle_virtio_ccw_notify(uint64_t subch_id, uint64_t data)return 0 ; } -int s390_virtio_hypercall (CPUS390XState *env) +int handle_diag_500 (CPUS390XState *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 : +case DIAG500_VIRTIO_CCW_NOTIFY : env->regs[2 ] =handle_virtio_ccw_notify (env->regs[2 ], env->regs[3 ]);return 0 ;default :
hw/s390x/s390-virtio-hcall.h +6 -5
@@ -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); +int handle_diag_500 (CPUS390XState *env);#endif /* HW_S390_VIRTIO_HCALL_H */
target/s390x/kvm/kvm.c +2 -8
@@ -1493,16 +1493,10 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl)static int handle_hypercall (S390CPU *cpu,struct kvm_run *run) { -CPUS390XState *env = &cpu->env; -int ret; - - ret =s390_virtio_hypercall (env); -if (ret == -EINVAL ) { +if (handle_diag_500 (&cpu->env)) {kvm_s390_program_interrupt (cpu,PGM_SPECIFICATION ); -return 0 ; } - -return ret; +return 0 ; }static void kvm_handle_diag_288 (S390CPU *cpu,struct kvm_run *run)
target/s390x/tcg/misc_helper.c +2 -2
@@ -117,9 +117,9 @@ 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); + r =handle_diag_500 (env);bql_unlock ();break ;case 0x44 :
Signature · 1 line
2.46.0
Re: [PATCH v1 03/14] s390x/s390-virtio-hcall: prepare for more diag500 hypercalls
Quoted 7 lines · 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).
We'll rename the files separately, so git properly detects the rename.
Quoted 7 lines
Signed-off-by David Hildenbrand <[email protected]>--- hw/s390x/s390-virtio-hcall.c | 8 ++++---- hw/s390x/s390-virtio-hcall.h | 11 ++++++----- target/s390x/kvm/kvm.c | 10 ++-------- target/s390x/tcg/misc_helper.c | 4 ++-- 4 files changed, 14 insertions(+), 19 deletions(-)
Re: [PATCH v1 03/14] s390x/s390-virtio-hcall: prepare for more diag500 hypercalls
In reply to David HildenbrandQuoted 15 lines · 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).
We'll rename the files separately, so git properly detects the rename.
Signed-off-by David Hildenbrand <[email protected]>--- hw/s390x/s390-virtio-hcall.c | 8 ++++---- hw/s390x/s390-virtio-hcall.h | 11 ++++++----- target/s390x/kvm/kvm.c | 10 ++-------- target/s390x/tcg/misc_helper.c | 4 ++-- 4 files changed, 14 insertions(+), 19 deletions(-)
[...]
target/s390x/kvm/kvm.c static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl) · line 1494
Quoted 8 lines
target/s390x/kvm/kvm.c +0
-0@@ -1493,16 +1493,10 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl)static int handle_hypercall (S390CPU *cpu,struct kvm_run *run)
Might as well make the return type void then.
More importantly, are you changing the behavior?
If I'm reading the code right, previously handle_instruction would inject an additional PGM_OPERATION due to the negative return value, which does seem off to me. If so, IMO this change should go into a separate patch.
I'm also wondering if the injection of PGM_SPECIFICATION should just go into handle_diag_500 and handle_hypercall should just be inlined.
Quoted 14 lines
target/s390x/kvm/kvm.c +2
-8{ -CPUS390XState *env = &cpu->env; -int ret; - - ret =s390_virtio_hypercall (env); -if (ret == -EINVAL ) { +if (handle_diag_500 (&cpu->env)) {kvm_s390_program_interrupt (cpu,PGM_SPECIFICATION ); -return 0 ; } - -return ret; +return 0 ; }
Re: [PATCH v1 03/14] s390x/s390-virtio-hcall: prepare for more diag500 hypercalls
Quoted 24 lines · Nina Schoetterl-Glausch
Quoted 15 lines · 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).
We'll rename the files separately, so git properly detects the rename.
Signed-off-by David Hildenbrand <[email protected]>--- hw/s390x/s390-virtio-hcall.c | 8 ++++---- hw/s390x/s390-virtio-hcall.h | 11 ++++++----- target/s390x/kvm/kvm.c | 10 ++-------- target/s390x/tcg/misc_helper.c | 4 ++-- 4 files changed, 14 insertions(+), 19 deletions(-)[...]
Quoted 7 lines
target/s390x/kvm/kvm.c +0
-0@@ -1493,16 +1493,10 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl)
Quoted 3 lines
target/s390x/kvm/kvm.c static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl) · line 1494
Quoted 1 line
target/s390x/kvm/kvm.c +0
-0static int handle_hypercall (S390CPU *cpu,struct kvm_run *run)Might as well make the return type void then.
Agreed.
Quoted 4 lines
More importantly, are you changing the behavior?
If I'm reading the code right, previouslyhandle_instructionwould inject an additionalPGM_OPERATIONdue to the negative return value, which does seem off to me. If so, IMO this change should go into a separate patch.
You are right, agreed.
Quoted 3 lines
I'm also wondering if the injection of
PGM_SPECIFICATIONshould just go intohandle_diag_500andhandle_hypercallshould just be inlined.
I had exactly that, and used s390_program_interrupt(env, PGM_SPECIFICATION, ra); let me revive that.
Thanks!
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v1 03/14] s390x/s390-virtio-hcall: prepare for more diag500 hypercalls
Quoted 29 lines · David Hildenbrand
Quoted 24 lines · Nina Schoetterl-Glausch
Quoted 15 lines · 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).
We'll rename the files separately, so git properly detects the rename.
Signed-off-by David Hildenbrand <[email protected]>--- hw/s390x/s390-virtio-hcall.c | 8 ++++---- hw/s390x/s390-virtio-hcall.h | 11 ++++++----- target/s390x/kvm/kvm.c | 10 ++-------- target/s390x/tcg/misc_helper.c | 4 ++-- 4 files changed, 14 insertions(+), 19 deletions(-)[...]
Quoted 7 lines
target/s390x/kvm/kvm.c +0
-0@@ -1493,16 +1493,10 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl)Quoted 3 lines
target/s390x/kvm/kvm.c static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl) · line 1494
Quoted 1 line
target/s390x/kvm/kvm.c +0
-0static int handle_hypercall (S390CPU *cpu,struct kvm_run *run)Might as well make the return type void then.
Quoted 8 lines
Agreed.
Quoted 4 lines
More importantly, are you changing the behavior?
If I'm reading the code right, previouslyhandle_instructionwould inject an additionalPGM_OPERATIONdue to the negative return value, which does seem off to me. If so, IMO this change should go into a separate patch.You are right, agreed.
Ah, reading again, we have a "return 0;" after the "kvm_s390_program_interrupt", so it should work as expected.
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v1 03/14] s390x/s390-virtio-hcall: prepare for more diag500 hypercalls
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · David Hildenbrand
Quoted 24 lines · Nina Schoetterl-Glausch
Quoted 15 lines · 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).
We'll rename the files separately, so git properly detects the rename.
Signed-off-by David Hildenbrand <[email protected]>--- hw/s390x/s390-virtio-hcall.c | 8 ++++---- hw/s390x/s390-virtio-hcall.h | 11 ++++++----- target/s390x/kvm/kvm.c | 10 ++-------- target/s390x/tcg/misc_helper.c | 4 ++-- 4 files changed, 14 insertions(+), 19 deletions(-)[...]
Quoted 7 lines
target/s390x/kvm/kvm.c +0
-0@@ -1493,16 +1493,10 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl)Quoted 3 lines
target/s390x/kvm/kvm.c static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl) · line 1494
Quoted 1 line
target/s390x/kvm/kvm.c +0
-0static int handle_hypercall (S390CPU *cpu,struct kvm_run *run)Might as well make the return type void then.
Agreed.
Quoted 4 lines
More importantly, are you changing the behavior?
If I'm reading the code right, previouslyhandle_instructionwould inject an additionalPGM_OPERATIONdue to the negative return value, which does seem off to me. If so, IMO this change should go into a separate patch.
Quoted 5 lines
Quoted 1 line
You are right, agreed.
Ah, reading again, we have a "return 0;" after the "
kvm_s390_program_interrupt", so it should work as expected.
The following in should be what you suggest:
hw/s390x/s390-virtio-hcall.c +5 -4
@@ -57,18 +57,19 @@ static int handle_virtio_ccw_notify(uint64_t subch_id, uint64_t data)return 0 ; } -int handle_diag_500 (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 DIAG500_VIRTIO_NOTIFY : env->regs[2 ] =handle_virtio_notify (env->regs[2 ]); -return 0 ; +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 +1 -1
@@ -19,6 +19,6 @@#define DIAG500_VIRTIO_SET_STATUS 2/* legacy */ #define DIAG500_VIRTIO_CCW_NOTIFY 3/* KVM_S390_VIRTIO_CCW_NOTIFY */ -int handle_diag_500 (CPUS390XState *env); +void handle_diag_500 (S390CPU *cpu,uintptr_t ra);#endif /* HW_S390_VIRTIO_HCALL_H */
target/s390x/kvm/kvm.c +1 -9
@@ -1491,14 +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) -{ -if (handle_diag_500 (&cpu->env)) { -kvm_s390_program_interrupt (cpu,PGM_SPECIFICATION ); - } -return 0 ; -} -static void kvm_handle_diag_288 (S390CPU *cpu,struct kvm_run *run) {uint64_t r1, r3;
@@ -1595,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 +1 -1
@@ -119,7 +119,7 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num)case 0x500 :/* QEMU/KVM hypercall */ bql_lock (); - r =handle_diag_500 (env); +handle_diag_500 (env_archcpu (env),GETPC ());bql_unlock ();break ;case 0x44 :
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v1 03/14] s390x/s390-virtio-hcall: prepare for more diag500 hypercalls
Quoted 38 lines · David Hildenbrand
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · David Hildenbrand
Quoted 24 lines · Nina Schoetterl-Glausch
Quoted 15 lines · 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).
We'll rename the files separately, so git properly detects the rename.
Signed-off-by David Hildenbrand <[email protected]>--- hw/s390x/s390-virtio-hcall.c | 8 ++++---- hw/s390x/s390-virtio-hcall.h | 11 ++++++----- target/s390x/kvm/kvm.c | 10 ++-------- target/s390x/tcg/misc_helper.c | 4 ++-- 4 files changed, 14 insertions(+), 19 deletions(-)[...]
Quoted 7 lines
target/s390x/kvm/kvm.c +0
-0@@ -1493,16 +1493,10 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl)Quoted 3 lines
target/s390x/kvm/kvm.c static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl) · line 1494
Quoted 1 line
target/s390x/kvm/kvm.c +0
-0static int handle_hypercall (S390CPU *cpu,struct kvm_run *run)Might as well make the return type void then.
Agreed.
Quoted 4 lines
More importantly, are you changing the behavior?
If I'm reading the code right, previouslyhandle_instructionwould inject an additionalPGM_OPERATIONdue to the negative return value, which does seem off to me. If so, IMO this change should go into a separate patch.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
You are right, agreed.
Ah, reading again, we have a "return 0;" after the "
kvm_s390_program_interrupt", so it should work as expected.The following in should be what you suggest:
Yup, looks good.
hw/s390x/s390-virtio-hcall.c static int handle_virtio_ccw_notify(uint64_t subch_id, uint64_t data) · line 60
Quoted 11 lines
hw/s390x/s390-virtio-hcall.c +1
-1@@ -57,18 +57,19 @@ static int handle_virtio_ccw_notify(uint64_t subch_id, uint64_t data)return 0 ; } -int handle_diag_500 (CPUS390XState *env) +void handle_diag_500 (S390CPU *cpu,uintptr_t ra)
I don't see a point to passing a cpu when we only need the env, but it doesn't matter.
Quoted 73 lines
hw/s390x/s390-virtio-hcall.c +4
-3{ +CPUS390XState *env = &cpu->env;const uint64_t subcode = env->regs[1 ];switch (subcode) {case DIAG500_VIRTIO_NOTIFY : env->regs[2 ] =handle_virtio_notify (env->regs[2 ]); -return 0 ; +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 +1
-1@@ -19,6 +19,6 @@#define DIAG500_VIRTIO_SET_STATUS 2/* legacy */ #define DIAG500_VIRTIO_CCW_NOTIFY 3/* KVM_S390_VIRTIO_CCW_NOTIFY */ -int handle_diag_500 (CPUS390XState *env); +void handle_diag_500 (S390CPU *cpu,uintptr_t ra);#endif /* HW_S390_VIRTIO_HCALL_H */ target/s390x/kvm/kvm.c +1
-9@@ -1491,14 +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) -{ -if (handle_diag_500 (&cpu->env)) { -kvm_s390_program_interrupt (cpu,PGM_SPECIFICATION ); - } -return 0 ; -} -static void kvm_handle_diag_288 (S390CPU *cpu,struct kvm_run *run) {uint64_t r1, r3;@@ -1595,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 +1
-1@@ -119,7 +119,7 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num)case 0x500 :/* QEMU/KVM hypercall */ bql_lock (); - r =handle_diag_500 (env); +handle_diag_500 (env_archcpu (env),GETPC ());bql_unlock ();break ;case 0x44 :
PATCH 4/14 s390x: rename s390-virtio-hcall* to s390-hypercall*
In reply to David HildenbrandLet'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
@@ -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
@@ -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
@@ -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 @@int handle_diag_500 (CPUS390XState *env); -#endif /* HW_S390_VIRTIO_HCALL_H */ +#endif /* HW_S390_HYPERCALL_H */
target/s390x/kvm/kvm.c +1 -1
@@ -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
@@ -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.0
Re: [PATCH v1 04/14] s390x: rename s390-virtio-hcall* to s390-hypercall*
Quoted 11 lines · David Hildenbrand
Let's make it clearer that we are talking about general QEMU/KVM-specific hypercalls.
Signed-off-by David Hildenbrand <[email protected]>--- 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(-)
Quoted 2 lines
rename
hw/s390x/{s390-virtio-hcall.c=>s390-hypercall.c} (97%) renamehw/s390x/{s390-virtio-hcall.h=>s390-hypercall.h} (86%)
PATCH 5/14 s390x/s390-virtio-ccw: move setting the maximum guest size from sclp to machine code
In reply to David HildenbrandNowadays, 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.
--- hw/s390x/s390-virtio-ccw.c | 22 ++++++++++++++++++---- hw/s390x/sclp.c | 11 ----------- 2 files changed, 18 insertions(+), 15 deletions(-)
hw/s390x/s390-virtio-ccw.c +18 -4
@@ -121,11 +121,15 @@ static void subsystem_reset(void) } } -static void s390_memory_init (MemoryRegion *ram) +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 hw_limit; +int ret; -if (!QEMU_IS_ALIGNED (memory_region_size (ram),1 * MiB)) { +if (!QEMU_IS_ALIGNED (ram_size,1 * MiB)) {/* * The SCLP cannot possibly expose smaller granularity right now and KVM * cannot handle smaller granularity. As we don't support NUMA, the
@@ -136,7 +140,17 @@ static void s390_memory_init(MemoryRegion *ram)exit (EXIT_FAILURE ); } -/* allocate RAM for core */ + ret =s390_set_memory_limit (ram_size, &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 ); + } + +/* Map the initial memory. Must happen after setting the memory limit. */ memory_region_add_subregion (sysmem,0 , ram);/*
@@ -217,7 +231,7 @@ static void ccw_init(MachineState *machine)qdev_realize_and_unref (DEVICE (ms->sclp),NULL , &error_fatal);/* init memory + setup max page size. Required for the CPU model */ -s390_memory_init (machine->ram); +s390_memory_init (machine);/* init CPUs (incl. CPU model) early so s390_has_feature() works */ s390_init_cpus (machine);
hw/s390x/sclp.c +0 -11
@@ -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)
Signature · 1 line
2.46.0
Re: [PATCH v1 05/14] s390x/s390-virtio-ccw: move setting the maximum guest size from sclp to machine code
Quoted 4 lines · 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.
Quoted 8 lines
While at it, use the actual RAM size, not the maximum RAM size which cannot currently be reached without support for any memory devices.
Signed-off-by David Hildenbrand <[email protected]>--- hw/s390x/s390-virtio-ccw.c | 22 ++++++++++++++++++---- hw/s390x/sclp.c | 11 ----------- 2 files changed, 18 insertions(+), 15 deletions(-)
PATCH 6/14 s390x: introduce s390_get_memory_limit()
In reply to David HildenbrandLet's add s390_get_memory_limit(), to query what has been successfully set via s390_set_memory_limit(). Allow setting the limit only once.
--- target/s390x/cpu-sysemu.c | 19 +++++++++++++++++-- target/s390x/cpu.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-)
target/s390x/cpu-sysemu.c +17 -2
@@ -255,12 +255,27 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu)return s390_count_running_cpus (); } +static uint64_t memory_limit; +int s390_set_memory_limit (uint64_t new_limit,uint64_t *hw_limit) { +int ret =0 ; + +if (memory_limit) { +return -EBUSY ; + }if (kvm_enabled ()) { -return kvm_s390_set_mem_limit (new_limit, hw_limit); + ret =kvm_s390_set_mem_limit (new_limit, hw_limit); + } +if (!ret) { + memory_limit = new_limit; } -return 0 ; +return ret; +} + +uint64_t s390_get_memory_limit (void ) +{ +return memory_limit; }void s390_set_max_pagesize (uint64_t pagesize,Error **errp)
target/s390x/cpu.h +1 -0
@@ -895,6 +895,7 @@ 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); +uint64_t s390_get_memory_limit (void );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.0
Re: [PATCH v1 06/14] s390x: introduce s390_get_memory_limit()
Quoted 8 lines · David Hildenbrand
Let's add
s390_get_memory_limit(), to query what has been successfully set vias390_set_memory_limit(). Allow setting the limit only once.Signed-off-by David Hildenbrand <[email protected]>--- target/s390x/cpu-sysemu.c | 19 +++++++++++++++++-- target/s390x/cpu.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-)
Re: [PATCH v1 06/14] s390x: introduce s390_get_memory_limit()
In reply to David HildenbrandQuoted 4 lines · David Hildenbrand
Let's add
s390_get_memory_limit(), to query what has been successfully set vias390_set_memory_limit(). Allow setting the limit only once.Signed-off-by David Hildenbrand <[email protected]>
Comment below.
Quoted 25 lines
--- target/s390x/cpu-sysemu.c | 19 +++++++++++++++++-- target/s390x/cpu.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-)target/s390x/cpu-sysemu.c +8
-1@@ -255,12 +255,27 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu)return s390_count_running_cpus (); } +static uint64_t memory_limit; +int s390_set_memory_limit (uint64_t new_limit,uint64_t *hw_limit) { +int ret =0 ; + +if (memory_limit) { +return -EBUSY ; + }if (kvm_enabled ()) { -return kvm_s390_set_mem_limit (new_limit, hw_limit); + ret =kvm_s390_set_mem_limit (new_limit, hw_limit);
target/s390x/cpu-sysemu.c unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu) · line 277
Quoted 10 lines
target/s390x/cpu-sysemu.c +8
-1+ } +if (!ret) { + memory_limit = new_limit; } -return 0 ; +return ret; +} + +uint64_t s390_get_memory_limit (void ) +{
Might be nice to guard/warn against s390_set_memory_limit not having been called before.
Quoted 16 lines
target/s390x/cpu-sysemu.c +1
-0+return memory_limit; }void s390_set_max_pagesize (uint64_t pagesize,Error **errp)target/s390x/cpu.h +1
-0@@ -895,6 +895,7 @@ 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); +uint64_t s390_get_memory_limit (void );void s390_set_max_pagesize (uint64_t pagesize,Error **errp);void s390_cmma_reset (void );void s390_enable_css_support (S390CPU *cpu);
Re: [PATCH v1 06/14] s390x: introduce s390_get_memory_limit()
Quoted 38 lines · Nina Schoetterl-Glausch
Quoted 4 lines · David Hildenbrand
Let's add
s390_get_memory_limit(), to query what has been successfully set vias390_set_memory_limit(). Allow setting the limit only once.Signed-off-by David Hildenbrand <[email protected]>Reviewed-by Nina Schoetterl-Glausch <[email protected]>Comment below.
Quoted 29 lines
--- target/s390x/cpu-sysemu.c | 19 +++++++++++++++++-- target/s390x/cpu.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-)target/s390x/cpu-sysemu.c +11
-1@@ -255,12 +255,27 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu)return s390_count_running_cpus (); } +static uint64_t memory_limit; +int s390_set_memory_limit (uint64_t new_limit,uint64_t *hw_limit) { +int ret =0 ; + +if (memory_limit) { +return -EBUSY ; + }if (kvm_enabled ()) { -return kvm_s390_set_mem_limit (new_limit, hw_limit); + ret =kvm_s390_set_mem_limit (new_limit, hw_limit); + } +if (!ret) { + memory_limit = new_limit; }
Quoted 9 lines
target/s390x/cpu-sysemu.c unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu) · line 277
Quoted 6 lines
target/s390x/cpu-sysemu.c +5
-1-return 0 ; +return ret; +} + +uint64_t s390_get_memory_limit (void ) +{Might be nice to guard/warn against
s390_set_memory_limitnot having been called before.
What about the following on top:
target/s390x/cpu-sysemu.c +4 -0
@@ -263,6 +263,8 @@ int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit)if (memory_limit) {return -EBUSY ; + }else if (!new_limit) { +return -EINVAL ; }if (kvm_enabled ()) { ret =kvm_s390_set_mem_limit (new_limit, hw_limit);
@@ -275,6 +277,8 @@ int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit)uint64_t s390_get_memory_limit (void ) { +/* We expect to be called after s390_set_memory_limit(). */ +assert (memory_limit);return memory_limit; }
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v1 06/14] s390x: introduce s390_get_memory_limit()
Quoted 14 lines · David Hildenbrand
Quoted 13 lines · Nina Schoetterl-Glausch
Quoted 4 lines · David Hildenbrand
Let's add
s390_get_memory_limit(), to query what has been successfully set vias390_set_memory_limit(). Allow setting the limit only once.Signed-off-by David Hildenbrand <[email protected]>Reviewed-by Nina Schoetterl-Glausch <[email protected]>Comment below.
Quoted 4 lines
--- target/s390x/cpu-sysemu.c | 19 +++++++++++++++++-- target/s390x/cpu.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-)
[...]
Quoted 23 lines
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ +uint64_t s390_get_memory_limit(void) +{Might be nice to guard/warn against
s390_set_memory_limitnot having been called before.What about the following on top:
target/s390x/cpu-sysemu.c +2
-0@@ -263,6 +263,8 @@ int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit)if (memory_limit) {return -EBUSY ; + }else if (!new_limit) { +return -EINVAL ; }if (kvm_enabled ()) { ret =kvm_s390_set_mem_limit (new_limit, hw_limit);
target/s390x/cpu-sysemu.c int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit) · line 283
Quoted 7 lines
target/s390x/cpu-sysemu.c +2
-0@@ -275,6 +277,8 @@ int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit)uint64_t s390_get_memory_limit (void ) { +/* We expect to be called after s390_set_memory_limit(). */ +assert (memory_limit);return memory_limit; }
Looks good.
Looking at the patch again I'm wondering if using globals in qemu is still encouraged. I know it's a common pattern today, but seeing efforts like the multiarch binary or Unicorn I'm wondering if there is aspirations to do things more "cleanly", in general, for far out benefits? I.e. memory_limit could be a machine property instead.
Re: [PATCH v1 06/14] s390x: introduce s390_get_memory_limit()
Quoted 8 lines
Looks good.
Looking at the patch again I'm wondering if using globals in qemu is still encouraged. I know it's a common pattern today, but seeing efforts like the multiarch binary or Unicorn I'm wondering if there is aspirations to do things more "cleanly", in general, for far out benefits? I.e.
memory_limitcould be a machine property instead.
Yes, I'll rework that code to simply store it in the machine, moving that code out of cpu-sysemu.c int s390-virtio-ccw.c.
Same for patch #12, thanks!
Signature · 3 lines
Cheers, David / dhildenb
PATCH 7/14 s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT
In reply to David HildenbrandA 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 | 3 +++ hw/s390x/s390-hypercall.h | 1 + 2 files changed, 4 insertions(+)
hw/s390x/s390-hypercall.c +3 -0
@@ -68,6 +68,9 @@ int handle_diag_500(CPUS390XState *env)case DIAG500_VIRTIO_CCW_NOTIFY : env->regs[2 ] =handle_virtio_ccw_notify (env->regs[2 ], env->regs[3 ]);return 0 ; +case DIAG500_STORAGE_LIMIT : + env->regs[2 ] =s390_get_memory_limit () -1 ; +return 0 ;default :return -EINVAL ; }
hw/s390x/s390-hypercall.h +1 -0
@@ -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 4int handle_diag_500 (CPUS390XState *env);
Signature · 1 line
2.46.0
Re: [PATCH v1 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT
Quoted 49 lines · 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().Signed-off-by David Hildenbrand <[email protected]>--- hw/s390x/s390-hypercall.c | 3 +++ hw/s390x/s390-hypercall.h | 1 + 2 files changed, 4 insertions(+)hw/s390x/s390-hypercall.c +3
-0@@ -68,6 +68,9 @@ int handle_diag_500(CPUS390XState *env)case DIAG500_VIRTIO_CCW_NOTIFY : env->regs[2 ] =handle_virtio_ccw_notify (env->regs[2 ], env->regs[3 ]);return 0 ; +case DIAG500_STORAGE_LIMIT : + env->regs[2 ] =s390_get_memory_limit () -1 ; +return 0 ;default :return -EINVAL ; }hw/s390x/s390-hypercall.h +0
-0
hw/s390x/s390-hypercall.h line 23
Quoted 6 lines
hw/s390x/s390-hypercall.h +1
-0@@ -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 4int handle_diag_500 (CPUS390XState *env);
Sounds very reasonable to me - but it would be good to get an Ack/Reviewed-by from IBM folks here (in case they prefer a different interface)... hope they'll join the discussion!
Thomas
Re: [PATCH v1 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT
Quoted 1 line · Thomas Huth
On 10/09/2024 19.58, David Hildenbrand wrote:
[...]
Quoted 10 lines
Quoted 10 lines
hw/s390x/s390-hypercall.h +1
-0@@ -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
Quoted 7 lines
hw/s390x/s390-hypercall.h line 23
Quoted 1 line
hw/s390x/s390-hypercall.h +0
-0int handle_diag_500 (CPUS390XState *env);Reviewed-by Thomas Huth <[email protected]>Sounds very reasonable to me - but it would be good to get an Ack/Reviewed-by from IBM folks here (in case they prefer a different interface)... hope they'll join the discussion!
I've publicized the series on the internal channels yesterday. We're aware of the fact that we need to provide review.
Re: [PATCH v1 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT
In reply to Thomas HuthQuoted 14 lines · On Thu, 12 Sep 2024 10:19:00 +0200 Thomas Huth <[email protected]> wrote:
hw/s390x/s390-hypercall.h line 23
Quoted 11 lines
hw/s390x/s390-hypercall.h +1
-0@@ -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 4int handle_diag_500 (CPUS390XState *env);Reviewed-by Thomas Huth <[email protected]>
Quoted 5 lines
Sounds very reasonable to me - but it would be good to get an Ack/Reviewed-by from IBM folks here (in case they prefer a different interface)... hope they'll join the discussion!
Thomas
According to Documentation/virt/kvm/s390/s390-diag.rst in the linux source tree DIAG 500 is for kvm virtio funcions.
Based on the commit message this storagelimit DIAG is rather loosely tied to virtio if at all, so from that perspective DIAG may not be a perfect fit. OTOH I don't see a better fit either. I would prefer to have Christian's opinion on this. I have no strong opinion myself.
If we decide to go with a DIAG, I would like to see Documentation/virt/kvm/s390/s390-diag.rst updated accordingly.
Also if decide to go with DIAG 500, maybe leaving some space between the codes more closely tied to virtio and between the ones less closely tied to virito (for the unlikely case that we end up wanting another DIAG 500 subcode for virtio) might make sense. I.e e could make DIAG500_STORAGE_LIMIT 8 or 16 instead of 4. Again nothing important, just an idea.
Regards,
Halil
Re: [PATCH v1 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT
Quoted 17 lines · Halil Pasic
Quoted 14 lines · On Thu, 12 Sep 2024 10:19:00 +0200 Thomas Huth <[email protected]> wrote:
hw/s390x/s390-hypercall.h line 23
Quoted 11 lines
hw/s390x/s390-hypercall.h +1
-0@@ -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 4int handle_diag_500 (CPUS390XState *env);Reviewed-by Thomas Huth <[email protected]>
Quoted 8 lines
Quoted 5 lines
Sounds very reasonable to me - but it would be good to get an Ack/Reviewed-by from IBM folks here (in case they prefer a different interface)... hope they'll join the discussion!
Thomas
According to
Documentation/virt/kvm/s390/s390-diag.rstin the linux source tree DIAG 500 is for kvm virtio funcions.
I assume you skimmed the QEMU patches, including the one that suggest changing (or rather extending) that.
Quoted 8 lines
Based on the commit message this storagelimit DIAG is rather loosely tied to virtio if at all, so from that perspective DIAG may not be a perfect fit. OTOH I don't see a better fit either. I would prefer to have Christian's opinion on this. I have no strong opinion myself.
If we decide to go with a DIAG, I would like to see>
Documentation/virt/kvm/s390/s390-diag.rstupdated accordingly.
I'll document wherever people fancy. I'll even document in multiple locations :)
Quoted 7 lines
Also if decide to go with DIAG 500, maybe leaving some space between the codes more closely tied to virtio and between the ones less closely tied to virito (for the unlikely case that we end up wanting another DIAG 500 subcode for virtio) might make sense. I.e e could make
DIAG500_STORAGE_LIMIT8 or 16 instead of 4. Again nothing important, just an idea.
I don't see a reason to do that, but in the end I don't care as long as people let me know what to do instead.
Thanks for taking a look!
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v1 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT
In reply to Halil PasicAm 27.09.24 um 20:05 schrieb Halil Pasic:
Quoted 23 lines
Quoted 14 lines · On Thu, 12 Sep 2024 10:19:00 +0200 Thomas Huth <[email protected]> wrote:
hw/s390x/s390-hypercall.h line 23
Quoted 11 lines
hw/s390x/s390-hypercall.h +1
-0@@ -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 4int handle_diag_500 (CPUS390XState *env);Reviewed-by Thomas Huth <[email protected]>Quoted 5 lines
Sounds very reasonable to me - but it would be good to get an Ack/Reviewed-by from IBM folks here (in case they prefer a different interface)... hope they'll join the discussion!
Thomas
Quoted 7 lines
According to
Documentation/virt/kvm/s390/s390-diag.rstin the linux source tree DIAG 500 is for kvm virtio funcions.Based on the commit message this storagelimit DIAG is rather loosely tied to virtio if at all, so from that perspective DIAG may not be a perfect fit. OTOH I don't see a better fit either. I would prefer to have Christian's opinion on this. I have no strong opinion myself.
Some remarks:
500 with a new subcode would work, it is marked as KVM hypervisor call in our docs. 501 was used in the past for software breakpoints. So we could use 502 as the next free one (This is reserved for KVM). We do have kvm_stat counters for 500, not sure if people debugging virtio will care.
The only important question for me is, what code is generated by gcc for the switch statement and will any variant slow down the virtio doorbell. diag.c has
if (!vcpu->kvm->arch.css_support ||
(vcpu->run->s.regs.gprs[1] != KVM_S390_VIRTIO_CCW_NOTIFY))
return -EOPNOTSUPP;So 500+4 should probably not cause any harm apart from branch prediction going wrong the first 2 or 3 notifies.
502 will make kvm_s390_handle_diag larger.
So I tend to go with 500+4.
Re: [PATCH v1 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT
Quoted 2 lines · On Mon, 30 Sep 2024 13:11:31 +0200 Christian Borntraeger…
We do have
kvm_statcounters for 500, not sure if people debugging virtio will care.
Could end up being confusing, as currently we can assume each and every DIAG 500 is a virtio doorbell. But I don't think the chance of this causing real headache is big.
Quoted 11 lines
The only important question for me is, what code is generated by gcc for the switch statement and will any variant slow down the virtio doorbell.
diag.chasif (!vcpu->kvm->arch.css_support || (vcpu->run->s.regs.gprs[1] != KVM_S390_VIRTIO_CCW_NOTIFY)) return -EOPNOTSUPP;So 500+4 should probably not cause any harm apart from branch prediction going wrong the first 2 or 3 notifies.
502 will make
kvm_s390_handle_diaglarger.
What do you mean by this last paragraph?
I suppose we are talking about
int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
{
int code = kvm_s390_get_base_disp_rs(vcpu, NULL) & 0xffff;
if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
trace_kvm_s390_handle_diag(vcpu, code);
switch (code) {
case 0x10:
return diag_release_pages(vcpu);
case 0x44:
return __diag_time_slice_end(vcpu);
case 0x9c:
return __diag_time_slice_end_directed(vcpu);
case 0x258:
return __diag_page_ref_service(vcpu);
case 0x308:
return __diag_ipl_functions(vcpu);
case 0x500:
return __diag_virtio_hypercall(vcpu);
default:
vcpu->stat.instruction_diagnose_other++;
return -EOPNOTSUPP;
}
}and my understanding is that the default branch of the switch statement would be already suitable for DIAG 502 as it is today for DIAG 502. So I'm quite confused by your statement that 502 will make kvm_s390_handle_diag larger (as the only meaning of larger I can think of is more code). Can you please clarify?
Regards,
Halil
Re: [PATCH v1 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT
Am 30.09.24 um 14:57 schrieb Halil Pasic:
Quoted 52 lines
Quoted 2 lines · On Mon, 30 Sep 2024 13:11:31 +0200 Christian Borntraeger…
We do have
kvm_statcounters for 500, not sure if people debugging virtio will care.Could end up being confusing, as currently we can assume each and every DIAG 500 is a virtio doorbell. But I don't think the chance of this causing real headache is big.
Quoted 11 lines
The only important question for me is, what code is generated by gcc for the switch statement and will any variant slow down the virtio doorbell.
diag.chasif (!vcpu->kvm->arch.css_support || (vcpu->run->s.regs.gprs[1] != KVM_S390_VIRTIO_CCW_NOTIFY)) return -EOPNOTSUPP;So 500+4 should probably not cause any harm apart from branch prediction going wrong the first 2 or 3 notifies.
502 will make
kvm_s390_handle_diaglarger.What do you mean by this last paragraph?
I suppose we are talking about
intkvm_s390_handle_diag(struct kvm_vcpu *vcpu){ int code = kvm_s390_get_base_disp_rs(vcpu, NULL) & 0xffff; if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); trace_kvm_s390_handle_diag(vcpu, code); switch (code) { case 0x10: return diag_release_pages(vcpu); case 0x44: return __diag_time_slice_end(vcpu); case 0x9c: return __diag_time_slice_end_directed(vcpu); case 0x258: return __diag_page_ref_service(vcpu); case 0x308: return __diag_ipl_functions(vcpu); case 0x500: return __diag_virtio_hypercall(vcpu); default: vcpu->stat.instruction_diagnose_other++; return -EOPNOTSUPP; } }
Quoted 5 lines
and my understanding is that the default branch of the switch statement would be already suitable for DIAG 502 as it is today for DIAG 502. So I'm quite confused by your statement that 502 will make
kvm_s390_handle_diaglarger (as the only meaning of larger I can think of is more code). Can you please clarify?
gcc has logic for switch statements that decide about branch table or a chained compare+jump. I think due to spectre gcc now avoids indirect branches as much as possible but still a larger switch statement might kick the decision from inline compare/jump to a branch table.
I am not worried in this particular case this was more or less a "what could go wrong".
Re: [PATCH v1 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT
On Tue, 1 Oct 2024 11:15:02 +0200
Christian Borntraeger <[email protected]> wrote:
[..]
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
So 500+4 should probably not cause any harm apart from branch prediction going wrong the first 2 or 3 notifies.
502 will make
kvm_s390_handle_diaglarger.What do you mean by this last paragraph?
[..]
Quoted 7 lines
gcc has logic for switch statements that decide about branch table or a chained compare+jump. I think due to spectre gcc now avoids indirect branches as much as possible but still a larger switch statement might kick the decision from inline compare/jump to a branch table.
I am not worried in this particular case this was more or less a "what could go wrong".
Hm, you did state that "502 will make kvm_s390_handle_diag larger". I suppose now we agree that 502 would not make kvm_s390_handle_diag larger. Right?
I understood that you prefer 500+4 over 502 because the latter would make kvm_s390_handle_diag larger. Now that we have, I hope clarified, that 502 would not make the switch larger, do you still prefer 500+4?
BTW your insights are very appreciated!
Regards,
Halil
Re: [PATCH v1 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT
Am 01.10.24 um 15:31 schrieb Halil Pasic:
Quoted 23 lines
On Tue, 1 Oct 2024 11:15:02 +0200
Christian Borntraeger <[email protected]> wrote:
[..]Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
So 500+4 should probably not cause any harm apart from branch prediction going wrong the first 2 or 3 notifies.
502 will make
kvm_s390_handle_diaglarger.What do you mean by this last paragraph?
[..]
Quoted 7 lines
gcc has logic for switch statements that decide about branch table or a chained compare+jump. I think due to spectre gcc now avoids indirect branches as much as possible but still a larger switch statement might kick the decision from inline compare/jump to a branch table.
I am not worried in this particular case this was more or less a "what could go wrong".
Hm, you did state that "502 will make
kvm_s390_handle_diaglarger". I suppose now we agree that 502 would not makekvm_s390_handle_diaglarger. Right?
Quoted 5 lines
I understood that you prefer 500+4 over 502 because the latter would make
kvm_s390_handle_diaglarger. Now that we have, I hope clarified, that 502 would not make the switch larger, do you still prefer 500+4?BTW your insights are very appreciated!
OK you mean that diag502 is not handled in the kernel but instead via default. Yes you are right. So it should not matter I guess.
Re: [PATCH v1 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT
In reply to Christian BorntraegerQuoted 27 lines · Christian Borntraeger
Am 27.09.24 um 20:05 schrieb Halil Pasic:
Quoted 26 lines
Quoted 14 lines · On Thu, 12 Sep 2024 10:19:00 +0200 Thomas Huth <[email protected]> wrote:
hw/s390x/s390-hypercall.h line 23
Quoted 11 lines
hw/s390x/s390-hypercall.h +1
-0@@ -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 4int handle_diag_500 (CPUS390XState *env);Reviewed-by Thomas Huth <[email protected]>Quoted 5 lines
Sounds very reasonable to me - but it would be good to get an Ack/Reviewed-by from IBM folks here (in case they prefer a different interface)... hope they'll join the discussion!
Thomas
According to
Documentation/virt/kvm/s390/s390-diag.rstin the linux source tree DIAG 500 is for kvm virtio funcions.
Quoted 8 lines
Quoted 4 lines
Based on the commit message this storagelimit DIAG is rather loosely tied to virtio if at all, so from that perspective DIAG may not be a perfect fit. OTOH I don't see a better fit either. I would prefer to have Christian's opinion on this. I have no strong opinion myself.
Some remarks:
500 with a new subcode would work, it is marked as KVM hypervisor call in our docs. 501 was used in the past for software breakpoints.
Right, we use it in the absence of KVM_CAP_S390_USER_INSTR0.
Quoted 3 lines
So we could use 502 as the next free one (This is reserved for KVM). We do have
kvm_statcounters for 500, not sure if people debugging virtio will care.
It would be one additional trigger during system boot, so likely not really an issue. We could always add new stats for selected subcodes (i.e, KVM_S390_VIRTIO_CCW_NOTIFY).
Quoted 9 lines
The only important question for me is, what code is generated by gcc for the switch statement and will any variant slow down the virtio doorbell.
diag.chasif (!vcpu->kvm->arch.css_support || (vcpu->run->s.regs.gprs[1] != KVM_S390_VIRTIO_CCW_NOTIFY)) return -EOPNOTSUPP;So 500+4 should probably not cause any harm apart from branch prediction going wrong the first 2 or 3 notifies.
Right, it's very unlikely to be noticeable at all.
Thanks for the feedback!
Signature · 3 lines
Cheers, David / dhildenb
PATCH 8/14 s390x/s390-stattrib-kvm: prepare memory devices and sparse memory layouts
In reply to David HildenbrandWith 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 | 63 +++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 23 deletions(-)
hw/s390x/s390-stattrib-kvm.c +40 -23
@@ -15,6 +15,7 @@#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,7 @@ 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 ; +unsigned long max =s390_get_memory_limit () /TARGET_PAGE_SIZE ;if (start_gfn + count > max) {error_report ("Out of memory bounds when setting storage attributes" );
@@ -103,39 +103,56 @@ 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 ; +unsigned long max =s390_get_memory_limit () /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.0
PATCH 9/14 s390x/s390-skeys: prepare for memory devices
In reply to David HildenbrandWith 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 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/s390x/s390-skeys.c +1 -3
@@ -251,9 +251,7 @@ 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 ()); - - skeys->key_count = machine->ram_size /TARGET_PAGE_SIZE ; + skeys->key_count =s390_get_memory_limit () /TARGET_PAGE_SIZE ; skeys->keydata =g_malloc0 (skeys->key_count);g_once_init_leave (&initialized,1 ); }
Signature · 1 line
2.46.0
PATCH 10/14 s390x/pv: check initial, not maximum RAM size
In reply to David HildenbrandWe actually want to check the available RAM, not the maximum RAM size.
--- target/s390x/kvm/pv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/kvm/pv.c +1 -1
@@ -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.0
Re: [PATCH v1 10/14] s390x/pv: check initial, not maximum RAM size
Quoted 3 lines · David Hildenbrand
We actually want to check the available RAM, not the maximum RAM size.
Signed-off-by David Hildenbrand <[email protected]>
Nit below.
Quoted 9 lines
--- target/s390x/kvm/pv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/s390x/kvm/pv.c +0
-0
target/s390x/kvm/pv.c bool s390_pv_vm_try_disable_async(S390CcwMachineState *ms) · line 139
Quoted 8 lines
target/s390x/kvm/pv.c +1
-1@@ -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; }
If I understood the kernel code right, the decision is made wrt the size of the gmap address space, which is the same as the limit set for the VM. So using s390_get_memory_limit would be semantically cleaner.
Re: [PATCH v1 10/14] s390x/pv: check initial, not maximum RAM size
Quoted 21 lines · Nina Schoetterl-Glausch
Quoted 3 lines · David Hildenbrand
We actually want to check the available RAM, not the maximum RAM size.
Signed-off-by David Hildenbrand <[email protected]>Reviewed-by Nina Schoetterl-Glausch <[email protected]>Nit below.
Quoted 14 lines
--- target/s390x/kvm/pv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/s390x/kvm/pv.c +1
-1@@ -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) ||
Quoted 8 lines
target/s390x/kvm/pv.c bool s390_pv_vm_try_disable_async(S390CcwMachineState *ms) · line 139
Quoted 3 lines
target/s390x/kvm/pv.c +0
-0!kvm_check_extension(kvm_state, KVM_CAP_S390_PROTECTED_ASYNC_DISABLE)) {return false; }If I understood the kernel code right, the decision is made wrt the size of the gmap address space, which is the same as the limit set for the VM. So using
s390_get_memory_limitwould be semantically cleaner.
I wonder if we should just drop the RAM size check. Not convinced the slightly faster reboot for such small VMs is really relevant? Makes the code more complicated than really necessary.
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v1 10/14] s390x/pv: check initial, not maximum RAM size
Quoted 31 lines · David Hildenbrand
Quoted 21 lines · Nina Schoetterl-Glausch
Quoted 3 lines · David Hildenbrand
We actually want to check the available RAM, not the maximum RAM size.
Signed-off-by David Hildenbrand <[email protected]>Reviewed-by Nina Schoetterl-Glausch <[email protected]>Nit below.
Quoted 14 lines
--- target/s390x/kvm/pv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/s390x/kvm/pv.c +1
-1@@ -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) ||Quoted 8 lines
target/s390x/kvm/pv.c bool s390_pv_vm_try_disable_async(S390CcwMachineState *ms) · line 139
Quoted 3 lines
target/s390x/kvm/pv.c +0
-0!kvm_check_extension(kvm_state, KVM_CAP_S390_PROTECTED_ASYNC_DISABLE)) {return false; }If I understood the kernel code right, the decision is made wrt the size of the gmap address space, which is the same as the limit set for the VM. So using
s390_get_memory_limitwould be semantically cleaner.
Quoted 3 lines
I wonder if we should just drop the RAM size check. Not convinced the slightly faster reboot for such small VMs is really relevant? Makes the code more complicated than really necessary.
Thinking about it,
target/s390x/kvm/pv.c +1 -1
@@ -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; }
Is probably the easiest change, thanks!
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v1 10/14] s390x/pv: check initial, not maximum RAM size
In reply to David HildenbrandAm 24.09.24 um 22:17 schrieb David Hildenbrand:
Quoted 31 lines · Nina Schoetterl-Glausch
Quoted 21 lines · David Hildenbrand
Quoted 3 lines
We actually want to check the available RAM, not the maximum RAM size.
Signed-off-by David Hildenbrand <[email protected]>Reviewed-by Nina Schoetterl-Glausch <[email protected]>Nit below.
Quoted 14 lines
---
target/s390x/kvm/pv.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)target/s390x/kvm/pv.c +1
-1@@ -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) ||Quoted 8 lines
target/s390x/kvm/pv.c bool s390_pv_vm_try_disable_async(S390CcwMachineState *ms) · line 139
Quoted 3 lines
target/s390x/kvm/pv.c +0
-0!kvm_check_extension(kvm_state, KVM_CAP_S390_PROTECTED_ASYNC_DISABLE)) { return false; }If I understood the kernel code right, the decision is made wrt the size of the gmap address space, which is the same as the limit set for the VM. So using
s390_get_memory_limitwould be semantically cleaner.
Quoted 1 line
I wonder if we should just drop the RAM size check. Not convinced the slightly faster reboot for such small VMs is really relevant? Makes the code more complicated than really necessary.
IIRC there have been functional issues with small guests and asnyc. Claudio, do you remember?
Re: [PATCH v1 10/14] s390x/pv: check initial, not maximum RAM size
Quoted 32 lines · On Mon, 30 Sep 2024 13:15:52 +0200 Christian Borntraeger…
Am 24.09.24 um 22:17 schrieb David Hildenbrand:
Quoted 31 lines · Nina Schoetterl-Glausch
Quoted 29 lines · David Hildenbrand
Quoted 3 lines
We actually want to check the available RAM, not the maximum RAM size.
Signed-off-by David Hildenbrand <[email protected]>Reviewed-by Nina Schoetterl-Glausch <[email protected]>Nit below.
Quoted 9 lines
---
target/s390x/kvm/pv.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)target/s390x/kvm/pv.c +0
-0target/s390x/kvm/pv.c bool s390_pv_vm_try_disable_async(S390CcwMachineState *ms) · line 139
Quoted 8 lines
target/s390x/kvm/pv.c +1
-1@@ -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; }If I understood the kernel code right, the decision is made wrt the size of the gmap address space, which is the same as the limit set for the VM. So using
s390_get_memory_limitwould be semantically cleaner.
Quoted 3 lines
Quoted 1 line
I wonder if we should just drop the RAM size check. Not convinced the slightly faster reboot for such small VMs is really relevant? Makes the code more complicated than really necessary.
IIRC there have been functional issues with small guests and asnyc. Claudio, do you remember?
if we are <2G, KVM allocates a segment table as the highest level table for the gmap ASCE. there are pointers lurking around in the reverse mapping prefix_tree, which point directly into segment tables.
if the ASCE is region3 or higher, that's not an issue. if it's a segment table, then it's an issue, because those pointers will end up pointing into freed memory, once the old asce is freed.
in short, we have to guarantee that we will never set aside a gmap ASCE if it is a segment table.
Re: [PATCH v1 10/14] s390x/pv: check initial, not maximum RAM size
Quoted 43 lines · Claudio Imbrenda
Quoted 32 lines · On Mon, 30 Sep 2024 13:15:52 +0200 Christian Borntraeger…
Am 24.09.24 um 22:17 schrieb David Hildenbrand:
Quoted 31 lines · Nina Schoetterl-Glausch
Quoted 29 lines · David Hildenbrand
Quoted 3 lines
We actually want to check the available RAM, not the maximum RAM size.
Signed-off-by David Hildenbrand <[email protected]>Reviewed-by Nina Schoetterl-Glausch <[email protected]>Nit below.
Quoted 9 lines
--- target/s390x/kvm/pv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/s390x/kvm/pv.c +0
-0target/s390x/kvm/pv.c bool s390_pv_vm_try_disable_async(S390CcwMachineState *ms) · line 139
Quoted 8 lines
target/s390x/kvm/pv.c +1
-1@@ -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; }If I understood the kernel code right, the decision is made wrt the size of the gmap address space, which is the same as the limit set for the VM. So using
s390_get_memory_limitwould be semantically cleaner.Quoted 3 lines
Quoted 1 line
I wonder if we should just drop the RAM size check. Not convinced the slightly faster reboot for such small VMs is really relevant? Makes the code more complicated than really necessary.
IIRC there have been functional issues with small guests and asnyc. Claudio, do you remember?
if we are <2G, KVM allocates a segment table as the highest level table for the gmap ASCE. there are pointers lurking around in the reverse mapping
prefix_tree, which point directly into segment tables.
Quoted 6 lines
if the ASCE is region3 or higher, that's not an issue. if it's a segment table, then it's an issue, because those pointers will end up pointing into freed memory, once the old asce is freed.
in short, we have to guarantee that we will never set aside a gmap ASCE if it is a segment table.
Thanks for the details, the kernel seems to properly safeguard against that. For now, I'll turn it into a check against the memory limit, which directly translates to the gmap ASCE used.
Thanks!
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v1 10/14] s390x/pv: check initial, not maximum RAM size
Quoted 44 lines · On Mon, 30 Sep 2024 15:14:52 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 43 lines · Claudio Imbrenda
Quoted 32 lines · On Mon, 30 Sep 2024 13:15:52 +0200 Christian Borntraeger…
Am 24.09.24 um 22:17 schrieb David Hildenbrand:
Quoted 31 lines · Nina Schoetterl-Glausch
Quoted 29 lines · David Hildenbrand
Quoted 3 lines
We actually want to check the available RAM, not the maximum RAM size.
Signed-off-by David Hildenbrand <[email protected]>Reviewed-by Nina Schoetterl-Glausch <[email protected]>Nit below.
Quoted 9 lines
--- target/s390x/kvm/pv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/s390x/kvm/pv.c +0
-0target/s390x/kvm/pv.c bool s390_pv_vm_try_disable_async(S390CcwMachineState *ms) · line 139
Quoted 8 lines
target/s390x/kvm/pv.c +1
-1@@ -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; }If I understood the kernel code right, the decision is made wrt the size of the gmap address space, which is the same as the limit set for the VM. So using
s390_get_memory_limitwould be semantically cleaner.Quoted 3 lines
Quoted 1 line
I wonder if we should just drop the RAM size check. Not convinced the slightly faster reboot for such small VMs is really relevant? Makes the code more complicated than really necessary.
IIRC there have been functional issues with small guests and asnyc. Claudio, do you remember?
if we are <2G, KVM allocates a segment table as the highest level table for the gmap ASCE. there are pointers lurking around in the reverse mapping
prefix_tree, which point directly into segment tables.
Quoted 8 lines
Quoted 6 lines
if the ASCE is region3 or higher, that's not an issue. if it's a segment table, then it's an issue, because those pointers will end up pointing into freed memory, once the old asce is freed.
in short, we have to guarantee that we will never set aside a gmap ASCE if it is a segment table.
Thanks for the details, the kernel seems to properly safeguard against
it does, but it returns an error if userspace tries; the check there is to prevent qemu from emitting confusing error messages.
Quoted 2 lines
that. For now, I'll turn it into a check against the memory limit, which directly translates to the gmap ASCE used.
sounds good
Quoted 2 lines
Thanks!
no problem :)
PATCH 11/14 s390x/s390-virtio-ccw: prepare for memory devices
In reply to David HildenbrandLet'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 | 25 +++++++++++++++++++++++-- hw/s390x/sclp.c | 6 +++++- 2 files changed, 28 insertions(+), 3 deletions(-)
hw/s390x/s390-virtio-ccw.c +23 -2
@@ -126,7 +126,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 hw_limit; +uint64_t hw_limit, devmem_base, devmem_size;int ret;if (!QEMU_IS_ALIGNED (ram_size,1 * MiB)) {
@@ -140,7 +140,21 @@ static void s390_memory_init(MachineState *machine)exit (EXIT_FAILURE ); } - ret =s390_set_memory_limit (ram_size, &hw_limit); + 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 + + ret =s390_set_memory_limit (devmem_base + devmem_size, &hw_limit);if (ret == -E2BIG ) {error_report ("host supports a maximum of %" PRIu64" GB" , hw_limit / GiB);
@@ -153,6 +167,13 @@ static void s390_memory_init(MachineState *machine)/* 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
@@ -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.0
PATCH 12/14 s390x: introduce s390_get_max_pagesize()
In reply to David HildenbrandLet's add a way to return the value (successfully) set via s390_set_max_pagesize() previously. This will be helpful to reject hotplugged memory devices that would exceed this initially set page size.
--- target/s390x/cpu-sysemu.c | 16 ++++++++++++++++ target/s390x/cpu.h | 1 + 2 files changed, 17 insertions(+)
target/s390x/cpu-sysemu.c +16 -0
@@ -278,11 +278,27 @@ uint64_t s390_get_memory_limit(void)return memory_limit; } +static uint64_t max_pagesize; +void s390_set_max_pagesize (uint64_t pagesize,Error **errp) { +ERRP_GUARD (); + +if (max_pagesize) { +error_setg (errp,"Maximum page size can only be set once" ); +return ; + }if (kvm_enabled ()) {kvm_s390_set_max_pagesize (pagesize, errp); } +if (!*errp) { + max_pagesize = pagesize; + } +} + +uint64_t s390_get_max_pagesize (void ) +{ +return max_pagesize; }void s390_cmma_reset (void )
target/s390x/cpu.h +1 -0
@@ -897,6 +897,7 @@ void s390_crypto_reset(void);int s390_set_memory_limit (uint64_t new_limit,uint64_t *hw_limit);uint64_t s390_get_memory_limit (void );void s390_set_max_pagesize (uint64_t pagesize,Error **errp); +uint64_t s390_get_max_pagesize (void );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.0
Re: [PATCH v1 12/14] s390x: introduce s390_get_max_pagesize()
Quoted 6 lines · David Hildenbrand
Let's add a way to return the value (successfully) set via
s390_set_max_pagesize()previously. This will be helpful to reject hotplugged memory devices that would exceed this initially set page size.Signed-off-by David Hildenbrand <[email protected]>---
I'll send a v2 shortly, this patch will become:
From 687f72e488ebed59e57793699d26feb4eebdc9e3 Mon Sep 17 00:00:00 2001
From: David Hildenbrand <[email protected]>
Date: Sun, 8 Sep 2024 23:25:27 +0200
Subject: [PATCH] s390x: remember the maximum page size
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
@@ -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
@@ -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
@@ -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
@@ -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 · 8 lines
2.46.1 -- Cheers, David / dhildenb
PATCH 13/14 s390x/virtio-ccw: add support for virtio based memory devices
In reply to David HildenbrandLet's implement support for abstract virtio based memory devices, using the virtio-pci implementation as an orientation.
As we neither support virtio-mem or virtio-pmem yet, the code is effectively unused and not wired up. We'll implement support for virtio-mem based on this next.
--- MAINTAINERS | 2 + hw/s390x/meson.build | 1 + hw/s390x/virtio-ccw-md.c | 153 +++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw-md.h | 44 +++++++++++ hw/virtio/Kconfig | 1 + 5 files changed, 201 insertions(+) create mode 100644 hw/s390x/virtio-ccw-md.c create mode 100644 hw/s390x/virtio-ccw-md.h
MAINTAINERS +2 -0
@@ -2400,6 +2400,8 @@ 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/virtio/virtio-md-pci.c F: include/hw/virtio/virtio-md-pci.h F: stubs/virtio-md-pci.c
hw/s390x/meson.build +1 -0
@@ -48,6 +48,7 @@ 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) hw_arch += {'s390x': s390x_ss}
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
@@ -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.0
PATCH 14/14 s390x: virtio-mem support
In reply to David HildenbrandLet'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=on2. 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/mem03. 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/mem04. 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/mem05. 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/mem06. 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/mem0Trying 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.
Note that we won't wire up virtio-mem-pci (should currently be impossible due to lack of support for MSI-X), but we'll add a safety net to reject plugging them.
--- MAINTAINERS | 2 + hw/s390x/Kconfig | 1 + hw/s390x/meson.build | 1 + hw/s390x/s390-virtio-ccw.c | 45 +++++++- hw/s390x/virtio-ccw-mem.c | 226 +++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw-mem.h | 34 ++++++ hw/virtio/virtio-mem.c | 4 +- 7 files changed, 311 insertions(+), 2 deletions(-) create mode 100644 hw/s390x/virtio-ccw-mem.c create mode 100644 hw/s390x/virtio-ccw-mem.h
MAINTAINERS +2 -0
@@ -2413,6 +2413,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
@@ -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
@@ -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) hw_arch += {'s390x': s390x_ss}
hw/s390x/s390-virtio-ccw.c +44 -1
82 lines not on this page · raw message
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
@@ -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 /* QEMU_VIRTIO_MEM_PCI_H */
hw/virtio/virtio-mem.c +3 -1
@@ -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;
@@ -161,7 +163,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.0
Quoted 26 lines · David Hildenbrand
This series is based on:
[PATCH v2] virtio: kconfig: memory devices are PCI only [1]I finally found the time (IOW forced myself) to finish virtio-mem support on s390x. The last RFC was from 2020, so I won't talk about what changed -- a lot changed in the meantime :)
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 migrationMore 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.
Quoted 8 lines
This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented 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)
I don't see anything needing virtio specific here, let me know if I missed anything.
A quick look is fine so I guess you can add
Quoted 69 lines
I'll send out the kernel driver bits soon.
[1] https://lkml.kernel.org/r/[email protected]
[2] https://gitlab.com/davidhildenbrand/s390x-os-virt-specCc 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 David Hildenbrand <[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: introduces390_get_memory_limit()s390x/s390-hypercall: introduce DIAG500STORAGE_LIMITs390x/s390-stattrib-kvm: prepare memory devices and sparse memory
layouts
s390x/s390-skeys: prepare for memory devices
s390x/pv: check initial, not maximum RAM size s390x/s390-virtio-ccw: prepare for memory devices
s390x: introduces390_get_max_pagesize()s390x/virtio-ccw: add support for virtio based memory devices
s390x: virtio-mem supportMAINTAINERS | 4 + hw/s390x/Kconfig | 1 + hw/s390x/meson.build | 4 +- hw/s390x/s390-hypercall.c | 77 +++++++++++ hw/s390x/s390-hypercall.h | 25 ++++ hw/s390x/s390-skeys.c | 4 +- hw/s390x/s390-stattrib-kvm.c | 63 +++++---- hw/s390x/s390-virtio-ccw.c | 143 +++++++++++++-------- hw/s390x/s390-virtio-hcall.c | 41 ------ hw/s390x/s390-virtio-hcall.h | 25 ---- hw/s390x/sclp.c | 17 +-- 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 +- target/s390x/cpu-sysemu.c | 35 ++++- target/s390x/cpu.h | 2 + target/s390x/kvm/kvm.c | 12 +- target/s390x/kvm/pv.c | 2 +- target/s390x/tcg/misc_helper.c | 6 +- 22 files changed, 746 insertions(+), 177 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.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.hSignature · 1 line
2.46.0
Quoted 37 lines · Michael S. Tsirkin
Quoted 26 lines · David Hildenbrand
This series is based on:
[PATCH v2] virtio: kconfig: memory devices are PCI only [1]I finally found the time (IOW forced myself) to finish virtio-mem support on s390x. The last RFC was from 2020, so I won't talk about what changed -- a lot changed in the meantime :)
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 migrationMore 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.
Quoted 8 lines
This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented 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 2 lines
I don't see anything needing virtio specific here, let me know if I missed anything.
No, it's really just wiring up virtio-mem.
Quoted 2 lines
A quick look is fine so I guess you can add
Thanks!
Signature · 3 lines
Cheers, David / dhildenb
Quoted 2 lines · David Hildenbrand
This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented at [2] once this+kernel part go upstream.
Why not in Documentation/virt/kvm/s390/?s390-diag.rst is very similar already.
I'd rather have it in a shared and bigger repo than in your personal gitlab one. Maybe there's a space somewhere in QEMU or the Virtio team's repos that would be a good fit if the kernel's docu isn't the right place?
Quoted 6 lines · Janosch Frank
Quoted 2 lines · David Hildenbrand
This series introduces a new diag(500) "STORAGE LIMIT" subcode that will be documented at [2] once this+kernel part go upstream.
Why not in
Documentation/virt/kvm/s390/?s390-diag.rstis very similar already.
I can document it anywhere people fancy, really I don't care. But this has some history. The last time we discussed it [1] there was:
"Regardless what we end up with, this needs to be specified somewhere(tm)." from Conny
"It must be well defined and easy to find also for kernel developers who actually have to care about memory detection code :)" from Heiko.
And then
"the kernel's s390-diag.rst should also point to it ... Nothing as complicated as an OASIS spec, but maybe a git??b project?" from Conny
Quoted 4 lines
I'd rather have it in a shared and bigger repo than in your personal gitlab one. Maybe there's a space somewhere in QEMU or the Virtio team's repos that would be a good fit if the kernel's docu isn't the right place?
At this point, outside of kernel/QEMU feels like the right thing to do. Conny is already a co-maintainer of my "personal" (;)) gitlab.
And now I realize that I CCed Heiko on the Linux series but not the QEMU series. My bad.
[1] https://lore.kernel.org/all/[email protected]/
Signature · 3 lines
Cheers, David / dhildenb
Quoted 5 lines
Quoted 4 lines
I'd rather have it in a shared and bigger repo than in your personal gitlab one. Maybe there's a space somewhere in QEMU or the Virtio team's repos that would be a good fit if the kernel's docu isn't the right place?
Quoted 8 lines
At this point, outside of kernel/QEMU feels like the right thing to do. Conny is already a co-maintainer of my "personal" (;)) gitlab.
And now I realize that I CCed Heiko on the Linux series but not the QEMU series. My bad.
No prob. Or if you want it in virtio spec, that's also fine.
Quoted 9 lines · Michael S. Tsirkin
Quoted 9 lines
Quoted 4 lines
I'd rather have it in a shared and bigger repo than in your personal gitlab one. Maybe there's a space somewhere in QEMU or the Virtio team's repos that would be a good fit if the kernel's docu isn't the right place?
At this point, outside of kernel/QEMU feels like the right thing to do. Conny is already a co-maintainer of my "personal" (;)) gitlab.
Quoted 7 lines
Quoted 4 lines
And now I realize that I CCed Heiko on the Linux series but not the QEMU series. My bad.
No prob. Or if you want it in virtio spec, that's also fine.
The virtio spec makes sense for documenting things needed to implement it, but what I liked about the gitlab project is that it tries to go into more s390-specific aspects (that feel a bit out of scope for the virtio spec), and that it provides a place to document non-virtio related interfaces.
Anyway, if we want to proceed with the gitlab project, would it make sense to create an org for it, so that it doesn't look like David's personal project? In any case, while I'm happy to stay on, I'm not that involved with s390 anymore, and it might make sense to add more people to it.
Quoted 25 lines · Cornelia Huck
Quoted 9 lines · Michael S. Tsirkin
Quoted 9 lines
Quoted 4 lines
I'd rather have it in a shared and bigger repo than in your personal gitlab one. Maybe there's a space somewhere in QEMU or the Virtio team's repos that would be a good fit if the kernel's docu isn't the right place?
At this point, outside of kernel/QEMU feels like the right thing to do. Conny is already a co-maintainer of my "personal" (;)) gitlab.
Quoted 7 lines
Quoted 4 lines
And now I realize that I CCed Heiko on the Linux series but not the QEMU series. My bad.
No prob. Or if you want it in virtio spec, that's also fine.
The virtio spec makes sense for documenting things needed to implement it, but what I liked about the gitlab project is that it tries to go into more s390-specific aspects (that feel a bit out of scope for the virtio spec), and that it provides a place to document non-virtio related interfaces.
Quoted 3 lines
Anyway, if we want to proceed with the gitlab project, would it make sense to create an org for it, so that it doesn't look like David's personal project?
I had that in mind as well, I can move the project.
Quoted 3 lines
In any case, while I'm happy to stay on, I'm not that involved with s390 anymore, and it might make sense to add more people to it.
Indeed!
Signature · 3 lines
Cheers, David / dhildenb
Quoted 3 lines · On Wed, 11 Sep 2024 21:09:27 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 3 lines
Anyway, if we want to proceed with the gitlab project, would it make sense to create an org for it, so that it doesn't look like David's personal project?
Frankly, I would prefer making Documentation/virt/kvm/s390/s390-diag.rst the authoritative documentation on DIAGs.
My train of thought is DIAG 500 is a KVM thing, and KVM is a linux kernel thing, so it just feels right for the documentatio to live within the linux source tree.
I may have missed some of the discussion: what were the benefits of having this in its separate project/repository?
Regards,
Halil
Quoted 7 lines · Halil Pasic
Quoted 3 lines · On Wed, 11 Sep 2024 21:09:27 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 3 lines
Anyway, if we want to proceed with the gitlab project, would it make sense to create an org for it, so that it doesn't look like David's personal project?
Quoted 6 lines
Frankly, I would prefer making
Documentation/virt/kvm/s390/s390-diag.rstthe authoritative documentation on DIAGs.My train of thought is DIAG 500 is a KVM thing, and KVM is a linux kernel thing, so it just feels right for the documentatio to live within the linux source tree.
QEMU/TCG is the proof that KVM is not necessarily involved.
Are you sure that no other OS out there besides Linux implements virtio on s390x, or would want to implement it? :)
Quoted 3 lines
I may have missed some of the discussion: what were the benefits of having this in its separate project/repository?
Having it independent of the implementation.
Signature · 3 lines
Cheers, David / dhildenb
Quoted 11 lines · On Fri, 27 Sep 2024 20:29:19 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 10 lines · Halil Pasic
Quoted 3 lines · On Wed, 11 Sep 2024 21:09:27 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 3 lines
Anyway, if we want to proceed with the gitlab project, would it make sense to create an org for it, so that it doesn't look like David's personal project?
Frankly, I would prefer making
Documentation/virt/kvm/s390/s390-diag.rstthe authoritative documentation on DIAGs.
Quoted 9 lines
Quoted 3 lines
My train of thought is DIAG 500 is a KVM thing, and KVM is a linux kernel thing, so it just feels right for the documentatio to live within the linux source tree.
QEMU/TCG is the proof that KVM is not necessarily involved.
Are you sure that no other OS out there besides Linux implements virtio on s390x, or would want to implement it? :)
As Christian has pointed out in another thread DIAG 500 is documented as the KVM hypervisor call, and that made me argue it is a KVM thing.
You are right KVM is not necessarily involved, and neither is QEMU. For me it is not about the components involved in the visualization, but about the people, projects and governance.
IMHO this is basically extending the s390 architecture. We are guaranteed to not collide with the Architecture because DIAG 500 is reserved for KVM as a project I guess.
Quoted 6 lines
Quoted 3 lines
I may have missed some of the discussion: what were the benefits of having this in its separate project/repository?
Having it independent of the implementation.
That is a valid point. But IMHO the benefit of having this independent, does not justify the churn of having a separate project with its own governance, and communication infrastructure. And I suppose for an open(?) specification, one would need those things.
No strong opinions though. If Christian, Janosch and Claudio are in favor of a separate "Specifications for open-source virtualization on s390x (IBM z Systems)" project, I'm fine with it as well.
Regards,
Halil
Quoted 27 lines · Halil Pasic
Quoted 11 lines · On Fri, 27 Sep 2024 20:29:19 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 10 lines · Halil Pasic
Quoted 3 lines · On Wed, 11 Sep 2024 21:09:27 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 3 lines
Anyway, if we want to proceed with the gitlab project, would it make sense to create an org for it, so that it doesn't look like David's personal project?
Frankly, I would prefer making
Documentation/virt/kvm/s390/s390-diag.rstthe authoritative documentation on DIAGs.Quoted 9 lines
Quoted 3 lines
My train of thought is DIAG 500 is a KVM thing, and KVM is a linux kernel thing, so it just feels right for the documentatio to live within the linux source tree.
QEMU/TCG is the proof that KVM is not necessarily involved.
Are you sure that no other OS out there besides Linux implements virtio on s390x, or would want to implement it? :)
As Christian has pointed out in another thread DIAG 500 is documented as the KVM hypervisor call, and that made me argue it is a KVM thing.
Quoted 7 lines
You are right KVM is not necessarily involved, and neither is QEMU. For me it is not about the components involved in the visualization, but about the people, projects and governance.
IMHO this is basically extending the s390 architecture. We are guaranteed to not collide with the Architecture because DIAG 500 is reserved for KVM as a project I guess.
That's my understanding. I assume because the CCW virtio machine started out as KVM-only, documenting that it is "KVM ONLY" may be because of historical reasons.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
I may have missed some of the discussion: what were the benefits of having this in its separate project/repository?
Quoted 7 lines
Quoted 2 lines
Having it independent of the implementation.
That is a valid point. But IMHO the benefit of having this independent, does not justify the churn of having a separate project with its own governance, and communication infrastructure. And I suppose for an open(?) specification, one would need those things.
I don't see the need to bring in all that bureaucracy. The original idea was simple: if QEMU/TCG or QEMU/KVM implement a hypercall (IOW: it was acked by the s390x maintainers), we document it somewhere.
Implementing something in QEMU and then modifying a KVM document in the kernel tree sounded odd.
It is a valid question to ask: what if any other hypervisor (cloud-hypervisor etc.) would want to implement a custom diag500 hypercall, and who would ack it. But I don't really think that we would have to sort this out this at this point in time.
Quoted 4 lines
No strong opinions though. If Christian, Janosch and Claudio are in favor of a separate "Specifications for open-source virtualization on s390x (IBM z Systems)" project, I'm fine with it as well.
I'm more than happy if we don't need that. As said, I'm happy to document wherever people tell me to document.
4 years ago we thought that having a separate repository was a good idea, maybe it is no longer. In that case, s390x mainters please let me know what to do :)
Signature · 3 lines
Cheers, David / dhildenb
Quoted 7 lines · David Hildenbrand
Quoted 6 lines · Halil Pasic
Quoted 3 lines · On Fri, 27 Sep 2024 20:29:19 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 2 lines · Halil Pasic
On Wed, 11 Sep 2024 21:09:27 +0200
David Hildenbrand <[email protected]> wrote:
[...]
Quoted 22 lines
Quoted 4 lines
That is a valid point. But IMHO the benefit of having this independent, does not justify the churn of having a separate project with its own governance, and communication infrastructure. And I suppose for an open(?) specification, one would need those things.
I don't see the need to bring in all that bureaucracy. The original idea was simple: if QEMU/TCG or QEMU/KVM implement a hypercall (IOW: it was acked by the s390x maintainers), we document it somewhere.
Implementing something in QEMU and then modifying a KVM document in the kernel tree sounded odd.
It is a valid question to ask: what if any other hypervisor (cloud-hypervisor etc.) would want to implement a custom diag500 hypercall, and who would ack it. But I don't really think that we would have to sort this out this at this point in time.
Quoted 4 lines
No strong opinions though. If Christian, Janosch and Claudio are in favor of a separate "Specifications for open-source virtualization on s390x (IBM z Systems)" project, I'm fine with it as well.
Quoted 7 lines
I'm more than happy if we don't need that. As said, I'm happy to document wherever people tell me to document.
4 years ago we thought that having a separate repository was a good idea, maybe it is no longer. In that case, s390x mainters please let me know what to do :)
I'd like to at least have a partial documentation in the kernel if not a full one. You can add a link to your repo to that.
Even if they go out of sync I'd rather have documentation where I'd expect it (Linux) than only the repo. IMHO duplication isn't a gigantic issue here.
We also have an internal space where KVM architecture is being stored (currently a handful of documents) and we'll store it there as well, including a link to the repo.
Quoted 36 lines · Janosch Frank
Quoted 7 lines · David Hildenbrand
Quoted 6 lines · Halil Pasic
Quoted 3 lines · On Fri, 27 Sep 2024 20:29:19 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 2 lines · Halil Pasic
On Wed, 11 Sep 2024 21:09:27 +0200
David Hildenbrand <[email protected]> wrote:[...]
Quoted 25 lines
Quoted 4 lines
That is a valid point. But IMHO the benefit of having this independent, does not justify the churn of having a separate project with its own governance, and communication infrastructure. And I suppose for an open(?) specification, one would need those things.
I don't see the need to bring in all that bureaucracy. The original idea was simple: if QEMU/TCG or QEMU/KVM implement a hypercall (IOW: it was acked by the s390x maintainers), we document it somewhere.
Implementing something in QEMU and then modifying a KVM document in the kernel tree sounded odd.
It is a valid question to ask: what if any other hypervisor (cloud-hypervisor etc.) would want to implement a custom diag500 hypercall, and who would ack it. But I don't really think that we would have to sort this out this at this point in time.
Quoted 4 lines
No strong opinions though. If Christian, Janosch and Claudio are in favor of a separate "Specifications for open-source virtualization on s390x (IBM z Systems)" project, I'm fine with it as well.
I'm more than happy if we don't need that. As said, I'm happy to document wherever people tell me to document.
Quoted 7 lines
Quoted 4 lines
4 years ago we thought that having a separate repository was a good idea, maybe it is no longer. In that case, s390x mainters please let me know what to do :)
I'd like to at least have a partial documentation in the kernel if not a full one. You can add a link to your repo to that.
Makes sense.
Quoted 4 lines
Even if they go out of sync I'd rather have documentation where I'd expect it (Linux) than only the repo. IMHO duplication isn't a gigantic issue here.
Agreed.
Quoted 4 lines
We also have an internal space where KVM architecture is being stored (currently a handful of documents) and we'll store it there as well, including a link to the repo.
Perfect. If there is a way to enable that repository, that would be great. For the time being I'll document it there as well.
Thanks!
Signature · 3 lines
Cheers, David / dhildenb