From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>,
Kevin Tian <kevin.tian@intel.com>,
Andrew Cooper <andrew.cooper3@citrix.com>, Wei Liu <wl@xen.org>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v2] x86/vmx: add support for virtualize SPEC_CTRL
Date: Thu, 15 Feb 2024 16:54:48 +0100 [thread overview]
Message-ID: <Zc4zyLgM-OUNc6xG@macbook> (raw)
In-Reply-To: <09cf678e-bdbd-47a9-8c9d-533e7bee9450@suse.com>
On Mon, Feb 12, 2024 at 03:09:01PM +0100, Jan Beulich wrote:
> On 09.02.2024 12:40, Roger Pau Monne wrote:
> > @@ -1378,6 +1379,10 @@ static int construct_vmcs(struct vcpu *v)
> > rc = vmx_add_msr(v, MSR_PRED_CMD, PRED_CMD_IBPB,
> > VMX_MSR_HOST);
> >
> > + /* Set any bits we don't allow toggling in the mask field. */
> > + if ( cpu_has_vmx_virt_spec_ctrl && v->arch.msrs->spec_ctrl.raw )
> > + __vmwrite(SPEC_CTRL_MASK, v->arch.msrs->spec_ctrl.raw);
>
> The right side of the conditional isn't strictly necessary here, is it?
> Might it be better to omit it, for clarity?
No strong opinion, my thinking was that skipping the vmwrite would be
better performance wise, but we don't care about performance here
anyway.
> > --- a/xen/arch/x86/hvm/vmx/vmx.c
> > +++ b/xen/arch/x86/hvm/vmx/vmx.c
> > @@ -823,18 +823,29 @@ static void cf_check vmx_cpuid_policy_changed(struct vcpu *v)
> > {
> > vmx_clear_msr_intercept(v, MSR_SPEC_CTRL, VMX_MSR_RW);
> >
> > - rc = vmx_add_guest_msr(v, MSR_SPEC_CTRL, 0);
> > - if ( rc )
> > - goto out;
> > + if ( !cpu_has_vmx_virt_spec_ctrl )
> > + {
> > + rc = vmx_add_guest_msr(v, MSR_SPEC_CTRL, 0);
> > + if ( rc )
> > + goto out;
> > + }
> > }
> > else
> > {
> > vmx_set_msr_intercept(v, MSR_SPEC_CTRL, VMX_MSR_RW);
> >
> > - rc = vmx_del_msr(v, MSR_SPEC_CTRL, VMX_MSR_GUEST);
> > - if ( rc && rc != -ESRCH )
> > - goto out;
> > - rc = 0; /* Tolerate -ESRCH */
> > + /*
> > + * NB: there's no need to clear the virtualize SPEC_CTRL control, as
> > + * the MSR intercept takes precedence. The SPEC_CTRL shadow VMCS field
> > + * is also not loaded on guest entry/exit if the intercept is set.
> > + */
>
> It wasn't so much the shadow field than the mask one that I was concerned
> might be used in some way. The shadow one clearly is used only during
> guest RDMSR/WRMSR processing. To not focus on "shadow", maybe simple say
> "The SPEC_CTRL shadow VMCS fields are also not ..."?
What about:
"The SPEC_CTRL shadow and mask VMCS fields don't take effect if the
intercept is set."
> > + if ( !cpu_has_vmx_virt_spec_ctrl )
> > + {
> > + rc = vmx_del_msr(v, MSR_SPEC_CTRL, VMX_MSR_GUEST);
> > + if ( rc && rc != -ESRCH )
> > + goto out;
> > + rc = 0; /* Tolerate -ESRCH */
> > + }
> > }
> >
> > /* MSR_PRED_CMD is safe to pass through if the guest knows about it. */
> > @@ -2629,6 +2640,9 @@ static uint64_t cf_check vmx_get_reg(struct vcpu *v, unsigned int reg)
> > switch ( reg )
> > {
> > case MSR_SPEC_CTRL:
> > + if ( cpu_has_vmx_virt_spec_ctrl )
> > + /* Requires remote VMCS loaded - fetched below. */
>
> I could see what "fetch" refers to here, but ...
>
> > + break;
> > rc = vmx_read_guest_msr(v, reg, &val);
> > if ( rc )
> > {
> > @@ -2652,6 +2666,11 @@ static uint64_t cf_check vmx_get_reg(struct vcpu *v, unsigned int reg)
> > vmx_vmcs_enter(v);
> > switch ( reg )
> > {
> > + case MSR_SPEC_CTRL:
> > + ASSERT(cpu_has_vmx_virt_spec_ctrl);
> > + __vmread(SPEC_CTRL_SHADOW, &val);
> > + break;
> > +
> > case MSR_IA32_BNDCFGS:
> > __vmread(GUEST_BNDCFGS, &val);
> > break;
> > @@ -2678,6 +2697,9 @@ static void cf_check vmx_set_reg(struct vcpu *v, unsigned int reg, uint64_t val)
> > switch ( reg )
> > {
> > case MSR_SPEC_CTRL:
> > + if ( cpu_has_vmx_virt_spec_ctrl )
> > + /* Requires remote VMCS loaded - fetched below. */
>
> ... since you also use the word here, I'm not sure it's really
> the VMREAD up there.
That one should be 'set below'.
Thanks, Roger.
next prev parent reply other threads:[~2024-02-15 15:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-09 11:40 [PATCH v2] x86/vmx: add support for virtualize SPEC_CTRL Roger Pau Monne
2024-02-12 14:09 ` Jan Beulich
2024-02-15 15:54 ` Roger Pau Monné [this message]
2024-02-15 16:07 ` 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=Zc4zyLgM-OUNc6xG@macbook \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.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.