Skip to contentSkip to conversation

x86/speculation: Change STIPB to STIBP

PATCH In review Waiman Long 4 participants 7 messages Dec 5, 2018 – Dec 7, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 x86/speculation: Change STIPB to STIBP

STIBP stands for Single Thread Indirect Branch Predictors. The acronym, however, can be easily mis-spelled as STIPB. It is perhaps due to the presence of another related term - IBPB (Indirect Branch Predictor Barrier).

Fix the mis-spelling in the code.

---
 arch/x86/kernel/cpu/bugs.c | 6 +++---
 arch/x86/kernel/process.h  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/bugs.c +3 -3
index 500278f..a68b32c 100644
@@ -54,7 +54,7 @@
 u64 __ro_after_init x86_amd_ls_cfg_base;
 u64 __ro_after_init x86_amd_ls_cfg_ssbd_mask;
 
-/* Control conditional STIPB in switch_to() */
+/* Control conditional STIBP in switch_to() */
 DEFINE_STATIC_KEY_FALSE(switch_to_cond_stibp);
 /* Control conditional IBPB in switch_mm() */
 DEFINE_STATIC_KEY_FALSE(switch_mm_cond_ibpb);
@@ -379,12 +379,12 @@ static void __init spec_v2_user_print_cond(const char *reason, bool secure)
 			"always-on" : "conditional");
 	}
 
-	/* If enhanced IBRS is enabled no STIPB required */
+	/* If enhanced IBRS is enabled no STIBP required */
 	if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
 		return;
 
 	/*
-	 * If SMT is not possible or STIBP is not available clear the STIPB
+	 * If SMT is not possible or STIBP is not available clear the STIBP
 	 * mode.
 	 */
 	if (!smt_possible || !boot_cpu_has(X86_FEATURE_STIBP))
arch/x86/kernel/process.h +1 -1
index 898e97c..320ab97 100644
@@ -19,7 +19,7 @@ static inline void switch_to_extra(struct task_struct *prev,
 	if (IS_ENABLED(CONFIG_SMP)) {
 		/*
 		 * Avoid __switch_to_xtra() invocation when conditional
-		 * STIPB is disabled and the only different bit is
+		 * STIBP is disabled and the only different bit is
 		 * TIF_SPEC_IB. For CONFIG_SMP=n TIF_SPEC_IB is not
 		 * in the TIF_WORK_CTXSW masks.
 		 */
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 2/2 x86/speculation: switch_to_cond_stibp on is the likely case

Since conditional STIBP is the default, it should be treated as the likely case. Changes the use of static_branch_unlikely() to static_branch_likely() for switch_to_cond_stibp.

---
 arch/x86/kernel/cpu/bugs.c | 2 +-
 arch/x86/kernel/process.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/bugs.c +1 -1
index a68b32c..bd11119 100644
@@ -153,7 +153,7 @@ void __init check_bugs(void)
 			hostval |= ssbd_tif_to_spec_ctrl(ti->flags);
 
 		/* Conditional STIBP enabled? */
-		if (static_branch_unlikely(&switch_to_cond_stibp))
+		if (static_branch_likely(&switch_to_cond_stibp))
 			hostval |= stibp_tif_to_spec_ctrl(ti->flags);
 
 		if (hostval != guestval) {
arch/x86/kernel/process.c +1 -1
index 7d31192..39a21ae 100644
@@ -434,7 +434,7 @@ static __always_inline void __speculation_ctrl_update(unsigned long tifp,
 	 * otherwise avoid the MSR write.
 	 */
 	if (IS_ENABLED(CONFIG_SMP) &&
-	    static_branch_unlikely(&switch_to_cond_stibp)) {
+	    static_branch_likely(&switch_to_cond_stibp)) {
 		updmsr |= !!(tif_diff & _TIF_SPEC_IB);
 		msr |= stibp_tif_to_spec_ctrl(tifn);
 	}
Signature · 1 line
1.8.3.1
maintainer
#2 lore raw

Re: [PATCH 2/2] x86/speculation: switch_to_cond_stibp on is the likely case

Quoted 3 lines · Waiman Long

Since conditional STIBP is the default, it should be treated as the likely case. Changes the use of static_branch_unlikely() to static_branch_likely() for switch_to_cond_stibp.

So now you're making kernels on 'fixed' or unaffected hardware slower.

Quoted 35 lines
---
 arch/x86/kernel/cpu/bugs.c | 2 +-
 arch/x86/kernel/process.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/bugs.c +1 -1
index a68b32c..bd11119 100644
@@ -153,7 +153,7 @@ void __init check_bugs(void)
 			hostval |= ssbd_tif_to_spec_ctrl(ti->flags);
 
 		/* Conditional STIBP enabled? */
-		if (static_branch_unlikely(&switch_to_cond_stibp))
+		if (static_branch_likely(&switch_to_cond_stibp))
 			hostval |= stibp_tif_to_spec_ctrl(ti->flags);
 
 		if (hostval != guestval) {
arch/x86/kernel/process.c +1 -1
index 7d31192..39a21ae 100644
@@ -434,7 +434,7 @@ static __always_inline void __speculation_ctrl_update(unsigned long tifp,
 	 * otherwise avoid the MSR write.
 	 */
 	if (IS_ENABLED(CONFIG_SMP) &&
-	    static_branch_unlikely(&switch_to_cond_stibp)) {
+	    static_branch_likely(&switch_to_cond_stibp)) {
 		updmsr |= !!(tif_diff & _TIF_SPEC_IB);
 		msr |= stibp_tif_to_spec_ctrl(tifn);
 	}
Signature · 1 line
1.8.3.1
#3 lore raw

Re: [PATCH 2/2] x86/speculation: switch_to_cond_stibp on is the likely case

Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Waiman Long

Since conditional STIBP is the default, it should be treated as the likely case. Changes the use of static_branch_unlikely() to static_branch_likely() for switch_to_cond_stibp.

So now you're making kernels on 'fixed' or unaffected hardware slower.

Good point.

The reason I sent out this patch is because of the inconsistency in the use of likely/unlikely hints.

arch/x86/kernel/cpu/bugs.c:156:        if
(static_branch_unlikely(&switch_to_cond_stibp))
arch/x86/kernel/process.c:440:
static_branch_unlikely(&switch_to_cond_stibp)) {
arch/x86/kernel/process.h:26:        if
(!static_branch_likely(&switch_to_cond_stibp)) {

So if we are aiming to optimize for "fixed" or unaffected hardware, maybe we should modify the likely hint to unlikely then.

Cheers,
Longman

maintainer
#4 lore raw

Re: [PATCH 2/2] x86/speculation: switch_to_cond_stibp on is the likely case

Quoted 19 lines · Waiman Long
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Waiman Long

Since conditional STIBP is the default, it should be treated as the likely case. Changes the use of static_branch_unlikely() to static_branch_likely() for switch_to_cond_stibp.

So now you're making kernels on 'fixed' or unaffected hardware slower.

Good point.

The reason I sent out this patch is because of the inconsistency in the use of likely/unlikely hints.

arch/x86/kernel/cpu/bugs.c:156:        if
(static_branch_unlikely(&switch_to_cond_stibp))
arch/x86/kernel/process.c:440:
static_branch_unlikely(&switch_to_cond_stibp)) {
arch/x86/kernel/process.h:26:        if
(!static_branch_likely(&switch_to_cond_stibp)) {

Quoted 2 lines

So if we are aiming to optimize for "fixed" or unaffected hardware, maybe we should modify the likely hint to unlikely then.

Right, I think that makes sense, Thomas?

#5 lore raw

Re: [PATCH 2/2] x86/speculation: switch_to_cond_stibp on is the likely case

Quoted 20 lines · Peter Zijlstra
Quoted 19 lines · Waiman Long
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Waiman Long

Since conditional STIBP is the default, it should be treated as the likely case. Changes the use of static_branch_unlikely() to static_branch_likely() for switch_to_cond_stibp.

So now you're making kernels on 'fixed' or unaffected hardware slower.

Good point.

The reason I sent out this patch is because of the inconsistency in the use of likely/unlikely hints.

arch/x86/kernel/cpu/bugs.c:156:        if
(static_branch_unlikely(&switch_to_cond_stibp))
arch/x86/kernel/process.c:440:
static_branch_unlikely(&switch_to_cond_stibp)) {
arch/x86/kernel/process.h:26:        if
(!static_branch_likely(&switch_to_cond_stibp)) {

Quoted 4 lines
Quoted 2 lines

So if we are aiming to optimize for "fixed" or unaffected hardware, maybe we should modify the likely hint to unlikely then.

Right, I think that makes sense, Thomas?

Yeah, I probably got that wrong in some places. Let me look.

Thanks,

Thomas

#6 lore raw

[tip:x86/pti] x86/speculation: Change misspelled STIPB to STIBP

In reply to Waiman Long
x86/speculation: Change misspelled STIPB to STIBP
Commit-ID:  aa77bfb354c495fc4361199e63fc5765b9e1e783
Gitweb:     https://git.kernel.org/tip/aa77bfb354c495fc4361199e63fc5765b9e1e783
Author:     Waiman Long <[email protected]>
AuthorDate: Wed, 5 Dec 2018 14:49:27 -0500
Committer:  Borislav Petkov <[email protected]>
CommitDate: Thu, 6 Dec 2018 11:49:15 +0100

x86/speculation: Change misspelled STIPB to STIBP

STIBP stands for Single Thread Indirect Branch Predictors. The acronym, however, can be easily mis-spelled as STIPB. It is perhaps due to the presence of another related term - IBPB (Indirect Branch Predictor Barrier).

Fix the mis-spelling in the code.

Cc "H. Peter Anvin" <[email protected]>
Cc Andi Kleen <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Kosina <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc KarimAllah Ahmed <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Tim Chen <[email protected]>
Cc x86-ml <[email protected]>
---
 arch/x86/kernel/cpu/bugs.c | 6 +++---
 arch/x86/kernel/process.h  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/bugs.c +3 -3
index 500278f5308e..a68b32cb845a 100644
@@ -54,7 +54,7 @@ static u64 __ro_after_init x86_spec_ctrl_mask = SPEC_CTRL_IBRS;
 u64 __ro_after_init x86_amd_ls_cfg_base;
 u64 __ro_after_init x86_amd_ls_cfg_ssbd_mask;
 
-/* Control conditional STIPB in switch_to() */
+/* Control conditional STIBP in switch_to() */
 DEFINE_STATIC_KEY_FALSE(switch_to_cond_stibp);
 /* Control conditional IBPB in switch_mm() */
 DEFINE_STATIC_KEY_FALSE(switch_mm_cond_ibpb);
@@ -379,12 +379,12 @@ spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)
 			"always-on" : "conditional");
 	}
 
-	/* If enhanced IBRS is enabled no STIPB required */
+	/* If enhanced IBRS is enabled no STIBP required */
 	if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
 		return;
 
 	/*
-	 * If SMT is not possible or STIBP is not available clear the STIPB
+	 * If SMT is not possible or STIBP is not available clear the STIBP
 	 * mode.
 	 */
 	if (!smt_possible || !boot_cpu_has(X86_FEATURE_STIBP))
arch/x86/kernel/process.h +1 -1
index 898e97cf6629..320ab978fb1f 100644
@@ -19,7 +19,7 @@ static inline void switch_to_extra(struct task_struct *prev,
 	if (IS_ENABLED(CONFIG_SMP)) {
 		/*
 		 * Avoid __switch_to_xtra() invocation when conditional
-		 * STIPB is disabled and the only different bit is
+		 * STIBP is disabled and the only different bit is
 		 * TIF_SPEC_IB. For CONFIG_SMP=n TIF_SPEC_IB is not
 		 * in the TIF_WORK_CTXSW masks.
 		 */