Skip to content

RFC trace, livepatch: Allow kprobe return overriding for livepatched functions

Yafang Shao bpf linux-trace-kernel live-patching lkml 1 version NAK

Status from this message: NACK.

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest4 patches 44 repliesNAK

Patches in v1

#Subject and filesSizeRepliesApplied
1/4trace: Simplify kprobe overridable function checkkernel/trace/bpf_trace.c kernel/trace/trace_kprobe.c kernel/trace/trace_probe.h+54 -531 reply
2/4trace: Allow kprobes to override livepatched functionskernel/trace/Kconfig kernel/trace/bpf_trace.c kernel/trace/trace_kprobe.c +1 more+38 -110 replies
3/4livepatch: Add "replaceable" attribute to klp_patchinclude/linux/livepatch.h kernel/livepatch/core.c+46 -019 replies
4/4livepatch: Implement livepatch hybrid modekernel/livepatch/core.c+6 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/4] trace, livepatch: Allow kprobe return overriding for livepatched functions

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.

Furthermore, this mechanism provides a lower-maintenance alternative to out-of-tree BPF hooks. Given the complexities of upstreaming custom BPF hooks (e.g., [0], [1]), this hybrid mode allows for the maintenance of stable, minimal hook points via livepatching with significantly reduced maintenance burden.

Yafang Shao (4):
trace: Simplify kprobe overridable function check
trace: Allow kprobes to override livepatched functions
livepatch: Add "replaceable" attribute to klp_patch
livepatch: Implement livepatch hybrid mode

 include/linux/livepatch.h   |  2 ++
 kernel/livepatch/core.c     | 50 +++++++++++++++++++++++++++++++
 kernel/trace/Kconfig        | 14 +++++++++
 kernel/trace/bpf_trace.c    | 14 ++++++---
 kernel/trace/trace_kprobe.c | 49 ++++++++++++------------------
 kernel/trace/trace_probe.h  | 59 +++++++++++++++++++++++++++----------
 6 files changed, 139 insertions(+), 49 deletions(-)
Signature · 1 line
2.47.3