Skip to content

Commit 6c81fe7

Browse files
Larry Basselctmarinas
authored andcommitted
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>
1 parent 6ab6463 commit 6c81fe7

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎arch/arm64/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ config ARM64
6363
select RTC_LIB
6464
select SPARSE_IRQ
6565
select SYSCTL_EXCEPTION_TRACE
66+
select HAVE_CONTEXT_TRACKING
6667
help
6768
ARM 64-bit (AArch64) Linux support.
6869

‎arch/arm64/include/asm/thread_info.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ static inline struct thread_info *current_thread_info(void)
103103
#define TIF_NEED_RESCHED 1
104104
#define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
105105
#define TIF_FOREIGN_FPSTATE 3 /* CPU's FP state is not current's */
106+
#define TIF_NOHZ 7
106107
#define TIF_SYSCALL_TRACE 8
107108
#define TIF_SYSCALL_AUDIT 9
108109
#define TIF_SYSCALL_TRACEPOINT 10
@@ -118,6 +119,7 @@ static inline struct thread_info *current_thread_info(void)
118119
#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
119120
#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
120121
#define _TIF_FOREIGN_FPSTATE (1 << TIF_FOREIGN_FPSTATE)
122+
#define _TIF_NOHZ (1 << TIF_NOHZ)
121123
#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
122124
#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
123125
#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
@@ -128,7 +130,8 @@ static inline struct thread_info *current_thread_info(void)
128130
_TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE)
129131

130132
#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
131-
_TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
133+
_TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
134+
_TIF_NOHZ)
132135

133136
#endif /* __KERNEL__ */
134137
#endif /* __ASM_THREAD_INFO_H */

‎arch/arm64/kernel/entry.S‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,32 @@
2929
#include <asm/unistd.h>
3030
#include <asm/unistd32.h>
3131

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+
3258
/*
3359
* Bad Abort numbers
3460
*-----------------
@@ -91,6 +117,7 @@
91117
.macro kernel_exit, el, ret = 0
92118
ldp x21, x22, [sp, #S_PC] // load ELR, SPSR
93119
.if \el == 0
120+
ct_user_enter
94121
ldr x23, [sp, #S_SP] // load return stack pointer
95122
.endif
96123
.if \ret
@@ -426,6 +453,7 @@ el0_da:
426453
mrs x26, far_el1
427454
// enable interrupts before calling the main handler
428455
enable_dbg_and_irq
456+
ct_user_exit
429457
bic x0, x26, #(0xff << 56)
430458
mov x1, x25
431459
mov x2, sp
@@ -438,6 +466,7 @@ el0_ia:
438466
mrs x26, far_el1
439467
// enable interrupts before calling the main handler
440468
enable_dbg_and_irq
469+
ct_user_exit
441470
mov x0, x26
442471
orr x1, x25, #1 << 24 // use reserved ISS bit for instruction aborts
443472
mov x2, sp
@@ -448,6 +477,7 @@ el0_fpsimd_acc:
448477
* Floating Point or Advanced SIMD access
449478
*/
450479
enable_dbg
480+
ct_user_exit
451481
mov x0, x25
452482
mov x1, sp
453483
adr lr, ret_to_user
@@ -457,6 +487,7 @@ el0_fpsimd_exc:
457487
* Floating Point or Advanced SIMD exception
458488
*/
459489
enable_dbg
490+
ct_user_exit
460491
mov x0, x25
461492
mov x1, sp
462493
adr lr, ret_to_user
@@ -479,6 +510,7 @@ el0_undef:
479510
*/
480511
// enable interrupts before calling the main handler
481512
enable_dbg_and_irq
513+
ct_user_exit
482514
mov x0, sp
483515
adr lr, ret_to_user
484516
b do_undefinstr
@@ -492,9 +524,11 @@ el0_dbg:
492524
mov x2, sp
493525
bl do_debug_exception
494526
enable_dbg
527+
ct_user_exit
495528
b ret_to_user
496529
el0_inv:
497530
enable_dbg
531+
ct_user_exit
498532
mov x0, sp
499533
mov x1, #BAD_SYNC
500534
mrs x2, esr_el1
@@ -511,6 +545,7 @@ el0_irq_naked:
511545
bl trace_hardirqs_off
512546
#endif
513547

548+
ct_user_exit
514549
irq_handler
515550

516551
#ifdef CONFIG_TRACE_IRQFLAGS
@@ -615,6 +650,7 @@ el0_svc:
615650
el0_svc_naked: // compat entry point
616651
stp x0, scno, [sp, #S_ORIG_X0] // save the original x0 and syscall number
617652
enable_dbg_and_irq
653+
ct_user_exit 1
618654

619655
ldr x16, [tsk, #TI_FLAGS] // check for syscall hooks
620656
tst x16, #_TIF_SYSCALL_WORK

0 commit comments

Comments
 (0)