From nobody Sat Apr 25 11:48:44 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43301C43334 for ; Tue, 12 Jul 2022 01:58:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229623AbiGLB6p (ORCPT ); Mon, 11 Jul 2022 21:58:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbiGLB6n (ORCPT ); Mon, 11 Jul 2022 21:58:43 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6709465B9 for ; Mon, 11 Jul 2022 18:58:41 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id h11-20020a170902f54b00b0016bfdca124fso4761102plf.9 for ; Mon, 11 Jul 2022 18:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:message-id:mime-version:subject:from:to:cc; bh=Y0CjAgq6supMoxk4TH1/4zRwjn0Pact/l2vMZyAt9GA=; b=QJaAKqQCW0/d5mjHyaHxMaXEl3uqeGDeikCIDIdSj//Q2pJ1NIJV//lz0ua65/T8qK jFbSoghPVz7L3q1i0RLtAQe8+hW7jPEDJ1sj4USQ+wYCNAbBdTbeZavgxKqKWIUdNgNa viKgW/k8XS9/ZgN9abeg0oJWqVVy/jy3VsmS4vNLud4CbEswyR0yT1rN4rJux4OtSJOG 5IAUwsMxue/ZEiq1kWHTwQaTjQQJL7W2sM0OayxHKh7GB06XzPx5H5HVYdHUNIz7wfww IluC9iQZefTx1yw80Dm3aiz656NLyCGeLVrKVFLzb/K9T1IWq4cVwOJDFlacIwl6JDPV z8tg== 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:message-id:mime-version:subject :from:to:cc; bh=Y0CjAgq6supMoxk4TH1/4zRwjn0Pact/l2vMZyAt9GA=; b=VEOZgzElaFmtcDcBvvCR/mCYoVELbkkU1hLdnioKqOSzC11gJ+IZNzu5gR+ueWIyV8 yFpB/RWoG9H7rJmx4tWrxw94fR84HK23m8vx62ufQuxpXE0SE0mGgsvLgehL39VgTCGL wSGOFFYbumzmNo5uap06foViSUBDlQ89i/PG5j5dtRBwlcaP/DuMK7gD27gBWeO12/1w Vttj4EvDH4nA1Lfcyt8Y/KpH3Xk95otwEZhzfemrOFnQbQ9PeBI3pOI94FpTG515UVuh B5meHz37XQ8fnoD4V/DCeL/yPtF6wni+7/3/rmnRuPG72s0ytcuYf3QvX9wKhgnKVGVO uEdw== X-Gm-Message-State: AJIora/O+WpY6GH74rSot9YXvDBEU+mcwg4kHQuF/1iF2JD2hjwHhKgP CYaNHxleaI9g6j8icT9ckOMARbHW4xQ= X-Google-Smtp-Source: AGRyM1sNI+6xOoDh+FCD+9HNCz58MEGIGdZiC6EF2YWTRAH3vdRMA795CEPy0BOmw00HoZFwU6YOTXpJpHc= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:1496:b0:52a:c3fb:8ec7 with SMTP id v22-20020a056a00149600b0052ac3fb8ec7mr11708706pfu.25.1657591120960; Mon, 11 Jul 2022 18:58:40 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 12 Jul 2022 01:58:38 +0000 Message-Id: <20220712015838.1253995-1-seanjc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.0.144.g8ac04bfd2-goog Subject: [PATCH] KVM: VMX: Update PT MSR intercepts during filter change iff PT in host+guest From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiaoyao Li Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update the Processor Trace (PT) MSR intercepts during a filter change if and only if PT may be exposed to the guest, i.e. only if KVM is operating in the so called "host+guest" mode where PT can be used simultaneously by both the host and guest. If PT is in system mode, the host is the sole owner of PT and the MSRs should never be passed through to the guest. Luckily the missed check only results in unnecessary work, as select RTIT MSRs are passed through only when RTIT tracing is enabled "in" the guest, and tracing can't be enabled in the guest when KVM is in system mode (writes to guest.MSR_IA32_RTIT_CTL are disallowed). Cc: Xiaoyao Li Signed-off-by: Sean Christopherson Reviewed-by: Xiaoyao Li --- arch/x86/kvm/vmx/vmx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 74ca64e97643..e6ab2c2c4d3b 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4004,7 +4004,9 @@ static void vmx_msr_filter_changed(struct kvm_vcpu *v= cpu) vmx_disable_intercept_for_msr(vcpu, msr, MSR_TYPE_W); } =20 - pt_update_intercept_for_msr(vcpu); + /* PT MSRs can be passed through iff PT is exposed to the guest. */ + if (vmx_pt_mode_is_host_guest()) + pt_update_intercept_for_msr(vcpu); } =20 static inline void kvm_vcpu_trigger_posted_interrupt(struct kvm_vcpu *vcpu, base-commit: 5406e590ac8fa33e390616031370806cdbcc5791 --=20 2.37.0.144.g8ac04bfd2-goog