From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: pbonzini@redhat.com
Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org,
frankja@linux.ibm.com, borntraeger@de.ibm.com
Subject: [GIT PULL v1 02/17] KVM: s390: Implement KVM_PRE_FAULT_MEMORY
Date: Mon, 15 Jun 2026 14:42:28 +0200 [thread overview]
Message-ID: <20260615124243.187614-3-imbrenda@linux.ibm.com> (raw)
In-Reply-To: <20260615124243.187614-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.
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Message-ID: <20260527144358.186359-3-imbrenda@linux.ibm.com>
---
arch/s390/kvm/Kconfig | 1 +
arch/s390/kvm/kvm-s390.c | 45 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 46 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..f6521f16532a 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,50 @@ 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 first page of 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 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 errors happen while faulting-in the page (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)
+{
+ struct guest_fault f = { .gfn = gpa_to_gfn(range->gpa), };
+ gpa_t end;
+ int rc;
+
+ if (kvm_is_ucontrol(vcpu->kvm))
+ return -EINVAL;
+
+ rc = kvm_s390_faultin_gfn(vcpu, NULL, &f);
+ if (rc == PGM_ADDRESSING)
+ return -ENOENT;
+ if (rc > 0)
+ return -EIO;
+ if (rc < 0)
+ return rc;
+
+ if (f.ptep)
+ return PAGE_SIZE;
+
+ end = ALIGN(range->gpa + PAGE_SIZE, f.crste_region3 ? _REGION3_SIZE : HPAGE_SIZE);
+ return min(range->size, end - range->gpa);
+}
+
/**
* kvm_test_age_gfn() - test young
* @kvm: the kvm instance
--
2.54.0
next prev parent reply other threads:[~2026-06-15 12:42 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 12:42 [GIT PULL v1 00/17] KVM: s390: New features for 7.2 Claudio Imbrenda
2026-06-15 12:42 ` [GIT PULL v1 01/17] KVM: s390: Track page size in struct guest_fault Claudio Imbrenda
2026-06-15 12:42 ` Claudio Imbrenda [this message]
2026-06-15 12:42 ` [GIT PULL v1 03/17] KVM: s390: Update KVM_PRE_FAULT_MEMORY API documentation Claudio Imbrenda
2026-06-15 12:42 ` [GIT PULL v1 04/17] KVM: selftests: Fix pre_fault_memory_test to run on s390 Claudio Imbrenda
2026-06-15 12:42 ` [GIT PULL v1 05/17] KVM: selftests: Enable pre_fault_memory_test for s390 Claudio Imbrenda
2026-06-15 12:42 ` [GIT PULL v1 06/17] KVM: s390: Add module parameter to fence 2G hugepages Claudio Imbrenda
2026-06-15 12:42 ` [GIT PULL v1 07/17] KVM: s390: Add capability to support " Claudio Imbrenda
2026-06-15 13:05 ` sashiko-bot
2026-06-15 12:42 ` [GIT PULL v1 08/17] KVM: s390: Allow for " Claudio Imbrenda
2026-06-15 12:42 ` [GIT PULL v1 09/17] KVM: s390: Document the KVM_CAP_S390_HPAGE_2G capability Claudio Imbrenda
2026-06-15 13:03 ` sashiko-bot
2026-06-15 12:42 ` [GIT PULL v1 10/17] KVM: s390: Initialize KVM_S390_GET_CMMA_BITS memory Claudio Imbrenda
2026-06-15 13:07 ` sashiko-bot
2026-06-15 12:42 ` [GIT PULL v1 11/17] KVM: s390: Minor refactor of base/ext facility lists Claudio Imbrenda
2026-06-15 12:42 ` [GIT PULL v1 12/17] s390/sclp: Detect ASTFLEIE 2 facility Claudio Imbrenda
2026-06-15 12:42 ` [GIT PULL v1 13/17] KVM: s390: vsie: Refactor handle_stfle Claudio Imbrenda
2026-06-15 12:42 ` [GIT PULL v1 14/17] KVM: s390: vsie: Implement ASTFLEIE facility 2 Claudio Imbrenda
2026-06-15 12:42 ` [GIT PULL v1 15/17] KVM: s390: Add map/unmap ioctl and clean mappings post-guest Claudio Imbrenda
2026-06-15 13:21 ` sashiko-bot
2026-06-15 12:42 ` [GIT PULL v1 16/17] KVM: s390: Enable adapter_indicators_set to use mapped pages Claudio Imbrenda
2026-06-15 13:21 ` sashiko-bot
2026-06-15 12:42 ` [GIT PULL v1 17/17] KVM: s390: Introducing kvm_arch_set_irq_inatomic fast inject Claudio Imbrenda
2026-06-15 13:23 ` sashiko-bot
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=20260615124243.187614-3-imbrenda@linux.ibm.com \
--to=imbrenda@linux.ibm.com \
--cc=borntraeger@de.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=pbonzini@redhat.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