mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 16:48:26 +02:00 
			
		
		
		
	arm64: ftrace: Add direct call trampoline samples support
The ftrace samples need per-architecture trampoline implementations to save and restore argument registers around the calls to my_direct_func* and to restore polluted registers (eg: x30). These samples also include <asm/asm-offsets.h> which, on arm64, is not necessary and redefines previously defined macros (resulting in warnings) so these includes are guarded by !CONFIG_ARM64. Link: https://lkml.kernel.org/r/20230427140700.625241-3-revest@chromium.org Reviewed-by: Mark Rutland <mark.rutland@arm.com> Tested-by: Mark Rutland <mark.rutland@arm.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Florent Revest <revest@chromium.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
This commit is contained in:
		
							parent
							
								
									8564c31587
								
							
						
					
					
						commit
						8c3526fb86
					
				
					 6 changed files with 151 additions and 0 deletions
				
			
		|  | @ -197,6 +197,8 @@ config ARM64 | |||
| 		    !CC_OPTIMIZE_FOR_SIZE) | ||||
| 	select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY \ | ||||
| 		if DYNAMIC_FTRACE_WITH_ARGS | ||||
| 	select HAVE_SAMPLE_FTRACE_DIRECT | ||||
| 	select HAVE_SAMPLE_FTRACE_DIRECT_MULTI | ||||
| 	select HAVE_EFFICIENT_UNALIGNED_ACCESS | ||||
| 	select HAVE_FAST_GUP | ||||
| 	select HAVE_FTRACE_MCOUNT_RECORD | ||||
|  |  | |||
|  | @ -2,7 +2,9 @@ | |||
| #include <linux/module.h> | ||||
| #include <linux/kthread.h> | ||||
| #include <linux/ftrace.h> | ||||
| #ifndef CONFIG_ARM64 | ||||
| #include <asm/asm-offsets.h> | ||||
| #endif | ||||
| 
 | ||||
| extern void my_direct_func1(void); | ||||
| extern void my_direct_func2(void); | ||||
|  | @ -96,6 +98,38 @@ asm ( | |||
| 
 | ||||
| #endif /* CONFIG_S390 */ | ||||
| 
 | ||||
| #ifdef CONFIG_ARM64 | ||||
| 
 | ||||
| asm ( | ||||
| "	.pushsection    .text, \"ax\", @progbits\n" | ||||
| "	.type		my_tramp1, @function\n" | ||||
| "	.globl		my_tramp1\n" | ||||
| "   my_tramp1:" | ||||
| "	bti	c\n" | ||||
| "	sub	sp, sp, #16\n" | ||||
| "	stp	x9, x30, [sp]\n" | ||||
| "	bl	my_direct_func1\n" | ||||
| "	ldp	x30, x9, [sp]\n" | ||||
| "	add	sp, sp, #16\n" | ||||
| "	ret	x9\n" | ||||
| "	.size		my_tramp1, .-my_tramp1\n" | ||||
| 
 | ||||
| "	.type		my_tramp2, @function\n" | ||||
| "	.globl		my_tramp2\n" | ||||
| "   my_tramp2:" | ||||
| "	bti	c\n" | ||||
| "	sub	sp, sp, #16\n" | ||||
| "	stp	x9, x30, [sp]\n" | ||||
| "	bl	my_direct_func2\n" | ||||
| "	ldp	x30, x9, [sp]\n" | ||||
| "	add	sp, sp, #16\n" | ||||
| "	ret	x9\n" | ||||
| "	.size		my_tramp2, .-my_tramp2\n" | ||||
| "	.popsection\n" | ||||
| ); | ||||
| 
 | ||||
| #endif /* CONFIG_ARM64 */ | ||||
| 
 | ||||
| #ifdef CONFIG_LOONGARCH | ||||
| 
 | ||||
| asm ( | ||||
|  |  | |||
|  | @ -2,7 +2,9 @@ | |||
| #include <linux/module.h> | ||||
| #include <linux/kthread.h> | ||||
| #include <linux/ftrace.h> | ||||
| #ifndef CONFIG_ARM64 | ||||
| #include <asm/asm-offsets.h> | ||||
| #endif | ||||
| 
 | ||||
| extern void my_direct_func1(unsigned long ip); | ||||
| extern void my_direct_func2(unsigned long ip); | ||||
|  | @ -103,6 +105,44 @@ asm ( | |||
| 
 | ||||
| #endif /* CONFIG_S390 */ | ||||
| 
 | ||||
| #ifdef CONFIG_ARM64 | ||||
| 
 | ||||
| asm ( | ||||
| "	.pushsection    .text, \"ax\", @progbits\n" | ||||
| "	.type		my_tramp1, @function\n" | ||||
| "	.globl		my_tramp1\n" | ||||
| "   my_tramp1:" | ||||
| "	bti	c\n" | ||||
| "	sub	sp, sp, #32\n" | ||||
| "	stp	x9, x30, [sp]\n" | ||||
| "	str	x0, [sp, #16]\n" | ||||
| "	mov	x0, x30\n" | ||||
| "	bl	my_direct_func1\n" | ||||
| "	ldp	x30, x9, [sp]\n" | ||||
| "	ldr	x0, [sp, #16]\n" | ||||
| "	add	sp, sp, #32\n" | ||||
| "	ret	x9\n" | ||||
| "	.size		my_tramp1, .-my_tramp1\n" | ||||
| 
 | ||||
| "	.type		my_tramp2, @function\n" | ||||
| "	.globl		my_tramp2\n" | ||||
| "   my_tramp2:" | ||||
| "	bti	c\n" | ||||
| "	sub	sp, sp, #32\n" | ||||
| "	stp	x9, x30, [sp]\n" | ||||
| "	str	x0, [sp, #16]\n" | ||||
| "	mov	x0, x30\n" | ||||
| "	bl	my_direct_func2\n" | ||||
| "	ldp	x30, x9, [sp]\n" | ||||
| "	ldr	x0, [sp, #16]\n" | ||||
| "	add	sp, sp, #32\n" | ||||
| "	ret	x9\n" | ||||
| "	.size		my_tramp2, .-my_tramp2\n" | ||||
| "	.popsection\n" | ||||
| ); | ||||
| 
 | ||||
| #endif /* CONFIG_ARM64 */ | ||||
| 
 | ||||
| #ifdef CONFIG_LOONGARCH | ||||
| #include <asm/asm.h> | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,7 +4,9 @@ | |||
| #include <linux/mm.h> /* for handle_mm_fault() */ | ||||
| #include <linux/ftrace.h> | ||||
| #include <linux/sched/stat.h> | ||||
| #ifndef CONFIG_ARM64 | ||||
| #include <asm/asm-offsets.h> | ||||
| #endif | ||||
| 
 | ||||
| extern void my_direct_func(unsigned long ip); | ||||
| 
 | ||||
|  | @ -66,6 +68,29 @@ asm ( | |||
| 
 | ||||
| #endif /* CONFIG_S390 */ | ||||
| 
 | ||||
| #ifdef CONFIG_ARM64 | ||||
| 
 | ||||
| asm ( | ||||
| "	.pushsection	.text, \"ax\", @progbits\n" | ||||
| "	.type		my_tramp, @function\n" | ||||
| "	.globl		my_tramp\n" | ||||
| "   my_tramp:" | ||||
| "	bti	c\n" | ||||
| "	sub	sp, sp, #32\n" | ||||
| "	stp	x9, x30, [sp]\n" | ||||
| "	str	x0, [sp, #16]\n" | ||||
| "	mov	x0, x30\n" | ||||
| "	bl	my_direct_func\n" | ||||
| "	ldp	x30, x9, [sp]\n" | ||||
| "	ldr	x0, [sp, #16]\n" | ||||
| "	add	sp, sp, #32\n" | ||||
| "	ret	x9\n" | ||||
| "	.size		my_tramp, .-my_tramp\n" | ||||
| "	.popsection\n" | ||||
| ); | ||||
| 
 | ||||
| #endif /* CONFIG_ARM64 */ | ||||
| 
 | ||||
| #ifdef CONFIG_LOONGARCH | ||||
| 
 | ||||
| #include <asm/asm.h> | ||||
|  |  | |||
|  | @ -3,7 +3,9 @@ | |||
| 
 | ||||
| #include <linux/mm.h> /* for handle_mm_fault() */ | ||||
| #include <linux/ftrace.h> | ||||
| #ifndef CONFIG_ARM64 | ||||
| #include <asm/asm-offsets.h> | ||||
| #endif | ||||
| 
 | ||||
| extern void my_direct_func(struct vm_area_struct *vma, unsigned long address, | ||||
| 			   unsigned int flags, struct pt_regs *regs); | ||||
|  | @ -72,6 +74,30 @@ asm ( | |||
| 
 | ||||
| #endif /* CONFIG_S390 */ | ||||
| 
 | ||||
| #ifdef CONFIG_ARM64 | ||||
| 
 | ||||
| asm ( | ||||
| "	.pushsection	.text, \"ax\", @progbits\n" | ||||
| "	.type		my_tramp, @function\n" | ||||
| "	.globl		my_tramp\n" | ||||
| "   my_tramp:" | ||||
| "	bti	c\n" | ||||
| "	sub	sp, sp, #48\n" | ||||
| "	stp	x9, x30, [sp]\n" | ||||
| "	stp	x0, x1, [sp, #16]\n" | ||||
| "	stp	x2, x3, [sp, #32]\n" | ||||
| "	bl	my_direct_func\n" | ||||
| "	ldp	x30, x9, [sp]\n" | ||||
| "	ldp	x0, x1, [sp, #16]\n" | ||||
| "	ldp	x2, x3, [sp, #32]\n" | ||||
| "	add	sp, sp, #48\n" | ||||
| "	ret	x9\n" | ||||
| "	.size		my_tramp, .-my_tramp\n" | ||||
| "	.popsection\n" | ||||
| ); | ||||
| 
 | ||||
| #endif /* CONFIG_ARM64 */ | ||||
| 
 | ||||
| #ifdef CONFIG_LOONGARCH | ||||
| 
 | ||||
| asm ( | ||||
|  |  | |||
|  | @ -3,7 +3,9 @@ | |||
| 
 | ||||
| #include <linux/sched.h> /* for wake_up_process() */ | ||||
| #include <linux/ftrace.h> | ||||
| #ifndef CONFIG_ARM64 | ||||
| #include <asm/asm-offsets.h> | ||||
| #endif | ||||
| 
 | ||||
| extern void my_direct_func(struct task_struct *p); | ||||
| 
 | ||||
|  | @ -63,6 +65,28 @@ asm ( | |||
| 
 | ||||
| #endif /* CONFIG_S390 */ | ||||
| 
 | ||||
| #ifdef CONFIG_ARM64 | ||||
| 
 | ||||
| asm ( | ||||
| "	.pushsection	.text, \"ax\", @progbits\n" | ||||
| "	.type		my_tramp, @function\n" | ||||
| "	.globl		my_tramp\n" | ||||
| "   my_tramp:" | ||||
| "	bti	c\n" | ||||
| "	sub	sp, sp, #32\n" | ||||
| "	stp	x9, x30, [sp]\n" | ||||
| "	str	x0, [sp, #16]\n" | ||||
| "	bl	my_direct_func\n" | ||||
| "	ldp	x30, x9, [sp]\n" | ||||
| "	ldr	x0, [sp, #16]\n" | ||||
| "	add	sp, sp, #32\n" | ||||
| "	ret	x9\n" | ||||
| "	.size		my_tramp, .-my_tramp\n" | ||||
| "	.popsection\n" | ||||
| ); | ||||
| 
 | ||||
| #endif /* CONFIG_ARM64 */ | ||||
| 
 | ||||
| #ifdef CONFIG_LOONGARCH | ||||
| 
 | ||||
| asm ( | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Florent Revest
						Florent Revest