Skip to content

Commit 342b380

Browse files
mrutland-armKAGA-KOKO
authored andcommitted
arm64: 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: Will Deacon <[email protected]> Acked-by: Paul E. McKenney <[email protected]> Cc: Catalin Marinas <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 050e22b commit 342b380

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

arch/arm64/kernel/entry-common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static __always_inline void prepare_exit_to_user_mode(struct pt_regs *regs)
129129

130130
local_daif_mask();
131131

132-
flags = READ_ONCE(current_thread_info()->flags);
132+
flags = read_thread_flags();
133133
if (unlikely(flags & _TIF_WORK_MASK))
134134
do_notify_resume(regs, flags);
135135
}

arch/arm64/kernel/ptrace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@ static void tracehook_report_syscall(struct pt_regs *regs,
18391839

18401840
int syscall_trace_enter(struct pt_regs *regs)
18411841
{
1842-
unsigned long flags = READ_ONCE(current_thread_info()->flags);
1842+
unsigned long flags = read_thread_flags();
18431843

18441844
if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) {
18451845
tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
@@ -1862,7 +1862,7 @@ int syscall_trace_enter(struct pt_regs *regs)
18621862

18631863
void syscall_trace_exit(struct pt_regs *regs)
18641864
{
1865-
unsigned long flags = READ_ONCE(current_thread_info()->flags);
1865+
unsigned long flags = read_thread_flags();
18661866

18671867
audit_syscall_exit(regs);
18681868

arch/arm64/kernel/signal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_flags)
948948
}
949949

950950
local_daif_mask();
951-
thread_flags = READ_ONCE(current_thread_info()->flags);
951+
thread_flags = read_thread_flags();
952952
} while (thread_flags & _TIF_WORK_MASK);
953953
}
954954

arch/arm64/kernel/syscall.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void syscall_trace_exit(struct pt_regs *regs);
8181
static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,
8282
const syscall_fn_t syscall_table[])
8383
{
84-
unsigned long flags = current_thread_info()->flags;
84+
unsigned long flags = read_thread_flags();
8585

8686
regs->orig_x0 = regs->regs[0];
8787
regs->syscallno = scno;
@@ -148,7 +148,7 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,
148148
*/
149149
if (!has_syscall_work(flags) && !IS_ENABLED(CONFIG_DEBUG_RSEQ)) {
150150
local_daif_mask();
151-
flags = current_thread_info()->flags;
151+
flags = read_thread_flags();
152152
if (!has_syscall_work(flags) && !(flags & _TIF_SINGLESTEP))
153153
return;
154154
local_daif_restore(DAIF_PROCCTX);

0 commit comments

Comments
 (0)