From 407390d1ce57f037d6575f4ae6a73a9d355b2388 Mon Sep 17 00:00:00 2001 From: Zeng Heng Date: Sat, 1 Jun 2024 14:38:28 +0800 Subject: [PATCH 1/2] arm64: cpufeature: Both the major and the minor version numbers need to be checked hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I92AK4 ----------------------------- Both the major version number and the minor version numbers need to be checked to confirm whether the MPAM Extension is supported on the platform. This supports MPAM v0.1 version for cpufeature detection, check [1] for details. [1] https://developer.arm.com/documentation/ddi0595/2021-12/AArch64- Registers/ID-AA64PFR1-EL1--AArch64-Processor-Feature-Register-1?lang=en Fixes: 21771eaaf93a ("arm64: cpufeature: discover CPU support for MPAM") Signed-off-by: Zeng Heng --- arch/arm64/include/asm/cpufeature.h | 7 +++++++ arch/arm64/kernel/cpufeature.c | 13 +++++++++---- arch/arm64/kernel/cpuinfo.c | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 450124238563..2af4c7ad7dc5 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -626,6 +626,13 @@ static inline bool id_aa64pfr0_mpam(u64 pfr0) return val > 0; } +static inline bool id_aa64pfr1_mpamfrac(u64 pfr1) +{ + u32 val = cpuid_feature_extract_unsigned_field(pfr1, ID_AA64PFR1_EL1_MPAM_frac_SHIFT); + + return val > 0; +} + static inline bool id_aa64pfr1_mte(u64 pfr1) { u32 val = cpuid_feature_extract_unsigned_field(pfr1, ID_AA64PFR1_EL1_MTE_SHIFT); diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index ba40892cc002..f94bc6eb83e0 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1078,7 +1078,8 @@ void __init init_cpu_features(struct cpuinfo_arm64 *info) vec_init_vq_map(ARM64_VEC_SME); } - if (id_aa64pfr0_mpam(info->reg_id_aa64pfr0)) + if (id_aa64pfr0_mpam(info->reg_id_aa64pfr0) || + id_aa64pfr1_mpamfrac(info->reg_id_aa64pfr1)) init_cpu_ftr_reg(SYS_MPAMIDR_EL1, info->reg_mpamidr); if (id_aa64pfr1_mte(info->reg_id_aa64pfr1)) @@ -1340,7 +1341,8 @@ void update_cpu_features(int cpu, vec_update_vq_map(ARM64_VEC_SME); } - if (id_aa64pfr0_mpam(info->reg_id_aa64pfr0)) { + if (id_aa64pfr0_mpam(info->reg_id_aa64pfr0) || + id_aa64pfr1_mpamfrac(info->reg_id_aa64pfr1)) { taint |= check_update_ftr_reg(SYS_MPAMIDR_EL1, cpu, info->reg_mpamidr, boot->reg_mpamidr); } @@ -2308,7 +2310,11 @@ cpucap_panic_on_conflict(const struct arm64_cpu_capabilities *cap) static bool __maybe_unused test_has_mpam(const struct arm64_cpu_capabilities *entry, int scope) { - if (!has_cpuid_feature(entry, scope)) + u64 pfr0 = read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1); + u64 pfr1 = read_sanitised_ftr_reg(SYS_ID_AA64PFR1_EL1); + + if (!id_aa64pfr0_mpam(pfr0) && + !id_aa64pfr1_mpamfrac(pfr1)) return false; /* Check firmware actually enabled MPAM on this cpu. */ @@ -2844,7 +2850,6 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .capability = ARM64_MPAM, .matches = test_has_mpam, .cpu_enable = cpu_enable_mpam, - ARM64_CPUID_FIELDS(ID_AA64PFR0_EL1, MPAM, 1) }, #endif #ifdef CONFIG_ARM64_TWED diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c index eecedf5b67fa..5ad8d8697d56 100644 --- a/arch/arm64/kernel/cpuinfo.c +++ b/arch/arm64/kernel/cpuinfo.c @@ -461,7 +461,8 @@ static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info) __cpuinfo_store_cpu_32bit(&info->aarch32); if (IS_ENABLED(CONFIG_ARM64_MPAM) && - id_aa64pfr0_mpam(info->reg_id_aa64pfr0)) + (id_aa64pfr0_mpam(info->reg_id_aa64pfr0) || + id_aa64pfr1_mpamfrac(info->reg_id_aa64pfr1))) info->reg_mpamidr = read_cpuid(MPAMIDR_EL1); cpuinfo_detect_icache_policy(info); -- Gitee From fc1c5dc839caad26d1b119d3eb5a9044a000b72d Mon Sep 17 00:00:00 2001 From: Zeng Heng Date: Sat, 1 Jun 2024 14:38:29 +0800 Subject: [PATCH 2/2] arm64/mpam: skip mpam initialize under kdump kernel hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I92AK4 ----------------------------- Skip MPAM initialize when running under kdump kernel. We put the judgement at the front of MPAM initialization to avoid meaningless initialization as much as possible. Fixes: 9cb26074545b ("arm_mpam: Probe MSCs to find the supported partid/pmg values") Signed-off-by: Zeng Heng --- arch/arm64/kernel/mpam.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/kernel/mpam.c b/arch/arm64/kernel/mpam.c index 02f43334f078..8fd9dbdc2b01 100644 --- a/arch/arm64/kernel/mpam.c +++ b/arch/arm64/kernel/mpam.c @@ -6,6 +6,7 @@ #include #include #include +#include DEFINE_STATIC_KEY_FALSE(arm64_mpam_has_hcr); DEFINE_STATIC_KEY_FALSE(mpam_enabled); @@ -14,6 +15,9 @@ DEFINE_PER_CPU(u64, arm64_mpam_current); static int __init arm64_mpam_register_cpus(void) { + if (is_kdump_kernel()) + return 0; + u64 mpamidr = read_sanitised_ftr_reg(SYS_MPAMIDR_EL1); u16 partid_max = FIELD_GET(MPAMIDR_PARTID_MAX, mpamidr); u8 pmg_max = FIELD_GET(MPAMIDR_PMG_MAX, mpamidr); -- Gitee