Skip to contentSkip to conversation

KVM: MMU: Don't use RCU for lockless shadow walking

PATCH Applied Avi Kivity 2 participants 2 messages May 14, 2012 – May 16, 2012

Subsystems (3)
lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH v3 1/1 KVM: MMU: Don't use RCU for lockless shadow walking

Using RCU for lockless shadow walking can increase the amount of memory in use by the system, since RCU grace periods are unpredictable. We also have an unconditional write to a shared variable (reader_counter), which isn't good for scaling.

Replace that with a scheme similar to x86's get_user_pages_fast(): disable interrupts during lockless shadow walk to force the freer (kvm_mmu_commit_zap_page()) to wait for the TLB flush IPI to find the processor with interrupts enabled.

We also add a new vcpu->mode, READING_SHADOW_PAGE_TABLES, to prevent kvm_flush_remote_tlbs() from avoiding the IPI.

v3: rebased, updated comments around barriers

---
 arch/x86/include/asm/kvm_host.h |    4 ---
 arch/x86/kvm/mmu.c              |   73 ++++++++++++++++-----------------------
 include/linux/kvm_host.h        |    3 +-
 3 files changed, 31 insertions(+), 49 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -4
index 69e39bc..64c8989 100644
@@ -240,8 +240,6 @@ struct kvm_mmu_page {
 #endif
 
 	int write_flooding_count;
-
-	struct rcu_head rcu;
 };
 
 struct kvm_pio_request {
@@ -540,8 +538,6 @@ struct kvm_arch {
 	u64 hv_guest_os_id;
 	u64 hv_hypercall;
 
-	atomic_t reader_counter;
-
 	#ifdef CONFIG_KVM_MMU_AUDIT
 	int audit_point;
 	#endif
arch/x86/kvm/mmu.c +29 -44

102 lines not on this page · raw message

include/linux/kvm_host.h +2 -1
index cae342d..c446435 100644
@@ -128,7 +128,8 @@ int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu);
 enum {
 	OUTSIDE_GUEST_MODE,
 	IN_GUEST_MODE,
-	EXITING_GUEST_MODE
+	EXITING_GUEST_MODE,
+	READING_SHADOW_PAGE_TABLES,
 };
 
 /*
Signature · 1 line
1.7.10.1
#1 lore raw
Quoted 10 lines · Avi Kivity

Using RCU for lockless shadow walking can increase the amount of memory in use by the system, since RCU grace periods are unpredictable. We also have an unconditional write to a shared variable (reader_counter), which isn't good for scaling.

Replace that with a scheme similar to x86's get_user_pages_fast(): disable interrupts during lockless shadow walk to force the freer (kvm_mmu_commit_zap_page()) to wait for the TLB flush IPI to find the processor with interrupts enabled.

Quoted 4 lines

We also add a new vcpu->mode, READING_SHADOW_PAGE_TABLES, to prevent kvm_flush_remote_tlbs() from avoiding the IPI.

Applied, thanks.