linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Seth Jennings <sjenning@redhat.com>,
	Jiri Kosina <jkosina@suse.cz>, Vojtech Pavlik <vojtech@suse.cz>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 9/9] livepatch: update task universe when exiting kernel
Date: Mon,  9 Feb 2015 11:31:21 -0600	[thread overview]
Message-ID: <9c012546723ee556ea8c1118811d2d02b2d1c9ed.1423499826.git.jpoimboe@redhat.com> (raw)
In-Reply-To: <cover.1423499826.git.jpoimboe@redhat.com>

Update a tasks's universe when returning from a system call or user
space interrupt, or after handling a signal.

This greatly increases the chances of a patch operation succeeding.  If
a task is I/O bound, it can switch universes when returning from a
system call.  If a task is CPU bound, it can switch universes when
returning from an interrupt.  If a task is sleeping on a to-be-patched
function, the user can send SIGSTOP and SIGCONT to force it to switch.

Since the idle "swapper" tasks don't ever exit the kernel, they're
updated from within the idle loop.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 arch/x86/include/asm/thread_info.h |  4 +++-
 arch/x86/kernel/signal.c           |  4 ++++
 include/linux/livepatch.h          |  2 ++
 kernel/livepatch/transition.c      | 15 +++++++++++++++
 kernel/sched/idle.c                |  4 ++++
 5 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index 547e344..4e46d36 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -78,6 +78,7 @@ struct thread_info {
 #define TIF_MCE_NOTIFY		10	/* notify userspace of an MCE */
 #define TIF_USER_RETURN_NOTIFY	11	/* notify kernel of userspace return */
 #define TIF_UPROBE		12	/* breakpointed or singlestepping */
+#define TIF_KLP_NEED_UPDATE	13	/* pending live patching update */
 #define TIF_NOTSC		16	/* TSC is not accessible in userland */
 #define TIF_IA32		17	/* IA32 compatibility process */
 #define TIF_FORK		18	/* ret_from_fork */
@@ -102,6 +103,7 @@ struct thread_info {
 #define _TIF_SECCOMP		(1 << TIF_SECCOMP)
 #define _TIF_MCE_NOTIFY		(1 << TIF_MCE_NOTIFY)
 #define _TIF_USER_RETURN_NOTIFY	(1 << TIF_USER_RETURN_NOTIFY)
+#define _TIF_KLP_NEED_UPDATE	(1 << TIF_KLP_NEED_UPDATE)
 #define _TIF_UPROBE		(1 << TIF_UPROBE)
 #define _TIF_NOTSC		(1 << TIF_NOTSC)
 #define _TIF_IA32		(1 << TIF_IA32)
@@ -141,7 +143,7 @@ struct thread_info {
 /* Only used for 64 bit */
 #define _TIF_DO_NOTIFY_MASK						\
 	(_TIF_SIGPENDING | _TIF_MCE_NOTIFY | _TIF_NOTIFY_RESUME |	\
-	 _TIF_USER_RETURN_NOTIFY | _TIF_UPROBE)
+	 _TIF_USER_RETURN_NOTIFY | _TIF_UPROBE | _TIF_KLP_NEED_UPDATE)
 
 /* flags to check in __switch_to() */
 #define _TIF_WORK_CTXSW							\
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index ed37a76..1d4b8e6 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -23,6 +23,7 @@
 #include <linux/user-return-notifier.h>
 #include <linux/uprobes.h>
 #include <linux/context_tracking.h>
+#include <linux/livepatch.h>
 
 #include <asm/processor.h>
 #include <asm/ucontext.h>
@@ -760,6 +761,9 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
 	if (thread_info_flags & _TIF_USER_RETURN_NOTIFY)
 		fire_user_return_notifiers();
 
+	if (unlikely(thread_info_flags & _TIF_KLP_NEED_UPDATE))
+		klp_update_task_universe(current);
+
 	user_enter();
 }
 
diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
index b8c2f15..14f6a96 100644
--- a/include/linux/livepatch.h
+++ b/include/linux/livepatch.h
@@ -134,6 +134,8 @@ extern int klp_universe_goal;
 
 static inline void klp_update_task_universe(struct task_struct *t)
 {
+	clear_tsk_thread_flag(t, TIF_KLP_NEED_UPDATE);
+
 	/* corresponding smp_wmb() is in klp_set_universe_goal() */
 	smp_rmb();
 
diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
index 20fafd2..dac8ea5 100644
--- a/kernel/livepatch/transition.c
+++ b/kernel/livepatch/transition.c
@@ -234,6 +234,9 @@ static void klp_transition_work_fn(struct work_struct *work)
  */
 void klp_start_transition(int universe)
 {
+	struct task_struct *g, *t;
+	unsigned int cpu;
+
 	if (WARN_ON(klp_universe_goal == universe))
 		return;
 
@@ -241,6 +244,18 @@ void klp_start_transition(int universe)
 		  universe == KLP_UNIVERSE_NEW ? "patching" : "unpatching");
 
 	klp_set_universe_goal(universe);
+
+	/* mark all normal tasks as needing a universe update */
+	read_lock(&tasklist_lock);
+	for_each_process_thread(g, t)
+		set_tsk_thread_flag(t, TIF_KLP_NEED_UPDATE);
+	read_unlock(&tasklist_lock);
+
+	/* mark all idle "swapper" tasks as needing a universe update */
+	get_online_cpus();
+	for_each_online_cpu(cpu)
+		set_tsk_thread_flag(idle_task(cpu), TIF_KLP_NEED_UPDATE);
+	put_online_cpus();
 }
 
 /*
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index c47fce7..c1390b6 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -7,6 +7,7 @@
 #include <linux/tick.h>
 #include <linux/mm.h>
 #include <linux/stackprotector.h>
+#include <linux/livepatch.h>
 
 #include <asm/tlb.h>
 
@@ -250,6 +251,9 @@ static void cpu_idle_loop(void)
 
 		sched_ttwu_pending();
 		schedule_preempt_disabled();
+
+		if (unlikely(test_thread_flag(TIF_KLP_NEED_UPDATE)))
+			klp_update_task_universe(current);
 	}
 }
 
-- 
2.1.0


  parent reply	other threads:[~2015-02-09 17:31 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-09 17:31 [RFC PATCH 0/9] livepatch: consistency model Josh Poimboeuf
2015-02-09 17:31 ` [RFC PATCH 1/9] livepatch: simplify disable error path Josh Poimboeuf
2015-02-13 12:25   ` Miroslav Benes
2015-02-18 17:03     ` Petr Mladek
2015-02-18 20:07   ` Jiri Kosina
2015-02-09 17:31 ` [RFC PATCH 2/9] livepatch: separate enabled and patched states Josh Poimboeuf
2015-02-10 16:44   ` Jiri Slaby
2015-02-10 17:21     ` Josh Poimboeuf
2015-02-13 12:57   ` Miroslav Benes
2015-02-13 14:39     ` Josh Poimboeuf
2015-02-13 14:46       ` Miroslav Benes
2015-02-09 17:31 ` [RFC PATCH 3/9] livepatch: move patching functions into patch.c Josh Poimboeuf
2015-02-10 18:27   ` Jiri Slaby
2015-02-10 18:50     ` Josh Poimboeuf
2015-02-13 14:28   ` Miroslav Benes
2015-02-13 15:09     ` Josh Poimboeuf
2015-02-09 17:31 ` [RFC PATCH 4/9] livepatch: get function sizes Josh Poimboeuf
2015-02-10 18:30   ` Jiri Slaby
2015-02-10 18:53     ` Josh Poimboeuf
2015-02-09 17:31 ` [RFC PATCH 5/9] sched: move task rq locking functions to sched.h Josh Poimboeuf
2015-02-10 10:48   ` Masami Hiramatsu
2015-02-10 14:54     ` Josh Poimboeuf
2015-02-09 17:31 ` [RFC PATCH 6/9] livepatch: create per-task consistency model Josh Poimboeuf
2015-02-10 10:58   ` Masami Hiramatsu
2015-02-10 14:59     ` Josh Poimboeuf
2015-02-10 15:59   ` Miroslav Benes
2015-02-10 16:56     ` Josh Poimboeuf
2015-02-11 16:28       ` Miroslav Benes
2015-02-11 20:23         ` Josh Poimboeuf
2015-02-10 19:27   ` Seth Jennings
2015-02-10 19:32     ` Josh Poimboeuf
2015-02-11 10:21   ` Miroslav Benes
2015-02-11 20:19     ` Josh Poimboeuf
2015-02-12 10:45       ` Miroslav Benes
2015-02-12  3:21   ` Josh Poimboeuf
2015-02-12 11:56     ` Peter Zijlstra
2015-02-12 12:25       ` Jiri Kosina
2015-02-12 12:36         ` Peter Zijlstra
2015-02-12 12:39           ` Jiri Kosina
2015-02-12 12:39         ` Peter Zijlstra
2015-02-12 12:42           ` Jiri Kosina
2015-02-12 13:01             ` Josh Poimboeuf
2015-02-12 12:51       ` Josh Poimboeuf
2015-02-12 13:08         ` Peter Zijlstra
2015-02-12 13:16           ` Jiri Kosina
2015-02-12 14:20             ` Josh Poimboeuf
2015-02-12 14:27               ` Jiri Kosina
2015-02-12 13:16           ` Jiri Slaby
2015-02-12 13:35             ` Peter Zijlstra
2015-02-12 14:08               ` Jiri Kosina
2015-02-12 15:24                 ` Josh Poimboeuf
2015-02-12 14:20               ` Jiri Slaby
2015-02-12 14:32           ` Jiri Kosina
2015-02-18 20:17             ` Ingo Molnar
2015-02-18 20:44               ` Vojtech Pavlik
2015-02-19  9:52                 ` Peter Zijlstra
2015-02-19 10:11                   ` Vojtech Pavlik
2015-02-19 10:51                     ` Peter Zijlstra
2015-02-12 13:26     ` Jiri Slaby
2015-02-12 15:48       ` Josh Poimboeuf
2015-02-14 11:40   ` Jiri Slaby
2015-02-17 14:59     ` Josh Poimboeuf
2015-02-16 14:19   ` Miroslav Benes
2015-02-17 15:10     ` Josh Poimboeuf
2015-02-17 15:48       ` Miroslav Benes
2015-02-17 16:01         ` Josh Poimboeuf
2015-02-18 12:42           ` Miroslav Benes
2015-02-18 13:15             ` Josh Poimboeuf
2015-02-18 13:42               ` Miroslav Benes
2015-02-09 17:31 ` [RFC PATCH 7/9] proc: add /proc/<pid>/universe to show livepatch status Josh Poimboeuf
2015-02-10 18:47   ` Jiri Slaby
2015-02-10 18:57     ` Josh Poimboeuf
2015-02-09 17:31 ` [RFC PATCH 8/9] livepatch: allow patch modules to be removed Josh Poimboeuf
2015-02-10 19:02   ` Jiri Slaby
2015-02-10 19:57     ` Josh Poimboeuf
2015-02-11 10:55       ` Jiri Slaby
2015-02-11 18:39         ` Josh Poimboeuf
2015-02-12 15:22     ` Miroslav Benes
2015-02-13 12:44       ` Josh Poimboeuf
2015-02-13 16:04       ` Josh Poimboeuf
2015-02-13 16:17         ` Miroslav Benes
2015-02-13 20:49           ` Josh Poimboeuf
2015-02-16 16:06             ` Miroslav Benes
2015-02-17 15:55               ` Josh Poimboeuf
2015-02-17 16:38                 ` Miroslav Benes
2015-02-09 17:31 ` Josh Poimboeuf [this message]
2015-02-16 10:16   ` [RFC PATCH 9/9] livepatch: update task universe when exiting kernel Jiri Slaby
2015-02-17 14:58     ` Josh Poimboeuf
2015-02-09 23:15 ` [RFC PATCH 0/9] livepatch: consistency model Jiri Kosina
2015-02-10  3:05   ` Josh Poimboeuf
2015-02-10  7:21     ` Jiri Kosina
2015-02-10  8:57 ` Jiri Kosina
2015-02-10 14:43   ` Josh Poimboeuf
2015-02-10 11:16 ` Masami Hiramatsu
2015-02-10 15:59   ` Josh Poimboeuf
2015-02-10 17:29     ` Josh Poimboeuf
2015-02-13 10:14 ` Jiri Kosina
2015-02-13 14:19   ` Josh Poimboeuf
2015-02-13 14:22     ` Jiri Kosina
2015-02-13 14:40       ` Miroslav Benes
2015-02-13 14:55         ` Josh Poimboeuf
2015-02-13 14:41       ` Josh Poimboeuf
2015-02-24 11:27         ` Masami Hiramatsu
2015-03-10 16:23 ` Josh Poimboeuf
2015-03-10 21:02   ` Jiri Kosina
2015-03-10 21:30     ` Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9c012546723ee556ea8c1118811d2d02b2d1c9ed.1423499826.git.jpoimboe@redhat.com \
    --to=jpoimboe@redhat.com \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=sjenning@redhat.com \
    --cc=vojtech@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).