Skip to contentSkip to conversation

KVM: s390: vsie: fix instruction retry for nested guests in ESA mode

PATCH New Yvan Janssens 2 participants 4 messages Nov 25

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover KVM: s390: vsie: fix instruction retry for nested guests in ESA mode

This series of patches fixes vsie rewinding the PSW of ESA-mode nested guests in the wrong doubleword, which made an intercepted instruction be skipped instead of repeated. Patch 1 is the fix, patch 2 is a selftest that reproduces the issue. The base is the current mainline (v7.4-rc4-260).

Claude has been used to try to find this bug; it was used to figure out what went wrong and what would be the most appropriate way to fix the problem. I've reviewed, verified and tested the results myself on my own machine (MTM 3907).

Changes in v2:
- patch 1: shorter commit message;
- patch 1: removed the comment block above vsie_rewind_psw(), added a short comment in the ESA branch (as requested by Janosch);
- dropped the Assisted-by trailers (removed from the documentation in the 7.4 cycle); the AI assistance is disclosed above instead;
- no code change in patch 2.

v1: https://lore.kernel.org/all/[email protected]/

Also - a note on the context of this fix; these problems were identified when trying to bring up Proxmox on s390x in my lab while adding support for non-Linux guests. This bug was found while trying to bring up z/VM as a KVM guest. There is another patch set on its way as an RFC to add the ESA/390-compatibility mode for first-level KVM guests, for programs that start in ESA/390 mode themselves, such as stand-alone utilities and the early IPL code of older systems. z/VM's ESA guests, e.g. CMS, already run as nested guests with this fix; what is still missing there is support for its ESA/XC guests, which is later work.

I understand the concern wrt. ESA accommodations; the annoying thing is that there are a bunch of potential guest OSes from the transition period from ESA to z/Arch only that need this to work to survive their initial bootstrap until they can reach z/Architecture mode; one example here is the IPL text used in z/OS 1.10->1.12.

I also understand that the support cycle for these systems expired long ago, and that the support cycle for a 3907 has also expired. My remaining question here is if you are open to support for this, as long as this does not provide a significant amount of overhead for maintenance.

If you want to discuss this off-list, I'm also available on the Open Mainframe Project Slack.

Yvan Janssens (2):
KVM: s390: vsie: Rewind the PSW of ESA mode guests in the right format
KVM: s390: selftests: Add a test for nested guests in ESA mode

 arch/s390/kvm/s390/vsie.c                     |  18 +-
 tools/testing/selftests/kvm/Makefile.kvm      |   1 +
 .../selftests/kvm/s390/vsie_esa_test.c        | 180 ++++++++++++++++++
 3 files changed, 197 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/s390/vsie_esa_test.c

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5

Signature · 1 line
2.47.3
#1 lore raw

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

ESA-mode guests in vsie have existed since commit b0ad874d9852 ("KVM:
s390: vsie: Allow non-zarch guests"); they use the 8-byte short PSW - the mask and instruction address share one doubleword.

vsie's PSW rewind originally still changed the second doubleword, which is unused in ESA mode, so the instruction is skipped instead of repeated. The visible effect is that the first STFLE after entering SIE does nothing in a nested guest.

This patch adds a vsie-specific rewind function that handles both formats; no short-PSW type is introduced - for ESA guests mask and address are written into the mask field.

Fixes b0ad874d9852 ("KVM: s390: vsie: Allow non-zarch guests")
---
 arch/s390/kvm/s390/vsie.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
arch/s390/kvm/s390/vsie.c +16 -2
index 3ce133f20fa2..ed40d40d89e4 100644
@@ -948,6 +948,20 @@ static inline void clear_vsie_icpt(struct vsie_page *vsie_page)
 	vsie_page->scb_s.icptcode = 0;
 }
 
+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;
+	}
+	/* ESA short PSW: mask and address both live in gpsw.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 +974,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 +1427,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;
Signature · 1 line
2.47.3
#2 lore raw

PATCH v2 2/2 KVM: s390: selftests: Add a test for nested guests in ESA mode

In reply to Yvan Janssens

Run a nested guest from a state description without the z/Architecture flag, with KVM_CAP_S390_VSIE_ESAMODE enabled, and let it execute STORE FACILITY LIST EXTENDED twice. vsie intercepts the first one of every SIE entry to shadow the facility list guest 2 designates and then has the instruction repeated.

The test checks that the second doubleword of the PSW field, which is not part of an ESA/390 PSW, comes back unchanged, that the PSW points behind the last instruction, and that the first instruction stored the designated list. What the second instruction stored is printed for diagnosis.

The test is skipped without the capability, without interpretive execution for the guest (SIEF2) and without facility 7 in the guest's model.

---
 tools/testing/selftests/kvm/Makefile.kvm      |   1 +
 .../selftests/kvm/s390/vsie_esa_test.c        | 180 ++++++++++++++++++
 2 files changed, 181 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/s390/vsie_esa_test.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
index 283c59d7649c..aef64ec2719c 100644
@@ -227,6 +227,7 @@ TEST_GEN_PROGS_s390 += s390/shared_zeropage_test
 TEST_GEN_PROGS_s390 += s390/ucontrol_test
 TEST_GEN_PROGS_s390 += s390/user_operexec
 TEST_GEN_PROGS_s390 += s390/keyop
+TEST_GEN_PROGS_s390 += s390/vsie_esa_test
 TEST_GEN_PROGS_s390 += rseq_test
 TEST_GEN_PROGS_s390 += s390/irq_routing
 TEST_GEN_PROGS_s390 += mmu_stress_test
tools/testing/selftests/kvm/s390/vsie_esa_test.c new file +180 -0

180 lines not on this page · raw message

Signature · 1 line
2.47.3