[RFC PATCH v1 51/57] arm64: Introduce cpu features for page sizes

Ryan Roberts
2024-10-14T12:35:58Z

Introduce one boot cpu feature per page size, ARM64_USE_PAGE_SIZE_*K.
These will enable use of the alternatives framework to patch code based
on the page size selected at boot.

Additionally, this provides a neat way to figure out what page size is
in use during boot from the kernel log.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---

***NOTE***
Any confused maintainers may want to read the cover note here for context:
https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/

arch/arm64/kernel/cpufeature.c | 25 +++++++++++++++++++++++++
arch/arm64/tools/cpucaps | 3 +++
2 files changed, 28 insertions(+)

diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 7705c9c0e7142..e5618423bb99d 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -1831,6 +1831,13 @@ static bool has_nv1(const struct arm64_cpu_capabilities *entry, int scope)
is_midr_in_range_list(read_cpuid_id(), nv1_ni_list)));
}

+static bool use_page_size(const struct arm64_cpu_capabilities *entry, int scope)
+{
+ return (entry->capability == ARM64_USE_PAGE_SIZE_4K && PAGE_SIZE == SZ_4K) ||
+ (entry->capability == ARM64_USE_PAGE_SIZE_16K && PAGE_SIZE == SZ_16K) ||
+ (entry->capability == ARM64_USE_PAGE_SIZE_64K && PAGE_SIZE == SZ_64K);
+}
+
static bool has_lpa2_at_stage1(u64 mmfr0)
{
unsigned int tgran;
@@ -2881,6 +2888,24 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
.matches = has_nv1,
ARM64_CPUID_FIELDS_NEG(ID_AA64MMFR4_EL1, E2H0, NI_NV1)
},
+ {
+ .desc = "4K page size",
+ .capability = ARM64_USE_PAGE_SIZE_4K,
+ .type = ARM64_CPUCAP_BOOT_CPU_FEATURE,
+ .matches = use_page_size,
+ },
+ {
+ .desc = "16K page size",
+ .capability = ARM64_USE_PAGE_SIZE_16K,
+ .type = ARM64_CPUCAP_BOOT_CPU_FEATURE,
+ .matches = use_page_size,
+ },
+ {
+ .desc = "64K page size",
+ .capability = ARM64_USE_PAGE_SIZE_64K,
+ .type = ARM64_CPUCAP_BOOT_CPU_FEATURE,
+ .matches = use_page_size,
+ },
{},
};

diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps
index ac3429d892b9a..5cb75675303c6 100644
--- a/arch/arm64/tools/cpucaps
+++ b/arch/arm64/tools/cpucaps
@@ -71,6 +71,9 @@ SPECTRE_BHB
SSBS
SVE
UNMAP_KERNEL_AT_EL0
+USE_PAGE_SIZE_4K
+USE_PAGE_SIZE_16K
+USE_PAGE_SIZE_64K
WORKAROUND_834220
WORKAROUND_843419
WORKAROUND_845719
--
2.43.0