2021-03-29 13:30:48

by Miroslav Benes

[permalink] [raw]
Subject: [PATCH v2] livepatch: Replace the fake signal sending with TIF_NOTIFY_SIGNAL infrastructure

Livepatch sends a fake signal to all remaining blocking tasks of a
running transition after a set period of time. It uses TIF_SIGPENDING
flag for the purpose. Commit 12db8b690010 ("entry: Add support for
TIF_NOTIFY_SIGNAL") added a generic infrastructure to achieve the same.
Replace our bespoke solution with the generic one.

Reviewed-by: Jens Axboe <[email protected]>
Reviewed-by: Petr Mladek <[email protected]>
Signed-off-by: Miroslav Benes <[email protected]>
---
v2:
- #include from kernel/signal.c removed [Petr]

kernel/livepatch/transition.c | 5 ++---
kernel/signal.c | 4 +---
2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
index f6310f848f34..3a4beb9395c4 100644
--- a/kernel/livepatch/transition.c
+++ b/kernel/livepatch/transition.c
@@ -9,6 +9,7 @@

#include <linux/cpu.h>
#include <linux/stacktrace.h>
+#include <linux/tracehook.h>
#include "core.h"
#include "patch.h"
#include "transition.h"
@@ -369,9 +370,7 @@ static void klp_send_signals(void)
* Send fake signal to all non-kthread tasks which are
* still not migrated.
*/
- spin_lock_irq(&task->sighand->siglock);
- signal_wake_up(task, 0);
- spin_unlock_irq(&task->sighand->siglock);
+ set_notify_signal(task);
}
}
read_unlock(&tasklist_lock);
diff --git a/kernel/signal.c b/kernel/signal.c
index f2a1b898da29..604290a8ca89 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -43,7 +43,6 @@
#include <linux/cn_proc.h>
#include <linux/compiler.h>
#include <linux/posix-timers.h>
-#include <linux/livepatch.h>
#include <linux/cgroup.h>
#include <linux/audit.h>

@@ -181,8 +180,7 @@ void recalc_sigpending_and_wake(struct task_struct *t)

void recalc_sigpending(void)
{
- if (!recalc_sigpending_tsk(current) && !freezing(current) &&
- !klp_patch_pending(current))
+ if (!recalc_sigpending_tsk(current) && !freezing(current))
clear_thread_flag(TIF_SIGPENDING);

}
--
2.30.2


2021-03-29 13:49:31

by Joe Lawrence

[permalink] [raw]
Subject: Re: [PATCH v2] livepatch: Replace the fake signal sending with TIF_NOTIFY_SIGNAL infrastructure

On 3/29/21 9:28 AM, Miroslav Benes wrote:
> Livepatch sends a fake signal to all remaining blocking tasks of a
> running transition after a set period of time. It uses TIF_SIGPENDING
> flag for the purpose. Commit 12db8b690010 ("entry: Add support for
> TIF_NOTIFY_SIGNAL") added a generic infrastructure to achieve the same.
> Replace our bespoke solution with the generic one.
>
> Reviewed-by: Jens Axboe <[email protected]>
> Reviewed-by: Petr Mladek <[email protected]>
> Signed-off-by: Miroslav Benes <[email protected]>
> ---
> v2:
> - #include from kernel/signal.c removed [Petr]
>
> kernel/livepatch/transition.c | 5 ++---
> kernel/signal.c | 4 +---
> 2 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
> index f6310f848f34..3a4beb9395c4 100644
> --- a/kernel/livepatch/transition.c
> +++ b/kernel/livepatch/transition.c
> @@ -9,6 +9,7 @@
>
> #include <linux/cpu.h>
> #include <linux/stacktrace.h>
> +#include <linux/tracehook.h>
> #include "core.h"
> #include "patch.h"
> #include "transition.h"
> @@ -369,9 +370,7 @@ static void klp_send_signals(void)
> * Send fake signal to all non-kthread tasks which are
> * still not migrated.
> */
> - spin_lock_irq(&task->sighand->siglock);
> - signal_wake_up(task, 0);
> - spin_unlock_irq(&task->sighand->siglock);
> + set_notify_signal(task);
> }
> }
> read_unlock(&tasklist_lock);
> diff --git a/kernel/signal.c b/kernel/signal.c
> index f2a1b898da29..604290a8ca89 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -43,7 +43,6 @@
> #include <linux/cn_proc.h>
> #include <linux/compiler.h>
> #include <linux/posix-timers.h>
> -#include <linux/livepatch.h>
> #include <linux/cgroup.h>
> #include <linux/audit.h>
>
> @@ -181,8 +180,7 @@ void recalc_sigpending_and_wake(struct task_struct *t)
>
> void recalc_sigpending(void)
> {
> - if (!recalc_sigpending_tsk(current) && !freezing(current) &&
> - !klp_patch_pending(current))
> + if (!recalc_sigpending_tsk(current) && !freezing(current))
> clear_thread_flag(TIF_SIGPENDING);
>
> }
>

Looks good to me. Thanks for checking on this and updating.

Acked-by: Joe Lawrence <[email protected]>

-- Joe

2021-03-30 07:46:23

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH v2] livepatch: Replace the fake signal sending with TIF_NOTIFY_SIGNAL infrastructure

On Mon, 29 Mar 2021, Miroslav Benes wrote:

> Livepatch sends a fake signal to all remaining blocking tasks of a
> running transition after a set period of time. It uses TIF_SIGPENDING
> flag for the purpose. Commit 12db8b690010 ("entry: Add support for
> TIF_NOTIFY_SIGNAL") added a generic infrastructure to achieve the same.
> Replace our bespoke solution with the generic one.
>
> Reviewed-by: Jens Axboe <[email protected]>
> Reviewed-by: Petr Mladek <[email protected]>
> Signed-off-by: Miroslav Benes <[email protected]>

Pushed out to livepatching#for-5.13/signal.

--
Jiri Kosina
SUSE Labs