Skip to content

Commit df35510

Browse files
amitdanielkachhapctmarinas
authored andcommitted
arm64: ptrauth: Add bootup/runtime flags for __cpu_setup
This patch allows __cpu_setup to be invoked with one of these flags, ARM64_CPU_BOOT_PRIMARY, ARM64_CPU_BOOT_SECONDARY or ARM64_CPU_RUNTIME. This is required as some cpufeatures need different handling during different scenarios. The input parameter in x0 is preserved till the end to be used inside this function. There should be no functional change with this patch and is useful for the subsequent ptrauth patch which utilizes it. Some upcoming arm cpufeatures can also utilize these flags. Suggested-by: James Morse <[email protected]> Signed-off-by: Amit Daniel Kachhap <[email protected]> Reviewed-by: Vincenzo Frascino <[email protected]> Reviewed-by: James Morse <[email protected]> Reviewed-by: Suzuki K Poulose <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent be12984 commit df35510

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

arch/arm64/include/asm/smp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
#define CPU_STUCK_REASON_52_BIT_VA (UL(1) << CPU_STUCK_REASON_SHIFT)
2424
#define CPU_STUCK_REASON_NO_GRAN (UL(2) << CPU_STUCK_REASON_SHIFT)
2525

26+
/* Possible options for __cpu_setup */
27+
/* Option to setup primary cpu */
28+
#define ARM64_CPU_BOOT_PRIMARY (1)
29+
/* Option to setup secondary cpus */
30+
#define ARM64_CPU_BOOT_SECONDARY (2)
31+
/* Option to setup cpus for different cpu run time services */
32+
#define ARM64_CPU_RUNTIME (3)
33+
2634
#ifndef __ASSEMBLY__
2735

2836
#include <asm/percpu.h>

arch/arm64/kernel/head.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ ENTRY(stext)
118118
* On return, the CPU will be ready for the MMU to be turned on and
119119
* the TCR will have been set.
120120
*/
121+
mov x0, #ARM64_CPU_BOOT_PRIMARY
121122
bl __cpu_setup // initialise processor
122123
b __primary_switch
123124
ENDPROC(stext)
@@ -712,6 +713,7 @@ secondary_startup:
712713
* Common entry point for secondary CPUs.
713714
*/
714715
bl __cpu_secondary_check52bitva
716+
mov x0, #ARM64_CPU_BOOT_SECONDARY
715717
bl __cpu_setup // initialise processor
716718
adrp x1, swapper_pg_dir
717719
bl __enable_mmu

arch/arm64/kernel/sleep.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <linux/linkage.h>
44
#include <asm/asm-offsets.h>
55
#include <asm/assembler.h>
6+
#include <asm/smp.h>
67

78
.text
89
/*
@@ -99,6 +100,7 @@ ENDPROC(__cpu_suspend_enter)
99100
.pushsection ".idmap.text", "awx"
100101
ENTRY(cpu_resume)
101102
bl el2_setup // if in EL2 drop to EL1 cleanly
103+
mov x0, #ARM64_CPU_RUNTIME
102104
bl __cpu_setup
103105
/* enable the MMU early - so we can access sleep_save_stash by va */
104106
adrp x1, swapper_pg_dir

arch/arm64/mm/proc.S

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,30 +408,30 @@ SYM_FUNC_END(idmap_kpti_install_ng_mappings)
408408
/*
409409
* __cpu_setup
410410
*
411-
* Initialise the processor for turning the MMU on. Return in x0 the
412-
* value of the SCTLR_EL1 register.
411+
* Initialise the processor for turning the MMU on.
412+
*
413+
* Input:
414+
* x0 with a flag ARM64_CPU_BOOT_PRIMARY/ARM64_CPU_BOOT_SECONDARY/ARM64_CPU_RUNTIME.
415+
* Output:
416+
* Return in x0 the value of the SCTLR_EL1 register.
413417
*/
414418
.pushsection ".idmap.text", "awx"
415419
SYM_FUNC_START(__cpu_setup)
416420
tlbi vmalle1 // Invalidate local TLB
417421
dsb nsh
418422

419-
mov x0, #3 << 20
420-
msr cpacr_el1, x0 // Enable FP/ASIMD
421-
mov x0, #1 << 12 // Reset mdscr_el1 and disable
422-
msr mdscr_el1, x0 // access to the DCC from EL0
423+
mov x1, #3 << 20
424+
msr cpacr_el1, x1 // Enable FP/ASIMD
425+
mov x1, #1 << 12 // Reset mdscr_el1 and disable
426+
msr mdscr_el1, x1 // access to the DCC from EL0
423427
isb // Unmask debug exceptions now,
424428
enable_dbg // since this is per-cpu
425-
reset_pmuserenr_el0 x0 // Disable PMU access from EL0
429+
reset_pmuserenr_el0 x1 // Disable PMU access from EL0
426430
/*
427431
* Memory region attributes
428432
*/
429433
mov_q x5, MAIR_EL1_SET
430434
msr mair_el1, x5
431-
/*
432-
* Prepare SCTLR
433-
*/
434-
mov_q x0, SCTLR_EL1_SET
435435
/*
436436
* Set/prepare TCR and TTBR. We use 512GB (39-bit) address range for
437437
* both user and kernel.
@@ -468,5 +468,9 @@ SYM_FUNC_START(__cpu_setup)
468468
1:
469469
#endif /* CONFIG_ARM64_HW_AFDBM */
470470
msr tcr_el1, x10
471+
/*
472+
* Prepare SCTLR
473+
*/
474+
mov_q x0, SCTLR_EL1_SET
471475
ret // return to head.S
472476
SYM_FUNC_END(__cpu_setup)

0 commit comments

Comments
 (0)