On 29.04.25 07:20, Nicholas Miehlbradt wrote:
The reset performed by subcode 3 of the diag308 instruction specifies
that system memory should be reset. This patch implements that
behaviour.
Introduce S390_RESET_REIPL_CLEAR to differentiate between subcode 3 and
subcode 4 resets.
When doing a clear reset, discard the ramblock containing the system
ram.
Signed-off-by: Nicholas Miehlbradt <[email protected]>
---
hw/s390x/ipl.h | 1 +
hw/s390x/s390-virtio-ccw.c | 6 ++++++
target/s390x/diag.c | 3 +--
target/s390x/kvm/kvm.c | 6 +++++-
4 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/hw/s390x/ipl.h b/hw/s390x/ipl.h
index cb55101f06..9c38946363 100644
--- a/hw/s390x/ipl.h
+++ b/hw/s390x/ipl.h
@@ -38,6 +38,7 @@ enum s390_reset {
/* default is a reset not triggered by a CPU e.g. issued by QMP */
S390_RESET_EXTERNAL = 0,
S390_RESET_REIPL,
+ S390_RESET_REIPL_CLEAR,
S390_RESET_MODIFIED_CLEAR,
S390_RESET_LOAD_NORMAL,
S390_RESET_PV,
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 94edd42dd2..bc07158b16 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -455,6 +455,7 @@ static void s390_machine_reset(MachineState *machine,
ResetType type)
enum s390_reset reset_type;
CPUState *cs, *t;
S390CPU *cpu;
+ RAMBlock *rb = machine->ram->ram_block;
/*
* Temporarily drop the record/replay mutex to let rr_cpu_thread_fn()
@@ -479,6 +480,7 @@ static void s390_machine_reset(MachineState *machine,
ResetType type)
switch (reset_type) {
case S390_RESET_EXTERNAL:
case S390_RESET_REIPL:
+ case S390_RESET_REIPL_CLEAR:
/*
* Reset the subsystem which includes a AP reset. If a PV
* guest had APQNs attached the AP reset is a prerequisite to
@@ -489,6 +491,10 @@ static void s390_machine_reset(MachineState *machine,
ResetType type)
s390_machine_unprotect(ms);
}
+ if (reset_type == S390_RESET_REIPL_CLEAR) {
+ ram_block_discard_range(rb, 0 , qemu_ram_get_used_length(rb));
+ }
+
I suspect that we don't care about virtio-mem devices, because the
memory semantics are different (and usually they will get reset to "no
memory" during reboots either way -> discarded)
The only problem I see is with vfio devices is the new "memory pinned"
mode. [1]
There, we'd have to check if any such device is around (discarding of
ram is disabled?), and fallback to actual zeroing of memory.
[1] https://lkml.kernel.org/r/[email protected]
--
Cheers,
David / dhildenb