From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: isaku.yamahata@intel.com, xiaoyao.li@intel.com,
binbin.wu@linux.intel.com, seanjc@google.com,
rick.p.edgecombe@intel.com
Subject: [PATCH 5/7] KVM: x86/mmu: Introduce kvm_tdp_map_page() to populate guest memory
Date: Wed, 17 Apr 2024 11:34:48 -0400 [thread overview]
Message-ID: <20240417153450.3608097-6-pbonzini@redhat.com> (raw)
In-Reply-To: <20240417153450.3608097-1-pbonzini@redhat.com>
From: Isaku Yamahata <isaku.yamahata@intel.com>
Introduce a helper function to call the KVM fault handler. It allows a new
ioctl to invoke the KVM fault handler to populate without seeing RET_PF_*
enums or other KVM MMU internal definitions because RET_PF_* are internal
to x86 KVM MMU. The implementation is restricted to two-dimensional paging
for simplicity. The shadow paging uses GVA for faulting instead of L1 GPA.
It makes the API difficult to use.
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Message-ID: <9b866a0ae7147f96571c439e75429a03dcb659b6.1712785629.git.isaku.yamahata@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/mmu.h | 3 +++
arch/x86/kvm/mmu/mmu.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index e8b620a85627..51ff4f67e115 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -183,6 +183,9 @@ static inline void kvm_mmu_refresh_passthrough_bits(struct kvm_vcpu *vcpu,
__kvm_mmu_refresh_passthrough_bits(vcpu, mmu);
}
+int kvm_tdp_map_page(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code,
+ u8 *level);
+
/*
* Check if a given access (described through the I/D, W/R and U/S bits of a
* page fault error code pfec) causes a permission fault with the given PTE
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 7fbcfc97edcc..fb2149d16f8d 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -4646,6 +4646,38 @@ int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
return direct_page_fault(vcpu, fault);
}
+int kvm_tdp_map_page(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code,
+ u8 *level)
+{
+ int r;
+
+ /* Restrict to TDP page fault. */
+ if (vcpu->arch.mmu->page_fault != kvm_tdp_page_fault)
+ return -EOPNOTSUPP;
+
+ r = __kvm_mmu_do_page_fault(vcpu, gpa, error_code, true, NULL, level);
+ if (r < 0)
+ return r;
+
+ switch (r) {
+ case RET_PF_RETRY:
+ return -EAGAIN;
+
+ case RET_PF_FIXED:
+ case RET_PF_SPURIOUS:
+ return 0;
+
+ case RET_PF_EMULATE:
+ return -EINVAL;
+
+ case RET_PF_CONTINUE:
+ case RET_PF_INVALID:
+ default:
+ WARN_ON_ONCE(r);
+ return -EIO;
+ }
+}
+
static void nonpaging_init_context(struct kvm_mmu *context)
{
context->page_fault = nonpaging_page_fault;
--
2.43.0
next prev parent reply other threads:[~2024-04-17 15:34 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-17 15:34 [PATCH v3 0/7] KVM: Guest Memory Pre-Population API Paolo Bonzini
2024-04-17 15:34 ` [PATCH 1/7] KVM: Document KVM_MAP_MEMORY ioctl Paolo Bonzini
2024-04-17 20:28 ` Sean Christopherson
2024-04-17 20:37 ` Paolo Bonzini
2024-04-19 13:57 ` Xu Yilun
2024-04-17 15:34 ` [PATCH 2/7] KVM: Add KVM_MAP_MEMORY vcpu ioctl to pre-populate guest memory Paolo Bonzini
2024-04-17 19:36 ` Isaku Yamahata
2024-04-17 21:07 ` Sean Christopherson
2024-04-17 21:13 ` Paolo Bonzini
2024-04-19 13:59 ` Xu Yilun
2024-04-19 14:08 ` Sean Christopherson
2024-04-19 14:01 ` Xu Yilun
2024-04-17 15:34 ` [PATCH 3/7] KVM: x86/mmu: Extract __kvm_mmu_do_page_fault() Paolo Bonzini
2024-04-17 19:47 ` Isaku Yamahata
2024-04-17 15:34 ` [PATCH 4/7] KVM: x86/mmu: Make __kvm_mmu_do_page_fault() return mapped level Paolo Bonzini
2024-04-17 15:34 ` Paolo Bonzini [this message]
2024-04-17 21:24 ` [PATCH 5/7] KVM: x86/mmu: Introduce kvm_tdp_map_page() to populate guest memory Sean Christopherson
2024-04-17 21:31 ` Paolo Bonzini
2024-04-17 22:26 ` Sean Christopherson
2024-04-17 21:34 ` Sean Christopherson
2024-04-17 21:47 ` Paolo Bonzini
2024-04-17 15:34 ` [PATCH 6/7] KVM: x86: Implement kvm_arch_vcpu_map_memory() Paolo Bonzini
2024-04-17 19:28 ` Isaku Yamahata
2024-04-17 21:37 ` Sean Christopherson
2024-04-17 15:34 ` [PATCH 7/7] KVM: selftests: x86: Add test for KVM_MAP_MEMORY Paolo Bonzini
2024-04-18 0:01 ` [PATCH v3 0/7] KVM: Guest Memory Pre-Population API Edgecombe, Rick P
2024-04-18 0:31 ` Paolo Bonzini
2024-04-18 0:33 ` Edgecombe, Rick P
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=20240417153450.3608097-6-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=binbin.wu@linux.intel.com \
--cc=isaku.yamahata@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rick.p.edgecombe@intel.com \
--cc=seanjc@google.com \
--cc=xiaoyao.li@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;
as well as URLs for NNTP newsgroup(s).