xref: /OK3568_Linux_fs/kernel/arch/powerpc/include/asm/livepatch.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * livepatch.h - powerpc-specific Kernel Live Patching Core
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2015-2016, SUSE, IBM Corp.
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun #ifndef _ASM_POWERPC_LIVEPATCH_H
8*4882a593Smuzhiyun #define _ASM_POWERPC_LIVEPATCH_H
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <linux/module.h>
11*4882a593Smuzhiyun #include <linux/ftrace.h>
12*4882a593Smuzhiyun #include <linux/sched/task_stack.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #ifdef CONFIG_LIVEPATCH
klp_arch_set_pc(struct pt_regs * regs,unsigned long ip)15*4882a593Smuzhiyun static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip)
16*4882a593Smuzhiyun {
17*4882a593Smuzhiyun 	regs->nip = ip;
18*4882a593Smuzhiyun }
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #define klp_get_ftrace_location klp_get_ftrace_location
klp_get_ftrace_location(unsigned long faddr)21*4882a593Smuzhiyun static inline unsigned long klp_get_ftrace_location(unsigned long faddr)
22*4882a593Smuzhiyun {
23*4882a593Smuzhiyun 	/*
24*4882a593Smuzhiyun 	 * Live patch works only with -mprofile-kernel on PPC. In this case,
25*4882a593Smuzhiyun 	 * the ftrace location is always within the first 16 bytes.
26*4882a593Smuzhiyun 	 */
27*4882a593Smuzhiyun 	return ftrace_location_range(faddr, faddr + 16);
28*4882a593Smuzhiyun }
29*4882a593Smuzhiyun 
klp_init_thread_info(struct task_struct * p)30*4882a593Smuzhiyun static inline void klp_init_thread_info(struct task_struct *p)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun 	/* + 1 to account for STACK_END_MAGIC */
33*4882a593Smuzhiyun 	task_thread_info(p)->livepatch_sp = end_of_stack(p) + 1;
34*4882a593Smuzhiyun }
35*4882a593Smuzhiyun #else
klp_init_thread_info(struct task_struct * p)36*4882a593Smuzhiyun static inline void klp_init_thread_info(struct task_struct *p) { }
37*4882a593Smuzhiyun #endif /* CONFIG_LIVEPATCH */
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun #endif /* _ASM_POWERPC_LIVEPATCH_H */
40