From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
Andrew Cooper <andrew.cooper3@citrix.com>, Wei Liu <wl@xen.org>,
Paul Durrant <paul@xen.org>
Subject: Re: [PATCH] x86/HVM: don't mark evtchn upcall vector as pending when vLAPIC is disabled
Date: Mon, 21 Nov 2022 11:53:56 +0100 [thread overview]
Message-ID: <Y3tYxMSGLDtBLHVc@Air-de-Roger> (raw)
In-Reply-To: <3add150d-ab4d-9147-005e-3f3160ec9667@suse.com>
On Mon, Nov 21, 2022 at 09:33:53AM +0100, Jan Beulich wrote:
> On 18.11.2022 15:26, Roger Pau Monné wrote:
> > On Fri, Nov 18, 2022 at 11:31:28AM +0100, Jan Beulich wrote:
> >> Linux'es relatively new use of HVMOP_set_evtchn_upcall_vector has
> >> exposed a problem with the marking of the respective vector as
> >> pending: For quite some time Linux has been checking whether any stale
> >> ISR or IRR bits would still be set while preparing the LAPIC for use.
> >> This check is now triggering on the upcall vector, as the registration,
> >> at least for APs, happens before the LAPIC is actually enabled.
> >>
> >> In software-disabled state an LAPIC would not accept any interrupt
> >> requests and hence no IRR bit would newly become set while in this
> >> state. As a result it is also wrong for us to mark the upcall vector as
> >> having a pending request when the vLAPIC is in this state.
> >>
> >> To compensate for the "enabled" check added to the assertion logic, add
> >> logic to (conditionally) mark the upcall vector as having a request
> >> pending at the time the LAPIC is being software-enabled by the guest.
> >>
> >> Fixes: 7b5b8ca7dffd ("x86/upcall: inject a spurious event after setting upcall vector")
> >> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> >> ---
> >> Don't one or both of the Viridian uses of vlapic_set_irq() need similar
> >> guarding?
> >>
> >> Is it actually necessary for hvmop_set_evtchn_upcall_vector() and
> >> hvm_set_callback_via() to call hvm_assert_evtchn_irq() when
> >> evtchn_upcall_pending is false?
> >>
> >> --- a/xen/arch/x86/hvm/irq.c
> >> +++ b/xen/arch/x86/hvm/irq.c
> >> @@ -321,9 +321,10 @@ void hvm_assert_evtchn_irq(struct vcpu *
> >>
> >> if ( v->arch.hvm.evtchn_upcall_vector != 0 )
> >> {
> >> - uint8_t vector = v->arch.hvm.evtchn_upcall_vector;
> >> + struct vlapic *vlapic = vcpu_vlapic(v);
> >>
> >> - vlapic_set_irq(vcpu_vlapic(v), vector, 0);
> >> + if ( vlapic_enabled(vlapic) )
> >> + vlapic_set_irq(vlapic, v->arch.hvm.evtchn_upcall_vector, 0);
> >
> > Shouldn't the vlapic_enabled() check itself be in vlapic_set_irq()? We
> > certainly don't want any vectors set until the vlapic is enabled, be
> > it event channel upcalls or any other sources.
>
> In principle yes, and I did consider doing so, but for several callers
> (potentially used frequently) this would be redundant with other
> checking they do already (first and foremost callers using
> vlapic_lowest_prio()). However, looking again I think vioapic_deliver()
> and vmsi_deliver() violate this as well in their dest_Fixed handling.
> (In both cases I'm actually inclined to also remove the odd *_inj_irq()
> helper functions.)
>
> > Maybe best to add an ASSERT in vlapic_set_irq() to be sure the lapic is
> > enabled, as other callers already check this before trying to inject?
>
> Perhaps, yes (once we've fixed paths where the check is presently
> missing).
Another option would be to unconditionally return 0 for IRR and ISR
reads when the LAPIC is disabled, that would avoid having to force the
event channel injection when the LAPIC is enabled, but there could be
more than just the event channel vector queued in that way which would
be against the spec.
> > Also, and not strictly related to your change, isn't this possibly
> > racy, as by the time you evaluate the return of vlapic_enabled() it is
> > already stale, as there's no lock to protect it from changing?
>
> Wouldn't this simply match a signal arriving to a physical LAPIC just
> the moment before it is enabled?
Hm, yes, any guest trying to play this kind of games with the APIC is
free to keep the pieces.
Thanks, Roger.
next prev parent reply other threads:[~2022-11-21 10:54 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 10:31 [PATCH] x86/HVM: don't mark evtchn upcall vector as pending when vLAPIC is disabled Jan Beulich
2022-11-18 12:31 ` Juergen Gross
2022-11-18 12:33 ` Andrew Cooper
2022-11-18 12:51 ` Roger Pau Monné
2022-11-18 12:54 ` Jan Beulich
2022-11-18 13:55 ` Roger Pau Monné
2022-11-18 13:58 ` Jan Beulich
2022-11-18 14:09 ` Roger Pau Monné
2022-11-18 14:27 ` Andrew Cooper
2022-11-21 8:56 ` Jan Beulich
2022-11-21 12:23 ` Andrew Cooper
2022-11-21 12:34 ` Jan Beulich
2022-11-23 12:03 ` Roger Pau Monné
2022-11-24 7:59 ` Jan Beulich
2022-11-24 8:42 ` Roger Pau Monné
2022-11-24 9:06 ` Roger Pau Monné
2022-11-24 9:11 ` Jan Beulich
2022-11-24 9:33 ` Roger Pau Monné
2022-11-24 11:16 ` Jan Beulich
2022-11-24 15:12 ` Roger Pau Monné
2022-11-25 8:43 ` Jan Beulich
2022-11-25 9:00 ` Roger Pau Monné
2022-11-25 9:09 ` Jan Beulich
2022-11-24 9:06 ` Jan Beulich
2022-12-05 13:44 ` Jan Beulich
2022-11-18 14:26 ` Roger Pau Monné
2022-11-21 8:33 ` Jan Beulich
2022-11-21 10:53 ` Roger Pau Monné [this message]
2022-11-21 11:14 ` Jan Beulich
2022-11-21 12:06 ` Jan Beulich
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=Y3tYxMSGLDtBLHVc@Air-de-Roger \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=paul@xen.org \
--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 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.