Skip to content

Commit 1462014

Browse files
committed
Merge branch 'kvm-master' into HEAD
x86: * Use SRCU to protect zap in __kvm_set_or_clear_apicv_inhibit() * Make argument order consistent for kvcalloc() * Userspace API fixes for DEBUGCTL and LBRs
2 parents 8e5423e + 8670866 commit 1462014

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
13381338
if (sanity_check_entries(entries, cpuid->nent, type))
13391339
return -EINVAL;
13401340

1341-
array.entries = kvcalloc(sizeof(struct kvm_cpuid_entry2), cpuid->nent, GFP_KERNEL);
1341+
array.entries = kvcalloc(cpuid->nent, sizeof(struct kvm_cpuid_entry2), GFP_KERNEL);
13421342
if (!array.entries)
13431343
return -ENOMEM;
13441344

arch/x86/kvm/vmx/capabilities.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ extern int __read_mostly pt_mode;
2424
#define PMU_CAP_FW_WRITES (1ULL << 13)
2525
#define PMU_CAP_LBR_FMT 0x3f
2626

27-
#define DEBUGCTLMSR_LBR_MASK (DEBUGCTLMSR_LBR | DEBUGCTLMSR_FREEZE_LBRS_ON_PMI)
28-
2927
struct nested_vmx_msrs {
3028
/*
3129
* We only store the "true" versions of the VMX capability MSRs. We
@@ -400,6 +398,7 @@ static inline bool vmx_pebs_supported(void)
400398
static inline u64 vmx_get_perf_capabilities(void)
401399
{
402400
u64 perf_cap = PMU_CAP_FW_WRITES;
401+
struct x86_pmu_lbr lbr;
403402
u64 host_perf_cap = 0;
404403

405404
if (!enable_pmu)
@@ -408,7 +407,8 @@ static inline u64 vmx_get_perf_capabilities(void)
408407
if (boot_cpu_has(X86_FEATURE_PDCM))
409408
rdmsrl(MSR_IA32_PERF_CAPABILITIES, host_perf_cap);
410409

411-
perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT;
410+
if (x86_perf_get_lbr(&lbr) >= 0 && lbr.nr)
411+
perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT;
412412

413413
if (vmx_pebs_supported()) {
414414
perf_cap |= host_perf_cap & PERF_CAP_PEBS_MASK;
@@ -419,19 +419,6 @@ static inline u64 vmx_get_perf_capabilities(void)
419419
return perf_cap;
420420
}
421421

422-
static inline u64 vmx_supported_debugctl(void)
423-
{
424-
u64 debugctl = 0;
425-
426-
if (boot_cpu_has(X86_FEATURE_BUS_LOCK_DETECT))
427-
debugctl |= DEBUGCTLMSR_BUS_LOCK_DETECT;
428-
429-
if (vmx_get_perf_capabilities() & PMU_CAP_LBR_FMT)
430-
debugctl |= DEBUGCTLMSR_LBR_MASK;
431-
432-
return debugctl;
433-
}
434-
435422
static inline bool cpu_has_notify_vmexit(void)
436423
{
437424
return vmcs_config.cpu_based_2nd_exec_ctrl &

arch/x86/kvm/vmx/vmx.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,15 +2021,17 @@ static u64 nested_vmx_truncate_sysenter_addr(struct kvm_vcpu *vcpu,
20212021
return (unsigned long)data;
20222022
}
20232023

2024-
static u64 vcpu_supported_debugctl(struct kvm_vcpu *vcpu)
2024+
static u64 vmx_get_supported_debugctl(struct kvm_vcpu *vcpu, bool host_initiated)
20252025
{
2026-
u64 debugctl = vmx_supported_debugctl();
2026+
u64 debugctl = 0;
20272027

2028-
if (!intel_pmu_lbr_is_enabled(vcpu))
2029-
debugctl &= ~DEBUGCTLMSR_LBR_MASK;
2028+
if (boot_cpu_has(X86_FEATURE_BUS_LOCK_DETECT) &&
2029+
(host_initiated || guest_cpuid_has(vcpu, X86_FEATURE_BUS_LOCK_DETECT)))
2030+
debugctl |= DEBUGCTLMSR_BUS_LOCK_DETECT;
20302031

2031-
if (!guest_cpuid_has(vcpu, X86_FEATURE_BUS_LOCK_DETECT))
2032-
debugctl &= ~DEBUGCTLMSR_BUS_LOCK_DETECT;
2032+
if ((vmx_get_perf_capabilities() & PMU_CAP_LBR_FMT) &&
2033+
(host_initiated || intel_pmu_lbr_is_enabled(vcpu)))
2034+
debugctl |= DEBUGCTLMSR_LBR | DEBUGCTLMSR_FREEZE_LBRS_ON_PMI;
20332035

20342036
return debugctl;
20352037
}
@@ -2103,7 +2105,9 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
21032105
vmcs_writel(GUEST_SYSENTER_ESP, data);
21042106
break;
21052107
case MSR_IA32_DEBUGCTLMSR: {
2106-
u64 invalid = data & ~vcpu_supported_debugctl(vcpu);
2108+
u64 invalid;
2109+
2110+
invalid = data & ~vmx_get_supported_debugctl(vcpu, msr_info->host_initiated);
21072111
if (invalid & (DEBUGCTLMSR_BTF|DEBUGCTLMSR_LBR)) {
21082112
if (report_ignored_msrs)
21092113
vcpu_unimpl(vcpu, "%s: BTF|LBR in IA32_DEBUGCTLMSR 0x%llx, nop\n",

arch/x86/kvm/x86.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10404,7 +10404,10 @@ void __kvm_set_or_clear_apicv_inhibit(struct kvm *kvm,
1040410404
kvm->arch.apicv_inhibit_reasons = new;
1040510405
if (new) {
1040610406
unsigned long gfn = gpa_to_gfn(APIC_DEFAULT_PHYS_BASE);
10407+
int idx = srcu_read_lock(&kvm->srcu);
10408+
1040710409
kvm_zap_gfn_range(kvm, gfn, gfn+1);
10410+
srcu_read_unlock(&kvm->srcu, idx);
1040810411
}
1040910412
} else {
1041010413
kvm->arch.apicv_inhibit_reasons = new;

0 commit comments

Comments
 (0)