KVM: x86: accept userspace interrupt only if no event is injected
Subsystems (4)
Paolo Bonzini
maintainerPATCH v3 1/1 KVM: x86: accept userspace interrupt only if no event is injected
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, DOSEMU 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.
--- arch/x86/kvm/x86.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +11 -2
@@ -4358,8 +4358,17 @@ static int kvm_cpu_accept_dm_intr(struct kvm_vcpu *vcpu)static int kvm_vcpu_ready_for_interrupt_injection (struct kvm_vcpu *vcpu) { -return kvm_arch_interrupt_allowed (vcpu) && -kvm_cpu_accept_dm_intr (vcpu); +/* +* Do not cause an interrupt window exit if an exception +* is pending or an event needs reinjection; userspace +* might want to inject the interrupt manually using KVM_SET_REGS +* or KVM_SET_SREGS. For that to work, we must be at an +* instruction boundary and with no events half-injected. +*/ +return (kvm_arch_interrupt_allowed (vcpu) && +kvm_cpu_accept_dm_intr (vcpu) && + !kvm_event_needs_reinjection (vcpu) && + !vcpu->arch.exception.pending); } static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
Signature · 1 line
2.27.0
Quoted 32 lines · Paolo Bonzini
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_INTERRUPTwhen an injected exception is present. However, DOSEMU is usingrun->ready_for_interrupt_injectionto 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.Reported-by Stas Sergeev <[email protected]>Tested-by Stas Sergeev <[email protected]>Fixes 71cc849b7093 ("KVM: x86: Fix split-irqchip vs interrupt injection window request")Signed-off-by Paolo Bonzini <[email protected]>--- arch/x86/kvm/x86.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)arch/x86/kvm/x86.c +0
-0@@ -4358,8 +4358,17 @@ static int kvm_cpu_accept_dm_intr(struct kvm_vcpu *vcpu)static int kvm_vcpu_ready_for_interrupt_injection (struct kvm_vcpu *vcpu) {
arch/x86/kvm/x86.c static int kvm_cpu_accept_dm_intr(struct kvm_vcpu *vcpu) · line 4368
Quoted 10 lines
arch/x86/kvm/x86.c +8
-2-return kvm_arch_interrupt_allowed (vcpu) && -kvm_cpu_accept_dm_intr (vcpu); +/* +* Do not cause an interrupt window exit if an exception +* is pending or an event needs reinjection; userspace +* might want to inject the interrupt manually using KVM_SET_REGS +* or KVM_SET_SREGS. For that to work, we must be at an +* instruction boundary and with no events half-injected. +*/ + return (kvm_arch_interrupt_allowed(vcpu) &&
Ha, adding a '(' is one way to fix the indentation.
Quoted 9 lines
arch/x86/kvm/x86.c +3
-0+kvm_cpu_accept_dm_intr (vcpu) && + !kvm_event_needs_reinjection (vcpu) && + !vcpu->arch.exception.pending); } static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,Signature · 1 line
2.27.0
28.07.2021 00:09, Paolo Bonzini пишет:
Quoted 15 lines
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_INTERRUPTwhen an injected exception is present. However, DOSEMU is usingrun->ready_for_interrupt_injectionto 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.
Quoted 3 lines
Reported-by Stas Sergeev <[email protected]>Tested-by Stas Sergeev <[email protected]>