Skip to contentSkip to conversation

powerpc/64s: support nospectre_v2 cmdline option

PATCH Applied Christopher M. Riedl 3 participants 4 messages May 24, 2019 – Aug 28, 2019 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 powerpc/64s: support nospectre_v2 cmdline option

Add support for disabling the kernel implemented spectre v2 mitigation (count cache flush on context switch) via the nospectre_v2 and mitigations=off cmdline options.

---
v4->v5:
Fix checkpatch complaint

 arch/powerpc/kernel/security.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
arch/powerpc/kernel/security.c +16 -3
index e1c9cf079503..7cfcb294b11c 100644
@@ -28,7 +28,7 @@ static enum count_cache_flush_type count_cache_flush_type = COUNT_CACHE_FLUSH_NO
 bool barrier_nospec_enabled;
 static bool no_nospec;
 static bool btb_flush_enabled;
-#ifdef CONFIG_PPC_FSL_BOOK3E
+#if defined(CONFIG_PPC_FSL_BOOK3E) || defined(CONFIG_PPC_BOOK3S_64)
 static bool no_spectrev2;
 #endif
 
@@ -114,7 +114,7 @@ static __init int security_feature_debugfs_init(void)
 device_initcall(security_feature_debugfs_init);
 #endif /* CONFIG_DEBUG_FS */
 
-#ifdef CONFIG_PPC_FSL_BOOK3E
+#if defined(CONFIG_PPC_FSL_BOOK3E) || defined(CONFIG_PPC_BOOK3S_64)
 static int __init handle_nospectre_v2(char *p)
 {
 	no_spectrev2 = true;
@@ -122,6 +122,9 @@ static int __init handle_nospectre_v2(char *p)
 	return 0;
 }
 early_param("nospectre_v2", handle_nospectre_v2);
+#endif /* CONFIG_PPC_FSL_BOOK3E || CONFIG_PPC_BOOK3S_64 */
+
+#ifdef CONFIG_PPC_FSL_BOOK3E
 void setup_spectre_v2(void)
 {
 	if (no_spectrev2 || cpu_mitigations_off())
@@ -399,7 +402,17 @@ static void toggle_count_cache_flush(bool enable)
 
 void setup_count_cache_flush(void)
 {
-	toggle_count_cache_flush(true);
+	bool enable = true;
+
+	if (no_spectrev2 || cpu_mitigations_off()) {
+		if (security_ftr_enabled(SEC_FTR_BCCTRL_SERIALISED) ||
+		    security_ftr_enabled(SEC_FTR_COUNT_CACHE_DISABLED))
+			pr_warn("Spectre v2 mitigations not under software control, can't disable\n");
+
+		enable = false;
+	}
+
+	toggle_count_cache_flush(enable);
 }
 
 #ifdef CONFIG_DEBUG_FS
Signature · 1 line
2.21.0
#1 lore raw
Quoted 7 lines · Christopher M. Riedl

Add support for disabling the kernel implemented spectre v2 mitigation (count cache flush on context switch) via the nospectre_v2 and mitigations=off cmdline options.

snowpatch is whinging about this breaking the build for some reason... https://patchwork.ozlabs.org/patch/1104583/

Quoted 58 lines

---
v4->v5:
Fix checkpatch complaint

  arch/powerpc/kernel/security.c | 19 ++++++++++++++++---
  1 file changed, 16 insertions(+), 3 deletions(-)
arch/powerpc/kernel/security.c +16 -3
index e1c9cf079503..7cfcb294b11c 100644
@@ -28,7 +28,7 @@ static enum count_cache_flush_type count_cache_flush_type = COUNT_CACHE_FLUSH_NO
  bool barrier_nospec_enabled;
  static bool no_nospec;
  static bool btb_flush_enabled;
-#ifdef CONFIG_PPC_FSL_BOOK3E
+#if defined(CONFIG_PPC_FSL_BOOK3E) || defined(CONFIG_PPC_BOOK3S_64)
  static bool no_spectrev2;
  #endif
 
@@ -114,7 +114,7 @@ static __init int security_feature_debugfs_init(void)
  device_initcall(security_feature_debugfs_init);
  #endif /* CONFIG_DEBUG_FS */
 
-#ifdef CONFIG_PPC_FSL_BOOK3E
+#if defined(CONFIG_PPC_FSL_BOOK3E) || defined(CONFIG_PPC_BOOK3S_64)
  static int __init handle_nospectre_v2(char *p)
  {
  	no_spectrev2 = true;
@@ -122,6 +122,9 @@ static int __init handle_nospectre_v2(char *p)
  	return 0;
  }
  early_param("nospectre_v2", handle_nospectre_v2);
+#endif /* CONFIG_PPC_FSL_BOOK3E || CONFIG_PPC_BOOK3S_64 */
+
+#ifdef CONFIG_PPC_FSL_BOOK3E
  void setup_spectre_v2(void)
  {
  	if (no_spectrev2 || cpu_mitigations_off())
@@ -399,7 +402,17 @@ static void toggle_count_cache_flush(bool enable)
 
  void setup_count_cache_flush(void)
  {
-	toggle_count_cache_flush(true);
+	bool enable = true;
+
+	if (no_spectrev2 || cpu_mitigations_off()) {
+		if (security_ftr_enabled(SEC_FTR_BCCTRL_SERIALISED) ||
+		    security_ftr_enabled(SEC_FTR_COUNT_CACHE_DISABLED))
+			pr_warn("Spectre v2 mitigations not under software control, can't disable\n");
+
+		enable = false;
+	}
+
+	toggle_count_cache_flush(enable);
  }
 
  #ifdef CONFIG_DEBUG_FS
Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]             IBM Australia Limited
#2 lore raw
Quoted 10 lines · Andrew Donnellan
Quoted 7 lines · Christopher M. Riedl

Add support for disabling the kernel implemented spectre v2 mitigation (count cache flush on context switch) via the nospectre_v2 and mitigations=off cmdline options.

snowpatch is whinging about this breaking the build for some reason... https://patchwork.ozlabs.org/patch/1104583/

Upon further inspection, it appears this was bogus, and now snowpatch is passing it happily.

Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]             IBM Australia Limited
#3 lore raw
In reply to Christopher M. Riedl
Quoted 7 lines · Christopher M. Riedl

Add support for disabling the kernel implemented spectre v2 mitigation (count cache flush on context switch) via the nospectre_v2 and mitigations=off cmdline options.

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/d8f0e0b073e1ec52a05f0c2a56318b47387d2f10

cheers