[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230120-vhost-klp-switching-v1-1-7c2b65519c43@kernel.org>
Date: Fri, 20 Jan 2023 16:12:21 -0600
From: "Seth Forshee (DigitalOcean)" <sforshee@...italocean.com>
To: Petr Mladek <pmladek@...e.com>, Jason Wang <jasowang@...hat.com>,
"Michael S. Tsirkin" <mst@...hat.com>,
Jiri Kosina <jikos@...nel.org>,
Miroslav Benes <mbenes@...e.cz>,
Joe Lawrence <joe.lawrence@...hat.com>,
Josh Poimboeuf <jpoimboe@...nel.org>
Cc: virtualization@...ts.linux-foundation.org, kvm@...r.kernel.org,
"Seth Forshee (DigitalOcean)" <sforshee@...nel.org>,
netdev@...r.kernel.org, live-patching@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH 1/2] livepatch: add an interface for safely switching kthreads
The only existing solution for transitioning a busy kernel thread is to
call klp_update_patch_state() from a safe location. However, this does
not account for the fact that even the main function of the kthread
could potentially be patched, leaving the patch switched but still
running the old version of a patched function.
To address this, add klp_switch_current() for use by kthreads to safely
transition themselves. This is just a wrapper around
klp_try_switch_task(), which can already transition the current task
with stack checking.
Signed-off-by: Seth Forshee (DigitalOcean) <sforshee@...nel.org>
---
include/linux/livepatch.h | 2 ++
kernel/livepatch/transition.c | 11 +++++++++++
2 files changed, 13 insertions(+)
diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
index 293e29960c6e..00b5981684a4 100644
--- a/include/linux/livepatch.h
+++ b/include/linux/livepatch.h
@@ -199,6 +199,7 @@ void klp_module_going(struct module *mod);
void klp_copy_process(struct task_struct *child);
void klp_update_patch_state(struct task_struct *task);
+void klp_switch_current(void);
static inline bool klp_patch_pending(struct task_struct *task)
{
@@ -240,6 +241,7 @@ static inline int klp_module_coming(struct module *mod) { return 0; }
static inline void klp_module_going(struct module *mod) {}
static inline bool klp_patch_pending(struct task_struct *task) { return false; }
static inline void klp_update_patch_state(struct task_struct *task) {}
+static inline void klp_switch_current(void) {}
static inline void klp_copy_process(struct task_struct *child) {}
static inline
diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
index f1b25ec581e0..ff328b912916 100644
--- a/kernel/livepatch/transition.c
+++ b/kernel/livepatch/transition.c
@@ -455,6 +455,17 @@ void klp_try_complete_transition(void)
klp_free_replaced_patches_async(patch);
}
+/*
+ * Safely try to switch the current task to the target patch state. This can
+ * be used by kthreads to transition if no to-be-patched or to-be-unpatched
+ * functions are on the call stack.
+ */
+void klp_switch_current(void)
+{
+ klp_try_switch_task(current);
+}
+EXPORT_SYMBOL_GPL(klp_switch_current);
+
/*
* Start the transition to the specified target patch state so tasks can begin
* switching to it.
--
b4 0.10.1
Powered by blists - more mailing lists