arm64/cpufeature: Add an option for mte support
Subsystems (2)
cover arm64/cpufeature: Add an option for mte support
From: Yee Lee <[email protected]>
Arm64 introduced mte to enforce memory protection but also increased the system requirements, such as the additional tag memory and the firmware control complexity. For the case of products with limited resouce or low-power environment, the requirements to support mte is unlikely reached. Hence, a solution for low-end devices is necessary.
This patch Add an option for mte support. An parameter from system is used to indicate its states for all requirements. If not, mte is disabled both in kernel and userspace.
=== Test ===
QEMU5.2 + mte
passed cmdline : "arm64_mte_not_support"
boot log:
...(skip)
[ 0.000000] CPU features: detected: Memory Tagging Extension [ 0.000000] CPU features: detected: Spectre-v2 [ 0.000000] CPU features: detected: Spectre-v4 [ 0.000000] CPU features: kernel page table isolation forced ON by KASLR [ 0.000000] CPU features: detected: Kernel page table isolation (KPTI) [ 0.000000] CPU features: MTE is disabled since system does not support.
Yee Lee (1):
arm64/cpufeature: Add option to disable mte support
arch/arm64/include/asm/cpufeature.h | 4 +++- arch/arm64/kernel/cpufeature.c | 13 +++++++++++++ arch/arm64/kernel/image-vars.h | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-)
Signature · 1 line
2.18.0
PATCH 1/1 arm64/cpufeature: Add option to disable mte support
From: Yee Lee <[email protected]>
Add a static key to exapnd the logic of system_supports_mte(). This function controls mte enablement in both EL1 and EL0.
The static key, "arm64_mte_support" is default true and can be disabled via the early_param.
--- arch/arm64/include/asm/cpufeature.h | 4 +++- arch/arm64/kernel/cpufeature.c | 13 +++++++++++++ arch/arm64/kernel/image-vars.h | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-)
arch/arm64/include/asm/cpufeature.h +3 -1
@@ -420,6 +420,7 @@ static __always_inline bool is_hyp_code(void) extern DECLARE_BITMAP(cpu_hwcaps, ARM64_NCAPS);extern struct static_key_false cpu_hwcap_keys[ARM64_NCAPS ];extern struct static_key_false arm64_const_caps_ready; +extern struct static_key_true arm64_mte_support;/* ARM64 CAPS + alternative_cb */ #define ARM64_NPATCHABLE (ARM64_NCAPS + 1)
@@ -756,7 +757,8 @@ static __always_inline bool system_uses_irq_prio_masking(void)static inline bool system_supports_mte (void ) {return IS_ENABLED (CONFIG_ARM64_MTE ) && -cpus_have_const_cap (ARM64_MTE ); +cpus_have_const_cap (ARM64_MTE ) && +static_branch_likely (&arm64_mte_support); }static inline bool system_has_prio_mask_debugging (void )
arch/arm64/kernel/cpufeature.c +13 -0
@@ -1840,9 +1840,22 @@ static void bti_enable(const struct arm64_cpu_capabilities *__unused) }#endif /* CONFIG_ARM64_BTI */ +DEFINE_STATIC_KEY_TRUE (arm64_mte_support); +EXPORT_SYMBOL (arm64_mte_support);#ifdef CONFIG_ARM64_MTE +static int __init disable_arm64_mte_support (char *str) +{ +static_branch_disable (&arm64_mte_support); +return 0 ; +} +early_param ("arm64_mte_not_support" , disable_arm64_mte_support); +static void cpu_enable_mte (struct arm64_cpu_capabilities const *cap) { +if (!system_supports_mte ()){ +pr_info ("MTE is disabled since system does not support.\n" ); +return ; + }/* * Clear the tags in the zero page. This needs to be done via the * linear map which has the Tagged attribute.
arch/arm64/kernel/image-vars.h +3 -0
@@ -83,6 +83,9 @@ KVM_NVHE_ALIAS(__icache_flags);KVM_NVHE_ALIAS (arm64_const_caps_ready);KVM_NVHE_ALIAS (cpu_hwcap_keys); +/* Static key which indicates if system supports mte */ +KVM_NVHE_ALIAS (arm64_mte_support); +/* Static keys which are set if a vGIC trap should be handled in hyp. */ KVM_NVHE_ALIAS (vgic_v2_cpuif_trap);KVM_NVHE_ALIAS (vgic_v3_cpuif_trap);
Signature · 1 line
2.18.0
Re: [PATCH 1/1] arm64/cpufeature: Add option to disable mte support
Quoted 7 lines · On 28/07/2021 10:42, [email protected] wrote:
From: Yee Lee <[email protected]>
Add a static key to exapnd the logic of
system_supports_mte(). This function controls mte enablement in both EL1 and EL0.The static key, "
arm64_mte_support" is default true and can be disabled via theearly_param.
Please could we use the id-reg override mechanism and give it an alias ?
See :
arch/arm64/kernel/idreg-override.c
And could add something along the lines of :
arm64.nomte
Cheers
Suzuki
Re: [PATCH 1/1] arm64/cpufeature: Add option to disable mte support
In reply to [email protected]Quoted 9 lines · On Wed, 28 Jul 2021 10:42:58 +0100, <[email protected]> wrote:
From: Yee Lee <[email protected]>
Add a static key to exapnd the logic of
system_supports_mte(). This function controls mte enablement in both EL1 and EL0.The static key, "
arm64_mte_support" is default true and can be disabled via theearly_param.
Quoted 6 lines
Signed-off-by Yee Lee <[email protected]>--- arch/arm64/include/asm/cpufeature.h | 4 +++- arch/arm64/kernel/cpufeature.c | 13 +++++++++++++ arch/arm64/kernel/image-vars.h | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-)
This seems terribly complicated. How about this instead ("arm64.nomte" on the command line)?
Thanks,
M.
arch/arm64/kernel/idreg-override.c +2 -0
@@ -54,6 +54,7 @@ static const struct ftr_set_desc pfr1 __initconst = { .override = &id_aa64pfr1_override, .fields = { { "bt", ID_AA64PFR1_BT_SHIFT }, + { "mte", ID_AA64PFR1_MTE_SHIFT }, {} }, };
@@ -100,6 +101,7 @@ static const struct { {"arm64.nopauth" ,"id_aa64isar1.gpi=0 id_aa64isar1.gpa=0 " "id_aa64isar1.api=0 id_aa64isar1.apa=0" }, + { "arm64.nomte", "id_aa64pfr1.mte=0" }, { "nokaslr", "kaslr.disabled=1" }, };
Signature · 6 lines
Without deviation from the norm, progress is not possible. _______________________________________________ Linux-mediatek mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-mediatek
Re: [PATCH 1/1] arm64/cpufeature: Add option to disable mte support
In reply to Suzuki K PouloseQuoted 13 lines · Suzuki K Poulose
Quoted 7 lines · On 28/07/2021 10:42, [email protected] wrote:
From: Yee Lee <[email protected]>
Add a static key to exapnd the logic of
system_supports_mte(). This function controls mte enablement in both EL1 and EL0.The static key, "
arm64_mte_support" is default true and can be disabled via theearly_param.Please could we use the id-reg override mechanism and give it an alias ?
Quoted 7 lines
See :
arch/arm64/kernel/idreg-override.cAnd could add something along the lines of :
arm64.nomte
Damn, you beat me to it! :D
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.