Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm64: enable context tracking

Make calls to ct_user_enter when the kernel is exited
and ct_user_exit when the kernel is entered (in el0_da,
el0_ia, el0_svc, el0_irq and all of the "error" paths).

These macros expand to function calls which will only work
properly if el0_sync and related code has been rearranged
(in a previous patch of this series).

The calls to ct_user_exit are made after hw debugging has been
enabled (enable_dbg_and_irq).

The call to ct_user_enter is made at the beginning of the
kernel_exit macro.

This patch is based on earlier work by Kevin Hilman.
Save/restore optimizations were also done by Kevin.

Acked-by: Will Deacon <will.deacon@arm.com>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
Tested-by: Kevin Hilman <khilman@linaro.org>
Signed-off-by: Larry Bassel <larry.bassel@linaro.org>
Signed-off-by: Kevin Hilman <khilman@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

authored by

Larry Bassel and committed by
Catalin Marinas
6c81fe79 6ab6463a

+41 -1
+1
arch/arm64/Kconfig
··· 63 63 select RTC_LIB 64 64 select SPARSE_IRQ 65 65 select SYSCTL_EXCEPTION_TRACE 66 + select HAVE_CONTEXT_TRACKING 66 67 help 67 68 ARM 64-bit (AArch64) Linux support. 68 69
+4 -1
arch/arm64/include/asm/thread_info.h
··· 103 103 #define TIF_NEED_RESCHED 1 104 104 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */ 105 105 #define TIF_FOREIGN_FPSTATE 3 /* CPU's FP state is not current's */ 106 + #define TIF_NOHZ 7 106 107 #define TIF_SYSCALL_TRACE 8 107 108 #define TIF_SYSCALL_AUDIT 9 108 109 #define TIF_SYSCALL_TRACEPOINT 10 ··· 119 118 #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) 120 119 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) 121 120 #define _TIF_FOREIGN_FPSTATE (1 << TIF_FOREIGN_FPSTATE) 121 + #define _TIF_NOHZ (1 << TIF_NOHZ) 122 122 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) 123 123 #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) 124 124 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) ··· 130 128 _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE) 131 129 132 130 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ 133 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP) 131 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ 132 + _TIF_NOHZ) 134 133 135 134 #endif /* __KERNEL__ */ 136 135 #endif /* __ASM_THREAD_INFO_H */
+36
arch/arm64/kernel/entry.S
··· 30 30 #include <asm/unistd32.h> 31 31 32 32 /* 33 + * Context tracking subsystem. Used to instrument transitions 34 + * between user and kernel mode. 35 + */ 36 + .macro ct_user_exit, syscall = 0 37 + #ifdef CONFIG_CONTEXT_TRACKING 38 + bl context_tracking_user_exit 39 + .if \syscall == 1 40 + /* 41 + * Save/restore needed during syscalls. Restore syscall arguments from 42 + * the values already saved on stack during kernel_entry. 43 + */ 44 + ldp x0, x1, [sp] 45 + ldp x2, x3, [sp, #S_X2] 46 + ldp x4, x5, [sp, #S_X4] 47 + ldp x6, x7, [sp, #S_X6] 48 + .endif 49 + #endif 50 + .endm 51 + 52 + .macro ct_user_enter 53 + #ifdef CONFIG_CONTEXT_TRACKING 54 + bl context_tracking_user_enter 55 + #endif 56 + .endm 57 + 58 + /* 33 59 * Bad Abort numbers 34 60 *----------------- 35 61 */ ··· 117 91 .macro kernel_exit, el, ret = 0 118 92 ldp x21, x22, [sp, #S_PC] // load ELR, SPSR 119 93 .if \el == 0 94 + ct_user_enter 120 95 ldr x23, [sp, #S_SP] // load return stack pointer 121 96 .endif 122 97 .if \ret ··· 453 426 mrs x26, far_el1 454 427 // enable interrupts before calling the main handler 455 428 enable_dbg_and_irq 429 + ct_user_exit 456 430 bic x0, x26, #(0xff << 56) 457 431 mov x1, x25 458 432 mov x2, sp ··· 466 438 mrs x26, far_el1 467 439 // enable interrupts before calling the main handler 468 440 enable_dbg_and_irq 441 + ct_user_exit 469 442 mov x0, x26 470 443 orr x1, x25, #1 << 24 // use reserved ISS bit for instruction aborts 471 444 mov x2, sp ··· 477 448 * Floating Point or Advanced SIMD access 478 449 */ 479 450 enable_dbg 451 + ct_user_exit 480 452 mov x0, x25 481 453 mov x1, sp 482 454 adr lr, ret_to_user ··· 487 457 * Floating Point or Advanced SIMD exception 488 458 */ 489 459 enable_dbg 460 + ct_user_exit 490 461 mov x0, x25 491 462 mov x1, sp 492 463 adr lr, ret_to_user ··· 510 479 */ 511 480 // enable interrupts before calling the main handler 512 481 enable_dbg_and_irq 482 + ct_user_exit 513 483 mov x0, sp 514 484 adr lr, ret_to_user 515 485 b do_undefinstr ··· 524 492 mov x2, sp 525 493 bl do_debug_exception 526 494 enable_dbg 495 + ct_user_exit 527 496 b ret_to_user 528 497 el0_inv: 529 498 enable_dbg 499 + ct_user_exit 530 500 mov x0, sp 531 501 mov x1, #BAD_SYNC 532 502 mrs x2, esr_el1 ··· 545 511 bl trace_hardirqs_off 546 512 #endif 547 513 514 + ct_user_exit 548 515 irq_handler 549 516 550 517 #ifdef CONFIG_TRACE_IRQFLAGS ··· 650 615 el0_svc_naked: // compat entry point 651 616 stp x0, scno, [sp, #S_ORIG_X0] // save the original x0 and syscall number 652 617 enable_dbg_and_irq 618 + ct_user_exit 1 653 619 654 620 ldr x16, [tsk, #TI_FLAGS] // check for syscall hooks 655 621 tst x16, #_TIF_SYSCALL_WORK