Skip to contentSkip to conversation

Add support for TIF_NOTIFY_SIGNAL

PATCH Superseded Jens Axboe 3 participants 46 messages Oct 15, 2020 – Oct 20, 2020

Subsystems (26)
Arm (32-bit) x86 PowerPC MIPS +22 more subsystems

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH v5 1/1 Add support for TIF_NOTIFY_SIGNAL

Hi,

The goal is this patch series is to decouple TWA_SIGNAL based task_work from real signals and signal delivery. The motivation is speeding up TWA_SIGNAL based task_work, particularly for threaded setups where ->sighand is shared across threads. See the last patch for numbers.

 arch/alpha/kernel/signal.c         |  1 -
 arch/arc/kernel/signal.c           |  2 +-
 arch/arm/kernel/signal.c           |  1 -
 arch/arm64/kernel/signal.c         |  1 -
 arch/c6x/kernel/signal.c           |  4 +--
 arch/csky/kernel/signal.c          |  1 -
 arch/h8300/kernel/signal.c         |  4 +--
 arch/hexagon/kernel/process.c      |  1 -
 arch/ia64/kernel/process.c         |  2 +-
 arch/m68k/kernel/signal.c          |  2 +-
 arch/microblaze/kernel/signal.c    |  2 +-
 arch/mips/kernel/signal.c          |  1 -
 arch/nds32/kernel/signal.c         |  4 +--
 arch/nios2/kernel/signal.c         |  2 +-
 arch/openrisc/kernel/signal.c      |  1 -
 arch/parisc/kernel/signal.c        |  4 +--
 arch/powerpc/kernel/signal.c       |  1 -
 arch/riscv/kernel/signal.c         |  4 +--
 arch/s390/kernel/signal.c          |  1 -
 arch/sh/kernel/signal_32.c         |  4 +--
 arch/sparc/kernel/signal_32.c      |  4 +--
 arch/sparc/kernel/signal_64.c      |  4 +--
 arch/um/kernel/process.c           |  2 +-
 arch/x86/include/asm/thread_info.h |  2 ++
 arch/x86/kernel/signal.c           |  7 +++--
 arch/xtensa/kernel/signal.c        |  2 +-
 include/linux/entry-common.h       |  9 +++++--
 include/linux/entry-kvm.h          |  4 +--
 include/linux/sched/signal.h       | 20 ++++++++++++---
 include/linux/tracehook.h          | 31 ++++++++++++++++++++--
 kernel/entry/common.c              |  7 +++--
 kernel/entry/kvm.c                 |  7 ++---
 kernel/events/uprobes.c            |  2 +-
 kernel/signal.c                    |  8 +++---
 kernel/task_work.c                 | 41 +++++++++++++++++++++---------
 35 files changed, 118 insertions(+), 75 deletions(-)

Changes since v4:
- Change ifdef as per Thomas
- Split x86 change from generic entry code
- Pass in TIF flags for arch_do_signal() to avoid doing multiple bit tests

Signature · 1 line
Jens Axboe
author maintainer
#1 lore raw

PATCH 1/5 tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume()

All the callers currently do this, clean it up and move the clearing into tracehook_notify_resume() instead.

---
 arch/alpha/kernel/signal.c      | 1 -
 arch/arc/kernel/signal.c        | 2 +-
 arch/arm/kernel/signal.c        | 1 -
 arch/arm64/kernel/signal.c      | 1 -
 arch/c6x/kernel/signal.c        | 4 +---
 arch/csky/kernel/signal.c       | 1 -
 arch/h8300/kernel/signal.c      | 4 +---
 arch/hexagon/kernel/process.c   | 1 -
 arch/ia64/kernel/process.c      | 2 +-
 arch/m68k/kernel/signal.c       | 2 +-
 arch/microblaze/kernel/signal.c | 2 +-
 arch/mips/kernel/signal.c       | 1 -
 arch/nds32/kernel/signal.c      | 4 +---
 arch/nios2/kernel/signal.c      | 2 +-
 arch/openrisc/kernel/signal.c   | 1 -
 arch/parisc/kernel/signal.c     | 4 +---
 arch/powerpc/kernel/signal.c    | 1 -
 arch/riscv/kernel/signal.c      | 4 +---
 arch/s390/kernel/signal.c       | 1 -
 arch/sh/kernel/signal_32.c      | 4 +---
 arch/sparc/kernel/signal_32.c   | 4 +---
 arch/sparc/kernel/signal_64.c   | 4 +---
 arch/um/kernel/process.c        | 2 +-
 arch/xtensa/kernel/signal.c     | 2 +-
 include/linux/tracehook.h       | 4 ++--
 kernel/entry/common.c           | 1 -
 kernel/entry/kvm.c              | 4 +---
 27 files changed, 18 insertions(+), 46 deletions(-)
arch/alpha/kernel/signal.c +0 -1
index 15bc9d1e79f4..3739efce1ec0 100644
@@ -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);
 			}
 		}
arch/arc/kernel/signal.c +1 -1
index 8222f8c54690..2be55fb96d87 100644
@@ -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);
 }
arch/arm/kernel/signal.c +0 -1
index c1892f733f20..585edbfccf6d 100644
@@ -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);
 			}
arch/arm64/kernel/signal.c +0 -1
index 3b4f31f35e45..4a6e1dc480c1 100644
@@ -936,7 +936,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);
 			}
arch/c6x/kernel/signal.c +1 -3
index d05c78eace1b..a3f15b9a79da 100644
@@ -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);
-	}
 }
arch/csky/kernel/signal.c +0 -1
index 970895df75ec..8b068cf37447 100644
@@ -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);
 	}
arch/h8300/kernel/signal.c +1 -3
index 69e68949787f..75d9b7e626b2 100644
@@ -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);
-	}
 }
arch/hexagon/kernel/process.c +0 -1
index dfd322c5ce83..5a0a95d93ddb 100644
@@ -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;
 	}
arch/ia64/kernel/process.c +1 -1
index f19cb97c0098..8f96cdda2f09 100644
@@ -189,7 +189,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);
 	}
arch/m68k/kernel/signal.c +1 -1
index a98fca977073..29e174a80bf6 100644
@@ -1134,6 +1134,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);
 }
arch/microblaze/kernel/signal.c +1 -1
index 4a96b59f0bee..f11a0ccccabc 100644
@@ -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);
 }
arch/mips/kernel/signal.c +0 -1
index a0262729cd4c..77d40126b8a9 100644
@@ -901,7 +901,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);
 	}
arch/nds32/kernel/signal.c +1 -3
index 36e25a410bb0..2acb94812af9 100644
@@ -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);
-	}
 }
arch/nios2/kernel/signal.c +1 -1
index d8a087cf2b42..cf2dca2ac7c3 100644
@@ -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;
arch/openrisc/kernel/signal.c +0 -1
index c779364f0cd0..af66f968dd45 100644
@@ -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);
 			}
 		}
arch/parisc/kernel/signal.c +1 -3
index 3c037fc96038..9f43eaeb0b0a 100644
@@ -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);
-	}
 }
arch/powerpc/kernel/signal.c +0 -1
index d15a98c758b8..74a94a125f0d 100644
@@ -327,7 +327,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);
 	}
arch/riscv/kernel/signal.c +1 -3
index e996e08f1061..bc6841867b51 100644
@@ -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);
-	}
 }
arch/s390/kernel/signal.c +0 -1
index b295090e2ce6..9e900a8977bd 100644
@@ -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);
 }
arch/sh/kernel/signal_32.c +1 -3
index 4fe3f00137bc..1add47fd31f6 100644
@@ -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);
-	}
 }
arch/sparc/kernel/signal_32.c +1 -3
index d0e0025ee3ba..741d0701003a 100644
@@ -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,
arch/sparc/kernel/signal_64.c +1 -3
index 255264bcb46a..f7ef7edcd5c1 100644
@@ -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();
 }
 
arch/um/kernel/process.c +1 -1
index 26b5e243d3fc..3bed09538dd9 100644
@@ -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);
 }
 
arch/xtensa/kernel/signal.c +1 -1
index b3b17d6c50f0..1fb1047f905c 100644
@@ -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);
 }
include/linux/tracehook.h +2 -2
index 36fb3bbed6b2..b480e1a07ed8 100644
@@ -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();
kernel/entry/common.c +0 -1
index 6fdb6105e6d6..d20ab4ac7183 100644
@@ -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);
 		}
kernel/entry/kvm.c +1 -3
index eb1a8a4c867c..b6678a5e3cf6 100644
@@ -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)
Signature · 1 line
2.28.0
author maintainer
#3 lore raw

Re: [PATCH 1/5] tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume()

Quoted 11 lines · Oleg Nesterov
Quoted 6 lines · Jens Axboe

All the callers currently do this, clean it up and move the clearing into tracehook_notify_resume() instead.

in case you didn't notice I already acked this change ;)

Apparently I missed that - thanks, added!

Signature · 1 line
Jens Axboe
author maintainer
#4 lore raw

PATCH 2/5 kernel: add task_sigpending() helper

In reply to Jens Axboe

This is in preparation for maintaining signal_pending() as the decider of whether or not a schedule() loop should be broken, or continue sleeping. This is different than the core signal use cases, where we really want to know if an actual signal is pending or not. task_sigpending() returns non-zero if TIF_SIGPENDING is set.

Only core kernel use cases should care about the distinction between the two, make sure those use the task_sigpending() helper.

---
 include/linux/sched/signal.h | 9 +++++++--
 kernel/events/uprobes.c      | 2 +-
 kernel/signal.c              | 8 ++++----
 3 files changed, 12 insertions(+), 7 deletions(-)
include/linux/sched/signal.h +7 -2
index 1bad18a1d8ba..404145dc536e 100644
@@ -353,11 +353,16 @@ static inline int restart_syscall(void)
 	return -ERESTARTNOINTR;
 }
 
-static inline int signal_pending(struct task_struct *p)
+static inline int task_sigpending(struct task_struct *p)
 {
 	return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
 }
 
+static inline int signal_pending(struct task_struct *p)
+{
+	return task_sigpending(p);
+}
+
 static inline int __fatal_signal_pending(struct task_struct *p)
 {
 	return unlikely(sigismember(&p->pending.signal, SIGKILL));
@@ -365,7 +370,7 @@ static inline int __fatal_signal_pending(struct task_struct *p)
 
 static inline int fatal_signal_pending(struct task_struct *p)
 {
-	return signal_pending(p) && __fatal_signal_pending(p);
+	return task_sigpending(p) && __fatal_signal_pending(p);
 }
 
 static inline int signal_pending_state(long state, struct task_struct *p)
kernel/events/uprobes.c +1 -1
index 0e18aaf23a7b..8bb26a338e06 100644
@@ -1973,7 +1973,7 @@ bool uprobe_deny_signal(void)
 
 	WARN_ON_ONCE(utask->state != UTASK_SSTEP);
 
-	if (signal_pending(t)) {
+	if (task_sigpending(t)) {
 		spin_lock_irq(&t->sighand->siglock);
 		clear_tsk_thread_flag(t, TIF_SIGPENDING);
 		spin_unlock_irq(&t->sighand->siglock);
kernel/signal.c +4 -4
index a38b3edc6851..9f86246a8637 100644
@@ -983,7 +983,7 @@ static inline bool wants_signal(int sig, struct task_struct *p)
 	if (task_is_stopped_or_traced(p))
 		return false;
 
-	return task_curr(p) || !signal_pending(p);
+	return task_curr(p) || !task_sigpending(p);
 }
 
 static void complete_signal(int sig, struct task_struct *p, enum pid_type type)
@@ -2822,7 +2822,7 @@ static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which)
 		/* Remove the signals this thread can handle. */
 		sigandsets(&retarget, &retarget, &t->blocked);
 
-		if (!signal_pending(t))
+		if (!task_sigpending(t))
 			signal_wake_up(t, 0);
 
 		if (sigisemptyset(&retarget))
@@ -2856,7 +2856,7 @@ void exit_signals(struct task_struct *tsk)
 
 	cgroup_threadgroup_change_end(tsk);
 
-	if (!signal_pending(tsk))
+	if (!task_sigpending(tsk))
 		goto out;
 
 	unblocked = tsk->blocked;
@@ -2900,7 +2900,7 @@ long do_no_restart_syscall(struct restart_block *param)
 
 static void __set_task_blocked(struct task_struct *tsk, const sigset_t *newset)
 {
-	if (signal_pending(tsk) && !thread_group_empty(tsk)) {
+	if (task_sigpending(tsk) && !thread_group_empty(tsk)) {
 		sigset_t newblocked;
 		/* A set of now blocked but previously unblocked signals. */
 		sigandnsets(&newblocked, newset, &current->blocked);
Signature · 1 line
2.28.0
maintainer Reviewed-by on v1 2/5
#5 lore raw

Re: [PATCH 2/5] kernel: add task_sigpending() helper

Quoted 7 lines · Jens Axboe

This is in preparation for maintaining signal_pending() as the decider of whether or not a schedule() loop should be broken, or continue sleeping. This is different than the core signal use cases, where we really want to know if an actual signal is pending or not. task_sigpending() returns non-zero if TIF_SIGPENDING is set.

Quoted 5 lines

Only core kernel use cases should care about the distinction between the two, make sure those use the task_sigpending() helper.

the same,

author maintainer
#6 lore raw

PATCH 3/5 kernel: add support for TIF_NOTIFY_SIGNAL

In reply to Jens Axboe

This adds TIF_NOTIFY_SIGNAL handling in the generic code, which if set, will return true if signal_pending() is used in a wait loop. That causes an exit of the loop so that notify_signal tracehooks can be run. If the wait loop is currently inside a system call, the system call is restarted once task_work has been processed.

---
 arch/x86/kernel/signal.c     |  2 +-
 include/linux/entry-common.h |  9 +++++++--
 include/linux/entry-kvm.h    |  4 ++--
 include/linux/sched/signal.h | 11 ++++++++++-
 include/linux/tracehook.h    | 27 +++++++++++++++++++++++++++
 kernel/entry/common.c        |  6 +++---
 kernel/entry/kvm.c           |  3 +++
 7 files changed, 53 insertions(+), 9 deletions(-)
arch/x86/kernel/signal.c +1 -1
index be0d7d4152ec..d18304e84c09 100644
@@ -804,7 +804,7 @@ static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
  * want to handle. Thus you cannot kill init even with a SIGKILL even by
  * mistake.
  */
-void arch_do_signal(struct pt_regs *regs)
+void arch_do_signal(struct pt_regs *regs, unsigned long ti_work)
 {
 	struct ksignal ksig;
 
include/linux/entry-common.h +7 -2
index 159c7476b11b..42e899b3b4a1 100644
@@ -37,6 +37,10 @@
 # define _TIF_UPROBE			(0)
 #endif
 
+#ifndef _TIF_NOTIFY_SIGNAL
+# define _TIF_NOTIFY_SIGNAL		(0)
+#endif
+
 /*
  * TIF flags handled in syscall_enter_from_usermode()
  */
@@ -69,7 +73,7 @@
 
 #define EXIT_TO_USER_MODE_WORK						\
 	(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_UPROBE |		\
-	 _TIF_NEED_RESCHED | _TIF_PATCH_PENDING |			\
+	 _TIF_NEED_RESCHED | _TIF_PATCH_PENDING | _TIF_NOTIFY_SIGNAL |	\
 	 ARCH_EXIT_TO_USER_MODE_WORK)
 
 /**
@@ -261,10 +265,11 @@ static __always_inline void arch_exit_to_user_mode(void) { }
 /**
  * arch_do_signal -  Architecture specific signal delivery function
  * @regs:	Pointer to currents pt_regs
+ * @ti_work:	task thread info work flags
  *
  * Invoked from exit_to_user_mode_loop().
  */
-void arch_do_signal(struct pt_regs *regs);
+void arch_do_signal(struct pt_regs *regs, unsigned long ti_work);
 
 /**
  * arch_syscall_exit_tracehook - Wrapper around tracehook_report_syscall_exit()
include/linux/entry-kvm.h +2 -2
index 0cef17afb41a..9b93f8584ff7 100644
@@ -11,8 +11,8 @@
 # define ARCH_XFER_TO_GUEST_MODE_WORK	(0)
 #endif
 
-#define XFER_TO_GUEST_MODE_WORK					\
-	(_TIF_NEED_RESCHED | _TIF_SIGPENDING |			\
+#define XFER_TO_GUEST_MODE_WORK						\
+	(_TIF_NEED_RESCHED | _TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL |	\
 	 _TIF_NOTIFY_RESUME | ARCH_XFER_TO_GUEST_MODE_WORK)
 
 struct kvm_vcpu;
include/linux/sched/signal.h +10 -1
index 404145dc536e..b2ecc34284b0 100644
@@ -360,6 +360,15 @@ static inline int task_sigpending(struct task_struct *p)
 
 static inline int signal_pending(struct task_struct *p)
 {
+#if defined(CONFIG_GENERIC_ENTRY) && defined(TIF_NOTIFY_SIGNAL)
+	/*
+	 * TIF_NOTIFY_SIGNAL isn't really a signal, but it requires the same
+	 * behavior in terms of ensuring that we break out of wait loops
+	 * so that notify signal callbacks can be processed.
+	 */
+	if (unlikely(test_tsk_thread_flag(p, TIF_NOTIFY_SIGNAL)))
+		return 1;
+#endif
 	return task_sigpending(p);
 }
 
@@ -507,7 +516,7 @@ extern int set_user_sigmask(const sigset_t __user *umask, size_t sigsetsize);
 static inline void restore_saved_sigmask_unless(bool interrupted)
 {
 	if (interrupted)
-		WARN_ON(!test_thread_flag(TIF_SIGPENDING));
+		WARN_ON(!signal_pending(current));
 	else
 		restore_saved_sigmask();
 }
include/linux/tracehook.h +27 -0
index b480e1a07ed8..0a5bb866e7a6 100644
@@ -198,4 +198,31 @@ static inline void tracehook_notify_resume(struct pt_regs *regs)
 	blkcg_maybe_throttle_current();
 }
 
+/*
+ * called by exit_to_user_mode_loop() if ti_work & _TIF_NOTIFY_SIGNAL. This
+ * is currently used by TWA_SIGNAL based task_work, which requires breaking
+ * wait loops to ensure that task_work is noticed and run.
+ */
+static inline void tracehook_notify_signal(void)
+{
+#if defined(CONFIG_GENERIC_ENTRY) && defined(TIF_NOTIFY_SIGNAL)
+	clear_thread_flag(TIF_NOTIFY_SIGNAL);
+	smp_mb__after_atomic();
+	if (current->task_works)
+		task_work_run();
+#endif
+}
+
+/*
+ * Called when we have work to process from exit_to_user_mode_loop()
+ */
+static inline void set_notify_signal(struct task_struct *task)
+{
+#if defined(CONFIG_GENERIC_ENTRY) && defined(TIF_NOTIFY_SIGNAL)
+	if (!test_and_set_tsk_thread_flag(task, TIF_NOTIFY_SIGNAL) &&
+	    !wake_up_state(task, TASK_INTERRUPTIBLE))
+		kick_process(task);
+#endif
+}
+
 #endif	/* <linux/tracehook.h> */
kernel/entry/common.c +3 -3
index d20ab4ac7183..bd3cf6279e94 100644
@@ -135,7 +135,7 @@ static __always_inline void exit_to_user_mode(void)
 }
 
 /* Workaround to allow gradual conversion of architecture code */
-void __weak arch_do_signal(struct pt_regs *regs) { }
+void __weak arch_do_signal(struct pt_regs *regs, unsigned long ti_work) { }
 
 static unsigned long exit_to_user_mode_loop(struct pt_regs *regs,
 					    unsigned long ti_work)
@@ -157,8 +157,8 @@ static unsigned long exit_to_user_mode_loop(struct pt_regs *regs,
 		if (ti_work & _TIF_PATCH_PENDING)
 			klp_update_patch_state(current);
 
-		if (ti_work & _TIF_SIGPENDING)
-			arch_do_signal(regs);
+		if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
+			arch_do_signal(regs, ti_work);
 
 		if (ti_work & _TIF_NOTIFY_RESUME) {
 			tracehook_notify_resume(regs);
kernel/entry/kvm.c +3 -0
index b6678a5e3cf6..49972ee99aff 100644
@@ -8,6 +8,9 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)
 	do {
 		int ret;
 
+		if (ti_work & _TIF_NOTIFY_SIGNAL)
+			tracehook_notify_signal();
+
 		if (ti_work & _TIF_SIGPENDING) {
 			kvm_handle_signal_exit(vcpu);
 			return -EINTR;
Signature · 1 line
2.28.0
maintainer
#7 lore raw

Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL

Quoted 4 lines · Jens Axboe

static inline int signal_pending(struct task_struct *p) {

include/linux/sched/signal.h +1 -0
+#if defined(CONFIG_GENERIC_ENTRY) && defined(TIF_NOTIFY_SIGNAL)

include/linux/sched/signal.h static inline int task_sigpending(struct task_struct *p) · line 373

Quoted 10 lines
include/linux/sched/signal.h +8 -0
+	/*
+	 * TIF_NOTIFY_SIGNAL isn't really a signal, but it requires the same
+	 * behavior in terms of ensuring that we break out of wait loops
+	 * so that notify signal callbacks can be processed.
+	 */
+	if (unlikely(test_tsk_thread_flag(p, TIF_NOTIFY_SIGNAL)))
+		return 1;
+#endif
 	return task_sigpending(p);
 }

I don't understand why does this version requires CONFIG_GENERIC_ENTRY.

Afaics, it is very easy to change all the non-x86 arches to support TIF_NOTIFY_SIGNAL, but it is not trivial to change them all to use kernel/entry/common.c ?

Oleg.

author maintainer
#8 lore raw

Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL

Quoted 18 lines · Oleg Nesterov
Quoted 4 lines · Jens Axboe

static inline int signal_pending(struct task_struct *p) {

include/linux/sched/signal.h +1 -0
+#if defined(CONFIG_GENERIC_ENTRY) && defined(TIF_NOTIFY_SIGNAL)

include/linux/sched/signal.h static inline int task_sigpending(struct task_struct *p) · line 373

Quoted 10 lines
include/linux/sched/signal.h +8 -0
+	/*
+	 * TIF_NOTIFY_SIGNAL isn't really a signal, but it requires the same
+	 * behavior in terms of ensuring that we break out of wait loops
+	 * so that notify signal callbacks can be processed.
+	 */
+	if (unlikely(test_tsk_thread_flag(p, TIF_NOTIFY_SIGNAL)))
+		return 1;
+#endif
 	return task_sigpending(p);
 }

I don't understand why does this version requires CONFIG_GENERIC_ENTRY.

Quoted 3 lines

Afaics, it is very easy to change all the non-x86 arches to support TIF_NOTIFY_SIGNAL, but it is not trivial to change them all to use kernel/entry/common.c ?

I think that Thomas wants to gate TIF_NOTIFY_SIGNAL on conversion to the generic entry code? Because you are right, it's usually pretty trivial to wire up the arch code, regardless of whether it uses the generic entry handling or not.

Signature · 1 line
Jens Axboe
maintainer
#9 lore raw

Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL

Quoted 20 lines · Jens Axboe
Quoted 18 lines · Oleg Nesterov
Quoted 4 lines · Jens Axboe

static inline int signal_pending(struct task_struct *p) {

include/linux/sched/signal.h +1 -0
+#if defined(CONFIG_GENERIC_ENTRY) && defined(TIF_NOTIFY_SIGNAL)

include/linux/sched/signal.h static inline int task_sigpending(struct task_struct *p) · line 373

Quoted 10 lines
include/linux/sched/signal.h +8 -0
+	/*
+	 * TIF_NOTIFY_SIGNAL isn't really a signal, but it requires the same
+	 * behavior in terms of ensuring that we break out of wait loops
+	 * so that notify signal callbacks can be processed.
+	 */
+	if (unlikely(test_tsk_thread_flag(p, TIF_NOTIFY_SIGNAL)))
+		return 1;
+#endif
 	return task_sigpending(p);
 }

I don't understand why does this version requires CONFIG_GENERIC_ENTRY.

Quoted 6 lines
Quoted 3 lines

Afaics, it is very easy to change all the non-x86 arches to support TIF_NOTIFY_SIGNAL, but it is not trivial to change them all to use kernel/entry/common.c ?

I think that Thomas wants to gate TIF_NOTIFY_SIGNAL on conversion to the generic entry code?

Then I think TIF_NOTIFY_SIGNAL will be never fully supported ;)

Oleg.

author maintainer
#10 lore raw

Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL

Quoted 21 lines · Oleg Nesterov
Quoted 20 lines · Jens Axboe
Quoted 18 lines · Oleg Nesterov
Quoted 4 lines · Jens Axboe

static inline int signal_pending(struct task_struct *p) {

include/linux/sched/signal.h +1 -0
+#if defined(CONFIG_GENERIC_ENTRY) && defined(TIF_NOTIFY_SIGNAL)

include/linux/sched/signal.h static inline int task_sigpending(struct task_struct *p) · line 373

Quoted 10 lines
include/linux/sched/signal.h +8 -0
+	/*
+	 * TIF_NOTIFY_SIGNAL isn't really a signal, but it requires the same
+	 * behavior in terms of ensuring that we break out of wait loops
+	 * so that notify signal callbacks can be processed.
+	 */
+	if (unlikely(test_tsk_thread_flag(p, TIF_NOTIFY_SIGNAL)))
+		return 1;
+#endif
 	return task_sigpending(p);
 }

I don't understand why does this version requires CONFIG_GENERIC_ENTRY.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Afaics, it is very easy to change all the non-x86 arches to support TIF_NOTIFY_SIGNAL, but it is not trivial to change them all to use kernel/entry/common.c ?

I think that Thomas wants to gate TIF_NOTIFY_SIGNAL on conversion to the generic entry code?

Then I think TIF_NOTIFY_SIGNAL will be never fully supported ;)

That is indeed a worry. From a functionality point of view, with the major archs supporting it, I'm not too worried about that side. But it does mean that we'll be stuck with the ifdeffery forever, which isn't great.

Thomas, are you fine with decoupling this from CONFIG_GENERIC_ENTRY, based on the above concerns?

Signature · 1 line
Jens Axboe
maintainer
#11 lore raw

Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL

Quoted 30 lines · Jens Axboe
Quoted 28 lines · Oleg Nesterov
Quoted 26 lines · Jens Axboe
Quoted 18 lines · Oleg Nesterov
Quoted 4 lines · Jens Axboe

static inline int signal_pending(struct task_struct *p) {

include/linux/sched/signal.h +1 -0
+#if defined(CONFIG_GENERIC_ENTRY) && defined(TIF_NOTIFY_SIGNAL)

include/linux/sched/signal.h static inline int task_sigpending(struct task_struct *p) · line 373

Quoted 10 lines
include/linux/sched/signal.h +8 -0
+	/*
+	 * TIF_NOTIFY_SIGNAL isn't really a signal, but it requires the same
+	 * behavior in terms of ensuring that we break out of wait loops
+	 * so that notify signal callbacks can be processed.
+	 */
+	if (unlikely(test_tsk_thread_flag(p, TIF_NOTIFY_SIGNAL)))
+		return 1;
+#endif
 	return task_sigpending(p);
 }

I don't understand why does this version requires CONFIG_GENERIC_ENTRY.

Quoted 3 lines

Afaics, it is very easy to change all the non-x86 arches to support TIF_NOTIFY_SIGNAL, but it is not trivial to change them all to use kernel/entry/common.c ?

I think that Thomas wants to gate TIF_NOTIFY_SIGNAL on conversion to the generic entry code?

Quoted 6 lines
Quoted 1 line

Then I think TIF_NOTIFY_SIGNAL will be never fully supported ;)

That is indeed a worry. From a functionality point of view, with the major archs supporting it, I'm not too worried about that side. But it does mean that we'll be stuck with the ifdeffery forever, which isn't great.

plus we can't kill the ugly JOBCTL_TASK_WORK.

Oleg.

maintainer
#12 lore raw

Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL

Quoted 9 lines · Oleg Nesterov
Quoted 5 lines · Jens Axboe

That is indeed a worry. From a functionality point of view, with the major archs supporting it, I'm not too worried about that side. But it does mean that we'll be stuck with the ifdeffery forever, which isn't great.

plus we can't kill the ugly JOBCTL_TASK_WORK.

not to mention we can not change freezer/livepatch to use NOTIFY_SIGNAL, or add new users of set_notify_signal().

Oleg.

author maintainer
#13 lore raw

Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL

Quoted 9 lines · Oleg Nesterov
Quoted 8 lines · Oleg Nesterov
Quoted 5 lines · Jens Axboe

That is indeed a worry. From a functionality point of view, with the major archs supporting it, I'm not too worried about that side. But it does mean that we'll be stuck with the ifdeffery forever, which isn't great.

Quoted 4 lines
Quoted 1 line

plus we can't kill the ugly JOBCTL_TASK_WORK.

not to mention we can not change freezer/livepatch to use NOTIFY_SIGNAL, or add new users of set_notify_signal().

Yeah I know, there's a whole slew of cleanups and code removal that can happen after this series, once all archs are converted. See:

https://git.kernel.dk/cgit/linux-block/log/?h=tif-task_work.arch

which is all of that on top of this series.

Signature · 1 line
Jens Axboe
#14 lore raw

Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL

In reply to Oleg Nesterov
Quoted 4 lines · Oleg Nesterov
Quoted 3 lines · Jens Axboe
Quoted 2 lines · Oleg Nesterov

I don't understand why does this version requires CONFIG_GENERIC_ENTRY.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Afaics, it is very easy to change all the non-x86 arches to support TIF_NOTIFY_SIGNAL, but it is not trivial to change them all to use kernel/entry/common.c ?

I think that Thomas wants to gate TIF_NOTIFY_SIGNAL on conversion to the generic entry code?

Then I think TIF_NOTIFY_SIGNAL will be never fully supported ;)

Yeah, we proliferate crap on that basis forever. _ALL_ architectures have the very same entry/exit ordering problems (or subsets and different ones) which we fixed on x86.

So no, we don't want to have 24 different variants of the same thing again. That's what common code is for.

Not doing that is making the life of everyone working on core infrastructure pointlessly harder. Architecture people still have enough ways to screw everyone up.

Thanks,

tglx

maintainer
#15 lore raw

Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL

Quoted 19 lines · Thomas Gleixner
Quoted 4 lines · Oleg Nesterov
Quoted 3 lines · Jens Axboe
Quoted 2 lines · Oleg Nesterov

I don't understand why does this version requires CONFIG_GENERIC_ENTRY.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Afaics, it is very easy to change all the non-x86 arches to support TIF_NOTIFY_SIGNAL, but it is not trivial to change them all to use kernel/entry/common.c ?

I think that Thomas wants to gate TIF_NOTIFY_SIGNAL on conversion to the generic entry code?

Then I think TIF_NOTIFY_SIGNAL will be never fully supported ;)

Yeah, we proliferate crap on that basis forever. _ALL_ architectures have the very same entry/exit ordering problems (or subsets and different ones) which we fixed on x86.

Quoted 6 lines

So no, we don't want to have 24 different variants of the same thing again. That's what common code is for.

Not doing that is making the life of everyone working on core infrastructure pointlessly harder. Architecture people still have enough ways to screw everyone up.

Sure, it would be nice to change them all to use kernel/entry/common.c.

Until then (until never), how can we kill JOBCTL_TASK_WORK ?

How can we remove freezing/klp_patch_pending from recalc_sigpending() ?

Oleg.

maintainer Reviewed-by on v1 3/5
#16 lore raw

Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL

In reply to Jens Axboe
Quoted 8 lines · Jens Axboe

This adds TIF_NOTIFY_SIGNAL handling in the generic code, which if set, will return true if signal_pending() is used in a wait loop. That causes an exit of the loop so that notify_signal tracehooks can be run. If the wait loop is currently inside a system call, the system call is restarted once task_work has been processed.

So I strongly disagree with CONFIG_GENERIC_ENTRY. Otherwise,

author maintainer
#17 lore raw

PATCH 4/5 x86: wire up TIF_NOTIFY_SIGNAL

In reply to Jens Axboe

We already get the ti_work passed in arch_do_signal(), define TIF_NOTIFY_SIGNAL and take the appropriate action in the signal handling based on _TIF_NOTIFY_SIGNAL and _TIF_SIGPENDING being set.

---
 arch/x86/include/asm/thread_info.h | 2 ++
 arch/x86/kernel/signal.c           | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
arch/x86/include/asm/thread_info.h +2 -0
index 267701ae3d86..86ade67f21b7 100644
@@ -93,6 +93,7 @@ struct thread_info {
 #define TIF_NOTSC		16	/* TSC is not accessible in userland */
 #define TIF_IA32		17	/* IA32 compatibility process */
 #define TIF_SLD			18	/* Restore split lock detection on context switch */
+#define TIF_NOTIFY_SIGNAL	19	/* signal notifications exist */
 #define TIF_MEMDIE		20	/* is terminating due to OOM killer */
 #define TIF_POLLING_NRFLAG	21	/* idle is polling for TIF_NEED_RESCHED */
 #define TIF_IO_BITMAP		22	/* uses I/O bitmap */
@@ -123,6 +124,7 @@ struct thread_info {
 #define _TIF_NOTSC		(1 << TIF_NOTSC)
 #define _TIF_IA32		(1 << TIF_IA32)
 #define _TIF_SLD		(1 << TIF_SLD)
+#define _TIF_NOTIFY_SIGNAL	(1 << TIF_NOTIFY_SIGNAL)
 #define _TIF_POLLING_NRFLAG	(1 << TIF_POLLING_NRFLAG)
 #define _TIF_IO_BITMAP		(1 << TIF_IO_BITMAP)
 #define _TIF_FORCED_TF		(1 << TIF_FORCED_TF)
arch/x86/kernel/signal.c +4 -1
index d18304e84c09..ec6490e53dc3 100644
@@ -808,7 +808,10 @@ void arch_do_signal(struct pt_regs *regs, unsigned long ti_work)
 {
 	struct ksignal ksig;
 
-	if (get_signal(&ksig)) {
+	if (ti_work & _TIF_NOTIFY_SIGNAL)
+		tracehook_notify_signal();
+
+	if ((ti_work & _TIF_SIGPENDING) && get_signal(&ksig)) {
 		/* Whee! Actually deliver the signal.  */
 		handle_signal(&ksig, regs);
 		return;
Signature · 1 line
2.28.0
#18 lore raw

Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL

Quoted 4 lines · Jens Axboe
arch/x86/kernel/signal.c +0 -0
@@ -808,7 +808,10 @@ void arch_do_signal(struct pt_regs *regs, unsigned long ti_work)
 {

arch/x86/kernel/signal.c void arch_do_signal(struct pt_regs *regs, unsigned long ti_work) · line 817

Quoted 10 lines
arch/x86/kernel/signal.c +4 -1
 	struct ksignal ksig;
 
-	if (get_signal(&ksig)) {
+	if (ti_work & _TIF_NOTIFY_SIGNAL)
+		tracehook_notify_signal();
+
+	if ((ti_work & _TIF_SIGPENDING) && get_signal(&ksig)) {
 		/* Whee! Actually deliver the signal.  */
 		handle_signal(&ksig, regs);
 		return;

Instead of adding this to every architectures signal magic, we can handle TIF_NOTIFY_SIGNAL in the core code:

static void handle_singal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

        arch_do_signal(ti_work, regs);
}
      loop {
      		if (ti_work & (SIGPENDING | NOTIFY_SIGNAL))
                	handle_signal_work(ti_work, regs);
      }

Hmm?

Thanks,

tglx

author maintainer
#19 lore raw

Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL

Quoted 27 lines · Thomas Gleixner
Quoted 4 lines · Jens Axboe
arch/x86/kernel/signal.c +0 -0
@@ -808,7 +808,10 @@ void arch_do_signal(struct pt_regs *regs, unsigned long ti_work)
 {

arch/x86/kernel/signal.c void arch_do_signal(struct pt_regs *regs, unsigned long ti_work) · line 817

Quoted 10 lines
arch/x86/kernel/signal.c +4 -1
 	struct ksignal ksig;
 
-	if (get_signal(&ksig)) {
+	if (ti_work & _TIF_NOTIFY_SIGNAL)
+		tracehook_notify_signal();
+
+	if ((ti_work & _TIF_SIGPENDING) && get_signal(&ksig)) {
 		/* Whee! Actually deliver the signal.  */
 		handle_signal(&ksig, regs);
 		return;

Instead of adding this to every architectures signal magic, we can handle TIF_NOTIFY_SIGNAL in the core code:

static void handle_singal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

        arch_do_signal(ti_work, regs);
}
Quoted 4 lines
      loop {
      		if (ti_work & (SIGPENDING | NOTIFY_SIGNAL))
                	handle_signal_work(ti_work, regs);
      }

We could, should probably make it:

static void handle_signal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

	if (ti_work & _TIF_SIGPENDING)
        	arch_do_signal(regs);
}

and then we can skip modifying arch_do_signal() all together, as it'll only be called if _TIF_SIGPENDING is set.

Signature · 1 line
Jens Axboe
#20 lore raw

Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL

Quoted 12 lines · Jens Axboe

On 10/15/20 8:11 AM, Thomas Gleixner wrote:
We could, should probably make it:

static void handle_signal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

	if (ti_work & _TIF_SIGPENDING)
        	arch_do_signal(regs);
}
Quoted 2 lines

and then we can skip modifying arch_do_signal() all together, as it'll only be called if _TIF_SIGPENDING is set.

Then you loose the syscall restart thing which was the whole point of this exercise :)

Thanks,

tglx

author maintainer
#21 lore raw

Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL

Quoted 13 lines · Thomas Gleixner
Quoted 12 lines · Jens Axboe

On 10/15/20 8:11 AM, Thomas Gleixner wrote:
We could, should probably make it:

static void handle_signal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

	if (ti_work & _TIF_SIGPENDING)
        	arch_do_signal(regs);
}
Quoted 5 lines
Quoted 2 lines

and then we can skip modifying arch_do_signal() all together, as it'll only be called if _TIF_SIGPENDING is set.

Then you loose the syscall restart thing which was the whole point of this exercise :)

Hah oh yeah, good point... But then we need to touch every arch do_signal() anyway, so probably not much point in making the change then.

Signature · 1 line
Jens Axboe
maintainer
#22 lore raw

Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL

In reply to Jens Axboe
Quoted 10 lines · Jens Axboe

static void handle_signal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

	if (ti_work & _TIF_SIGPENDING)
        	arch_do_signal(regs);
}
Quoted 2 lines

and then we can skip modifying arch_do_signal() all together, as it'll only be called if _TIF_SIGPENDING is set.

No, this can't work. We need to restart the syscall if TIF_NOTIFY_SIGNAL.

Oleg.

author maintainer
#23 lore raw

Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL

Quoted 7 lines · Oleg Nesterov
Quoted 6 lines · Jens Axboe

static void handle_signal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();
Quoted 8 lines
Quoted 6 lines
	if (ti_work & _TIF_SIGPENDING)
        	arch_do_signal(regs);
}

and then we can skip modifying arch_do_signal() all together, as it'll only be called if _TIF_SIGPENDING is set.

No, this can't work. We need to restart the syscall if TIF_NOTIFY_SIGNAL.

Yeah braino, Thomas caught that one too.

Signature · 1 line
Jens Axboe
maintainer
#24 lore raw

Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL

In reply to Thomas Gleixner
Quoted 28 lines · Thomas Gleixner
Quoted 4 lines · Jens Axboe
arch/x86/kernel/signal.c +0 -0
@@ -808,7 +808,10 @@ void arch_do_signal(struct pt_regs *regs, unsigned long ti_work)
 {

arch/x86/kernel/signal.c void arch_do_signal(struct pt_regs *regs, unsigned long ti_work) · line 817

Quoted 10 lines
arch/x86/kernel/signal.c +4 -1
 	struct ksignal ksig;
 
-	if (get_signal(&ksig)) {
+	if (ti_work & _TIF_NOTIFY_SIGNAL)
+		tracehook_notify_signal();
+
+	if ((ti_work & _TIF_SIGPENDING) && get_signal(&ksig)) {
 		/* Whee! Actually deliver the signal.  */
 		handle_signal(&ksig, regs);
 		return;

Instead of adding this to every architectures signal magic, we can handle TIF_NOTIFY_SIGNAL in the core code:

static void handle_singal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

        arch_do_signal(ti_work, regs);
}
Quoted 4 lines
      loop {
      		if (ti_work & (SIGPENDING | NOTIFY_SIGNAL))
                	handle_signal_work(ti_work, regs);
      }

To me this looks like unnecessary complication. We need to change every architecture anyway, how can this helper help?

Oleg.

#25 lore raw

Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL

Quoted 12 lines · Oleg Nesterov
Quoted 11 lines · Thomas Gleixner

Instead of adding this to every architectures signal magic, we can handle TIF_NOTIFY_SIGNAL in the core code:

static void handle_singal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

        arch_do_signal(ti_work, regs);
}
Quoted 7 lines
Quoted 4 lines
      loop {
      		if (ti_work & (SIGPENDING | NOTIFY_SIGNAL))
                	handle_signal_work(ti_work, regs);
      }

To me this looks like unnecessary complication. We need to change every architecture anyway, how can this helper help?

You need to change ONE architecture because nobody else uses the common entry loop right now. For those who move over they have to supply arch_do_signal() anyway, so the extra TIF check is not a problem.

We really don't want all architectures to have the same thing copy&pasta'd. That's the whole point of common code to avoid that.

Thanks,

tglx

maintainer
#26 lore raw

Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL

Quoted 19 lines · Thomas Gleixner
Quoted 17 lines · Oleg Nesterov
Quoted 15 lines · Thomas Gleixner

Instead of adding this to every architectures signal magic, we can handle TIF_NOTIFY_SIGNAL in the core code:

static void handle_singal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

        arch_do_signal(ti_work, regs);
}
      loop {
      		if (ti_work & (SIGPENDING | NOTIFY_SIGNAL))
                	handle_signal_work(ti_work, regs);
      }
Quoted 5 lines
Quoted 2 lines

To me this looks like unnecessary complication. We need to change every architecture anyway, how can this helper help?

You need to change ONE architecture because nobody else uses the common entry loop right now.

so we need to change other arches to use the common entry loop.

Quoted 2 lines

For those who move over they have to supply
arch_do_signal() anyway,

and this arch_do_signal() should be changed to check _TIF_SIGPENDING.

See also my replies to 3/5. I strongly disagree with CONFIG_GENERIC_ENTRY. But even if we require CONFIG_GENERIC_ENTRY, why do we want this helper?

We can just change exit_to_user_mode_loop() to do

	if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) {
		if (ti_work & _TIF_NOTIFY_SIGNAL)
			tracehook_notify_signal();
		arch_do_signal(ti_work, regs);
	}

but I'd prefer to handle SIGPENDING/NOTIFY_SIGNAL in one place.

Oleg.

#27 lore raw

Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL

In reply to Oleg Nesterov
Quoted 12 lines · Oleg Nesterov
Quoted 11 lines · Thomas Gleixner

Instead of adding this to every architectures signal magic, we can handle TIF_NOTIFY_SIGNAL in the core code:

static void handle_singal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

        arch_do_signal(ti_work, regs);
}
Quoted 7 lines
Quoted 4 lines
      loop {
      		if (ti_work & (SIGPENDING | NOTIFY_SIGNAL))
                	handle_signal_work(ti_work, regs);
      }

To me this looks like unnecessary complication. We need to change every architecture anyway, how can this helper help?

This is about the generic entry code. For the users of that it makes absolutely no sense to have that in architecture code.

Something which every architecture needs to do in the exactly same way goes into the common code. If not, you can spare the exercise of having common code in the first place.

Also arch_do_signal() becomes a misnomer with this new magic.

static void handle_signal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

        arch_do_signal_or_restart(ti_work, regs);
}

which makes it entirely clear what this is about.

Thanks,

tglx

maintainer
#28 lore raw

Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL

Quoted 22 lines · Thomas Gleixner
Quoted 12 lines · Oleg Nesterov
Quoted 11 lines · Thomas Gleixner

Instead of adding this to every architectures signal magic, we can handle TIF_NOTIFY_SIGNAL in the core code:

static void handle_singal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

        arch_do_signal(ti_work, regs);
}
Quoted 7 lines
Quoted 4 lines
      loop {
      		if (ti_work & (SIGPENDING | NOTIFY_SIGNAL))
                	handle_signal_work(ti_work, regs);
      }

To me this looks like unnecessary complication. We need to change every architecture anyway, how can this helper help?

Quoted 8 lines

This is about the generic entry code. For the users of that it makes absolutely no sense to have that in architecture code.

Something which every architecture needs to do in the exactly same way goes into the common code. If not, you can spare the exercise of having common code in the first place.

Also arch_do_signal() becomes a misnomer with this new magic.

Well, to me arch_do_signal() paths should handle the signal_pending() == T case.

But I won't argue, this is subjective.

Quoted 9 lines

static void handle_signal_work(ti_work, regs)

{
	if (ti_work & _TIF_NOTIFY_SIGNAL)
        	tracehook_notify_signal();

        arch_do_signal_or_restart(ti_work, regs);
}

which makes it entirely clear what this is about.

In this case I'd prefer to pass the "(ti_work & _TIF_SIGPENDING)" boolen to arch_do_signal_or_restart().

But again, I won't argue. And to remind, we do not really need to touch arch_do_signal() at all. We can just add

	if (test_thread_flag(TIF_NOTIFY_SIGNAL))
		tracehook_notify_signal();

	if (!task_sigpending(current))
		return 0;

at the start of get_signal() and avoid the code duplication automatically.

Oleg.

#29 lore raw

Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL

Quoted 5 lines · Oleg Nesterov

On 10/16, Thomas Gleixner wrote:

But again, I won't argue. And to remind, we do not really need to touch arch_do_signal() at all. We can just add

Quoted 7 lines
	if (test_thread_flag(TIF_NOTIFY_SIGNAL))
		tracehook_notify_signal();

	if (!task_sigpending(current))
		return 0;

at the start of get_signal() and avoid the code duplication automatically.

That works as well and is smart, but it's completely non obvious while

     if (ti_work & _TIF_NOTIFY_SIGNAL)
            tracehook_notify_signal();

     arch_do_signal_or_restart(ti_work & _TIF_SIGPENDING);

makes it entirely clear to follow the logic and it just operates on cached ti_work.

You can still do this for the non generic entry architectures:

     if (!IS_ENABLED(CONFIG_GENERIC_ENTRY) &&
     	 (test_thread_flag(TIF_NOTIFY_SIGNAL))

tracehook_notify_signal();

to avoid the churn in arch/*.

Thanks,

tglx

maintainer
#31 lore raw

introduce asm-generic/thread_info.h ?

In reply to Jens Axboe

arch/x86/include/asm/thread_info.h struct thread_info { · line 99

Quoted 11 lines · Jens Axboe
arch/x86/include/asm/thread_info.h +1 -0
@@ -93,6 +93,7 @@ struct thread_info {
 #define TIF_NOTSC		16	/* TSC is not accessible in userland */
 #define TIF_IA32		17	/* IA32 compatibility process */
 #define TIF_SLD			18	/* Restore split lock detection on context switch */
+#define TIF_NOTIFY_SIGNAL	19	/* signal notifications exist */
 #define TIF_MEMDIE		20	/* is terminating due to OOM killer */
 #define TIF_POLLING_NRFLAG	21	/* idle is polling for TIF_NEED_RESCHED */
 #define TIF_IO_BITMAP		22	/* uses I/O bitmap */

This is offtopic, but I am wondering if something like the patch below makes any sense.

It moves the common TIF_ flags into include/asm-generic/thread_info.h

Generated by this script:

	#!/usr/bin/perl -w
	use strict;

	# the (probably incomplete) list of arches which have some bits
	# hardcoded
	my $SKIP = join '|', qw(c6x sparc);

	# the (incomplete) list of "safe" flags which can be moved into
	# asm-generic even if not supported
	my @SAFE = qw(TIF_SECCOMP TIF_UPROBE);

	my %tifs;

	my @files = grep {
		open my $fd, '<', $_ or die $_;
		my $has; local $_;
		/^\s*#define\s*(TIF_\w+)\s+\d+\b/ and $has = ++$tifs{$1}
			while <$fd>;
		$has;
	}	grep !m{^arch/($SKIP)/}o,
		split "\n", qx(find arch/*/include/asm/thread_info*.h);

	my %comm = map +($_,1), grep $tifs{$_} == @files, keys %tifs;
	$comm{$_} = $tifs{$_} = 1 for @SAFE;

	our $ctr;

	my @comm = sort keys %comm;
	print "--- /dev/null\n+++ x/include/asm-generic/thread_info.h\n";
	print "@@ -0,0 +1,@{[2*@comm+3]} @@\n";
	print "+#define $_\t@{[$ctr++]}\n" for @comm;
	print "+\n+#define TIF__ARCH\t$ctr\n+\n";
	print "+#define _$_\t(1 << $_)\n" for @comm;

	sub patch
	{
		return $_ unless /^(\s*#define\s*)(_)?(TIF_\w+)/ and $tifs{$3};
		return if $comm{$3}; return $_ if $2;
		(!$ctr && "#include <asm-generic/thread_info.h>\n\n")
			. s/\b\d+/(TIF__ARCH+@{[$ctr++]})/r;
	}

	for my $file (sort @files) {
		open my $fd, '<', $file or die;
		open my $diff, "|diff -u --label=x/$file $file --label=x/$file -"
			or die;
		$ctr = 0; print $diff patch while <$fd>;
	}

Oleg.

include/asm-generic/thread_info.h new file +17 -0
@@ -0,0 +1,17 @@
+#define TIF_MEMDIE	0
+#define TIF_NEED_RESCHED	1
+#define TIF_NOTIFY_RESUME	2
+#define TIF_SECCOMP	3
+#define TIF_SIGPENDING	4
+#define TIF_SYSCALL_TRACE	5
+#define TIF_UPROBE	6
+
+#define TIF__ARCH	7
+
+#define _TIF_MEMDIE	(1 << TIF_MEMDIE)
+#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
+#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
+#define _TIF_SECCOMP	(1 << TIF_SECCOMP)
+#define _TIF_SIGPENDING	(1 << TIF_SIGPENDING)
+#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
+#define _TIF_UPROBE	(1 << TIF_UPROBE)
arch/alpha/include/asm/thread_info.h +5 -12
@@ -57,19 +57,12 @@
  *
  * TIF_SYSCALL_TRACE is known to be 0 via blbs.
  */
-#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
-#define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
-#define TIF_SIGPENDING		2	/* signal pending */
-#define TIF_NEED_RESCHED	3	/* rescheduling necessary */
-#define TIF_SYSCALL_AUDIT	4	/* syscall audit active */
-#define TIF_DIE_IF_KERNEL	9	/* dik recursion lock */
-#define TIF_MEMDIE		13	/* is terminating due to OOM killer */
-#define TIF_POLLING_NRFLAG	14	/* idle is polling for TIF_NEED_RESCHED */
+#include <asm-generic/thread_info.h>
+
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+0)	/* syscall audit active */
+#define TIF_DIE_IF_KERNEL	(TIF__ARCH+1)	/* dik recursion lock */
+#define TIF_POLLING_NRFLAG	(TIF__ARCH+2)	/* idle is polling for TIF_NEED_RESCHED */
 
-#define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
-#define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
-#define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
 #define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
 
arch/arc/include/asm/thread_info.h +4 -12
@@ -74,22 +74,14 @@
  * - pending work-to-be-done flags are in LSW
  * - other flags in MSW
  */
-#define TIF_RESTORE_SIGMASK	0	/* restore sig mask in do_signal() */
-#define TIF_NOTIFY_RESUME	1	/* resumption notification requested */
-#define TIF_SIGPENDING		2	/* signal pending */
-#define TIF_NEED_RESCHED	3	/* rescheduling necessary */
-#define TIF_SYSCALL_AUDIT	4	/* syscall auditing active */
-#define TIF_SYSCALL_TRACE	15	/* syscall trace active */
+#include <asm-generic/thread_info.h>
+
+#define TIF_RESTORE_SIGMASK	(TIF__ARCH+0)	/* restore sig mask in do_signal() */
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+1)	/* syscall auditing active */
 
 /* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_MEMDIE		16
 
-#define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
-#define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
-#define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
-#define _TIF_MEMDIE		(1<<TIF_MEMDIE)
 
 /* work to do on interrupt/exception return */
 #define _TIF_WORK_MASK		(_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
arch/arm/include/asm/thread_info.h +6 -17
@@ -127,27 +127,16 @@
  *  TIF_USEDFPU		- FPU was used by this task this quantum (SMP)
  *  TIF_POLLING_NRFLAG	- true if poll_idle() is polling TIF_NEED_RESCHED
  */
-#define TIF_SIGPENDING		0	/* signal pending */
-#define TIF_NEED_RESCHED	1	/* rescheduling necessary */
-#define TIF_NOTIFY_RESUME	2	/* callback before returning to user */
-#define TIF_UPROBE		3	/* breakpointed or singlestepping */
-#define TIF_SYSCALL_TRACE	4	/* syscall trace active */
-#define TIF_SYSCALL_AUDIT	5	/* syscall auditing active */
-#define TIF_SYSCALL_TRACEPOINT	6	/* syscall tracepoint instrumentation */
-#define TIF_SECCOMP		7	/* seccomp syscall filtering active */
+#include <asm-generic/thread_info.h>
 
-#define TIF_USING_IWMMXT	17
-#define TIF_MEMDIE		18	/* is terminating due to OOM killer */
-#define TIF_RESTORE_SIGMASK	20
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+0)	/* syscall auditing active */
+#define TIF_SYSCALL_TRACEPOINT	(TIF__ARCH+1)	/* syscall tracepoint instrumentation */
+
+#define TIF_USING_IWMMXT	(TIF__ARCH+2)
+#define TIF_RESTORE_SIGMASK	(TIF__ARCH+3)
 
-#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
-#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
-#define _TIF_UPROBE		(1 << TIF_UPROBE)
-#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
 #define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
-#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
 #define _TIF_USING_IWMMXT	(1 << TIF_USING_IWMMXT)
 
 /* Checks for any syscall work in entry-common.S */
arch/arm64/include/asm/thread_info.h +15 -26

52 lines not on this page · raw message

arch/csky/include/asm/thread_info.h +6 -18
@@ -57,29 +57,17 @@
 
 #endif /* !__ASSEMBLY__ */
 
-#define TIF_SIGPENDING		0	/* signal pending */
-#define TIF_NOTIFY_RESUME	1       /* callback before returning to user */
-#define TIF_NEED_RESCHED	2	/* rescheduling necessary */
-#define TIF_UPROBE		3	/* uprobe breakpoint or singlestep */
-#define TIF_SYSCALL_TRACE	4	/* syscall trace active */
-#define TIF_SYSCALL_TRACEPOINT	5       /* syscall tracepoint instrumentation */
-#define TIF_SYSCALL_AUDIT	6	/* syscall auditing */
-#define TIF_POLLING_NRFLAG	16	/* poll_idle() is TIF_NEED_RESCHED */
-#define TIF_MEMDIE		18      /* is terminating due to OOM killer */
-#define TIF_RESTORE_SIGMASK	20	/* restore signal mask in do_signal() */
-#define TIF_SECCOMP		21	/* secure computing */
+#include <asm-generic/thread_info.h>
+
+#define TIF_SYSCALL_TRACEPOINT	(TIF__ARCH+0)       /* syscall tracepoint instrumentation */
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+1)	/* syscall auditing */
+#define TIF_POLLING_NRFLAG	(TIF__ARCH+2)	/* poll_idle() is TIF_NEED_RESCHED */
+#define TIF_RESTORE_SIGMASK	(TIF__ARCH+3)	/* restore signal mask in do_signal() */
 
-#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
-#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
 #define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
-#define _TIF_UPROBE		(1 << TIF_UPROBE)
 #define _TIF_POLLING_NRFLAG	(1 << TIF_POLLING_NRFLAG)
-#define _TIF_MEMDIE		(1 << TIF_MEMDIE)
 #define _TIF_RESTORE_SIGMASK	(1 << TIF_RESTORE_SIGMASK)
-#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
 
 #define _TIF_WORK_MASK		(_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
 				 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
arch/h8300/include/asm/thread_info.h +7 -14
@@ -63,22 +63,15 @@
 /*
  * thread information flag bit numbers
  */
-#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
-#define TIF_SIGPENDING		1	/* signal pending */
-#define TIF_NEED_RESCHED	2	/* rescheduling necessary */
-#define TIF_SINGLESTEP		3	/* singlestepping active */
-#define TIF_MEMDIE		4	/* is terminating due to OOM killer */
-#define TIF_RESTORE_SIGMASK	5	/* restore signal mask in do_signal() */
-#define TIF_NOTIFY_RESUME	6	/* callback before returning to user */
-#define TIF_SYSCALL_AUDIT	7	/* syscall auditing active */
-#define TIF_SYSCALL_TRACEPOINT	8	/* for ftrace syscall instrumentation */
-#define TIF_POLLING_NRFLAG	9	/* true if poll_idle() is polling TIF_NEED_RESCHED */
+#include <asm-generic/thread_info.h>
+
+#define TIF_SINGLESTEP		(TIF__ARCH+0)	/* singlestepping active */
+#define TIF_RESTORE_SIGMASK	(TIF__ARCH+1)	/* restore signal mask in do_signal() */
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+2)	/* syscall auditing active */
+#define TIF_SYSCALL_TRACEPOINT	(TIF__ARCH+3)	/* for ftrace syscall instrumentation */
+#define TIF_POLLING_NRFLAG	(TIF__ARCH+4)	/* true if poll_idle() is polling TIF_NEED_RESCHED */
 
 /* as above, but as bit values */
-#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
-#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
-#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
 #define _TIF_SINGLESTEP		(1 << TIF_SINGLESTEP)
 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
 #define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
arch/hexagon/include/asm/thread_info.h +4 -11
@@ -89,19 +89,12 @@
  * - other flags in MSW
  */
 
-#define TIF_SYSCALL_TRACE       0       /* syscall trace active */
-#define TIF_NOTIFY_RESUME       1       /* resumption notification requested */
-#define TIF_SIGPENDING          2       /* signal pending */
-#define TIF_NEED_RESCHED        3       /* rescheduling necessary */
-#define TIF_SINGLESTEP          4       /* restore ss @ return to usr mode */
-#define TIF_RESTORE_SIGMASK     6       /* restore sig mask in do_signal() */
+#include <asm-generic/thread_info.h>
+
+#define TIF_SINGLESTEP          (TIF__ARCH+0)       /* restore ss @ return to usr mode */
+#define TIF_RESTORE_SIGMASK     (TIF__ARCH+1)       /* restore sig mask in do_signal() */
 /* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_MEMDIE              17      /* OOM killer killed process */
 
-#define _TIF_SYSCALL_TRACE      (1 << TIF_SYSCALL_TRACE)
-#define _TIF_NOTIFY_RESUME      (1 << TIF_NOTIFY_RESUME)
-#define _TIF_SIGPENDING         (1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED       (1 << TIF_NEED_RESCHED)
 #define _TIF_SINGLESTEP         (1 << TIF_SINGLESTEP)
 
 /* work to do on interrupt/exception return - All but TIF_SYSCALL_TRACE */
arch/ia64/include/asm/thread_info.h +8 -15
@@ -98,25 +98,18 @@
  * - pending work-to-be-done flags are in least-significant 16 bits, other flags
  *   in top 16 bits
  */
-#define TIF_SIGPENDING		0	/* signal pending */
-#define TIF_NEED_RESCHED	1	/* rescheduling necessary */
-#define TIF_SYSCALL_TRACE	2	/* syscall trace active */
-#define TIF_SYSCALL_AUDIT	3	/* syscall auditing active */
-#define TIF_SINGLESTEP		4	/* restore singlestep on return to user mode */
-#define TIF_NOTIFY_RESUME	6	/* resumption notification requested */
-#define TIF_MEMDIE		17	/* is terminating due to OOM killer */
-#define TIF_MCA_INIT		18	/* this task is processing MCA or INIT */
-#define TIF_DB_DISABLED		19	/* debug trap disabled for fsyscall */
-#define TIF_RESTORE_RSE		21	/* user RBS is newer than kernel RBS */
-#define TIF_POLLING_NRFLAG	22	/* idle is polling for TIF_NEED_RESCHED */
+#include <asm-generic/thread_info.h>
+
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+0)	/* syscall auditing active */
+#define TIF_SINGLESTEP		(TIF__ARCH+1)	/* restore singlestep on return to user mode */
+#define TIF_MCA_INIT		(TIF__ARCH+2)	/* this task is processing MCA or INIT */
+#define TIF_DB_DISABLED		(TIF__ARCH+3)	/* debug trap disabled for fsyscall */
+#define TIF_RESTORE_RSE		(TIF__ARCH+4)	/* user RBS is newer than kernel RBS */
+#define TIF_POLLING_NRFLAG	(TIF__ARCH+5)	/* idle is polling for TIF_NEED_RESCHED */
 
-#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
 #define _TIF_SINGLESTEP		(1 << TIF_SINGLESTEP)
 #define _TIF_SYSCALL_TRACEAUDIT	(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP)
-#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
-#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
 #define _TIF_MCA_INIT		(1 << TIF_MCA_INIT)
 #define _TIF_DB_DISABLED	(1 << TIF_DB_DISABLED)
 #define _TIF_RESTORE_RSE	(1 << TIF_RESTORE_RSE)
arch/m68k/include/asm/thread_info.h +4 -7
@@ -60,12 +60,9 @@
  * bits 0-7 are tested at every exception exit
  * bits 8-15 are also tested at syscall exit
  */
-#define TIF_NOTIFY_RESUME	5	/* callback before returning to user */
-#define TIF_SIGPENDING		6	/* signal pending */
-#define TIF_NEED_RESCHED	7	/* rescheduling necessary */
-#define TIF_DELAYED_TRACE	14	/* single step a syscall */
-#define TIF_SYSCALL_TRACE	15	/* syscall trace active */
-#define TIF_MEMDIE		16	/* is terminating due to OOM killer */
-#define TIF_RESTORE_SIGMASK	18	/* restore signal mask in do_signal */
+#include <asm-generic/thread_info.h>
+
+#define TIF_DELAYED_TRACE	(TIF__ARCH+0)	/* single step a syscall */
+#define TIF_RESTORE_SIGMASK	(TIF__ARCH+1)	/* restore signal mask in do_signal */
 
 #endif	/* _ASM_M68K_THREAD_INFO_H */
arch/microblaze/include/asm/thread_info.h +5 -14
@@ -101,27 +101,18 @@
  * - pending work-to-be-done flags are in LSW
  * - other flags in MSW
  */
-#define TIF_SYSCALL_TRACE	0 /* syscall trace active */
-#define TIF_NOTIFY_RESUME	1 /* resumption notification requested */
-#define TIF_SIGPENDING		2 /* signal pending */
-#define TIF_NEED_RESCHED	3 /* rescheduling necessary */
 /* restore singlestep on return to user mode */
-#define TIF_SINGLESTEP		4
-#define TIF_MEMDIE		6	/* is terminating due to OOM killer */
-#define TIF_SYSCALL_AUDIT	9       /* syscall auditing active */
-#define TIF_SECCOMP		10      /* secure computing */
+#include <asm-generic/thread_info.h>
+
+#define TIF_SINGLESTEP		(TIF__ARCH+0)
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+1)       /* syscall auditing active */
 
 /* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_POLLING_NRFLAG	16
+#define TIF_POLLING_NRFLAG	(TIF__ARCH+2)
 
-#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
-#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
-#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
 #define _TIF_SINGLESTEP		(1 << TIF_SINGLESTEP)
 #define _TIF_POLLING_NRFLAG	(1 << TIF_POLLING_NRFLAG)
 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
-#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
 
 /* work to do in syscall trace */
 #define _TIF_WORK_SYSCALL_MASK  (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP | \
arch/mips/include/asm/thread_info.h +17 -28

53 lines not on this page · raw message

arch/nds32/include/asm/thread_info.h +6 -13
@@ -44,21 +44,14 @@
  *  TIF_NOTIFY_RESUME	- callback before returning to user
  *  TIF_POLLING_NRFLAG	- true if poll_idle() is polling TIF_NEED_RESCHED
  */
-#define TIF_SIGPENDING		1
-#define TIF_NEED_RESCHED	2
-#define TIF_SINGLESTEP		3
-#define TIF_NOTIFY_RESUME	4	/* callback before returning to user */
-#define TIF_SYSCALL_TRACE	8
-#define TIF_POLLING_NRFLAG	17
-#define TIF_MEMDIE		18
-#define TIF_FREEZE		19
-#define TIF_RESTORE_SIGMASK	20
+#include <asm-generic/thread_info.h>
+
+#define TIF_SINGLESTEP		(TIF__ARCH+0)
+#define TIF_POLLING_NRFLAG	(TIF__ARCH+1)
+#define TIF_FREEZE		(TIF__ARCH+2)
+#define TIF_RESTORE_SIGMASK	(TIF__ARCH+3)
 
-#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
-#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
 #define _TIF_SINGLESTEP		(1 << TIF_SINGLESTEP)
-#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
 #define _TIF_POLLING_NRFLAG	(1 << TIF_POLLING_NRFLAG)
 #define _TIF_FREEZE		(1 << TIF_FREEZE)
 #define _TIF_RESTORE_SIGMASK	(1 << TIF_RESTORE_SIGMASK)
arch/nios2/include/asm/thread_info.h +5 -14
@@ -79,23 +79,14 @@
  * - pending work-to-be-done flags are in LSW
  * - other flags in MSW
  */
-#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
-#define TIF_NOTIFY_RESUME	1	/* resumption notification requested */
-#define TIF_SIGPENDING		2	/* signal pending */
-#define TIF_NEED_RESCHED	3	/* rescheduling necessary */
-#define TIF_MEMDIE		4	/* is terminating due to OOM killer */
-#define TIF_SECCOMP		5	/* secure computing */
-#define TIF_SYSCALL_AUDIT	6	/* syscall auditing active */
-#define TIF_RESTORE_SIGMASK	9	/* restore signal mask in do_signal() */
+#include <asm-generic/thread_info.h>
 
-#define TIF_POLLING_NRFLAG	16	/* true if poll_idle() is polling
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+0)	/* syscall auditing active */
+#define TIF_RESTORE_SIGMASK	(TIF__ARCH+1)	/* restore signal mask in do_signal() */
+
+#define TIF_POLLING_NRFLAG	(TIF__ARCH+2)	/* true if poll_idle() is polling
 					   TIF_NEED_RESCHED */
 
-#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
-#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
-#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
-#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
 #define _TIF_RESTORE_SIGMASK	(1 << TIF_RESTORE_SIGMASK)
 #define _TIF_POLLING_NRFLAG	(1 << TIF_POLLING_NRFLAG)
arch/openrisc/include/asm/thread_info.h +6 -13
@@ -91,23 +91,16 @@
  *   - pending work-to-be-done flags are in LSW
  *   - other flags in MSW
  */
-#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
-#define TIF_NOTIFY_RESUME	1	/* resumption notification requested */
-#define TIF_SIGPENDING		2	/* signal pending */
-#define TIF_NEED_RESCHED	3	/* rescheduling necessary */
-#define TIF_SINGLESTEP		4	/* restore singlestep on return to user
+#include <asm-generic/thread_info.h>
+
+#define TIF_SINGLESTEP		(TIF__ARCH+0)	/* restore singlestep on return to user
 					 * mode
 					 */
-#define TIF_SYSCALL_TRACEPOINT  8       /* for ftrace syscall instrumentation */
-#define TIF_RESTORE_SIGMASK     9
-#define TIF_POLLING_NRFLAG	16	/* true if poll_idle() is polling						 * TIF_NEED_RESCHED
+#define TIF_SYSCALL_TRACEPOINT  (TIF__ARCH+1)       /* for ftrace syscall instrumentation */
+#define TIF_RESTORE_SIGMASK     (TIF__ARCH+2)
+#define TIF_POLLING_NRFLAG	(TIF__ARCH+3)	/* true if poll_idle() is polling						 * TIF_NEED_RESCHED
 					 */
-#define TIF_MEMDIE              17
 
-#define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
-#define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
-#define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
 #define _TIF_SINGLESTEP		(1<<TIF_SINGLESTEP)
 #define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
 
arch/parisc/include/asm/thread_info.h +8 -17
@@ -46,29 +46,20 @@
 /*
  * thread information flags
  */
-#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
-#define TIF_SIGPENDING		1	/* signal pending */
-#define TIF_NEED_RESCHED	2	/* rescheduling necessary */
-#define TIF_POLLING_NRFLAG	3	/* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_32BIT               4       /* 32 bit binary */
-#define TIF_MEMDIE		5	/* is terminating due to OOM killer */
-#define TIF_SYSCALL_AUDIT	7	/* syscall auditing active */
-#define TIF_NOTIFY_RESUME	8	/* callback before returning to user */
-#define TIF_SINGLESTEP		9	/* single stepping? */
-#define TIF_BLOCKSTEP		10	/* branch stepping? */
-#define TIF_SECCOMP		11	/* secure computing */
-#define TIF_SYSCALL_TRACEPOINT	12	/* syscall tracepoint instrumentation */
+#include <asm-generic/thread_info.h>
+
+#define TIF_POLLING_NRFLAG	(TIF__ARCH+0)	/* true if poll_idle() is polling TIF_NEED_RESCHED */
+#define TIF_32BIT               (TIF__ARCH+1)       /* 32 bit binary */
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+2)	/* syscall auditing active */
+#define TIF_SINGLESTEP		(TIF__ARCH+3)	/* single stepping? */
+#define TIF_BLOCKSTEP		(TIF__ARCH+4)	/* branch stepping? */
+#define TIF_SYSCALL_TRACEPOINT	(TIF__ARCH+5)	/* syscall tracepoint instrumentation */
 
-#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
-#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
 #define _TIF_POLLING_NRFLAG	(1 << TIF_POLLING_NRFLAG)
 #define _TIF_32BIT		(1 << TIF_32BIT)
 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
-#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
 #define _TIF_SINGLESTEP		(1 << TIF_SINGLESTEP)
 #define _TIF_BLOCKSTEP		(1 << TIF_BLOCKSTEP)
-#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
 #define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
 
 #define _TIF_USER_WORK_MASK     (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | \
arch/powerpc/include/asm/thread_info.h +16 -27

62 lines not on this page · raw message

arch/riscv/include/asm/thread_info.h +5 -14
@@ -71,23 +71,14 @@
  * - pending work-to-be-done flags are in lowest half-word
  * - other flags in upper half-word(s)
  */
-#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
-#define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
-#define TIF_SIGPENDING		2	/* signal pending */
-#define TIF_NEED_RESCHED	3	/* rescheduling necessary */
-#define TIF_RESTORE_SIGMASK	4	/* restore signal mask in do_signal() */
-#define TIF_MEMDIE		5	/* is terminating due to OOM killer */
-#define TIF_SYSCALL_TRACEPOINT  6       /* syscall tracepoint instrumentation */
-#define TIF_SYSCALL_AUDIT	7	/* syscall auditing */
-#define TIF_SECCOMP		8	/* syscall secure computing */
+#include <asm-generic/thread_info.h>
+
+#define TIF_RESTORE_SIGMASK	(TIF__ARCH+0)	/* restore signal mask in do_signal() */
+#define TIF_SYSCALL_TRACEPOINT  (TIF__ARCH+1)       /* syscall tracepoint instrumentation */
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+2)	/* syscall auditing */
 
-#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
-#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
-#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
 #define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
-#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
 
 #define _TIF_WORK_MASK \
 	(_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED)
arch/s390/include/asm/thread_info.h +16 -27

58 lines not on this page · raw message

arch/sh/include/asm/thread_info.h +6 -15
@@ -102,24 +102,15 @@
  *   we blow the tst immediate size constraints and need to fix up
  *   arch/sh/kernel/entry-common.S.
  */
-#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
-#define TIF_SIGPENDING		1	/* signal pending */
-#define TIF_NEED_RESCHED	2	/* rescheduling necessary */
-#define TIF_SINGLESTEP		4	/* singlestepping active */
-#define TIF_SYSCALL_AUDIT	5	/* syscall auditing active */
-#define TIF_SECCOMP		6	/* secure computing */
-#define TIF_NOTIFY_RESUME	7	/* callback before returning to user */
-#define TIF_SYSCALL_TRACEPOINT	8	/* for ftrace syscall instrumentation */
-#define TIF_POLLING_NRFLAG	17	/* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_MEMDIE		18	/* is terminating due to OOM killer */
+#include <asm-generic/thread_info.h>
+
+#define TIF_SINGLESTEP		(TIF__ARCH+0)	/* singlestepping active */
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+1)	/* syscall auditing active */
+#define TIF_SYSCALL_TRACEPOINT	(TIF__ARCH+2)	/* for ftrace syscall instrumentation */
+#define TIF_POLLING_NRFLAG	(TIF__ARCH+3)	/* true if poll_idle() is polling TIF_NEED_RESCHED */
 
-#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
-#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
 #define _TIF_SINGLESTEP		(1 << TIF_SINGLESTEP)
 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
-#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
-#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
 #define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
 #define _TIF_POLLING_NRFLAG	(1 << TIF_POLLING_NRFLAG)
 
arch/um/include/asm/thread_info.h +5 -14
@@ -54,21 +54,12 @@
 
 #endif
 
-#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
-#define TIF_SIGPENDING		1	/* signal pending */
-#define TIF_NEED_RESCHED	2	/* rescheduling necessary */
-#define TIF_RESTART_BLOCK	4
-#define TIF_MEMDIE		5	/* is terminating due to OOM killer */
-#define TIF_SYSCALL_AUDIT	6
-#define TIF_RESTORE_SIGMASK	7
-#define TIF_NOTIFY_RESUME	8
-#define TIF_SECCOMP		9	/* secure computing */
+#include <asm-generic/thread_info.h>
+
+#define TIF_RESTART_BLOCK	(TIF__ARCH+0)
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+1)
+#define TIF_RESTORE_SIGMASK	(TIF__ARCH+2)
 
-#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
-#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
-#define _TIF_MEMDIE		(1 << TIF_MEMDIE)
 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
-#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
 
 #endif
arch/x86/include/asm/thread_info.h +24 -35

73 lines not on this page · raw message

arch/xtensa/include/asm/thread_info.h +7 -15
@@ -106,25 +106,17 @@
  * thread information flags
  * - these are process state flags that various assembly files may need to access
  */
-#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
-#define TIF_SIGPENDING		1	/* signal pending */
-#define TIF_NEED_RESCHED	2	/* rescheduling necessary */
-#define TIF_SINGLESTEP		3	/* restore singlestep on return to user mode */
-#define TIF_SYSCALL_TRACEPOINT	4	/* syscall tracepoint instrumentation */
-#define TIF_MEMDIE		5	/* is terminating due to OOM killer */
-#define TIF_RESTORE_SIGMASK	6	/* restore signal mask in do_signal() */
-#define TIF_NOTIFY_RESUME	7	/* callback before returning to user */
-#define TIF_DB_DISABLED		8	/* debug trap disabled for syscall */
-#define TIF_SYSCALL_AUDIT	9	/* syscall auditing active */
-#define TIF_SECCOMP		10	/* secure computing */
+#include <asm-generic/thread_info.h>
+
+#define TIF_SINGLESTEP		(TIF__ARCH+0)	/* restore singlestep on return to user mode */
+#define TIF_SYSCALL_TRACEPOINT	(TIF__ARCH+1)	/* syscall tracepoint instrumentation */
+#define TIF_RESTORE_SIGMASK	(TIF__ARCH+2)	/* restore signal mask in do_signal() */
+#define TIF_DB_DISABLED		(TIF__ARCH+3)	/* debug trap disabled for syscall */
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+4)	/* syscall auditing active */
 
-#define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
-#define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
 #define _TIF_SINGLESTEP		(1<<TIF_SINGLESTEP)
 #define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
-#define _TIF_SECCOMP		(1<<TIF_SECCOMP)
 
 #define _TIF_WORK_MASK		(_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP | \
 				 _TIF_SYSCALL_TRACEPOINT | \
author maintainer
#32 lore raw

PATCH 5/5 task_work: use TIF_NOTIFY_SIGNAL if available

In reply to Jens Axboe

If the arch supports TIF_NOTIFY_SIGNAL, then use that for TWA_SIGNAL as it's more efficient than using the signal delivery method. This is especially true on threaded applications, where ->sighand is shared across threads, but it's also lighter weight on non-shared cases.

io_uring is a heavy consumer of TWA_SIGNAL based task_work. On my test box, even just using 16 threads shows a nice improvement running an io_uring based echo server.

stock kernel:
0.01% <= 0.1 milliseconds
95.86% <= 0.2 milliseconds
98.27% <= 0.3 milliseconds
99.71% <= 0.4 milliseconds
100.00% <= 0.5 milliseconds
100.00% <= 0.6 milliseconds
100.00% <= 0.7 milliseconds
100.00% <= 0.8 milliseconds
100.00% <= 0.9 milliseconds
100.00% <= 1.0 milliseconds
100.00% <= 1.1 milliseconds
100.00% <= 2 milliseconds
100.00% <= 3 milliseconds
100.00% <= 3 milliseconds
1378930.00 requests per second
~1600% CPU

1.38M requests/second, and all 16 CPUs are maxed out.

patched kernel:
0.01% <= 0.1 milliseconds
98.24% <= 0.2 milliseconds
99.47% <= 0.3 milliseconds
99.99% <= 0.4 milliseconds
100.00% <= 0.5 milliseconds
100.00% <= 0.6 milliseconds
100.00% <= 0.7 milliseconds
100.00% <= 0.8 milliseconds
100.00% <= 0.9 milliseconds
100.00% <= 1.2 milliseconds
1666111.38 requests per second
~1450% CPU

1.67M requests/second, and we're no longer just hammering on the sighand lock. The original reporter states:

"For 5.7.15 my benchmark achieves 1.6M qps and system cpu is at ~80%.
for 5.7.16 or later it achieves only 1M qps and the system cpu is is at ~100%"

with the only difference there being that TWA_SIGNAL is used unconditionally in 5.7.16, since we need it to be able to solve an inability to run task_work if the application is waiting in the kernel already on an event that needs task_work run to be satisfied. Also see commit 0ba9c9edcd15.

---
 kernel/task_work.c | 41 +++++++++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 12 deletions(-)
kernel/task_work.c +29 -12
index 613b2d634af8..81163b946224 100644
@@ -5,6 +5,34 @@
 
 static struct callback_head work_exited; /* all we need is ->next == NULL */
 
+/*
+ * TWA_SIGNAL signaling - use TIF_NOTIFY_SIGNAL, if available, as it's faster
+ * than TIF_SIGPENDING as there's no dependency on ->sighand. The latter is
+ * shared for threads, and can cause contention on sighand->lock. Even for
+ * the non-threaded case TIF_NOTIFY_SIGNAL is more efficient, as no locking
+ * or IRQ disabling is involved for notification (or running) purposes.
+ */
+static void task_work_notify_signal(struct task_struct *task)
+{
+#if defined(CONFIG_GENERIC_ENTRY) && defined(TIF_NOTIFY_SIGNAL)
+	set_notify_signal(task);
+#else
+	unsigned long flags;
+
+	/*
+	 * Only grab the sighand lock if we don't already have some
+	 * task_work pending. This pairs with the smp_store_mb()
+	 * in get_signal(), see comment there.
+	 */
+	if (!(READ_ONCE(task->jobctl) & JOBCTL_TASK_WORK) &&
+	    lock_task_sighand(task, &flags)) {
+		task->jobctl |= JOBCTL_TASK_WORK;
+		signal_wake_up(task, 0);
+		unlock_task_sighand(task, &flags);
+	}
+#endif
+}
+
 /**
  * task_work_add - ask the @task to execute @work->func()
  * @task: the task which should run the callback
@@ -28,7 +56,6 @@ int
 task_work_add(struct task_struct *task, struct callback_head *work, int notify)
 {
 	struct callback_head *head;
-	unsigned long flags;
 
 	do {
 		head = READ_ONCE(task->task_works);
@@ -42,17 +69,7 @@ task_work_add(struct task_struct *task, struct callback_head *work, int notify)
 		set_notify_resume(task);
 		break;
 	case TWA_SIGNAL:
-		/*
-		 * Only grab the sighand lock if we don't already have some
-		 * task_work pending. This pairs with the smp_store_mb()
-		 * in get_signal(), see comment there.
-		 */
-		if (!(READ_ONCE(task->jobctl) & JOBCTL_TASK_WORK) &&
-		    lock_task_sighand(task, &flags)) {
-			task->jobctl |= JOBCTL_TASK_WORK;
-			signal_wake_up(task, 0);
-			unlock_task_sighand(task, &flags);
-		}
+		task_work_notify_signal(task);
 		break;
 	}
 
Signature · 1 line
2.28.0
maintainer
#33 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

Quoted 2 lines · Jens Axboe

Yes, but ...

kernel/task_work.c line 17

Quoted 3 lines
kernel/task_work.c +3 -0
+static void task_work_notify_signal(struct task_struct *task)
+{
+#if defined(CONFIG_GENERIC_ENTRY) && defined(TIF_NOTIFY_SIGNAL)

as long as defined(CONFIG_GENERIC_ENTRY) goes away ;)

Thomas, I strongly, strongly disagree with you. But even if you are right and only CONFIG_GENERIC_ENTRY arches should use TIF_NOTIFY_SIGNAL, why should this series check CONFIG_GENERIC_ENTRY ?

You can simply nack the patch which adds TIF_NOTIFY_SIGNAL to arch/xxx/include/asm/thread_info.h.

Oleg.

author maintainer
#34 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

Quoted 12 lines · Oleg Nesterov
Quoted 2 lines · Jens Axboe

Yes, but ...

kernel/task_work.c line 17

Quoted 3 lines
kernel/task_work.c +3 -0
+static void task_work_notify_signal(struct task_struct *task)
+{
+#if defined(CONFIG_GENERIC_ENTRY) && defined(TIF_NOTIFY_SIGNAL)

as long as defined(CONFIG_GENERIC_ENTRY) goes away ;)

Quoted 6 lines

Thomas, I strongly, strongly disagree with you. But even if you are right and only CONFIG_GENERIC_ENTRY arches should use TIF_NOTIFY_SIGNAL, why should this series check CONFIG_GENERIC_ENTRY ?

You can simply nack the patch which adds TIF_NOTIFY_SIGNAL to arch/xxx/include/asm/thread_info.h.

This seems to be the biggest area of contention right now. Just to summarize, we have two options:

1) We leave the CONFIG_GENERIC_ENTRY requirement, which means that the rest of the cleanups otherwise enabled by this series will not be able to move forward until the very last arch is converted to the generic entry code.

2) We go back to NOT having the CONFIG_GENERIC_ENTRY requirement, and archs can easily opt-in to TIF_NOTIFY_SIGNAL independently of switching to the generic entry code.

I understand Thomas's reasoning in wanting to push archs towards the generic entry code, and I fully support that. However, it does seem like the road paved by #1 is long and potentially neverending, which would leave us with never being able to kill the various bits of code that we otherwise would be able to.

Thomas, I do agree with Oleg on this one, I think we can make quicker progress on cleanups with option #2. This isn't really going to hinder any arch conversion to the generic entry code, as arch patches would be funeled through the arch trees anyway.

Thomas?

Signature · 1 line
Jens Axboe
#35 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

Quoted 3 lines · Jens Axboe
Quoted 2 lines · Oleg Nesterov

You can simply nack the patch which adds TIF_NOTIFY_SIGNAL to arch/xxx/include/asm/thread_info.h.

As if that is going to change anything...

Quoted 18 lines

This seems to be the biggest area of contention right now. Just to summarize, we have two options:

1) We leave the CONFIG_GENERIC_ENTRY requirement, which means that the rest of the cleanups otherwise enabled by this series will not be able to move forward until the very last arch is converted to the generic entry code.

2) We go back to NOT having the CONFIG_GENERIC_ENTRY requirement, and archs can easily opt-in to TIF_NOTIFY_SIGNAL independently of switching to the generic entry code.

I understand Thomas's reasoning in wanting to push archs towards the generic entry code, and I fully support that. However, it does seem like the road paved by #1 is long and potentially neverending, which would leave us with never being able to kill the various bits of code that we otherwise would be able to.

Quoted 4 lines

Thomas, I do agree with Oleg on this one, I think we can make quicker progress on cleanups with option #2. This isn't really going to hinder any arch conversion to the generic entry code, as arch patches would be funeled through the arch trees anyway.

I completely understand the desire to remove the jobctl mess and it looks like a valuable cleanup on it's own.

But I fundamentaly disagree with the wording of #2:

'and archs can easily opt-in ....'

Just doing it on an opt-in base is not any different from making it dependent on CONFIG_GENERIC_ENTRY. It's just painted differently and makes it easy for you to bring the performance improvement to the less than a handful architectures which actually care about io_uring.

So if you change #2 to:

Drop the CONFIG_GENERIC_ENTRY dependency, make _all_ architectures use TIF_NOTIFY_SIGNAL and clean up the jobctl and whatever related mess.

and actually act apon it, then I'm fine with that approach.

Anything else is just proliferating the existing mess and yet another promise of great improvements which never materialize.

Just to prove my point:

e91b48162332 ("task_work: teach task_work_add() to do signal_wake_up()")

added TWA_SIGNAL in June with the following in the changelog:

TODO: once this patch is merged we need to change all current users of task_work_add(notify = true) to use TWA_RESUME.

Now let's look at reality:

arch/x86/kernel/cpu/mce/core.c: task_work_add(current, &current->mce_kill_me, true);
arch/x86/kernel/cpu/resctrl/rdtgroup.c: ret = task_work_add(tsk, &callback->work, true);
drivers/acpi/apei/ghes.c: ret = task_work_add(current, &estatus_node->task_work,
drivers/acpi/apei/ghes.c- true);
drivers/android/binder.c: task_work_add(current, &twcb->twork, true);
fs/file_table.c: if (!task_work_add(task, &file->f_u.fu_rcuhead, true))

fs/io_uring.c: ret = task_work_add(req->task, &req->task_work, TWA_RESUME);

fs/io_uring.c: task_work_add(tsk, &req->task_work, 0);

fs/io_uring.c- notify = 0;
fs/io_uring.c- if (!(ctx->flags & IORING_SETUP_SQPOLL) && twa_signal_ok)
fs/io_uring.c- notify = TWA_SIGNAL;
fs/io_uring.c-
fs/io_uring.c: ret = task_work_add(tsk, &req->task_work, notify);

fs/io_uring.c: task_work_add(tsk, &req->task_work, 0);

fs/io_uring.c: task_work_add(tsk, &req->task_work, 0);
fs/io_uring.c: task_work_add(tsk, &req->task_work, 0);

fs/namespace.c: if (!task_work_add(task, &mnt->mnt_rcu, true))

kernel/events/uprobes.c: task_work_add(t, &t->utask->dup_xol_work, true);

kernel/irq/manage.c: task_work_add(current, &on_exit_work, false);

kernel/sched/fair.c: task_work_add(curr, work, true);

kernel/task_work.c:task_work_add(struct task_struct *task, struct callback_head *work, int notify)
kernel/time/posix-cpu-timers.c: task_work_add(tsk, &tsk->posix_cputimers_work.work, TWA_RESUME);

security/keys/keyctl.c: ret = task_work_add(parent, newwork, true);

security/yama/yama_lsm.c: if (task_work_add(current, &info->work, true) == 0)

See? Adding TODO's and making promises about cleanups is easy.

The patch adding this is sloppy at best. Instead of using a named enum it just defines TWA_RESUME and TWA_SIGNAL.

That makes the code really readable:

     notify = 0;
     if (cond)
     	notify = TWA_SIGNAL;

Making that

enum task_work_notify_mode {
TWA_NONE,
TWA_RESUME,
TWA_SIGNAL,
};

would have been not convoluted enough, right?

Also the kernel documentation of task_work_add() is outdated and partially wrong. Can be fixed later as well, right?

This features first and let others deal with the mess we create mindset has to stop. I'm dead tired of it.

Thanks,

tglx

#36 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

Quoted 9 lines · Thomas Gleixner
Quoted 1 line · Jens Axboe

On 10/15/20 9:49 AM, Oleg Nesterov wrote:

So if you change #2 to:

Drop the CONFIG_GENERIC_ENTRY dependency, make _all_ architectures use TIF_NOTIFY_SIGNAL and clean up the jobctl and whatever related mess.

and actually act apon it, then I'm fine with that approach.

Which makes me rethink my view on Olegs suggestion:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

You can simply nack the patch which adds TIF_NOTIFY_SIGNAL to arch/xxx/include/asm/thread_info.h.

That's a truly great suggestion:

X86 is going to have that TIF bit once the above is available.

I'm happy to help with the merge logistics of this.

Thanks,

tglx

author maintainer
#37 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

Quoted 13 lines · Thomas Gleixner
Quoted 9 lines · Thomas Gleixner
Quoted 1 line · Jens Axboe

On 10/15/20 9:49 AM, Oleg Nesterov wrote:

So if you change #2 to:

Drop the CONFIG_GENERIC_ENTRY dependency, make _all_ architectures use TIF_NOTIFY_SIGNAL and clean up the jobctl and whatever related mess.

and actually act apon it, then I'm fine with that approach.

Which makes me rethink my view on Olegs suggestion:

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

You can simply nack the patch which adds TIF_NOTIFY_SIGNAL to arch/xxx/include/asm/thread_info.h.

That's a truly great suggestion:

X86 is going to have that TIF bit once the above is available.

I'm happy to help with the merge logistics of this.

Not really following this email...

But it seems to me that you're happy with approach 2, so I'll do the following:

- Get rid of the CONFIG_GENERIC_ENTRY dependency for TIF_NOTIFY_SIGNAL
- Respin the arch additions and cleanups on top of that again

And hopefully we'll have something mergeable at that point. Once we have this series merged somewhere (would be great if you could carry it), I'll be talking to arch folks on the rest. Once archs have taken the necessary bits, I'll be posting the third and final series which is the cleanups that are currently sitting on top of the arch support.

Signature · 1 line
Jens Axboe
#38 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

Quoted 9 lines · Jens Axboe
Quoted 6 lines · Thomas Gleixner

On Fri, Oct 16 2020 at 11:00, Thomas Gleixner wrote:
That's a truly great suggestion:

X86 is going to have that TIF bit once the above is available.

I'm happy to help with the merge logistics of this.

Not really following this email...

What I tried to convey is, that the x86 tif bit is not going in before the complete thing (including cleanups) is available. I'm only half joking.

Quoted 11 lines

But it seems to me that you're happy with approach 2, so I'll do the following:

- Get rid of the CONFIG_GENERIC_ENTRY dependency for TIF_NOTIFY_SIGNAL
- Respin the arch additions and cleanups on top of that again

And hopefully we'll have something mergeable at that point. Once we have this series merged somewhere (would be great if you could carry it), I'll be talking to arch folks on the rest. Once archs have taken the necessary bits, I'll be posting the third and final series which is the cleanups that are currently sitting on top of the arch support.

Can you please just post the full thing after resolving #1 of the list items which I pointed out in the other reply?

With moving the handling into get_signal() you don't need more changes to arch/* than adding the TIF bit, right? So there should not be much talking involved other than agreeing on the bit number to use.

I might be missing something though.

Thanks,

tglx

maintainer
#39 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

Quoted 3 lines · Thomas Gleixner

With moving the handling into get_signal() you don't need more changes to arch/* than adding the TIF bit, right?

we still need to do something like

- if (thread_flags & _TIF_SIGPENDING)
+ if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
do_signal(...);

and add _TIF_NOTIFY_SIGNAL to the WORK-PENDING mask in arch/* code.

Oleg.

author maintainer
#40 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

Quoted 5 lines · Oleg Nesterov
Quoted 3 lines · Thomas Gleixner

With moving the handling into get_signal() you don't need more changes to arch/* than adding the TIF bit, right?

Quoted 7 lines

we still need to do something like

- if (thread_flags & _TIF_SIGPENDING)
+ if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
do_signal(...);

and add _TIF_NOTIFY_SIGNAL to the WORK-PENDING mask in arch/* code.

Yes, but it becomes really minimal at that point, and just that. There's no touching any of the arch do_signal() code.

Just finished the update of the branch to this model, and it does simplify things quite a bit! Most arch patches are now exactly just what you write above, no more.

Signature · 1 line
Jens Axboe
#41 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

Quoted 12 lines · Jens Axboe
Quoted 11 lines · Oleg Nesterov
Quoted 3 lines · Thomas Gleixner

With moving the handling into get_signal() you don't need more changes to arch/* than adding the TIF bit, right?

we still need to do something like

- if (thread_flags & _TIF_SIGPENDING)
+ if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
do_signal(...);

Quoted 8 lines
Quoted 1 line

and add _TIF_NOTIFY_SIGNAL to the WORK-PENDING mask in arch/* code.

Yes, but it becomes really minimal at that point, and just that. There's no touching any of the arch do_signal() code.

Just finished the update of the branch to this model, and it does simplify things quite a bit! Most arch patches are now exactly just what you write above, no more.

Except for all the nasty ones which have these checks in ASM :)

author maintainer
#42 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

Quoted 15 lines · Thomas Gleixner
Quoted 14 lines · Jens Axboe
Quoted 12 lines · Oleg Nesterov
Quoted 3 lines · Thomas Gleixner

With moving the handling into get_signal() you don't need more changes to arch/* than adding the TIF bit, right?

we still need to do something like

- if (thread_flags & _TIF_SIGPENDING)
+ if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
do_signal(...);

and add _TIF_NOTIFY_SIGNAL to the WORK-PENDING mask in arch/* code.

Quoted 8 lines
Quoted 6 lines

Yes, but it becomes really minimal at that point, and just that. There's no touching any of the arch do_signal() code.

Just finished the update of the branch to this model, and it does simplify things quite a bit! Most arch patches are now exactly just what you write above, no more.

Except for all the nasty ones which have these checks in ASM :)

Actually not that many of them, and the biggest part of that set are easy enough too (just adding the mask to the check). The only exceptions are where TIF_NOTIFY_SIGNAL end up spilling over 8/16-bit, and the particular arch currently uses some mask compare variant that now needs to be modified. powerpc was the worst there, but I'm told a free bit will show up in the merge window so all my powerpc asm fiddling was for naught :-)

Only remaining issue I'm aware of in the arch conversions is arm, which runs into this exact issue. Need to check with some arm guys on what the best approach is there...

Signature · 1 line
Jens Axboe
author maintainer
#43 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

In reply to Thomas Gleixner
Quoted 33 lines · Thomas Gleixner
Quoted 3 lines · Jens Axboe
Quoted 2 lines · Oleg Nesterov

You can simply nack the patch which adds TIF_NOTIFY_SIGNAL to arch/xxx/include/asm/thread_info.h.

As if that is going to change anything...

Quoted 18 lines

This seems to be the biggest area of contention right now. Just to summarize, we have two options:

1) We leave the CONFIG_GENERIC_ENTRY requirement, which means that the rest of the cleanups otherwise enabled by this series will not be able to move forward until the very last arch is converted to the generic entry code.

2) We go back to NOT having the CONFIG_GENERIC_ENTRY requirement, and archs can easily opt-in to TIF_NOTIFY_SIGNAL independently of switching to the generic entry code.

I understand Thomas's reasoning in wanting to push archs towards the generic entry code, and I fully support that. However, it does seem like the road paved by #1 is long and potentially neverending, which would leave us with never being able to kill the various bits of code that we otherwise would be able to.

Quoted 4 lines

Thomas, I do agree with Oleg on this one, I think we can make quicker progress on cleanups with option #2. This isn't really going to hinder any arch conversion to the generic entry code, as arch patches would be funeled through the arch trees anyway.

I completely understand the desire to remove the jobctl mess and it looks like a valuable cleanup on it's own.

Quoted 8 lines

But I fundamentaly disagree with the wording of #2:

'and archs can easily opt-in ....'

Just doing it on an opt-in base is not any different from making it dependent on CONFIG_GENERIC_ENTRY. It's just painted differently and makes it easy for you to bring the performance improvement to the less than a handful architectures which actually care about io_uring.

It's a lot easier for me to add support for archs for TIF_NOTIFY_SIGNAL, than it is to convert them to CONFIG_GENERIC ENTRY. And in fact I already _did_ convert all archs, in a separate series. Is it perfect yet? No. arm needs a bit of love, powerpc should be cleaned up once the 5.10 merge happens for that arch (dropping a bit), and s390 I need someone to verify. But apart from that, it is already done.

Quoted 7 lines

So if you change #2 to:

Drop the CONFIG_GENERIC_ENTRY dependency, make _all_ architectures use TIF_NOTIFY_SIGNAL and clean up the jobctl and whatever related mess.

and actually act apon it, then I'm fine with that approach.

Already did that too!

https://git.kernel.dk/cgit/linux-block/log/?h=tif-task_work.arch

It's sitting on top of this series. So the work is already done.

Quoted 11 lines

Anything else is just proliferating the existing mess and yet another promise of great improvements which never materialize.

Just to prove my point:

e91b48162332 ("task_work: teach task_work_add() to do signal_wake_up()")

added TWA_SIGNAL in June with the following in the changelog:

TODO: once this patch is merged we need to change all current users of task_work_add(notify = true) to use TWA_RESUME.

Totally agree the ball was dropped on this one. I did actually write a patch, just never had time to get it out.

Quoted 2 lines

This features first and let others deal with the mess we create mindset has to stop. I'm dead tired of it.

I totally agree, and we're on the same page. I think you'll find that in the past I always carry through, the task_work notification was somewhat of a rush due to a hang related to it. For this particular case, the cleanups and arch additions are pretty much ready to go.

Signature · 1 line
Jens Axboe
#44 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

Jens,

Quoted 5 lines · Jens Axboe

On 10/16/20 3:00 AM, Thomas Gleixner wrote:
I totally agree, and we're on the same page. I think you'll find that in the past I always carry through, the task_work notification was somewhat of a rush due to a hang related to it. For this particular case, the cleanups and arch additions are pretty much ready to go.

As we seem to be on the same page with this, let me suggest how this should go:

1) A cleanup for the task_work_add() mess. This is trivial enough and should go in before rc1.

2) The TIF_NOTIFY_RESUME change is a nice cleanup on it's own and can go before rc1 as well.

This gets stuff out of the way and reduces conflict surface.

3) Core infrastructure (patch 2 + 3 + 5) of this series

Please make the changes I asked for in the generic entry code and moving the handling into get_signal() for everybody else.

So get_signal() gains:

     if (!IS_ENABLED(CONFIG_GENERIC_ENTRY) {
	 (test_thread_flag(TIF_NOTIFY_SIGNAL))
		tracehook_notify_signal();

         if (!task_sigpending(current))
 		return 0;
     }

And with that you don't have to touch do_signal() in any architecture except x86 which becomes:

arch_do_signal_or_restart(bool sigpending)

4) Conversion of all architectures which means adding the TIF bit.

If the architecture folks are happy, then this can be collected in tip, which would be preferred because then

5) Cleanups

can just go on top.

Hmm?

Thanks,

tglx

author maintainer
#45 lore raw

Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available

Quoted 9 lines · Thomas Gleixner

Jens,

Quoted 5 lines · Jens Axboe

On 10/16/20 3:00 AM, Thomas Gleixner wrote:
I totally agree, and we're on the same page. I think you'll find that in the past I always carry through, the task_work notification was somewhat of a rush due to a hang related to it. For this particular case, the cleanups and arch additions are pretty much ready to go.

Quoted 5 lines

As we seem to be on the same page with this, let me suggest how this should go:

1) A cleanup for the task_work_add() mess. This is trivial enough and should go in before rc1.

No problem, I'll get that posted shortly.

Quoted 2 lines

2) The TIF_NOTIFY_RESUME change is a nice cleanup on it's own and can go before rc1 as well.

Would you mind taking that one? It's good to go.

Quoted 15 lines

3) Core infrastructure (patch 2 + 3 + 5) of this series

Please make the changes I asked for in the generic entry code and moving the handling into get_signal() for everybody else.

   So get_signal() gains:

     if (!IS_ENABLED(CONFIG_GENERIC_ENTRY) {
	 (test_thread_flag(TIF_NOTIFY_SIGNAL))
		tracehook_notify_signal();

         if (!task_sigpending(current))
 		return 0;
     }
Quoted 4 lines

And with that you don't have to touch do_signal() in any architecture except x86 which becomes:

arch_do_signal_or_restart(bool sigpending)

Already did most of this, just need to handle the !CONFIG_GENERIC_ENTRY for get_signal() and adapt the existing non-generic arch patches to this.

Quoted 4 lines

4) Conversion of all architectures which means adding the TIF bit.

If the architecture folks are happy, then this can be collected in tip, which would be preferred because then

Mostly done,

Quoted 6 lines

5) Cleanups

can just go on top.

Hmm?

Sounds good to me, as long as we keep the existing ordering with x86/generic TIF_NOTIFY_SIGNAL support being able to move forward before all archs have acked the arch specific change. Doesn't really change how I'll get it done, and we're mostly there. Just don't anything gated on potential slowest common denominator.

Signature · 1 line
Jens Axboe