Skip to content

Commit f4b027c

Browse files
sean-jcPeter Zijlstra
authored andcommitted
KVM: x86: Register Processor Trace interrupt hook iff PT enabled in guest
Override the Processor Trace (PT) interrupt handler for guest mode if and only if PT is configured for host+guest mode, i.e. is being used independently by both host and guest. If PT is configured for system mode, the host fully controls PT and must handle all events. Fixes: 8479e04 ("KVM: x86: Inject PMI for KVM guest") Reported-by: Alexander Shishkin <[email protected]> Reported-by: Artem Kashkanov <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Paolo Bonzini <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 5c7df80 commit f4b027c

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,7 @@ struct kvm_x86_init_ops {
15161516
int (*disabled_by_bios)(void);
15171517
int (*check_processor_compatibility)(void);
15181518
int (*hardware_setup)(void);
1519+
bool (*intel_pt_intr_in_guest)(void);
15191520

15201521
struct kvm_x86_ops *runtime_ops;
15211522
};

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7865,6 +7865,7 @@ static struct kvm_x86_init_ops vmx_init_ops __initdata = {
78657865
.disabled_by_bios = vmx_disabled_by_bios,
78667866
.check_processor_compatibility = vmx_check_processor_compat,
78677867
.hardware_setup = hardware_setup,
7868+
.intel_pt_intr_in_guest = vmx_pt_mode_is_host_guest,
78687869

78697870
.runtime_ops = &vmx_x86_ops,
78707871
};

arch/x86/kvm/x86.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8510,7 +8510,7 @@ static struct perf_guest_info_callbacks kvm_guest_cbs = {
85108510
.is_in_guest = kvm_is_in_guest,
85118511
.is_user_mode = kvm_is_user_mode,
85128512
.get_guest_ip = kvm_get_guest_ip,
8513-
.handle_intel_pt_intr = kvm_handle_intel_pt_intr,
8513+
.handle_intel_pt_intr = NULL,
85148514
};
85158515

85168516
#ifdef CONFIG_X86_64
@@ -11222,6 +11222,8 @@ int kvm_arch_hardware_setup(void *opaque)
1122211222
memcpy(&kvm_x86_ops, ops->runtime_ops, sizeof(kvm_x86_ops));
1122311223
kvm_ops_static_call_update();
1122411224

11225+
if (ops->intel_pt_intr_in_guest && ops->intel_pt_intr_in_guest())
11226+
kvm_guest_cbs.handle_intel_pt_intr = kvm_handle_intel_pt_intr;
1122511227
perf_register_guest_info_callbacks(&kvm_guest_cbs);
1122611228

1122711229
if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES))
@@ -11252,6 +11254,7 @@ int kvm_arch_hardware_setup(void *opaque)
1125211254
void kvm_arch_hardware_unsetup(void)
1125311255
{
1125411256
perf_unregister_guest_info_callbacks(&kvm_guest_cbs);
11257+
kvm_guest_cbs.handle_intel_pt_intr = NULL;
1125511258

1125611259
static_call(kvm_x86_hardware_unsetup)();
1125711260
}

0 commit comments

Comments
 (0)