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>
Subject: Re: [PATCH v4 4/4] x86/PV: issue branch prediction barrier when switching 64-bit guest to kernel mode
Date: Tue, 19 Dec 2023 16:11:09 +0100 [thread overview]
Message-ID: <ZYGyjQiAomxh0QnI@macbook> (raw)
In-Reply-To: <aacaa220-3e95-4dff-9572-79f9e79faeae@suse.com>
On Tue, Dec 19, 2023 at 03:06:50PM +0100, Jan Beulich wrote:
> On 19.12.2023 12:48, Roger Pau Monné wrote:
> > On Tue, Dec 19, 2023 at 10:56:16AM +0100, Jan Beulich wrote:
> >> On 18.12.2023 18:24, Roger Pau Monné wrote:
> >>> On Tue, Feb 14, 2023 at 05:12:08PM +0100, Jan Beulich wrote:
> >>>> --- a/xen/arch/x86/pv/domain.c
> >>>> +++ b/xen/arch/x86/pv/domain.c
> >>>> @@ -455,6 +455,7 @@ static void _toggle_guest_pt(struct vcpu
> >>>> void toggle_guest_mode(struct vcpu *v)
> >>>> {
> >>>> const struct domain *d = v->domain;
> >>>> + struct cpu_info *cpu_info = get_cpu_info();
> >>>> unsigned long gs_base;
> >>>>
> >>>> ASSERT(!is_pv_32bit_vcpu(v));
> >>>> @@ -467,15 +468,21 @@ void toggle_guest_mode(struct vcpu *v)
> >>>> if ( v->arch.flags & TF_kernel_mode )
> >>>> v->arch.pv.gs_base_kernel = gs_base;
> >>>> else
> >>>> + {
> >>>> v->arch.pv.gs_base_user = gs_base;
> >>>> +
> >>>> + if ( opt_ibpb_mode_switch &&
> >>>> + !(d->arch.spec_ctrl_flags & SCF_entry_ibpb) &&
> >>>> + !VM_ASSIST(d, mode_switch_no_ibpb) )
> >>>> + cpu_info->spec_ctrl_flags |= SCF_new_pred_ctxt;
> >>>
> >>> Likewise similar to the remarks I've made before, if doing an IBPB on
> >>> entry is enough to cover for the case here, it must also be fine to
> >>> issue the IBPB right here, instead of deferring to return to guest
> >>> context?
> >>>
> >>> The only concern would be (as you mentioned before) to avoid clearing
> >>> valid Xen predictions, but I would rather see some figures about what
> >>> effect the delaying to return to guest has vs issuing it right here.
> >>
> >> Part of the reason (aiui) to do things on the exit path was to
> >> consolidate the context switch induced one and the user->kernel switch
> >> one into the same place and mechanism.
> >
> > Isn't it kind of a very specific case that we end up doing a
> > user->kernel switch as part of a context switch? IOW: would require
> > the vCPU to be scheduled out at that very specific point.
>
> No, there's no user->kernel switch at the same time as context switch.
> What I was trying to explain is that with the actual IBPB being issued
> on exit to guest, both the context switch path and the user->kernel
> mode switch path set the same indicator, for the exit path to consume.
Deferring to exit to guest path could be OK, but unless strictly
needed, which I don't think it's the case, I would request for IBPB to
be executed in C context rather than assembly one.
> >>>> + *
> >>>> + * By default (on affected and capable hardware) as a safety measure Xen,
> >>>> + * to cover for the fact that guest-kernel and guest-user modes are both
> >>>> + * running in ring 3 (and hence share prediction context), would issue a
> >>>> + * barrier for user->kernel mode switches of PV guests.
> >>>> + */
> >>>> +#define VMASST_TYPE_mode_switch_no_ibpb 33
> >>>
> >>> Would it be possible to define the assist as
> >>> VMASST_TYPE_mode_switch_ibpb and have it on when enabled? So that the
> >>> guest would disable it if unneeded? IMO negated options are in
> >>> general harder to understand.
> >>
> >> Negative options aren't nice, yes, but VM assists start out as all
> >> clear.
> >
> > Are you sure? I see VMASST_TYPE_pae_extended_cr3 getting set in
> > dom0_construct_pv() and that makes me wonder whether other bits
> > couldn't start set also.
> >
> > Maybe there's some restriction I'm missing, but I don't see any
> > wording in the description of the interface that states that all
> > assists are supposed to start disabled.
>
> Well, that setting of pae_extended_cr3 is in response to the kernel's
> notes section having a respective indicator. So we still only set the
> bit in response to what the kernel's asking us to do, just that here
> we carry out the request ahead of launching the kernel.
>
> Also consider what would happen during migration if there was a
> default-on assist: At the destination we can't know whether the
> source simply didn't know of the bit, or whether the guest elected to
> clear it.
Hm, I see, so I was indeed missing that aspect. VM assist is passed
as a plain bitmap, and there's no signal on which assists the VM had
available on the source side if not enabled.
Thanks, Roger.
next prev parent reply other threads:[~2023-12-19 15:11 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-14 16:09 [PATCH v4 0/4 + v1 0/1] x86/spec-ctrl: IBPB improvements Jan Beulich
2023-02-14 16:10 ` [PATCH v4 1/4] x86/spec-ctrl: add logic to issue IBPB on exit to guest Jan Beulich
2023-12-18 12:11 ` Roger Pau Monné
2023-12-18 13:46 ` Jan Beulich
2023-12-18 13:50 ` Jan Beulich
2023-12-18 15:43 ` Roger Pau Monné
2023-12-18 16:02 ` Jan Beulich
2023-12-18 13:54 ` Jan Beulich
2023-12-18 15:40 ` Roger Pau Monné
2023-12-18 16:00 ` Jan Beulich
2023-02-14 16:11 ` [PATCH v4 2/4] x86/spec-ctrl: defer context-switch IBPB until guest entry Jan Beulich
2023-12-18 12:39 ` Roger Pau Monné
2023-12-18 13:58 ` Jan Beulich
2023-12-18 17:27 ` Roger Pau Monné
2023-02-14 16:11 ` [PATCH v4 3/4] x86: limit issuing of IBPB during context switch Jan Beulich
2023-12-18 15:19 ` Roger Pau Monné
2023-12-18 16:09 ` Jan Beulich
2023-12-18 16:11 ` Jan Beulich
2023-02-14 16:12 ` [PATCH v4 4/4] x86/PV: issue branch prediction barrier when switching 64-bit guest to kernel mode Jan Beulich
2023-12-18 17:24 ` Roger Pau Monné
2023-12-19 9:56 ` Jan Beulich
2023-12-19 11:48 ` Roger Pau Monné
2023-12-19 14:06 ` Jan Beulich
2023-12-19 15:11 ` Roger Pau Monné [this message]
2023-12-19 17:07 ` Roger Pau Monné
2023-12-20 9:25 ` Jan Beulich
2023-12-20 9:59 ` Roger Pau Monné
2023-02-14 16:13 ` [PATCH] x86/Xen: make use of IBPB controlling VM assist Jan Beulich
2023-02-14 23:53 ` Boris Ostrovsky
2023-02-15 0:07 ` Boris Ostrovsky
2023-02-15 8:31 ` Jan Beulich
2023-02-15 23:22 ` Boris Ostrovsky
2023-02-16 7:33 ` Jan Beulich
2023-03-17 13:56 ` Juergen Gross
2023-03-17 14:21 ` Andrew Cooper
2023-03-17 14:28 ` Juergen Gross
2023-03-20 10:21 ` Jan Beulich
2023-03-20 10:19 ` Jan Beulich
2023-03-20 13:02 ` Juergen Gross
2023-03-20 13:17 ` Jan Beulich
2023-03-20 13:35 ` Juergen Gross
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=ZYGyjQiAomxh0QnI@macbook \
--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 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.