Skip to content

Commit e6f8b6c

Browse files
calmisisuryasaimadhu
authored andcommitted
KVM: VMX: Extend VMXs #AC interceptor to handle split lock #AC in guest
Two types of #AC can be generated in Intel CPUs: 1. legacy alignment check #AC 2. split lock #AC Reflect #AC back into the guest if the guest has legacy alignment checks enabled or if split lock detection is disabled. If the #AC is not a legacy one and split lock detection is enabled, then invoke handle_guest_split_lock() which will either warn and disable split lock detection for this task or force SIGBUS on it. [ tglx: Switch it to handle_guest_split_lock() and rename the misnamed helper function. ] Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Xiaoyao Li <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> 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]
1 parent 9de6fe3 commit e6f8b6c

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4588,6 +4588,26 @@ static int handle_machine_check(struct kvm_vcpu *vcpu)
45884588
return 1;
45894589
}
45904590

4591+
/*
4592+
* If the host has split lock detection disabled, then #AC is
4593+
* unconditionally injected into the guest, which is the pre split lock
4594+
* detection behaviour.
4595+
*
4596+
* If the host has split lock detection enabled then #AC is
4597+
* only injected into the guest when:
4598+
* - Guest CPL == 3 (user mode)
4599+
* - Guest has #AC detection enabled in CR0
4600+
* - Guest EFLAGS has AC bit set
4601+
*/
4602+
static inline bool guest_inject_ac(struct kvm_vcpu *vcpu)
4603+
{
4604+
if (!boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT))
4605+
return true;
4606+
4607+
return vmx_get_cpl(vcpu) == 3 && kvm_read_cr0_bits(vcpu, X86_CR0_AM) &&
4608+
(kvm_get_rflags(vcpu) & X86_EFLAGS_AC);
4609+
}
4610+
45914611
static int handle_exception_nmi(struct kvm_vcpu *vcpu)
45924612
{
45934613
struct vcpu_vmx *vmx = to_vmx(vcpu);
@@ -4653,9 +4673,6 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
46534673
return handle_rmode_exception(vcpu, ex_no, error_code);
46544674

46554675
switch (ex_no) {
4656-
case AC_VECTOR:
4657-
kvm_queue_exception_e(vcpu, AC_VECTOR, error_code);
4658-
return 1;
46594676
case DB_VECTOR:
46604677
dr6 = vmcs_readl(EXIT_QUALIFICATION);
46614678
if (!(vcpu->guest_debug &
@@ -4684,6 +4701,20 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
46844701
kvm_run->debug.arch.pc = vmcs_readl(GUEST_CS_BASE) + rip;
46854702
kvm_run->debug.arch.exception = ex_no;
46864703
break;
4704+
case AC_VECTOR:
4705+
if (guest_inject_ac(vcpu)) {
4706+
kvm_queue_exception_e(vcpu, AC_VECTOR, error_code);
4707+
return 1;
4708+
}
4709+
4710+
/*
4711+
* Handle split lock. Depending on detection mode this will
4712+
* either warn and disable split lock detection for this
4713+
* task or force SIGBUS on it.
4714+
*/
4715+
if (handle_guest_split_lock(kvm_rip_read(vcpu)))
4716+
return 1;
4717+
fallthrough;
46874718
default:
46884719
kvm_run->exit_reason = KVM_EXIT_EXCEPTION;
46894720
kvm_run->ex.exception = ex_no;

0 commit comments

Comments
 (0)