From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org,
borntraeger@de.ibm.com, frankja@linux.ibm.com, david@kernel.org,
seiden@linux.ibm.com, nrb@linux.ibm.com,
schlameuss@linux.ibm.com, gra@linux.ibm.com, pbonzini@redhat.com,
seanjc@google.com, yan.y.zhao@intel.com,
isaku.yamahata@intel.com
Subject: [PATCH v1 1/4] KVM: s390: Implement KVM_PRE_FAULT_MEMORY
Date: Wed, 20 May 2026 17:17:07 +0200 [thread overview]
Message-ID: <20260520151710.231788-2-imbrenda@linux.ibm.com> (raw)
In-Reply-To: <20260520151710.231788-1-imbrenda@linux.ibm.com>
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.
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
arch/s390/kvm/Kconfig | 1 +
arch/s390/kvm/kvm-s390.c | 41 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig
index 5b835bc6a194..8d3ee17a1bcb 100644
--- a/arch/s390/kvm/Kconfig
+++ b/arch/s390/kvm/Kconfig
@@ -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
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index e09960c2e6ed..dd220f3d6e94 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -630,6 +630,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
case KVM_CAP_S390_USER_OPEREXEC:
case KVM_CAP_S390_KEYOP:
case KVM_CAP_S390_VSIE_ESAMODE:
+ case KVM_CAP_PRE_FAULT_MEMORY:
r = 1;
break;
case KVM_CAP_SET_GUEST_DEBUG2:
@@ -5736,6 +5737,46 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
return;
}
+/**
+ * kvm_arch_vcpu_pre_fault_memory() -- pre-fault and link gmap dat tables
+ * @vcpu: the vcpu that shall appear to have generated the fault-in.
+ * @range: the range that needs to be faulted in.
+ *
+ * The given range is faulted in and the corresponding gmap page tables are
+ * created, as if the given vCPU had performed a read operation. If the range
+ * ends outside of a memslot, only the part inside the memslot is faulted in.
+ * If the range starts outside any memslots, an error is returned. An error is
+ * also returned for UCONTROL VMs, which should instead use the
+ * KVM_S390_VCPU_FAULT ioctl.
+ *
+ * Return:
+ * * %-ENOENT if the range lies outside of a memslot.
+ * * %-EINVAL in case of invalid state (for example if the VM is UCONTROL)
+ * * %-EIO if other errors happen while faulting-in the page (considered a
+ * bug, will trigger a warning in the caller).
+ * * other error codes < 0 in case of other errors.
+ * * otherwise a number > 0 of bytes that have been faulted in successfully.
+ */
+long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu, struct kvm_pre_fault_memory *range)
+{
+ unsigned long i;
+ int rc;
+
+ if (kvm_is_ucontrol(vcpu->kvm))
+ return -EINVAL;
+
+ for (i = 0; i < range->size; i += PAGE_SIZE) {
+ rc = kvm_s390_faultin_gfn_simple(vcpu, NULL, gpa_to_gfn(range->gpa + i), false);
+ if (rc == PGM_ADDRESSING)
+ return i ? i : -ENOENT;
+ if (rc == -EINTR)
+ return i ? i : -EINTR;
+ if (rc)
+ return -EIO;
+ }
+ return i;
+}
+
/**
* kvm_test_age_gfn() - test young
* @kvm: the kvm instance
--
2.54.0
next prev parent reply other threads:[~2026-05-20 15:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 15:17 [PATCH v1 0/4] " Claudio Imbrenda
2026-05-20 15:17 ` Claudio Imbrenda [this message]
2026-05-20 15:17 ` [PATCH v1 2/4] KVM: s390: Update KVM_PRE_FAULT_MEMORY API documentation Claudio Imbrenda
2026-05-20 15:17 ` [PATCH v1 3/4] KVM: selftests: Fix pre_fault_memory_test to run on s390 Claudio Imbrenda
2026-05-20 15:27 ` Sean Christopherson
2026-05-20 16:20 ` Claudio Imbrenda
2026-05-20 15:17 ` [PATCH v1 4/4] KVM: selftests: Enable pre_fault_memory_test for s390 Claudio Imbrenda
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=20260520151710.231788-2-imbrenda@linux.ibm.com \
--to=imbrenda@linux.ibm.com \
--cc=borntraeger@de.ibm.com \
--cc=david@kernel.org \
--cc=frankja@linux.ibm.com \
--cc=gra@linux.ibm.com \
--cc=isaku.yamahata@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=nrb@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=schlameuss@linux.ibm.com \
--cc=seanjc@google.com \
--cc=seiden@linux.ibm.com \
--cc=yan.y.zhao@intel.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®