4343#include <linux/stacktrace.h>
4444
4545#include <asm/alternative.h>
46+ #include <asm/apple_cpufeature.h>
4647#include <asm/compat.h>
4748#include <asm/cpufeature.h>
4849#include <asm/cacheflush.h>
@@ -374,6 +375,11 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
374375 if (system_supports_tpidr2 ())
375376 p -> thread .tpidr2_el0 = read_sysreg_s (SYS_TPIDR2_EL0 );
376377
378+ #ifdef CONFIG_ARM64_ACTLR_STATE
379+ if (system_has_actlr_state ())
380+ p -> thread .actlr = read_sysreg (actlr_el1 );
381+ #endif
382+
377383 if (stack_start ) {
378384 if (is_compat_thread (task_thread_info (p )))
379385 childregs -> compat_sp = stack_start ;
@@ -516,6 +522,64 @@ void update_sctlr_el1(u64 sctlr)
516522 isb ();
517523}
518524
525+ #ifdef CONFIG_ARM64_ACTLR_STATE
526+ /*
527+ * IMPDEF control register ACTLR_EL1 handling. Some CPUs use this to
528+ * expose features that can be controlled by userspace.
529+ */
530+ static void actlr_thread_switch (struct task_struct * next )
531+ {
532+ if (!system_has_actlr_state ())
533+ return ;
534+
535+ current -> thread .actlr = read_sysreg (actlr_el1 );
536+ write_sysreg (next -> thread .actlr , actlr_el1 );
537+ }
538+ #else
539+ static inline void actlr_thread_switch (struct task_struct * next )
540+ {
541+ }
542+ #endif
543+
544+ #ifdef CONFIG_ARM64_MEMORY_MODEL_CONTROL
545+ int arch_prctl_mem_model_get (struct task_struct * t )
546+ {
547+ if (cpus_have_const_cap (ARM64_HAS_TSO_APPLE ) &&
548+ t -> thread .actlr & ACTLR_APPLE_TSO )
549+ return PR_SET_MEM_MODEL_TSO ;
550+
551+ return PR_SET_MEM_MODEL_DEFAULT ;
552+ }
553+
554+ int arch_prctl_mem_model_set (struct task_struct * t , unsigned long val )
555+ {
556+ if (cpus_have_const_cap (ARM64_HAS_TSO_FIXED ) && val == PR_SET_MEM_MODEL_TSO )
557+ return 0 ;
558+
559+ if (cpus_have_const_cap (ARM64_HAS_TSO_APPLE )) {
560+ WARN_ON (!system_has_actlr_state ());
561+
562+ switch (val ) {
563+ case PR_SET_MEM_MODEL_TSO :
564+ t -> thread .actlr |= ACTLR_APPLE_TSO ;
565+ break ;
566+ case PR_SET_MEM_MODEL_DEFAULT :
567+ t -> thread .actlr &= ~ACTLR_APPLE_TSO ;
568+ break ;
569+ default :
570+ return - EINVAL ;
571+ }
572+ write_sysreg (t -> thread .actlr , actlr_el1 );
573+ return 0 ;
574+ }
575+
576+ if (val == PR_SET_MEM_MODEL_DEFAULT )
577+ return 0 ;
578+
579+ return - EINVAL ;
580+ }
581+ #endif
582+
519583/*
520584 * Thread switching.
521585 */
@@ -533,6 +597,7 @@ struct task_struct *__switch_to(struct task_struct *prev,
533597 ssbs_thread_switch (next );
534598 erratum_1418040_thread_switch (next );
535599 ptrauth_thread_switch_user (next );
600+ actlr_thread_switch (next );
536601
537602 /*
538603 * Complete any pending TLB or cache maintenance on this CPU in case
@@ -654,6 +719,10 @@ void arch_setup_new_exec(void)
654719 arch_prctl_spec_ctrl_set (current , PR_SPEC_STORE_BYPASS ,
655720 PR_SPEC_ENABLE );
656721 }
722+
723+ #ifdef CONFIG_ARM64_MEMORY_MODEL_CONTROL
724+ arch_prctl_mem_model_set (current , PR_SET_MEM_MODEL_DEFAULT );
725+ #endif
657726}
658727
659728#ifdef CONFIG_ARM64_TAGGED_ADDR_ABI
0 commit comments