2020-10-16 19:56:51

by Jens Axboe

[permalink] [raw]
Subject: [PATCHSET v6] Add support for TIF_NOTIFY_SIGNAL

Hi,

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

Cleanups in this series, see changelog. But the arch and cleanup
series that goes after this series is much simpler now that we handle
TIF_NOTIFY_SIGNAL generically for !CONFIG_GENERIC_ENTRY.


Changes since v5:
- Don't make TIF_NOTIFY_SIGNAL dependent on CONFIG_GENERIC_ENTRY
- Handle TIF_NOTIFY_SIGNAL in get_signal() for !CONFIG_GENERIC_ENTRY
- Add handle_signal_work(), and change arch_do_signal() to
arch_do_signal_or_restart() and pass in a 'has_signal' bool for that
- Dropped TIF_NOTIFY_RESUME patch from this series, sent out
separately.


arch/x86/include/asm/thread_info.h | 2 ++
arch/x86/kernel/signal.c | 4 +--
include/linux/entry-common.h | 11 +++++---
include/linux/entry-kvm.h | 4 +--
include/linux/sched/signal.h | 20 ++++++++++++---
include/linux/tracehook.h | 27 ++++++++++++++++++++
kernel/entry/common.c | 14 +++++++---
kernel/entry/kvm.c | 3 +++
kernel/events/uprobes.c | 2 +-
kernel/signal.c | 22 +++++++++++++---
kernel/task_work.c | 41 +++++++++++++++++++++---------
11 files changed, 120 insertions(+), 30 deletions(-)

--
Jens Axboe




2020-10-16 19:56:52

by Jens Axboe

[permalink] [raw]
Subject: [PATCH 1/4] kernel: add task_sigpending() helper

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 <[email protected]>
Reviewed-by: Oleg Nesterov <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
---
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

2020-10-23 13:32:23

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCHSET v6] Add support for TIF_NOTIFY_SIGNAL

On 10/16/20 9:45 AM, Jens Axboe wrote:
> 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.
>
> Cleanups in this series, see changelog. But the arch and cleanup
> series that goes after this series is much simpler now that we handle
> TIF_NOTIFY_SIGNAL generically for !CONFIG_GENERIC_ENTRY.

Any objections to this one? I just rebased this one and the full arch
series that sits on top for -git, but apart from that, no changes.

Thomas, would be nice to know if you're good with patch 2+3 at this
point. Once we get outside of the merge window next week, I'll post
the updated series since we get a few conflicts at this point, and
would be great if you could carry this for 5.11.

--
Jens Axboe

2020-10-26 10:41:12

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCHSET v6] Add support for TIF_NOTIFY_SIGNAL

On Thu, Oct 22 2020 at 20:22, Jens Axboe wrote:
> On 10/16/20 9:45 AM, Jens Axboe wrote:
> Thomas, would be nice to know if you're good with patch 2+3 at this
> point. Once we get outside of the merge window next week, I'll post
> the updated series since we get a few conflicts at this point, and
> would be great if you could carry this for 5.11.

LGTM