All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Fang <peter.fang@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	"Nicholas Piggin" <npiggin@gmail.com>
Cc: Yosry Ahmed <yosry@kernel.org>,
	Ritesh Harjani <ritesh.list@gmail.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>, <x86@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>, <kvm@vger.kernel.org>,
	<linuxppc-dev@lists.ozlabs.org>, <linux-kernel@vger.kernel.org>,
	Peter Fang <peter.fang@intel.com>
Subject: [PATCH v2 3/3] KVM: Take gpa_t in kvm_vcpu_map[_readonly]()
Date: Tue, 7 Apr 2026 17:11:30 -0700	[thread overview]
Message-ID: <20260408001137.3290444-4-peter.fang@intel.com> (raw)
In-Reply-To: <20260408001137.3290444-1-peter.fang@intel.com>

Move the conversion from a gpa_t to a gfn_t into kvm_vcpu_map() and
kvm_vcpu_map_readonly() so that they take a gpa_t directly, reducing
boilerplate at call sites.

__kvm_vcpu_map() still takes a gfn_t because guest page mapping is
fundamentally GFN-based.

No functional change intended.

Compile-tested on x86 and ppc, which are the current users of these
interfaces.

Suggested-by: Yosry Ahmed <yosry@kernel.org>
Signed-off-by: Peter Fang <peter.fang@intel.com>
---
 arch/powerpc/kvm/book3s_pr.c |  2 +-
 arch/x86/kvm/svm/nested.c    |  4 ++--
 arch/x86/kvm/svm/sev.c       |  2 +-
 arch/x86/kvm/svm/svm.c       |  8 ++++----
 arch/x86/kvm/vmx/nested.c    | 11 +++++------
 include/linux/kvm_host.h     |  8 ++++----
 6 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 2ba2dd26a7ea..45dea4064618 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -644,7 +644,7 @@ static void kvmppc_patch_dcbz(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte)
 	u32 *page;
 	int i, r;
 
-	r = kvm_vcpu_map(vcpu, pte->raddr >> PAGE_SHIFT, &map);
+	r = kvm_vcpu_map(vcpu, pte->raddr, &map);
 	if (r)
 		return;
 
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index b36c33255bed..f168b54828bb 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -1019,7 +1019,7 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)
 	}
 
 	vmcb12_gpa = svm->vmcb->save.rax;
-	ret = kvm_vcpu_map(vcpu, gpa_to_gfn(vmcb12_gpa), &map);
+	ret = kvm_vcpu_map(vcpu, vmcb12_gpa, &map);
 	if (ret == -EINVAL) {
 		kvm_inject_gp(vcpu, 0);
 		return 1;
@@ -1134,7 +1134,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
 	struct kvm_host_map map;
 	int rc;
 
-	rc = kvm_vcpu_map(vcpu, gpa_to_gfn(svm->nested.vmcb12_gpa), &map);
+	rc = kvm_vcpu_map(vcpu, svm->nested.vmcb12_gpa, &map);
 	if (rc) {
 		if (rc == -EINVAL)
 			kvm_inject_gp(vcpu, 0);
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 3f9c1aa39a0a..524607bb8cc2 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -4405,7 +4405,7 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
 		return 1;
 	}
 
-	if (kvm_vcpu_map(vcpu, ghcb_gpa >> PAGE_SHIFT, &svm->sev_es.ghcb_map)) {
+	if (kvm_vcpu_map(vcpu, ghcb_gpa, &svm->sev_es.ghcb_map)) {
 		/* Unable to map GHCB from guest */
 		vcpu_unimpl(vcpu, "vmgexit: error mapping GHCB [%#llx] from guest\n",
 			    ghcb_gpa);
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index e6477affac9a..823c6a6f3594 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -2159,7 +2159,7 @@ static int vmload_vmsave_interception(struct kvm_vcpu *vcpu, bool vmload)
 	if (nested_svm_check_permissions(vcpu))
 		return 1;
 
-	ret = kvm_vcpu_map(vcpu, gpa_to_gfn(svm->vmcb->save.rax), &map);
+	ret = kvm_vcpu_map(vcpu, svm->vmcb->save.rax, &map);
 	if (ret) {
 		if (ret == -EINVAL)
 			kvm_inject_gp(vcpu, 0);
@@ -4820,7 +4820,7 @@ static int svm_enter_smm(struct kvm_vcpu *vcpu, union kvm_smram *smram)
 	 * that, see svm_prepare_switch_to_guest()) which must be
 	 * preserved.
 	 */
-	if (kvm_vcpu_map(vcpu, gpa_to_gfn(svm->nested.hsave_msr), &map_save))
+	if (kvm_vcpu_map(vcpu, svm->nested.hsave_msr, &map_save))
 		return 1;
 
 	BUILD_BUG_ON(offsetof(struct vmcb, save) != 0x400);
@@ -4854,11 +4854,11 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)
 	if (!(smram64->efer & EFER_SVME))
 		return 1;
 
-	if (kvm_vcpu_map(vcpu, gpa_to_gfn(smram64->svm_guest_vmcb_gpa), &map))
+	if (kvm_vcpu_map(vcpu, smram64->svm_guest_vmcb_gpa, &map))
 		return 1;
 
 	ret = 1;
-	if (kvm_vcpu_map(vcpu, gpa_to_gfn(svm->nested.hsave_msr), &map_save))
+	if (kvm_vcpu_map(vcpu, svm->nested.hsave_msr, &map_save))
 		goto unmap_map;
 
 	if (svm_allocate_nested(svm))
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 937aeb474af7..ee3ff76a8678 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -696,7 +696,7 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,
 			return true;
 	}
 
-	if (kvm_vcpu_map_readonly(vcpu, gpa_to_gfn(vmcs12->msr_bitmap), &map))
+	if (kvm_vcpu_map_readonly(vcpu, vmcs12->msr_bitmap, &map))
 		return false;
 
 	msr_bitmap_l1 = (unsigned long *)map.hva;
@@ -2138,8 +2138,7 @@ static enum nested_evmptrld_status nested_vmx_handle_enlightened_vmptrld(
 
 		nested_release_evmcs(vcpu);
 
-		if (kvm_vcpu_map(vcpu, gpa_to_gfn(evmcs_gpa),
-				 &vmx->nested.hv_evmcs_map))
+		if (kvm_vcpu_map(vcpu, evmcs_gpa, &vmx->nested.hv_evmcs_map))
 			return EVMPTRLD_ERROR;
 
 		vmx->nested.hv_evmcs = vmx->nested.hv_evmcs_map.hva;
@@ -3437,7 +3436,7 @@ static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
 	if (nested_cpu_has2(vmcs12, SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES)) {
 		map = &vmx->nested.apic_access_page_map;
 
-		if (!kvm_vcpu_map(vcpu, gpa_to_gfn(vmcs12->apic_access_addr), map)) {
+		if (!kvm_vcpu_map(vcpu, vmcs12->apic_access_addr, map)) {
 			vmcs_write64(APIC_ACCESS_ADDR, pfn_to_hpa(map->pfn));
 		} else {
 			pr_debug_ratelimited("%s: no backing for APIC-access address in vmcs12\n",
@@ -3453,7 +3452,7 @@ static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
 	if (nested_cpu_has(vmcs12, CPU_BASED_TPR_SHADOW)) {
 		map = &vmx->nested.virtual_apic_map;
 
-		if (!kvm_vcpu_map(vcpu, gpa_to_gfn(vmcs12->virtual_apic_page_addr), map)) {
+		if (!kvm_vcpu_map(vcpu, vmcs12->virtual_apic_page_addr, map)) {
 			vmcs_write64(VIRTUAL_APIC_PAGE_ADDR, pfn_to_hpa(map->pfn));
 		} else if (nested_cpu_has(vmcs12, CPU_BASED_CR8_LOAD_EXITING) &&
 		           nested_cpu_has(vmcs12, CPU_BASED_CR8_STORE_EXITING) &&
@@ -3479,7 +3478,7 @@ static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
 	if (nested_cpu_has_posted_intr(vmcs12)) {
 		map = &vmx->nested.pi_desc_map;
 
-		if (!kvm_vcpu_map(vcpu, gpa_to_gfn(vmcs12->posted_intr_desc_addr), map)) {
+		if (!kvm_vcpu_map(vcpu, vmcs12->posted_intr_desc_addr, map)) {
 			vmx->nested.pi_desc =
 				(struct pi_desc *)(((void *)map->hva) +
 				offset_in_page(vmcs12->posted_intr_desc_addr));
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 484378cfdcc0..893a8c76a665 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1897,16 +1897,16 @@ int __kvm_vcpu_map(struct kvm_vcpu *vcpu, gfn_t gfn, struct kvm_host_map *map,
 		   bool writable);
 void kvm_vcpu_unmap(struct kvm_vcpu *vcpu, struct kvm_host_map *map);
 
-static inline int kvm_vcpu_map(struct kvm_vcpu *vcpu, gfn_t gfn,
+static inline int kvm_vcpu_map(struct kvm_vcpu *vcpu, gpa_t gpa,
 			       struct kvm_host_map *map)
 {
-	return __kvm_vcpu_map(vcpu, gfn, map, true);
+	return __kvm_vcpu_map(vcpu, gpa_to_gfn(gpa), map, true);
 }
 
-static inline int kvm_vcpu_map_readonly(struct kvm_vcpu *vcpu, gfn_t gfn,
+static inline int kvm_vcpu_map_readonly(struct kvm_vcpu *vcpu, gpa_t gpa,
 					struct kvm_host_map *map)
 {
-	return __kvm_vcpu_map(vcpu, gfn, map, false);
+	return __kvm_vcpu_map(vcpu, gpa_to_gfn(gpa), map, false);
 }
 
 static inline void kvm_vcpu_map_mark_dirty(struct kvm_vcpu *vcpu,
-- 
2.53.0


  parent reply	other threads:[~2026-04-08  0:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08  0:11 [PATCH v2 0/3] KVM: Fix and clean up kvm_vcpu_map[_readonly]() usages Peter Fang
2026-04-08  0:11 ` [PATCH v2 1/3] KVM: Fix kvm_vcpu_map[_readonly]() function prototypes Peter Fang
2026-04-21 23:05   ` Yosry Ahmed
2026-04-08  0:11 ` [PATCH v2 2/3] KVM: Move page mapping/unmapping APIs in kvm_host.h Peter Fang
2026-04-21 23:06   ` Yosry Ahmed
2026-04-08  0:11 ` Peter Fang [this message]
2026-04-21 23:08   ` [PATCH v2 3/3] KVM: Take gpa_t in kvm_vcpu_map[_readonly]() Yosry Ahmed
2026-04-21 23:19     ` Sean Christopherson
2026-04-21 23:25       ` Yosry Ahmed
2026-04-21 23:29       ` Sean Christopherson
2026-04-21 23:41         ` Yosry Ahmed
2026-04-22  0:27           ` Sean Christopherson
2026-04-22 20:19             ` Yosry Ahmed
2026-04-22 20:34               ` Sean Christopherson
2026-04-22 21:44                 ` Yosry Ahmed
2026-04-22 22:17                   ` Sean Christopherson
2026-04-22 22:19                     ` Yosry Ahmed
2026-04-23  7:49               ` Peter Fang
2026-04-24  8:25   ` Gautam Menghani
2026-04-25  4:25     ` Peter Fang
2026-04-24 10:27 ` [PATCH v2 0/3] KVM: Fix and clean up kvm_vcpu_map[_readonly]() usages David Woodhouse
2026-04-27  8:05   ` Peter Fang
2026-05-04 17:59     ` Sean Christopherson
2026-05-07  8:18       ` Peter Fang
2026-05-13 17:33         ` Sean Christopherson

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=20260408001137.3290444-4-peter.fang@intel.com \
    --to=peter.fang@intel.com \
    --cc=bp@alien8.de \
    --cc=chleroy@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=ritesh.list@gmail.com \
    --cc=seanjc@google.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    --cc=yosry@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.