Skip to contentSkip to conversation

KVM: s390: fix ESSA addressing exception injection in migration mode

PATCH Applied Gautam Gala 4 participants 7 messages Oct 15 – Oct 19

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

v2 cover KVM: s390: fix ESSA addressing exception injection in migration mode

ESSA emulation in migration mode silently dropped addressing exceptions when the guest page-table walk failed, so the guest never received the expected PGM_ADDRESSING interrupt during live migration.

Patch 1 fixes dat_perform_essa() to return PGM_ADDRESSING on a walk failure, and __do_essa() to inject the program interrupt when it sees that return value.

Patch 2 adds a regression test integrated into the existing cmma_test selftest.

Changes since v1:
- dat_perform_essa() now returns +PGM_ADDRESSING instead of -PGM_ADDRESSING; kvm_s390_inject_program_int() takes an unsigned u16 so passing -5 would have wrapped to 0xFFFB and injected a bogus PIC. __do_essa() comparison and inject call updated accordingly. The kernel-doc return-value entry is corrected to %PGM_ADDRESSING.
- Selftest: pgm_handler_c() now reads the actual PIC from lowcore (__LC_PGM_INT_CODE) instead of hard-coding PGM_ADDRESSING, so the test would have caught the sign error above had it been in v1.
- Selftest: virt_map(vm, 0, 0, 1) added so the DAT-on guest can access the lowcore to read the PIC.
- Selftest: PGM_ADDRESSING, __LC_PGM_INT_CODE and __LC_PGM_NEW_PSW constants moved to the shared s390/processor.h header.
- Selftest: SIGALRM/alarm() timeout wrapper removed.

Gautam Gala (2):
KVM: s390: fix ESSA addressing exception injection in migration mode
KVM: s390: selftests: add ESSA migration mode PGM_ADDRESSING
regression test

 arch/s390/kvm/gmap/dat.c                      |  5 +-
 arch/s390/kvm/s390/priv.c                     |  2 +
 .../selftests/kvm/include/s390/processor.h    |  7 ++
 tools/testing/selftests/kvm/s390/cmma_test.c  | 69 +++++++++++++++++++
 4 files changed, 82 insertions(+), 1 deletion(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH v2 1/2 KVM: s390: fix ESSA addressing exception injection in migration mode

__do_essa() treated any negative return from dat_perform_essa() as the normal "no CBRL entry appended" case and returned 0, so a page-table walk failure silently dropped the addressing exception.

Return -PGM_ADDRESSING on a walk failure and inject the program interrupt in __do_essa() for the -PGM_ADDRESSING return value.

DAT_WALK_ANY is required in the dat_entry_walk() call so that a GFN backed by a large page (segment or region entry) does not return an
error: the walk stops early but succeeds, leaving ptep as NULL, which is already handled by the existing "set exception state, return -1" path. Without DAT_WALK_ANY such addresses would fall through to the new error path and incorrectly inject PGM_ADDRESSING.

---
 arch/s390/kvm/gmap/dat.c  | 5 ++++-
 arch/s390/kvm/s390/priv.c | 2 ++
 2 files changed, 6 insertions(+), 1 deletion(-)
arch/s390/kvm/gmap/dat.c +4 -1
index ff80d02c9f56..a2031aece4ed 100644
@@ -1084,6 +1084,7 @@ int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn)
  * * %1 if the page state has been altered and the page is to be added to the CBRL
  * * %0 if the page state has been altered, but the page is not to be added to the CBRL
  * * %-1 if the page state has not been altered and the page is not to be added to the CBRL
+ * * %PGM_ADDRESSING if the guest page-table walk failed
  */
 int dat_perform_essa(union asce asce, gfn_t gfn, int orc, union essa_state *state, bool *dirty)
 {
@@ -1092,7 +1093,9 @@ int dat_perform_essa(union asce asce, gfn_t gfn, int orc, union essa_state *stat
 	union pte *ptep;
 	int res = 0;
 
-	if (dat_entry_walk(NULL, gfn, asce, 0, TABLE_TYPE_PAGE_TABLE, &crstep, &ptep)) {
+	if (dat_entry_walk(NULL, gfn, asce, DAT_WALK_ANY, TABLE_TYPE_PAGE_TABLE, &crstep, &ptep))
+		return PGM_ADDRESSING;
+	if (!ptep) {
 		*state = (union essa_state) { .exception = 1 };
 		return -1;
 	}
arch/s390/kvm/s390/priv.c +2 -0
index b3cb2c2c3aa7..9089b8f5d550 100644
@@ -1168,6 +1168,8 @@ static inline int __do_essa(struct kvm_vcpu *vcpu, const int orc)
 	entries = (vcpu->arch.sie_block->cbrlo & ~PAGE_MASK) >> 3;
 
 	nappended = dat_perform_essa(vcpu->arch.gmap->asce, gfn, orc, &state, &dirtied);
+	if (nappended == PGM_ADDRESSING)
+		return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
 	vcpu->run->s.regs.gprs[r1] = state.val;
 	if (nappended < 0)
 		return 0;
Signature · 1 line
2.55.0
#2 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines

__do_essa() treated any negative return from dat_perform_essa() as the normal "no CBRL entry appended" case and returned 0, so a page-table walk failure silently dropped the addressing exception.

Return -PGM_ADDRESSING on a walk failure and inject the program interrupt in __do_essa() for the -PGM_ADDRESSING return value.

DAT_WALK_ANY is required in the dat_entry_walk() call so that a GFN backed by a large page (segment or region entry) does not return an
error: the walk stops early but succeeds, leaving ptep as NULL, which is already handled by the existing "set exception state, return -1" path. Without DAT_WALK_ANY such addresses would fall through to the new error path and incorrectly inject PGM_ADDRESSING.

Quoted 5 lines

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH v2 2/2 KVM: s390: selftests: add ESSA migration mode PGM_ADDRESSING regression test

In reply to Gautam Gala

Regression test for the bug where ESSA emulation in migration mode silently dropped addressing exceptions instead of injecting PGM_ADDRESSING into the guest.

The test is integrated into cmma_test alongside the existing CMMA migration tests.

---
 .../selftests/kvm/include/s390/processor.h    |  7 ++
 tools/testing/selftests/kvm/s390/cmma_test.c  | 69 +++++++++++++++++++
 2 files changed, 76 insertions(+)
tools/testing/selftests/kvm/include/s390/processor.h +7 -0
index 33fef6fd9617..d71df6784dad 100644
@@ -26,6 +26,13 @@
 #define PAGE_SIZE BIT_ULL(PAGE_SHIFT)
 #define PAGE_MASK (~(PAGE_SIZE - 1))
 
+/* Program interruption codes */
+#define PGM_ADDRESSING		0x05
+
+/* Lowcore offsets */
+#define __LC_PGM_INT_CODE	0x8e
+#define __LC_PGM_NEW_PSW	0x1d0
+
 /* Is there a portable way to do this? */
 static inline void cpu_relax(void)
 {
tools/testing/selftests/kvm/s390/cmma_test.c +69 -0

87 lines not on this page · raw message

Signature · 1 line
2.55.0
#4 lore raw

Re: [PATCH v2 2/2] KVM: s390: selftests: add ESSA migration mode PGM_ADDRESSING regression test

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

Regression test for the bug where ESSA emulation in migration mode silently dropped addressing exceptions instead of injecting PGM_ADDRESSING into the guest.

The test is integrated into cmma_test alongside the existing CMMA migration tests.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
maintainer Reviewed-by on the v2 series
#5 lore raw
In reply to Gautam Gala
Quoted 10 lines · On Thu, 15 Oct 2026 12:48:20 +0200 Gautam Gala <[email protected]> wrote:

ESSA emulation in migration mode silently dropped addressing exceptions when the guest page-table walk failed, so the guest never received the expected PGM_ADDRESSING interrupt during live migration.

Patch 1 fixes dat_perform_essa() to return PGM_ADDRESSING on a walk failure, and __do_essa() to inject the program interrupt when it sees that return value.

Patch 2 adds a regression test integrated into the existing cmma_test selftest.

Whole series:

Quoted 27 lines

Changes since v1:
- dat_perform_essa() now returns +PGM_ADDRESSING instead of -PGM_ADDRESSING; kvm_s390_inject_program_int() takes an unsigned u16 so passing -5 would have wrapped to 0xFFFB and injected a bogus PIC. __do_essa() comparison and inject call updated accordingly. The kernel-doc return-value entry is corrected to %PGM_ADDRESSING.
- Selftest: pgm_handler_c() now reads the actual PIC from lowcore (__LC_PGM_INT_CODE) instead of hard-coding PGM_ADDRESSING, so the test would have caught the sign error above had it been in v1.
- Selftest: virt_map(vm, 0, 0, 1) added so the DAT-on guest can access the lowcore to read the PIC.
- Selftest: PGM_ADDRESSING, __LC_PGM_INT_CODE and __LC_PGM_NEW_PSW constants moved to the shared s390/processor.h header.
- Selftest: SIGALRM/alarm() timeout wrapper removed.

Gautam Gala (2):
KVM: s390: fix ESSA addressing exception injection in migration mode
KVM: s390: selftests: add ESSA migration mode PGM_ADDRESSING
regression test

 arch/s390/kvm/gmap/dat.c                      |  5 +-
 arch/s390/kvm/s390/priv.c                     |  2 +
 .../selftests/kvm/include/s390/processor.h    |  7 ++
 tools/testing/selftests/kvm/s390/cmma_test.c  | 69 +++++++++++++++++++
 4 files changed, 82 insertions(+), 1 deletion(-)
maintainer Applied
#6 lore raw
In reply to Gautam Gala

Am 15.10.26 um 12:48 schrieb Gautam Gala:

Quoted 31 lines

ESSA emulation in migration mode silently dropped addressing exceptions when the guest page-table walk failed, so the guest never received the expected PGM_ADDRESSING interrupt during live migration.

Patch 1 fixes dat_perform_essa() to return PGM_ADDRESSING on a walk failure, and __do_essa() to inject the program interrupt when it sees that return value.

Patch 2 adds a regression test integrated into the existing cmma_test selftest.

Changes since v1:
- dat_perform_essa() now returns +PGM_ADDRESSING instead of -PGM_ADDRESSING; kvm_s390_inject_program_int() takes an unsigned u16 so passing -5 would have wrapped to 0xFFFB and injected a bogus PIC. __do_essa() comparison and inject call updated accordingly. The kernel-doc return-value entry is corrected to %PGM_ADDRESSING.
- Selftest: pgm_handler_c() now reads the actual PIC from lowcore (__LC_PGM_INT_CODE) instead of hard-coding PGM_ADDRESSING, so the test would have caught the sign error above had it been in v1.
- Selftest: virt_map(vm, 0, 0, 1) added so the DAT-on guest can access the lowcore to read the PIC.
- Selftest: PGM_ADDRESSING, __LC_PGM_INT_CODE and __LC_PGM_NEW_PSW constants moved to the shared s390/processor.h header.
- Selftest: SIGALRM/alarm() timeout wrapper removed.

Gautam Gala (2):
KVM: s390: fix ESSA addressing exception injection in migration mode
KVM: s390: selftests: add ESSA migration mode PGM_ADDRESSING
regression test

Quoted 6 lines
  arch/s390/kvm/gmap/dat.c                      |  5 +-
  arch/s390/kvm/s390/priv.c                     |  2 +
  .../selftests/kvm/include/s390/processor.h    |  7 ++
  tools/testing/selftests/kvm/s390/cmma_test.c  | 69 +++++++++++++++++++
  4 files changed, 82 insertions(+), 1 deletion(-)

Thanks, applied.