[PATCH] x86/spec-ctrl: Fix default calculation of opt_srb_lock

Andrew Cooper posted 1 patch 2 years, 3 months ago
Test gitlab-ci passed
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20220104144422.29989-1-andrew.cooper3@citrix.com
xen/arch/x86/spec_ctrl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] x86/spec-ctrl: Fix default calculation of opt_srb_lock
Posted by Andrew Cooper 2 years, 3 months ago
Since this logic was introduced, opt_tsx has become more complicated and
shouldn't be compared to 0 directly.  While there are no buggy logic paths,
the correct expression is !(opt_tsx & 1) but the rtm_disabled boolean is
easier and clearer to use.

Fixes: 8fe24090d940 ("x86/cpuid: Rework HLE and RTM handling")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Wei Liu <wl@xen.org>
---
 xen/arch/x86/spec_ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/arch/x86/spec_ctrl.c b/xen/arch/x86/spec_ctrl.c
index a5569c7f2b3f..c18cc8aa493a 100644
--- a/xen/arch/x86/spec_ctrl.c
+++ b/xen/arch/x86/spec_ctrl.c
@@ -1245,7 +1245,7 @@ void __init init_speculation_mitigations(void)
          */
         if ( opt_srb_lock == -1 &&
              (caps & (ARCH_CAPS_MDS_NO|ARCH_CAPS_TAA_NO)) == ARCH_CAPS_MDS_NO &&
-             (!cpu_has_hle || ((caps & ARCH_CAPS_TSX_CTRL) && opt_tsx == 0)) )
+             (!cpu_has_hle || ((caps & ARCH_CAPS_TSX_CTRL) && rtm_disabled)) )
             opt_srb_lock = 0;
 
         val &= ~MCU_OPT_CTRL_RNGDS_MITG_DIS;
-- 
2.11.0


Re: [PATCH] x86/spec-ctrl: Fix default calculation of opt_srb_lock
Posted by Jan Beulich 2 years, 3 months ago
On 04.01.2022 15:44, Andrew Cooper wrote:
> Since this logic was introduced, opt_tsx has become more complicated and
> shouldn't be compared to 0 directly.  While there are no buggy logic paths,
> the correct expression is !(opt_tsx & 1) but the rtm_disabled boolean is
> easier and clearer to use.
> 
> Fixes: 8fe24090d940 ("x86/cpuid: Rework HLE and RTM handling")
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>


Re: [PATCH] x86/spec-ctrl: Fix default calculation of opt_srb_lock
Posted by Jan Beulich 2 years, 3 months ago
On 04.01.2022 15:44, Andrew Cooper wrote:
> Since this logic was introduced, opt_tsx has become more complicated and
> shouldn't be compared to 0 directly.  While there are no buggy logic paths,
> the correct expression is !(opt_tsx & 1) but the rtm_disabled boolean is
> easier and clearer to use.
> 
> Fixes: 8fe24090d940 ("x86/cpuid: Rework HLE and RTM handling")

Is this accurate? Backporting the change to 4.13 locally, I notice that
commit (and hence the rtm_disabled global variable) is not present on
that branch, yet opt_tsx already has the "more complicated" behavior.

Jan