Skip to content

Commit

Permalink
Merge tag 'arch-cleanup-2020-10-22' of git://git.kernel.dk/linux-block
Browse files Browse the repository at this point in the history
Pull arch task_work cleanups from Jens Axboe:
 "Two cleanups that don't fit other categories:

   - Finally get the task_work_add() cleanup done properly, so we don't
     have random 0/1/false/true/TWA_SIGNAL confusing use cases. Updates
     all callers, and also fixes up the documentation for
     task_work_add().

   - While working on some TIF related changes for 5.11, this
     TIF_NOTIFY_RESUME cleanup fell out of that. Remove some arch
     duplication for how that is handled"

* tag 'arch-cleanup-2020-10-22' of git://git.kernel.dk/linux-block:
  task_work: cleanup notification modes
  tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume()
  • Loading branch information
torvalds committed Oct 23, 2020
2 parents 0a14d76 + 91989c7 commit 4a22709
Show file tree
Hide file tree
Showing 41 changed files with 64 additions and 76 deletions.
1 change: 0 additions & 1 deletion arch/alpha/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ do_work_pending(struct pt_regs *regs, unsigned long thread_flags,
do_signal(regs, r0, r19);
r0 = 0;
} else {
clear_thread_flag(TIF_NOTIFY_RESUME);
tracehook_notify_resume(regs);
}
}
Expand Down
2 changes: 1 addition & 1 deletion arch/arc/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,6 @@ void do_notify_resume(struct pt_regs *regs)
* ASM glue gaurantees that this is only called when returning to
* user mode
*/
if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
if (test_thread_flag(TIF_NOTIFY_RESUME))
tracehook_notify_resume(regs);
}
1 change: 0 additions & 1 deletion arch/arm/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
} else if (thread_flags & _TIF_UPROBE) {
uprobe_notify_resume(regs);
} else {
clear_thread_flag(TIF_NOTIFY_RESUME);
tracehook_notify_resume(regs);
rseq_handle_notify_resume(NULL, regs);
}
Expand Down
1 change: 0 additions & 1 deletion arch/arm64/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,
do_signal(regs);

if (thread_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
tracehook_notify_resume(regs);
rseq_handle_notify_resume(NULL, regs);
}
Expand Down
4 changes: 1 addition & 3 deletions arch/c6x/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags,
if (thread_info_flags & (1 << TIF_SIGPENDING))
do_signal(regs, syscall);

if (thread_info_flags & (1 << TIF_NOTIFY_RESUME)) {
clear_thread_flag(TIF_NOTIFY_RESUME);
if (thread_info_flags & (1 << TIF_NOTIFY_RESUME))
tracehook_notify_resume(regs);
}
}
1 change: 0 additions & 1 deletion arch/csky/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,
do_signal(regs);

if (thread_info_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
tracehook_notify_resume(regs);
rseq_handle_notify_resume(NULL, regs);
}
Expand Down
4 changes: 1 addition & 3 deletions arch/h8300/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags)
if (thread_info_flags & _TIF_SIGPENDING)
do_signal(regs);

if (thread_info_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
if (thread_info_flags & _TIF_NOTIFY_RESUME)
tracehook_notify_resume(regs);
}
}
1 change: 0 additions & 1 deletion arch/hexagon/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
}

if (thread_info_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
tracehook_notify_resume(regs);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/ia64/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ do_notify_resume_user(sigset_t *unused, struct sigscratch *scr, long in_syscall)
ia64_do_signal(scr, in_syscall);
}

if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME)) {
if (test_thread_flag(TIF_NOTIFY_RESUME)) {
local_irq_enable(); /* force interrupt enable */
tracehook_notify_resume(&scr->pt);
}
Expand Down
2 changes: 1 addition & 1 deletion arch/m68k/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,6 @@ void do_notify_resume(struct pt_regs *regs)
if (test_thread_flag(TIF_SIGPENDING))
do_signal(regs);

if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
if (test_thread_flag(TIF_NOTIFY_RESUME))
tracehook_notify_resume(regs);
}
2 changes: 1 addition & 1 deletion arch/microblaze/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, int in_syscall)
if (test_thread_flag(TIF_SIGPENDING))
do_signal(regs, in_syscall);

if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
if (test_thread_flag(TIF_NOTIFY_RESUME))
tracehook_notify_resume(regs);
}
1 change: 0 additions & 1 deletion arch/mips/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
do_signal(regs);

if (thread_info_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
tracehook_notify_resume(regs);
rseq_handle_notify_resume(NULL, regs);
}
Expand Down
4 changes: 1 addition & 3 deletions arch/nds32/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,6 @@ do_notify_resume(struct pt_regs *regs, unsigned int thread_flags)
if (thread_flags & _TIF_SIGPENDING)
do_signal(regs);

if (thread_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
if (thread_flags & _TIF_NOTIFY_RESUME)
tracehook_notify_resume(regs);
}
}
2 changes: 1 addition & 1 deletion arch/nios2/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ asmlinkage int do_notify_resume(struct pt_regs *regs)
*/
return restart;
}
} else if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
} else if (test_thread_flag(TIF_NOTIFY_RESUME))
tracehook_notify_resume(regs);

return 0;
Expand Down
1 change: 0 additions & 1 deletion arch/openrisc/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
}
syscall = 0;
} else {
clear_thread_flag(TIF_NOTIFY_RESUME);
tracehook_notify_resume(regs);
}
}
Expand Down
4 changes: 1 addition & 3 deletions arch/parisc/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,6 @@ void do_notify_resume(struct pt_regs *regs, long in_syscall)
if (test_thread_flag(TIF_SIGPENDING))
do_signal(regs, in_syscall);

if (test_thread_flag(TIF_NOTIFY_RESUME)) {
clear_thread_flag(TIF_NOTIFY_RESUME);
if (test_thread_flag(TIF_NOTIFY_RESUME))
tracehook_notify_resume(regs);
}
}
1 change: 0 additions & 1 deletion arch/powerpc/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
}

if (thread_info_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
tracehook_notify_resume(regs);
rseq_handle_notify_resume(NULL, regs);
}
Expand Down
4 changes: 1 addition & 3 deletions arch/riscv/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ asmlinkage __visible void do_notify_resume(struct pt_regs *regs,
if (thread_info_flags & _TIF_SIGPENDING)
do_signal(regs);

if (thread_info_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
if (thread_info_flags & _TIF_NOTIFY_RESUME)
tracehook_notify_resume(regs);
}
}
1 change: 0 additions & 1 deletion arch/s390/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ void do_signal(struct pt_regs *regs)

void do_notify_resume(struct pt_regs *regs)
{
clear_thread_flag(TIF_NOTIFY_RESUME);
tracehook_notify_resume(regs);
rseq_handle_notify_resume(NULL, regs);
}
4 changes: 1 addition & 3 deletions arch/sh/kernel/signal_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned int save_r0,
if (thread_info_flags & _TIF_SIGPENDING)
do_signal(regs, save_r0);

if (thread_info_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
if (thread_info_flags & _TIF_NOTIFY_RESUME)
tracehook_notify_resume(regs);
}
}
4 changes: 1 addition & 3 deletions arch/sparc/kernel/signal_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,8 @@ void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0,
{
if (thread_info_flags & _TIF_SIGPENDING)
do_signal(regs, orig_i0);
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
if (thread_info_flags & _TIF_NOTIFY_RESUME)
tracehook_notify_resume(regs);
}
}

asmlinkage int do_sys_sigstack(struct sigstack __user *ssptr,
Expand Down
4 changes: 1 addition & 3 deletions arch/sparc/kernel/signal_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,8 @@ void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long
uprobe_notify_resume(regs);
if (thread_info_flags & _TIF_SIGPENDING)
do_signal(regs, orig_i0);
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
if (thread_info_flags & _TIF_NOTIFY_RESUME)
tracehook_notify_resume(regs);
}
user_enter();
}

2 changes: 1 addition & 1 deletion arch/um/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void interrupt_end(void)
schedule();
if (test_thread_flag(TIF_SIGPENDING))
do_signal(regs);
if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
if (test_thread_flag(TIF_NOTIFY_RESUME))
tracehook_notify_resume(regs);
}

Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/mce/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ static void queue_task_work(struct mce *m, int kill_it)
else
current->mce_kill_me.func = kill_me_maybe;

task_work_add(current, &current->mce_kill_me, true);
task_work_add(current, &current->mce_kill_me, TWA_RESUME);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/resctrl/rdtgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ static int __rdtgroup_move_task(struct task_struct *tsk,
* callback has been invoked.
*/
atomic_inc(&rdtgrp->waitcount);
ret = task_work_add(tsk, &callback->work, true);
ret = task_work_add(tsk, &callback->work, TWA_RESUME);
if (ret) {
/*
* Task is exiting. Drop the refcount and free the callback.
Expand Down
2 changes: 1 addition & 1 deletion arch/xtensa/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,6 @@ void do_notify_resume(struct pt_regs *regs)
if (test_thread_flag(TIF_SIGPENDING))
do_signal(regs);

if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
if (test_thread_flag(TIF_NOTIFY_RESUME))
tracehook_notify_resume(regs);
}
2 changes: 1 addition & 1 deletion drivers/acpi/apei/ghes.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ static void ghes_proc_in_irq(struct irq_work *irq_work)
estatus_node->task_work.func = ghes_kick_task_work;
estatus_node->task_work_cpu = smp_processor_id();
ret = task_work_add(current, &estatus_node->task_work,
true);
TWA_RESUME);
if (ret)
estatus_node->task_work.func = NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/android/binder.c
Original file line number Diff line number Diff line change
Expand Up @@ -2229,7 +2229,7 @@ static void binder_deferred_fd_close(int fd)
__close_fd_get_file(fd, &twcb->file);
if (twcb->file) {
filp_close(twcb->file, current->files);
task_work_add(current, &twcb->twork, true);
task_work_add(current, &twcb->twork, TWA_RESUME);
} else {
kfree(twcb);
}
Expand Down
2 changes: 1 addition & 1 deletion fs/file_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ void fput_many(struct file *file, unsigned int refs)

if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
init_task_work(&file->f_u.fu_rcuhead, ____fput);
if (!task_work_add(task, &file->f_u.fu_rcuhead, true))
if (!task_work_add(task, &file->f_u.fu_rcuhead, TWA_RESUME))
return;
/*
* After this task has run exit_task_work(),
Expand Down
13 changes: 7 additions & 6 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,8 @@ static int io_req_task_work_add(struct io_kiocb *req, bool twa_signal_ok)
{
struct task_struct *tsk = req->task;
struct io_ring_ctx *ctx = req->ctx;
int ret, notify;
enum task_work_notify_mode notify;
int ret;

if (tsk->flags & PF_EXITING)
return -ESRCH;
Expand All @@ -1987,7 +1988,7 @@ static int io_req_task_work_add(struct io_kiocb *req, bool twa_signal_ok)
* processing task_work. There's no reliable way to tell if TWA_RESUME
* will do the job.
*/
notify = 0;
notify = TWA_NONE;
if (!(ctx->flags & IORING_SETUP_SQPOLL) && twa_signal_ok)
notify = TWA_SIGNAL;

Expand Down Expand Up @@ -2056,7 +2057,7 @@ static void io_req_task_queue(struct io_kiocb *req)

init_task_work(&req->task_work, io_req_task_cancel);
tsk = io_wq_get_task(req->ctx->io_wq);
task_work_add(tsk, &req->task_work, 0);
task_work_add(tsk, &req->task_work, TWA_NONE);
wake_up_process(tsk);
}
}
Expand Down Expand Up @@ -2177,7 +2178,7 @@ static void io_free_req_deferred(struct io_kiocb *req)
struct task_struct *tsk;

tsk = io_wq_get_task(req->ctx->io_wq);
task_work_add(tsk, &req->task_work, 0);
task_work_add(tsk, &req->task_work, TWA_NONE);
wake_up_process(tsk);
}
}
Expand Down Expand Up @@ -3291,7 +3292,7 @@ static int io_async_buf_func(struct wait_queue_entry *wait, unsigned mode,
/* queue just for cancelation */
init_task_work(&req->task_work, io_req_task_cancel);
tsk = io_wq_get_task(req->ctx->io_wq);
task_work_add(tsk, &req->task_work, 0);
task_work_add(tsk, &req->task_work, TWA_NONE);
wake_up_process(tsk);
}
return 1;
Expand Down Expand Up @@ -4857,7 +4858,7 @@ static int __io_async_wake(struct io_kiocb *req, struct io_poll_iocb *poll,

WRITE_ONCE(poll->canceled, true);
tsk = io_wq_get_task(req->ctx->io_wq);
task_work_add(tsk, &req->task_work, 0);
task_work_add(tsk, &req->task_work, TWA_NONE);
wake_up_process(tsk);
}
return 1;
Expand Down
2 changes: 1 addition & 1 deletion fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ static void mntput_no_expire(struct mount *mnt)
struct task_struct *task = current;
if (likely(!(task->flags & PF_KTHREAD))) {
init_task_work(&mnt->mnt_rcu, __cleanup_mnt);
if (!task_work_add(task, &mnt->mnt_rcu, true))
if (!task_work_add(task, &mnt->mnt_rcu, TWA_RESUME))
return;
}
if (llist_add(&mnt->mnt_llist, &delayed_mntput_list))
Expand Down
11 changes: 8 additions & 3 deletions include/linux/task_work.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ init_task_work(struct callback_head *twork, task_work_func_t func)
twork->func = func;
}

#define TWA_RESUME 1
#define TWA_SIGNAL 2
int task_work_add(struct task_struct *task, struct callback_head *twork, int);
enum task_work_notify_mode {
TWA_NONE,
TWA_RESUME,
TWA_SIGNAL,
};

int task_work_add(struct task_struct *task, struct callback_head *twork,
enum task_work_notify_mode mode);

struct callback_head *task_work_cancel(struct task_struct *, task_work_func_t);
void task_work_run(void);
Expand Down
4 changes: 2 additions & 2 deletions include/linux/tracehook.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ static inline void set_notify_resume(struct task_struct *task)
*/
static inline void tracehook_notify_resume(struct pt_regs *regs)
{
clear_thread_flag(TIF_NOTIFY_RESUME);
/*
* The caller just cleared TIF_NOTIFY_RESUME. This barrier
* pairs with task_work_add()->set_notify_resume() after
* This barrier pairs with task_work_add()->set_notify_resume() after
* hlist_add_head(task->task_works);
*/
smp_mb__after_atomic();
Expand Down
1 change: 0 additions & 1 deletion kernel/entry/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ static unsigned long exit_to_user_mode_loop(struct pt_regs *regs,
arch_do_signal(regs);

if (ti_work & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
tracehook_notify_resume(regs);
rseq_handle_notify_resume(NULL, regs);
}
Expand Down
4 changes: 1 addition & 3 deletions kernel/entry/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)
if (ti_work & _TIF_NEED_RESCHED)
schedule();

if (ti_work & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
if (ti_work & _TIF_NOTIFY_RESUME)
tracehook_notify_resume(NULL);
}

ret = arch_xfer_to_guest_mode_handle_work(vcpu, ti_work);
if (ret)
Expand Down
2 changes: 1 addition & 1 deletion kernel/events/uprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ void uprobe_copy_process(struct task_struct *t, unsigned long flags)

t->utask->dup_xol_addr = area->vaddr;
init_task_work(&t->utask->dup_xol_work, dup_xol_work);
task_work_add(t, &t->utask->dup_xol_work, true);
task_work_add(t, &t->utask->dup_xol_work, TWA_RESUME);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion kernel/irq/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ static int irq_thread(void *data)
handler_fn = irq_thread_fn;

init_task_work(&on_exit_work, irq_thread_dtor);
task_work_add(current, &on_exit_work, false);
task_work_add(current, &on_exit_work, TWA_NONE);

irq_thread_check_affinity(desc, action);

Expand Down
Loading

0 comments on commit 4a22709

Please sign in to comment.