All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: nSVM: clear events pending from svm_complete_interrupts() when exiting to L1
@ 2019-01-07 18:44 Vitaly Kuznetsov
  2019-01-21 15:55 ` Vitaly Kuznetsov
  2019-01-25 17:51 ` Paolo Bonzini
  0 siblings, 2 replies; 3+ messages in thread
From: Vitaly Kuznetsov @ 2019-01-07 18:44 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář, linux-kernel,
	Joerg Roedel, x86

kvm-unit-tests' eventinj "NMI failing on IDT" test results in NMI being
delivered to the host (L1) when it's running nested. The problem seems to
be: svm_complete_interrupts() raises 'nmi_injected' flag but later we
decide to reflect EXIT_NPF to L1. The flag remains pending and we do NMI
injection upon entry so it got delivered to L1 instead of L2.

It seems that VMX code solves the same issue in prepare_vmcs12(), this was
introduced with code refactoring in commit 5f3d5799974b ("KVM: nVMX: Rework
event injection and recovery").

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/kvm/svm.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 33d4ed6e78a5..db842dafccf0 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -3419,6 +3419,14 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
 	kvm_mmu_reset_context(&svm->vcpu);
 	kvm_mmu_load(&svm->vcpu);
 
+	/*
+	 * Drop what we picked up for L2 via svm_complete_interrupts() so it
+	 * doesn't end up in L1.
+	 */
+	svm->vcpu.arch.nmi_injected = false;
+	kvm_clear_exception_queue(&svm->vcpu);
+	kvm_clear_interrupt_queue(&svm->vcpu);
+
 	return 0;
 }
 
-- 
2.20.1

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

* Re: [PATCH] KVM: nSVM: clear events pending from svm_complete_interrupts() when exiting to L1
  2019-01-07 18:44 [PATCH] KVM: nSVM: clear events pending from svm_complete_interrupts() when exiting to L1 Vitaly Kuznetsov
@ 2019-01-21 15:55 ` Vitaly Kuznetsov
  2019-01-25 17:51 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Vitaly Kuznetsov @ 2019-01-21 15:55 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář, linux-kernel,
	Joerg Roedel, x86

Vitaly Kuznetsov <vkuznets@redhat.com> writes:

> kvm-unit-tests' eventinj "NMI failing on IDT" test results in NMI being
> delivered to the host (L1) when it's running nested. The problem seems to
> be: svm_complete_interrupts() raises 'nmi_injected' flag but later we
> decide to reflect EXIT_NPF to L1. The flag remains pending and we do NMI
> injection upon entry so it got delivered to L1 instead of L2.
>
> It seems that VMX code solves the same issue in prepare_vmcs12(), this was
> introduced with code refactoring in commit 5f3d5799974b ("KVM: nVMX: Rework
> event injection and recovery").
>
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  arch/x86/kvm/svm.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 33d4ed6e78a5..db842dafccf0 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -3419,6 +3419,14 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
>  	kvm_mmu_reset_context(&svm->vcpu);
>  	kvm_mmu_load(&svm->vcpu);
>  
> +	/*
> +	 * Drop what we picked up for L2 via svm_complete_interrupts() so it
> +	 * doesn't end up in L1.
> +	 */
> +	svm->vcpu.arch.nmi_injected = false;
> +	kvm_clear_exception_queue(&svm->vcpu);
> +	kvm_clear_interrupt_queue(&svm->vcpu);
> +
>  	return 0;
>  }

Ping?

-- 
Vitaly

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

* Re: [PATCH] KVM: nSVM: clear events pending from svm_complete_interrupts() when exiting to L1
  2019-01-07 18:44 [PATCH] KVM: nSVM: clear events pending from svm_complete_interrupts() when exiting to L1 Vitaly Kuznetsov
  2019-01-21 15:55 ` Vitaly Kuznetsov
@ 2019-01-25 17:51 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2019-01-25 17:51 UTC (permalink / raw)
  To: Vitaly Kuznetsov, kvm
  Cc: Radim Krčmář, linux-kernel, Joerg Roedel, x86

On 07/01/19 19:44, Vitaly Kuznetsov wrote:
> kvm-unit-tests' eventinj "NMI failing on IDT" test results in NMI being
> delivered to the host (L1) when it's running nested. The problem seems to
> be: svm_complete_interrupts() raises 'nmi_injected' flag but later we
> decide to reflect EXIT_NPF to L1. The flag remains pending and we do NMI
> injection upon entry so it got delivered to L1 instead of L2.
> 
> It seems that VMX code solves the same issue in prepare_vmcs12(), this was
> introduced with code refactoring in commit 5f3d5799974b ("KVM: nVMX: Rework

Queued, thanks.

Paolo

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

end of thread, other threads:[~2019-01-25 17:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-07 18:44 [PATCH] KVM: nSVM: clear events pending from svm_complete_interrupts() when exiting to L1 Vitaly Kuznetsov
2019-01-21 15:55 ` Vitaly Kuznetsov
2019-01-25 17:51 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.