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

Re: [PATCH] x86/spec-ctrl: Knobs for STIBP and PSFD, and follow hardware STIBP hint


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 17 Mar 2022 10:58:22 +0100
  • 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=ZklsvcfisBfRstzsvUpH+Z1Nwq1WZ+inWhlObqE1dg8=; b=IEMTwPKXZNDMyaBukM5cjV/coq+fUd0qcZK7J0VB04CYoRl7/2PqN1CqvqOiZ/0l2pWT/AEvAadjOHYfuifQGZXm5jo51AjZyw2iMX1SWy80c19/jfrSMdvcVqL8ojn/S7sbkgQ7N2FYbHkq5zlgUli616DIrT67494pxrLxeYmYKLlfWwhcGApy01vPUcmlq6k/3AZA4idfG5xhxhLEUsTQ1CDv6utxGIctJDB3kgHY7/nU2rrepYi7cNGU6W3DqjG9KAzeo0RTWarLSt9adOw93J0jsRPGs8gCb0u8dWo5u+NSHIHQImHv6n21p1w4KNMmJpqfXm8td6CMexo35g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mexw3tiNTs+OOoCSiERhjezTsbEWrjJ5rYP4XvEuamv2ENkL8MHgXN+z5C1ozIKbYdorUTOLF1sfKuiNk+txDOmqd4d12pG4d4pj8bjI596P1o9G7OGanxWj5cKVhW/bYxm7T6cLjljopSF+9pKcTtMzH0PeRvT2voNsT7ThOouGgwU2QFHTBj9g6Jul2C1pbF6xz9vTZajAlBTymxtvmG/fr4h/ukzuEsfiPq6b7cjLVirOifbu5wqrLYNcKR3OAgZfdSjrxMMj2sueCN5qn12yUt/iYcgKUFOSDU5q9YNdnQoDyB4JXw4Mk331ZrRPz+Vcg/KZ3wgsA5AXsfZ7Zg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 17 Mar 2022 09:58:52 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 16.03.2022 15:00, Andrew Cooper wrote:
> STIBP and PSFD are slightly weird bits, because they're both implied by other
> bits in MSR_SPEC_CTRL.  Add fine grain controls for them, and take the
> implications into account when setting IBRS/SSBD.
> 
> Rearrange the IBPB text/variables/logic to keep all the MSR_SPEC_CTRL bits
> together, for consistency.
> 
> However, AMD have a hardware hint CPUID bit recommending that STIBP be set
> uniaterally.  This is advertised on Zen3, so follow the recommendation.  This
> is the only default change.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>

In principle
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
but I have two comments:

> @@ -170,12 +174,18 @@ static int __init cf_check parse_spec_ctrl(const char 
> *s)
>              else
>                  rc = -EINVAL;
>          }
> +
>          else if ( (val = parse_boolean("ibrs", s, ss)) >= 0 )
>              opt_ibrs = val;
> -        else if ( (val = parse_boolean("ibpb", s, ss)) >= 0 )
> -            opt_ibpb = val;
> +        else if ( (val = parse_boolean("stibp", s, ss)) >= 0 )
> +            opt_stibp = val;
>          else if ( (val = parse_boolean("ssbd", s, ss)) >= 0 )
>              opt_ssbd = val;
> +        else if ( (val = parse_boolean("psfd", s, ss)) >= 0 )
> +            opt_psfd = val;
> +
> +        else if ( (val = parse_boolean("ibpb", s, ss)) >= 0 )
> +            opt_ibpb = val;
>          else if ( (val = parse_boolean("eager-fpu", s, ss)) >= 0 )
>              opt_eager_fpu = val;
>          else if ( (val = parse_boolean("l1d-flush", s, ss)) >= 0 )

Personally I find blank lines ahead of "else if" misleading. Could I
talk you into moving ibrs+stibp and ssbd+psfd close to the end of this
(immediately ahead of "else"), prefixing each pair with a comment about
one feature implying the other (and hence the comments replacing the
blank lines)?

Otoh I notice that we already have blank lines elsewhere in the middle
if this block of code, but at least there they're accompanied by a
comment making more obvious why there is such separation. Which means
as an intermediate approach I'd be okay with no re-ordering, but with
comments added.

> @@ -1070,12 +1083,50 @@ void __init init_speculation_mitigations(void)
>  
>      /* If we have IBRS available, see whether we should use it. */
>      if ( has_spec_ctrl && ibrs )
> +    {
> +        /* IBRS implies STIBP.  */
> +        if ( opt_stibp == -1 )
> +            opt_stibp = 1;
> +
>          default_xen_spec_ctrl |= SPEC_CTRL_IBRS;
> +    }
> +
> +    /* Use STIBP by default if the hardware hint is set. */
> +    if ( opt_stibp == -1 && boot_cpu_has(X86_FEATURE_STIBP_ALWAYS) )
> +        opt_stibp = 1;
> +
> +    /*
> +     * Otherwise, don't use STIBP by default.  It has some severe performance
> +     * implications on older hardware.
> +     */
> +    if ( opt_stibp == -1 )
> +        opt_stibp = 0;

I'd find this easier to read if written along the lines of

    if ( opt_stibp == -1 )
    {
        /*
         * Use STIBP by default if the hardware hint is set.  Otherwise,
         * don't use STIBP by default.  It has some severe performance
         * implications on older hardware.
         */
        opt_stibp = !!boot_cpu_has(X86_FEATURE_STIBP_ALWAYS);
    }

FTAOD I'm not going to insist on either adjustment.

Jan




 


Rackspace

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