All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dong, Eddie" <eddie.dong@intel.com>
To: Dmytro Maluka <dmy@semihalf.com>, "Christopherson,,
	Sean" <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Eric Auger <eric.auger@redhat.com>,
	Alex Williamson <alex.williamson@redhat.com>,
	"Liu, Rong L" <rong.l.liu@intel.com>,
	Zhenyu Wang <zhenyuw@linux.intel.com>,
	"Tomasz Nowicki" <tn@semihalf.com>,
	Grzegorz Jaszczyk <jaz@semihalf.com>,
	"upstream@semihalf.com" <upstream@semihalf.com>,
	Dmitry Torokhov <dtor@google.com>, Marc Zyngier <maz@kernel.org>
Subject: RE: [PATCH v2 0/5] KVM: Fix oneshot interrupts forwarding
Date: Wed, 10 Aug 2022 17:53:04 +0000	[thread overview]
Message-ID: <BL0PR11MB30423A9EE500C4081A281D078A659@BL0PR11MB3042.namprd11.prod.outlook.com> (raw)
In-Reply-To: <f4b162a5-1da6-478f-fcab-d79cece32dde@semihalf.com>

> On 8/10/22 7:17 PM, Dong, Eddie wrote:
> >>>
> >>>
> >>>> However, with KVM + vfio (or whatever is listening on the
> >>>> resamplefd) we don't check that the interrupt is still masked in
> >>>> the guest at the moment
> >> of EOI.
> >>>> Resamplefd is notified regardless, so vfio prematurely unmasks the
> >>>> host physical IRQ, thus a new (unwanted) physical interrupt is
> >>>> generated in the host and queued for injection to the guest."
> >>>>
> >>>
> >>> Emulation of level triggered IRQ is a pain point ☹ I read we need to
> >>> emulate the "level" of the IRQ pin (connecting from device to IRQchip, i.e.
> >> ioapic here).
> >>> Technically, the guest can change the polarity of vIOAPIC, which
> >>> will lead to a new  virtual IRQ even w/o host side interrupt.
> >>
> >> Thanks, interesting point. Do you mean that this behavior (a new vIRQ
> >> as a result of polarity change) may already happen with the existing KVM
> code?
> >>
> >> It doesn't seem so to me. AFAICT, KVM completely ignores the vIOAPIC
> >> polarity bit, in particular it doesn't handle change of the polarity by the guest
> (i.e.
> >> doesn't update the virtual IRR register, and so on), so it shouldn't
> >> result in a new interrupt.
> >
> > Correct, KVM doesn't handle polarity now. Probably because unlikely
> > the commercial OSes will change polarity.
> >
> >>
> >> Since commit 100943c54e09 ("kvm: x86: ignore ioapic polarity") there
> >> seems to be an assumption that KVM interpretes the IRQ level value as
> >> active (asserted) vs inactive (deasserted) rather than high vs low, i.e.
> >
> > Asserted/deasserted vs. high/low is same to me, though
> asserted/deasserted hints more for event rather than state.
> >
> >> the polarity doesn't matter to KVM.
> >>
> >> So, since both sides (KVM emulating the IOAPIC, and vfio/whatever
> >> emulating an external interrupt source) seem to operate on a level of
> >> abstraction of "asserted" vs "de-asserted" interrupt state regardless
> >> of the polarity, and that seems not a bug but a feature, it seems
> >> that we don't need to emulate the IRQ level as such. Or am I missing
> something?
> >
> > YES, I know current KVM doesn't handle it.  Whether we should support it is
> another story which I cannot speak for.
> > Paolo and Alex are the right person 😊
> > The reason I mention this is because the complexity to adding a pending
> event vs. supporting a interrupt pin state is same.
> > I am wondering if we need to revisit it or not.  Behavior closing to real
> hardware helps us to avoid potential issues IMO, but I am fine to either choice.
> 
> I guess that would imply revisiting KVM irqfd interface, since its design is based
> rather on events than states, even for level-triggered
> interrupts:

We can read 2 different events:  IRQ fire/no-fire event, and state change event (for consumers to maintain internal assert/deassert state). 
If we switch from the former one to the later one.  Do we need to change the interface?

Probably needs Paolo and Alex to give clear direction, given that ARM64 side seems have similar state concept too.

Thanks Dmytro!

Eddie

> 
> - trigger event (from vfio to KVM) to assert an IRQ
> - resample event (from KVM to vfio) to de-assert an IRQ
> 
> >
> >>
> >> OTOH, I guess this means that the existing KVM's emulation of
> >> level-triggered interrupts is somewhat limited (a guest may
> >> legitimately expect an interrupt fired as a result of polarity
> >> change, and that case is not supported by KVM). But that is rather
> >> out of scope of the oneshot interrupts issue addressed by this patchset.
> >
> > Agree.
> > I didn't know any commercial OSes change polarity either. But I know Xen
> hypervisor uses polarity under certain condition.
> > One day, we may see the issue when running Xen as a L1 hypervisor.  But this
> is not the current worry.
> >
> >
> >>
> >>> "pending" field of kvm_kernel_irqfd_resampler in patch 3 means more
> >>> an
> >> event rather than an interrupt level.
> >
> > I know.  I am fine either.
> >
> > Thanks Eddie
> >
> >>>
> >>>

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

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-05 19:39 [PATCH v2 0/5] KVM: Fix oneshot interrupts forwarding Dmytro Maluka
2022-08-05 19:39 ` [PATCH v2 1/5] KVM: x86: Move irq mask notifiers from x86 to generic KVM Dmytro Maluka
2022-08-09 20:43   ` Eric Auger
2022-08-05 19:39 ` [PATCH v2 2/5] KVM: x86: Add kvm_register_and_fire_irq_mask_notifier() Dmytro Maluka
2022-08-09 20:43   ` Eric Auger
2022-08-09 23:56     ` Dmytro Maluka
2022-08-05 19:39 ` [PATCH v2 3/5] KVM: irqfd: Postpone resamplefd notify for oneshot interrupts Dmytro Maluka
2022-08-09 20:45   ` Eric Auger
2022-08-09 23:57     ` Dmytro Maluka
2022-08-10  8:41     ` Marc Zyngier
2022-08-05 19:39 ` [PATCH v2 4/5] KVM: irqfd: Rename resampler->notifier Dmytro Maluka
2022-08-09 20:46   ` Eric Auger
2022-08-05 19:39 ` [PATCH v2 5/5] KVM: Rename kvm_irq_has_notifier() Dmytro Maluka
2022-08-08 23:26 ` [PATCH v2 0/5] KVM: Fix oneshot interrupts forwarding Dong, Eddie
2022-08-09  7:24   ` Dmytro Maluka
2022-08-09 20:01     ` Dong, Eddie
2022-08-09 23:30       ` Dmytro Maluka
2022-08-10  6:51         ` Marc Zyngier
2022-08-10  8:12           ` Eric Auger
2022-08-10 13:01             ` Marc Zyngier
2022-08-10 17:02               ` Dmytro Maluka
2022-08-11  6:48                 ` Paolo Bonzini
2022-08-11 22:40                   ` Liu, Rong L
2022-08-13 14:04                     ` Dmytro Maluka
2022-08-11 12:21                 ` Marc Zyngier
2022-08-11 13:54                   ` Dmytro Maluka
2022-08-13 12:59                     ` Dmytro Maluka
2022-08-10 17:06           ` Dmytro Maluka
2022-08-11 12:35             ` Marc Zyngier
2022-08-11 13:04               ` Dmytro Maluka
2022-08-10 17:17         ` Dong, Eddie
2022-08-10 17:34           ` Dmytro Maluka
2022-08-10 17:53             ` Dong, Eddie [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=BL0PR11MB30423A9EE500C4081A281D078A659@BL0PR11MB3042.namprd11.prod.outlook.com \
    --to=eddie.dong@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dmy@semihalf.com \
    --cc=dtor@google.com \
    --cc=eric.auger@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jaz@semihalf.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rong.l.liu@intel.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=tn@semihalf.com \
    --cc=upstream@semihalf.com \
    --cc=x86@kernel.org \
    --cc=zhenyuw@linux.intel.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.