LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] KVM: x86: accept userspace interrupt only if no event is injected
@ 2021-07-14 21:38 Paolo Bonzini
  2021-07-16  7:27 ` stsp
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2021-07-14 21:38 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: stable, Stas Sergeev

Once an exception has been injected, any side effects related to
the exception (such as setting CR2 or DR6) have been taked place.
Therefore, once KVM sets the VM-entry interruption information
field or the AMD EVENTINJ field, the next VM-entry must deliver that
exception.

Pending interrupts are processed after injected exceptions, so
in theory it would not be a problem to use KVM_INTERRUPT when
an injected exception is present.  However, DOSBox is using
run->ready_for_interrupt_injection to detect interrupt windows
and then using KVM_SET_SREGS/KVM_SET_REGS to inject the
interrupt manually.  For this to work, the interrupt window
must be delayed after the completion of the previous event
injection.

Cc: stable@vger.kernel.org
Reported-by: Stas Sergeev <stsp2@yandex.ru>
Tested-by: Stas Sergeev <stsp2@yandex.ru>
Fixes: 71cc849b7093 ("KVM: x86: Fix split-irqchip vs interrupt injection window request")
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kvm/x86.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index fe3aaf195292..7fbab29b3569 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4342,6 +4342,9 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
 
 static int kvm_cpu_accept_dm_intr(struct kvm_vcpu *vcpu)
 {
+	if (kvm_event_needs_reinjection(vcpu))
+		return false;
+
 	/*
 	 * We can accept userspace's request for interrupt injection
 	 * as long as we have a place to store the interrupt number.
-- 
2.27.0


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

* Re: [PATCH] KVM: x86: accept userspace interrupt only if no event is injected
  2021-07-14 21:38 [PATCH] KVM: x86: accept userspace interrupt only if no event is injected Paolo Bonzini
@ 2021-07-16  7:27 ` stsp
  2021-07-16 14:41   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: stsp @ 2021-07-16  7:27 UTC (permalink / raw)
  To: Paolo Bonzini, linux-kernel, kvm; +Cc: stable


15.07.2021 00:38, Paolo Bonzini пишет:
> Once an exception has been injected, any side effects related to
> the exception (such as setting CR2 or DR6) have been taked

"taken"? Probably a typo.


>   place.
> Therefore, once KVM sets the VM-entry interruption information
> field or the AMD EVENTINJ field, the next VM-entry must deliver that
> exception.
>
> Pending interrupts are processed after injected exceptions, so
> in theory it would not be a problem to use KVM_INTERRUPT when
> an injected exception is present.  However, DOSBox

dosemu2 to be precise.


>   is using
> run->ready_for_interrupt_injection to detect interrupt windows
> and then using KVM_SET_SREGS/KVM_SET_REGS to inject the
> interrupt manually.  For this to work, the interrupt window
> must be delayed after the completion of the previous event
> injection.
>
> Cc: stable@vger.kernel.org
> Reported-by: Stas Sergeev <stsp2@yandex.ru>
> Tested-by: Stas Sergeev <stsp2@yandex.ru>
> Fixes: 71cc849b7093 ("KVM: x86: Fix split-irqchip vs interrupt injection window request")
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   arch/x86/kvm/x86.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index fe3aaf195292..7fbab29b3569 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -4342,6 +4342,9 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
>   
>   static int kvm_cpu_accept_dm_intr(struct kvm_vcpu *vcpu)
>   {
> +	if (kvm_event_needs_reinjection(vcpu))
> +		return false;
> +

kvm_event_needs_reinjection() seems
to miss exception.pending check.
Don't we need it too?

Also perhaps a comment would be good
to have to avoid it from disappearing again,
as obviously kvm devs tend to overlook
the possibility of injecting interrupts by hands.


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

* Re: [PATCH] KVM: x86: accept userspace interrupt only if no event is injected
  2021-07-16  7:27 ` stsp
@ 2021-07-16 14:41   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2021-07-16 14:41 UTC (permalink / raw)
  To: stsp, linux-kernel, kvm; +Cc: stable

On 16/07/21 09:27, stsp wrote:
>> +    if (kvm_event_needs_reinjection(vcpu))
>> +        return false;
>> +
> 
> kvm_event_needs_reinjection() seems
> to miss exception.pending check.
> Don't we need it too?

Yes, good point.

Paolo


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

end of thread, other threads:[~2021-07-16 14:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14 21:38 [PATCH] KVM: x86: accept userspace interrupt only if no event is injected Paolo Bonzini
2021-07-16  7:27 ` stsp
2021-07-16 14:41   ` 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).