Skip to contentSkip to conversation

arm64: Avoid enabling KPTI unnecessarily

PATCH Superseded Ard Biesheuvel 4 participants 4 messages Nov 27, 2023 arm64

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: Avoid enabling KPTI unnecessarily

From: Ard Biesheuvel <[email protected]>

Commit 42c5a3b04bf6 refactored the KPTI init code in a way that results in the use of non-global kernel mappings even on systems that have no need for it, and even when KPTI has been disabled explicitly via the command line.

Ensure that this only happens when we have decided (based on the detected CPU features) that KPTI should be enabled.

Fixes 42c5a3b04bf6 ("arm64: Split kpti_install_ng_mappings()")
---
 arch/arm64/kernel/cpufeature.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/cpufeature.c +2 -1
index 646591c67e7a..4b1762b9c37c 100644
@@ -3352,7 +3352,8 @@ void __init setup_system_features(void)
 	 */
 	enable_cpu_capabilities(SCOPE_ALL & ~SCOPE_BOOT_CPU);
 
-	kpti_install_ng_mappings();
+	if (arm64_kernel_unmapped_at_el0())
+		kpti_install_ng_mappings();
 
 	sve_setup();
 	sme_setup();
Signature · 7 lines
2.39.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 22 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

Commit 42c5a3b04bf6 refactored the KPTI init code in a way that results in the use of non-global kernel mappings even on systems that have no need for it, and even when KPTI has been disabled explicitly via the command line.

Ensure that this only happens when we have decided (based on the detected CPU features) that KPTI should be enabled.

Fixes 42c5a3b04bf6 ("arm64: Split kpti_install_ng_mappings()")
---
 arch/arm64/kernel/cpufeature.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/cpufeature.c +0 -0
index 646591c67e7a..4b1762b9c37c 100644

arch/arm64/kernel/cpufeature.c void __init setup_system_features(void) · line 3359

Quoted 9 lines
arch/arm64/kernel/cpufeature.c +2 -1
@@ -3352,7 +3352,8 @@ void __init setup_system_features(void)
 	 */
 	enable_cpu_capabilities(SCOPE_ALL & ~SCOPE_BOOT_CPU);
 
-	kpti_install_ng_mappings();
+	if (arm64_kernel_unmapped_at_el0())
+		kpti_install_ng_mappings();
 
 	sve_setup();
 	sme_setup();
	M.
Signature · 6 lines
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#2 lore raw
Quoted 32 lines · Marc Zyngier
Quoted 29 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

Commit 42c5a3b04bf6 refactored the KPTI init code in a way that results in the use of non-global kernel mappings even on systems that have no need for it, and even when KPTI has been disabled explicitly via the command line.

Ensure that this only happens when we have decided (based on the detected CPU features) that KPTI should be enabled.

Fixes 42c5a3b04bf6 ("arm64: Split kpti_install_ng_mappings()")
---
 arch/arm64/kernel/cpufeature.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/cpufeature.c +2 -1
index 646591c67e7a..4b1762b9c37c 100644
@@ -3352,7 +3352,8 @@ void __init setup_system_features(void)
       */
      enable_cpu_capabilities(SCOPE_ALL & ~SCOPE_BOOT_CPU);
 
-     kpti_install_ng_mappings();
+     if (arm64_kernel_unmapped_at_el0())
+             kpti_install_ng_mappings();
 
Quoted 6 lines

arch/arm64/kernel/cpufeature.c void __init setup_system_features(void) · line 3359

Quoted 2 lines
arch/arm64/kernel/cpufeature.c +0 -0
      sve_setup();
      sme_setup();

Bah now kpti=on is broken ...

Will respin,

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

reviewer
#3 lore raw
In reply to Ard Biesheuvel

Hi Ard,

Quoted 21 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

Commit 42c5a3b04bf6 refactored the KPTI init code in a way that results in the use of non-global kernel mappings even on systems that have no need for it, and even when KPTI has been disabled explicitly via the command line.

Ensure that this only happens when we have decided (based on the detected CPU features) that KPTI should be enabled.

Fixes 42c5a3b04bf6 ("arm64: Split kpti_install_ng_mappings()")
---
 arch/arm64/kernel/cpufeature.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/cpufeature.c +0 -0
index 646591c67e7a..4b1762b9c37c 100644

arch/arm64/kernel/cpufeature.c void __init setup_system_features(void) · line 3356

Quoted 6 lines
arch/arm64/kernel/cpufeature.c +2 -1
@@ -3352,7 +3352,8 @@ void __init setup_system_features(void)
 	 */
 	enable_cpu_capabilities(SCOPE_ALL & ~SCOPE_BOOT_CPU);
 
-	kpti_install_ng_mappings();
+	if (arm64_kernel_unmapped_at_el0())
+		kpti_install_ng_mappings();

My bad; I had intended that kpti_install_ng_mappings() checked everything necessary, but clearly I missed this.

Modulo breakage, could we move the conditionality into kpti_install_ng_mappings()?

Thanks,
Mark.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel