All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Roger Pau Monne <roger.pau@citrix.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: Mon, 12 Feb 2024 15:09:01 +0100	[thread overview]
Message-ID: <09cf678e-bdbd-47a9-8c9d-533e7bee9450@suse.com> (raw)
In-Reply-To: <20240209114045.97005-1-roger.pau@citrix.com>

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?

> --- 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 ..."?

> +        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.

Jan


  reply	other threads:[~2024-02-12 14:09 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 [this message]
2024-02-15 15:54   ` Roger Pau Monné
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=09cf678e-bdbd-47a9-8c9d-533e7bee9450@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=roger.pau@citrix.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.