linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lai Jiangshan <jiangshanlai+lkml@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>,
	LKML <linux-kernel@vger.kernel.org>,
	kvm@vger.kernel.org, Filippo Sironi <sironi@amazon.de>,
	David Woodhouse <dwmw@amazon.co.uk>,
	"v4.7+" <stable@vger.kernel.org>,
	Wanpeng Li <wanpengli@tencent.com>
Subject: Re: [PATCH 2/2] KVM: x86: Fix split-irqchip vs interrupt injection window request
Date: Thu, 15 Apr 2021 16:06:26 +0800	[thread overview]
Message-ID: <CAJhGHyAM6e_XW7iTgYZ3CBv_ANUx4cAZh8+Hq7uXyM6OT1Sf8Q@mail.gmail.com> (raw)
In-Reply-To: <5b422691-ffc5-d73a-1bda-f1ee61116756@redhat.com>

On Thu, Apr 15, 2021 at 2:07 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 15/04/21 02:59, Lai Jiangshan wrote:
> > The next call to inject_pending_event() will reach here AT FIRST with
> > vcpu->arch.exception.injected==false and vcpu->arch.exception.pending==false
> >
> >>           ... if (!vcpu->arch.exception.pending) {
> >>                   if (vcpu->arch.nmi_injected) {
> >>                           static_call(kvm_x86_set_nmi)(vcpu);
> >>                           can_inject = false;
> >>                   } else if (vcpu->arch.interrupt.injected) {
> >>                           static_call(kvm_x86_set_irq)(vcpu);
> >>                           can_inject = false;
> >
> > And comes here and vcpu->arch.interrupt.injected is true for there is
> > an interrupt queued by KVM_INTERRUPT for pure user irqchip. It then does
> > the injection of the interrupt without checking the EFLAGS.IF.
>
> Ok, understood now.  Yeah, that could be a problem for userspace irqchip
> so we should switch it to use pending_external_vector instead.  Are you
> going to write the patch or should I?
>

I wish you do it.  I haven't figured out how to write a clean test for
it and confirm it in upstream.  But I will backport your patch and test it.

My fix is changing the behavior back to before 664f8e26b00c7 where
arch.exception.pending=true would prevent ready_for_interrupt_injection
to be non-zero.  So that KVM_INTERRUPT maintains the original behavior
that it can immediately inject IRQ into guests. (Userspace may regret
an unearthly injected IRQ for it has no right to revise the IRQ or cancel
it.)  But your fix will unify the behaviors of all kinds of irqchips.

Thanks
Lai


> Thanks!
>
> Paolo
>
> > My question is that what stops the next call to inject_pending_event()
> > to reach here when KVM_INTERRUPT is called with exepction pending.
>

  reply	other threads:[~2021-04-15  8:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27 11:21 [PATCH 0/2] KVM: x86: cleanup and fix userspace interrupt window Paolo Bonzini
2020-11-27 11:21 ` [PATCH 1/2] KVM: x86: handle !lapic_in_kernel case in kvm_cpu_*_extint Paolo Bonzini
2020-11-27 11:56   ` David Woodhouse
2020-11-27 12:52   ` Filippo Sironi
2020-11-27 11:21 ` [PATCH 2/2] KVM: x86: Fix split-irqchip vs interrupt injection window request Paolo Bonzini
2020-11-27 12:53   ` Filippo Sironi
2021-04-09  7:14   ` Lai Jiangshan
2021-04-12 21:43     ` Sean Christopherson
2021-04-13 11:03       ` Lai Jiangshan
2021-04-13 12:15         ` Paolo Bonzini
2021-04-14  2:28           ` Lai Jiangshan
2021-04-14 16:58             ` Paolo Bonzini
2021-04-15  0:59               ` Lai Jiangshan
2021-04-15  6:07                 ` Paolo Bonzini
2021-04-15  8:06                   ` Lai Jiangshan [this message]
2021-04-13 12:10       ` Paolo Bonzini
2020-11-27 12:49 ` [PATCH 0/2] KVM: x86: cleanup and fix userspace interrupt window David Woodhouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJhGHyAM6e_XW7iTgYZ3CBv_ANUx4cAZh8+Hq7uXyM6OT1Sf8Q@mail.gmail.com \
    --to=jiangshanlai+lkml@gmail.com \
    --cc=dwmw@amazon.co.uk \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=sironi@amazon.de \
    --cc=stable@vger.kernel.org \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).