Skip to content

Commit 48a60bd

Browse files
committed
Merge tag 'core_entry_for_v5.17_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull thread_info flag accessor helper updates from Borislav Petkov: "Add a set of thread_info.flags accessors which snapshot it before accesing it in order to prevent any potential data races, and convert all users to those new accessors" * tag 'core_entry_for_v5.17_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: powerpc: Snapshot thread flags powerpc: Avoid discarding flags in system_call_exception() openrisc: Snapshot thread flags microblaze: Snapshot thread flags arm64: Snapshot thread flags ARM: Snapshot thread flags alpha: Snapshot thread flags sched: Snapshot thread flags entry: Snapshot thread flags x86: Snapshot thread flags thread_info: Add helpers to snapshot thread flags
2 parents 5ba13c1 + 985faa7 commit 48a60bd

File tree

19 files changed

+46
-34
lines changed

19 files changed

+46
-34
lines changed

arch/alpha/kernel/signal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,6 @@ do_work_pending(struct pt_regs *regs, unsigned long thread_flags,
535535
}
536536
}
537537
local_irq_disable();
538-
thread_flags = current_thread_info()->flags;
538+
thread_flags = read_thread_flags();
539539
} while (thread_flags & _TIF_WORK_MASK);
540540
}

arch/arm/kernel/signal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
631631
}
632632
}
633633
local_irq_disable();
634-
thread_flags = current_thread_info()->flags;
634+
thread_flags = read_thread_flags();
635635
} while (thread_flags & _TIF_WORK_MASK);
636636
return 0;
637637
}

arch/arm/mm/alignment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
990990
* there is no work pending for this thread.
991991
*/
992992
raw_local_irq_disable();
993-
if (!(current_thread_info()->flags & _TIF_WORK_MASK))
993+
if (!(read_thread_flags() & _TIF_WORK_MASK))
994994
set_cr(cr_no_alignment);
995995
}
996996

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);

arch/microblaze/kernel/signal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ static void do_signal(struct pt_regs *regs, int in_syscall)
283283
#ifdef DEBUG_SIG
284284
pr_info("do signal: %p %d\n", regs, in_syscall);
285285
pr_info("do signal2: %lx %lx %ld [%lx]\n", regs->pc, regs->r1,
286-
regs->r12, current_thread_info()->flags);
286+
regs->r12, read_thread_flags());
287287
#endif
288288

289289
if (get_signal(&ksig)) {

arch/openrisc/kernel/signal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
313313
}
314314
}
315315
local_irq_disable();
316-
thread_flags = current_thread_info()->flags;
316+
thread_flags = read_thread_flags();
317317
} while (thread_flags & _TIF_WORK_MASK);
318318
return 0;
319319
}

arch/powerpc/kernel/interrupt.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ notrace long system_call_exception(long r3, long r4, long r5,
148148
*/
149149
if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) &&
150150
unlikely(MSR_TM_TRANSACTIONAL(regs->msr)))
151-
current_thread_info()->flags |= _TIF_RESTOREALL;
151+
set_bits(_TIF_RESTOREALL, &current_thread_info()->flags);
152152

153153
/*
154154
* If the system call was made with a transaction active, doom it and
@@ -181,7 +181,7 @@ notrace long system_call_exception(long r3, long r4, long r5,
181181

182182
local_irq_enable();
183183

184-
if (unlikely(current_thread_info()->flags & _TIF_SYSCALL_DOTRACE)) {
184+
if (unlikely(read_thread_flags() & _TIF_SYSCALL_DOTRACE)) {
185185
if (unlikely(trap_is_unsupported_scv(regs))) {
186186
/* Unsupported scv vector */
187187
_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
@@ -343,7 +343,7 @@ interrupt_exit_user_prepare_main(unsigned long ret, struct pt_regs *regs)
343343
unsigned long ti_flags;
344344

345345
again:
346-
ti_flags = READ_ONCE(current_thread_info()->flags);
346+
ti_flags = read_thread_flags();
347347
while (unlikely(ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) {
348348
local_irq_enable();
349349
if (ti_flags & _TIF_NEED_RESCHED) {
@@ -359,7 +359,7 @@ interrupt_exit_user_prepare_main(unsigned long ret, struct pt_regs *regs)
359359
do_notify_resume(regs, ti_flags);
360360
}
361361
local_irq_disable();
362-
ti_flags = READ_ONCE(current_thread_info()->flags);
362+
ti_flags = read_thread_flags();
363363
}
364364

365365
if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && IS_ENABLED(CONFIG_PPC_FPU)) {
@@ -437,7 +437,7 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,
437437
/* Check whether the syscall is issued inside a restartable sequence */
438438
rseq_syscall(regs);
439439

440-
ti_flags = current_thread_info()->flags;
440+
ti_flags = read_thread_flags();
441441

442442
if (unlikely(r3 >= (unsigned long)-MAX_ERRNO) && is_not_scv) {
443443
if (likely(!(ti_flags & (_TIF_NOERROR | _TIF_RESTOREALL)))) {
@@ -532,8 +532,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)
532532
unsigned long flags;
533533
unsigned long ret = 0;
534534
unsigned long kuap;
535-
bool stack_store = current_thread_info()->flags &
536-
_TIF_EMULATE_STACK_STORE;
535+
bool stack_store = read_thread_flags() & _TIF_EMULATE_STACK_STORE;
537536

538537
if (regs_is_unrecoverable(regs))
539538
unrecoverable_exception(regs);
@@ -554,7 +553,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)
554553
again:
555554
if (IS_ENABLED(CONFIG_PREEMPT)) {
556555
/* Return to preemptible kernel context */
557-
if (unlikely(current_thread_info()->flags & _TIF_NEED_RESCHED)) {
556+
if (unlikely(read_thread_flags() & _TIF_NEED_RESCHED)) {
558557
if (preempt_count() == 0)
559558
preempt_schedule_irq();
560559
}

0 commit comments

Comments
 (0)