All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Peter Xu <peterx@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 v2 4/5] KVM: Kick resamplefd for split kernel irqchip
Date: Mon, 9 Mar 2020 16:33:59 -0600	[thread overview]
Message-ID: <20200309163359.45ac9c3e@w520.home> (raw)
In-Reply-To: <20200309161059.7c1cc49e@w520.home>

On Mon, 9 Mar 2020 16:10:59 -0600
Alex Williamson <alex.williamson@redhat.com> wrote:

> On Fri, 28 Feb 2020 11:15:02 -0500
> Peter Xu <peterx@redhat.com> wrote:
> 
> > This is majorly only for X86 because that's the only one that supports
> > split irqchip for now.
> > 
> > When the irqchip is split, we face a dilemma that KVM irqfd will be
> > enabled, however the slow irqchip is still running in the userspace.
> > It means that the resamplefd in the kernel irqfds won't take any
> > effect and it will miss to ack INTx interrupts on EOIs.
> > 
> > One example is split irqchip with VFIO INTx, which will break if we
> > use the VFIO INTx fast path.
> > 
> > This patch can potentially supports the VFIO fast path again for INTx,
> > that the IRQ delivery will still use the fast path, while we don't
> > need to trap MMIOs in QEMU for the device to emulate the EIOs (see the
> > callers of vfio_eoi() hook).  However the EOI of the INTx will still
> > need to be done from the userspace by caching all the resamplefds in
> > QEMU and kick properly for IOAPIC EOI broadcast.
> > 
> > This is tricky because in this case the userspace ioapic irr &
> > remote-irr will be bypassed.  However such a change will greatly boost
> > performance for assigned devices using INTx irqs (TCP_RR boosts 46%
> > after this patch applied).
> > 
> > When the userspace is responsible for the resamplefd kickup, don't
> > register it on the kvm_irqfd anymore, because on newer kernels (after
> > commit 654f1f13ea56, 5.2+) the KVM_IRQFD will fail if with both split
> > irqchip and resamplefd.  This will make sure that the fast path will
> > work for all supported kernels.
> > 
> > https://patchwork.kernel.org/patch/10738541/#22609933
> > 
> > Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> >  accel/kvm/kvm-all.c    | 85 +++++++++++++++++++++++++++++++++++++++++-
> >  accel/kvm/trace-events |  1 +
> >  hw/intc/ioapic.c       | 23 +++++++++++-
> >  include/sysemu/kvm.h   |  7 ++++
> >  4 files changed, 112 insertions(+), 4 deletions(-)
> > 
> > diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> > index d49b74512a..89771ea114 100644
> > --- a/accel/kvm/kvm-all.c
> > +++ b/accel/kvm/kvm-all.c
> > @@ -159,9 +159,65 @@ static const KVMCapabilityInfo kvm_required_capabilites[] = {
> >  static NotifierList kvm_irqchip_change_notifiers =
> >      NOTIFIER_LIST_INITIALIZER(kvm_irqchip_change_notifiers);
> >  
> > +struct KVMResampleFd {
> > +    int gsi;
> > +    EventNotifier *resample_event;
> > +    QLIST_ENTRY(KVMResampleFd) node;
> > +};
> > +typedef struct KVMResampleFd KVMResampleFd;
> > +
> > +/*
> > + * Only used with split irqchip where we need to do the resample fd
> > + * kick for the kernel from userspace.
> > + */
> > +static QLIST_HEAD(, KVMResampleFd) kvm_resample_fd_list =
> > +    QLIST_HEAD_INITIALIZER(kvm_resample_fd_list);
> > +
> >  #define kvm_slots_lock(kml)      qemu_mutex_lock(&(kml)->slots_lock)
> >  #define kvm_slots_unlock(kml)    qemu_mutex_unlock(&(kml)->slots_lock)
> >  
> > +static inline void kvm_resample_fd_remove(int gsi)
> > +{
> > +    KVMResampleFd *rfd;
> > +
> > +    QLIST_FOREACH(rfd, &kvm_resample_fd_list, node) {
> > +        if (rfd->gsi == gsi) {
> > +            QLIST_REMOVE(rfd, node);
> > +            g_free(rfd);
> > +            break;
> > +        }
> > +    }
> > +}
> > +
> > +static inline void kvm_resample_fd_insert(int gsi, EventNotifier *event)
> > +{
> > +    KVMResampleFd *rfd = g_new0(KVMResampleFd, 1);
> > +
> > +    rfd->gsi = gsi;
> > +    rfd->resample_event = event;
> > +
> > +    QLIST_INSERT_HEAD(&kvm_resample_fd_list, rfd, node);
> > +}
> > +
> > +bool kvm_resample_fd_notify(int gsi)
> > +{
> > +    KVMResampleFd *rfd;
> > +
> > +    if (!kvm_irqchip_is_split()) {
> > +        return false;
> > +    }
> > +
> > +    QLIST_FOREACH(rfd, &kvm_resample_fd_list, node) {
> > +        if (rfd->gsi == gsi) {
> > +            event_notifier_set(rfd->resample_event);
> > +            trace_kvm_resample_fd_notify(gsi);
> > +            return true;
> > +        }
> > +    }
> > +
> > +    return false;
> > +}
> > +
> >  int kvm_get_max_memslots(void)
> >  {
> >      KVMState *s = KVM_STATE(current_accel());  
> [snip]  
> > diff --git a/hw/intc/ioapic.c b/hw/intc/ioapic.c
> > index 15747fe2c2..13921b333d 100644
> > --- a/hw/intc/ioapic.c
> > +++ b/hw/intc/ioapic.c
> > @@ -236,8 +236,27 @@ 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), then we don't need to clear
> > +             * the remote-IRR and check irr again because they'll
> > +             * always be zeros.
> > +             */
> > +            if (kvm_resample_fd_notify(n)) {
> > +                continue;
> > +            }  
> 
> It seems the problem I reported is here.  In my configuration virtio-blk
> and an assigned e1000e share an interrupt.  virtio-blk is initializing
> and apparently triggers an interrupt.  The vfio-pci device is
> configured for INTx though not active yet, but kvm_resample_fd_notify()
> kicks the fd here, so we continue.  If I remove the continue here both
> devices seem to work, but I don't claim to understand the condition
> we're trying to continue for here yet.  This series needs more testing
> with shared interrupts.  Thanks,

I'm also curious how this ended up between testing whether the vector
is masked and testing that it's level triggered.  We shouldn't have any
edge triggered resamplers.  I find however that if I move the resampler
notify to after the remote IRR test, my NIC gets starved of interrupts.
So empirically, it seems kvm_resample_fd_notify() should be a void
function called unconditionally between the original mask+level check
removed above and the IRR check below.  Thanks,

Alex



  reply	other threads:[~2020-03-09 22:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-28 16:14 [PATCH v2 0/5] vfio/pci: Fix up breakage against split irqchip and INTx Peter Xu
2020-02-28 16:14 ` [PATCH v2 1/5] vfio/pci: Disable INTx fast path if using split irqchip Peter Xu
2020-02-28 16:15 ` [PATCH v2 2/5] vfio/pci: Use kvm_irqchip_add_irqfd_notifier_gsi() for irqfds Peter Xu
2020-02-28 16:15 ` [PATCH v2 3/5] KVM: Pass EventNotifier into kvm_irqchip_assign_irqfd Peter Xu
2020-02-28 16:15 ` [PATCH v2 4/5] KVM: Kick resamplefd for split kernel irqchip Peter Xu
2020-03-02 15:07   ` Auger Eric
2020-03-05 23:58   ` Alex Williamson
2020-03-06  0:43     ` Peter Xu
2020-03-09 21:04       ` Alex Williamson
2020-03-09 22:10   ` Alex Williamson
2020-03-09 22:33     ` Alex Williamson [this message]
2020-03-10  0:38       ` Peter Xu
2020-03-10  1:54         ` Alex Williamson
2020-03-09 23:28     ` Peter Xu
2020-02-28 16:15 ` [PATCH v2 5/5] Revert "vfio/pci: Disable INTx fast path if using split irqchip" Peter Xu
2020-03-02 15:10   ` Auger Eric
2020-03-02 15:09 ` [PATCH v2 0/5] vfio/pci: Fix up breakage against split irqchip and INTx Auger Eric

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=20200309163359.45ac9c3e@w520.home \
    --to=alex.williamson@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.