From 4df4ae2e80db3178d993e30921ad2247a5141fd3 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Mon, 17 Aug 2020 21:35:43 +0200 Subject: [PATCH] kernel/x86: Enable machine check exceptions if supported. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This enables generation of exceptions that are due to uncorrected hardware errors. The exception handlers were already in place and will now actually trigger kernel panics. Note that this is the simplest form of MCE "handling" and does not add anything of the broader machine check architecture (MCA) that also allow reporting of corrected errors. As MCEs are generally hard to decode due to their hardware specifity, this merely makes such problems more obvious. Might help to discern hardware issues in cases that would otherwise just triple fault and cause a reboot. Change-Id: I9e3a2640458f7c562066478d0ca90e3a46c3a325 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3155 Reviewed-by: waddlesplash Reviewed-by: Axel Dörfler --- headers/private/kernel/arch/x86/arch_cpu.h | 1 + src/system/kernel/arch/x86/arch_cpu.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/headers/private/kernel/arch/x86/arch_cpu.h b/headers/private/kernel/arch/x86/arch_cpu.h index dbb6cb1e5c..2acd0271bf 100644 --- a/headers/private/kernel/arch/x86/arch_cpu.h +++ b/headers/private/kernel/arch/x86/arch_cpu.h @@ -352,6 +352,7 @@ // cr4 flags #define IA32_CR4_PAE (1UL << 5) +#define IA32_CR4_MCE (1UL << 6) #define IA32_CR4_GLOBAL_PAGES (1UL << 7) #define CR4_OS_FXSR (1UL << 9) #define CR4_OS_XMM_EXCEPTION (1UL << 10) diff --git a/src/system/kernel/arch/x86/arch_cpu.cpp b/src/system/kernel/arch/x86/arch_cpu.cpp index e62c85e28f..fc120be406 100644 --- a/src/system/kernel/arch/x86/arch_cpu.cpp +++ b/src/system/kernel/arch/x86/arch_cpu.cpp @@ -1350,6 +1350,9 @@ arch_cpu_init_percpu(kernel_args* args, int cpu) gCpuIdleFunc = halt_idle; } + if (x86_check_feature(IA32_FEATURE_MCE, FEATURE_COMMON)) + x86_write_cr4(x86_read_cr4() | IA32_CR4_MCE); + #ifdef __x86_64__ // if RDTSCP is available write cpu number in TSC_AUX if (x86_check_feature(IA32_FEATURE_AMD_EXT_RDTSCP, FEATURE_EXT_AMD))