Skip to contentSkip to conversation

x86/spec-ctrl: Fix default calculation of opt_srb_lock

PATCH In review Andrew Cooper 2 participants 3 messages Jan 4, 2022 – Jan 5, 2022

lore
Share & tools
lore
#0 lore raw

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

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")

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/x86/spec_ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/spec_ctrl.c +1 -1
index a5569c7f2b3f..c18cc8aa493a 100644
@@ -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;
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Andrew Cooper

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")
#2 lore raw
In reply to Andrew Cooper
Quoted 6 lines · Andrew Cooper

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