Skip to content

Commit fd1e0fd

Browse files
liu-song-6ctmarinas
authored andcommitted
arm64: Implement HAVE_LIVEPATCH
Allocate a task flag used to represent the patch pending state for the task. When a livepatch is being loaded or unloaded, the livepatch code uses this flag to select the proper version of a being patched kernel functions to use for current task. In arch/arm64/Kconfig, select HAVE_LIVEPATCH and include proper Kconfig. This is largely based on [1] by Suraj Jitindar Singh. [1] https://lore.kernel.org/all/[email protected]/ Cc: Suraj Jitindar Singh <[email protected]> Cc: Torsten Duwe <[email protected]> Acked-by: Miroslav Benes <[email protected]> Tested-by: Breno Leitao <[email protected]> Tested-by: Andrea della Porta <[email protected]> Signed-off-by: Song Liu <[email protected]> Acked-by: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 805f13e commit fd1e0fd

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

arch/arm64/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ config ARM64
280280
select USER_STACKTRACE_SUPPORT
281281
select VDSO_GETRANDOM
282282
select HAVE_RELIABLE_STACKTRACE
283+
select HAVE_LIVEPATCH
283284
help
284285
ARM 64-bit (AArch64) Linux support.
285286

@@ -2499,3 +2500,5 @@ endmenu # "CPU Power Management"
24992500
source "drivers/acpi/Kconfig"
25002501

25012502
source "arch/arm64/kvm/Kconfig"
2503+
2504+
source "kernel/livepatch/Kconfig"

arch/arm64/include/asm/thread_info.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void arch_setup_new_exec(void);
7070
#define TIF_SYSCALL_TRACEPOINT 10 /* syscall tracepoint for ftrace */
7171
#define TIF_SECCOMP 11 /* syscall secure computing */
7272
#define TIF_SYSCALL_EMU 12 /* syscall emulation active */
73+
#define TIF_PATCH_PENDING 13 /* pending live patching update */
7374
#define TIF_MEMDIE 18 /* is terminating due to OOM killer */
7475
#define TIF_FREEZE 19
7576
#define TIF_RESTORE_SIGMASK 20
@@ -96,6 +97,7 @@ void arch_setup_new_exec(void);
9697
#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
9798
#define _TIF_SECCOMP (1 << TIF_SECCOMP)
9899
#define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU)
100+
#define _TIF_PATCH_PENDING (1 << TIF_PATCH_PENDING)
99101
#define _TIF_UPROBE (1 << TIF_UPROBE)
100102
#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP)
101103
#define _TIF_32BIT (1 << TIF_32BIT)
@@ -107,7 +109,8 @@ void arch_setup_new_exec(void);
107109
#define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY | \
108110
_TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \
109111
_TIF_UPROBE | _TIF_MTE_ASYNC_FAULT | \
110-
_TIF_NOTIFY_SIGNAL | _TIF_SIGPENDING)
112+
_TIF_NOTIFY_SIGNAL | _TIF_SIGPENDING | \
113+
_TIF_PATCH_PENDING)
111114

112115
#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
113116
_TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \

arch/arm64/kernel/entry-common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/context_tracking.h>
99
#include <linux/kasan.h>
1010
#include <linux/linkage.h>
11+
#include <linux/livepatch.h>
1112
#include <linux/lockdep.h>
1213
#include <linux/ptrace.h>
1314
#include <linux/resume_user_mode.h>
@@ -144,6 +145,9 @@ static void do_notify_resume(struct pt_regs *regs, unsigned long thread_flags)
144145
(void __user *)NULL, current);
145146
}
146147

148+
if (thread_flags & _TIF_PATCH_PENDING)
149+
klp_update_patch_state(current);
150+
147151
if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
148152
do_signal(regs);
149153

0 commit comments

Comments
 (0)