KVM Archive on lore.kernel.org
 help / color / Atom feed
From: Isaku Yamahata <isaku.yamahata@intel.com>
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>
Cc: isaku.yamahata@gmail.com, Isaku Yamahata <isaku.yamahata@intel.com>
Subject: [RFC PATCH 04/10] KVM: x86/mmu: make try_async_pf() receive single argument
Date: Tue, 20 Apr 2021 03:39:14 -0700
Message-ID: <20c3f7e7d7214b8fdff6d7882ad49e6ae07a41e7.1618914692.git.isaku.yamahata@intel.com> (raw)
In-Reply-To: <cover.1618914692.git.isaku.yamahata@intel.com>

Convert try_async_pf() to receive single struct kvm_page_fault instead of
many arguments.

No functional change is intended.

Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
 arch/x86/kvm/mmu.h             |  9 +++++++
 arch/x86/kvm/mmu/mmu.c         | 45 +++++++++++++++++-----------------
 arch/x86/kvm/mmu/paging_tmpl.h | 23 +++++++++--------
 3 files changed, 42 insertions(+), 35 deletions(-)

diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index fa3b1df502e7..b60fcad7279c 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -111,12 +111,17 @@ struct kvm_page_fault {
 	struct kvm_vcpu *vcpu;
 	gpa_t cr2_or_gpa;
 	u32 error_code;
+	bool write_fault;
 	bool prefault;
 
 	/* internal state */
 	gfn_t gfn;
 	bool is_tdp;
 	int max_level;
+
+	kvm_pfn_t pfn;
+	hva_t hva;
+	bool map_writable;
 };
 
 static inline void kvm_page_fault_init(
@@ -126,12 +131,16 @@ static inline void kvm_page_fault_init(
 	kpf->vcpu = vcpu;
 	kpf->cr2_or_gpa = cr2_or_gpa;
 	kpf->error_code = error_code;
+	kpf->write_fault = error_code & PFERR_WRITE_MASK;
 	kpf->prefault = prefault;
 
 	/* default value */
 	kpf->is_tdp = false;
 	kpf->gfn = cr2_or_gpa >> PAGE_SHIFT;
 	kpf->max_level = PG_LEVEL_4K;
+	kpf->pfn = KVM_PFN_NOSLOT;
+	kpf->hva = KVM_HVA_ERR_BAD;
+	kpf->map_writable = false;
 }
 
 int kvm_tdp_page_fault(struct kvm_page_fault *kpf);
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index cb90148f90af..a2422bd9f59b 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -3646,27 +3646,29 @@ static bool kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
 				  kvm_vcpu_gfn_to_hva(vcpu, gfn), &arch);
 }
 
-static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn,
-			 gpa_t cr2_or_gpa, kvm_pfn_t *pfn, hva_t *hva,
-			 bool write, bool *writable)
+static bool try_async_pf(struct kvm_page_fault *kpf)
 {
+	struct kvm_vcpu *vcpu = kpf->vcpu;
+	gfn_t gfn = kpf->gfn;
+	gpa_t cr2_or_gpa = kpf->cr2_or_gpa;
 	struct kvm_memory_slot *slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn);
 	bool async;
 
 	/* Don't expose private memslots to L2. */
 	if (is_guest_mode(vcpu) && !kvm_is_visible_memslot(slot)) {
-		*pfn = KVM_PFN_NOSLOT;
-		*writable = false;
+		kpf->pfn = KVM_PFN_NOSLOT;
+		kpf->map_writable = false;
 		return false;
 	}
 
 	async = false;
-	*pfn = __gfn_to_pfn_memslot(slot, gfn, false, &async,
-				    write, writable, hva);
+	kpf->pfn = __gfn_to_pfn_memslot(slot, gfn, false, &async,
+					kpf->write_fault, &kpf->map_writable,
+					&kpf->hva);
 	if (!async)
 		return false; /* *pfn has correct page already */
 
-	if (!prefault && kvm_can_do_async_pf(vcpu)) {
+	if (!kpf->prefault && kvm_can_do_async_pf(vcpu)) {
 		trace_kvm_try_async_get_page(cr2_or_gpa, gfn);
 		if (kvm_find_async_pf_gfn(vcpu, gfn)) {
 			trace_kvm_async_pf_doublefault(cr2_or_gpa, gfn);
@@ -3676,8 +3678,9 @@ static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn,
 			return true;
 	}
 
-	*pfn = __gfn_to_pfn_memslot(slot, gfn, false, NULL,
-				    write, writable, hva);
+	kpf->pfn = __gfn_to_pfn_memslot(slot, gfn, false, NULL,
+					kpf->write_fault, &kpf->map_writable,
+					&kpf->hva);
 	return false;
 }
 
@@ -3689,13 +3692,9 @@ static int direct_page_fault(struct kvm_page_fault *kpf)
 	bool prefault = kpf->prefault;
 	int max_level = kpf->max_level;
 	bool is_tdp = kpf->is_tdp;
-	bool write = error_code & PFERR_WRITE_MASK;
-	bool map_writable;
 
 	gfn_t gfn = kpf->gfn;
 	unsigned long mmu_seq;
-	kvm_pfn_t pfn;
-	hva_t hva;
 	int r;
 
 	if (page_fault_handle_page_track(vcpu, error_code, gfn))
@@ -3714,11 +3713,10 @@ static int direct_page_fault(struct kvm_page_fault *kpf)
 	mmu_seq = vcpu->kvm->mmu_notifier_seq;
 	smp_rmb();
 
-	if (try_async_pf(vcpu, prefault, gfn, gpa, &pfn, &hva,
-			 write, &map_writable))
+	if (try_async_pf(kpf))
 		return RET_PF_RETRY;
 
-	if (handle_abnormal_pfn(vcpu, is_tdp ? 0 : gpa, gfn, pfn, ACC_ALL, &r))
+	if (handle_abnormal_pfn(vcpu, is_tdp ? 0 : gpa, gfn, kpf->pfn, ACC_ALL, &r))
 		return r;
 
 	r = RET_PF_RETRY;
@@ -3728,25 +3726,26 @@ static int direct_page_fault(struct kvm_page_fault *kpf)
 	else
 		write_lock(&vcpu->kvm->mmu_lock);
 
-	if (!is_noslot_pfn(pfn) && mmu_notifier_retry_hva(vcpu->kvm, mmu_seq, hva))
+	if (!is_noslot_pfn(kpf->pfn) &&
+	    mmu_notifier_retry_hva(vcpu->kvm, mmu_seq, kpf->hva))
 		goto out_unlock;
 	r = make_mmu_pages_available(vcpu);
 	if (r)
 		goto out_unlock;
 
 	if (is_tdp_mmu_root(vcpu->kvm, vcpu->arch.mmu->root_hpa))
-		r = kvm_tdp_mmu_map(vcpu, gpa, error_code, map_writable, max_level,
-				    pfn, prefault);
+		r = kvm_tdp_mmu_map(vcpu, gpa, error_code, kpf->map_writable,
+				    max_level, kpf->pfn, prefault);
 	else
-		r = __direct_map(vcpu, gpa, error_code, map_writable, max_level, pfn,
-				 prefault, is_tdp);
+		r = __direct_map(vcpu, gpa, error_code, kpf->map_writable,
+				 max_level, kpf->pfn, prefault, is_tdp);
 
 out_unlock:
 	if (is_tdp_mmu_root(vcpu->kvm, vcpu->arch.mmu->root_hpa))
 		read_unlock(&vcpu->kvm->mmu_lock);
 	else
 		write_unlock(&vcpu->kvm->mmu_lock);
-	kvm_release_pfn_clean(pfn);
+	kvm_release_pfn_clean(kpf->pfn);
 	return r;
 }
 
diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h
index dc814463a8df..f2beb7f7c378 100644
--- a/arch/x86/kvm/mmu/paging_tmpl.h
+++ b/arch/x86/kvm/mmu/paging_tmpl.h
@@ -795,14 +795,12 @@ static int FNAME(page_fault)(struct kvm_page_fault *kpf)
 	gpa_t addr = kpf->cr2_or_gpa;
 	u32 error_code = kpf->error_code;
 	bool prefault = kpf->prefault;
-	bool write_fault = error_code & PFERR_WRITE_MASK;
+	bool write_fault = kpf->write_fault;
 	bool user_fault = error_code & PFERR_USER_MASK;
 	struct guest_walker walker;
 	int r;
-	kvm_pfn_t pfn;
-	hva_t hva;
 	unsigned long mmu_seq;
-	bool map_writable, is_self_change_mapping;
+	bool is_self_change_mapping;
 	int max_level;
 
 	pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
@@ -851,11 +849,11 @@ static int FNAME(page_fault)(struct kvm_page_fault *kpf)
 	mmu_seq = vcpu->kvm->mmu_notifier_seq;
 	smp_rmb();
 
-	if (try_async_pf(vcpu, prefault, walker.gfn, addr, &pfn, &hva,
-			 write_fault, &map_writable))
+	kpf->gfn = walker.gfn;
+	if (try_async_pf(kpf))
 		return RET_PF_RETRY;
 
-	if (handle_abnormal_pfn(vcpu, addr, walker.gfn, pfn, walker.pte_access, &r))
+	if (handle_abnormal_pfn(vcpu, addr, walker.gfn, kpf->pfn, walker.pte_access, &r))
 		return r;
 
 	/*
@@ -864,7 +862,7 @@ static int FNAME(page_fault)(struct kvm_page_fault *kpf)
 	 */
 	if (write_fault && !(walker.pte_access & ACC_WRITE_MASK) &&
 	     !is_write_protection(vcpu) && !user_fault &&
-	      !is_noslot_pfn(pfn)) {
+	      !is_noslot_pfn(kpf->pfn)) {
 		walker.pte_access |= ACC_WRITE_MASK;
 		walker.pte_access &= ~ACC_USER_MASK;
 
@@ -880,20 +878,21 @@ static int FNAME(page_fault)(struct kvm_page_fault *kpf)
 
 	r = RET_PF_RETRY;
 	write_lock(&vcpu->kvm->mmu_lock);
-	if (!is_noslot_pfn(pfn) && mmu_notifier_retry_hva(vcpu->kvm, mmu_seq, hva))
+	if (!is_noslot_pfn(kpf->pfn) &&
+	    mmu_notifier_retry_hva(vcpu->kvm, mmu_seq, kpf->hva))
 		goto out_unlock;
 
 	kvm_mmu_audit(vcpu, AUDIT_PRE_PAGE_FAULT);
 	r = make_mmu_pages_available(vcpu);
 	if (r)
 		goto out_unlock;
-	r = FNAME(fetch)(vcpu, addr, &walker, error_code, max_level, pfn,
-			 map_writable, prefault);
+	r = FNAME(fetch)(vcpu, addr, &walker, error_code, max_level, kpf->pfn,
+			 kpf->map_writable, prefault);
 	kvm_mmu_audit(vcpu, AUDIT_POST_PAGE_FAULT);
 
 out_unlock:
 	write_unlock(&vcpu->kvm->mmu_lock);
-	kvm_release_pfn_clean(pfn);
+	kvm_release_pfn_clean(kpf->pfn);
 	return r;
 }
 
-- 
2.25.1


  parent reply index

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-20 10:39 [RFC PATCH 00/10] KVM: x86/mmu: simplify argument to kvm page fault handler Isaku Yamahata
2021-04-20 10:39 ` [RFC PATCH 01/10] KVM: x86/mmu: make kvm_mmu_do_page_fault() receive single argument Isaku Yamahata
2021-04-20 10:39 ` [RFC PATCH 02/10] KVM: x86/mmu: make kvm_mmu:page_fault " Isaku Yamahata
2021-04-20 10:39 ` [RFC PATCH 03/10] KVM: x86/mmu: make direct_page_fault() " Isaku Yamahata
2021-04-20 10:39 ` Isaku Yamahata [this message]
2021-04-20 10:39 ` [RFC PATCH 05/10] KVM: x86/mmu: make page_fault_handle_page_track() " Isaku Yamahata
2021-04-20 10:39 ` [RFC PATCH 06/10] KVM: x86/mmu: make handle_abnormal_pfn() " Isaku Yamahata
2021-04-20 10:39 ` [RFC PATCH 07/10] KVM: x86/mmu: make fast_page_fault() " Isaku Yamahata
2021-04-20 10:39 ` [RFC PATCH 08/10] KVM: x86/mmu: make __direct_map() " Isaku Yamahata
2021-04-20 10:39 ` [RFC PATCH 09/10] KVM: x86/mmu: make kvm_tdp_mmu_map() " Isaku Yamahata
2021-04-20 10:39 ` [RFC PATCH 10/10] KVM: x86/mmu: make FNAME(fetch) " Isaku Yamahata
2021-05-26 21:10 ` [RFC PATCH 00/10] KVM: x86/mmu: simplify argument to kvm page fault handler Sean Christopherson
2021-06-10 12:45   ` Paolo Bonzini
2021-06-10 22:00     ` Isaku Yamahata

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=20c3f7e7d7214b8fdff6d7882ad49e6ae07a41e7.1618914692.git.isaku.yamahata@intel.com \
    --to=isaku.yamahata@intel.com \
    --cc=isaku.yamahata@gmail.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.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

KVM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kvm/0 kvm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kvm kvm/ https://lore.kernel.org/kvm \
		kvm@vger.kernel.org
	public-inbox-index kvm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.kvm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git