Skip to content

Commit caf6900

Browse files
Xiao Guangrongmatosatti
authored andcommitted
KVM: MMU: lazily drop large spte
Currently, kvm zaps the large spte if write-protected is needed, the later read can fault on that spte. Actually, we can make the large spte readonly instead of making them not present, the page fault caused by read access can be avoided The idea is from Avi: | As I mentioned before, write-protecting a large spte is a good idea, | since it moves some work from protect-time to fault-time, so it reduces | jitter. This removes the need for the return value. Reviewed-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
1 parent 5037878 commit caf6900

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

‎arch/x86/kvm/mmu.c‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,7 @@ static void drop_large_spte(struct kvm_vcpu *vcpu, u64 *sptep)
11061106

11071107
/*
11081108
* Write-protect on the specified @sptep, @pt_protect indicates whether
1109-
* spte writ-protection is caused by protecting shadow page table.
1110-
* @flush indicates whether tlb need be flushed.
1109+
* spte write-protection is caused by protecting shadow page table.
11111110
*
11121111
* Note: write protection is difference between drity logging and spte
11131112
* protection:
@@ -1116,10 +1115,9 @@ static void drop_large_spte(struct kvm_vcpu *vcpu, u64 *sptep)
11161115
* - for spte protection, the spte can be writable only after unsync-ing
11171116
* shadow page.
11181117
*
1119-
* Return true if the spte is dropped.
1118+
* Return true if tlb need be flushed.
11201119
*/
1121-
static bool
1122-
spte_write_protect(struct kvm *kvm, u64 *sptep, bool *flush, bool pt_protect)
1120+
static bool spte_write_protect(struct kvm *kvm, u64 *sptep, bool pt_protect)
11231121
{
11241122
u64 spte = *sptep;
11251123

@@ -1129,17 +1127,11 @@ spte_write_protect(struct kvm *kvm, u64 *sptep, bool *flush, bool pt_protect)
11291127

11301128
rmap_printk("rmap_write_protect: spte %p %llx\n", sptep, *sptep);
11311129

1132-
if (__drop_large_spte(kvm, sptep)) {
1133-
*flush |= true;
1134-
return true;
1135-
}
1136-
11371130
if (pt_protect)
11381131
spte &= ~SPTE_MMU_WRITEABLE;
11391132
spte = spte & ~PT_WRITABLE_MASK;
11401133

1141-
*flush |= mmu_spte_update(sptep, spte);
1142-
return false;
1134+
return mmu_spte_update(sptep, spte);
11431135
}
11441136

11451137
static bool __rmap_write_protect(struct kvm *kvm, unsigned long *rmapp,
@@ -1151,11 +1143,8 @@ static bool __rmap_write_protect(struct kvm *kvm, unsigned long *rmapp,
11511143

11521144
for (sptep = rmap_get_first(*rmapp, &iter); sptep;) {
11531145
BUG_ON(!(*sptep & PT_PRESENT_MASK));
1154-
if (spte_write_protect(kvm, sptep, &flush, pt_protect)) {
1155-
sptep = rmap_get_first(*rmapp, &iter);
1156-
continue;
1157-
}
11581146

1147+
flush |= spte_write_protect(kvm, sptep, pt_protect);
11591148
sptep = rmap_get_next(&iter);
11601149
}
11611150

@@ -2596,6 +2585,8 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
25962585
break;
25972586
}
25982587

2588+
drop_large_spte(vcpu, iterator.sptep);
2589+
25992590
if (!is_shadow_present_pte(*iterator.sptep)) {
26002591
u64 base_addr = iterator.addr;
26012592

0 commit comments

Comments
 (0)