Skip to content

Commit 1e249c4

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: unify asm-arch manipulation
Assemblers will reject instructions not supported by a target architecture version, and so we must explicitly tell the assembler the latest architecture version for which we want to assemble instructions from. We've added a few AS_HAS_ARMV8_<N> definitions for this, in addition to an inconsistently named AS_HAS_PAC definition, from which arm64's top-level Makefile determines the architecture version that we intend to target, and generates the `asm-arch` variable. To make this a bit clearer and easier to maintain, this patch reworks the Makefile to determine asm-arch in a single if-else-endif chain. AS_HAS_PAC, which is defined when the assembler supports `-march=armv8.3-a`, is renamed to AS_HAS_ARMV8_3. As the logic for armv8.3-a is lifted out of the block handling pointer authentication, `asm-arch` may now be set to armv8.3-a regardless of whether support for pointer authentication is selected. This means that it will be possible to assemble armv8.3-a instructions even if we didn't intend to, but this is consistent with our handling of other architecture versions, and the compiler won't generate armv8.3-a instructions regardless. For the moment there's no need for an CONFIG_AS_HAS_ARMV8_1, as the code for LSE atomics and LDAPR use individual `.arch_extension` entries and do not require the baseline asm arch to be bumped to armv8.1-a. The other armv8.1-a features (e.g. PAN) do not require assembler support. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Mark Brown <broonie@kernel.org> Cc: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20230131105809.991288-2-mark.rutland@arm.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent b7bfaa7 commit 1e249c4

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

arch/arm64/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ config ARM64_PTR_AUTH_KERNEL
18181818
bool "Use pointer authentication for kernel"
18191819
default y
18201820
depends on ARM64_PTR_AUTH
1821-
depends on (CC_HAS_SIGN_RETURN_ADDRESS || CC_HAS_BRANCH_PROT_PAC_RET) && AS_HAS_PAC
1821+
depends on (CC_HAS_SIGN_RETURN_ADDRESS || CC_HAS_BRANCH_PROT_PAC_RET) && AS_HAS_ARMV8_3
18221822
# Modern compilers insert a .note.gnu.property section note for PAC
18231823
# which is only understood by binutils starting with version 2.33.1.
18241824
depends on LD_IS_LLD || LD_VERSION >= 23301 || (CC_IS_GCC && GCC_VERSION < 90100)
@@ -1843,7 +1843,7 @@ config CC_HAS_SIGN_RETURN_ADDRESS
18431843
# GCC 7, 8
18441844
def_bool $(cc-option,-msign-return-address=all)
18451845

1846-
config AS_HAS_PAC
1846+
config AS_HAS_ARMV8_3
18471847
def_bool $(cc-option,-Wa$(comma)-march=armv8.3-a)
18481848

18491849
config AS_HAS_CFI_NEGATE_RA_STATE

arch/arm64/Makefile

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ stack_protector_prepare: prepare0
6363
include/generated/asm-offsets.h))
6464
endif
6565

66-
ifeq ($(CONFIG_AS_HAS_ARMV8_2), y)
67-
# make sure to pass the newest target architecture to -march.
68-
asm-arch := armv8.2-a
69-
endif
70-
7166
# Ensure that if the compiler supports branch protection we default it
7267
# off, this will be overridden if we are using branch protection.
7368
branch-prot-flags-y += $(call cc-option,-mbranch-protection=none)
@@ -88,25 +83,29 @@ branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET_BTI) := -mbranch-protectio
8883
else
8984
branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET) := -mbranch-protection=$(PACRET-y)
9085
endif
91-
# -march=armv8.3-a enables the non-nops instructions for PAC, to avoid the
92-
# compiler to generate them and consequently to break the single image contract
93-
# we pass it only to the assembler. This option is utilized only in case of non
94-
# integrated assemblers.
95-
ifeq ($(CONFIG_AS_HAS_PAC), y)
96-
asm-arch := armv8.3-a
97-
endif
9886
endif
9987

10088
KBUILD_CFLAGS += $(branch-prot-flags-y)
10189

102-
ifeq ($(CONFIG_AS_HAS_ARMV8_4), y)
103-
# make sure to pass the newest target architecture to -march.
104-
asm-arch := armv8.4-a
105-
endif
106-
90+
# Tell the assembler to support instructions from the latest target
91+
# architecture.
92+
#
93+
# For non-integrated assemblers we'll pass this on the command line, and for
94+
# integrated assemblers we'll define ARM64_ASM_ARCH and ARM64_ASM_PREAMBLE for
95+
# inline usage.
96+
#
97+
# We cannot pass the same arch flag to the compiler as this would allow it to
98+
# freely generate instructions which are not supported by earlier architecture
99+
# versions, which would prevent a single kernel image from working on earlier
100+
# hardware.
107101
ifeq ($(CONFIG_AS_HAS_ARMV8_5), y)
108-
# make sure to pass the newest target architecture to -march.
109-
asm-arch := armv8.5-a
102+
asm-arch := armv8.5-a
103+
else ifeq ($(CONFIG_AS_HAS_ARMV8_4), y)
104+
asm-arch := armv8.4-a
105+
else ifeq ($(CONFIG_AS_HAS_ARMV8_3), y)
106+
asm-arch := armv8.3-a
107+
else ifeq ($(CONFIG_AS_HAS_ARMV8_2), y)
108+
asm-arch := armv8.2-a
110109
endif
111110

112111
ifdef asm-arch

0 commit comments

Comments
 (0)