From: Peter Xu <peterx@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Cornelia Huck <cohuck@redhat.com>,
qemu-devel@nongnu.org, Eric Auger <eric.auger@redhat.com>
Subject: Re: [PATCH v3 4/5] KVM: Kick resamplefd for split kernel irqchip
Date: Tue, 17 Mar 2020 18:41:38 -0400 [thread overview]
Message-ID: <20200317224138.GE233068@xz-x1> (raw)
In-Reply-To: <20200317161200.0c41fe60@w520.home>
On Tue, Mar 17, 2020 at 04:12:00PM -0600, Alex Williamson wrote:
> On Tue, 17 Mar 2020 17:41:08 -0400
> Peter Xu <peterx@redhat.com> wrote:
>
> > On Tue, Mar 17, 2020 at 03:06:46PM -0600, Alex Williamson wrote:
> >
> > [...]
> >
> > > > diff --git a/hw/intc/ioapic.c b/hw/intc/ioapic.c
> > > > index 15747fe2c2..81a17cc2b8 100644
> > > > --- a/hw/intc/ioapic.c
> > > > +++ b/hw/intc/ioapic.c
> > > > @@ -236,8 +236,29 @@ void ioapic_eoi_broadcast(int vector)
> > > > for (n = 0; n < IOAPIC_NUM_PINS; n++) {
> > > > entry = s->ioredtbl[n];
> > > >
> > > > - if ((entry & IOAPIC_VECTOR_MASK) != vector ||
> > > > - ((entry >> IOAPIC_LVT_TRIGGER_MODE_SHIFT) & 1) != IOAPIC_TRIGGER_LEVEL) {
> > > > + if ((entry & IOAPIC_VECTOR_MASK) != vector) {
> > > > + continue;
> > > > + }
> > > > +
> > > > + /*
> > > > + * When IOAPIC is in the userspace while APIC is still in
> > > > + * the kernel (i.e., split irqchip), we have a trick to
> > > > + * kick the resamplefd logic for registered irqfds from
> > > > + * userspace to deactivate the IRQ. When that happens, it
> > > > + * means the irq bypassed userspace IOAPIC (so the irr and
> > > > + * remote-irr of the table entry should be bypassed too
> > > > + * even if interrupt come). Still kick the resamplefds if
> > > > + * they're bound to the IRQ, to make sure to EOI the
> > > > + * interrupt for the hardware correctly.
> > > > + *
> > > > + * Note: We still need to go through the irr & remote-irr
> > > > + * operations below because we don't know whether there're
> > > > + * emulated devices that are using/sharing the same IRQ.
> > > > + */
> > > > + kvm_resample_fd_notify(n);
> > > > +
> > > > + if (((entry >> IOAPIC_LVT_TRIGGER_MODE_SHIFT) & 1) !=
> > > > + IOAPIC_TRIGGER_LEVEL) {
> > > > continue;
> > > > }
> > > >
> > >
> > > What's the logic for sending resampler notifies before testing if the
> > > ioapic entry is in level triggered mode? vfio won't use this for
> > > anything other than level triggered. Inserting it between these checks
> > > confused me and in my testing wasn't necessary. Thanks,
> >
> > I put it there to match the kernel implementation, and IIUC Paolo
> > agreed with that too:
> >
> > https://patchwork.kernel.org/patch/11407441/#23190969
> >
> > Since we've discussed a few times here, I think I can talk a bit more
> > on how I understand this in case I was wrong...
> >
> > Even if we have the fact that all the existing devices that use this
> > code should be using level-triggered IRQs, however... *If* there comes
> > an edge-triggered INTx device and we assign it using vfio-pci, vfio
> > should also mask the IRQ after it generates (according to
> > vfio_intx_handler), is that right? Then we still need to kick the
> > resamplefd for that does-not-exist device too to make sure it'll work?
>
> "edge-triggered INTx" is not a thing that exists. The PCI spec defines
> interrupt pins as:
>
> 2.2.6. Interrupt Pins (Optional)
>
> Interrupts on PCI are optional and defined as "level sensitive,"
> asserted low (negative true), using open drain output drivers.
Ah OK! I didn't notice it's a spec-wise answer...
>
> Masking of interrupts while they're in-service is not done for edge
> triggered interrupts, we assume that being a discrete interrupt is a
> sufficient rate limiter versus a level triggered interrupt, which is
> continuous and can saturate the host.
>
> If it exists before the level check only to match the kernel, maybe a
> comment or todo item to check whether it's the optimal approach for
> both cases should be in order. I can't think of any reason why we'd
> need it for the sake of edge triggered vfio interrupts in either place.
I guess the KVM implementation of that is still required for the
kernel PIT implementation as Paolo mentioned. Since this seems to be
confusing and the userspace does not have a real use case for that,
let me repost this patch only so the userspace resamplefd only reacts
to level triggered interrupts.
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2020-03-17 22:42 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-17 19:50 [PATCH v3 0/5] vfio/pci: Fix up breakage against split irqchip and INTx Peter Xu
2020-03-17 19:50 ` [PATCH v3 1/5] vfio/pci: Disable INTx fast path if using split irqchip Peter Xu
2020-03-17 22:57 ` Alex Williamson
2020-03-17 19:50 ` [PATCH v3 2/5] vfio/pci: Use kvm_irqchip_add_irqfd_notifier_gsi() for irqfds Peter Xu
2020-03-17 22:57 ` Alex Williamson
2020-03-17 19:50 ` [PATCH v3 3/5] KVM: Pass EventNotifier into kvm_irqchip_assign_irqfd Peter Xu
2020-03-17 22:58 ` Alex Williamson
2020-03-17 19:50 ` [PATCH v3 4/5] KVM: Kick resamplefd for split kernel irqchip Peter Xu
2020-03-17 21:06 ` Alex Williamson
2020-03-17 21:41 ` Peter Xu
2020-03-17 22:12 ` Alex Williamson
2020-03-17 22:41 ` Peter Xu [this message]
2020-03-17 22:49 ` [PATCH v3.1 " Peter Xu
2020-03-17 22:58 ` Alex Williamson
2020-03-17 19:50 ` [PATCH v3 5/5] Revert "vfio/pci: Disable INTx fast path if using split irqchip" Peter Xu
2020-03-17 22:58 ` Alex Williamson
2020-03-18 2:56 ` [PATCH v3 0/5] vfio/pci: Fix up breakage against split irqchip and INTx no-reply
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=20200317224138.GE233068@xz-x1 \
--to=peterx@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=cohuck@redhat.com \
--cc=eric.auger@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).