From: Alex Williamson <alex.williamson@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
jan.kiszka@siemens.com, mst@redhat.com
Subject: Re: [PATCH 3/4] kvm: Extend irqfd to support level interrupts
Date: Mon, 25 Jun 2012 13:29:50 -0600 [thread overview]
Message-ID: <1340652590.1207.59.camel@bling.home> (raw)
In-Reply-To: <1340551118.14120.66.camel@bling.home>
On Sun, 2012-06-24 at 09:18 -0600, Alex Williamson wrote:
> On Sun, 2012-06-24 at 13:29 +0300, Avi Kivity wrote:
> > On 06/23/2012 01:16 AM, Alex Williamson wrote:
> > > KVM_IRQFD currently only supports edge triggered interrupts,
> > > asserting then immediately deasserting an interrupt. There are a
> > > couple ways we can emulate level triggered interrupts using
> > > discrete events depending on the usage model we expect from drivers.
> > > This patch implements a level emulation model useful for external
> > > assigned device drivers, like VFIO. The irqfd is used to assert
> > > the interrupt. When the guest issues an EOI for the interrupt, the
> > > level is automatically deasserted and the irqfd user is notified via
> > > an eventfd. This is therefore the LEVEL_EOI extension to KVM_IRQFD.
> > > To do this, we need to allocate a new irq source ID for the interrupt
> > > so we don't get interference from userspace.
> > >
> > >
> > > +With KVM_CAP_IRQFD_LEVEL_EOI KVM_IRQFD is able to support a level
> > > +triggered interrupt model where the irqchip pin (kvm_irqfd.gsi) is
> > > +asserted from the kvm_irqfd.fd eventfd and remain asserted until the
> > > +guest issues an EOI for the irqchip pin. The level interrupt is
> > > +then de-asserted and the caller is notified via the eventfd specified
> > > +by kvm_irqfd.fd2. Note that users of this interface are responsible
> > > +for re-asserting the interrupt if their device still requires service
> > > +after receiving the EOI notification. Additionally, users must not
> > > +re-assert an interrupt until after receiving an EOI.
> >
> > What happens if this is violated?
>
> Hmm, perhaps nothing. The only race I see is re-asserting in the gap
> between de-asserting the guest and sending the EOI. At worst that would
> cause a spurious interrupt, so probably no big deal.
>
> > > When available,
> > > +this feature is enabled using the KVM_IRQFD_FLAG_LEVEL_EOI flag.
> > > +De-assigning an irqfd setup using this flag should include both
> > > +KVM_IRQFD_FLAG_DEASSIGN and KVM_IRQFD_FLAG_LEVEL_EOI and will be
> > > +matched using kvm_irqfd.fd, kvm_irqfd.gsi, and kvm_irqfd.fd2.
> > > +De-assigning automatically de-asserts the interrupt line setup through
> > > +this interface.
> > >
> > > @@ -203,8 +232,8 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
> > > struct kvm_irq_routing_table *irq_rt;
> > > struct _irqfd *irqfd, *tmp;
> > > struct file *file = NULL;
> > > - struct eventfd_ctx *eventfd = NULL;
> > > - int ret;
> > > + struct eventfd_ctx *eventfd = NULL, *eoi_eventfd = NULL;
> > > + int ret, irq_source_id = -1;
> > > unsigned int events;
> > >
> > > irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL);
> > > @@ -214,7 +243,30 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
> > > irqfd->kvm = kvm;
> > > irqfd->gsi = args->gsi;
> > > INIT_LIST_HEAD(&irqfd->list);
> > > - INIT_WORK(&irqfd->inject, irqfd_inject);
> > > +
> > > + if (args->flags & KVM_IRQFD_FLAG_LEVEL_EOI) {
> > > + irq_source_id = kvm_request_irq_source_id(kvm);
> > > + if (irq_source_id < 0) {
> > > + ret = irq_source_id;
> > > + goto fail;
> >
> > 'file' is NULL at this point, and fput() doesn't test for NULL.
>
> Good catch. I was looking for an excuse to move the existing code to
> eventfd_ctx_fdget() and avoid the 2 step process it uses now.
Well, we need file later, so a !NULL test will fix it.
...
>
> > Xen had/has a hack for doing this in a different way, based on ioapic
> > polarity. When the host takes an interrupt, they reverse the polarity
> > on that ioapic pin, so they get interrupts on both assertion and
> > deassertion. This is more general and more correct, but waaaaaaaaaaay
> > more intrusive and won't play well with shared host interrupts. But
> > let's at least consider it.
>
> Thanks, I'll look for that code.
I can't find the code for it, pointers welcome. I have a hard time
thinking this is practical for legacy interrupts though. It sounds more
like an x86 party trick that minimally breaks shared host interrupts,
but more likely is intrusive (hey, why's that PCI driver asking for an
active high interrupt, obviously wrong, BUG) and probably breaks on most
non-x86 platforms. I just can't imagine the cost/benefit works out for
it with legacy interrupts. Thanks,
Alex
next prev parent reply other threads:[~2012-06-25 19:29 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-22 22:15 [PATCH 0/4] kvm: level triggered irqfd support Alex Williamson
2012-06-22 22:15 ` [PATCH 1/4] kvm: Pass kvm_irqfd to functions Alex Williamson
2012-06-22 22:15 ` [PATCH 2/4] kvm: Add missing KVM_IRQFD API documentation Alex Williamson
2012-06-24 8:34 ` Michael S. Tsirkin
2012-06-24 14:56 ` Alex Williamson
2012-06-24 15:46 ` Michael S. Tsirkin
2012-06-22 22:16 ` [PATCH 3/4] kvm: Extend irqfd to support level interrupts Alex Williamson
2012-06-24 8:28 ` Michael S. Tsirkin
2012-06-24 14:50 ` Alex Williamson
2012-06-24 15:45 ` Michael S. Tsirkin
2012-06-24 21:52 ` Alex Williamson
2012-06-24 10:29 ` Avi Kivity
2012-06-24 15:18 ` Alex Williamson
2012-06-24 15:49 ` Michael S. Tsirkin
2012-06-24 21:59 ` Alex Williamson
2012-06-24 23:02 ` Michael S. Tsirkin
2012-06-25 16:17 ` Alex Williamson
2012-06-25 20:13 ` Michael S. Tsirkin
2012-06-25 19:29 ` Alex Williamson [this message]
2012-06-22 22:16 ` [PATCH 4/4][RFC] kvm: eoi_eventfd Alex Williamson
2012-06-24 8:24 ` Michael S. Tsirkin
2012-06-24 14:47 ` Alex Williamson
2012-06-24 15:40 ` Michael S. Tsirkin
2012-06-24 21:50 ` Alex Williamson
2012-06-24 22:35 ` Michael S. Tsirkin
2012-06-25 16:09 ` Alex Williamson
2012-06-25 20:12 ` Michael S. Tsirkin
2012-06-24 12:56 ` Avi Kivity
2012-06-24 15:02 ` Alex Williamson
2012-06-28 16:27 ` Avi Kivity
2012-06-28 17:21 ` Alex Williamson
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=1340652590.1207.59.camel@bling.home \
--to=alex.williamson@redhat.com \
--cc=avi@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.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