From nobody Tue Feb 10 07:40:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1632269174; cv=none; d=zohomail.com; s=zohoarc; b=axiFZz/SxaiJARpFccTTXqLH47+OnzZrgBqnVi+cj7O1h9ZA8kgGCzvk8Ut9PHjsLac0x0Da4/Bdl1TF50iTn5X6uwPd21k1GKD9xM4iKCE6ZQr5EdQEruMCdf54fxbLIgfRxE1Eba2/uhHv2xDE55y/rfP318+o593ax0HTRHo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632269174; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=WoefsUy8P8uVLjBhkd6fplSxv9zXtwFfZO3aWK09BqE=; b=KxKbb9yPyr91YJmTy5TsysAV/ON2sBpldX1gmLzGYC9TSb02gpPubR9iUGQY24plIFxXJ4f+tfYjHpK5GzE6dZD4briH+uZ12YsVr+qenk3tfv7bfYIicyhHXz6ZqAc4QekHRvTttcQb9G11mCr5v81Klk9oVcwhWf0aSuIHf9s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1632269174757397.8485226748061; Tue, 21 Sep 2021 17:06:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.191986.342206 (Exim 4.92) (envelope-from ) id 1mSplx-0001oN-Gh; Wed, 22 Sep 2021 00:06:01 +0000 Received: by outflank-mailman (output) from mailman id 191986.342206; Wed, 22 Sep 2021 00:06:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mSplx-0001oG-Ce; Wed, 22 Sep 2021 00:06:01 +0000 Received: by outflank-mailman (input) for mailman id 191986; Wed, 22 Sep 2021 00:05:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mSplv-0000pt-PV for xen-devel@lists.xenproject.org; Wed, 22 Sep 2021 00:05:59 +0000 Received: from mail-qk1-x749.google.com (unknown [2607:f8b0:4864:20::749]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ac59d283-ef6f-43ef-b078-c6d60780eaee; Wed, 22 Sep 2021 00:05:50 +0000 (UTC) Received: by mail-qk1-x749.google.com with SMTP id w2-20020a3794020000b02903b54f40b442so6728543qkd.0 for ; Tue, 21 Sep 2021 17:05:50 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ac59d283-ef6f-43ef-b078-c6d60780eaee DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=WoefsUy8P8uVLjBhkd6fplSxv9zXtwFfZO3aWK09BqE=; b=W3dvAswYaFrMhdUxOnj+C5EXMMEyJrI4w2EWKYkJvgEgkHuR8IaKKfSJHg9j0xw5+k fgorvfW1/YzGQUtW4RZ95gDG0qA72H/qeIgYOd+4TOG6c+1wocOOu3VRxQzsB6jGSO5g yRDdyBni9EhmFEE/PynpUeNnGYgcYXTu6HydYJ60R/86lZ/rosIKMEDAP+lTix9jhUIs 1g7+eQ1MkKa4HLPulfOq0mS5b56v1Wn9wTgMBlG9vvFK/yuOUIxbO5OMIO050BN1ziI7 quI8vYbT72gL4MHo6ScRZ81Wr5yMBwO1kb48G3KB1R6pXXjpQyqrpGzih9Su7JxvCNCF qqhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=WoefsUy8P8uVLjBhkd6fplSxv9zXtwFfZO3aWK09BqE=; b=8JkYGt9AFKK9fxlN5HT0T0FQacaAuxTjAWY1k7easL+z1G0mWtfqypZJaY8QjfE62p x8yRU1OcNWHdyDO0QgE8dJlZT3LmKJD3uFHxJ8DtWVvVaCYCR4zCYyryKSQXr+lx25VC XqtdM4D8ZdIOLMVYZ8PMFWtAESqOZWipcBowtLsbvkdOwmwyGm96Ahoi2hPVD7GTfkj+ 8ub4nkVinJY4ffpwfGi9Ge2wJn+J2JMr1zkLdaArXqSj7CcBDhZYbkBcsQwGvOudCXY3 IiqiSdqbGCV1vztCrhQr9gc2aphV//u51GL69WR1EH1qUWpnyEmTrJSGflr3pDqWTIqJ yN7g== X-Gm-Message-State: AOAM532n8RXTyT2RWh/ZdgN36wt0G+5bJfYawIyt+QBZdAmGPBIopsP7 jFgdo9+w80BclW/navCCG32c8R/8eoE= X-Google-Smtp-Source: ABdhPJydgoIIy+PWW+KTdPOq8w+CNl9+TVcl5SdFV/4H0FYG9MktEVuetKxR7qEx7VklEO7jLEzl555CBZg= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:b022:92d6:d37b:686c]) (user=seanjc job=sendgmr) by 2002:a25:2cd6:: with SMTP id s205mr42869270ybs.445.1632269150043; Tue, 21 Sep 2021 17:05:50 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 21 Sep 2021 17:05:20 -0700 In-Reply-To: <20210922000533.713300-1-seanjc@google.com> Message-Id: <20210922000533.713300-4-seanjc@google.com> Mime-Version: 1.0 References: <20210922000533.713300-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog Subject: [PATCH v3 03/16] KVM: x86: Register Processor Trace interrupt hook iff PT enabled in guest From: Sean Christopherson To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Will Deacon , Mark Rutland , Marc Zyngier , Guo Ren , Nick Hu , Greentime Hu , Vincent Chen , Paul Walmsley , Palmer Dabbelt , Albert Ou , Paolo Bonzini , Boris Ostrovsky , Juergen Gross Cc: Alexander Shishkin , Jiri Olsa , Namhyung Kim , James Morse , Alexandru Elisei , Suzuki K Poulose , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Stefano Stabellini , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, Artem Kashkanov , Like Xu , Zhu Lingshan X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1632269176009100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Cc: Like Xu Reported-by: Alexander Shishkin Reported-by: Artem Kashkanov Signed-off-by: Sean Christopherson Acked-by: Paolo Bonzini --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/vmx/vmx.c | 1 + arch/x86/kvm/x86.c | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.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); =20 struct kvm_x86_ops *runtime_ops; }; 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 __initdat= a =3D { .disabled_by_bios =3D vmx_disabled_by_bios, .check_processor_compatibility =3D vmx_check_processor_compat, .hardware_setup =3D hardware_setup, + .intel_pt_intr_in_guest =3D vmx_pt_mode_is_host_guest, =20 .runtime_ops =3D &vmx_x86_ops, }; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index fb6015f97f9e..ffc6c2d73508 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= =3D { .is_in_guest =3D kvm_is_in_guest, .is_user_mode =3D kvm_is_user_mode, .get_guest_ip =3D kvm_get_guest_ip, - .handle_intel_pt_intr =3D kvm_handle_intel_pt_intr, + .handle_intel_pt_intr =3D NULL, }; =20 #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(); =20 + if (ops->intel_pt_intr_in_guest && ops->intel_pt_intr_in_guest()) + kvm_guest_cbs.handle_intel_pt_intr =3D kvm_handle_intel_pt_intr; perf_register_guest_info_callbacks(&kvm_guest_cbs); =20 if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES)) @@ -11091,6 +11093,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 =3D NULL; =20 static_call(kvm_x86_hardware_unsetup)(); } --=20 2.33.0.464.g1972c5931b-goog