mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yvan Janssens <yvanj@cyber.gent>
To: Christian Borntraeger <borntraeger@linux.ibm.com>,
	Janosch Frank <frankja@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: David Hildenbrand <david@kernel.org>,
	Eric Farman <farman@linux.ibm.com>,
	Hendrik Brueckner <brueckner@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Shuah Khan <shuah@kernel.org>,
	kvm@vger.kernel.org, linux-s390@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] KVM: s390: vsie: Rewind the PSW of ESA mode guests in the right format
Date: Wed, 25 Nov 2026 16:16:06 +0100	[thread overview]
Message-ID: <20261125151607.3039477-2-yvanj@cyber.gent> (raw)
In-Reply-To: <20261125151607.3039477-1-yvanj@cyber.gent>

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@vger.kernel.org # 7.1+
Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Yvan Janssens <yvanj@cyber.gent>
---
 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



  reply	other threads:[~2026-11-25 15:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 15:16 [PATCH 0/2] KVM: s390: vsie: fix instruction retry for nested guests in ESA mode Yvan Janssens
2026-11-25 15:16 ` Yvan Janssens [this message]
2026-11-25 15:16 ` [PATCH 2/2] KVM: s390: selftests: Add a test " Yvan Janssens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125151607.3039477-2-yvanj@cyber.gent \
    --to=yvanj@cyber.gent \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=brueckner@linux.ibm.com \
    --cc=david@kernel.org \
    --cc=farman@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=svens@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®