Re: [PATCH 3/6] KVM: MMU: Add EPT support

Anthony Liguori
2008-04-18T13:30:14Z

Yang, Sheng wrote:
> @@ -1048,17 +1071,18 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64
> *shadow_pte,
> * whether the guest actually used the pte (in order to detect
> * demand paging).
> */
> - spte = PT_PRESENT_MASK | PT_DIRTY_MASK;
> + spte = shadow_base_present_pte | shadow_dirty_mask;
> if (!speculative)
> pte_access |= PT_ACCESSED_MASK;
> if (!dirty)
> pte_access &= ~ACC_WRITE_MASK;
> - if (!(pte_access & ACC_EXEC_MASK))
> - spte |= PT64_NX_MASK;
> -
> - spte |= PT_PRESENT_MASK;
> + if (pte_access & ACC_EXEC_MASK) {
> + if (shadow_x_mask)
> + spte |= shadow_x_mask;
> + } else if (shadow_nx_mask)
> + spte |= shadow_nx_mask;
>

This looks like it may be a bug. The old behavior sets NX if
(pte_access & ACC_EXEC_MASK). The new behavior unconditionally sets NX
and never sets PRESENT. Also, the if (shadow_x_mask) checks are
unnecessary. spte |= 0 is a nop.

> if (pte_access & ACC_USER_MASK)
> - spte |= PT_USER_MASK;
> + spte |= shadow_user_mask;
> if (largepage)
> spte |= PT_PAGE_SIZE_MASK;
>

Regards,

Anthony Liguori