Commit 4f38b7f4 authored by Chenyi Qiang's avatar Chenyi Qiang Committed by Aichun Shi
Browse files

x86/bus_lock: Don't assume the init value of DEBUGCTLMSR.BUS_LOCK_DETECT to be zero

mainline inclusion
from mainline-v6.0-rc1
commit ffa6482e
category: feature
feature: KVM Bus Lock Debug Exception
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I5RHW7
CVE: N/A
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/


commit/?id=ffa6482e

Intel-SIG: commit ffa6482e ("x86/bus_lock: Don't assume the init value of DEBUGCTLMSR.BUS_LOCK_DETECT to be zero")

-------------------------------------

x86/bus_lock: Don't assume the init value of DEBUGCTLMSR.BUS_LOCK_DETECT to be zero

It's possible that this kernel has been kexec'd from a kernel that
enabled bus lock detection, or (hypothetically) BIOS/firmware has set
DEBUGCTLMSR_BUS_LOCK_DETECT.

Disable bus lock detection explicitly if not wanted.

Fixes: ebb1064e ("x86/traps: Handle #DB for bus lock")
Signed-off-by: default avatarChenyi Qiang <chenyi.qiang@intel.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Reviewed-by: default avatarTony Luck <tony.luck@intel.com>
Link: https://lore.kernel.org/r/20220802033206.21333-1-chenyi.qiang@intel.com


Signed-off-by: default avatarAichun Shi <aichun.shi@intel.com>
parent b9ddddea
Loading
Loading
Loading
Loading
+14 −13
Original line number Diff line number Diff line
@@ -1150,22 +1150,23 @@ static void bus_lock_init(void)
{
	u64 val;

	/*
	 * Warn and fatal are handled by #AC for split lock if #AC for
	 * split lock is supported.
	 */
	if (!boot_cpu_has(X86_FEATURE_BUS_LOCK_DETECT) ||
	    (boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT) &&
	    (sld_state == sld_warn || sld_state == sld_fatal)) ||
	    sld_state == sld_off)
	if (!boot_cpu_has(X86_FEATURE_BUS_LOCK_DETECT))
		return;

	rdmsrl(MSR_IA32_DEBUGCTLMSR, val);

	if ((boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT) &&
	    (sld_state == sld_warn || sld_state == sld_fatal)) ||
	    sld_state == sld_off) {
		/*
	 * Enable #DB for bus lock. All bus locks are handled in #DB except
	 * split locks are handled in #AC in the fatal case.
		 * Warn and fatal are handled by #AC for split lock if #AC for
		 * split lock is supported.
		 */
	rdmsrl(MSR_IA32_DEBUGCTLMSR, val);
		val &= ~DEBUGCTLMSR_BUS_LOCK_DETECT;
	} else {
		val |= DEBUGCTLMSR_BUS_LOCK_DETECT;
	}

	wrmsrl(MSR_IA32_DEBUGCTLMSR, val);
}