Skip to content

Commit 413b427

Browse files
sean-jcgregkh
authored andcommitted
KVM: x86: Register Processor Trace interrupt hook iff PT enabled in guest
commit f4b027c upstream. 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 <alexander.shishkin@linux.intel.com> Reported-by: Artem Kashkanov <artem.kashkanov@intel.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20211111020738.2512932-4-seanjc@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 723acd7 commit 413b427

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,7 @@ struct kvm_x86_init_ops {
13061306
int (*disabled_by_bios)(void);
13071307
int (*check_processor_compatibility)(void);
13081308
int (*hardware_setup)(void);
1309+
bool (*intel_pt_intr_in_guest)(void);
13091310

13101311
struct kvm_x86_ops *runtime_ops;
13111312
};

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7915,6 +7915,7 @@ static struct kvm_x86_init_ops vmx_init_ops __initdata = {
79157915
.disabled_by_bios = vmx_disabled_by_bios,
79167916
.check_processor_compatibility = vmx_check_processor_compat,
79177917
.hardware_setup = hardware_setup,
7918+
.intel_pt_intr_in_guest = vmx_pt_mode_is_host_guest,
79187919

79197920
.runtime_ops = &vmx_x86_ops,
79207921
};

arch/x86/kvm/x86.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7882,7 +7882,7 @@ static struct perf_guest_info_callbacks kvm_guest_cbs = {
78827882
.is_in_guest = kvm_is_in_guest,
78837883
.is_user_mode = kvm_is_user_mode,
78847884
.get_guest_ip = kvm_get_guest_ip,
7885-
.handle_intel_pt_intr = kvm_handle_intel_pt_intr,
7885+
.handle_intel_pt_intr = NULL,
78867886
};
78877887

78887888
#ifdef CONFIG_X86_64
@@ -8005,6 +8005,8 @@ int kvm_arch_init(void *opaque)
80058005
PT_PRESENT_MASK, 0, sme_me_mask);
80068006
kvm_timer_init();
80078007

8008+
if (ops->intel_pt_intr_in_guest && ops->intel_pt_intr_in_guest())
8009+
kvm_guest_cbs.handle_intel_pt_intr = kvm_handle_intel_pt_intr;
80088010
perf_register_guest_info_callbacks(&kvm_guest_cbs);
80098011

80108012
if (boot_cpu_has(X86_FEATURE_XSAVE)) {
@@ -8042,6 +8044,7 @@ void kvm_arch_exit(void)
80428044
#endif
80438045
kvm_lapic_exit();
80448046
perf_unregister_guest_info_callbacks(&kvm_guest_cbs);
8047+
kvm_guest_cbs.handle_intel_pt_intr = NULL;
80458048

80468049
if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
80478050
cpufreq_unregister_notifier(&kvmclock_cpufreq_notifier_block,

0 commit comments

Comments
 (0)