Skip to contentSkip to conversation

kvm: nVMX: Remove unnecessary sync_roots from handle_invept

PATCH Applied Jim Mattson 2 participants 3 messages Jun 13, 2019 – Jul 2, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: nVMX: Remove unnecessary sync_roots from handle_invept

When L0 is executing handle_invept(), the TDP MMU is active. Emulating an L1 INVEPT does require synchronizing the appropriate shadow EPT root(s), but a call to kvm_mmu_sync_roots in this context won't do that. Similarly, the hardware TLB and paging-structure-cache entries associated with the appropriate shadow EPT root(s) must be flushed, but requesting a TLB_FLUSH from this context won't do that either.

How did this ever work? KVM always does a sync_roots and TLB flush (in the correct context) when transitioning from L1 to L2. That isn't the best choice for nested VM performance, but it effectively papers over the mistakes here.

Remove the unnecessary operations and leave a comment to try to do better in the future.

Fixes bfd0a56b90005f ("nEPT: Nested INVEPT")
Cc Xiao Guangrong <[email protected]>
Cc Nadav Har'El <[email protected]>
Cc Jun Nakajima <[email protected]>
Cc Xinhao Xu <[email protected]>
Cc Yang Zhang <[email protected]>
Cc Gleb Natapov <[email protected]>
Cc Paolo Bonzini <[email protected]>

Reviewed-by Peter Shier <[email protected]>

---
 arch/x86/kvm/vmx/nested.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/kvm/vmx/nested.c +3 -5
index 1032f068f0b9..35621e73e726 100644
@@ -4670,13 +4670,11 @@ static int handle_invept(struct kvm_vcpu *vcpu)
 
 	switch (type) {
 	case VMX_EPT_EXTENT_GLOBAL:
+	case VMX_EPT_EXTENT_CONTEXT:
 	/*
-	 * TODO: track mappings and invalidate
-	 * single context requests appropriately
+	 * TODO: Sync the necessary shadow EPT roots here, rather than
+	 * at the next emulated VM-entry.
 	 */
-	case VMX_EPT_EXTENT_CONTEXT:
-		kvm_mmu_sync_roots(vcpu);
-		kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
 		break;
 	default:
 		BUG_ON(1);
Signature · 1 line
2.22.0.rc2.383.gf4fbbf30c2-goog
#1 lore raw
Quoted 54 lines · Jim Mattson

When L0 is executing handle_invept(), the TDP MMU is active. Emulating an L1 INVEPT does require synchronizing the appropriate shadow EPT root(s), but a call to kvm_mmu_sync_roots in this context won't do that. Similarly, the hardware TLB and paging-structure-cache entries associated with the appropriate shadow EPT root(s) must be flushed, but requesting a TLB_FLUSH from this context won't do that either.

How did this ever work? KVM always does a sync_roots and TLB flush (in the correct context) when transitioning from L1 to L2. That isn't the best choice for nested VM performance, but it effectively papers over the mistakes here.

Remove the unnecessary operations and leave a comment to try to do better in the future.

Fixes bfd0a56b90005f ("nEPT: Nested INVEPT")
Cc Xiao Guangrong <[email protected]>
Cc Nadav Har'El <[email protected]>
Cc Jun Nakajima <[email protected]>
Cc Xinhao Xu <[email protected]>
Cc Yang Zhang <[email protected]>
Cc Gleb Natapov <[email protected]>
Cc Paolo Bonzini <[email protected]>

Reviewed-by Peter Shier <[email protected]>

---
 arch/x86/kvm/vmx/nested.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/kvm/vmx/nested.c +3 -6
index 1032f068f0b9..35621e73e726 100644
@@ -4670,13 +4670,11 @@ static int handle_invept(struct kvm_vcpu *vcpu)
 
        switch (type) {
        case VMX_EPT_EXTENT_GLOBAL:
+       case VMX_EPT_EXTENT_CONTEXT:
        /*
-        * TODO: track mappings and invalidate
-        * single context requests appropriately
+        * TODO: Sync the necessary shadow EPT roots here, rather than
+        * at the next emulated VM-entry.
         */
-       case VMX_EPT_EXTENT_CONTEXT:
-               kvm_mmu_sync_roots(vcpu);
-               kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
                break;
        default:
                BUG_ON(1);
--
Quoted 2 lines

2.22.0.rc2.383.gf4fbbf30c2-goog

Ping.

maintainer Applied
#2 lore raw
In reply to Jim Mattson
Quoted 24 lines · Jim Mattson

When L0 is executing handle_invept(), the TDP MMU is active. Emulating an L1 INVEPT does require synchronizing the appropriate shadow EPT root(s), but a call to kvm_mmu_sync_roots in this context won't do that. Similarly, the hardware TLB and paging-structure-cache entries associated with the appropriate shadow EPT root(s) must be flushed, but requesting a TLB_FLUSH from this context won't do that either.

How did this ever work? KVM always does a sync_roots and TLB flush (in the correct context) when transitioning from L1 to L2. That isn't the best choice for nested VM performance, but it effectively papers over the mistakes here.

Remove the unnecessary operations and leave a comment to try to do better in the future.

Fixes bfd0a56b90005f ("nEPT: Nested INVEPT")
Cc Xiao Guangrong <[email protected]>
Cc Nadav Har'El <[email protected]>
Cc Jun Nakajima <[email protected]>
Cc Xinhao Xu <[email protected]>
Cc Yang Zhang <[email protected]>
Cc Gleb Natapov <[email protected]>
Cc Paolo Bonzini <[email protected]>
Quoted 6 lines

Reviewed-by Peter Shier <[email protected]>

---
 arch/x86/kvm/vmx/nested.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Queued, thanks.

Paolo