@@ -1105,7 +1105,8 @@ static void drop_large_spte(struct kvm_vcpu *vcpu, u64 *sptep)
11051105
11061106/*
11071107 * Write-protect on the specified @sptep, @pt_protect indicates whether
1108- * spte write-protection is caused by protecting shadow page table.
1108+ * spte writ-protection is caused by protecting shadow page table.
1109+ * @flush indicates whether tlb need be flushed.
11091110 *
11101111 * Note: write protection is difference between drity logging and spte
11111112 * protection:
@@ -1114,9 +1115,10 @@ static void drop_large_spte(struct kvm_vcpu *vcpu, u64 *sptep)
11141115 * - for spte protection, the spte can be writable only after unsync-ing
11151116 * shadow page.
11161117 *
1117- * Return true if tlb need be flushed .
1118+ * Return true if the spte is dropped .
11181119 */
1119- static bool spte_write_protect (struct kvm * kvm , u64 * sptep , bool pt_protect )
1120+ static bool
1121+ spte_write_protect (struct kvm * kvm , u64 * sptep , bool * flush , bool pt_protect )
11201122{
11211123 u64 spte = * sptep ;
11221124
@@ -1126,11 +1128,17 @@ static bool spte_write_protect(struct kvm *kvm, u64 *sptep, bool pt_protect)
11261128
11271129 rmap_printk ("rmap_write_protect: spte %p %llx\n" , sptep , * sptep );
11281130
1131+ if (__drop_large_spte (kvm , sptep )) {
1132+ * flush |= true;
1133+ return true;
1134+ }
1135+
11291136 if (pt_protect )
11301137 spte &= ~SPTE_MMU_WRITEABLE ;
11311138 spte = spte & ~PT_WRITABLE_MASK ;
11321139
1133- return mmu_spte_update (sptep , spte );
1140+ * flush |= mmu_spte_update (sptep , spte );
1141+ return false;
11341142}
11351143
11361144static bool __rmap_write_protect (struct kvm * kvm , unsigned long * rmapp ,
@@ -1142,8 +1150,11 @@ static bool __rmap_write_protect(struct kvm *kvm, unsigned long *rmapp,
11421150
11431151 for (sptep = rmap_get_first (* rmapp , & iter ); sptep ;) {
11441152 BUG_ON (!(* sptep & PT_PRESENT_MASK ));
1153+ if (spte_write_protect (kvm , sptep , & flush , pt_protect )) {
1154+ sptep = rmap_get_first (* rmapp , & iter );
1155+ continue ;
1156+ }
11451157
1146- flush |= spte_write_protect (kvm , sptep , pt_protect );
11471158 sptep = rmap_get_next (& iter );
11481159 }
11491160
@@ -2581,8 +2592,6 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
25812592 break ;
25822593 }
25832594
2584- drop_large_spte (vcpu , iterator .sptep );
2585-
25862595 if (!is_shadow_present_pte (* iterator .sptep )) {
25872596 u64 base_addr = iterator .addr ;
25882597
0 commit comments