]> git.dujemihanovic.xyz Git - linux.git/commitdiff
KVM: X86: Expose bus lock debug exception to guest
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 6 May 2021 10:30:04 +0000 (06:30 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 7 May 2021 10:06:20 +0000 (06:06 -0400)
Bus lock debug exception is an ability to notify the kernel by an #DB
trap after the instruction acquires a bus lock and is executed when
CPL>0. This allows the kernel to enforce user application throttling or
mitigations.

Existence of bus lock debug exception is enumerated via
CPUID.(EAX=7,ECX=0).ECX[24]. Software can enable these exceptions by
setting bit 2 of the MSR_IA32_DEBUGCTL. Expose the CPUID to guest and
emulate the MSR handling when guest enables it.

Support for this feature was originally developed by Xiaoyao Li and
Chenyi Qiang, but code has since changed enough that this patch has
nothing in common with theirs, except for this commit message.

Co-developed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com>
Message-Id: <20210202090433.13441-4-chenyi.qiang@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/cpuid.c
arch/x86/kvm/vmx/capabilities.h
arch/x86/kvm/vmx/vmx.c

index f42e9491a6c8cb76d91636d5973c40deddf88a78..9a48f138832d42ee79eb153ca1288868d6560f5b 100644 (file)
@@ -458,7 +458,7 @@ void kvm_set_cpu_caps(void)
                F(AVX512_VPOPCNTDQ) | F(UMIP) | F(AVX512_VBMI2) | F(GFNI) |
                F(VAES) | F(VPCLMULQDQ) | F(AVX512_VNNI) | F(AVX512_BITALG) |
                F(CLDEMOTE) | F(MOVDIRI) | F(MOVDIR64B) | 0 /*WAITPKG*/ |
-               F(SGX_LC)
+               F(SGX_LC) | F(BUS_LOCK_DETECT)
        );
        /* Set LA57 based on hardware capability. */
        if (cpuid_ecx(7) & F(LA57))
index d1d77985e889fbf98cc4f40f3ef90a4ae2e95329..8dee8a5fbc17fe2f4faccbc0ed0cbabacee66914 100644 (file)
@@ -398,6 +398,9 @@ static inline u64 vmx_supported_debugctl(void)
 {
        u64 debugctl = 0;
 
+       if (boot_cpu_has(X86_FEATURE_BUS_LOCK_DETECT))
+               debugctl |= DEBUGCTLMSR_BUS_LOCK_DETECT;
+
        if (vmx_get_perf_capabilities() & PMU_CAP_LBR_FMT)
                debugctl |= DEBUGCTLMSR_LBR_MASK;
 
index 61f7e5221bf3aa86f31a9b15e101ce35c065b561..f2fd447eed459a2e8c91da44845b7ecec153ee33 100644 (file)
@@ -2014,6 +2014,9 @@ static u64 vcpu_supported_debugctl(struct kvm_vcpu *vcpu)
        if (!intel_pmu_lbr_is_enabled(vcpu))
                debugctl &= ~DEBUGCTLMSR_LBR_MASK;
 
+       if (!guest_cpuid_has(vcpu, X86_FEATURE_BUS_LOCK_DETECT))
+               debugctl &= ~DEBUGCTLMSR_BUS_LOCK_DETECT;
+
        return debugctl;
 }