[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v5 2/3] amd/msr: allow passthrough of VIRT_SPEC_CTRL for HVM guests


  • To: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 6 May 2022 14:15:47 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fZ1qEo4Rd9MIG4RAQQAmB4EKLXIO9dWWevg+YaxVE44=; b=FSmPlYFwBp7U2ddqsWuwMQ7tvGd5CnRHfOTYnzKM8o8eHzTQ2BpxyrRrOXPKT9UAMxCRGQExI2aZ4409CRXBgQSYgTj4motpHhUqvDfJniIobg758zEGO60oJjgzRGMr9641XeyqyieAuSXTGJYWQLchlL1zS5H8iva589C2YjLCgwyBxEpHL8bKIdHRl46X1Z700/4mOTqLvfDxP8oXtX7aaK2Eh/GDvcfutFdWCgXMZV1LmK734iqnhUiLRY8m2EuaTyV5WM6rVtxu6xEESSbLSGLhGrInXAPTpjjPkHSoyKCehrBuiPXLBG9ao8mqxrxOIJrsYSiImHtsUF3INw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OVWOnjfkOJVjLWxo6ZLpJwl+Uu30NVn2mw2JiUmxpuWKrTO5tO0JFtjUzYbcfCw8Y+nfYwm8x4407yXxOfFP1Af41Jlf+b8KWJLRLmLLRLwGBWDVKkoMp0tY2nYyoECBaRIUXRAtJNeIEZ31KWsFyPdryabH4gx7AvW/QXhEE3iDScGkMBpuMxqr0cQkEbExwrO6Kr5LFexk0Sr73Jj0n5kccAVY2lzmhcGa/OspUqsAv0H/NPI0xo97G449nuSonGbP2Gv+cuWydMQUd1BvXQ4ucg6xCEWcskDH/UiBESJs//HU220sydZNim/RbhAoXQ11HVSnIhG8AmFkHK5EHg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Fri, 06 May 2022 12:16:05 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 03.05.2022 10:26, Roger Pau Monne wrote:
> --- a/xen/arch/x86/cpuid.c
> +++ b/xen/arch/x86/cpuid.c
> @@ -541,6 +541,9 @@ static void __init calculate_hvm_max_policy(void)
>           raw_cpuid_policy.basic.sep )
>          __set_bit(X86_FEATURE_SEP, hvm_featureset);
>  
> +    if ( boot_cpu_has(X86_FEATURE_VIRT_SC_MSR_HVM) )
> +        __set_bit(X86_FEATURE_VIRT_SSBD, hvm_featureset);
> +
>      /*
>       * If Xen isn't virtualising MSR_SPEC_CTRL for HVM guests (functional
>       * availability, or admin choice), hide the feature.

Especially with the setting of VIRT_SSBD below here (from patch 1) I
don't think this can go without comment. The more that the other
instance ...

> @@ -597,6 +600,13 @@ static void __init calculate_hvm_def_policy(void)
>      guest_common_feature_adjustments(hvm_featureset);
>      guest_common_default_feature_adjustments(hvm_featureset);
>  
> +    /*
> +     * Only expose VIRT_SSBD if AMD_SSBD is not available, and thus
> +     * VIRT_SC_MSR_HVM is set.
> +     */
> +    if ( boot_cpu_has(X86_FEATURE_VIRT_SC_MSR_HVM) )
> +        __set_bit(X86_FEATURE_VIRT_SSBD, hvm_featureset);
> +
>      sanitise_featureset(hvm_featureset);
>      cpuid_featureset_to_policy(hvm_featureset, p);
>      recalculate_xstate(p);

... here is about default exposure, so cannot really be extended to
the condition under which this is put in "max" (except that of course
"max" needs to include everything "def" has).

> @@ -3105,6 +3116,30 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
>      vmcb_set_vintr(vmcb, intr);
>  }
>  
> +/* Called with GIF=0. */
> +void vmexit_virt_spec_ctrl(void)
> +{
> +    unsigned int val = opt_ssbd ? SPEC_CTRL_SSBD : 0;
> +
> +    if ( val == current->arch.msrs->virt_spec_ctrl.raw )
> +        return;
> +
> +    if ( cpu_has_virt_ssbd )
> +        wrmsr(MSR_VIRT_SPEC_CTRL, val, 0);
> +}
> +
> +/* Called with GIF=0. */
> +void vmentry_virt_spec_ctrl(void)
> +{
> +    unsigned int val = opt_ssbd ? SPEC_CTRL_SSBD : 0;
> +
> +    if ( val == current->arch.msrs->virt_spec_ctrl.raw )
> +        return;
> +
> +    if ( cpu_has_virt_ssbd )
> +        wrmsr(MSR_VIRT_SPEC_CTRL, current->arch.msrs->virt_spec_ctrl.raw, 0);
> +}

I guess the double use of current makes it difficult for the compiler
to CSE both uses. Furthermore for symmetry with the other function
how about

void vmentry_virt_spec_ctrl(void)
{
    unsigned int val = current->arch.msrs->virt_spec_ctrl.raw;

    if ( val == (opt_ssbd ? SPEC_CTRL_SSBD : 0) )
        return;

    if ( cpu_has_virt_ssbd )
        wrmsr(MSR_VIRT_SPEC_CTRL, val, 0);
}

i.e. "val" always representing the value we want to write?

With at least a comment added above, and preferably with the change
to the function (unless that gets in the way of the 3rd patch)
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>

Jan




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.