Skip to content

Commit 1d9d900

Browse files
committed
arm64: Introduce scaffolding to add ACTLR_EL1 to thread state
Some CPUs expose IMPDEF features in ACTLR_EL1 that can be meaningfully controlled per-thread (like TSO control on Apple cores). Add the basic scaffolding to save/restore this register as part of context switching. This mechanism is disabled by default both by config symbol and via a runtime check, which ensures it is never triggered unless the system is known to need it for some feature (which also implies that the layout of ACTLR_EL1 is uniform between all CPU core types). Signed-off-by: Hector Martin <[email protected]>
1 parent 457391b commit 1d9d900

5 files changed

Lines changed: 36 additions & 0 deletions

File tree

arch/arm64/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ config KASAN_SHADOW_OFFSET
380380
config UNWIND_TABLES
381381
bool
382382

383+
config ARM64_ACTLR_STATE
384+
bool
385+
383386
source "arch/arm64/Kconfig.platforms"
384387

385388
menu "Kernel Features"

arch/arm64/include/asm/cpufeature.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,11 @@ static inline unsigned int get_vmid_bits(u64 mmfr1)
915915
return 8;
916916
}
917917

918+
static __always_inline bool system_has_actlr_state(void)
919+
{
920+
return false;
921+
}
922+
918923
struct arm64_ftr_reg *get_arm64_ftr_reg(u32 sys_id);
919924

920925
extern struct arm64_ftr_override id_aa64mmfr1_override;

arch/arm64/include/asm/processor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ struct thread_struct {
179179
u64 sctlr_user;
180180
u64 svcr;
181181
u64 tpidr2_el0;
182+
#ifdef CONFIG_ARM64_ACTLR_STATE
183+
u64 actlr;
184+
#endif
182185
};
183186

184187
static inline unsigned int thread_get_vl(struct thread_struct *thread,

arch/arm64/kernel/process.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
374374
if (system_supports_tpidr2())
375375
p->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0);
376376

377+
if (system_has_actlr_state())
378+
p->thread.actlr = read_sysreg(actlr_el1);
379+
377380
if (stack_start) {
378381
if (is_compat_thread(task_thread_info(p)))
379382
childregs->compat_sp = stack_start;
@@ -516,6 +519,19 @@ void update_sctlr_el1(u64 sctlr)
516519
isb();
517520
}
518521

522+
/*
523+
* IMPDEF control register ACTLR_EL1 handling. Some CPUs use this to
524+
* expose features that can be controlled by userspace.
525+
*/
526+
static void actlr_thread_switch(struct task_struct *next)
527+
{
528+
if (!system_has_actlr_state())
529+
return;
530+
531+
current->thread.actlr = read_sysreg(actlr_el1);
532+
write_sysreg(next->thread.actlr, actlr_el1);
533+
}
534+
519535
/*
520536
* Thread switching.
521537
*/
@@ -533,6 +549,7 @@ struct task_struct *__switch_to(struct task_struct *prev,
533549
ssbs_thread_switch(next);
534550
erratum_1418040_thread_switch(next);
535551
ptrauth_thread_switch_user(next);
552+
actlr_thread_switch(next);
536553

537554
/*
538555
* Complete any pending TLB or cache maintenance on this CPU in case

arch/arm64/kernel/setup.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,14 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p)
380380
*/
381381
init_task.thread_info.ttbr0 = phys_to_ttbr(__pa_symbol(reserved_pg_dir));
382382
#endif
383+
#ifdef CONFIG_ARM64_ACTLR_STATE
384+
/* Store the boot CPU ACTLR_EL1 value as the default. This will only
385+
* be actually restored during context switching iff the platform is
386+
* known to use ACTLR_EL1 for exposable features and its layout is
387+
* known to be the same on all CPUs.
388+
*/
389+
init_task.thread.actlr = read_sysreg(actlr_el1);
390+
#endif
383391

384392
if (boot_args[1] || boot_args[2] || boot_args[3]) {
385393
pr_err("WARNING: x1-x3 nonzero in violation of boot protocol:\n"

0 commit comments

Comments
 (0)