Skip to content

Commit 3cd86a5

Browse files
committed
Merge tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
Pull arm64 updates from Catalin Marinas: "The bulk is in-kernel pointer authentication, activity monitors and lots of asm symbol annotations. I also queued the sys_mremap() patch commenting the asymmetry in the address untagging. Summary: - In-kernel Pointer Authentication support (previously only offered to user space). - ARM Activity Monitors (AMU) extension support allowing better CPU utilisation numbers for the scheduler (frequency invariance). - Memory hot-remove support for arm64. - Lots of asm annotations (SYM_*) in preparation for the in-kernel Branch Target Identification (BTI) support. - arm64 perf updates: ARMv8.5-PMU 64-bit counters, refactoring the PMU init callbacks, support for new DT compatibles. - IPv6 header checksum optimisation. - Fixes: SDEI (software delegated exception interface) double-lock on hibernate with shared events. - Minor clean-ups and refactoring: cpu_ops accessor, cpu_do_switch_mm() converted to C, cpufeature finalisation helper. - sys_mremap() comment explaining the asymmetric address untagging behaviour" * tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux: (81 commits) mm/mremap: Add comment explaining the untagging behaviour of mremap() arm64: head: Convert install_el2_stub to SYM_INNER_LABEL arm64: Introduce get_cpu_ops() helper function arm64: Rename cpu_read_ops() to init_cpu_ops() arm64: Declare ACPI parking protocol CPU operation if needed arm64: move kimage_vaddr to .rodata arm64: use mov_q instead of literal ldr arm64: Kconfig: verify binutils support for ARM64_PTR_AUTH lkdtm: arm64: test kernel pointer authentication arm64: compile the kernel with ptrauth return address signing kconfig: Add support for 'as-option' arm64: suspend: restore the kernel ptrauth keys arm64: __show_regs: strip PAC from lr in printk arm64: unwind: strip PAC from kernel addresses arm64: mask PAC bits of __builtin_return_address arm64: initialize ptrauth keys for kernel booting task arm64: initialize and switch ptrauth kernel keys arm64: enable ptrauth earlier arm64: cpufeature: handle conflicts based on capability arm64: cpufeature: Move cpu capability helpers inside C file ...
2 parents a8222fd + b2a84de commit 3cd86a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2192
-700
lines changed

Documentation/arm64/amu.rst

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
=======================================================
2+
Activity Monitors Unit (AMU) extension in AArch64 Linux
3+
=======================================================
4+
5+
Author: Ionela Voinescu <[email protected]>
6+
7+
Date: 2019-09-10
8+
9+
This document briefly describes the provision of Activity Monitors Unit
10+
support in AArch64 Linux.
11+
12+
13+
Architecture overview
14+
---------------------
15+
16+
The activity monitors extension is an optional extension introduced by the
17+
ARMv8.4 CPU architecture.
18+
19+
The activity monitors unit, implemented in each CPU, provides performance
20+
counters intended for system management use. The AMU extension provides a
21+
system register interface to the counter registers and also supports an
22+
optional external memory-mapped interface.
23+
24+
Version 1 of the Activity Monitors architecture implements a counter group
25+
of four fixed and architecturally defined 64-bit event counters.
26+
- CPU cycle counter: increments at the frequency of the CPU.
27+
- Constant counter: increments at the fixed frequency of the system
28+
clock.
29+
- Instructions retired: increments with every architecturally executed
30+
instruction.
31+
- Memory stall cycles: counts instruction dispatch stall cycles caused by
32+
misses in the last level cache within the clock domain.
33+
34+
When in WFI or WFE these counters do not increment.
35+
36+
The Activity Monitors architecture provides space for up to 16 architected
37+
event counters. Future versions of the architecture may use this space to
38+
implement additional architected event counters.
39+
40+
Additionally, version 1 implements a counter group of up to 16 auxiliary
41+
64-bit event counters.
42+
43+
On cold reset all counters reset to 0.
44+
45+
46+
Basic support
47+
-------------
48+
49+
The kernel can safely run a mix of CPUs with and without support for the
50+
activity monitors extension. Therefore, when CONFIG_ARM64_AMU_EXTN is
51+
selected we unconditionally enable the capability to allow any late CPU
52+
(secondary or hotplugged) to detect and use the feature.
53+
54+
When the feature is detected on a CPU, we flag the availability of the
55+
feature but this does not guarantee the correct functionality of the
56+
counters, only the presence of the extension.
57+
58+
Firmware (code running at higher exception levels, e.g. arm-tf) support is
59+
needed to:
60+
- Enable access for lower exception levels (EL2 and EL1) to the AMU
61+
registers.
62+
- Enable the counters. If not enabled these will read as 0.
63+
- Save/restore the counters before/after the CPU is being put/brought up
64+
from the 'off' power state.
65+
66+
When using kernels that have this feature enabled but boot with broken
67+
firmware the user may experience panics or lockups when accessing the
68+
counter registers. Even if these symptoms are not observed, the values
69+
returned by the register reads might not correctly reflect reality. Most
70+
commonly, the counters will read as 0, indicating that they are not
71+
enabled.
72+
73+
If proper support is not provided in firmware it's best to disable
74+
CONFIG_ARM64_AMU_EXTN. To be noted that for security reasons, this does not
75+
bypass the setting of AMUSERENR_EL0 to trap accesses from EL0 (userspace) to
76+
EL1 (kernel). Therefore, firmware should still ensure accesses to AMU registers
77+
are not trapped in EL2/EL3.
78+
79+
The fixed counters of AMUv1 are accessible though the following system
80+
register definitions:
81+
- SYS_AMEVCNTR0_CORE_EL0
82+
- SYS_AMEVCNTR0_CONST_EL0
83+
- SYS_AMEVCNTR0_INST_RET_EL0
84+
- SYS_AMEVCNTR0_MEM_STALL_EL0
85+
86+
Auxiliary platform specific counters can be accessed using
87+
SYS_AMEVCNTR1_EL0(n), where n is a value between 0 and 15.
88+
89+
Details can be found in: arch/arm64/include/asm/sysreg.h.
90+
91+
92+
Userspace access
93+
----------------
94+
95+
Currently, access from userspace to the AMU registers is disabled due to:
96+
- Security reasons: they might expose information about code executed in
97+
secure mode.
98+
- Purpose: AMU counters are intended for system management use.
99+
100+
Also, the presence of the feature is not visible to userspace.
101+
102+
103+
Virtualization
104+
--------------
105+
106+
Currently, access from userspace (EL0) and kernelspace (EL1) on the KVM
107+
guest side is disabled due to:
108+
- Security reasons: they might expose information about code executed
109+
by other guests or the host.
110+
111+
Any attempt to access the AMU registers will result in an UNDEFINED
112+
exception being injected into the guest.

Documentation/arm64/booting.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,20 @@ Before jumping into the kernel, the following conditions must be met:
248248
- HCR_EL2.APK (bit 40) must be initialised to 0b1
249249
- HCR_EL2.API (bit 41) must be initialised to 0b1
250250

251+
For CPUs with Activity Monitors Unit v1 (AMUv1) extension present:
252+
- If EL3 is present:
253+
CPTR_EL3.TAM (bit 30) must be initialised to 0b0
254+
CPTR_EL2.TAM (bit 30) must be initialised to 0b0
255+
AMCNTENSET0_EL0 must be initialised to 0b1111
256+
AMCNTENSET1_EL0 must be initialised to a platform specific value
257+
having 0b1 set for the corresponding bit for each of the auxiliary
258+
counters present.
259+
- If the kernel is entered at EL1:
260+
AMCNTENSET0_EL0 must be initialised to 0b1111
261+
AMCNTENSET1_EL0 must be initialised to a platform specific value
262+
having 0b1 set for the corresponding bit for each of the auxiliary
263+
counters present.
264+
251265
The requirements described above for CPU mode, caches, MMUs, architected
252266
timers, coherency and system registers apply to all CPUs. All CPUs must
253267
enter the kernel in the same exception level.

Documentation/arm64/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ARM64 Architecture
66
:maxdepth: 1
77

88
acpi_object_usage
9+
amu
910
arm-acpi
1011
booting
1112
cpu-feature-registers

arch/arm64/Kconfig

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ config ARM64
117117
select HAVE_ALIGNED_STRUCT_PAGE if SLUB
118118
select HAVE_ARCH_AUDITSYSCALL
119119
select HAVE_ARCH_BITREVERSE
120+
select HAVE_ARCH_COMPILER_H
120121
select HAVE_ARCH_HUGE_VMAP
121122
select HAVE_ARCH_JUMP_LABEL
122123
select HAVE_ARCH_JUMP_LABEL_RELATIVE
@@ -280,6 +281,9 @@ config ZONE_DMA32
280281
config ARCH_ENABLE_MEMORY_HOTPLUG
281282
def_bool y
282283

284+
config ARCH_ENABLE_MEMORY_HOTREMOVE
285+
def_bool y
286+
283287
config SMP
284288
def_bool y
285289

@@ -951,11 +955,11 @@ config HOTPLUG_CPU
951955

952956
# Common NUMA Features
953957
config NUMA
954-
bool "Numa Memory Allocation and Scheduler Support"
958+
bool "NUMA Memory Allocation and Scheduler Support"
955959
select ACPI_NUMA if ACPI
956960
select OF_NUMA
957961
help
958-
Enable NUMA (Non Uniform Memory Access) support.
962+
Enable NUMA (Non-Uniform Memory Access) support.
959963

960964
The kernel will try to allocate memory used by a CPU on the
961965
local memory of the CPU and add some more
@@ -1497,23 +1501,82 @@ config ARM64_PTR_AUTH
14971501
bool "Enable support for pointer authentication"
14981502
default y
14991503
depends on !KVM || ARM64_VHE
1504+
depends on (CC_HAS_SIGN_RETURN_ADDRESS || CC_HAS_BRANCH_PROT_PAC_RET) && AS_HAS_PAC
1505+
depends on CC_IS_GCC || (CC_IS_CLANG && AS_HAS_CFI_NEGATE_RA_STATE)
1506+
depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_REGS)
15001507
help
15011508
Pointer authentication (part of the ARMv8.3 Extensions) provides
15021509
instructions for signing and authenticating pointers against secret
15031510
keys, which can be used to mitigate Return Oriented Programming (ROP)
15041511
and other attacks.
15051512

15061513
This option enables these instructions at EL0 (i.e. for userspace).
1507-
15081514
Choosing this option will cause the kernel to initialise secret keys
15091515
for each process at exec() time, with these keys being
15101516
context-switched along with the process.
15111517

1518+
If the compiler supports the -mbranch-protection or
1519+
-msign-return-address flag (e.g. GCC 7 or later), then this option
1520+
will also cause the kernel itself to be compiled with return address
1521+
protection. In this case, and if the target hardware is known to
1522+
support pointer authentication, then CONFIG_STACKPROTECTOR can be
1523+
disabled with minimal loss of protection.
1524+
15121525
The feature is detected at runtime. If the feature is not present in
15131526
hardware it will not be advertised to userspace/KVM guest nor will it
15141527
be enabled. However, KVM guest also require VHE mode and hence
15151528
CONFIG_ARM64_VHE=y option to use this feature.
15161529

1530+
If the feature is present on the boot CPU but not on a late CPU, then
1531+
the late CPU will be parked. Also, if the boot CPU does not have
1532+
address auth and the late CPU has then the late CPU will still boot
1533+
but with the feature disabled. On such a system, this option should
1534+
not be selected.
1535+
1536+
This feature works with FUNCTION_GRAPH_TRACER option only if
1537+
DYNAMIC_FTRACE_WITH_REGS is enabled.
1538+
1539+
config CC_HAS_BRANCH_PROT_PAC_RET
1540+
# GCC 9 or later, clang 8 or later
1541+
def_bool $(cc-option,-mbranch-protection=pac-ret+leaf)
1542+
1543+
config CC_HAS_SIGN_RETURN_ADDRESS
1544+
# GCC 7, 8
1545+
def_bool $(cc-option,-msign-return-address=all)
1546+
1547+
config AS_HAS_PAC
1548+
def_bool $(as-option,-Wa$(comma)-march=armv8.3-a)
1549+
1550+
config AS_HAS_CFI_NEGATE_RA_STATE
1551+
def_bool $(as-instr,.cfi_startproc\n.cfi_negate_ra_state\n.cfi_endproc\n)
1552+
1553+
endmenu
1554+
1555+
menu "ARMv8.4 architectural features"
1556+
1557+
config ARM64_AMU_EXTN
1558+
bool "Enable support for the Activity Monitors Unit CPU extension"
1559+
default y
1560+
help
1561+
The activity monitors extension is an optional extension introduced
1562+
by the ARMv8.4 CPU architecture. This enables support for version 1
1563+
of the activity monitors architecture, AMUv1.
1564+
1565+
To enable the use of this extension on CPUs that implement it, say Y.
1566+
1567+
Note that for architectural reasons, firmware _must_ implement AMU
1568+
support when running on CPUs that present the activity monitors
1569+
extension. The required support is present in:
1570+
* Version 1.5 and later of the ARM Trusted Firmware
1571+
1572+
For kernels that have this configuration enabled but boot with broken
1573+
firmware, you may need to say N here until the firmware is fixed.
1574+
Otherwise you may experience firmware panics or lockups when
1575+
accessing the counter registers. Even if you are not observing these
1576+
symptoms, the values returned by the register reads might not
1577+
correctly reflect reality. Most commonly, the value read will be 0,
1578+
indicating that the counter is not enabled.
1579+
15171580
endmenu
15181581

15191582
menu "ARMv8.5 architectural features"

arch/arm64/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ stack_protector_prepare: prepare0
6565
include/generated/asm-offsets.h))
6666
endif
6767

68+
ifeq ($(CONFIG_ARM64_PTR_AUTH),y)
69+
branch-prot-flags-$(CONFIG_CC_HAS_SIGN_RETURN_ADDRESS) := -msign-return-address=all
70+
branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET) := -mbranch-protection=pac-ret+leaf
71+
# -march=armv8.3-a enables the non-nops instructions for PAC, to avoid the
72+
# compiler to generate them and consequently to break the single image contract
73+
# we pass it only to the assembler. This option is utilized only in case of non
74+
# integrated assemblers.
75+
branch-prot-flags-$(CONFIG_AS_HAS_PAC) += -Wa,-march=armv8.3-a
76+
KBUILD_CFLAGS += $(branch-prot-flags-y)
77+
endif
78+
6879
ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
6980
KBUILD_CPPFLAGS += -mbig-endian
7081
CHECKFLAGS += -D__AARCH64EB__

arch/arm64/crypto/aes-ce.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <linux/linkage.h>
1010
#include <asm/assembler.h>
1111

12-
#define AES_ENTRY(func) SYM_FUNC_START(ce_ ## func)
13-
#define AES_ENDPROC(func) SYM_FUNC_END(ce_ ## func)
12+
#define AES_FUNC_START(func) SYM_FUNC_START(ce_ ## func)
13+
#define AES_FUNC_END(func) SYM_FUNC_END(ce_ ## func)
1414

1515
.arch armv8-a+crypto
1616

0 commit comments

Comments
 (0)