Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #include <linux/mm.h> /* for handle_mm_fault() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <linux/ftrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) extern void my_direct_func(struct vm_area_struct *vma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) 			   unsigned long address, unsigned int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) void my_direct_func(struct vm_area_struct *vma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 			unsigned long address, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 	trace_printk("handle mm fault vma=%p address=%lx flags=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 		     vma, address, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) extern void my_tramp(void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) asm (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) "	.pushsection    .text, \"ax\", @progbits\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) "	.type		my_tramp, @function\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) "	.globl		my_tramp\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) "   my_tramp:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) "	pushq %rbp\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) "	movq %rsp, %rbp\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) "	pushq %rdi\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) "	pushq %rsi\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) "	pushq %rdx\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) "	call my_direct_func\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) "	popq %rdx\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) "	popq %rsi\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) "	popq %rdi\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) "	leave\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) "	ret\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) "	.size		my_tramp, .-my_tramp\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) "	.popsection\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static int __init ftrace_direct_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	return register_ftrace_direct((unsigned long)handle_mm_fault,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 				     (unsigned long)my_tramp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static void __exit ftrace_direct_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	unregister_ftrace_direct((unsigned long)handle_mm_fault,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 				 (unsigned long)my_tramp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) module_init(ftrace_direct_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) module_exit(ftrace_direct_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) MODULE_AUTHOR("Steven Rostedt");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) MODULE_DESCRIPTION("Another example use case of using register_ftrace_direct()");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) MODULE_LICENSE("GPL");