Skip to contentSkip to conversation

KVM: s390: Additional LPSW/E fixes

PATCH In review Janosch Frank 2 participants 6 messages Apr 23

Subsystems (4)
lore
Share & tools
lore

Janosch Frank

author maintainer
#0 lore raw

cover KVM: s390: Additional LPSW/E fixes

Another round of fixups for LPSW/E since Heiko found a problem with my fix and I found another pre-existing issue where the ilc is not being set to 0.

To verify my fixes I've added code to the bear test which loads an invalid PSW and checks the bear and ilc values. Due to the current s390 lib state I had to resort to real address memory accesses.

I'd expect the fixes to arrive via master while the test moves through next landing after Christian's cpumodel change.

I've added \n two the first fix to make the code a bit more readable.

Janosch Frank (3):
KVM: s390: selftests: Add load psw bear test
kvm: s390: Fix LPSW/E early exception bear behavior
kvm: s390: Fix lpsw/e spec exception ilc reporting

 arch/s390/kvm/priv.c                     |  20 +-
 tools/testing/selftests/kvm/Makefile.kvm |   1 +
 tools/testing/selftests/kvm/s390/bear.c  | 250 +++++++++++++++++++++++
 3 files changed, 267 insertions(+), 4 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/s390/bear.c
Signature · 1 line
2.51.0
author maintainer
#1 lore raw

PATCH 1/3 KVM: s390: selftests: Add load psw bear test

The bear is set for lpsw and lpswe, so let's check that also happens when kvm emulates these instructions.

Load PSW and all of its variants are only emulated by KVM if there's a pending machine check. Therefore the tests inject those but never open the masks to receive them.

---
 tools/testing/selftests/kvm/Makefile.kvm |   1 +
 tools/testing/selftests/kvm/s390/bear.c  | 250 +++++++++++++++++++++++
 2 files changed, 251 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/s390/bear.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
index 6471fa214a9f..9afb6479dbee 100644
@@ -207,6 +207,7 @@ TEST_GEN_PROGS_s390 += s390/user_operexec
 TEST_GEN_PROGS_s390 += s390/keyop
 TEST_GEN_PROGS_s390 += rseq_test
 TEST_GEN_PROGS_s390 += s390/irq_routing
+TEST_GEN_PROGS_s390 += s390/bear
 
 TEST_GEN_PROGS_riscv = $(TEST_GEN_PROGS_COMMON)
 TEST_GEN_PROGS_riscv += riscv/sbi_pmu_test
tools/testing/selftests/kvm/s390/bear.c new file +250 -0

250 lines not on this page · raw message

Signature · 1 line
2.51.0
author maintainer
#2 lore raw

PATCH 2/3 kvm: s390: Fix LPSW/E early exception bear behavior

In reply to Janosch Frank

When loading a PSW a lot of specification exceptions are recognized after the PSW has been loaded. In these cases the load PSW(E) succeeds but the loaded PSW was invalid. Since the load completed we need to set the bear.

Fixes 1653545abc68 ("KVM: s390: Fix lpsw/e breaking event handling")
---
 arch/s390/kvm/priv.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/s390/kvm/priv.c +6 -2
index cc0553da14cb..56e63679f9d1 100644
@@ -736,9 +736,11 @@ int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
 	gpsw->mask = (new_psw.mask & ~PSW32_MASK_BASE) << 32;
 	gpsw->mask |= new_psw.addr & PSW32_ADDR_AMODE;
 	gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE;
+	vcpu->arch.sie_block->gbea = iaddr;
+
 	if (!is_valid_psw(gpsw))
 		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
-	vcpu->arch.sie_block->gbea = iaddr;
+
 	return 0;
 }
 
@@ -762,9 +764,11 @@ static int handle_lpswe(struct kvm_vcpu *vcpu)
 	if (rc)
 		return kvm_s390_inject_prog_cond(vcpu, rc);
 	vcpu->arch.sie_block->gpsw = new_psw;
+	vcpu->arch.sie_block->gbea = iaddr;
+
 	if (!is_valid_psw(&vcpu->arch.sie_block->gpsw))
 		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
-	vcpu->arch.sie_block->gbea = iaddr;
+
 	return 0;
 }
 
Signature · 1 line
2.51.0
author maintainer
#3 lore raw

PATCH 3/3 kvm: s390: Fix lpsw/e spec exception ilc reporting

In reply to Janosch Frank

On early PSW specification exception the ILC has to be 0 according to architecture.

Fixes 48a3e950f4cee ("KVM: s390: Add support for machine checks.")
---
 arch/s390/kvm/priv.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
arch/s390/kvm/priv.c +12 -4
index 56e63679f9d1..9fd7d3f1d1e8 100644
@@ -713,6 +713,7 @@ int is_valid_psw(psw_t *psw)
 int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
 {
 	psw_t *gpsw = &vcpu->arch.sie_block->gpsw;
+	struct kvm_s390_pgm_info info = {};
 	psw32_t new_psw;
 	u64 addr, iaddr;
 	int rc;
@@ -738,14 +739,18 @@ int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
 	gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE;
 	vcpu->arch.sie_block->gbea = iaddr;
 
-	if (!is_valid_psw(gpsw))
-		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+	if (!is_valid_psw(gpsw)) {
+		info.code = PGM_SPECIFICATION;
+		info.flags = KVM_S390_PGM_FLAGS_ILC_VALID;
+		return kvm_s390_inject_prog_irq(vcpu, &info);
+	}
 
 	return 0;
 }
 
 static int handle_lpswe(struct kvm_vcpu *vcpu)
 {
+	struct kvm_s390_pgm_info info = {};
 	psw_t new_psw;
 	u64 addr, iaddr;
 	int rc;
@@ -766,8 +771,11 @@ static int handle_lpswe(struct kvm_vcpu *vcpu)
 	vcpu->arch.sie_block->gpsw = new_psw;
 	vcpu->arch.sie_block->gbea = iaddr;
 
-	if (!is_valid_psw(&vcpu->arch.sie_block->gpsw))
-		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+	if (!is_valid_psw(&vcpu->arch.sie_block->gpsw)) {
+		info.code = PGM_SPECIFICATION;
+		info.flags = KVM_S390_PGM_FLAGS_ILC_VALID;
+		return kvm_s390_inject_prog_irq(vcpu, &info);
+	}
 
 	return 0;
 }
Signature · 1 line
2.51.0
maintainer
#4 lore raw

Re: [PATCH 3/3] kvm: s390: Fix lpsw/e spec exception ilc reporting

Quoted 22 lines · Janosch Frank

On early PSW specification exception the ILC has to be 0 according to architecture.

Fixes 48a3e950f4cee ("KVM: s390: Add support for machine checks.")
---
 arch/s390/kvm/priv.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
arch/s390/kvm/priv.c +1 -0
index 56e63679f9d1..9fd7d3f1d1e8 100644
@@ -713,6 +713,7 @@ int is_valid_psw(psw_t *psw)
 int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
 {
 	psw_t *gpsw = &vcpu->arch.sie_block->gpsw;
+	struct kvm_s390_pgm_info info = {};
 	psw32_t new_psw;
 	u64 addr, iaddr;
 	int rc;

arch/s390/kvm/priv.c int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu) · line 746

Quoted 10 lines
arch/s390/kvm/priv.c +5 -2
@@ -738,14 +739,18 @@ int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
 	gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE;
 	vcpu->arch.sie_block->gbea = iaddr;
 
-	if (!is_valid_psw(gpsw))
-		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+	if (!is_valid_psw(gpsw)) {
+		info.code = PGM_SPECIFICATION;
+		info.flags = KVM_S390_PGM_FLAGS_ILC_VALID;
+		return kvm_s390_inject_prog_irq(vcpu, &info);
+	}

Hmm... looking at the architecture: an odd instruction address in the PSW does not result in an early specification exception, but a "normal" specification exception. is_valid_psw() however also checks for an odd instruction address. So I guess this is still not entirely correct.

I'm also wondering if the above implementation is correct if PER is enabled when the specification happens...

Btw.: you may want to have consistent short descriptions for your two patches. That is consistently use upper or lower case for "LPSW/E".

author maintainer
#5 lore raw

Re: [PATCH 3/3] kvm: s390: Fix lpsw/e spec exception ilc reporting

Quoted 39 lines · Heiko Carstens
Quoted 22 lines · Janosch Frank

On early PSW specification exception the ILC has to be 0 according to architecture.

Fixes 48a3e950f4cee ("KVM: s390: Add support for machine checks.")
---
  arch/s390/kvm/priv.c | 16 ++++++++++++----
  1 file changed, 12 insertions(+), 4 deletions(-)
arch/s390/kvm/priv.c +1 -0
index 56e63679f9d1..9fd7d3f1d1e8 100644
@@ -713,6 +713,7 @@ int is_valid_psw(psw_t *psw)
  int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
  {
  	psw_t *gpsw = &vcpu->arch.sie_block->gpsw;
+	struct kvm_s390_pgm_info info = {};
  	psw32_t new_psw;
  	u64 addr, iaddr;
  	int rc;

arch/s390/kvm/priv.c int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu) · line 746

Quoted 10 lines
arch/s390/kvm/priv.c +5 -2
@@ -738,14 +739,18 @@ int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
  	gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE;
  	vcpu->arch.sie_block->gbea = iaddr;
 
-	if (!is_valid_psw(gpsw))
-		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+	if (!is_valid_psw(gpsw)) {
+		info.code = PGM_SPECIFICATION;
+		info.flags = KVM_S390_PGM_FLAGS_ILC_VALID;
+		return kvm_s390_inject_prog_irq(vcpu, &info);
+	}

Hmm... looking at the architecture: an odd instruction address in the PSW does not result in an early specification exception, but a "normal" specification exception. is_valid_psw() however also checks for an odd instruction address. So I guess this is still not entirely correct.

Quoted 2 lines

I'm also wondering if the above implementation is correct if PER is enabled when the specification happens...

Well, we're hopefully slowly getting there one patch at a time.

Quoted 3 lines

Btw.: you may want to have consistent short descriptions for your two patches. That is consistently use upper or lower case for "LPSW/E".

Will fix
I'll also have to rename the bear test to lpsw since we're now testing way more things.