kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm: nVMX: Remove unnecessary sync_roots from handle_invept
@ 2019-06-13 16:16 Jim Mattson
  2019-07-02 16:39 ` Jim Mattson
  2019-07-02 16:50 ` Paolo Bonzini
  0 siblings, 2 replies; 3+ messages in thread
From: Jim Mattson @ 2019-06-13 16:16 UTC (permalink / raw)
  To: kvm
  Cc: Jim Mattson, Junaid Shahid, Xiao Guangrong, Nadav Har'El,
	Jun Nakajima, Xinhao Xu, Yang Zhang, Gleb Natapov, Paolo Bonzini

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.

Reported-by: Junaid Shahid <junaids@google.com>
Fixes: bfd0a56b90005f ("nEPT: Nested INVEPT")
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: Nadav Har'El <nyh@il.ibm.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
Cc: Xinhao Xu <xinhao.xu@intel.com>
Cc: Yang Zhang <yang.z.zhang@Intel.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by Peter Shier <pshier@google.com>
Reviewed-by: Junaid Shahid <junaids@google.com>
Signed-off-by: Jim Mattson <jmattson@google.com>
---
 arch/x86/kvm/vmx/nested.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 1032f068f0b9..35621e73e726 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -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);
-- 
2.22.0.rc2.383.gf4fbbf30c2-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] kvm: nVMX: Remove unnecessary sync_roots from handle_invept
  2019-06-13 16:16 [PATCH] kvm: nVMX: Remove unnecessary sync_roots from handle_invept Jim Mattson
@ 2019-07-02 16:39 ` Jim Mattson
  2019-07-02 16:50 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Jim Mattson @ 2019-07-02 16:39 UTC (permalink / raw)
  To: kvm list; +Cc: Junaid Shahid, Xiao Guangrong, Jun Nakajima, Paolo Bonzini

On Thu, Jun 13, 2019 at 9:16 AM Jim Mattson <jmattson@google.com> wrote:
>
> 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.
>
> Reported-by: Junaid Shahid <junaids@google.com>
> Fixes: bfd0a56b90005f ("nEPT: Nested INVEPT")
> Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
> Cc: Nadav Har'El <nyh@il.ibm.com>
> Cc: Jun Nakajima <jun.nakajima@intel.com>
> Cc: Xinhao Xu <xinhao.xu@intel.com>
> Cc: Yang Zhang <yang.z.zhang@Intel.com>
> Cc: Gleb Natapov <gleb@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Reviewed-by Peter Shier <pshier@google.com>
> Reviewed-by: Junaid Shahid <junaids@google.com>
> Signed-off-by: Jim Mattson <jmattson@google.com>
> ---
>  arch/x86/kvm/vmx/nested.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 1032f068f0b9..35621e73e726 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -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);
> --
> 2.22.0.rc2.383.gf4fbbf30c2-goog
>

Ping.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kvm: nVMX: Remove unnecessary sync_roots from handle_invept
  2019-06-13 16:16 [PATCH] kvm: nVMX: Remove unnecessary sync_roots from handle_invept Jim Mattson
  2019-07-02 16:39 ` Jim Mattson
@ 2019-07-02 16:50 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2019-07-02 16:50 UTC (permalink / raw)
  To: Jim Mattson, kvm
  Cc: Junaid Shahid, Xiao Guangrong, Nadav Har'El, Jun Nakajima,
	Xinhao Xu, Yang Zhang, Gleb Natapov

On 13/06/19 18:16, Jim Mattson wrote:
> 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.
> 
> Reported-by: Junaid Shahid <junaids@google.com>
> Fixes: bfd0a56b90005f ("nEPT: Nested INVEPT")
> Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
> Cc: Nadav Har'El <nyh@il.ibm.com>
> Cc: Jun Nakajima <jun.nakajima@intel.com>
> Cc: Xinhao Xu <xinhao.xu@intel.com>
> Cc: Yang Zhang <yang.z.zhang@Intel.com>
> Cc: Gleb Natapov <gleb@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Reviewed-by Peter Shier <pshier@google.com>
> Reviewed-by: Junaid Shahid <junaids@google.com>
> Signed-off-by: Jim Mattson <jmattson@google.com>
> ---
>  arch/x86/kvm/vmx/nested.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)

Queued, thanks.

Paolo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-02 16:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-13 16:16 [PATCH] kvm: nVMX: Remove unnecessary sync_roots from handle_invept Jim Mattson
2019-07-02 16:39 ` Jim Mattson
2019-07-02 16:50 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).