KVM: MMU: flush tlb if the spte can be locklessly modified
authorXiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Thu, 17 Apr 2014 09:06:15 +0000 (17:06 +0800)
committerMarcelo Tosatti <mtosatti@redhat.com>
Wed, 23 Apr 2014 20:49:51 +0000 (17:49 -0300)
Relax the tlb flush condition since we will write-protect the spte out of mmu
lock. Note lockless write-protection only marks the writable spte to readonly
and the spte can be writable only if both SPTE_HOST_WRITEABLE and
SPTE_MMU_WRITEABLE are set (that are tested by spte_is_locklessly_modifiable)

This patch is used to avoid this kind of race:

      VCPU 0                         VCPU 1
lockless wirte protection:
      set spte.w = 0
                                 lock mmu-lock

                                 write protection the spte to sync shadow page,
                                 see spte.w = 0, then without flush tlb

 unlock mmu-lock

                                 !!! At this point, the shadow page can still be
                                     writable due to the corrupt tlb entry
     Flush all TLB

Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
arch/x86/kvm/mmu.c

index ddf06963a74c4941f6292a6ef4d3024f4333e49e..388a2ef83911368daf79c10495152ca1fc492899 100644 (file)
@@ -595,7 +595,8 @@ static bool mmu_spte_update(u64 *sptep, u64 new_spte)
         * we always atomicly update it, see the comments in
         * spte_has_volatile_bits().
         */
-       if (is_writable_pte(old_spte) && !is_writable_pte(new_spte))
+       if (spte_is_locklessly_modifiable(old_spte) &&
+             !is_writable_pte(new_spte))
                ret = true;
 
        if (!shadow_accessed_mask)