io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHSET v5] Add support for TIF_NOTIFY_SIGNAL
@ 2020-10-15 13:16 Jens Axboe
  2020-10-15 13:16 ` [PATCH 1/5] tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume() Jens Axboe
                   ` (4 more replies)
  0 siblings, 5 replies; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 13:16 UTC (permalink / raw)
  To: linux-kernel, io-uring; +Cc: peterz, oleg, tglx

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

-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 46+ messages in thread

* [PATCH 1/5] tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume()
  2020-10-15 13:16 [PATCHSET v5] Add support for TIF_NOTIFY_SIGNAL Jens Axboe
@ 2020-10-15 13:16 ` Jens Axboe
  2020-10-15 14:42   ` Oleg Nesterov
  2020-10-15 13:16 ` [PATCH 2/5] kernel: add task_sigpending() helper Jens Axboe
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 13:16 UTC (permalink / raw)
  To: linux-kernel, io-uring; +Cc: peterz, oleg, tglx, Jens Axboe

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

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 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(-)

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


^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH 2/5] kernel: add task_sigpending() helper
  2020-10-15 13:16 [PATCHSET v5] Add support for TIF_NOTIFY_SIGNAL Jens Axboe
  2020-10-15 13:16 ` [PATCH 1/5] tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume() Jens Axboe
@ 2020-10-15 13:16 ` Jens Axboe
  2020-10-15 14:42   ` Oleg Nesterov
  2020-10-15 13:16 ` [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL Jens Axboe
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 13:16 UTC (permalink / raw)
  To: linux-kernel, io-uring; +Cc: peterz, oleg, tglx, 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.

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 include/linux/sched/signal.h | 9 +++++++--
 kernel/events/uprobes.c      | 2 +-
 kernel/signal.c              | 8 ++++----
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index 1bad18a1d8ba..404145dc536e 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -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)
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 0e18aaf23a7b..8bb26a338e06 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -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);
diff --git a/kernel/signal.c b/kernel/signal.c
index a38b3edc6851..9f86246a8637 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -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);
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL
  2020-10-15 13:16 [PATCHSET v5] Add support for TIF_NOTIFY_SIGNAL Jens Axboe
  2020-10-15 13:16 ` [PATCH 1/5] tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume() Jens Axboe
  2020-10-15 13:16 ` [PATCH 2/5] kernel: add task_sigpending() helper Jens Axboe
@ 2020-10-15 13:16 ` Jens Axboe
  2020-10-15 14:31   ` Oleg Nesterov
  2020-10-15 14:44   ` Oleg Nesterov
  2020-10-15 13:17 ` [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL Jens Axboe
  2020-10-15 13:17 ` [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available Jens Axboe
  4 siblings, 2 replies; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 13:16 UTC (permalink / raw)
  To: linux-kernel, io-uring; +Cc: peterz, oleg, tglx, 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.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 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(-)

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index be0d7d4152ec..d18304e84c09 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -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;
 
diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
index 159c7476b11b..42e899b3b4a1 100644
--- a/include/linux/entry-common.h
+++ b/include/linux/entry-common.h
@@ -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()
diff --git a/include/linux/entry-kvm.h b/include/linux/entry-kvm.h
index 0cef17afb41a..9b93f8584ff7 100644
--- a/include/linux/entry-kvm.h
+++ b/include/linux/entry-kvm.h
@@ -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;
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index 404145dc536e..b2ecc34284b0 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -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();
 }
diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
index b480e1a07ed8..0a5bb866e7a6 100644
--- a/include/linux/tracehook.h
+++ b/include/linux/tracehook.h
@@ -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> */
diff --git a/kernel/entry/common.c b/kernel/entry/common.c
index d20ab4ac7183..bd3cf6279e94 100644
--- a/kernel/entry/common.c
+++ b/kernel/entry/common.c
@@ -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);
diff --git a/kernel/entry/kvm.c b/kernel/entry/kvm.c
index b6678a5e3cf6..49972ee99aff 100644
--- a/kernel/entry/kvm.c
+++ b/kernel/entry/kvm.c
@@ -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;
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-15 13:16 [PATCHSET v5] Add support for TIF_NOTIFY_SIGNAL Jens Axboe
                   ` (2 preceding siblings ...)
  2020-10-15 13:16 ` [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL Jens Axboe
@ 2020-10-15 13:17 ` Jens Axboe
  2020-10-15 14:11   ` Thomas Gleixner
                     ` (2 more replies)
  2020-10-15 13:17 ` [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available Jens Axboe
  4 siblings, 3 replies; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 13:17 UTC (permalink / raw)
  To: linux-kernel, io-uring; +Cc: peterz, oleg, tglx, 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.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 arch/x86/include/asm/thread_info.h | 2 ++
 arch/x86/kernel/signal.c           | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index 267701ae3d86..86ade67f21b7 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -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)
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index d18304e84c09..ec6490e53dc3 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -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;
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 46+ messages in thread

* [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-15 13:16 [PATCHSET v5] Add support for TIF_NOTIFY_SIGNAL Jens Axboe
                   ` (3 preceding siblings ...)
  2020-10-15 13:17 ` [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL Jens Axboe
@ 2020-10-15 13:17 ` Jens Axboe
  2020-10-15 15:49   ` Oleg Nesterov
  4 siblings, 1 reply; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 13:17 UTC (permalink / raw)
  To: linux-kernel, io-uring; +Cc: peterz, oleg, tglx, Jens Axboe, Roman Gershman

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.

Reported-by: Roman Gershman <romger@amazon.com>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 kernel/task_work.c | 41 +++++++++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 12 deletions(-)

diff --git a/kernel/task_work.c b/kernel/task_work.c
index 613b2d634af8..81163b946224 100644
--- a/kernel/task_work.c
+++ b/kernel/task_work.c
@@ -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;
 	}
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-15 13:17 ` [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL Jens Axboe
@ 2020-10-15 14:11   ` Thomas Gleixner
  2020-10-15 14:31     ` Jens Axboe
  2020-10-15 14:34     ` Oleg Nesterov
  2020-10-15 14:44   ` Oleg Nesterov
  2020-10-20 10:57   ` introduce asm-generic/thread_info.h ? Oleg Nesterov
  2 siblings, 2 replies; 46+ messages in thread
From: Thomas Gleixner @ 2020-10-15 14:11 UTC (permalink / raw)
  To: Jens Axboe, linux-kernel, io-uring; +Cc: peterz, oleg, Jens Axboe

On Thu, Oct 15 2020 at 07:17, Jens Axboe wrote:
> --- a/arch/x86/kernel/signal.c
> +++ b/arch/x86/kernel/signal.c
> @@ -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;

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

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-15 14:11   ` Thomas Gleixner
@ 2020-10-15 14:31     ` Jens Axboe
  2020-10-15 14:34       ` Thomas Gleixner
  2020-10-15 14:36       ` Oleg Nesterov
  2020-10-15 14:34     ` Oleg Nesterov
  1 sibling, 2 replies; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 14:31 UTC (permalink / raw)
  To: Thomas Gleixner, linux-kernel, io-uring; +Cc: peterz, oleg

On 10/15/20 8:11 AM, Thomas Gleixner wrote:
> On Thu, Oct 15 2020 at 07:17, Jens Axboe wrote:
>> --- a/arch/x86/kernel/signal.c
>> +++ b/arch/x86/kernel/signal.c
>> @@ -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;
> 
> 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);
>       }

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.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL
  2020-10-15 13:16 ` [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL Jens Axboe
@ 2020-10-15 14:31   ` Oleg Nesterov
  2020-10-15 14:33     ` Jens Axboe
  2020-10-15 14:44   ` Oleg Nesterov
  1 sibling, 1 reply; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 14:31 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15, Jens Axboe wrote:
>
>  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);
>  }

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.


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL
  2020-10-15 14:31   ` Oleg Nesterov
@ 2020-10-15 14:33     ` Jens Axboe
  2020-10-15 14:37       ` Oleg Nesterov
  0 siblings, 1 reply; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 14:33 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15/20 8:31 AM, Oleg Nesterov wrote:
> On 10/15, Jens Axboe wrote:
>>
>>  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);
>>  }
> 
> 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 ?

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.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-15 14:11   ` Thomas Gleixner
  2020-10-15 14:31     ` Jens Axboe
@ 2020-10-15 14:34     ` Oleg Nesterov
  2020-10-15 14:54       ` Thomas Gleixner
  2020-10-16  9:55       ` Thomas Gleixner
  1 sibling, 2 replies; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 14:34 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Jens Axboe, linux-kernel, io-uring, peterz

On 10/15, Thomas Gleixner wrote:
>
> On Thu, Oct 15 2020 at 07:17, Jens Axboe wrote:
> > --- a/arch/x86/kernel/signal.c
> > +++ b/arch/x86/kernel/signal.c
> > @@ -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;
> 
> 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);
>       }

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

Oleg.


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-15 14:31     ` Jens Axboe
@ 2020-10-15 14:34       ` Thomas Gleixner
  2020-10-15 14:35         ` Jens Axboe
  2020-10-15 14:36       ` Oleg Nesterov
  1 sibling, 1 reply; 46+ messages in thread
From: Thomas Gleixner @ 2020-10-15 14:34 UTC (permalink / raw)
  To: Jens Axboe, linux-kernel, io-uring; +Cc: peterz, oleg

On Thu, Oct 15 2020 at 08:31, Jens Axboe wrote:
> 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);
> }
>
> 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

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-15 14:34       ` Thomas Gleixner
@ 2020-10-15 14:35         ` Jens Axboe
  0 siblings, 0 replies; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 14:35 UTC (permalink / raw)
  To: Thomas Gleixner, linux-kernel, io-uring; +Cc: peterz, oleg

On 10/15/20 8:34 AM, Thomas Gleixner wrote:
> On Thu, Oct 15 2020 at 08:31, Jens Axboe wrote:
>> 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);
>> }
>>
>> 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.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-15 14:31     ` Jens Axboe
  2020-10-15 14:34       ` Thomas Gleixner
@ 2020-10-15 14:36       ` Oleg Nesterov
  2020-10-15 14:42         ` Jens Axboe
  1 sibling, 1 reply; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 14:36 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Thomas Gleixner, linux-kernel, io-uring, peterz

On 10/15, Jens Axboe wrote:
>
> 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.

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

Oleg.


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL
  2020-10-15 14:33     ` Jens Axboe
@ 2020-10-15 14:37       ` Oleg Nesterov
  2020-10-15 14:43         ` Jens Axboe
  2020-10-15 15:01         ` Thomas Gleixner
  0 siblings, 2 replies; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 14:37 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15, Jens Axboe wrote:
>
> On 10/15/20 8:31 AM, Oleg Nesterov wrote:
> > On 10/15, Jens Axboe wrote:
> >>
> >>  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);
> >>  }
> > 
> > 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 ?
> 
> 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.


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-15 14:36       ` Oleg Nesterov
@ 2020-10-15 14:42         ` Jens Axboe
  0 siblings, 0 replies; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 14:42 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Thomas Gleixner, linux-kernel, io-uring, peterz

On 10/15/20 8:36 AM, Oleg Nesterov wrote:
> On 10/15, Jens Axboe wrote:
>>
>> 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.
> 
> No, this can't work. We need to restart the syscall if TIF_NOTIFY_SIGNAL.

Yeah braino, Thomas caught that one too.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 1/5] tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume()
  2020-10-15 13:16 ` [PATCH 1/5] tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume() Jens Axboe
@ 2020-10-15 14:42   ` Oleg Nesterov
  2020-10-15 14:43     ` Jens Axboe
  0 siblings, 1 reply; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 14:42 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15, Jens Axboe wrote:
>
> All the callers currently do this, clean it up and move the clearing
> into tracehook_notify_resume() instead.
>
> Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Jens Axboe <axboe@kernel.dk>

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

Reviewed-by: Oleg Nesterov <oleg@redhat.com>



^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 2/5] kernel: add task_sigpending() helper
  2020-10-15 13:16 ` [PATCH 2/5] kernel: add task_sigpending() helper Jens Axboe
@ 2020-10-15 14:42   ` Oleg Nesterov
  0 siblings, 0 replies; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 14:42 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15, Jens Axboe wrote:
>
> 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.
> 
> Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Jens Axboe <axboe@kernel.dk>

the same,

Reviewed-by: Oleg Nesterov <oleg@redhat.com>


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL
  2020-10-15 14:37       ` Oleg Nesterov
@ 2020-10-15 14:43         ` Jens Axboe
  2020-10-15 14:47           ` Oleg Nesterov
  2020-10-15 15:01         ` Thomas Gleixner
  1 sibling, 1 reply; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 14:43 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15/20 8:37 AM, Oleg Nesterov wrote:
> On 10/15, Jens Axboe wrote:
>>
>> On 10/15/20 8:31 AM, Oleg Nesterov wrote:
>>> On 10/15, Jens Axboe wrote:
>>>>
>>>>  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);
>>>>  }
>>>
>>> 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 ?
>>
>> 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?

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 1/5] tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume()
  2020-10-15 14:42   ` Oleg Nesterov
@ 2020-10-15 14:43     ` Jens Axboe
  0 siblings, 0 replies; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 14:43 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15/20 8:42 AM, Oleg Nesterov wrote:
> On 10/15, Jens Axboe wrote:
>>
>> All the callers currently do this, clean it up and move the clearing
>> into tracehook_notify_resume() instead.
>>
>> Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
>> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> 
> in case you didn't notice I already acked this change ;)
> 
> Reviewed-by: Oleg Nesterov <oleg@redhat.com>

Apparently I missed that - thanks, added!

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL
  2020-10-15 13:16 ` [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL Jens Axboe
  2020-10-15 14:31   ` Oleg Nesterov
@ 2020-10-15 14:44   ` Oleg Nesterov
  1 sibling, 0 replies; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 14:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15, Jens Axboe wrote:
>
> 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.
>
> Signed-off-by: Jens Axboe <axboe@kernel.dk>

So I strongly disagree with CONFIG_GENERIC_ENTRY. Otherwise,

Reviewed-by: Oleg Nesterov <oleg@redhat.com>


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-15 13:17 ` [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL Jens Axboe
  2020-10-15 14:11   ` Thomas Gleixner
@ 2020-10-15 14:44   ` Oleg Nesterov
  2020-10-20 10:57   ` introduce asm-generic/thread_info.h ? Oleg Nesterov
  2 siblings, 0 replies; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 14:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15, Jens Axboe wrote:
>
> 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.
> 
> Signed-off-by: Jens Axboe <axboe@kernel.dk>

Reviewed-by: Oleg Nesterov <oleg@redhat.com>


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL
  2020-10-15 14:43         ` Jens Axboe
@ 2020-10-15 14:47           ` Oleg Nesterov
  2020-10-15 14:53             ` Oleg Nesterov
  0 siblings, 1 reply; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 14:47 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15, Jens Axboe wrote:
>
> On 10/15/20 8:37 AM, Oleg Nesterov wrote:
> > On 10/15, Jens Axboe wrote:
> >>
> >> On 10/15/20 8:31 AM, Oleg Nesterov wrote:
> >>> On 10/15, Jens Axboe wrote:
> >>>>
> >>>>  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);
> >>>>  }
> >>>
> >>> 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 ?
> >>
> >> 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.

plus we can't kill the ugly JOBCTL_TASK_WORK.

Oleg.


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL
  2020-10-15 14:47           ` Oleg Nesterov
@ 2020-10-15 14:53             ` Oleg Nesterov
  2020-10-15 14:56               ` Jens Axboe
  0 siblings, 1 reply; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 14:53 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15, Oleg Nesterov wrote:
>
> On 10/15, Jens Axboe wrote:
> >
> > 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.


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-15 14:34     ` Oleg Nesterov
@ 2020-10-15 14:54       ` Thomas Gleixner
  2020-10-15 15:17         ` Oleg Nesterov
  2020-10-16  9:55       ` Thomas Gleixner
  1 sibling, 1 reply; 46+ messages in thread
From: Thomas Gleixner @ 2020-10-15 14:54 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Jens Axboe, linux-kernel, io-uring, peterz

On Thu, Oct 15 2020 at 16:34, Oleg Nesterov wrote:
> On 10/15, Thomas Gleixner wrote:
>> 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);
>>       }
>
> 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

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL
  2020-10-15 14:53             ` Oleg Nesterov
@ 2020-10-15 14:56               ` Jens Axboe
  0 siblings, 0 replies; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 14:56 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15/20 8:53 AM, Oleg Nesterov wrote:
> On 10/15, Oleg Nesterov wrote:
>>
>> On 10/15, Jens Axboe wrote:
>>>
>>> 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().

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.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL
  2020-10-15 14:37       ` Oleg Nesterov
  2020-10-15 14:43         ` Jens Axboe
@ 2020-10-15 15:01         ` Thomas Gleixner
  2020-10-15 15:27           ` Oleg Nesterov
  1 sibling, 1 reply; 46+ messages in thread
From: Thomas Gleixner @ 2020-10-15 15:01 UTC (permalink / raw)
  To: Oleg Nesterov, Jens Axboe; +Cc: linux-kernel, io-uring, peterz

On Thu, Oct 15 2020 at 16:37, Oleg Nesterov wrote:
> On 10/15, Jens Axboe wrote:
>> On 10/15/20 8:31 AM, Oleg Nesterov wrote:
>> > 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 ?
>> 
>> 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



^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-15 14:54       ` Thomas Gleixner
@ 2020-10-15 15:17         ` Oleg Nesterov
  0 siblings, 0 replies; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 15:17 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Jens Axboe, linux-kernel, io-uring, peterz

On 10/15, Thomas Gleixner wrote:
>
> On Thu, Oct 15 2020 at 16:34, Oleg Nesterov wrote:
> > On 10/15, Thomas Gleixner wrote:
> >> 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);
> >>       }
> >
> > 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.

> 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.


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL
  2020-10-15 15:01         ` Thomas Gleixner
@ 2020-10-15 15:27           ` Oleg Nesterov
  0 siblings, 0 replies; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 15:27 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Jens Axboe, linux-kernel, io-uring, peterz

On 10/15, Thomas Gleixner wrote:
>
> On Thu, Oct 15 2020 at 16:37, Oleg Nesterov wrote:
> > On 10/15, Jens Axboe wrote:
> >> On 10/15/20 8:31 AM, Oleg Nesterov wrote:
> >> > 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 ?
> >>
> >> 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.

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.


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-15 13:17 ` [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available Jens Axboe
@ 2020-10-15 15:49   ` Oleg Nesterov
  2020-10-15 18:39     ` Jens Axboe
  0 siblings, 1 reply; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-15 15:49 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, io-uring, peterz, tglx, Roman Gershman

On 10/15, Jens Axboe wrote:
>
> Reviewed-by: Oleg Nesterov <oleg@redhat.com>

Yes, but ...

> +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.


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-15 15:49   ` Oleg Nesterov
@ 2020-10-15 18:39     ` Jens Axboe
  2020-10-16  9:00       ` Thomas Gleixner
  0 siblings, 1 reply; 46+ messages in thread
From: Jens Axboe @ 2020-10-15 18:39 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: linux-kernel, io-uring, peterz, tglx, Roman Gershman

On 10/15/20 9:49 AM, Oleg Nesterov wrote:
> On 10/15, Jens Axboe wrote:
>>
>> Reviewed-by: Oleg Nesterov <oleg@redhat.com>
> 
> Yes, but ...
> 
>> +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.

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?

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-15 18:39     ` Jens Axboe
@ 2020-10-16  9:00       ` Thomas Gleixner
  2020-10-16  9:39         ` Thomas Gleixner
  2020-10-16 13:33         ` Jens Axboe
  0 siblings, 2 replies; 46+ messages in thread
From: Thomas Gleixner @ 2020-10-16  9:00 UTC (permalink / raw)
  To: Jens Axboe, Oleg Nesterov; +Cc: linux-kernel, io-uring, peterz, Roman Gershman

On Thu, Oct 15 2020 at 12:39, Jens Axboe wrote:
> On 10/15/20 9:49 AM, Oleg Nesterov wrote:
>> 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...

> 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.

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

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-16  9:00       ` Thomas Gleixner
@ 2020-10-16  9:39         ` Thomas Gleixner
  2020-10-16 13:35           ` Jens Axboe
  2020-10-16 13:33         ` Jens Axboe
  1 sibling, 1 reply; 46+ messages in thread
From: Thomas Gleixner @ 2020-10-16  9:39 UTC (permalink / raw)
  To: Jens Axboe, Oleg Nesterov; +Cc: linux-kernel, io-uring, peterz, Roman Gershman

On Fri, Oct 16 2020 at 11:00, Thomas Gleixner wrote:
> On Thu, Oct 15 2020 at 12:39, Jens Axboe wrote:
>> 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:

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


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-15 14:34     ` Oleg Nesterov
  2020-10-15 14:54       ` Thomas Gleixner
@ 2020-10-16  9:55       ` Thomas Gleixner
  2020-10-16 10:54         ` Oleg Nesterov
  1 sibling, 1 reply; 46+ messages in thread
From: Thomas Gleixner @ 2020-10-16  9:55 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Jens Axboe, linux-kernel, io-uring, peterz

On Thu, Oct 15 2020 at 16:34, Oleg Nesterov wrote:
> On 10/15, Thomas Gleixner wrote:
>> 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);
>>       }
>
> 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

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-16  9:55       ` Thomas Gleixner
@ 2020-10-16 10:54         ` Oleg Nesterov
  2020-10-16 13:07           ` Thomas Gleixner
  0 siblings, 1 reply; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-16 10:54 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Jens Axboe, linux-kernel, io-uring, peterz

On 10/16, Thomas Gleixner wrote:
>
> On Thu, Oct 15 2020 at 16:34, Oleg Nesterov wrote:
> > On 10/15, Thomas Gleixner wrote:
> >> 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);
> >>       }
> >
> > 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.

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

But I won't argue, this is subjective.

> 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.


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL
  2020-10-16 10:54         ` Oleg Nesterov
@ 2020-10-16 13:07           ` Thomas Gleixner
  0 siblings, 0 replies; 46+ messages in thread
From: Thomas Gleixner @ 2020-10-16 13:07 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Jens Axboe, linux-kernel, io-uring, peterz

On Fri, Oct 16 2020 at 12:54, Oleg Nesterov wrote:
> 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
>
> 	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

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-16  9:00       ` Thomas Gleixner
  2020-10-16  9:39         ` Thomas Gleixner
@ 2020-10-16 13:33         ` Jens Axboe
  2020-10-16 14:11           ` Thomas Gleixner
  1 sibling, 1 reply; 46+ messages in thread
From: Jens Axboe @ 2020-10-16 13:33 UTC (permalink / raw)
  To: Thomas Gleixner, Oleg Nesterov
  Cc: linux-kernel, io-uring, peterz, Roman Gershman

On 10/16/20 3:00 AM, Thomas Gleixner wrote:
> On Thu, Oct 15 2020 at 12:39, Jens Axboe wrote:
>> On 10/15/20 9:49 AM, Oleg Nesterov wrote:
>>> 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...
> 
>> 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.
> 
> 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.

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.

> 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.

> 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.
 
> 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.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-16  9:39         ` Thomas Gleixner
@ 2020-10-16 13:35           ` Jens Axboe
  2020-10-16 14:17             ` Thomas Gleixner
  0 siblings, 1 reply; 46+ messages in thread
From: Jens Axboe @ 2020-10-16 13:35 UTC (permalink / raw)
  To: Thomas Gleixner, Oleg Nesterov
  Cc: linux-kernel, io-uring, peterz, Roman Gershman

On 10/16/20 3:39 AM, Thomas Gleixner wrote:
> On Fri, Oct 16 2020 at 11:00, Thomas Gleixner wrote:
>> On Thu, Oct 15 2020 at 12:39, Jens Axboe wrote:
>>> 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:
> 
>>>> 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.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-16 13:33         ` Jens Axboe
@ 2020-10-16 14:11           ` Thomas Gleixner
  2020-10-16 14:22             ` Jens Axboe
  0 siblings, 1 reply; 46+ messages in thread
From: Thomas Gleixner @ 2020-10-16 14:11 UTC (permalink / raw)
  To: Jens Axboe, Oleg Nesterov; +Cc: linux-kernel, io-uring, peterz, Roman Gershman

Jens,

On Fri, Oct 16 2020 at 07:33, Jens Axboe wrote:
> 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

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-16 13:35           ` Jens Axboe
@ 2020-10-16 14:17             ` Thomas Gleixner
  2020-10-16 14:51               ` Oleg Nesterov
  0 siblings, 1 reply; 46+ messages in thread
From: Thomas Gleixner @ 2020-10-16 14:17 UTC (permalink / raw)
  To: Jens Axboe, Oleg Nesterov; +Cc: linux-kernel, io-uring, peterz, Roman Gershman

On Fri, Oct 16 2020 at 07:35, Jens Axboe wrote:
> On 10/16/20 3:39 AM, Thomas Gleixner wrote:
>> 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.

> 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



^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-16 14:11           ` Thomas Gleixner
@ 2020-10-16 14:22             ` Jens Axboe
  0 siblings, 0 replies; 46+ messages in thread
From: Jens Axboe @ 2020-10-16 14:22 UTC (permalink / raw)
  To: Thomas Gleixner, Oleg Nesterov
  Cc: linux-kernel, io-uring, peterz, Roman Gershman

On 10/16/20 8:11 AM, Thomas Gleixner wrote:
> Jens,
> 
> On Fri, Oct 16 2020 at 07:33, Jens Axboe wrote:
>> 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.

No problem, I'll get that posted shortly.

> 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.

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

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.

> 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,
> 
> 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.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-16 14:17             ` Thomas Gleixner
@ 2020-10-16 14:51               ` Oleg Nesterov
  2020-10-16 14:53                 ` Jens Axboe
  0 siblings, 1 reply; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-16 14:51 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Jens Axboe, linux-kernel, io-uring, peterz, Roman Gershman

On 10/16, Thomas Gleixner wrote:
>
> 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.


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-16 14:51               ` Oleg Nesterov
@ 2020-10-16 14:53                 ` Jens Axboe
  2020-10-16 18:03                   ` Thomas Gleixner
  0 siblings, 1 reply; 46+ messages in thread
From: Jens Axboe @ 2020-10-16 14:53 UTC (permalink / raw)
  To: Oleg Nesterov, Thomas Gleixner
  Cc: linux-kernel, io-uring, peterz, Roman Gershman

On 10/16/20 8:51 AM, Oleg Nesterov wrote:
> On 10/16, Thomas Gleixner wrote:
>>
>> 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.

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.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-16 14:53                 ` Jens Axboe
@ 2020-10-16 18:03                   ` Thomas Gleixner
  2020-10-16 18:05                     ` Jens Axboe
  0 siblings, 1 reply; 46+ messages in thread
From: Thomas Gleixner @ 2020-10-16 18:03 UTC (permalink / raw)
  To: Jens Axboe, Oleg Nesterov; +Cc: linux-kernel, io-uring, peterz, Roman Gershman

On Fri, Oct 16 2020 at 08:53, Jens Axboe wrote:
> On 10/16/20 8:51 AM, Oleg Nesterov wrote:
>> On 10/16, Thomas Gleixner wrote:
>>>
>>> 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.
>
> 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 :)

^ permalink raw reply	[flat|nested] 46+ messages in thread

* Re: [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available
  2020-10-16 18:03                   ` Thomas Gleixner
@ 2020-10-16 18:05                     ` Jens Axboe
  0 siblings, 0 replies; 46+ messages in thread
From: Jens Axboe @ 2020-10-16 18:05 UTC (permalink / raw)
  To: Thomas Gleixner, Oleg Nesterov
  Cc: linux-kernel, io-uring, peterz, Roman Gershman

On 10/16/20 12:03 PM, Thomas Gleixner wrote:
> On Fri, Oct 16 2020 at 08:53, Jens Axboe wrote:
>> On 10/16/20 8:51 AM, Oleg Nesterov wrote:
>>> On 10/16, Thomas Gleixner wrote:
>>>>
>>>> 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.
>>
>> 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...

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 46+ messages in thread

* introduce asm-generic/thread_info.h ?
  2020-10-15 13:17 ` [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL Jens Axboe
  2020-10-15 14:11   ` Thomas Gleixner
  2020-10-15 14:44   ` Oleg Nesterov
@ 2020-10-20 10:57   ` Oleg Nesterov
  2 siblings, 0 replies; 46+ messages in thread
From: Oleg Nesterov @ 2020-10-20 10:57 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, io-uring, peterz, tglx

On 10/15, Jens Axboe wrote:
>
> --- a/arch/x86/include/asm/thread_info.h
> +++ b/arch/x86/include/asm/thread_info.h
> @@ -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.

--- /dev/null
+++ x/include/asm-generic/thread_info.h
@@ -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)
--- x/arch/alpha/include/asm/thread_info.h
+++ x/arch/alpha/include/asm/thread_info.h
@@ -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)
 
--- x/arch/arc/include/asm/thread_info.h
+++ x/arch/arc/include/asm/thread_info.h
@@ -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 | \
--- x/arch/arm/include/asm/thread_info.h
+++ x/arch/arm/include/asm/thread_info.h
@@ -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 */
--- x/arch/arm64/include/asm/thread_info.h
+++ x/arch/arm64/include/asm/thread_info.h
@@ -61,37 +61,26 @@
 
 #endif
 
-#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_FOREIGN_FPSTATE	3	/* CPU's FP state is not current's */
-#define TIF_UPROBE		4	/* uprobe breakpoint or singlestep */
-#define TIF_FSCHECK		5	/* Check FS is USER_DS on return */
-#define TIF_SYSCALL_TRACE	8	/* syscall trace active */
-#define TIF_SYSCALL_AUDIT	9	/* syscall auditing */
-#define TIF_SYSCALL_TRACEPOINT	10	/* syscall tracepoint for ftrace */
-#define TIF_SECCOMP		11	/* syscall secure computing */
-#define TIF_SYSCALL_EMU		12	/* syscall emulation active */
-#define TIF_MEMDIE		18	/* is terminating due to OOM killer */
-#define TIF_FREEZE		19
-#define TIF_RESTORE_SIGMASK	20
-#define TIF_SINGLESTEP		21
-#define TIF_32BIT		22	/* 32bit process */
-#define TIF_SVE			23	/* Scalable Vector Extension in use */
-#define TIF_SVE_VL_INHERIT	24	/* Inherit sve_vl_onexec across exec */
-#define TIF_SSBD		25	/* Wants SSB mitigation */
-#define TIF_TAGGED_ADDR		26	/* Allow tagged user addresses */
+#include <asm-generic/thread_info.h>
+
+#define TIF_FOREIGN_FPSTATE	(TIF__ARCH+0)	/* CPU's FP state is not current's */
+#define TIF_FSCHECK		(TIF__ARCH+1)	/* Check FS is USER_DS on return */
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+2)	/* syscall auditing */
+#define TIF_SYSCALL_TRACEPOINT	(TIF__ARCH+3)	/* syscall tracepoint for ftrace */
+#define TIF_SYSCALL_EMU		(TIF__ARCH+4)	/* syscall emulation active */
+#define TIF_FREEZE		(TIF__ARCH+5)
+#define TIF_RESTORE_SIGMASK	(TIF__ARCH+6)
+#define TIF_SINGLESTEP		(TIF__ARCH+7)
+#define TIF_32BIT		(TIF__ARCH+8)	/* 32bit process */
+#define TIF_SVE			(TIF__ARCH+9)	/* Scalable Vector Extension in use */
+#define TIF_SVE_VL_INHERIT	(TIF__ARCH+10)	/* Inherit sve_vl_onexec across exec */
+#define TIF_SSBD		(TIF__ARCH+11)	/* Wants SSB mitigation */
+#define TIF_TAGGED_ADDR		(TIF__ARCH+12)	/* Allow tagged user addresses */
 
-#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
-#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
 #define _TIF_FOREIGN_FPSTATE	(1 << TIF_FOREIGN_FPSTATE)
-#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_SYSCALL_EMU	(1 << TIF_SYSCALL_EMU)
-#define _TIF_UPROBE		(1 << TIF_UPROBE)
 #define _TIF_FSCHECK		(1 << TIF_FSCHECK)
 #define _TIF_SINGLESTEP		(1 << TIF_SINGLESTEP)
 #define _TIF_32BIT		(1 << TIF_32BIT)
--- x/arch/csky/include/asm/thread_info.h
+++ x/arch/csky/include/asm/thread_info.h
@@ -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)
--- x/arch/h8300/include/asm/thread_info.h
+++ x/arch/h8300/include/asm/thread_info.h
@@ -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)
--- x/arch/hexagon/include/asm/thread_info.h
+++ x/arch/hexagon/include/asm/thread_info.h
@@ -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 */
--- x/arch/ia64/include/asm/thread_info.h
+++ x/arch/ia64/include/asm/thread_info.h
@@ -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)
--- x/arch/m68k/include/asm/thread_info.h
+++ x/arch/m68k/include/asm/thread_info.h
@@ -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 */
--- x/arch/microblaze/include/asm/thread_info.h
+++ x/arch/microblaze/include/asm/thread_info.h
@@ -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 | \
--- x/arch/mips/include/asm/thread_info.h
+++ x/arch/mips/include/asm/thread_info.h
@@ -109,36 +109,25 @@
  * - pending work-to-be-done flags are in LSW
  * - other flags in MSW
  */
-#define TIF_SIGPENDING		1	/* signal pending */
-#define TIF_NEED_RESCHED	2	/* rescheduling necessary */
-#define TIF_SYSCALL_AUDIT	3	/* syscall auditing active */
-#define TIF_SECCOMP		4	/* secure computing */
-#define TIF_NOTIFY_RESUME	5	/* callback before returning to user */
-#define TIF_UPROBE		6	/* breakpointed or singlestepping */
-#define TIF_RESTORE_SIGMASK	9	/* restore signal mask in do_signal() */
-#define TIF_USEDFPU		16	/* FPU was used by this task this quantum (SMP) */
-#define TIF_MEMDIE		18	/* is terminating due to OOM killer */
-#define TIF_NOHZ		19	/* in adaptive nohz mode */
-#define TIF_FIXADE		20	/* Fix address errors in software */
-#define TIF_LOGADE		21	/* Log address errors to syslog */
-#define TIF_32BIT_REGS		22	/* 32-bit general purpose registers */
-#define TIF_32BIT_ADDR		23	/* 32-bit address space (o32/n32) */
-#define TIF_FPUBOUND		24	/* thread bound to FPU-full CPU set */
-#define TIF_LOAD_WATCH		25	/* If set, load watch registers */
-#define TIF_SYSCALL_TRACEPOINT	26	/* syscall tracepoint instrumentation */
-#define TIF_32BIT_FPREGS	27	/* 32-bit floating point registers */
-#define TIF_HYBRID_FPREGS	28	/* 64b FP registers, odd singles in bits 63:32 of even doubles */
-#define TIF_USEDMSA		29	/* MSA has been used this quantum */
-#define TIF_MSA_CTX_LIVE	30	/* MSA context must be preserved */
-#define TIF_SYSCALL_TRACE	31	/* syscall trace active */
+#include <asm-generic/thread_info.h>
+
+#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_USEDFPU		(TIF__ARCH+2)	/* FPU was used by this task this quantum (SMP) */
+#define TIF_NOHZ		(TIF__ARCH+3)	/* in adaptive nohz mode */
+#define TIF_FIXADE		(TIF__ARCH+4)	/* Fix address errors in software */
+#define TIF_LOGADE		(TIF__ARCH+5)	/* Log address errors to syslog */
+#define TIF_32BIT_REGS		(TIF__ARCH+6)	/* 32-bit general purpose registers */
+#define TIF_32BIT_ADDR		(TIF__ARCH+7)	/* 32-bit address space (o32/n32) */
+#define TIF_FPUBOUND		(TIF__ARCH+8)	/* thread bound to FPU-full CPU set */
+#define TIF_LOAD_WATCH		(TIF__ARCH+9)	/* If set, load watch registers */
+#define TIF_SYSCALL_TRACEPOINT	(TIF__ARCH+10)	/* syscall tracepoint instrumentation */
+#define TIF_32BIT_FPREGS	(TIF__ARCH+11)	/* 32-bit floating point registers */
+#define TIF_HYBRID_FPREGS	(TIF__ARCH+12)	/* 64b FP registers, odd singles in bits 63:32 of even doubles */
+#define TIF_USEDMSA		(TIF__ARCH+13)	/* MSA has been used this quantum */
+#define TIF_MSA_CTX_LIVE	(TIF__ARCH+14)	/* MSA context must be preserved */
 
-#define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
-#define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
-#define _TIF_SECCOMP		(1<<TIF_SECCOMP)
-#define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
-#define _TIF_UPROBE		(1<<TIF_UPROBE)
 #define _TIF_USEDFPU		(1<<TIF_USEDFPU)
 #define _TIF_NOHZ		(1<<TIF_NOHZ)
 #define _TIF_FIXADE		(1<<TIF_FIXADE)
--- x/arch/nds32/include/asm/thread_info.h
+++ x/arch/nds32/include/asm/thread_info.h
@@ -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)
--- x/arch/nios2/include/asm/thread_info.h
+++ x/arch/nios2/include/asm/thread_info.h
@@ -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)
--- x/arch/openrisc/include/asm/thread_info.h
+++ x/arch/openrisc/include/asm/thread_info.h
@@ -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)
 
--- x/arch/parisc/include/asm/thread_info.h
+++ x/arch/parisc/include/asm/thread_info.h
@@ -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 | \
--- x/arch/powerpc/include/asm/thread_info.h
+++ x/arch/powerpc/include/asm/thread_info.h
@@ -87,46 +87,35 @@
 /*
  * 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_FSCHECK		3	/* Check FS is USER_DS on return */
-#define TIF_SYSCALL_EMU		4	/* syscall emulation active */
-#define TIF_RESTORE_TM		5	/* need to restore TM FP/VEC/VSX */
-#define TIF_PATCH_PENDING	6	/* pending live patching update */
-#define TIF_SYSCALL_AUDIT	7	/* syscall auditing active */
-#define TIF_SINGLESTEP		8	/* singlestepping active */
-#define TIF_NOHZ		9	/* in adaptive nohz mode */
-#define TIF_SECCOMP		10	/* secure computing */
-#define TIF_RESTOREALL		11	/* Restore all regs (implies NOERROR) */
-#define TIF_NOERROR		12	/* Force successful syscall return */
-#define TIF_NOTIFY_RESUME	13	/* callback before returning to user */
-#define TIF_UPROBE		14	/* breakpointed or single-stepping */
-#define TIF_SYSCALL_TRACEPOINT	15	/* syscall tracepoint instrumentation */
-#define TIF_EMULATE_STACK_STORE	16	/* Is an instruction emulation
+#include <asm-generic/thread_info.h>
+
+#define TIF_FSCHECK		(TIF__ARCH+0)	/* Check FS is USER_DS on return */
+#define TIF_SYSCALL_EMU		(TIF__ARCH+1)	/* syscall emulation active */
+#define TIF_RESTORE_TM		(TIF__ARCH+2)	/* need to restore TM FP/VEC/VSX */
+#define TIF_PATCH_PENDING	(TIF__ARCH+3)	/* pending live patching update */
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+4)	/* syscall auditing active */
+#define TIF_SINGLESTEP		(TIF__ARCH+5)	/* singlestepping active */
+#define TIF_NOHZ		(TIF__ARCH+6)	/* in adaptive nohz mode */
+#define TIF_RESTOREALL		(TIF__ARCH+7)	/* Restore all regs (implies NOERROR) */
+#define TIF_NOERROR		(TIF__ARCH+8)	/* Force successful syscall return */
+#define TIF_SYSCALL_TRACEPOINT	(TIF__ARCH+9)	/* syscall tracepoint instrumentation */
+#define TIF_EMULATE_STACK_STORE	(TIF__ARCH+10)	/* Is an instruction emulation
 						for stack store? */
-#define TIF_MEMDIE		17	/* is terminating due to OOM killer */
 #if defined(CONFIG_PPC64)
-#define TIF_ELF2ABI		18	/* function descriptors must die! */
+#define TIF_ELF2ABI		(TIF__ARCH+11)	/* function descriptors must die! */
 #endif
-#define TIF_POLLING_NRFLAG	19	/* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_32BIT		20	/* 32 bit binary */
+#define TIF_POLLING_NRFLAG	(TIF__ARCH+12)	/* true if poll_idle() is polling TIF_NEED_RESCHED */
+#define TIF_32BIT		(TIF__ARCH+13)	/* 32 bit binary */
 
 /* 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_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
 #define _TIF_32BIT		(1<<TIF_32BIT)
 #define _TIF_RESTORE_TM		(1<<TIF_RESTORE_TM)
 #define _TIF_PATCH_PENDING	(1<<TIF_PATCH_PENDING)
 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
 #define _TIF_SINGLESTEP		(1<<TIF_SINGLESTEP)
-#define _TIF_SECCOMP		(1<<TIF_SECCOMP)
 #define _TIF_RESTOREALL		(1<<TIF_RESTOREALL)
 #define _TIF_NOERROR		(1<<TIF_NOERROR)
-#define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
-#define _TIF_UPROBE		(1<<TIF_UPROBE)
 #define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
 #define _TIF_EMULATE_STACK_STORE	(1<<TIF_EMULATE_STACK_STORE)
 #define _TIF_NOHZ		(1<<TIF_NOHZ)
--- x/arch/riscv/include/asm/thread_info.h
+++ x/arch/riscv/include/asm/thread_info.h
@@ -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)
--- x/arch/s390/include/asm/thread_info.h
+++ x/arch/s390/include/asm/thread_info.h
@@ -58,33 +58,24 @@
  * thread information flags bit numbers
  */
 /* _TIF_WORK bits */
-#define TIF_NOTIFY_RESUME	0	/* callback before returning to user */
-#define TIF_SIGPENDING		1	/* signal pending */
-#define TIF_NEED_RESCHED	2	/* rescheduling necessary */
-#define TIF_UPROBE		3	/* breakpointed or single-stepping */
-#define TIF_GUARDED_STORAGE	4	/* load guarded storage control block */
-#define TIF_PATCH_PENDING	5	/* pending live patching update */
-#define TIF_PGSTE		6	/* New mm's will use 4K page tables */
-#define TIF_ISOLATE_BP		8	/* Run process with isolated BP */
-#define TIF_ISOLATE_BP_GUEST	9	/* Run KVM guests with isolated BP */
-
-#define TIF_31BIT		16	/* 32bit process */
-#define TIF_MEMDIE		17	/* is terminating due to OOM killer */
-#define TIF_RESTORE_SIGMASK	18	/* restore signal mask in do_signal() */
-#define TIF_SINGLE_STEP		19	/* This task is single stepped */
-#define TIF_BLOCK_STEP		20	/* This task is block stepped */
-#define TIF_UPROBE_SINGLESTEP	21	/* This task is uprobe single stepped */
+#include <asm-generic/thread_info.h>
+
+#define TIF_GUARDED_STORAGE	(TIF__ARCH+0)	/* load guarded storage control block */
+#define TIF_PATCH_PENDING	(TIF__ARCH+1)	/* pending live patching update */
+#define TIF_PGSTE		(TIF__ARCH+2)	/* New mm's will use 4K page tables */
+#define TIF_ISOLATE_BP		(TIF__ARCH+3)	/* Run process with isolated BP */
+#define TIF_ISOLATE_BP_GUEST	(TIF__ARCH+4)	/* Run KVM guests with isolated BP */
+
+#define TIF_31BIT		(TIF__ARCH+5)	/* 32bit process */
+#define TIF_RESTORE_SIGMASK	(TIF__ARCH+6)	/* restore signal mask in do_signal() */
+#define TIF_SINGLE_STEP		(TIF__ARCH+7)	/* This task is single stepped */
+#define TIF_BLOCK_STEP		(TIF__ARCH+8)	/* This task is block stepped */
+#define TIF_UPROBE_SINGLESTEP	(TIF__ARCH+9)	/* This task is uprobe single stepped */
 
 /* _TIF_TRACE bits */
-#define TIF_SYSCALL_TRACE	24	/* syscall trace active */
-#define TIF_SYSCALL_AUDIT	25	/* syscall auditing active */
-#define TIF_SECCOMP		26	/* secure computing */
-#define TIF_SYSCALL_TRACEPOINT	27	/* syscall tracepoint instrumentation */
-
-#define _TIF_NOTIFY_RESUME	BIT(TIF_NOTIFY_RESUME)
-#define _TIF_SIGPENDING		BIT(TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	BIT(TIF_NEED_RESCHED)
-#define _TIF_UPROBE		BIT(TIF_UPROBE)
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+10)	/* syscall auditing active */
+#define TIF_SYSCALL_TRACEPOINT	(TIF__ARCH+11)	/* syscall tracepoint instrumentation */
+
 #define _TIF_GUARDED_STORAGE	BIT(TIF_GUARDED_STORAGE)
 #define _TIF_PATCH_PENDING	BIT(TIF_PATCH_PENDING)
 #define _TIF_ISOLATE_BP		BIT(TIF_ISOLATE_BP)
@@ -93,9 +84,7 @@
 #define _TIF_31BIT		BIT(TIF_31BIT)
 #define _TIF_SINGLE_STEP	BIT(TIF_SINGLE_STEP)
 
-#define _TIF_SYSCALL_TRACE	BIT(TIF_SYSCALL_TRACE)
 #define _TIF_SYSCALL_AUDIT	BIT(TIF_SYSCALL_AUDIT)
-#define _TIF_SECCOMP		BIT(TIF_SECCOMP)
 #define _TIF_SYSCALL_TRACEPOINT	BIT(TIF_SYSCALL_TRACEPOINT)
 
 #endif /* _ASM_THREAD_INFO_H */
--- x/arch/sh/include/asm/thread_info.h
+++ x/arch/sh/include/asm/thread_info.h
@@ -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)
 
--- x/arch/um/include/asm/thread_info.h
+++ x/arch/um/include/asm/thread_info.h
@@ -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
--- x/arch/x86/include/asm/thread_info.h
+++ x/arch/x86/include/asm/thread_info.h
@@ -74,49 +74,38 @@
  * - these are process state flags that various assembly files
  *   may need to access
  */
-#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_SINGLESTEP		4	/* reenable singlestep on user return*/
-#define TIF_SSBD		5	/* Speculative store bypass disable */
-#define TIF_SYSCALL_EMU		6	/* syscall emulation active */
-#define TIF_SYSCALL_AUDIT	7	/* syscall auditing active */
-#define TIF_SECCOMP		8	/* secure computing */
-#define TIF_SPEC_IB		9	/* Indirect branch speculation mitigation */
-#define TIF_SPEC_FORCE_UPDATE	10	/* Force speculation MSR update in context switch */
-#define TIF_USER_RETURN_NOTIFY	11	/* notify kernel of userspace return */
-#define TIF_UPROBE		12	/* breakpointed or singlestepping */
-#define TIF_PATCH_PENDING	13	/* pending live patching update */
-#define TIF_NEED_FPU_LOAD	14	/* load FPU on return to userspace */
-#define TIF_NOCPUID		15	/* CPUID is not accessible in userland */
-#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_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 */
-#define TIF_FORCED_TF		24	/* true if TF in eflags artificially */
-#define TIF_BLOCKSTEP		25	/* set when we want DEBUGCTLMSR_BTF */
-#define TIF_LAZY_MMU_UPDATES	27	/* task is updating the mmu lazily */
-#define TIF_SYSCALL_TRACEPOINT	28	/* syscall tracepoint instrumentation */
-#define TIF_ADDR32		29	/* 32-bit address space on 64 bits */
-#define TIF_X32			30	/* 32-bit native x86-64 binary */
-#define TIF_FSCHECK		31	/* Check FS is USER_DS on return */
+#include <asm-generic/thread_info.h>
+
+#define TIF_SINGLESTEP		(TIF__ARCH+0)	/* reenable singlestep on user return*/
+#define TIF_SSBD		(TIF__ARCH+1)	/* Speculative store bypass disable */
+#define TIF_SYSCALL_EMU		(TIF__ARCH+2)	/* syscall emulation active */
+#define TIF_SYSCALL_AUDIT	(TIF__ARCH+3)	/* syscall auditing active */
+#define TIF_SPEC_IB		(TIF__ARCH+4)	/* Indirect branch speculation mitigation */
+#define TIF_SPEC_FORCE_UPDATE	(TIF__ARCH+5)	/* Force speculation MSR update in context switch */
+#define TIF_USER_RETURN_NOTIFY	(TIF__ARCH+6)	/* notify kernel of userspace return */
+#define TIF_PATCH_PENDING	(TIF__ARCH+7)	/* pending live patching update */
+#define TIF_NEED_FPU_LOAD	(TIF__ARCH+8)	/* load FPU on return to userspace */
+#define TIF_NOCPUID		(TIF__ARCH+9)	/* CPUID is not accessible in userland */
+#define TIF_NOTSC		(TIF__ARCH+10)	/* TSC is not accessible in userland */
+#define TIF_IA32		(TIF__ARCH+11)	/* IA32 compatibility process */
+#define TIF_SLD			(TIF__ARCH+12)	/* Restore split lock detection on context switch */
+#define TIF_POLLING_NRFLAG	(TIF__ARCH+13)	/* idle is polling for TIF_NEED_RESCHED */
+#define TIF_IO_BITMAP		(TIF__ARCH+14)	/* uses I/O bitmap */
+#define TIF_FORCED_TF		(TIF__ARCH+15)	/* true if TF in eflags artificially */
+#define TIF_BLOCKSTEP		(TIF__ARCH+16)	/* set when we want DEBUGCTLMSR_BTF */
+#define TIF_LAZY_MMU_UPDATES	(TIF__ARCH+17)	/* task is updating the mmu lazily */
+#define TIF_SYSCALL_TRACEPOINT	(TIF__ARCH+18)	/* syscall tracepoint instrumentation */
+#define TIF_ADDR32		(TIF__ARCH+19)	/* 32-bit address space on 64 bits */
+#define TIF_X32			(TIF__ARCH+20)	/* 32-bit native x86-64 binary */
+#define TIF_FSCHECK		(TIF__ARCH+21)	/* Check FS is USER_DS on return */
 
-#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_SSBD		(1 << TIF_SSBD)
 #define _TIF_SYSCALL_EMU	(1 << TIF_SYSCALL_EMU)
 #define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
-#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
 #define _TIF_SPEC_IB		(1 << TIF_SPEC_IB)
 #define _TIF_SPEC_FORCE_UPDATE	(1 << TIF_SPEC_FORCE_UPDATE)
 #define _TIF_USER_RETURN_NOTIFY	(1 << TIF_USER_RETURN_NOTIFY)
-#define _TIF_UPROBE		(1 << TIF_UPROBE)
 #define _TIF_PATCH_PENDING	(1 << TIF_PATCH_PENDING)
 #define _TIF_NEED_FPU_LOAD	(1 << TIF_NEED_FPU_LOAD)
 #define _TIF_NOCPUID		(1 << TIF_NOCPUID)
--- x/arch/xtensa/include/asm/thread_info.h
+++ x/arch/xtensa/include/asm/thread_info.h
@@ -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 | \


^ permalink raw reply	[flat|nested] 46+ messages in thread

end of thread, other threads:[~2020-10-20 10:57 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15 13:16 [PATCHSET v5] Add support for TIF_NOTIFY_SIGNAL Jens Axboe
2020-10-15 13:16 ` [PATCH 1/5] tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume() Jens Axboe
2020-10-15 14:42   ` Oleg Nesterov
2020-10-15 14:43     ` Jens Axboe
2020-10-15 13:16 ` [PATCH 2/5] kernel: add task_sigpending() helper Jens Axboe
2020-10-15 14:42   ` Oleg Nesterov
2020-10-15 13:16 ` [PATCH 3/5] kernel: add support for TIF_NOTIFY_SIGNAL Jens Axboe
2020-10-15 14:31   ` Oleg Nesterov
2020-10-15 14:33     ` Jens Axboe
2020-10-15 14:37       ` Oleg Nesterov
2020-10-15 14:43         ` Jens Axboe
2020-10-15 14:47           ` Oleg Nesterov
2020-10-15 14:53             ` Oleg Nesterov
2020-10-15 14:56               ` Jens Axboe
2020-10-15 15:01         ` Thomas Gleixner
2020-10-15 15:27           ` Oleg Nesterov
2020-10-15 14:44   ` Oleg Nesterov
2020-10-15 13:17 ` [PATCH 4/5] x86: wire up TIF_NOTIFY_SIGNAL Jens Axboe
2020-10-15 14:11   ` Thomas Gleixner
2020-10-15 14:31     ` Jens Axboe
2020-10-15 14:34       ` Thomas Gleixner
2020-10-15 14:35         ` Jens Axboe
2020-10-15 14:36       ` Oleg Nesterov
2020-10-15 14:42         ` Jens Axboe
2020-10-15 14:34     ` Oleg Nesterov
2020-10-15 14:54       ` Thomas Gleixner
2020-10-15 15:17         ` Oleg Nesterov
2020-10-16  9:55       ` Thomas Gleixner
2020-10-16 10:54         ` Oleg Nesterov
2020-10-16 13:07           ` Thomas Gleixner
2020-10-15 14:44   ` Oleg Nesterov
2020-10-20 10:57   ` introduce asm-generic/thread_info.h ? Oleg Nesterov
2020-10-15 13:17 ` [PATCH 5/5] task_work: use TIF_NOTIFY_SIGNAL if available Jens Axboe
2020-10-15 15:49   ` Oleg Nesterov
2020-10-15 18:39     ` Jens Axboe
2020-10-16  9:00       ` Thomas Gleixner
2020-10-16  9:39         ` Thomas Gleixner
2020-10-16 13:35           ` Jens Axboe
2020-10-16 14:17             ` Thomas Gleixner
2020-10-16 14:51               ` Oleg Nesterov
2020-10-16 14:53                 ` Jens Axboe
2020-10-16 18:03                   ` Thomas Gleixner
2020-10-16 18:05                     ` Jens Axboe
2020-10-16 13:33         ` Jens Axboe
2020-10-16 14:11           ` Thomas Gleixner
2020-10-16 14:22             ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).