Skip to content

Commit d7e94db

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/split_lock: Provide handle_guest_split_lock()
Without at least minimal handling for split lock detection induced #AC, VMX will just run into the same problem as the VMWare hypervisor, which was reported by Kenneth. It will inject the #AC blindly into the guest whether the guest is prepared or not. Provide a function for guest mode which acts depending on the host SLD mode. If mode == sld_warn, treat it like user space, i.e. emit a warning, disable SLD and mark the task accordingly. Otherwise force SIGBUS. [ bp: Add a !CPU_SUP_INTEL stub for handle_guest_split_lock(). ] Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Paolo Bonzini <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 5b8b9d0 commit d7e94db

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

arch/x86/include/asm/cpu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,18 @@ unsigned int x86_stepping(unsigned int sig);
4444
extern void __init cpu_set_core_cap_bits(struct cpuinfo_x86 *c);
4545
extern void switch_to_sld(unsigned long tifn);
4646
extern bool handle_user_split_lock(struct pt_regs *regs, long error_code);
47+
extern bool handle_guest_split_lock(unsigned long ip);
4748
#else
4849
static inline void __init cpu_set_core_cap_bits(struct cpuinfo_x86 *c) {}
4950
static inline void switch_to_sld(unsigned long tifn) {}
5051
static inline bool handle_user_split_lock(struct pt_regs *regs, long error_code)
5152
{
5253
return false;
5354
}
55+
56+
static inline bool handle_guest_split_lock(unsigned long ip)
57+
{
58+
return false;
59+
}
5460
#endif
5561
#endif /* _ASM_X86_CPU_H */

arch/x86/kernel/cpu/intel.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <asm/elf.h>
2222
#include <asm/cpu_device_id.h>
2323
#include <asm/cmdline.h>
24+
#include <asm/traps.h>
2425

2526
#ifdef CONFIG_X86_64
2627
#include <linux/topology.h>
@@ -1066,13 +1067,10 @@ static void split_lock_init(void)
10661067
split_lock_verify_msr(sld_state != sld_off);
10671068
}
10681069

1069-
bool handle_user_split_lock(struct pt_regs *regs, long error_code)
1070+
static void split_lock_warn(unsigned long ip)
10701071
{
1071-
if ((regs->flags & X86_EFLAGS_AC) || sld_state == sld_fatal)
1072-
return false;
1073-
10741072
pr_warn_ratelimited("#AC: %s/%d took a split_lock trap at address: 0x%lx\n",
1075-
current->comm, current->pid, regs->ip);
1073+
current->comm, current->pid, ip);
10761074

10771075
/*
10781076
* Disable the split lock detection for this task so it can make
@@ -1081,6 +1079,31 @@ bool handle_user_split_lock(struct pt_regs *regs, long error_code)
10811079
*/
10821080
sld_update_msr(false);
10831081
set_tsk_thread_flag(current, TIF_SLD);
1082+
}
1083+
1084+
bool handle_guest_split_lock(unsigned long ip)
1085+
{
1086+
if (sld_state == sld_warn) {
1087+
split_lock_warn(ip);
1088+
return true;
1089+
}
1090+
1091+
pr_warn_once("#AC: %s/%d %s split_lock trap at address: 0x%lx\n",
1092+
current->comm, current->pid,
1093+
sld_state == sld_fatal ? "fatal" : "bogus", ip);
1094+
1095+
current->thread.error_code = 0;
1096+
current->thread.trap_nr = X86_TRAP_AC;
1097+
force_sig_fault(SIGBUS, BUS_ADRALN, NULL);
1098+
return false;
1099+
}
1100+
EXPORT_SYMBOL_GPL(handle_guest_split_lock);
1101+
1102+
bool handle_user_split_lock(struct pt_regs *regs, long error_code)
1103+
{
1104+
if ((regs->flags & X86_EFLAGS_AC) || sld_state == sld_fatal)
1105+
return false;
1106+
split_lock_warn(regs->ip);
10841107
return true;
10851108
}
10861109

0 commit comments

Comments
 (0)