[tip:ras/core] x86/mce: Merge mce_amd_inj into mce-inject

2017-06-14 Thread tip-bot for Borislav Petkov
Commit-ID:  bc8e80d56c1ecb35e65df392d7601d1427d14efe
Gitweb: http://git.kernel.org/tip/bc8e80d56c1ecb35e65df392d7601d1427d14efe
Author: Borislav Petkov 
AuthorDate: Tue, 13 Jun 2017 18:28:30 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 14 Jun 2017 07:32:07 +0200

x86/mce: Merge mce_amd_inj into mce-inject

Reuse mce_amd_inj's debugfs interface so that mce-inject can
benefit from it too. The old functionality is still preserved under
CONFIG_X86_MCELOG_LEGACY.

Tested-by: Yazen Ghannam 
Signed-off-by: Borislav Petkov 
Acked-by: Yazen Ghannam 
Cc: Borislav Petkov 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Tony Luck 
Link: http://lkml.kernel.org/r/20170613162835.30750-4...@alien8.de
Signed-off-by: Ingo Molnar 
---
 arch/x86/Kconfig|   2 +-
 arch/x86/Makefile   |   2 -
 arch/x86/include/asm/processor.h|   5 +
 arch/x86/kernel/cpu/mcheck/mce-inject.c | 542 +++-
 arch/x86/ras/Kconfig|  11 -
 arch/x86/ras/Makefile   |   2 -
 arch/x86/ras/mce_amd_inj.c  | 492 -
 7 files changed, 532 insertions(+), 524 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0efb4c9..4371b6b 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1082,7 +1082,7 @@ config X86_MCE_THRESHOLD
def_bool y
 
 config X86_MCE_INJECT
-   depends on X86_MCE && X86_LOCAL_APIC && X86_MCELOG_LEGACY
+   depends on X86_MCE && X86_LOCAL_APIC && DEBUG_FS
tristate "Machine check injector support"
---help---
  Provide support for injecting machine checks for testing purposes.
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index bf240b9..ad2db82 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -257,8 +257,6 @@ drivers-$(CONFIG_PM) += arch/x86/power/
 
 drivers-$(CONFIG_FB) += arch/x86/video/
 
-drivers-$(CONFIG_RAS) += arch/x86/ras/
-
 
 # boot loader support. Several targets are kept for legacy purposes
 
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 3cada99..71f6fba 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -901,8 +901,13 @@ static inline int mpx_disable_management(void)
 }
 #endif /* CONFIG_X86_INTEL_MPX */
 
+#ifdef CONFIG_CPU_SUP_AMD
 extern u16 amd_get_nb_id(int cpu);
 extern u32 amd_get_nodes_per_socket(void);
+#else
+static inline u16 amd_get_nb_id(int cpu)   { return 0; }
+static inline u32 amd_get_nodes_per_socket(void)   { return 0; }
+#endif
 
 static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
 {
diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c 
b/arch/x86/kernel/cpu/mcheck/mce-inject.c
index 99165b2..7170186 100644
--- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
+++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
@@ -10,23 +10,108 @@
  * Authors:
  * Andi Kleen
  * Ying Huang
+ *
+ * The AMD part (from mce_amd_inj.c): a simple MCE injection facility
+ * for testing different aspects of the RAS code. This driver should be
+ * built as module so that it can be loaded on production kernels for
+ * testing purposes.
+ *
+ * This file may be distributed under the terms of the GNU General Public
+ * License version 2.
+ *
+ * Copyright (c) 2010-17:  Borislav Petkov 
+ *Advanced Micro Devices Inc.
  */
-#include 
-#include 
-#include 
-#include 
-#include 
+
+#include 
+#include 
+#include 
 #include 
-#include 
-#include 
-#include 
+#include 
 #include 
-#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
-#include 
-#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
 #include 
+#include 
+#include 
 #include 
+#include 
+
+#include "mce-internal.h"
+
+/*
+ * Collect all the MCi_XXX settings
+ */
+static struct mce i_mce;
+static struct dentry *dfs_inj;
+
+static u8 n_banks;
+
+#define MAX_FLAG_OPT_SIZE  3
+#define NBCFG  0x44
+
+enum injection_type {
+   SW_INJ = 0, /* SW injection, simply decode the error */
+   HW_INJ, /* Trigger a #MC */
+   DFR_INT_INJ,/* Trigger Deferred error interrupt */
+   THR_INT_INJ,/* Trigger threshold interrupt */
+   N_INJ_TYPES,
+};
+
+static const char * const flags_options[] = {
+   [SW_INJ] = "sw",
+   [HW_INJ] = "hw",
+   [DFR_INT_INJ] = "df",
+   [THR_INT_INJ] = "th",
+   NULL
+};
+
+/* Set default injection to SW_INJ */
+static enum injection_type inj_type = SW_INJ;
+
+#define MCE_INJECT_SET(reg)\
+static int inj_##reg##_set(void *data, u64 val)
\
+{   

[tip:ras/core] x86/mce: Merge mce_amd_inj into mce-inject

2017-06-14 Thread tip-bot for Borislav Petkov
Commit-ID:  bc8e80d56c1ecb35e65df392d7601d1427d14efe
Gitweb: http://git.kernel.org/tip/bc8e80d56c1ecb35e65df392d7601d1427d14efe
Author: Borislav Petkov 
AuthorDate: Tue, 13 Jun 2017 18:28:30 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 14 Jun 2017 07:32:07 +0200

x86/mce: Merge mce_amd_inj into mce-inject

Reuse mce_amd_inj's debugfs interface so that mce-inject can
benefit from it too. The old functionality is still preserved under
CONFIG_X86_MCELOG_LEGACY.

Tested-by: Yazen Ghannam 
Signed-off-by: Borislav Petkov 
Acked-by: Yazen Ghannam 
Cc: Borislav Petkov 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Tony Luck 
Link: http://lkml.kernel.org/r/20170613162835.30750-4...@alien8.de
Signed-off-by: Ingo Molnar 
---
 arch/x86/Kconfig|   2 +-
 arch/x86/Makefile   |   2 -
 arch/x86/include/asm/processor.h|   5 +
 arch/x86/kernel/cpu/mcheck/mce-inject.c | 542 +++-
 arch/x86/ras/Kconfig|  11 -
 arch/x86/ras/Makefile   |   2 -
 arch/x86/ras/mce_amd_inj.c  | 492 -
 7 files changed, 532 insertions(+), 524 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0efb4c9..4371b6b 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1082,7 +1082,7 @@ config X86_MCE_THRESHOLD
def_bool y
 
 config X86_MCE_INJECT
-   depends on X86_MCE && X86_LOCAL_APIC && X86_MCELOG_LEGACY
+   depends on X86_MCE && X86_LOCAL_APIC && DEBUG_FS
tristate "Machine check injector support"
---help---
  Provide support for injecting machine checks for testing purposes.
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index bf240b9..ad2db82 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -257,8 +257,6 @@ drivers-$(CONFIG_PM) += arch/x86/power/
 
 drivers-$(CONFIG_FB) += arch/x86/video/
 
-drivers-$(CONFIG_RAS) += arch/x86/ras/
-
 
 # boot loader support. Several targets are kept for legacy purposes
 
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 3cada99..71f6fba 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -901,8 +901,13 @@ static inline int mpx_disable_management(void)
 }
 #endif /* CONFIG_X86_INTEL_MPX */
 
+#ifdef CONFIG_CPU_SUP_AMD
 extern u16 amd_get_nb_id(int cpu);
 extern u32 amd_get_nodes_per_socket(void);
+#else
+static inline u16 amd_get_nb_id(int cpu)   { return 0; }
+static inline u32 amd_get_nodes_per_socket(void)   { return 0; }
+#endif
 
 static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
 {
diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c 
b/arch/x86/kernel/cpu/mcheck/mce-inject.c
index 99165b2..7170186 100644
--- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
+++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
@@ -10,23 +10,108 @@
  * Authors:
  * Andi Kleen
  * Ying Huang
+ *
+ * The AMD part (from mce_amd_inj.c): a simple MCE injection facility
+ * for testing different aspects of the RAS code. This driver should be
+ * built as module so that it can be loaded on production kernels for
+ * testing purposes.
+ *
+ * This file may be distributed under the terms of the GNU General Public
+ * License version 2.
+ *
+ * Copyright (c) 2010-17:  Borislav Petkov 
+ *Advanced Micro Devices Inc.
  */
-#include 
-#include 
-#include 
-#include 
-#include 
+
+#include 
+#include 
+#include 
 #include 
-#include 
-#include 
-#include 
+#include 
 #include 
-#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
-#include 
-#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
 #include 
+#include 
+#include 
 #include 
+#include 
+
+#include "mce-internal.h"
+
+/*
+ * Collect all the MCi_XXX settings
+ */
+static struct mce i_mce;
+static struct dentry *dfs_inj;
+
+static u8 n_banks;
+
+#define MAX_FLAG_OPT_SIZE  3
+#define NBCFG  0x44
+
+enum injection_type {
+   SW_INJ = 0, /* SW injection, simply decode the error */
+   HW_INJ, /* Trigger a #MC */
+   DFR_INT_INJ,/* Trigger Deferred error interrupt */
+   THR_INT_INJ,/* Trigger threshold interrupt */
+   N_INJ_TYPES,
+};
+
+static const char * const flags_options[] = {
+   [SW_INJ] = "sw",
+   [HW_INJ] = "hw",
+   [DFR_INT_INJ] = "df",
+   [THR_INT_INJ] = "th",
+   NULL
+};
+
+/* Set default injection to SW_INJ */
+static enum injection_type inj_type = SW_INJ;
+
+#define MCE_INJECT_SET(reg)\
+static int inj_##reg##_set(void *data, u64 val)
\
+{  \
+   struct mce *m = (struct mce *)data; \
+   \
+   m->reg = val;