[PATCH v4 03/11] x86/bhi: Make the depth of BHB-clearing configurable

Pawan Gupta posted 11 patches 1 week, 4 days ago
There is a newer version of this series
[PATCH v4 03/11] x86/bhi: Make the depth of BHB-clearing configurable
Posted by Pawan Gupta 1 week, 4 days ago
The BHB clearing sequence has two nested loops that determine the depth of
BHB to be cleared. Introduce an argument to the macro to allow the loop
count (and hence the depth) to be controlled from outside the macro.

Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
---
 arch/x86/entry/entry_64.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index a62dbc89c5e75b955ebf6d84f20d157d4bce0253..a2891af416c874349c065160708752c41bc6ba36 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -1527,8 +1527,8 @@ SYM_CODE_END(rewind_stack_and_make_dead)
  * Note, callers should use a speculation barrier like LFENCE immediately after
  * a call to this function to ensure BHB is cleared before indirect branches.
  */
-.macro	CLEAR_BHB_LOOP_SEQ
-	movl	$5, %ecx
+.macro	CLEAR_BHB_LOOP_SEQ outer_loop_count:req, inner_loop_count:req
+	movl	$\outer_loop_count, %ecx
 	ANNOTATE_INTRA_FUNCTION_CALL
 	call	1f
 	jmp	5f
@@ -1550,7 +1550,7 @@ SYM_CODE_END(rewind_stack_and_make_dead)
 	 * but some Clang versions (e.g. 18) don't like this.
 	 */
 	.skip 32 - 18, 0xcc
-2:	movl	$5, %eax
+2:	movl	$\inner_loop_count, %eax
 3:	jmp	4f
 	nop
 4:	sub	$1, %eax
@@ -1573,7 +1573,7 @@ SYM_FUNC_START(clear_bhb_loop)
 	push	%rbp
 	mov	%rsp, %rbp
 
-	CLEAR_BHB_LOOP_SEQ
+	CLEAR_BHB_LOOP_SEQ 5, 5
 
 	pop	%rbp
 	RET

-- 
2.34.1
Re: [PATCH v4 03/11] x86/bhi: Make the depth of BHB-clearing configurable
Posted by Nikolay Borisov 1 week, 4 days ago

On 11/20/25 08:18, Pawan Gupta wrote:
> The BHB clearing sequence has two nested loops that determine the depth of
> BHB to be cleared. Introduce an argument to the macro to allow the loop
> count (and hence the depth) to be controlled from outside the macro.
> 
> Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>

Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>