arm64: E0PD support
cover arm64: E0PD support
This series adds support for E0PD. We enable E0PD unconditionally where present and on systems where all the CPUs in the system support E0PD we will not automatically enable KPTI for KASLR. The integration with KPTI is safe but not optimal for big.LITTLE systems where only some CPUs support E0PD since for them it will still use KPTI even on the CPUs that have E0PD, I've not yet come up with something I like for integrating support for them with the command line overrides.
arm64: Add initial support for E0PD
arm64: Don't use KPTI where we have E0PD
arch/arm64/Kconfig | 14 ++++++++++++++ arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/include/asm/pgtable-hwdef.h | 2 ++ arch/arm64/include/asm/sysreg.h | 1 + arch/arm64/kernel/cpufeature.c | 29 ++++++++++++++++++++++++++++- 5 files changed, 47 insertions(+), 2 deletions(-)
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 1/2 arm64: Add initial support for E0PD
Kernel Page Table Isolation (KPTI) is used to mitigate some speculation based security issues by ensuring that the kernel is not mapped when userspace is running but this approach is expensive and is incompatible with SPE. E0PD, introduced in the ARMv8.5 extensions, provides an alternative to this which ensures that accesses from userspace to the kernel's half of the memory map to always fault with constant time, preventing timing attacks without requiring constant unmapping and remapping or preventing legitimate accesses.
This initial patch does not yet integrate with KPTI, this will be dealt with in followup patches. Ideally we could ensure that by default we don't use KPTI on CPUs where E0PD is present.
--- arch/arm64/Kconfig | 14 +++++++++++++ arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/include/asm/pgtable-hwdef.h | 2 ++ arch/arm64/include/asm/sysreg.h | 1 + arch/arm64/kernel/cpufeature.c | 27 ++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +14 -0
@@ -1409,6 +1409,20 @@ config ARM64_PTR_AUTH endmenu +menu "ARMv8.5 architectural features" + +config ARM64_E0PD + bool "Enable support for E0PD" + default y + help + E0PD (part of the ARMv8.5 extensions) ensures that EL0 + accesses made via TTBR1 always fault in constant time, + providing the same guarantees as KPTI with lower overhead. + + This option enables E0PD where available. + +endmenu + config ARM64_SVE bool "ARM Scalable Vector Extension support" default y
arch/arm64/include/asm/cpucaps.h +2 -1
@@ -52,7 +52,8 @@#define ARM64_HAS_IRQ_PRIO_MASKING 42#define ARM64_HAS_DCPODP 43#define ARM64_WORKAROUND_1463225 44 +#define ARM64_HAS_E0PD 45 -#define ARM64_NCAPS 45 +#define ARM64_NCAPS 46#endif /* __ASM_CPUCAPS_H */
arch/arm64/include/asm/pgtable-hwdef.h +2 -0
@@ -292,6 +292,8 @@#define TCR_HD (UL(1) << 40)#define TCR_NFD0 (UL(1) << 53)#define TCR_NFD1 (UL(1) << 54) +#define TCR_E0PD0 (UL(1) << 55) +#define TCR_E0PD1 (UL(1) << 56)/* * TTBR.
arch/arm64/include/asm/sysreg.h +1 -0
@@ -652,6 +652,7 @@#define ID_AA64MMFR1_VMIDBITS_16 2/* id_aa64mmfr2 */ +#define ID_AA64MMFR2_E0PD_SHIFT 60#define ID_AA64MMFR2_FWB_SHIFT 40#define ID_AA64MMFR2_AT_SHIFT 32#define ID_AA64MMFR2_LVA_SHIFT 16
arch/arm64/kernel/cpufeature.c +27 -0
@@ -211,6 +211,7 @@ static const struct arm64_ftr_bits ftr_id_aa64mmfr1[] = { };static const struct arm64_ftr_bits ftr_id_aa64mmfr2[] = { +ARM64_FTR_BITS (FTR_HIDDEN ,FTR_NONSTRICT ,FTR_LOWER_SAFE ,ID_AA64MMFR2_E0PD_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_HIDDEN ,FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64MMFR2_FWB_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_VISIBLE ,FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64MMFR2_AT_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_HIDDEN ,FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64MMFR2_LVA_SHIFT ,4 ,0 ),
@@ -1236,6 +1237,19 @@ static void cpu_enable_address_auth(struct arm64_cpu_capabilities const *cap) }#endif /* CONFIG_ARM64_PTR_AUTH */ +#ifdef CONFIG_ARM64_E0PD +static void cpu_enable_e0pd (struct arm64_cpu_capabilities const *cap) +{ +/* +* The cpu_enable() callback gets called even on CPUs that +* don't detect the feature so we need to verify if we can +* enable. +*/ +if (this_cpu_has_cap (ARM64_HAS_E0PD )) +sysreg_clear_set (tcr_el1,0 ,TCR_E0PD1 ); +} +#endif /* CONFIG_ARM64_E0PD */ +#ifdef CONFIG_ARM64_PSEUDO_NMI static bool enable_pseudo_nmi;
@@ -1551,6 +1565,19 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .sign = FTR_UNSIGNED, .min_field_value = 1, }, +#endif +#ifdef CONFIG_ARM64_E0PD + { + .desc = "E0PD", + .capability = ARM64_HAS_E0PD, + .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE, + .sys_reg = SYS_ID_AA64MMFR2_EL1, + .sign = FTR_UNSIGNED, + .field_pos = ID_AA64MMFR2_E0PD_SHIFT, + .matches = has_cpuid_feature, + .min_field_value = 1, + .cpu_enable = cpu_enable_e0pd, + }, #endif {}, };
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 1/2] arm64: Add initial support for E0PD
Quoted 13 lines · Mark Brown
Kernel Page Table Isolation (KPTI) is used to mitigate some speculation based security issues by ensuring that the kernel is not mapped when userspace is running but this approach is expensive and is incompatible with SPE. E0PD, introduced in the ARMv8.5 extensions, provides an alternative to this which ensures that accesses from userspace to the kernel's half of the memory map to always fault with constant time, preventing timing attacks without requiring constant unmapping and remapping or preventing legitimate accesses.
This initial patch does not yet integrate with KPTI, this will be dealt with in followup patches. Ideally we could ensure that by default we don't use KPTI on CPUs where E0PD is present.
Quoted 9 lines
Signed-off-by Mark Brown <[email protected]>--- arch/arm64/Kconfig | 14 +++++++++++++ arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/include/asm/pgtable-hwdef.h | 2 ++ arch/arm64/include/asm/sysreg.h | 1 + arch/arm64/kernel/cpufeature.c | 27 ++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-)
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerRe: [PATCH 1/2] arm64: Add initial support for E0PD
In reply to Mark BrownQuoted 29 lines · Mark Brown
Kernel Page Table Isolation (KPTI) is used to mitigate some speculation based security issues by ensuring that the kernel is not mapped when userspace is running but this approach is expensive and is incompatible with SPE. E0PD, introduced in the ARMv8.5 extensions, provides an alternative to this which ensures that accesses from userspace to the kernel's half of the memory map to always fault with constant time, preventing timing attacks without requiring constant unmapping and remapping or preventing legitimate accesses.
This initial patch does not yet integrate with KPTI, this will be dealt with in followup patches. Ideally we could ensure that by default we don't use KPTI on CPUs where E0PD is present.
Signed-off-by Mark Brown <[email protected]>--- arch/arm64/Kconfig | 14 +++++++++++++ arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/include/asm/pgtable-hwdef.h | 2 ++ arch/arm64/include/asm/sysreg.h | 1 + arch/arm64/kernel/cpufeature.c | 27 ++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-)arch/arm64/Kconfig +0
-0@@ -1409,6 +1409,20 @@ config ARM64_PTR_AUTH endmenu
arch/arm64/Kconfig config ARM64_PTR_AUTH · line 1420
Quoted 10 lines
arch/arm64/Kconfig +9
-0+menu "ARMv8.5 architectural features" + +config ARM64_E0PD + bool "Enable support for E0PD" + default y + help + E0PD (part of the ARMv8.5 extensions) ensures that EL0 + accesses made via TTBR1 always fault in constant time, + providing the same guarantees as KPTI with lower overhead.
This could do with a slight tweak, since there are two E0PD bits in the TCR, which apply to TTBR0 and TTBR1 separately. I'd also be reluctant to state that it provides the /same/ guarantees as kpti, since I don't think it will cause a translation fault.
It's probably also worth mentioning that, unlike kpti, E0PDx doesn't break profiling with SPE.
arch/arm64/Kconfig config ARM64_PTR_AUTH · line 1422
Quoted 1 line
arch/arm64/Kconfig +1
-0+ This option enables E0PD where available.
For TTBR1.
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 2/2 arm64: Don't use KPTI where we have E0PD
In reply to Mark BrownSince E0PD is intended to fulfil the same role as KPTI we don't need to use KPTI on CPUs where E0PD is available, we can rely on E0PD instead. Change the check that forces KPTI on when KASLR is enabled to check for E0PD before doing so, CPUs with E0PD are not expected to be affected by meltdown so should not need to enable KPTI for other reasons.
Since we repeat the KPTI check for all CPUs we will still enable KPTI if any of the CPUs in the system lacks E0PD. Since KPTI itself is not changed by this patch once we enable KPTI we will do so for all CPUs. This is safe but not optimally performant for such systems.
KPTI can still be forced on from the command line if required.
--- arch/arm64/kernel/cpufeature.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/cpufeature.c +1 -1
@@ -995,7 +995,7 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry,/* Useful for KASLR robustness */ if (IS_ENABLED (CONFIG_RANDOMIZE_BASE ) &&kaslr_offset () >0 ) { -if (!__kpti_forced) { +if (!__kpti_forced && !this_cpu_has_cap (ARM64_HAS_E0PD )) { str ="KASLR" ; __kpti_forced =1 ; }
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 2/2] arm64: Don't use KPTI where we have E0PD
Quoted 23 lines · Mark Brown
Since E0PD is intended to fulfil the same role as KPTI we don't need to use KPTI on CPUs where E0PD is available, we can rely on E0PD instead. Change the check that forces KPTI on when KASLR is enabled to check for E0PD before doing so, CPUs with E0PD are not expected to be affected by meltdown so should not need to enable KPTI for other reasons.
Since we repeat the KPTI check for all CPUs we will still enable KPTI if any of the CPUs in the system lacks E0PD. Since KPTI itself is not changed by this patch once we enable KPTI we will do so for all CPUs. This is safe but not optimally performant for such systems.
KPTI can still be forced on from the command line if required.
Signed-off-by Mark Brown <[email protected]>--- arch/arm64/kernel/cpufeature.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kernel/cpufeature.c +0
-0
arch/arm64/kernel/cpufeature.c static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, · line 1001
Quoted 8 lines
arch/arm64/kernel/cpufeature.c +1
-1@@ -995,7 +995,7 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry,/* Useful for KASLR robustness */ if (IS_ENABLED (CONFIG_RANDOMIZE_BASE ) &&kaslr_offset () >0 ) { -if (!__kpti_forced) { +if (!__kpti_forced && !this_cpu_has_cap (ARM64_HAS_E0PD )) { str ="KASLR" ; __kpti_forced =1 ; }
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerRe: [PATCH 2/2] arm64: Don't use KPTI where we have E0PD
In reply to Mark BrownQuoted 23 lines · Mark Brown
Since E0PD is intended to fulfil the same role as KPTI we don't need to use KPTI on CPUs where E0PD is available, we can rely on E0PD instead. Change the check that forces KPTI on when KASLR is enabled to check for E0PD before doing so, CPUs with E0PD are not expected to be affected by meltdown so should not need to enable KPTI for other reasons.
Since we repeat the KPTI check for all CPUs we will still enable KPTI if any of the CPUs in the system lacks E0PD. Since KPTI itself is not changed by this patch once we enable KPTI we will do so for all CPUs. This is safe but not optimally performant for such systems.
KPTI can still be forced on from the command line if required.
Signed-off-by Mark Brown <[email protected]>--- arch/arm64/kernel/cpufeature.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kernel/cpufeature.c +0
-0
arch/arm64/kernel/cpufeature.c static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, · line 1001
Quoted 8 lines
arch/arm64/kernel/cpufeature.c +1
-1@@ -995,7 +995,7 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry,/* Useful for KASLR robustness */ if (IS_ENABLED (CONFIG_RANDOMIZE_BASE ) &&kaslr_offset () >0 ) { -if (!__kpti_forced) { +if (!__kpti_forced && !this_cpu_has_cap (ARM64_HAS_E0PD )) { str ="KASLR" ; __kpti_forced =1 ; }
Hmm. I'm surprised you haven't had to hack arm64_kernel_use_ng_mappings().
If you boot with RANDOMIZE_BASE=y on a machine with E0PDx support, can you dump the kernel page tables in /sys/kernel/debug/kernel_page_tables and check that they're using global mappings? I think some of the early mappings might still be nG with your patch.
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 2/2] arm64: Don't use KPTI where we have E0PD
Quoted 11 lines · Will Deacon
arch/arm64/kernel/cpufeature.c static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, · line 1001
Quoted 6 lines · Mark Brown
arch/arm64/kernel/cpufeature.c +1
-1if (IS_ENABLED (CONFIG_RANDOMIZE_BASE ) &&kaslr_offset () >0 ) { -if (!__kpti_forced) { +if (!__kpti_forced && !this_cpu_has_cap (ARM64_HAS_E0PD )) { str ="KASLR" ; __kpti_forced =1 ; }Hmm. I'm surprised you haven't had to hack
arm64_kernel_use_ng_mappings().
Quoted 4 lines
If you boot with RANDOMIZE_BASE=y on a machine with E0PDx support, can you dump the kernel page tables in
/sys/kernel/debug/kernel_page_tablesand check that they're using global mappings? I think some of the early mappings might still be nG with your patch.
Hrm, yeah - they are if I not only turn on RANDOMIZE_BASE but also ensure KASLR gets a seed it'll pay attention to passed. I had been testing with it on but changes I'd made in the test environment to pass a seed in had been broken so it silently wasn't actually doing anything. The simplest thing would just be to add an IS_ENABLED() check in _use_ng_mappings() which I've verifed does the right thing at the expense of requiring the remapping later, but obviously that's a useful optimization so we should really check the FTR.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel