From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>, Wei Liu <wl@xen.org>,
<xen-devel@lists.xenproject.org>
Subject: Re: [PATCH v4 05/12] x86/hvm: allowing registering EOI callbacks for GSIs
Date: Tue, 4 May 2021 12:27:08 +0200 [thread overview]
Message-ID: <YJEhfO0gSxFJQc8u@Air-de-Roger> (raw)
In-Reply-To: <19b0b30d-2fd6-4cc3-fd7a-4f4a3ce735f7@suse.com>
On Mon, May 03, 2021 at 05:50:39PM +0200, Jan Beulich wrote:
> On 20.04.2021 16:07, Roger Pau Monne wrote:
> > Such callbacks will be executed once a EOI is performed by the guest,
> > regardless of whether the interrupts are injected from the vIO-APIC or
> > the vPIC, as ISA IRQs are translated to GSIs and then the
> > corresponding callback is executed at EOI.
> >
> > The vIO-APIC infrastructure for handling EOIs is build on top of the
> > existing vlapic EOI callback functionality, while the vPIC one is
> > handled when writing to the vPIC EOI register.
> >
> > Note that such callbacks need to be registered and de-registered, and
> > that a single GSI can have multiple callbacks associated. That's
> > because GSIs can be level triggered and shared, as that's the case
> > with legacy PCI interrupts shared between several devices.
> >
> > Strictly speaking this is a non-functional change, since there are no
> > users of this new interface introduced by this change.
> >
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
>
> In principle, as everything looks functionally correct to me,
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
>
> Nevertheless, besides a few remarks further down, I have to admit I'm
> concerned of the direct-to-indirect calls conversion (not just here,
> but also covering earlier patches), which (considering we're talking
> of EOI) I expect may occur quite frequently for at least some guests.
I would expect the vmexit cost for each EOI would shadow any gain
between using direct vs indirect calls.
> There aren't that many different callback functions which get
> registered, are there? Hence I wonder whether enumerating them and
> picking the right one via, say, an enum wouldn't be more efficient
> and still allow elimination of (in the case here) unconditional calls
> to hvm_dpci_eoi() for every EOI.
So for the vlapic (vector) callbacks we have the current consumers:
- MSI passthrough.
- vPT.
- IO-APIC.
For GSI callbacks we have:
- GSI passthrough.
- vPT.
I could see about implementing this.
This is also kind of blocked on the RTC stuff, since vPT cannot be
migrated to this new model unless we remove strict_mode or changfe the
logic here to allow GSI callbacks to de-register themselves.
>
> > --- a/xen/arch/x86/hvm/irq.c
> > +++ b/xen/arch/x86/hvm/irq.c
> > @@ -595,6 +595,81 @@ int hvm_local_events_need_delivery(struct vcpu *v)
> > return !hvm_interrupt_blocked(v, intack);
> > }
> >
> > +int hvm_gsi_register_callback(struct domain *d, unsigned int gsi,
> > + struct hvm_gsi_eoi_callback *cb)
> > +{
> > + struct hvm_irq *hvm_irq = hvm_domain_irq(d);
> > +
> > + if ( gsi >= hvm_irq->nr_gsis )
> > + {
> > + ASSERT_UNREACHABLE();
> > + return -EINVAL;
> > + }
> > +
> > + write_lock(&hvm_irq->gsi_callbacks_lock);
> > + list_add(&cb->list, &hvm_irq->gsi_callbacks[gsi]);
> > + write_unlock(&hvm_irq->gsi_callbacks_lock);
> > +
> > + return 0;
> > +}
> > +
> > +int hvm_gsi_unregister_callback(struct domain *d, unsigned int gsi,
> > + struct hvm_gsi_eoi_callback *cb)
> > +{
> > + struct hvm_irq *hvm_irq = hvm_domain_irq(d);
> > + const struct list_head *tmp;
> > + bool found = false;
> > +
> > + if ( gsi >= hvm_irq->nr_gsis )
> > + {
> > + ASSERT_UNREACHABLE();
> > + return -EINVAL;
> > + }
> > +
> > + write_lock(&hvm_irq->gsi_callbacks_lock);
> > + list_for_each ( tmp, &hvm_irq->gsi_callbacks[gsi] )
> > + if ( tmp == &cb->list )
> > + {
> > + list_del(&cb->list);
>
> Minor remark: Would passing "tmp" here lead to better generated
> code?
Maybe? I don't mind doing so.
> > @@ -419,13 +421,25 @@ static void eoi_callback(struct vcpu *v, unsigned int vector, void *data)
> > if ( is_iommu_enabled(d) )
> > {
> > spin_unlock(&d->arch.hvm.irq_lock);
> > - hvm_dpci_eoi(d, vioapic->base_gsi + pin);
> > + hvm_dpci_eoi(d, gsi);
> > spin_lock(&d->arch.hvm.irq_lock);
> > }
> >
> > + /*
> > + * Callbacks don't expect to be executed with any lock held, so
> > + * drop the lock that protects the vIO-APIC fields from changing.
> > + *
> > + * Note that the redirection entry itself cannot go away, so upon
> > + * retaking the lock we only need to avoid making assumptions on
> > + * redirection entry field values (ie: recheck the IRR field).
> > + */
> > + spin_unlock(&d->arch.hvm.irq_lock);
> > + hvm_gsi_execute_callbacks(d, gsi);
> > + spin_lock(&d->arch.hvm.irq_lock);
>
> While this may be transient in the series, as said before I'm not
> happy about this double unlock/relock sequence. I didn't really
> understand what would be wrong with
>
> spin_unlock(&d->arch.hvm.irq_lock);
> if ( is_iommu_enabled(d) )
> hvm_dpci_eoi(d, gsi);
> hvm_gsi_execute_callbacks(d, gsi);
> spin_lock(&d->arch.hvm.irq_lock);
>
> This in particular wouldn't grow but even shrink the later patch
> dropping the call to hvm_dpci_eoi().
Sure.
> > --- a/xen/arch/x86/hvm/vpic.c
> > +++ b/xen/arch/x86/hvm/vpic.c
> > @@ -235,6 +235,8 @@ static void vpic_ioport_write(
> > unsigned int pin = __scanbit(pending, 8);
> >
> > ASSERT(pin < 8);
> > + hvm_gsi_execute_callbacks(current->domain,
> > + hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin));
> > hvm_dpci_eoi(current->domain,
> > hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin));
> > __clear_bit(pin, &pending);
> > @@ -285,6 +287,8 @@ static void vpic_ioport_write(
> > /* Release lock and EOI the physical interrupt (if any). */
> > vpic_update_int_output(vpic);
> > vpic_unlock(vpic);
> > + hvm_gsi_execute_callbacks(current->domain,
> > + hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin));
> > hvm_dpci_eoi(current->domain,
> > hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin));
> > return; /* bail immediately */
>
> Another presumably minor remark: In the IO-APIC case you insert after
> the call to hvm_dpci_eoi(). I wonder if consistency wouldn't help
> avoid questions of archeologists in a couple of years time.
Hm, sorry, I remember trying to place them in the same order, but
likely messed up the order during some rebase.
Thanks, Roger.
next prev parent reply other threads:[~2021-05-04 10:27 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-20 14:07 [PATCH v4 00/12] x86/intr: introduce EOI callbacks and fix vPT Roger Pau Monne
2021-04-20 14:07 ` [PATCH v4 01/12] x86/rtc: drop code related to strict mode Roger Pau Monne
2021-04-29 14:53 ` Jan Beulich
2021-05-03 9:28 ` Roger Pau Monné
2021-05-03 12:26 ` Jan Beulich
2021-05-03 14:47 ` Roger Pau Monné
2021-05-03 14:58 ` Jan Beulich
2021-05-03 15:28 ` Roger Pau Monné
2021-05-03 15:59 ` Jan Beulich
2021-04-20 14:07 ` [PATCH v4 02/12] x86/vlapic: introduce an EOI callback mechanism Roger Pau Monne
2021-04-29 15:48 ` Jan Beulich
2021-04-20 14:07 ` [PATCH v4 03/12] x86/vmsi: use the newly introduced EOI callbacks Roger Pau Monne
2021-04-20 14:07 ` [PATCH v4 04/12] x86/vioapic: switch to use the EOI callback mechanism Roger Pau Monne
2021-04-29 15:51 ` Jan Beulich
2021-04-20 14:07 ` [PATCH v4 05/12] x86/hvm: allowing registering EOI callbacks for GSIs Roger Pau Monne
2021-05-03 15:50 ` Jan Beulich
2021-05-04 10:27 ` Roger Pau Monné [this message]
2021-04-20 14:07 ` [PATCH v4 06/12] x86/dpci: move code Roger Pau Monne
2021-04-20 14:07 ` [PATCH v4 07/12] x86/dpci: switch to use a GSI EOI callback Roger Pau Monne
2021-05-04 9:28 ` Jan Beulich
2021-04-20 14:07 ` [PATCH v4 08/12] x86/vpt: switch interrupt injection model Roger Pau Monne
2021-05-04 11:00 ` Jan Beulich
2021-04-20 14:07 ` [PATCH v4 09/12] x86/irq: remove unused parameter from hvm_isa_irq_assert Roger Pau Monne
2021-05-04 11:42 ` Jan Beulich
2021-04-20 14:07 ` [PATCH v4 10/12] x86/irq: drop return value from hvm_ioapic_assert Roger Pau Monne
2021-05-04 11:42 ` Jan Beulich
2021-04-20 14:07 ` [PATCH v4 11/12] x86/vpt: remove vPT timers per-vCPU lists Roger Pau Monne
2021-04-20 14:07 ` [PATCH v4 12/12] x86/vpt: introduce a per-vPT lock Roger Pau Monne
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=YJEhfO0gSxFJQc8u@Air-de-Roger \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.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).