[PATCH 1/2] KVM: s390: vsie: Rewind the PSW of ESA mode guests in the right format

From: Yvan Janssens

Date: Wed Nov 25 2026 - 10:17:21 EST


A state description without the z/Architecture flag holds the eight-byte
ESA/390 PSW in the first doubleword of its PSW field: the addressing mode
is bit 32 and the instruction address is in bits 33-63 of that doubleword
(Principles of Operation, "Program-Status Word" as it applies in the
ESA/390-compatibility mode). The second doubleword is not part of the
PSW.

Since nested guests can be run in ESA mode, vsie still rewinds the PSW of
their shadow state description as if it were a z/Architecture PSW. It
subtracts the instruction length from the second doubleword, which leaves
the instruction address alone and stores a wrapped address there
(0x7ffffffc for one four-byte instruction). The value is copied back into
the state description of guest 2 when the shadow is released.

The rewind is how vsie repeats an instruction: STORE FACILITY LIST
EXTENDED after the facility list that guest 2 designates has been
shadowed (handle_stfle()), MOVE PAGE after a fault was resolved
(vsie_handle_mvpg()), and the instruction that is reported with an
addressing exception when guest 3 touches memory guest 2 does not have.
For a guest in ESA mode the instruction is skipped instead. The first
STORE FACILITY LIST EXTENDED after every entry into SIE returns with its
operand and the condition code untouched, so a program in the nested
guest that looks at the facility list sees zeros.

Rewind the instruction address where the format of the state description
has it.

The selftest in the next patch reproduces the problem: on 7.3.6 the
second doubleword of the PSW field comes back as 0x7ffffff8 after two
skipped instructions and the nested guest never stores a facility list.

Fixes: b0ad874d9852 ("KVM: s390: vsie: Allow non-zarch guests")
Cc: stable@xxxxxxxxxxxxxxx # 7.1+
Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Yvan Janssens <yvanj@xxxxxxxxxx>
---
arch/s390/kvm/s390/vsie.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/arch/s390/kvm/s390/vsie.c b/arch/s390/kvm/s390/vsie.c
index 3ce133f20fa2..58afe913bff4 100644
--- a/arch/s390/kvm/s390/vsie.c
+++ b/arch/s390/kvm/s390/vsie.c
@@ -948,6 +948,25 @@ static inline void clear_vsie_icpt(struct vsie_page *vsie_page)
vsie_page->scb_s.icptcode = 0;
}

+/*
+ * Rewind the PSW of a shadow scb. An ESA mode guest has the eight-byte
+ * ESA/390 PSW in the first doubleword of the PSW field: the addressing mode
+ * in bit 32 and the instruction address in bits 33-63. The second doubleword
+ * is not part of its PSW.
+ */
+static void vsie_rewind_psw(struct kvm_s390_sie_block *scb, int ilen)
+{
+ u64 addr_mask;
+
+ if (atomic_read(&scb->cpuflags) & CPUSTAT_ZARCH) {
+ scb->gpsw.addr = __rewind_psw(scb->gpsw, ilen);
+ return;
+ }
+ addr_mask = scb->gpsw.mask & PSW32_ADDR_AMODE ? PSW32_ADDR_INSN : 0x00ffffffUL;
+ scb->gpsw.mask = (scb->gpsw.mask & ~PSW32_ADDR_INSN) |
+ ((scb->gpsw.mask - ilen) & addr_mask);
+}
+
/* rewind the psw and clear the vsie icpt, so we can retry execution */
static void retry_vsie_icpt(struct vsie_page *vsie_page)
{
@@ -960,7 +979,7 @@ static void retry_vsie_icpt(struct vsie_page *vsie_page)
if (!ilen)
ilen = 4;
}
- scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, ilen);
+ vsie_rewind_psw(scb_s, ilen);
clear_vsie_icpt(vsie_page);
}

@@ -1413,7 +1432,7 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
scb_s->icptcode = ICPT_PROGI;
scb_s->iprcc = PGM_ADDRESSING;
scb_s->pgmilc = 4;
- scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4);
+ vsie_rewind_psw(scb_s, 4);
rc = 1;
}
return rc;
--
2.47.3