[PATCH 6/8] x86/mce/mce-inject: Preset the MCE injection struct

From: Borislav Petkov
Date: Tue Jun 13 2017 - 12:30:00 EST


From: Borislav Petkov <bp@xxxxxxx>

Populate the MCE injection struct before doing initial injection so that
values which don't change have sane defaults.

Signed-off-by: Borislav Petkov <bp@xxxxxxx>
Acked-by: Yazen Ghannam <yazen.ghannam@xxxxxxx>
Tested-by: Yazen Ghannam <yazen.ghannam@xxxxxxx>
---
arch/x86/kernel/cpu/mcheck/mce-inject.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
index 00af8dd8fc59..231ad23b24a9 100644
--- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
+++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
@@ -103,6 +103,13 @@ DEFINE_SIMPLE_ATTRIBUTE(misc_fops, inj_misc_get, inj_misc_set, "%llx\n");
DEFINE_SIMPLE_ATTRIBUTE(addr_fops, inj_addr_get, inj_addr_set, "%llx\n");
DEFINE_SIMPLE_ATTRIBUTE(synd_fops, inj_synd_get, inj_synd_set, "%llx\n");

+static void setup_inj_struct(struct mce *m)
+{
+ memset(m, 0, sizeof(struct mce));
+
+ m->cpuvendor = boot_cpu_data.x86_vendor;
+}
+
/* Update fake mce registers on current CPU. */
static void inject_mce(struct mce *m)
{
@@ -700,6 +707,8 @@ static int __init inject_init(void)
register_nmi_handler(NMI_LOCAL, mce_raise_notify, 0, "mce_notify");
mce_register_injector_chain(&inject_nb);

+ setup_inj_struct(&i_mce);
+
pr_info("Machine check injector initialized\n");

return 0;
--
2.13.0