Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2128977pxb; Mon, 23 Aug 2021 12:40:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztCmmMG0WEbcR16KRsE0QFwRoKW91yY9Gasjj2SOI88bu5griYQcVIEkVbP/u3o3IpTOBc X-Received: by 2002:a6b:b4ce:: with SMTP id d197mr21207499iof.69.1629747602913; Mon, 23 Aug 2021 12:40:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629747602; cv=none; d=google.com; s=arc-20160816; b=HNOZtNkYHyoY6b4N4Q9DZfD++YnOzsXvACplwGcfRnM4eI4yqvKtF1z3CtRUaFqv4C j2v3we+gy9YMG2ThVFUgbuxqsuVB+quEEdKsaFDtJXI3Ho9WDOhNjCHmVt64kgoA8jGD uXa+hUA54XhNEJNrzbk9JbYZvy5tkLSrm+qxZ+Gifnbfyj1H2ZIPj7QweQG3cD7MBdDe BCkxFH9R/IOOhdR1ALwW/Mhio1hP21V1RvjSVBVK/66z51GjYim2wGKbeXhN3HAhQCrf IOtT2+c0jipfy5aDoRIDoFoJdx4ea0vXTYLZfVji2IFCpu+/TYLLUFL9cT0VpAEPNMO9 2xQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=szW3JQG930FKvjzbx7RUR8NrPsOs8RDaZiZuKadIl/c=; b=mJYKNj9tAsR3Fp/mNZLjPv2N7ZuJ6iOzDDrhvfl3h7573J9esv7B66SARjiXZmV1aD jJw2ANnlFnUhDCH43II+AiGyncFXZxua1wSjfLUNhbUhIv1sJiBItL820IBtUDssrMw8 TQ0g8qi4kzN4fyGMHMYmJbQsassy8pZHdQgvCSbFEBoPJtoxpMMPRYmBCfZtwD4+q2hj DX6YFTKPh54Hs36M86K7xYaBwgKegUafx7pbEPioNOsL+FI5iqVKB9+SULZxb1/eGJsn TERQsDWqh8Dvti1YV8OUllIPmCzRzWw2FvLeNiPaZXjul1yBOi9EX1fsDjjNt3z9uUKK 8zqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mGb2GjPM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g2si19463604ioo.75.2021.08.23.12.39.51; Mon, 23 Aug 2021 12:40:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mGb2GjPM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232237AbhHWTiN (ORCPT + 99 others); Mon, 23 Aug 2021 15:38:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232195AbhHWTiL (ORCPT ); Mon, 23 Aug 2021 15:38:11 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62238C061757 for ; Mon, 23 Aug 2021 12:37:28 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id q80-20020a25d953000000b0059a45a5f834so3031196ybg.22 for ; Mon, 23 Aug 2021 12:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=szW3JQG930FKvjzbx7RUR8NrPsOs8RDaZiZuKadIl/c=; b=mGb2GjPMpo5einI6v+vymMibeQDV2rcstCmDsFC+CTwfIzLpWCXzmDSNTW4Ng/VIbQ Lfbhzix8jYFd2bZSAH6OfK1X4P7nJw6unIzpXtwyNFhFEL9MPWWxXqfONjt1YOVqppMx Hs7kmUS4kItkmiwX9q3cs4JChgoOlpPMNESJCF5cXP9MJSwvPesYoBhZV7oSzwKZFAYs Im9GtijBfKykKkvQDFtvU44VrgXsA2ryF8u++9TFhkG1NHW92jgglvnOZuyO2GCLW+E6 CXUUzRxwb8FEx3iGI3opuwxfn+iZtVzyGcmPyD/SRRVcx0uZUXLMuUyzxvDVHeeVvJu/ qFsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=szW3JQG930FKvjzbx7RUR8NrPsOs8RDaZiZuKadIl/c=; b=WkvSiLjTYabRnH/WHsRcJsB+pjg/ocw9NQu3D/cEG2KK6gcD3ClZAZcVguyXtWRPs5 3gd0ntHagzYepa8PsLaoaxxomWFffYxe5FeLHbJnApeIDddaupoSKoZWRMNkqP3Lp+ji /t+PN8ipXVUENa3HGtsXrSoiOEugpEPU8ngMu3SFrnXRR8W/4aCGxcO3sf9c5Cy1p2ty rMzbS5ueqHTjgAV5p5D7CPwjhykKRsw9UvQRJke+kvM1ertmOsIh3+SLpT7mqb3lq2+X zhSxgajLBnHqkw4/wn0bI4eDH5MKMCukas7uFCFTUnFevLkJZvX9hg3umEcoOAkVVuye D23A== X-Gm-Message-State: AOAM532hm3OouRffagu/zEiMr6pB5yrIkt9M/qYQbGPnoDsTMI3e2XWb vCCYvTniZneVOuSmhmTMw0pcRHq5cmY= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:109c:7eb8:d5ed:2e59]) (user=seanjc job=sendgmr) by 2002:a25:804:: with SMTP id 4mr44395426ybi.346.1629747447617; Mon, 23 Aug 2021 12:37:27 -0700 (PDT) Reply-To: Sean Christopherson Date: Mon, 23 Aug 2021 12:37:08 -0700 In-Reply-To: <20210823193709.55886-1-seanjc@google.com> Message-Id: <20210823193709.55886-3-seanjc@google.com> Mime-Version: 1.0 References: <20210823193709.55886-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog Subject: [PATCH 2/3] KVM: x86: Register Processor Trace interrupt hook iff PT enabled in guest From: Sean Christopherson To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Paolo Bonzini Cc: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Artem Kashkanov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: 8479e04e7d6b ("KVM: x86: Inject PMI for KVM guest") Cc: stable@vger.kernel.org Reported-by: Alexander Shishkin Reported-by: Artem Kashkanov Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/pmu.h | 1 + arch/x86/kvm/vmx/vmx.c | 1 + arch/x86/kvm/x86.c | 4 +++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 09b256db394a..1ea4943a73d7 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1494,6 +1494,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; }; diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h index 0e4f2b1fa9fb..b06dbbd7eeeb 100644 --- a/arch/x86/kvm/pmu.h +++ b/arch/x86/kvm/pmu.h @@ -41,6 +41,7 @@ struct kvm_pmu_ops { void (*reset)(struct kvm_vcpu *vcpu); void (*deliver_pmi)(struct kvm_vcpu *vcpu); void (*cleanup)(struct kvm_vcpu *vcpu); + void (*handle_intel_pt_intr)(void); }; static inline u64 pmc_bitmask(struct kvm_pmc *pmc) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index fada1055f325..f19d72136f77 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7896,6 +7896,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, }; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index fb6015f97f9e..b5ade47dad9c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8305,7 +8305,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 @@ -11061,6 +11061,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)) -- 2.33.0.rc2.250.ged5fa647cd-goog