Skip to contentSkip to conversation

x86/mm: Inline mm_mangle_tif_spec_bits() and l1d_flush_evaluate()

PATCH In review Khalid Ali 2 participants 2 messages Jun 23, 2025

Subsystems (2)
lore
Share & tools
lore

Khalid Ali

author
#0 lore raw

PATCH 1/1 x86/mm: Inline mm_mangle_tif_spec_bits() and l1d_flush_evaluate()

From: Khalid Ali <[email protected]>

These two functions are called from performance critical path like context switch.

So make sure the compiler optimizes out by inlining. This won't result increase of size because these functions only have one call site.

---
 arch/x86/mm/tlb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/mm/tlb.c +2 -2
index 39f80111e6f1..657e8e254b69 100644
@@ -624,7 +624,7 @@ static void l1d_flush_force_sigbus(struct callback_head *ch)
 	force_sig(SIGBUS);
 }
 
-static void l1d_flush_evaluate(unsigned long prev_mm, unsigned long next_mm,
+static __always_inline void l1d_flush_evaluate(unsigned long prev_mm, unsigned long next_mm,
 				struct task_struct *next)
 {
 	/* Flush L1D if the outgoing task requests it */
@@ -648,7 +648,7 @@ static void l1d_flush_evaluate(unsigned long prev_mm, unsigned long next_mm,
 	}
 }
 
-static unsigned long mm_mangle_tif_spec_bits(struct task_struct *next)
+static __always_inline unsigned long mm_mangle_tif_spec_bits(struct task_struct *next)
 {
 	unsigned long next_tif = read_task_thread_flags(next);
 	unsigned long spec_bits = (next_tif >> TIF_SPEC_IB) & LAST_USER_MM_SPEC_MASK;
Signature · 1 line
2.49.0
#1 lore raw
Quoted 5 lines · Khalid Ali

These two functions are called from performance critical path like context switch.

So make sure the compiler optimizes out by inlining. This won't result increase of size because these functions only have one call site.

Khalid,

The compiler is currently given the latitude to choose an inlining strategy for these functions. Generally, I'd assume that it's doing something sane unless there's a specific compiler making suboptimal decisions.

Do you have some evidence that compilers are doing the wrong thing? Perhaps some generated code that looks wrong to you or some evidence that the proposed change improves performance?