]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
KVM: MMU: Remove user access when allowing kernel access to gpte.w=0 page
authorAvi Kivity <avi@redhat.com>
Thu, 27 May 2010 11:35:58 +0000 (14:35 +0300)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 2 Aug 2010 17:30:05 +0000 (10:30 -0700)
If cr0.wp=0, we have to allow the guest kernel access to a page with pte.w=0.
We do that by setting spte.w=1, since the host cr0.wp must remain set so the
host can write protect pages.  Once we allow write access, we must remove
user access otherwise we mistakenly allow the user to write the page.

Reviewed-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
(cherry picked from commit 69325a122580d3a7b26589e8efdd6663001c3297)

arch/x86/kvm/mmu.c

index 62fd8e6a6de993bb21e7be8533e84296ef524c8e..eae4cbd132f54a965824909099cf73e22604d831 100644 (file)
@@ -1837,6 +1837,9 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
 
                spte |= PT_WRITABLE_MASK;
 
+               if (!tdp_enabled && !(pte_access & ACC_WRITE_MASK))
+                       spte &= ~PT_USER_MASK;
+
                /*
                 * Optimization: for pte sync, if spte was writable the hash
                 * lookup is unnecessary (and expensive). Write protection