Skip to content

Commit

Permalink
KVM: x86: Register Processor Trace interrupt hook iff PT enabled in g…
Browse files Browse the repository at this point in the history
…uest

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>
  • Loading branch information
sean-jc authored and gregkh committed Jan 20, 2022
1 parent 51d24f0 commit ec985a8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions arch/x86/include/asm/kvm_host.h
Expand Up @@ -1519,6 +1519,7 @@ struct kvm_x86_init_ops {
int (*disabled_by_bios)(void);
int (*check_processor_compatibility)(void);
int (*hardware_setup)(void);
bool (*intel_pt_intr_in_guest)(void);

struct kvm_x86_ops *runtime_ops;
};
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kvm/vmx/vmx.c
Expand Up @@ -7905,6 +7905,7 @@ static struct kvm_x86_init_ops vmx_init_ops __initdata = {
.disabled_by_bios = vmx_disabled_by_bios,
.check_processor_compatibility = vmx_check_processor_compat,
.hardware_setup = hardware_setup,
.intel_pt_intr_in_guest = vmx_pt_mode_is_host_guest,

.runtime_ops = &vmx_x86_ops,
};
Expand Down
5 changes: 4 additions & 1 deletion arch/x86/kvm/x86.c
Expand Up @@ -8560,7 +8560,7 @@ static struct perf_guest_info_callbacks kvm_guest_cbs = {
.is_in_guest = kvm_is_in_guest,
.is_user_mode = kvm_is_user_mode,
.get_guest_ip = kvm_get_guest_ip,
.handle_intel_pt_intr = kvm_handle_intel_pt_intr,
.handle_intel_pt_intr = NULL,
};

#ifdef CONFIG_X86_64
Expand Down Expand Up @@ -11266,6 +11266,8 @@ int kvm_arch_hardware_setup(void *opaque)
memcpy(&kvm_x86_ops, ops->runtime_ops, sizeof(kvm_x86_ops));
kvm_ops_static_call_update();

if (ops->intel_pt_intr_in_guest && ops->intel_pt_intr_in_guest())
kvm_guest_cbs.handle_intel_pt_intr = kvm_handle_intel_pt_intr;
perf_register_guest_info_callbacks(&kvm_guest_cbs);

if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES))
Expand Down Expand Up @@ -11296,6 +11298,7 @@ int kvm_arch_hardware_setup(void *opaque)
void kvm_arch_hardware_unsetup(void)
{
perf_unregister_guest_info_callbacks(&kvm_guest_cbs);
kvm_guest_cbs.handle_intel_pt_intr = NULL;

static_call(kvm_x86_hardware_unsetup)();
}
Expand Down

0 comments on commit ec985a8

Please sign in to comment.