Skip to content

Commit ec45d1c

Browse files
wildea01ctmarinas
authored andcommitted
arm64: mm: update CONTEXTIDR register to contain PID of current process
This patch is a port of 575320d ("ARM: 7445/1: mm: update CONTEXTIDR register to contain PID of current process") from ARM that introduces a new Kconfig option which, when enabled, causes the kernel to write the PID of the current task into the CONTEXTIDR register on context switch. This is useful when analysing hardware trace, since writes to this register can be configured to emit an event into the trace stream. Signed-off-by: Will Deacon <will.deacon@arm.com> [catalin.marinas@arm.com: contextidr_thread_switch() moved to mmu_context.h] Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 3a0310e commit ec45d1c

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎arch/arm64/Kconfig.debug‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,12 @@ config EARLY_PRINTK
3333
is assumed that the early console device has been initialised
3434
by the boot loader prior to starting the Linux kernel.
3535

36+
config PID_IN_CONTEXTIDR
37+
bool "Write the current PID to the CONTEXTIDR register"
38+
help
39+
Enabling this option causes the kernel to write the current PID to
40+
the CONTEXTIDR register, at the expense of some additional
41+
instructions during context switch. Say Y here only if you are
42+
planning to use hardware trace tools with this kernel.
43+
3644
endmenu

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ extern unsigned int cpu_last_asid;
3535
void __init_new_context(struct task_struct *tsk, struct mm_struct *mm);
3636
void __new_context(struct mm_struct *mm);
3737

38+
#ifdef CONFIG_PID_IN_CONTEXTIDR
39+
static inline void contextidr_thread_switch(struct task_struct *next)
40+
{
41+
asm(
42+
" msr contextidr_el1, %0\n"
43+
" isb"
44+
:
45+
: "r" (task_pid_nr(next)));
46+
}
47+
#else
48+
static inline void contextidr_thread_switch(struct task_struct *next)
49+
{
50+
}
51+
#endif
52+
3853
/*
3954
* Set TTBR0 to empty_zero_page. No translations will be possible via TTBR0.
4055
*/

‎arch/arm64/kernel/process.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@
4545

4646
#include <asm/compat.h>
4747
#include <asm/cacheflush.h>
48+
#include <asm/fpsimd.h>
49+
#include <asm/mmu_context.h>
4850
#include <asm/processor.h>
4951
#include <asm/stacktrace.h>
50-
#include <asm/fpsimd.h>
5152

5253
static void setup_restart(void)
5354
{
@@ -319,6 +320,7 @@ struct task_struct *__switch_to(struct task_struct *prev,
319320
/* the actual thread switch */
320321
last = cpu_switch_to(prev, next);
321322

323+
contextidr_thread_switch(next);
322324
return last;
323325
}
324326

0 commit comments

Comments
 (0)