Skip to content

Commit dca99fb

Browse files
mrutland-armKAGA-KOKO
authored andcommitted
x86: Snapshot thread flags
Some thread flags can be set remotely, and so even when IRQs are disabled, the flags can change under our feet. Generally this is unlikely to cause a problem in practice, but it is somewhat unsound, and KCSAN will legitimately warn that there is a data race. To avoid such issues, a snapshot of the flags has to be taken prior to using them. Some places already use READ_ONCE() for that, others do not. Convert them all to the new flag accessor helpers. Signed-off-by: Mark Rutland <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Acked-by: Paul E. McKenney <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7ad6398 commit dca99fb

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

arch/x86/kernel/process.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void arch_setup_new_exec(void)
365365
clear_thread_flag(TIF_SSBD);
366366
task_clear_spec_ssb_disable(current);
367367
task_clear_spec_ssb_noexec(current);
368-
speculation_ctrl_update(task_thread_info(current)->flags);
368+
speculation_ctrl_update(read_thread_flags());
369369
}
370370
}
371371

@@ -617,7 +617,7 @@ static unsigned long speculation_ctrl_update_tif(struct task_struct *tsk)
617617
clear_tsk_thread_flag(tsk, TIF_SPEC_IB);
618618
}
619619
/* Return the updated threadinfo flags*/
620-
return task_thread_info(tsk)->flags;
620+
return read_task_thread_flags(tsk);
621621
}
622622

623623
void speculation_ctrl_update(unsigned long tif)
@@ -653,8 +653,8 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p)
653653
{
654654
unsigned long tifp, tifn;
655655

656-
tifn = READ_ONCE(task_thread_info(next_p)->flags);
657-
tifp = READ_ONCE(task_thread_info(prev_p)->flags);
656+
tifn = read_task_thread_flags(next_p);
657+
tifp = read_task_thread_flags(prev_p);
658658

659659
switch_to_bitmap(tifp);
660660

arch/x86/kernel/process.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p);
1313
static inline void switch_to_extra(struct task_struct *prev,
1414
struct task_struct *next)
1515
{
16-
unsigned long next_tif = task_thread_info(next)->flags;
17-
unsigned long prev_tif = task_thread_info(prev)->flags;
16+
unsigned long next_tif = read_task_thread_flags(next);
17+
unsigned long prev_tif = read_task_thread_flags(prev);
1818

1919
if (IS_ENABLED(CONFIG_SMP)) {
2020
/*

arch/x86/mm/tlb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static void l1d_flush_evaluate(unsigned long prev_mm, unsigned long next_mm,
361361

362362
static unsigned long mm_mangle_tif_spec_bits(struct task_struct *next)
363363
{
364-
unsigned long next_tif = task_thread_info(next)->flags;
364+
unsigned long next_tif = read_task_thread_flags(next);
365365
unsigned long spec_bits = (next_tif >> TIF_SPEC_IB) & LAST_USER_MM_SPEC_MASK;
366366

367367
/*

0 commit comments

Comments
 (0)