kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] KVM: nVMX: Consult only the "basic" exit reason when routing nested exit
@ 2020-02-28  1:50 linmiaohe
  0 siblings, 0 replies; 6+ messages in thread
From: linmiaohe @ 2020-02-28  1:50 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Paolo Bonzini, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel, Xiaoyao Li

Sean Christopherson <sean.j.christopherson@intel.com> writes:
>Consult only the basic exit reason, i.e. bits 15:0 of vmcs.EXIT_REASON, when determining whether a nested VM-Exit should be reflected into L1 or handled by KVM in L0.
>
>For better or worse, the switch statement in nested_vmx_exit_reflected() currently defaults to "true", i.e. reflects any nested VM-Exit without dedicated logic.  Because the case statements only contain the basic exit reason, any VM-Exit with modifier bits set will be reflected to L1, even if KVM intended to handle it in L0.
>
>Practically speaking, this only affects EXIT_REASON_MCE_DURING_VMENTRY, i.e. a #MC that occurs on nested VM-Enter would be incorrectly routed to L1, as "failed VM-Entry" is the only modifier that KVM can currently encounter.  The SMM modifiers will never be generated as KVM doesn't support/employ a SMI Transfer Monitor.  Ditto for "exit from enclave", as KVM doesn't yet support virtualizing SGX, i.e. it's impossible to enter an enclave in a KVM guest (L1 or L2).
>

Nice catch! There are similar patch catching this exit reson error.
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>

>Fixes: 644d711aa0e1 ("KVM: nVMX: Deciding if L0 or L1 should handle an L2 exit")
>Cc: Jim Mattson <jmattson@google.com>
>Cc: Xiaoyao Li <xiaoyao.li@intel.com>
>Cc: stable@vger.kernel.org
>Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
>---

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

* Re: [PATCH] KVM: nVMX: Consult only the "basic" exit reason when routing nested exit
  2020-02-27 20:51   ` Sean Christopherson
@ 2020-02-28  9:57     ` Paolo Bonzini
  0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2020-02-28  9:57 UTC (permalink / raw)
  To: Sean Christopherson, Krish Sadhukhan
  Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
	linux-kernel, Xiaoyao Li

On 27/02/20 21:51, Sean Christopherson wrote:
> So part of me thinks the best way to resolve the printing would be to
> modify VMX_EXIT_REASONS to do "| VMX_EXIT_REASONS_FAILED_VMENTRY" where
> appropriate, i.e. on INVALID_STATE, MSR_LOAD_FAIL and MCE_DURING_VMENTRY.
> The downside of that approach is it breaks again when new modifiers come
> along, e.g. SGX's ENCLAVE_EXIT.  But again, the modifier is likely useful
> information.
> 
> I think the most foolproof and informative way to handle this would be to
> add a macro and/or helper function, e.g. kvm_print_vmx_exit_reason(), to
> wrap __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) so that it
> prints both the name of the basic exit reason as well as the names for
> any modifiers.
> 
> TL;DR: I still like this patch as is, especially since it'll be easy to
> backport.  I'll send a separate patch for the tracepoint issue.

Agreed, thanks.  I queued this one.

Paolo


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

* Re: [PATCH] KVM: nVMX: Consult only the "basic" exit reason when routing nested exit
  2020-02-27 20:08 ` Krish Sadhukhan
@ 2020-02-27 20:51   ` Sean Christopherson
  2020-02-28  9:57     ` Paolo Bonzini
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Christopherson @ 2020-02-27 20:51 UTC (permalink / raw)
  To: Krish Sadhukhan
  Cc: Paolo Bonzini, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel, Xiaoyao Li

On Thu, Feb 27, 2020 at 12:08:55PM -0800, Krish Sadhukhan wrote:
> 
> On 2/27/20 9:44 AM, Sean Christopherson wrote:
> >Consult only the basic exit reason, i.e. bits 15:0 of vmcs.EXIT_REASON,
> >when determining whether a nested VM-Exit should be reflected into L1 or
> >handled by KVM in L0.
> >
> >For better or worse, the switch statement in nested_vmx_exit_reflected()
> >currently defaults to "true", i.e. reflects any nested VM-Exit without
> >dedicated logic.  Because the case statements only contain the basic
> >exit reason, any VM-Exit with modifier bits set will be reflected to L1,
> >even if KVM intended to handle it in L0.
> >
> >Practically speaking, this only affects EXIT_REASON_MCE_DURING_VMENTRY,
> >i.e. a #MC that occurs on nested VM-Enter would be incorrectly routed to
> >L1, as "failed VM-Entry" is the only modifier that KVM can currently
> >encounter.  The SMM modifiers will never be generated as KVM doesn't
> >support/employ a SMI Transfer Monitor.  Ditto for "exit from enclave",
> >as KVM doesn't yet support virtualizing SGX, i.e. it's impossible to
> >enter an enclave in a KVM guest (L1 or L2).
> 
> 
> It seems nested_vmx_exit_reflected() deals only with the basic exit reason.
> If it doesn't need anything beyond bits 15:0, may be vmx_handle_exit() can
> pass just the base exit reason ?

Argh.  I was going to simply respond with "It traces exit_reason via
trace_kvm_nested_vmexit().", but then I looked at the tracing code :-(

The tracepoints that print the names of the VM-Exit are flawed in the sense
that they'll always print the raw value for VM-Exits with modifiers.  E.g.
a consistency check VM-Exit on invalid guest state will print 0x80000021
instead of INVALID_STATE.

Stripping bits 31:16 when invoking the tracepoint would fix the immediate
issue, but I'm not sure I like that approach because doing so drops
information that could potentially be quite helpful, e.g. if nested VM-Exit
injection injected EXIT_REASON_MSR_LOAD_FAIL without also setting
VMX_EXIT_REASONS_FAILED_VMENTRY, which could break/confuse the L1 VMM.
I'm also not remotely confident that we won't screw this up again in the
future :-)

So part of me thinks the best way to resolve the printing would be to
modify VMX_EXIT_REASONS to do "| VMX_EXIT_REASONS_FAILED_VMENTRY" where
appropriate, i.e. on INVALID_STATE, MSR_LOAD_FAIL and MCE_DURING_VMENTRY.
The downside of that approach is it breaks again when new modifiers come
along, e.g. SGX's ENCLAVE_EXIT.  But again, the modifier is likely useful
information.

I think the most foolproof and informative way to handle this would be to
add a macro and/or helper function, e.g. kvm_print_vmx_exit_reason(), to
wrap __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) so that it
prints both the name of the basic exit reason as well as the names for
any modifiers.

TL;DR: I still like this patch as is, especially since it'll be easy to
backport.  I'll send a separate patch for the tracepoint issue.


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

* Re: [PATCH] KVM: nVMX: Consult only the "basic" exit reason when routing nested exit
  2020-02-27 17:44 Sean Christopherson
  2020-02-27 19:20 ` Oliver Upton
@ 2020-02-27 20:08 ` Krish Sadhukhan
  2020-02-27 20:51   ` Sean Christopherson
  1 sibling, 1 reply; 6+ messages in thread
From: Krish Sadhukhan @ 2020-02-27 20:08 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini
  Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
	linux-kernel, Xiaoyao Li


On 2/27/20 9:44 AM, Sean Christopherson wrote:
> Consult only the basic exit reason, i.e. bits 15:0 of vmcs.EXIT_REASON,
> when determining whether a nested VM-Exit should be reflected into L1 or
> handled by KVM in L0.
>
> For better or worse, the switch statement in nested_vmx_exit_reflected()
> currently defaults to "true", i.e. reflects any nested VM-Exit without
> dedicated logic.  Because the case statements only contain the basic
> exit reason, any VM-Exit with modifier bits set will be reflected to L1,
> even if KVM intended to handle it in L0.
>
> Practically speaking, this only affects EXIT_REASON_MCE_DURING_VMENTRY,
> i.e. a #MC that occurs on nested VM-Enter would be incorrectly routed to
> L1, as "failed VM-Entry" is the only modifier that KVM can currently
> encounter.  The SMM modifiers will never be generated as KVM doesn't
> support/employ a SMI Transfer Monitor.  Ditto for "exit from enclave",
> as KVM doesn't yet support virtualizing SGX, i.e. it's impossible to
> enter an enclave in a KVM guest (L1 or L2).


It seems nested_vmx_exit_reflected() deals only with the basic exit 
reason. If it doesn't need anything beyond bits 15:0, may be 
vmx_handle_exit() can pass just the base exit reason ?

>
> Fixes: 644d711aa0e1 ("KVM: nVMX: Deciding if L0 or L1 should handle an L2 exit")
> Cc: Jim Mattson <jmattson@google.com>
> Cc: Xiaoyao Li <xiaoyao.li@intel.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>   arch/x86/kvm/vmx/nested.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 0946122a8d3b..127065bbde2c 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -5554,7 +5554,7 @@ bool nested_vmx_exit_reflected(struct kvm_vcpu *vcpu, u32 exit_reason)
>   				vmcs_read32(VM_EXIT_INTR_ERROR_CODE),
>   				KVM_ISA_VMX);
>   
> -	switch (exit_reason) {
> +	switch ((u16)exit_reason) {
>   	case EXIT_REASON_EXCEPTION_NMI:
>   		if (is_nmi(intr_info))
>   			return false;
Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>

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

* Re: [PATCH] KVM: nVMX: Consult only the "basic" exit reason when routing nested exit
  2020-02-27 17:44 Sean Christopherson
@ 2020-02-27 19:20 ` Oliver Upton
  2020-02-27 20:08 ` Krish Sadhukhan
  1 sibling, 0 replies; 6+ messages in thread
From: Oliver Upton @ 2020-02-27 19:20 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Paolo Bonzini, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm list, Linux Kernel Mailing List, Xiaoyao Li

On Thu, Feb 27, 2020 at 9:47 AM Sean Christopherson
<sean.j.christopherson@intel.com> wrote:
>
> Consult only the basic exit reason, i.e. bits 15:0 of vmcs.EXIT_REASON,
> when determining whether a nested VM-Exit should be reflected into L1 or
> handled by KVM in L0.
>
> For better or worse, the switch statement in nested_vmx_exit_reflected()
> currently defaults to "true", i.e. reflects any nested VM-Exit without
> dedicated logic.  Because the case statements only contain the basic
> exit reason, any VM-Exit with modifier bits set will be reflected to L1,
> even if KVM intended to handle it in L0.
>
> Practically speaking, this only affects EXIT_REASON_MCE_DURING_VMENTRY,
> i.e. a #MC that occurs on nested VM-Enter would be incorrectly routed to
> L1, as "failed VM-Entry" is the only modifier that KVM can currently
> encounter.  The SMM modifiers will never be generated as KVM doesn't
> support/employ a SMI Transfer Monitor.  Ditto for "exit from enclave",
> as KVM doesn't yet support virtualizing SGX, i.e. it's impossible to
> enter an enclave in a KVM guest (L1 or L2).
>
> Fixes: 644d711aa0e1 ("KVM: nVMX: Deciding if L0 or L1 should handle an L2 exit")
> Cc: Jim Mattson <jmattson@google.com>
> Cc: Xiaoyao Li <xiaoyao.li@intel.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>  arch/x86/kvm/vmx/nested.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 0946122a8d3b..127065bbde2c 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -5554,7 +5554,7 @@ bool nested_vmx_exit_reflected(struct kvm_vcpu *vcpu, u32 exit_reason)
>                                 vmcs_read32(VM_EXIT_INTR_ERROR_CODE),
>                                 KVM_ISA_VMX);
>
> -       switch (exit_reason) {
> +       switch ((u16)exit_reason) {
>         case EXIT_REASON_EXCEPTION_NMI:
>                 if (is_nmi(intr_info))
>                         return false;
> --
> 2.24.1
>
Reviewed-by: Oliver Upton <oupton@google.com>

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

* [PATCH] KVM: nVMX: Consult only the "basic" exit reason when routing nested exit
@ 2020-02-27 17:44 Sean Christopherson
  2020-02-27 19:20 ` Oliver Upton
  2020-02-27 20:08 ` Krish Sadhukhan
  0 siblings, 2 replies; 6+ messages in thread
From: Sean Christopherson @ 2020-02-27 17:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel, Xiaoyao Li

Consult only the basic exit reason, i.e. bits 15:0 of vmcs.EXIT_REASON,
when determining whether a nested VM-Exit should be reflected into L1 or
handled by KVM in L0.

For better or worse, the switch statement in nested_vmx_exit_reflected()
currently defaults to "true", i.e. reflects any nested VM-Exit without
dedicated logic.  Because the case statements only contain the basic
exit reason, any VM-Exit with modifier bits set will be reflected to L1,
even if KVM intended to handle it in L0.

Practically speaking, this only affects EXIT_REASON_MCE_DURING_VMENTRY,
i.e. a #MC that occurs on nested VM-Enter would be incorrectly routed to
L1, as "failed VM-Entry" is the only modifier that KVM can currently
encounter.  The SMM modifiers will never be generated as KVM doesn't
support/employ a SMI Transfer Monitor.  Ditto for "exit from enclave",
as KVM doesn't yet support virtualizing SGX, i.e. it's impossible to
enter an enclave in a KVM guest (L1 or L2).

Fixes: 644d711aa0e1 ("KVM: nVMX: Deciding if L0 or L1 should handle an L2 exit")
Cc: Jim Mattson <jmattson@google.com>
Cc: Xiaoyao Li <xiaoyao.li@intel.com>
Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/vmx/nested.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 0946122a8d3b..127065bbde2c 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -5554,7 +5554,7 @@ bool nested_vmx_exit_reflected(struct kvm_vcpu *vcpu, u32 exit_reason)
 				vmcs_read32(VM_EXIT_INTR_ERROR_CODE),
 				KVM_ISA_VMX);
 
-	switch (exit_reason) {
+	switch ((u16)exit_reason) {
 	case EXIT_REASON_EXCEPTION_NMI:
 		if (is_nmi(intr_info))
 			return false;
-- 
2.24.1


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

end of thread, other threads:[~2020-02-28  9:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-28  1:50 [PATCH] KVM: nVMX: Consult only the "basic" exit reason when routing nested exit linmiaohe
  -- strict thread matches above, loose matches on Subject: below --
2020-02-27 17:44 Sean Christopherson
2020-02-27 19:20 ` Oliver Upton
2020-02-27 20:08 ` Krish Sadhukhan
2020-02-27 20:51   ` Sean Christopherson
2020-02-28  9:57     ` 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).