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

From: Janosch Frank

Date: Wed Nov 25 2026 - 11:20:04 EST


On 11/25/26 4:16 PM, Yvan Janssens wrote:
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

I'm wondering if we should only copy the a DWORD back to the guest for the PSW in ESA mode and not the long PSW. On the other hand I'd like to have as little ESA accommodations in this code as possible. Sigh.

skipped instructions and the nested guest never stores a facility list.

While I do appreciate documentation of what a patch changes and why it changes it, I don't like lengthy explanations of basic concepts.
Please take the time to write this yourself if it's not 100% trivial. This helps me to decide if you actually understood the changes that you're proposing. Especially when you change obscure stuff like this :)

I'd suggest something like:

Basic ESA mode support for vsie was introduced with b0ad874d9852.
Such guests use the 8 byte short PSW instead of the 16 byte zArch PSW.
This means that the mask and the address have to share the same DWORD.

Unfortunately the vsie code does not consider this when rewinding the PSW address in the shadow scb and manipulates the (unused) second DWORD instead of the first. This patch adds a vsie specific rewind function to address that.

Since vsie only provides basic ESA support I'm not adding a short PSW and we make do with writing mask and address into the same PSW mask field.




Code seems fine.


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.
+ */

Please remove this comment it suffers from the same problem that the commit message has.

+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;
+ }

Please add a short comment that this is for the esa short psw and that's why everything is written to the mask.

+ 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;