Skip to content

Commit 33271a9

Browse files
sean-jcPeter Zijlstra
authored andcommitted
KVM: x86: Move Intel Processor Trace interrupt handler to vmx.c
Now that all state needed for VMX's PT interrupt handler is exposed to vmx.c (specifically the currently running vCPU), move the handler into vmx.c where it belongs. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e1bfc24 commit 33271a9

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ struct kvm_x86_init_ops {
15171517
int (*disabled_by_bios)(void);
15181518
int (*check_processor_compatibility)(void);
15191519
int (*hardware_setup)(void);
1520-
bool (*intel_pt_intr_in_guest)(void);
1520+
unsigned int (*handle_intel_pt_intr)(void);
15211521

15221522
struct kvm_x86_ops *runtime_ops;
15231523
};

arch/x86/kvm/vmx/vmx.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7655,6 +7655,20 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = {
76557655
.vcpu_deliver_sipi_vector = kvm_vcpu_deliver_sipi_vector,
76567656
};
76577657

7658+
static unsigned int vmx_handle_intel_pt_intr(void)
7659+
{
7660+
struct kvm_vcpu *vcpu = kvm_get_running_vcpu();
7661+
7662+
/* '0' on failure so that the !PT case can use a RET0 static call. */
7663+
if (!kvm_arch_pmi_in_guest(vcpu))
7664+
return 0;
7665+
7666+
kvm_make_request(KVM_REQ_PMI, vcpu);
7667+
__set_bit(MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI_BIT,
7668+
(unsigned long *)&vcpu->arch.pmu.global_status);
7669+
return 1;
7670+
}
7671+
76587672
static __init void vmx_setup_user_return_msrs(void)
76597673
{
76607674

@@ -7681,6 +7695,8 @@ static __init void vmx_setup_user_return_msrs(void)
76817695
kvm_add_user_return_msr(vmx_uret_msrs_list[i]);
76827696
}
76837697

7698+
static struct kvm_x86_init_ops vmx_init_ops __initdata;
7699+
76847700
static __init int hardware_setup(void)
76857701
{
76867702
unsigned long host_bndcfgs;
@@ -7839,6 +7855,10 @@ static __init int hardware_setup(void)
78397855
return -EINVAL;
78407856
if (!enable_ept || !cpu_has_vmx_intel_pt())
78417857
pt_mode = PT_MODE_SYSTEM;
7858+
if (pt_mode == PT_MODE_HOST_GUEST)
7859+
vmx_init_ops.handle_intel_pt_intr = vmx_handle_intel_pt_intr;
7860+
else
7861+
vmx_init_ops.handle_intel_pt_intr = NULL;
78427862

78437863
setup_default_sgx_lepubkeyhash();
78447864

@@ -7867,7 +7887,7 @@ static struct kvm_x86_init_ops vmx_init_ops __initdata = {
78677887
.disabled_by_bios = vmx_disabled_by_bios,
78687888
.check_processor_compatibility = vmx_check_processor_compat,
78697889
.hardware_setup = hardware_setup,
7870-
.intel_pt_intr_in_guest = vmx_pt_mode_is_host_guest,
7890+
.handle_intel_pt_intr = NULL,
78717891

78727892
.runtime_ops = &vmx_x86_ops,
78737893
};

arch/x86/kvm/x86.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8469,20 +8469,6 @@ static void kvm_timer_init(void)
84698469
kvmclock_cpu_online, kvmclock_cpu_down_prep);
84708470
}
84718471

8472-
static unsigned int kvm_handle_intel_pt_intr(void)
8473-
{
8474-
struct kvm_vcpu *vcpu = kvm_get_running_vcpu();
8475-
8476-
/* '0' on failure so that the !PT case can use a RET0 static call. */
8477-
if (!kvm_arch_pmi_in_guest(vcpu))
8478-
return 0;
8479-
8480-
kvm_make_request(KVM_REQ_PMI, vcpu);
8481-
__set_bit(MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI_BIT,
8482-
(unsigned long *)&vcpu->arch.pmu.global_status);
8483-
return 1;
8484-
}
8485-
84868472
#ifdef CONFIG_X86_64
84878473
static void pvclock_gtod_update_fn(struct work_struct *work)
84888474
{
@@ -11192,11 +11178,7 @@ int kvm_arch_hardware_setup(void *opaque)
1119211178
memcpy(&kvm_x86_ops, ops->runtime_ops, sizeof(kvm_x86_ops));
1119311179
kvm_ops_static_call_update();
1119411180

11195-
/* Temporary ugliness. */
11196-
if (ops->intel_pt_intr_in_guest && ops->intel_pt_intr_in_guest())
11197-
kvm_register_perf_callbacks(kvm_handle_intel_pt_intr);
11198-
else
11199-
kvm_register_perf_callbacks(NULL);
11181+
kvm_register_perf_callbacks(ops->handle_intel_pt_intr);
1120011182

1120111183
if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES))
1120211184
supported_xss = 0;

0 commit comments

Comments
 (0)