Skip to content

Commit 0dfac6f

Browse files
xinli-intelKAGA-KOKO
authored andcommitted
x86/entry: Test ti_work for zero before processing individual bits
In most cases, ti_work values passed to arch_exit_to_user_mode_prepare() are zeros, e.g., 99% in kernel build tests. So an obvious optimization is to test ti_work for zero before processing individual bits in it. Omit the optimization when FPU debugging is enabled, otherwise the FPU consistency check is never executed. Intel 0day tests did not find a perfermance regression with this change. Suggested-by: H. Peter Anvin (Intel) <[email protected]> Signed-off-by: Xin Li (Intel) <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent 723edbd commit 0dfac6f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/x86/include/asm/entry-common.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs)
4444
}
4545
#define arch_enter_from_user_mode arch_enter_from_user_mode
4646

47-
static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
48-
unsigned long ti_work)
47+
static inline void arch_exit_work(unsigned long ti_work)
4948
{
5049
if (ti_work & _TIF_USER_RETURN_NOTIFY)
5150
fire_user_return_notifiers();
@@ -56,6 +55,13 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
5655
fpregs_assert_state_consistent();
5756
if (unlikely(ti_work & _TIF_NEED_FPU_LOAD))
5857
switch_fpu_return();
58+
}
59+
60+
static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
61+
unsigned long ti_work)
62+
{
63+
if (IS_ENABLED(CONFIG_X86_DEBUG_FPU) || unlikely(ti_work))
64+
arch_exit_work(ti_work);
5965

6066
#ifdef CONFIG_COMPAT
6167
/*

0 commit comments

Comments
 (0)