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

Re: [PATCH 3/3] x86/amd: Use newer SSBD mechanisms if they exist


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 19 Aug 2021 16:59:34 +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-SenderADCheck; bh=EaqTGpIseiymaGgJz3/lZYw8fD50FDo3wl4e7ApZd7A=; b=SnhsGQn1vu5k1MZWOTPwnNelY7JLBq9v6YblXUH+xYuLGEg5jTLcq8N9YlQeFzYUlCW8SJBBRWMohuq0WKN7q4rw2DLeTdyWEtYdBfx2STzvP+hfvaXw7o40Hj+UlycpRtHIHxm3Wq3utFRoWf/2qQUspF8QSzxt6n5CHW6y46coMuhDw1XdwccdF+WPMqT4bknM9lMGwUXa506OZyX81XHYV15V1g/REN/FtxRnXtQEU1EsGicfley+QKBvscytmtzT8LnTvXLPkOpYTHMWIYsqBw40zFEe2/1s7cnN11rTu0W6qMVQnXf8IVlLhawy91qU2Yc+Gp1T/nxNw/7N2g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jFKMWH0C2Pc3yG+GdDDHrZNWc93aquCHNYaIrIQV6xcn8mU8q5917TR7vdeNGbvBvgaETL8kG4b5KC/ne7nQCz/Q0FP7MeMG/dnNRt6OWAk7FCY/LaSfy1iWAXlTM/GRFC/Jw/2U+T0nHUMuYcbrwHY3fQe2Cjv8nOvZQaFh7Df2GTyW5mCu8CO7nSVUSGNdUa/NAfHB7gaSqVgT1Yu+TG3C1e24xcK/PzqykgTPSitosW3pn7B2X/BgVQdJ7jWvw8MHIwBZXBYl3q1F0gY+Ti2g1dEJ6lbBbe9J6wGMQ7eocpWU6MXhf02OqXw+RlewF8oZOM9c51REERnqCNIwLA==
  • Authentication-results: lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=none action=none header.from=suse.com;
  • Cc: Wei Liu <wei.liu2@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 19 Aug 2021 14:59:54 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 17.08.2021 16:30, Andrew Cooper wrote:
> The opencoded legacy Memory Disambiguation logic in init_amd() neglected
> Fam19h for the Zen3 microarchitecture.
> 
> In practice, all Zen2 based system (AMD Fam17h Model >= 0x30 and Hygon Fam18h
> Model >= 0x4) have the architectural MSR_SPEC_CTRL and the SSBD bit within it.
> 
> Implement the algorithm given in AMD's SSBD whitepaper, and leave a
> printk_once() behind in the case that no controls can be found.
> 
> This now means that a user choosing `spec-ctrl=no-ssb` will actually turn off
> Memory Disambiguation on Fam19h/Zen3 systems.

Aiui you mean `spec-ctrl=no-ssbd` here? And the effect would then be
to turn _on_ Memory Disambiguation, unless the original comment was
the wrong way round? I'm also concerned by this behavioral change:
I think opt_ssbd would want to become a tristate, such that not
specifying the option at all will not also result in turning the bit
off even if it was on for some reason (firmware?). Similarly
"spec-ctrl=no" and "spec-ctrl=no-xen" imo shouldn't have this effect.

> --- a/xen/arch/x86/cpu/amd.c
> +++ b/xen/arch/x86/cpu/amd.c
> @@ -681,6 +681,56 @@ void amd_init_lfence(struct cpuinfo_x86 *c)
>                         c->x86_capability);
>  }
>  
> +/*
> + * Refer to the AMD Speculative Store Bypass whitepaper:
> + * 
> https://developer.amd.com/wp-content/resources/124441_AMD64_SpeculativeStoreBypassDisable_Whitepaper_final.pdf
> + */
> +void amd_init_ssbd(const struct cpuinfo_x86 *c)
> +{
> +     int bit = -1;
> +
> +     if (cpu_has_ssb_no)
> +             return;
> +
> +     if (cpu_has_amd_ssbd) {
> +             wrmsrl(MSR_SPEC_CTRL, opt_ssbd ? SPEC_CTRL_SSBD : 0);
> +             return;
> +     }
> +
> +     if (cpu_has_virt_ssbd) {
> +             wrmsrl(MSR_VIRT_SPEC_CTRL, opt_ssbd ? SPEC_CTRL_SSBD : 0);
> +             return;
> +     }
> +
> +     switch (c->x86) {
> +     case 0x15: bit = 54; break;
> +     case 0x16: bit = 33; break;
> +     case 0x17:
> +     case 0x18: bit = 10; break;
> +     }
> +
> +     if (bit >= 0) {
> +             uint64_t val, mask = 1ull << bit;
> +
> +             if (rdmsr_safe(MSR_AMD64_LS_CFG, val) ||
> +                 ({
> +                         val &= ~mask;
> +                         if ( opt_ssbd )

Nit: No spaces inside the parentheses here.

Jan




 


Rackspace

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