From: christoffer.dall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] ARM: KVM: add irqfd and irq routing support
Date: Fri, 6 Jun 2014 14:36:06 +0200 [thread overview]
Message-ID: <20140606123606.GC22341@lvm> (raw)
In-Reply-To: <20140605103736.GB3994@lvm>
On Thu, Jun 05, 2014 at 12:37:36PM +0200, Christoffer Dall wrote:
> On Mon, Jun 02, 2014 at 04:42:36PM +0200, Eric Auger wrote:
> > On 06/02/2014 03:54 PM, Marc Zyngier wrote:
> > > Hi Eric,
> > >
> > > On Mon, Jun 02 2014 at 8:29:56 am BST, Eric Auger <eric.auger@linaro.org> wrote:
>
> [...]
>
> > >> @@ -408,11 +411,27 @@ static bool handle_mmio_clear_pending_reg(struct kvm_vcpu *vcpu,
> > >> struct kvm_exit_mmio *mmio,
> > >> phys_addr_t offset)
> > >> {
> > >> - u32 *reg = vgic_bitmap_get_reg(&vcpu->kvm->arch.vgic.irq_state,
> > >> + struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
> > >> + unsigned int i;
> > >> + bool is_assigned_irq;
> > >> + DECLARE_BITMAP(old, VGIC_NR_SHARED_IRQS);
> > >> + DECLARE_BITMAP(diff, VGIC_NR_SHARED_IRQS);
> > >> + unsigned long *pending =
> > >> + vgic_bitmap_get_shared_map(&dist->irq_state);
> > >> + u32 *reg;
> > >> + bitmap_copy(old, pending, VGIC_NR_SHARED_IRQS);
> > >
> > > That's really heavy. You could find out which interrupts are potentially
> > > affected (only 32 of them) and just handle those. Also, you do the copy
> > > on both the read and write paths. Not great.
> > for the copy you are fully right. I will add the check. Then to detect
> > which pending IRQ is cleared I need to further study how I can optimize.
> > Why do you say 32? Can't any SPI be assigned to a guest?
> > >
> > >> + reg = vgic_bitmap_get_reg(&vcpu->kvm->arch.vgic.irq_state,
> > >> vcpu->vcpu_id, offset);
> > >> vgic_reg_access(mmio, reg, offset,
> > >> ACCESS_READ_VALUE | ACCESS_WRITE_CLEARBIT);
> > >> if (mmio->is_write) {
> > >> + pending = vgic_bitmap_get_shared_map(&dist->irq_state);
> > >> + bitmap_xor(diff, old, pending, VGIC_NR_SHARED_IRQS);
> > >> + for_each_set_bit(i, diff, VGIC_NR_SHARED_IRQS) {
> > >> + is_assigned_irq = kvm_irq_has_notifier(vcpu->kvm, 0, i);
> > >> + if (is_assigned_irq)
> > >> + kvm_notify_acked_irq(vcpu->kvm, 0, i);
> > >
> > > Are you saying that a masked interrupt should be treated the same as an
> > > EOI-ed interrupt? That seems wrong from my PoV.
> > Actually all that stuff comes from a bug I encountered with
> > qemu_system_arm and the VFIO platform QEMU device (RFCv3 sent today).
> > The scenario is the following:
> > 1) I launch a 1st qemu_system_arm session with one xgmac bound to the
> > KVM guest with vfio. IRQs are routed through irqfd.
> > 2) I kill that session and launch a 2d one.
> >
> > After the 1st session kill, xgmac ic still running (funny principle of
> > VFIO "meta" driver which is HW device agnostic and do not know how to
> > reset the xgmac). So very early I can see the xgmac sends a main IRQ
> > which is handled by the vfio platform driver. This later masks the IRQ
> > before signaling the eventfd. During guest setup I observe MMIO accesses
> > that clears the xgmac pending IRQ under the hood. So for that IRQ the
> > maintenance IRQ code will never be called, the notifier will not be be
> > acked and thus the IRQ is never unmasked at VFIO driver level. As a
> > result the xgmac driver gets stuck.
> >
> > So currently this is the best fix I have found. VFIO Reset management
> > need to be further studied anyway. THis is planned but I understand it
> > will not straightforward.
>
> It sounds to me like this is being done in the wrong place. ICPENDRn
> and ISPENDRn are used for saving/restoring state, not for
> enabling/disabling IRQs.
>
> Somehow, the VFIO driver must know that the xgmac has an active
> interrupt which is masked. When you setup the IRQ routing for your new
> VM (when you start it the second time) there must be a mechanism to
> probe this state, but you don't inject that into the VM until the VM
> actually enables that IRQ (the guest kernel does request_irq()). This
> should already be handled by the existing vgic code.
>
> Note that what should also happen is that the guest driver should now
> reset the xgmac so that it doesn't inject IRQs, which should let VFIO
> know to lower the line to the vgic too, and then only later it becomes
> re-enabeld. But that should be handled generically, iow. we shouldn't
> write code specifically to address only such a flow of events.
>
Talked to Eric about this again, and I think the problem is that we're
not handling ICPENDRn and ISPENDRn properly. It was a pain to deal with
this in the QEMU too, but basically we're not honering the semantics of
the registers, because the final pending state needs to be or'ed with
the external input signal.
I'll have a look at fixing this.
-Christoffer
next prev parent reply other threads:[~2014-06-06 12:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-02 7:29 [PATCH v2] ARM: KVM: add irqfd and irq routing support Eric Auger
2014-06-02 13:54 ` Marc Zyngier
2014-06-02 14:42 ` Eric Auger
2014-06-05 10:37 ` Christoffer Dall
2014-06-06 12:36 ` Christoffer Dall [this message]
2014-06-06 12:16 ` Christoffer Dall
2014-06-17 11:42 ` Eric Auger
2014-06-05 10:28 ` Christoffer Dall
2014-06-05 13:15 ` Eric Auger
2014-06-05 14:39 ` Christoffer Dall
2014-06-05 15:58 ` Eric Auger
2014-06-05 16:08 ` Christoffer Dall
2014-06-06 7:41 ` Eric Auger
2014-06-19 14:13 ` Will Deacon
2014-06-19 14:40 ` Eric Auger
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=20140606123606.GC22341@lvm \
--to=christoffer.dall@linaro.org \
--cc=linux-arm-kernel@lists.infradead.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).