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

Re: [PATCH v5 3/3] amd/msr: implement VIRT_SPEC_CTRL for HVM guests using legacy SSBD


  • To: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 6 May 2022 14:41:09 +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=XEDhe/YcaFNWtFa5mlIhtq1tl7msIAasVJli4k2Qn0g=; b=DpuR/xNKynR3Rq/zcKfuKYvcVvWVMiUsdKTigmPFBZRT18TmDa/y6O9z+vYjlEn71u/Yc2vX5Yby6P167AifIwulwq5yy89jQm1HVbhD7VZvGBw24c/tWK80bSK5Fl4DgiddkhV5QBWV4aXJyJfDvy+YZxJ7b1CECZddN2EugUG1IWwycAJ5qgqzs+sqMle1QwLM+gm+eha28qg3euy86PILeSPZ5FHottHJeg2x3VyClRAcAH7zaSrC/IJ27Kz3FAvFupn0f3dgARe0ZVK9VxN1IBbqg1F56S+kJVrqaYSUhPR6lORMbx6SzECU90cthpWR21f+4PoSobo5ez35hw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oVRMXn4jSz0OgNBY5Gsu/5EvVUv6bxlaWf6lgOl3ZHlB2r94bQ5x9+YlZzykR+TqDxLxf1+Q+1M9L6SfHe3PQICFNIlo6oCiz3O9HnwdXCgs7TyiJRmFQc4ehXfIKlH5Yfl7EsPNZ+zKF2oCQEbhtjfOlL7dCj1bdHdfvKtTL2sz//xMcb6m0fVh/slyQXsiIME9oRxOnhYLLLr7nNfgQILafMiDSp2TCTHSMwXdV1n2FTNICQMynUmmriqEd1Zimmivuoak4lxxHUFK+8JKBG0V6gG35ea3sxS3I3RDwF1J83x0D/qc+RMz2lfPS4v8inf0/6fxmK6nQjelt3VfiA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Henry Wang <Henry.Wang@xxxxxxx>, Community Manager <community.manager@xxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Fri, 06 May 2022 12:41:19 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 03.05.2022 10:26, Roger Pau Monne wrote:
> Expose VIRT_SSBD to guests if the hardware supports setting SSBD in
> the LS_CFG MSR (a.k.a. non-architectural way). Different AMD CPU
> families use different bits in LS_CFG, so exposing VIRT_SPEC_CTRL.SSBD
> allows for an unified way of exposing SSBD support to guests on AMD
> hardware that's compatible migration wise, regardless of what
> underlying mechanism is used to set SSBD.
> 
> Note that on AMD Family 17h and Hygon Family 18h processors the value
> of SSBD in LS_CFG is shared between threads on the same core, so
> there's extra logic in order to synchronize the value and have SSBD
> set as long as one of the threads in the core requires it to be set.
> Such logic also requires extra storage for each thread state, which is
> allocated at initialization time.
> 
> Do the context switching of the SSBD selection in LS_CFG between
> hypervisor and guest in the same handler that's already used to switch
> the value of VIRT_SPEC_CTRL.
> 
> Suggested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
with one nit:

> +void amd_set_legacy_ssbd(bool enable)
> +{
> +     const struct cpuinfo_x86 *c = &current_cpu_data;
> +     struct ssbd_ls_cfg *status;
> +
> +     if ((c->x86 != 0x17 && c->x86 != 0x18) || c->x86_num_siblings <= 1) {
> +             set_legacy_ssbd(c, enable);
> +             return;
> +     }
> +
> +     status = &ssbd_ls_cfg[c->phys_proc_id * ssbd_max_cores +
> +                           c->cpu_core_id];
> +
> +     /*
> +      * Open code a very simple spinlock: this function is used with GIF==0
> +      * and different IF values, so would trigger the checklock detector.
> +      * Instead of trying to workaround the detector, use a very simple lock
> +      * implementation: it's better to reduce the amount of code executed
> +      * with GIF==0.
> +      */
> +     while ( test_and_set_bool(status->locked) )

Nit: A bit of Xen style slipped into here.

> --- a/xen/arch/x86/hvm/svm/svm.c
> +++ b/xen/arch/x86/hvm/svm/svm.c
> @@ -3126,6 +3126,8 @@ void vmexit_virt_spec_ctrl(void)
>  
>      if ( cpu_has_virt_ssbd )
>          wrmsr(MSR_VIRT_SPEC_CTRL, val, 0);
> +    else
> +        amd_set_legacy_ssbd(val);
>  }
>  
>  /* Called with GIF=0. */
> @@ -3138,6 +3140,8 @@ void vmentry_virt_spec_ctrl(void)
>  
>      if ( cpu_has_virt_ssbd )
>          wrmsr(MSR_VIRT_SPEC_CTRL, current->arch.msrs->virt_spec_ctrl.raw, 0);
> +    else
> +        amd_set_legacy_ssbd(!val);
>  }

Aiui the adjustment suggested for patch 2 will not really get in the way
of this, by only requiring to drop the ! .

Jan




 


Rackspace

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