Skip to contentSkip to conversation

arm64: livepatch: Enable livepatch without sframe

PATCH Superseded Song Liu 2 participants 5 messages Mar 19, 2025 – Mar 20, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Song Liu

author maintainer
#0 lore raw

v2 cover arm64: livepatch: Enable livepatch without sframe

There are recent efforts to enable livepatch for arm64, with sframe [1] or without sframe [2]. This set tries to enable livepatch without sframe. Some of the code, however, are from [1].

Although the sframe implementation is more promising in longer term, it suffers from the following issues:

1. sframe is not yet supported in llvm;
2. There is still bug in binutil [3], so that we cannot yet use sframe

     with gcc;

3. sframe unwinder hasn't been fully verified in the kernel.

On the other hand, arm64 processors have become more and more important in the data center world. Therefore, it is getting critical to support livepatching of arm64 kernels.

With recent change in arm64 unwinder [4], it is possible to reliably livepatch arm64 kernels without sframe. This is because we do not need arch_stack_walk_reliable() to get reliable stack trace in all scenarios. Instead, we only need arch_stack_walk_reliable() to detect when the stack trace is not reliable, then the livepatch logic can retry the patch transition at a later time.

Given the increasing need of livepatching, and relatively long time before sframe is fully ready (for both gcc and clang), we would like to enable livepatch without sframe.

Thanks!

[1] https://lore.kernel.org/live-patching/[email protected]/
[2] https://lore.kernel.org/live-patching/[email protected]/
[3] https://sourceware.org/bugzilla/show_bug.cgi?id=32589
[4] https://lore.kernel.org/linux-arm-kernel/[email protected]/

Changes v1 => v2:

1. Rework arch_stack_walk_reliable().

v1: https://lore.kernel.org/live-patching/[email protected]/

Song Liu (2):
arm64: Implement arch_stack_walk_reliable
arm64: Implement HAVE_LIVEPATCH

 arch/arm64/Kconfig                   |  3 ++
 arch/arm64/include/asm/thread_info.h |  4 +-
 arch/arm64/kernel/entry-common.c     |  4 ++
 arch/arm64/kernel/stacktrace.c       | 70 +++++++++++++++++++++-------
 4 files changed, 64 insertions(+), 17 deletions(-)

--
2.47.1

author maintainer
#1 lore raw

PATCH v2 1/2 arm64: Implement arch_stack_walk_reliable

With proper exception boundary detection, it is possible to implment arch_stack_walk_reliable without sframe.

Note that, arch_stack_walk_reliable does not guarantee getting reliable stack in all scenarios. Instead, it can reliably detect when the stack trace is not reliable, which is enough to provide reliable livepatching.

---
 arch/arm64/Kconfig             |  2 +-
 arch/arm64/kernel/stacktrace.c | 70 ++++++++++++++++++++++++++--------
 2 files changed, 55 insertions(+), 17 deletions(-)
arch/arm64/Kconfig +1 -1
index 940343beb3d4..ed4f7bf4a879 100644
@@ -275,6 +275,7 @@ config ARM64
 	select HAVE_SOFTIRQ_ON_OWN_STACK
 	select USER_STACKTRACE_SUPPORT
 	select VDSO_GETRANDOM
+	select HAVE_RELIABLE_STACKTRACE
 	help
 	  ARM 64-bit (AArch64) Linux support.
 
@@ -2499,4 +2500,3 @@ endmenu # "CPU Power Management"
 source "drivers/acpi/Kconfig"
 
 source "arch/arm64/kvm/Kconfig"
-
arch/arm64/kernel/stacktrace.c +54 -16

138 lines not on this page · raw message

Signature · 1 line
2.47.1
maintainer
#2 lore raw

Re: [PATCH v2 1/2] arm64: Implement arch_stack_walk_reliable

arch/arm64/kernel/stacktrace.c noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry, · line 424

Quoted 12 lines · Song Liu
arch/arm64/kernel/stacktrace.c +12 -0
+noinline noinstr int arch_stack_walk_reliable(stack_trace_consume_fn consume_entry,
+			void *cookie, struct task_struct *task)
+{
+	struct kunwind_consume_entry_data data = {
+		.consume_entry = consume_entry,
+		.cookie = cookie,
+	};
+	int ret;
+
+	ret = kunwind_stack_walk(arch_kunwind_consume_entry, &data, task, NULL, true);
+	if (ret == -ENOENT)
+		ret = 0;

Is this check redundant with the -ENOENT check in do_kunwind() which already converts ret to zero?

Signature · 1 line
Josh
author maintainer
#3 lore raw

Re: [PATCH v2 1/2] arm64: Implement arch_stack_walk_reliable

Quoted 17 lines · Josh Poimboeuf

arch/arm64/kernel/stacktrace.c noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry, · line 424

Quoted 12 lines · Song Liu
arch/arm64/kernel/stacktrace.c +12 -0
+noinline noinstr int arch_stack_walk_reliable(stack_trace_consume_fn consume_entry,
+                     void *cookie, struct task_struct *task)
+{
+     struct kunwind_consume_entry_data data = {
+             .consume_entry = consume_entry,
+             .cookie = cookie,
+     };
+     int ret;
+
+     ret = kunwind_stack_walk(arch_kunwind_consume_entry, &data, task, NULL, true);
+     if (ret == -ENOENT)
+             ret = 0;

Is this check redundant with the -ENOENT check in do_kunwind() which already converts ret to zero?

Indeed. This check is redundant.

Thanks,
Song

author maintainer
#4 lore raw

PATCH v2 2/2 arm64: Implement HAVE_LIVEPATCH

In reply to Song Liu

This is largely based on [1] by Suraj Jitindar Singh.

Test coverage:

- Passed manual tests with samples/livepatch.
- Passed all but test-kprobe.sh in selftests/livepatch. test-kprobe.sh is expected to fail, because arm64 doesn't have KPROBES_ON_FTRACE.
- Passed tests with kpatch-build [2]. (This version includes commits that are not merged to upstream kpatch yet).

[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/liu-song-6/kpatch/tree/fb-6.13

Cc Suraj Jitindar Singh <[email protected]>
Cc Torsten Duwe <[email protected]>
---
 arch/arm64/Kconfig                   | 3 +++
 arch/arm64/include/asm/thread_info.h | 4 +++-
 arch/arm64/kernel/entry-common.c     | 4 ++++
 3 files changed, 10 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +3 -0
index ed4f7bf4a879..bc9edba6171a 100644
@@ -276,6 +276,7 @@ config ARM64
 	select USER_STACKTRACE_SUPPORT
 	select VDSO_GETRANDOM
 	select HAVE_RELIABLE_STACKTRACE
+	select HAVE_LIVEPATCH
 	help
 	  ARM 64-bit (AArch64) Linux support.
 
@@ -2500,3 +2501,5 @@ endmenu # "CPU Power Management"
 source "drivers/acpi/Kconfig"
 
 source "arch/arm64/kvm/Kconfig"
+
+source "kernel/livepatch/Kconfig"
arch/arm64/include/asm/thread_info.h +3 -1
index 1114c1c3300a..4ac42e13032b 100644
@@ -64,6 +64,7 @@ void arch_setup_new_exec(void);
 #define TIF_UPROBE		4	/* uprobe breakpoint or singlestep */
 #define TIF_MTE_ASYNC_FAULT	5	/* MTE Asynchronous Tag Check Fault */
 #define TIF_NOTIFY_SIGNAL	6	/* signal notifications exist */
+#define TIF_PATCH_PENDING	7	/* pending live patching update */
 #define TIF_SYSCALL_TRACE	8	/* syscall trace active */
 #define TIF_SYSCALL_AUDIT	9	/* syscall auditing */
 #define TIF_SYSCALL_TRACEPOINT	10	/* syscall tracepoint for ftrace */
@@ -92,6 +93,7 @@ void arch_setup_new_exec(void);
 #define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
 #define _TIF_SECCOMP		(1 << TIF_SECCOMP)
 #define _TIF_SYSCALL_EMU	(1 << TIF_SYSCALL_EMU)
+#define _TIF_PATCH_PENDING	(1 << TIF_PATCH_PENDING)
 #define _TIF_UPROBE		(1 << TIF_UPROBE)
 #define _TIF_SINGLESTEP		(1 << TIF_SINGLESTEP)
 #define _TIF_32BIT		(1 << TIF_32BIT)
@@ -103,7 +105,7 @@ void arch_setup_new_exec(void);
 #define _TIF_WORK_MASK		(_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
 				 _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \
 				 _TIF_UPROBE | _TIF_MTE_ASYNC_FAULT | \
-				 _TIF_NOTIFY_SIGNAL)
+				 _TIF_NOTIFY_SIGNAL | _TIF_PATCH_PENDING)
 
 #define _TIF_SYSCALL_WORK	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
 				 _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
arch/arm64/kernel/entry-common.c +4 -0
index b260ddc4d3e9..b537af333b42 100644
@@ -8,6 +8,7 @@
 #include <linux/context_tracking.h>
 #include <linux/kasan.h>
 #include <linux/linkage.h>
+#include <linux/livepatch.h>
 #include <linux/lockdep.h>
 #include <linux/ptrace.h>
 #include <linux/resume_user_mode.h>
@@ -144,6 +145,9 @@ static void do_notify_resume(struct pt_regs *regs, unsigned long thread_flags)
 				       (void __user *)NULL, current);
 		}
 
+		if (thread_flags & _TIF_PATCH_PENDING)
+			klp_update_patch_state(current);
+
 		if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
 			do_signal(regs);
 
Signature · 1 line
2.47.1