Skip to content

Commit 6ce8951

Browse files
mrutland-armKAGA-KOKO
authored andcommitted
entry: 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]> Acked-by: Paul E. McKenney <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent dca99fb commit 6ce8951

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

include/linux/entry-kvm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static inline void xfer_to_guest_mode_prepare(void)
7575
*/
7676
static inline bool __xfer_to_guest_mode_work_pending(void)
7777
{
78-
unsigned long ti_work = READ_ONCE(current_thread_info()->flags);
78+
unsigned long ti_work = read_thread_flags();
7979

8080
return !!(ti_work & XFER_TO_GUEST_MODE_WORK);
8181
}

kernel/entry/common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static unsigned long exit_to_user_mode_loop(struct pt_regs *regs,
187187
/* Check if any of the above work has queued a deferred wakeup */
188188
tick_nohz_user_enter_prepare();
189189

190-
ti_work = READ_ONCE(current_thread_info()->flags);
190+
ti_work = read_thread_flags();
191191
}
192192

193193
/* Return the latest work state for arch_exit_to_user_mode() */
@@ -196,7 +196,7 @@ static unsigned long exit_to_user_mode_loop(struct pt_regs *regs,
196196

197197
static void exit_to_user_mode_prepare(struct pt_regs *regs)
198198
{
199-
unsigned long ti_work = READ_ONCE(current_thread_info()->flags);
199+
unsigned long ti_work = read_thread_flags();
200200

201201
lockdep_assert_irqs_disabled();
202202

kernel/entry/kvm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)
2626
if (ret)
2727
return ret;
2828

29-
ti_work = READ_ONCE(current_thread_info()->flags);
29+
ti_work = read_thread_flags();
3030
} while (ti_work & XFER_TO_GUEST_MODE_WORK || need_resched());
3131
return 0;
3232
}
@@ -43,7 +43,7 @@ int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu)
4343
* disabled in the inner loop before going into guest mode. No need
4444
* to disable interrupts here.
4545
*/
46-
ti_work = READ_ONCE(current_thread_info()->flags);
46+
ti_work = read_thread_flags();
4747
if (!(ti_work & XFER_TO_GUEST_MODE_WORK))
4848
return 0;
4949

0 commit comments

Comments
 (0)