xref: /linux/arch/powerpc/include/asm/livepatch.h (revision ed1cd6deb013a11959d17a94e35ce159197632da)
1f63e6d89SMichael Ellerman /*
2f63e6d89SMichael Ellerman  * livepatch.h - powerpc-specific Kernel Live Patching Core
3f63e6d89SMichael Ellerman  *
4f63e6d89SMichael Ellerman  * Copyright (C) 2015-2016, SUSE, IBM Corp.
5f63e6d89SMichael Ellerman  *
6f63e6d89SMichael Ellerman  * This program is free software; you can redistribute it and/or
7f63e6d89SMichael Ellerman  * modify it under the terms of the GNU General Public License
8f63e6d89SMichael Ellerman  * as published by the Free Software Foundation; either version 2
9f63e6d89SMichael Ellerman  * of the License, or (at your option) any later version.
10f63e6d89SMichael Ellerman  *
11f63e6d89SMichael Ellerman  * This program is distributed in the hope that it will be useful,
12f63e6d89SMichael Ellerman  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13f63e6d89SMichael Ellerman  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14f63e6d89SMichael Ellerman  * GNU General Public License for more details.
15f63e6d89SMichael Ellerman  *
16f63e6d89SMichael Ellerman  * You should have received a copy of the GNU General Public License
17f63e6d89SMichael Ellerman  * along with this program; if not, see <http://www.gnu.org/licenses/>.
18f63e6d89SMichael Ellerman  */
19f63e6d89SMichael Ellerman #ifndef _ASM_POWERPC_LIVEPATCH_H
20f63e6d89SMichael Ellerman #define _ASM_POWERPC_LIVEPATCH_H
21f63e6d89SMichael Ellerman 
22f63e6d89SMichael Ellerman #include <linux/module.h>
23f63e6d89SMichael Ellerman #include <linux/ftrace.h>
24*ed1cd6deSChristophe Leroy #include <linux/sched/task_stack.h>
25f63e6d89SMichael Ellerman 
26f63e6d89SMichael Ellerman #ifdef CONFIG_LIVEPATCH
27f63e6d89SMichael Ellerman static inline int klp_check_compiler_support(void)
28f63e6d89SMichael Ellerman {
29f63e6d89SMichael Ellerman 	return 0;
30f63e6d89SMichael Ellerman }
31f63e6d89SMichael Ellerman 
32f63e6d89SMichael Ellerman static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip)
33f63e6d89SMichael Ellerman {
34f63e6d89SMichael Ellerman 	regs->nip = ip;
35f63e6d89SMichael Ellerman }
36f63e6d89SMichael Ellerman 
37f63e6d89SMichael Ellerman #define klp_get_ftrace_location klp_get_ftrace_location
38f63e6d89SMichael Ellerman static inline unsigned long klp_get_ftrace_location(unsigned long faddr)
39f63e6d89SMichael Ellerman {
40f63e6d89SMichael Ellerman 	/*
41f63e6d89SMichael Ellerman 	 * Live patch works only with -mprofile-kernel on PPC. In this case,
42f63e6d89SMichael Ellerman 	 * the ftrace location is always within the first 16 bytes.
43f63e6d89SMichael Ellerman 	 */
44f63e6d89SMichael Ellerman 	return ftrace_location_range(faddr, faddr + 16);
45f63e6d89SMichael Ellerman }
465d31a96eSMichael Ellerman 
47*ed1cd6deSChristophe Leroy static inline void klp_init_thread_info(struct task_struct *p)
485d31a96eSMichael Ellerman {
495d31a96eSMichael Ellerman 	/* + 1 to account for STACK_END_MAGIC */
50*ed1cd6deSChristophe Leroy 	task_thread_info(p)->livepatch_sp = end_of_stack(p) + 1;
515d31a96eSMichael Ellerman }
525d31a96eSMichael Ellerman #else
53*ed1cd6deSChristophe Leroy static inline void klp_init_thread_info(struct task_struct *p) { }
54f63e6d89SMichael Ellerman #endif /* CONFIG_LIVEPATCH */
55f63e6d89SMichael Ellerman 
56f63e6d89SMichael Ellerman #endif /* _ASM_POWERPC_LIVEPATCH_H */
57