Skip to contentSkip to conversation

KVM: s390: Implement KVM_PRE_FAULT_MEMORY

PATCH Superseded Claudio Imbrenda 2 participants 7 messages May 20

Subsystems (5)
Documentation KVM Kselftest s390 +1 more subsystems

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Claudio Imbrenda

author maintainer
#0 lore raw

cover KVM: s390: Implement KVM_PRE_FAULT_MEMORY

Implement KVM_PRE_FAULT_MEMORY on s390, and update documentation and selftests accordingly.

Faulted-in pages will be marked as accessed, unlike x86, otherwise they will trigger a minor fault when accessed. Avoiding such faults is one of the points of KVM_PRE_FAULT_MEMORY.

CCing x86 people due to changes in the documentation and the selftests

Claudio Imbrenda (4):
KVM: s390: Implement KVM_PRE_FAULT_MEMORY
KVM: s390: Update KVM_PRE_FAULT_MEMORY API documentation
KVM: selftests: Fix pre_fault_memory_test to run on s390
KVM: selftests: Enable pre_fault_memory_test for s390

 Documentation/virt/kvm/api.rst                |  5 ++-
 arch/s390/kvm/Kconfig                         |  1 +
 arch/s390/kvm/kvm-s390.c                      | 41 +++++++++++++++++++
 tools/testing/selftests/kvm/Makefile.kvm      |  1 +
 .../selftests/kvm/pre_fault_memory_test.c     |  7 ++--
 5 files changed, 50 insertions(+), 5 deletions(-)
Signature · 1 line
2.54.0
author maintainer
#1 lore raw

PATCH 1/4 KVM: s390: Implement KVM_PRE_FAULT_MEMORY

Implement and enable the KVM_PRE_FAULT_MEMORY ioctl for s390.

Faulted-in pages will be marked as accessed, unlike x86, otherwise they will trigger a minor fault when accessed. Avoiding such faults is one of the points of KVM_PRE_FAULT_MEMORY.

---
 arch/s390/kvm/Kconfig    |  1 +
 arch/s390/kvm/kvm-s390.c | 41 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
arch/s390/kvm/Kconfig +1 -0
index 5b835bc6a194..8d3ee17a1bcb 100644
@@ -30,6 +30,7 @@ config KVM
 	select KVM_VFIO
 	select VIRT_XFER_TO_GUEST_WORK
 	select KVM_MMU_LOCKLESS_AGING
+	select KVM_GENERIC_PRE_FAULT_MEMORY
 	help
 	  Support hosting paravirtualized guest machines using the SIE
 	  virtualization capability on the mainframe. This should work
arch/s390/kvm/kvm-s390.c +41 -0

53 lines not on this page · raw message

Signature · 1 line
2.54.0
author maintainer
#2 lore raw

PATCH 2/4 KVM: s390: Update KVM_PRE_FAULT_MEMORY API documentation

In reply to Claudio Imbrenda

Update the API documentation for KVM_PRE_FAULT_MEMORY to account for its s390 implementation.

---
 Documentation/virt/kvm/api.rst | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Documentation/virt/kvm/api.rst +3 -2
index 52bbbb553ce1..e7998feaa940 100644
@@ -6471,7 +6471,8 @@ Errors:
 
   ========== ===============================================================
   EINVAL     The specified `gpa` and `size` were invalid (e.g. not
-             page aligned, causes an overflow, or size is zero).
+             page aligned, causes an overflow, or size is zero), or the VM
+             is UCONTROL (s390).
   ENOENT     The specified `gpa` is outside defined memslots.
   EINTR      An unmasked signal is pending and no page was processed.
   EFAULT     The parameter address was invalid.
@@ -6494,7 +6495,7 @@ Errors:
 KVM_PRE_FAULT_MEMORY populates KVM's stage-2 page tables used to map memory
 for the current vCPU state.  KVM maps memory as if the vCPU generated a
 stage-2 read page fault, e.g. faults in memory as needed, but doesn't break
-CoW.  However, KVM does not mark any newly created stage-2 PTE as Accessed.
+CoW.  On x86, KVM does not mark any newly created stage-2 PTE as Accessed.
 
 In the case of confidential VM types where there is an initial set up of
 private guest memory before the guest is 'finalized'/measured, this ioctl
Signature · 1 line
2.54.0
author maintainer
#3 lore raw

PATCH 3/4 KVM: selftests: Fix pre_fault_memory_test to run on s390

In reply to Claudio Imbrenda

Add a missing #include <ucall_common.h> which is needed and otherwise not included on s390.

Fence the assertion vcpu->run->exit_reason == KVM_EXIT_IO so that it is only checked on x86. On s390 the UCALL will return with a different code.

---
 tools/testing/selftests/kvm/pre_fault_memory_test.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/kvm/pre_fault_memory_test.c +4 -3
index fcb57fd034e6..42794892e902 100644
@@ -11,6 +11,7 @@
 #include <kvm_util.h>
 #include <processor.h>
 #include <pthread.h>
+#include <ucall_common.h>
 
 /* Arbitrarily chosen values */
 #define TEST_SIZE		(SZ_2M + PAGE_SIZE)
@@ -167,7 +168,6 @@ static void __test_pre_fault_memory(unsigned long vm_type, bool private)
 		.type = vm_type,
 	};
 	struct kvm_vcpu *vcpu;
-	struct kvm_run *run;
 	struct kvm_vm *vm;
 	struct ucall uc;
 
@@ -193,10 +193,11 @@ static void __test_pre_fault_memory(unsigned long vm_type, bool private)
 	vcpu_args_set(vcpu, 1, gva);
 	vcpu_run(vcpu);
 
-	run = vcpu->run;
-	TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
+#ifdef __x86_64__
+	TEST_ASSERT(vcpu->run->exit_reason == KVM_EXIT_IO,
 		    "Wanted KVM_EXIT_IO, got exit reason: %u (%s)",
 		    run->exit_reason, exit_reason_str(run->exit_reason));
+#endif
 
 	switch (get_ucall(vcpu, &uc)) {
 	case UCALL_ABORT:
Signature · 1 line
2.54.0
#4 lore raw

Re: [PATCH v1 3/4] KVM: selftests: Fix pre_fault_memory_test to run on s390

Quoted 33 lines · Claudio Imbrenda

Add a missing #include <ucall_common.h> which is needed and otherwise not included on s390.

Fence the assertion vcpu->run->exit_reason == KVM_EXIT_IO so that it is only checked on x86. On s390 the UCALL will return with a different code.

---
 tools/testing/selftests/kvm/pre_fault_memory_test.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/kvm/pre_fault_memory_test.c +1 -1
index fcb57fd034e6..42794892e902 100644
@@ -11,6 +11,7 @@
 #include <kvm_util.h>
 #include <processor.h>
 #include <pthread.h>
+#include <ucall_common.h>
 
 /* Arbitrarily chosen values */
 #define TEST_SIZE		(SZ_2M + PAGE_SIZE)
@@ -167,7 +168,6 @@ static void __test_pre_fault_memory(unsigned long vm_type, bool private)
 		.type = vm_type,
 	};
 	struct kvm_vcpu *vcpu;
-	struct kvm_run *run;
 	struct kvm_vm *vm;
 	struct ucall uc;
 

tools/testing/selftests/kvm/pre_fault_memory_test.c static void __test_pre_fault_memory(unsigned long vm_type, bool private) · line 196

Quoted 6 lines
tools/testing/selftests/kvm/pre_fault_memory_test.c +1 -2
@@ -193,10 +193,11 @@ static void __test_pre_fault_memory(unsigned long vm_type, bool private)
 	vcpu_args_set(vcpu, 1, gva);
 	vcpu_run(vcpu);
 
-	run = vcpu->run;
-	TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
+#ifdef __x86_64__

I'd say just delete this assertion entirely. It's an extra layer of paranoia to guard against stale ucall data, but x86's ucall_arch_get_ucall() already has sufficient guards.

Quoted 10 lines
tools/testing/selftests/kvm/pre_fault_memory_test.c +2 -0
+	TEST_ASSERT(vcpu->run->exit_reason == KVM_EXIT_IO,
 		    "Wanted KVM_EXIT_IO, got exit reason: %u (%s)",
 		    run->exit_reason, exit_reason_str(run->exit_reason));
+#endif
 
 	switch (get_ucall(vcpu, &uc)) {
 	case UCALL_ABORT:
Signature · 1 line
2.54.0
author maintainer
#5 lore raw

Re: [PATCH v1 3/4] KVM: selftests: Fix pre_fault_memory_test to run on s390

Quoted 37 lines · On Wed, 20 May 2026 08:27:24 -0700 Sean Christopherson <[email protected]>…
Quoted 36 lines · Claudio Imbrenda

Add a missing #include <ucall_common.h> which is needed and otherwise not included on s390.

Fence the assertion vcpu->run->exit_reason == KVM_EXIT_IO so that it is only checked on x86. On s390 the UCALL will return with a different code.

---
 tools/testing/selftests/kvm/pre_fault_memory_test.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/kvm/pre_fault_memory_test.c +1 -1
index fcb57fd034e6..42794892e902 100644
@@ -11,6 +11,7 @@
 #include <kvm_util.h>
 #include <processor.h>
 #include <pthread.h>
+#include <ucall_common.h>
 
 /* Arbitrarily chosen values */
 #define TEST_SIZE		(SZ_2M + PAGE_SIZE)
@@ -167,7 +168,6 @@ static void __test_pre_fault_memory(unsigned long vm_type, bool private)
 		.type = vm_type,
 	};
 	struct kvm_vcpu *vcpu;
-	struct kvm_run *run;
 	struct kvm_vm *vm;
 	struct ucall uc;
 
@@ -193,10 +193,11 @@ static void __test_pre_fault_memory(unsigned long vm_type, bool private)
 	vcpu_args_set(vcpu, 1, gva);
 	vcpu_run(vcpu);
 
Quoted 7 lines

tools/testing/selftests/kvm/pre_fault_memory_test.c static void __test_pre_fault_memory(unsigned long vm_type, bool private) · line 196

Quoted 3 lines
tools/testing/selftests/kvm/pre_fault_memory_test.c +1 -2
-	run = vcpu->run;
-	TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
+#ifdef __x86_64__  

I'd say just delete this assertion entirely. It's an extra layer of paranoia to guard against stale ucall data, but x86's ucall_arch_get_ucall() already has sufficient guards.

will do, thanks!

Quoted 11 lines
Quoted 11 lines
tools/testing/selftests/kvm/pre_fault_memory_test.c +2 -0
+	TEST_ASSERT(vcpu->run->exit_reason == KVM_EXIT_IO,
 		    "Wanted KVM_EXIT_IO, got exit reason: %u (%s)",
 		    run->exit_reason, exit_reason_str(run->exit_reason));
+#endif
 
 	switch (get_ucall(vcpu, &uc)) {
 	case UCALL_ABORT:
Signature · 1 line
2.54.0
author maintainer
#6 lore raw

PATCH 4/4 KVM: selftests: Enable pre_fault_memory_test for s390

In reply to Claudio Imbrenda

Enable the pre_fault_memory_test to run on s390.

---
 tools/testing/selftests/kvm/Makefile.kvm | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/kvm/Makefile.kvm +1 -0
index 9118a5a51b89..fff939db89cd 100644
@@ -210,6 +210,7 @@ TEST_GEN_PROGS_s390 += s390/keyop
 TEST_GEN_PROGS_s390 += rseq_test
 TEST_GEN_PROGS_s390 += s390/irq_routing
 TEST_GEN_PROGS_s390 += mmu_stress_test
+TEST_GEN_PROGS_s390 += pre_fault_memory_test
 
 TEST_GEN_PROGS_riscv = $(TEST_GEN_PROGS_COMMON)
 TEST_GEN_PROGS_riscv += riscv/sbi_pmu_test
Signature · 1 line
2.54.0