Commit a12f4381 authored by Paolo Bonzini's avatar Paolo Bonzini

KVM: MMU: pass struct kvm_page_fault to mmu_set_spte

mmu_set_spte is called for either PTE prefetching or page faults.  The
three boolean arguments write_fault, speculative and host_writable are
always respectively false/true/true for prefetching and coming from
a struct kvm_page_fault for page faults.

Let mmu_set_spte distinguish these two situation by accepting a
possibly NULL struct kvm_page_fault argument.
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 7158bee4
...@@ -2675,9 +2675,8 @@ int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, gfn_t gfn, bool can_unsync, ...@@ -2675,9 +2675,8 @@ int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, gfn_t gfn, bool can_unsync,
} }
static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
unsigned int pte_access, bool write_fault, unsigned int pte_access, gfn_t gfn,
gfn_t gfn, kvm_pfn_t pfn, bool speculative, kvm_pfn_t pfn, struct kvm_page_fault *fault)
bool host_writable)
{ {
struct kvm_mmu_page *sp = sptep_to_sp(sptep); struct kvm_mmu_page *sp = sptep_to_sp(sptep);
int level = sp->role.level; int level = sp->role.level;
...@@ -2687,6 +2686,11 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, ...@@ -2687,6 +2686,11 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
bool wrprot; bool wrprot;
u64 spte; u64 spte;
/* Prefetching always gets a writable pfn. */
bool host_writable = !fault || fault->map_writable;
bool speculative = !fault || fault->prefault;
bool write_fault = fault && fault->write;
pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__, pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__,
*sptep, write_fault, gfn); *sptep, write_fault, gfn);
...@@ -2778,8 +2782,8 @@ static int direct_pte_prefetch_many(struct kvm_vcpu *vcpu, ...@@ -2778,8 +2782,8 @@ static int direct_pte_prefetch_many(struct kvm_vcpu *vcpu,
return -1; return -1;
for (i = 0; i < ret; i++, gfn++, start++) { for (i = 0; i < ret; i++, gfn++, start++) {
mmu_set_spte(vcpu, start, access, false, gfn, mmu_set_spte(vcpu, start, access, gfn,
page_to_pfn(pages[i]), true, true); page_to_pfn(pages[i]), NULL);
put_page(pages[i]); put_page(pages[i]);
} }
...@@ -2981,8 +2985,7 @@ static int __direct_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) ...@@ -2981,8 +2985,7 @@ static int __direct_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
return -EFAULT; return -EFAULT;
ret = mmu_set_spte(vcpu, it.sptep, ACC_ALL, ret = mmu_set_spte(vcpu, it.sptep, ACC_ALL,
fault->write, base_gfn, fault->pfn, base_gfn, fault->pfn, fault);
fault->prefault, fault->map_writable);
if (ret == RET_PF_SPURIOUS) if (ret == RET_PF_SPURIOUS)
return ret; return ret;
......
...@@ -578,13 +578,7 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, ...@@ -578,13 +578,7 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
if (is_error_pfn(pfn)) if (is_error_pfn(pfn))
return false; return false;
/* mmu_set_spte(vcpu, spte, pte_access, gfn, pfn, NULL);
* we call mmu_set_spte() with host_writable = true because
* pte_prefetch_gfn_to_pfn always gets a writable pfn.
*/
mmu_set_spte(vcpu, spte, pte_access, false, gfn, pfn,
true, true);
kvm_release_pfn_clean(pfn); kvm_release_pfn_clean(pfn);
return true; return true;
} }
...@@ -763,9 +757,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, ...@@ -763,9 +757,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault,
if (WARN_ON_ONCE(it.level != fault->goal_level)) if (WARN_ON_ONCE(it.level != fault->goal_level))
return -EFAULT; return -EFAULT;
ret = mmu_set_spte(vcpu, it.sptep, gw->pte_access, fault->write, ret = mmu_set_spte(vcpu, it.sptep, gw->pte_access,
base_gfn, fault->pfn, fault->prefault, base_gfn, fault->pfn, fault);
fault->map_writable);
if (ret == RET_PF_SPURIOUS) if (ret == RET_PF_SPURIOUS)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment