Skip to content

Commit 3d34ade

Browse files
committed
KVM: MMU: Move gpte_access() out of paging_tmpl.h
We no longer rely on paging_tmpl.h defines; so we can move the function to mmu.c. Rely on zero extension to 64 bits to get the correct nx behaviour. Reviewed-by: Xiao Guangrong <[email protected]> Signed-off-by: Avi Kivity <[email protected]>
1 parent edc2ae8 commit 3d34ade

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

arch/x86/kvm/mmu.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3437,6 +3437,16 @@ static bool sync_mmio_spte(u64 *sptep, gfn_t gfn, unsigned access,
34373437
return false;
34383438
}
34393439

3440+
static inline unsigned gpte_access(struct kvm_vcpu *vcpu, u64 gpte)
3441+
{
3442+
unsigned access;
3443+
3444+
access = (gpte & (PT_WRITABLE_MASK | PT_USER_MASK)) | ACC_EXEC_MASK;
3445+
access &= ~(gpte >> PT64_NX_SHIFT);
3446+
3447+
return access;
3448+
}
3449+
34403450
#define PTTYPE 64
34413451
#include "paging_tmpl.h"
34423452
#undef PTTYPE

arch/x86/kvm/paging_tmpl.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,6 @@ static int FNAME(cmpxchg_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
101101
return (ret != orig_pte);
102102
}
103103

104-
static unsigned FNAME(gpte_access)(struct kvm_vcpu *vcpu, pt_element_t gpte)
105-
{
106-
unsigned access;
107-
108-
access = (gpte & (PT_WRITABLE_MASK | PT_USER_MASK)) | ACC_EXEC_MASK;
109-
#if PTTYPE == 64
110-
access &= ~(gpte >> PT64_NX_SHIFT);
111-
#endif
112-
return access;
113-
}
114-
115104
static bool FNAME(is_last_gpte)(struct guest_walker *walker,
116105
struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
117106
pt_element_t gpte)
@@ -217,7 +206,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
217206

218207
last_gpte = FNAME(is_last_gpte)(walker, vcpu, mmu, pte);
219208
if (last_gpte) {
220-
pte_access = pt_access & FNAME(gpte_access)(vcpu, pte);
209+
pte_access = pt_access & gpte_access(vcpu, pte);
221210
/* check if the kernel is fetching from user page */
222211
if (unlikely(pte_access & PT_USER_MASK) &&
223212
kvm_read_cr4_bits(vcpu, X86_CR4_SMEP))
@@ -268,7 +257,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
268257
break;
269258
}
270259

271-
pt_access &= FNAME(gpte_access)(vcpu, pte);
260+
pt_access &= gpte_access(vcpu, pte);
272261
--walker->level;
273262
}
274263

@@ -364,7 +353,7 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
364353
return;
365354

366355
pgprintk("%s: gpte %llx spte %p\n", __func__, (u64)gpte, spte);
367-
pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte);
356+
pte_access = sp->role.access & gpte_access(vcpu, gpte);
368357
protect_clean_gpte(&pte_access, gpte);
369358
pfn = gfn_to_pfn_atomic(vcpu->kvm, gpte_to_gfn(gpte));
370359
if (mmu_invalid_pfn(pfn))
@@ -438,7 +427,7 @@ static void FNAME(pte_prefetch)(struct kvm_vcpu *vcpu, struct guest_walker *gw,
438427
if (FNAME(prefetch_invalid_gpte)(vcpu, sp, spte, gpte))
439428
continue;
440429

441-
pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte);
430+
pte_access = sp->role.access & gpte_access(vcpu, gpte);
442431
protect_clean_gpte(&pte_access, gpte);
443432
gfn = gpte_to_gfn(gpte);
444433
pfn = pte_prefetch_gfn_to_pfn(vcpu, gfn,
@@ -791,7 +780,7 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
791780

792781
gfn = gpte_to_gfn(gpte);
793782
pte_access = sp->role.access;
794-
pte_access &= FNAME(gpte_access)(vcpu, gpte);
783+
pte_access &= gpte_access(vcpu, gpte);
795784
protect_clean_gpte(&pte_access, gpte);
796785

797786
if (sync_mmio_spte(&sp->spt[i], gfn, pte_access, &nr_present))

0 commit comments

Comments
 (0)