11ccea77eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 2f63e6d89SMichael Ellerman /* 3f63e6d89SMichael Ellerman * livepatch.h - powerpc-specific Kernel Live Patching Core 4f63e6d89SMichael Ellerman * 5f63e6d89SMichael Ellerman * Copyright (C) 2015-2016, SUSE, IBM Corp. 6f63e6d89SMichael Ellerman */ 7f63e6d89SMichael Ellerman #ifndef _ASM_POWERPC_LIVEPATCH_H 8f63e6d89SMichael Ellerman #define _ASM_POWERPC_LIVEPATCH_H 9f63e6d89SMichael Ellerman 10f63e6d89SMichael Ellerman #include <linux/module.h> 11f63e6d89SMichael Ellerman #include <linux/ftrace.h> 12ed1cd6deSChristophe Leroy #include <linux/sched/task_stack.h> 13f63e6d89SMichael Ellerman 14f63e6d89SMichael Ellerman #ifdef CONFIG_LIVEPATCH 152860cd8aSSteven Rostedt (VMware) static inline void klp_arch_set_pc(struct ftrace_regs *fregs, unsigned long ip) 16f63e6d89SMichael Ellerman { 172860cd8aSSteven Rostedt (VMware) struct pt_regs *regs = ftrace_get_regs(fregs); 182860cd8aSSteven Rostedt (VMware) 1959dc5bfcSNicholas Piggin regs_set_return_ip(regs, ip); 20f63e6d89SMichael Ellerman } 21f63e6d89SMichael Ellerman 22f63e6d89SMichael Ellerman #define klp_get_ftrace_location klp_get_ftrace_location 23f63e6d89SMichael Ellerman static inline unsigned long klp_get_ftrace_location(unsigned long faddr) 24f63e6d89SMichael Ellerman { 25f63e6d89SMichael Ellerman /* 26*a4520b25SChristophe Leroy * Live patch works on PPC32 and only with -mprofile-kernel on PPC64. In 27*a4520b25SChristophe Leroy * both cases, the ftrace location is always within the first 16 bytes. 28f63e6d89SMichael Ellerman */ 29f63e6d89SMichael Ellerman return ftrace_location_range(faddr, faddr + 16); 30f63e6d89SMichael Ellerman } 31*a4520b25SChristophe Leroy #endif /* CONFIG_LIVEPATCH */ 325d31a96eSMichael Ellerman 33*a4520b25SChristophe Leroy #ifdef CONFIG_LIVEPATCH_64 34ed1cd6deSChristophe Leroy static inline void klp_init_thread_info(struct task_struct *p) 355d31a96eSMichael Ellerman { 365d31a96eSMichael Ellerman /* + 1 to account for STACK_END_MAGIC */ 37ed1cd6deSChristophe Leroy task_thread_info(p)->livepatch_sp = end_of_stack(p) + 1; 385d31a96eSMichael Ellerman } 395d31a96eSMichael Ellerman #else 40ed1cd6deSChristophe Leroy static inline void klp_init_thread_info(struct task_struct *p) { } 41*a4520b25SChristophe Leroy #endif 42f63e6d89SMichael Ellerman 43f63e6d89SMichael Ellerman #endif /* _ASM_POWERPC_LIVEPATCH_H */ 44