From: Yafang Shao <laoar.shao@gmail.com>
To: jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz,
pmladek@suse.com, joe.lawrence@redhat.com, rostedt@goodmis.org,
mhiramat@kernel.org, mathieu.desnoyers@efficios.com,
kpsingh@kernel.org, mattbobrowski@google.com, song@kernel.org,
jolsa@kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com,
memxor@gmail.com, yonghong.song@linux.dev
Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org,
Yafang Shao <laoar.shao@gmail.com>
Subject: [RFC PATCH 4/4] livepatch: Implement livepatch hybrid mode
Date: Thu, 2 Apr 2026 17:26:07 +0800 [thread overview]
Message-ID: <20260402092607.96430-5-laoar.shao@gmail.com> (raw)
In-Reply-To: <20260402092607.96430-1-laoar.shao@gmail.com>
Livepatching allows for rapid experimentation with new kernel features
without interrupting production workloads. However, static livepatches lack
the flexibility required to tune features based on task-specific attributes,
such as cgroup membership, which is critical in multi-tenant k8s
environments. Furthermore, hardcoding logic into a livepatch prevents
dynamic adjustments based on the runtime environment.
To address this, we propose a hybrid approach using BPF. Our production use
case involves:
1. Deploying a Livepatch function to serve as a stable BPF hook.
2. Utilizing bpf_override_return() to dynamically modify the return value
of that hook based on the current task's context.
A significant challenge arises when atomic-replace is enabled. In this
mode, deploying a new livepatch changes the target function's address,
forcing a re-attachment of the BPF program. This re-attachment latency is
unacceptable in critical paths, such as those handling networking policies.
To solve this, we introduce a hybrid livepatch mode that allows specific
patches to remain non-replaceable, ensuring the function address remains
stable and the BPF program stays attached.
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
kernel/livepatch/core.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 04f9e84f114f..5a44154131c8 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -665,6 +665,8 @@ static int klp_add_nops(struct klp_patch *patch)
klp_for_each_object(old_patch, old_obj) {
int err;
+ if (!old_patch->replaceable)
+ continue;
err = klp_add_object_nops(patch, old_obj);
if (err)
return err;
@@ -837,6 +839,8 @@ void klp_free_replaced_patches_async(struct klp_patch *new_patch)
klp_for_each_patch_safe(old_patch, tmp_patch) {
if (old_patch == new_patch)
return;
+ if (!old_patch->replaceable)
+ continue;
klp_free_patch_async(old_patch);
}
}
@@ -1239,6 +1243,8 @@ void klp_unpatch_replaced_patches(struct klp_patch *new_patch)
if (old_patch == new_patch)
return;
+ if (!old_patch->replaceable)
+ continue;
old_patch->enabled = false;
klp_unpatch_objects(old_patch);
}
--
2.47.3
next prev parent reply other threads:[~2026-04-02 9:26 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 9:26 [RFC PATCH 0/4] trace, livepatch: Allow kprobe return overriding for livepatched functions Yafang Shao
2026-04-02 9:26 ` [RFC PATCH 1/4] trace: Simplify kprobe overridable function check Yafang Shao
2026-04-02 13:13 ` Masami Hiramatsu
2026-04-02 9:26 ` [RFC PATCH 2/4] trace: Allow kprobes to override livepatched functions Yafang Shao
2026-04-02 12:48 ` Menglong Dong
2026-04-02 13:20 ` Yafang Shao
2026-04-03 10:25 ` Menglong Dong
2026-04-03 11:30 ` Steven Rostedt
2026-04-03 13:30 ` Yafang Shao
2026-04-03 14:26 ` Alexei Starovoitov
2026-04-03 16:00 ` Yafang Shao
2026-04-03 13:26 ` Yafang Shao
2026-04-02 9:26 ` [RFC PATCH 3/4] livepatch: Add "replaceable" attribute to klp_patch Yafang Shao
2026-04-03 16:19 ` Song Liu
2026-04-03 20:55 ` Dylan Hatch
2026-04-03 21:35 ` Song Liu
2026-04-06 11:08 ` Yafang Shao
2026-04-06 18:11 ` Song Liu
2026-04-06 21:12 ` Joe Lawrence
2026-04-07 2:54 ` Song Liu
2026-04-07 3:16 ` Yafang Shao
2026-04-02 9:26 ` Yafang Shao [this message]
2026-04-03 16:06 ` [RFC PATCH 0/4] trace, livepatch: Allow kprobe return overriding for livepatched functions Song Liu
2026-04-06 10:55 ` Yafang Shao
2026-04-06 18:26 ` Song Liu
2026-04-07 2:21 ` Yafang Shao
2026-04-07 2:46 ` Song Liu
2026-04-07 3:13 ` Yafang Shao
2026-04-06 5:36 ` Christoph Hellwig
2026-04-06 10:57 ` Yafang Shao
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=20260402092607.96430-5-laoar.shao@gmail.com \
--to=laoar.shao@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jolsa@kernel.org \
--cc=jpoimboe@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=mattbobrowski@google.com \
--cc=mbenes@suse.cz \
--cc=memxor@gmail.com \
--cc=mhiramat@kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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