All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: "Roger Pau Monné" <roger.pau@citrix.com>, "Wei Liu" <wl@xen.org>,
	Xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH 3/8] x86/svm: VMEntry/Exit logic for MSR_SPEC_CTRL
Date: Wed, 26 Jan 2022 17:50:50 +0100	[thread overview]
Message-ID: <f5c1134a-f446-7031-877e-6a3177120de9@suse.com> (raw)
In-Reply-To: <20220126084452.28975-4-andrew.cooper3@citrix.com>

On 26.01.2022 09:44, Andrew Cooper wrote:
> 1) It would be slightly more efficient to pass curr and cpu_info into
>    vm{entry,exit}_spec_ctrl(), but setup of such state can't be in the
>    ALTERNATIVE block because then the call displacement won't get fixed up.
>    All the additional accesses are hot off the stack, so almost certainly
>    negligible compared to the WRMSR.

What's wrong with using two instances of ALTERNATIVE, one to setup the
call arguments and the 2nd for just the CALL?

> --- a/xen/arch/x86/hvm/svm/entry.S
> +++ b/xen/arch/x86/hvm/svm/entry.S
> @@ -55,11 +55,11 @@ __UNLIKELY_END(nsvm_hap)
>          mov  %rsp, %rdi
>          call svm_vmenter_helper
>  
> -        mov VCPU_arch_msrs(%rbx), %rax
> -        mov VCPUMSR_spec_ctrl_raw(%rax), %eax
> +        clgi
>  
>          /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */
> -        /* SPEC_CTRL_EXIT_TO_SVM   (nothing currently) */
> +        /* SPEC_CTRL_EXIT_TO_SVM       Req:                           Clob: C   */
> +        ALTERNATIVE "", __stringify(call vmentry_spec_ctrl), X86_FEATURE_SC_MSR_HVM

I guess the new upper case C after Clob: stands for "all call-clobbered
registers"? In which case ...

> @@ -86,8 +85,9 @@ __UNLIKELY_END(nsvm_hap)
>  
>          GET_CURRENT(bx)
>  
> -        /* SPEC_CTRL_ENTRY_FROM_SVM    Req: b=curr %rsp=regs/cpuinfo, Clob: ac  */
> +        /* SPEC_CTRL_ENTRY_FROM_SVM    Req:                           Clob: ac,C */
>          ALTERNATIVE "", DO_OVERWRITE_RSB, X86_FEATURE_SC_RSB_HVM
> +        ALTERNATIVE "", __stringify(call vmexit_spec_ctrl), X86_FEATURE_SC_MSR_HVM

... why the explicit further "ac" here? Is the intention to annotate
every individual ALTERNATIVE this way?

> --- a/xen/arch/x86/hvm/svm/svm.c
> +++ b/xen/arch/x86/hvm/svm/svm.c
> @@ -3086,6 +3086,36 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
>      vmcb_set_vintr(vmcb, intr);
>  }
>  
> +/* Called with GIF=0. */
> +void vmexit_spec_ctrl(void)
> +{
> +    struct cpu_info *info = get_cpu_info();
> +    unsigned int val = info->xen_spec_ctrl;
> +
> +    /*
> +     * Write to MSR_SPEC_CTRL unconditionally, for the RAS[:32] flushing side
> +     * effect.
> +     */
> +    wrmsr(MSR_SPEC_CTRL, val, 0);
> +    info->last_spec_ctrl = val;
> +}
> +
> +/* Called with GIF=0. */
> +void vmentry_spec_ctrl(void)
> +{
> +    struct cpu_info *info = get_cpu_info();
> +    const struct vcpu *curr = current;
> +    unsigned int val = curr->arch.msrs->spec_ctrl.raw;
> +
> +    if ( val != info->last_spec_ctrl )
> +    {
> +        wrmsr(MSR_SPEC_CTRL, val, 0);
> +        info->last_spec_ctrl = val;
> +    }

Is this correct for the very first use on a CPU? last_spec_ctrl
starts out as zero afaict, and hence this very first write would be
skipped if the guest value is also zero (which it will be for a
vCPU first launched), even if we have a non-zero value in the MSR
at that point.

Jan



  reply	other threads:[~2022-01-26 16:51 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-26  8:44 [PATCH 0/8] x86: MSR_SPEC_CTRL support for SVM guests Andrew Cooper
2022-01-26  8:44 ` [PATCH 1/8] x86/msr: Fix migration compatibility issue with MSR_SPEC_CTRL Andrew Cooper
2022-01-26 12:17   ` Roger Pau Monné
2022-01-26 12:54     ` Andrew Cooper
2022-01-26 16:33   ` Jan Beulich
2022-01-26  8:44 ` [PATCH 2/8] x86/boot: Collect AMD speculative features earlier during boot Andrew Cooper
2022-01-26 12:44   ` Roger Pau Monné
2022-01-26 12:50     ` Jan Beulich
2022-01-26 13:37     ` Andrew Cooper
2022-01-26 13:47       ` Andrew Cooper
2022-01-26 14:11         ` Andrew Cooper
2022-01-26  8:44 ` [PATCH 3/8] x86/svm: VMEntry/Exit logic for MSR_SPEC_CTRL Andrew Cooper
2022-01-26 16:50   ` Jan Beulich [this message]
2022-01-26 20:16     ` Andrew Cooper
2022-01-27  7:25       ` Jan Beulich
2022-01-27 21:55         ` Andrew Cooper
2022-01-26  8:44 ` [PATCH 4/8] x86/spec-ctrl: Drop use_spec_ctrl boolean Andrew Cooper
2022-01-26 16:54   ` Jan Beulich
2022-01-26  8:44 ` [PATCH 5/8] x86/spec-ctrl: Introduce new has_spec_ctrl boolean Andrew Cooper
2022-01-26 16:57   ` Jan Beulich
2022-01-26  8:44 ` [PATCH 6/8] x86/spec-ctrl: Use common MSR_SPEC_CTRL logic for AMD Andrew Cooper
2022-01-26 17:05   ` Jan Beulich
2022-01-26  8:44 ` [PATCH 7/8] x86/msr: AMD MSR_SPEC_CTRL infrastructure Andrew Cooper
2022-01-27 13:06   ` Jan Beulich
2022-01-26  8:44 ` [PATCH 8/8] x86/cpuid: Enable MSR_SPEC_CTRL in SVM guests by default Andrew Cooper
2022-01-26 12:17   ` Andrew Cooper
2022-01-27 13:47   ` Jan Beulich
2022-01-27 17:20     ` Andrew Cooper

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=f5c1134a-f446-7031-877e-6a3177120de9@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.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.