All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Liu, Rong L" <rong.l.liu@intel.com>
To: "eric.auger@redhat.com" <eric.auger@redhat.com>,
	Dmytro Maluka <dmy@semihalf.com>,
	Micah Morton <mortonm@chromium.org>
Cc: Alex Williamson <alex.williamson@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>, "Christopherson,,
	Sean" <seanjc@google.com>, "Paolo Bonzini" <pbonzini@redhat.com>,
	Tomasz Nowicki <tn@semihalf.com>,
	"Grzegorz Jaszczyk" <jaz@semihalf.com>,
	Dmitry Torokhov <dtor@google.com>
Subject: RE: Add vfio-platform support for ONESHOT irq forwarding?
Date: Mon, 8 Aug 2022 17:34:30 +0000	[thread overview]
Message-ID: <MW3PR11MB4554B529859E87F2717105A8C7639@MW3PR11MB4554.namprd11.prod.outlook.com> (raw)
In-Reply-To: <069a98a2-d4a1-8599-9deb-069115d5d22c@redhat.com>

Hi Eric,

> -----Original Message-----
> From: Eric Auger <eric.auger@redhat.com>
> Sent: Thursday, August 4, 2022 7:39 AM
> To: Liu, Rong L <rong.l.liu@intel.com>; Dmytro Maluka
> <dmy@semihalf.com>; Micah Morton <mortonm@chromium.org>
> Cc: Alex Williamson <alex.williamson@redhat.com>;
> kvm@vger.kernel.org; Christopherson,, Sean <seanjc@google.com>;
> Paolo Bonzini <pbonzini@redhat.com>; Tomasz Nowicki
> <tn@semihalf.com>; Grzegorz Jaszczyk <jaz@semihalf.com>; Dmitry
> Torokhov <dtor@google.com>
> Subject: Re: Add vfio-platform support for ONESHOT irq forwarding?
> 
> H Liu,
> 
> On 7/26/22 00:03, Liu, Rong L wrote:
> > Hi Eric,
> >
> >> -----Original Message-----
> >> From: Dmytro Maluka <dmy@semihalf.com>
> >> Sent: Thursday, July 7, 2022 2:16 AM
> >> To: eric.auger@redhat.com; Micah Morton
> <mortonm@chromium.org>
> >> Cc: Alex Williamson <alex.williamson@redhat.com>;
> >> kvm@vger.kernel.org; Christopherson,, Sean <seanjc@google.com>;
> >> Paolo Bonzini <pbonzini@redhat.com>; Liu, Rong L
> >> <rong.l.liu@intel.com>; Tomasz Nowicki <tn@semihalf.com>;
> Grzegorz
> >> Jaszczyk <jaz@semihalf.com>; Dmitry Torokhov <dtor@google.com>
> >> Subject: Re: Add vfio-platform support for ONESHOT irq forwarding?
> >>
> >> Hi Eric,
> >>
> >> On 7/7/22 10:25 AM, Eric Auger wrote:
> >>>> Again, this doesn't seem to be true. Just as explained in my above
> >>>> reply to Alex, the guest deactivates (EOI) the vIRQ already after the
> >>>> completion of the vIRQ hardirq handler, not the vIRQ thread.
> >>>>
> >>>> So VFIO unmask handler gets called too early, before the interrupt
> >>>> gets serviced and acked in the vIRQ thread.
> >>> Fair enough, on vIRQ hardirq handler the physical IRQ gets unmasked.
> >>> This event occurs on guest EOI, which triggers the resamplefd. But
> what
> >>> is the state of the vIRQ? Isn't it stil masked until the vIRQ thread
> >>> completes, preventing the physical IRQ from being propagated to the
> >> guest?
> >>
> >> Even if vIRQ is still masked by the time when
> >> vfio_automasked_irq_handler() signals the eventfd (which in itself is
> >> not guaranteed, I guess), I believe KVM is buffering this event, so
> >> after the vIRQ is unmasked, this new IRQ will be injected to the guest
> >> anyway.
> >>
> >>>> It seems the obvious fix is to postpone sending irq ack notifications
> >>>> in KVM from EOI to unmask (for oneshot interrupts only). Luckily,
> we
> >>>> don't need to provide KVM with the info that the given interrupt is
> >>>> oneshot. KVM can just find it out from the fact that the interrupt is
> >>>> masked at the time of EOI.
> >>> you mean the vIRQ right?
> >> Right.
> >>
> >>> Before going further and we invest more time in that thread, please
> >>> could you give us additional context info and confidence
> >>> in/understanding of the stakes. This thread is from Jan 2021 and was
> >>> discontinued for a while. vfio-platform currently only is enabled on
> >> ARM
> >>> and maintained for very few devices which properly implement reset
> >>> callbacks and duly use an underlying IOMMU.
> > Do you have more questions about this issue after following info and
> POC from
> > Dmytro?
> > I agree that we tried to extend the vfio infrastructure to x86 and a few
> more
> > devices which may not "traditionally" supported by current vfio
> implementation.
> > However if we view vfio as a general infrastructure to be used for pass-
> thru
> > devices (this is what we intend to do, implementation may vary),
> Oneshot
> > interrupt is not properly handled.
> 
> sorry for the delay, I was out of office and it took me some time to
> catch up.
> 
> Yes the problem and context is clearer now after the last emails. I now
> understand the vEOI (inducing the VFIO pIRQ unmask) is done before the
> device interrupt line is deasserted by the threaded handler and the vIRQ
> unmask is done, causing spurious hits of the same oneshot IRQ.
> 
> Thanks
> 
> Eric

No problem.  Good summary of the problem:-)  And thanks for confirming that
you agree oneshot interrupt handling is an issue in virtualized environment.

Thanks,

Rong
> >
> > From this discussion when oneshot interrupt is first upstreamed:
> > https://lkml.iu.edu/hypermail/linux/kernel/0908.1/02114.html it says:
> "... we
> > need to keep the interrupt line masked until the threaded handler has
> executed.
> > ... The interrupt line is unmasked after the thread handler function has
> been
> > executed." using today's vfio architecture, (physical) interrupt line is
> > unmasked by vfio after EOI introduced vmexit, instead after the
> threaded
> > function has been executed (or in x86 world, when virtual interrupt is
> > unmasked): this totally violates how oneshot irq should be used.   We
> have a few
> > internal discussions and we couldn't find a solution which are both
> correct and
> > efficient.  But at least we can target a "correct" solution first and that
> will
> > help us resolve bugs we have on our products now.
> >
> >> Sure. We are not really using vfio-platform for the devices we are
> >> concerned with, since those are not DMA capable devices, and some
> of
> >> them are not really platform devices but I2C or SPI devices. Instead we
> >> are using (hopefully temporarily) Micah's module for forwarding
> >> arbitrary IRQs [1][2] which mostly reimplements the VFIO irq
> forwarding
> >> mechanism.
> >>
> >> Also with a few simple hacks I managed to use vfio-platform for the
> same
> >> thing (just as a PoC) and confirmed, unsurprisingly, that the problems
> >> with oneshot interrupts are observed with vfio-platform as well.
> >>
> >> [1]
> >>
> https://chromium.googlesource.com/chromiumos/third_party/kernel/+/
> >> refs/heads/chromeos-5.10-manatee/virt/lib/platirqforward.c
> >>
> >> [2]
> >> https://lkml.kernel.org/kvm/CAJ-
> >>
> EccPU8KpU96PM2PtroLjdNVDbvnxwKwWJr2B+RBKuXEr7Vw@mail.gmail
> >> .com/T/
> >>
> >> Thanks,
> >> Dmytro


      reply	other threads:[~2022-08-08 17:34 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-25 15:46 Add vfio-platform support for ONESHOT irq forwarding? Micah Morton
2021-01-25 17:31 ` Auger Eric
2021-01-25 18:32   ` Micah Morton
2021-01-26  8:48     ` Auger Eric
2021-01-26 15:31       ` Micah Morton
2021-01-26 16:05         ` Auger Eric
2021-01-25 20:36 ` Alex Williamson
2021-01-26  8:53   ` Auger Eric
2021-01-26 15:15     ` Micah Morton
2021-01-26 16:19       ` Auger Eric
2021-01-27 15:58         ` Micah Morton
2021-01-29 19:57           ` Micah Morton
2021-01-30 16:38             ` Auger Eric
2022-07-06 15:25               ` Dmytro Maluka
2022-07-06 20:39                 ` Sean Christopherson
2022-07-07  7:38                   ` Dmytro Maluka
2022-07-07 15:00                     ` Sean Christopherson
2022-07-07 17:38                       ` Dmytro Maluka
2022-07-12 16:02                         ` Liu, Rong L
2022-08-04 14:44                           ` Eric Auger
2022-08-08 21:15                             ` Liu, Rong L
2022-07-07  8:25                 ` Eric Auger
2022-07-07  9:15                   ` Dmytro Maluka
2022-07-25 22:03                     ` Liu, Rong L
2022-08-04 14:39                       ` Eric Auger
2022-08-08 17:34                         ` Liu, Rong L [this message]

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=MW3PR11MB4554B529859E87F2717105A8C7639@MW3PR11MB4554.namprd11.prod.outlook.com \
    --to=rong.l.liu@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=dmy@semihalf.com \
    --cc=dtor@google.com \
    --cc=eric.auger@redhat.com \
    --cc=jaz@semihalf.com \
    --cc=kvm@vger.kernel.org \
    --cc=mortonm@chromium.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tn@semihalf.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 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.