Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp817017rdb; Tue, 23 Jan 2024 16:40:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQRajqD2vudb7FaVOJj0NuZudg8B3n4Xhjj91NRP9uSE1vfiw4YtN0A+hTgOXVFMT3NJSp X-Received: by 2002:a05:620a:bcd:b0:783:5099:79c1 with SMTP id s13-20020a05620a0bcd00b00783509979c1mr9160373qki.93.1706056843538; Tue, 23 Jan 2024 16:40:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706056843; cv=pass; d=google.com; s=arc-20160816; b=XCyEt0u2VC/nafzqlh46d5mkGxhFdWMm3+SLWfaibaA3PrdsEjtqj/0fuai9RDLSxc hlMdgHR87VLRL3ZgROvhFYd67Fka4A4hxhBfKhN3cpXgx0KqGe4DvgJ/n1glvYNuPx7A DO2LiKx6hhfv91bMuO5XXQ0I0jDOhnjKrz1PmDeLyxgJe5ehZndjoSLSjDnOK2Je2fhO CyKQtFCfMgadSdMIK+fyERvMWgRKEy/EU5lUpk9r9fW3Dx0lYUM+fAbWwvpFezpFESCe l7mpStQ8L1w18SYmTWcZ3NaRCSHZVMa9lipQ4s7EGjfourMfVzerunVHP49w2CRKtflo YilQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=FZPx6jaS+VlPs9U7Plzj144efeFD6kMtS2nhR6IMeJ0=; fh=BmxsMTAymmGF1UJR5MpB1hk/0oqfyaaP+WHwoCwyPO4=; b=woq3gVgV29wmUMrCFh1Ku5fHrspjyPg4AroaCmFalQ6ZWL24uB3DC4LKsbCh+PGMgR uqlJrrl7Jo++43GRYPqTBv1Gl+6b5clBes7IgY/yN6JMq9YQYdJS49B2sBmJ1uYROkHC GMLc0ZNe/crTHxu1LRyL9uKNqomYAG8nuf6oW4cOiLn9f7av6nmFERgx3OtTMJbmCrGD QBp1mgHXvGOY5e73H9HsM7rPR3PoFSTQkTdlTDSNBBqq4DpKXCSh3PLodZzTSE8fbDqu sFPWVdmuKdjTNVSKa5qWdKWigcGOl8hLhL7lBvaBbPPnCgYDedpto9T40B4TEJ/2Z/Il 7gXg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QZvNqtW1; arc=pass (i=1 spf=pass spfdomain=flex--mizhang.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-36229-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36229-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ee12-20020a05620a800c00b00783ac6d6940si2402488qkb.480.2024.01.23.16.40.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 16:40:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36229-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QZvNqtW1; arc=pass (i=1 spf=pass spfdomain=flex--mizhang.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-36229-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36229-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7995E1C2764D for ; Wed, 24 Jan 2024 00:40:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34B938814; Wed, 24 Jan 2024 00:39:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QZvNqtW1" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E081A46AA for ; Wed, 24 Jan 2024 00:39:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706056753; cv=none; b=GWYyNa6B3CNGfYRZtI9yUiji5Vh4jQlhgHsZ0hEgw92fHaSObEXk2idhzLUf5mfmHZN+ZvBqqalffL97XXC8hhDKYXzwXn3i1sAtMp/xKJOt/PcVO6bQ5fvIPbCf/T82TqamCbDIE0pyXKo3tNlKgZ4XIVAQo50fNTdTBwNeYpI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706056753; c=relaxed/simple; bh=d47FqiBmt2oY1UnGiiPAsKGV/K1xPRRMHQa1eYmYyd8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AXTlmTcL3YZR2Jaw7XAUTFKH98lRGi03LWaeJe8sFJOzq5eZGLSoXeIxyZy5N3Oc9OwTGJld8tgYFGpi2Me4OYCXTGxmByb1YcskTID7eYSGsVxmMrar0vxNpo/o2yDW5K4HuKk8/hKx1BbeKGEPSYhkZbUWDRH78Xw4xXKLf5k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mizhang.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QZvNqtW1; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mizhang.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc365b303abso2741497276.3 for ; Tue, 23 Jan 2024 16:39:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706056751; x=1706661551; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=FZPx6jaS+VlPs9U7Plzj144efeFD6kMtS2nhR6IMeJ0=; b=QZvNqtW1K5neCEhphKF66B15SarKJB3xYcoPBIPDn1qqArAJ15x5UOnbh5Wefkem+h c+nCKOZlZZ2sZdnIKUnVCWSeqE2x4sXVx3Hexmwahm2c05UBvCQGxi2CykbtfqUqnvjz yjeZvVNwO75rWJxsC3n8muwHYU5WprdC09sVuvalEqu0mtmwqB+9LknPWBtHf62flUQT 2rFfsrNU+v2AtACMEJYzuxoRUyn2Q1064OEk7lFfmZ6I8JDcRuuW079CUa7M5CLdI4GZ fVDyGrg7wIgNNBQSA038aCJhT7tQ64W75Ool0h6wqWwypyH5a1Ra5Q2anZcpM+EUkRgZ Mn6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706056751; x=1706661551; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FZPx6jaS+VlPs9U7Plzj144efeFD6kMtS2nhR6IMeJ0=; b=U/L6JaXLboMLnNr8fde58WutBehJ89E5Y+0p9VIyrnYxDyeWTGdpLPmKlA/ONI0wmT fYMd8tF9HR0A/X0bc9T8aehdQGpHjpcA1sWgSKxzPB9H3NQf9uWehPCjCgZLtBQuciBL JFA3z6nhLECAhf3pojrkrKNYQxwCdS3f/4UUSChl6XaQtVwfU2A4ObYQXPpKodJIBSa1 vD3YWYLfB8Tc7nq/0F6TObs4dqHdpKNlnMtA8s2YqgalBWVyqrg/JRwAp5rZRzzfegdE qTGMdCi1tNxNqJtrhdlgJXVQOcelvF1hL5VpvekWBCPMRFkPcDSCUEsuTZY14O/sPZlg ZxQg== X-Gm-Message-State: AOJu0YwuNabbXm/MhvcIVnY0B2CSXmzCHAQ5AytPcVvax22J++3eJ1IX 1zJc9hH8QBhA0pfYq0jLaNU6wMPplRw8IVtpQKvRzO50xErURW1RqLwHI8sDp9e33d9yI6/5Ds6 jg0TFCA== X-Received: from mizhang-super.c.googlers.com ([35.247.89.60]) (user=mizhang job=sendgmr) by 2002:a05:6902:987:b0:dc2:2847:b34a with SMTP id bv7-20020a056902098700b00dc22847b34amr672ybb.9.1706056750785; Tue, 23 Jan 2024 16:39:10 -0800 (PST) Reply-To: Mingwei Zhang Date: Wed, 24 Jan 2024 00:38:57 +0000 In-Reply-To: <20240124003858.3954822-1-mizhang@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240124003858.3954822-1-mizhang@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240124003858.3954822-3-mizhang@google.com> Subject: [PATCH 2/2] KVM: x86/pmu: Remove vcpu_get_perf_capabilities() From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini Cc: "H. Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Aaron Lewis , Mingwei Zhang Content-Type: text/plain; charset="UTF-8" Remove vcpu_get_perf_capabilities() helper and directly use the vcpu->arch.perf_capabilities which now contains the true value of IA32_PERF_CAPABILITIES if exposed to guest (and 0 otherwise). This should slightly improve performance by avoiding the runtime check of X86_FEATURE_PDCM. Signed-off-by: Mingwei Zhang --- arch/x86/kvm/vmx/pmu_intel.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index a6216c874729..7cbee2d16ed9 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -158,17 +158,9 @@ static struct kvm_pmc *intel_rdpmc_ecx_to_pmc(struct kvm_vcpu *vcpu, return &counters[array_index_nospec(idx, num_counters)]; } -static inline u64 vcpu_get_perf_capabilities(struct kvm_vcpu *vcpu) -{ - if (!guest_cpuid_has(vcpu, X86_FEATURE_PDCM)) - return 0; - - return vcpu->arch.perf_capabilities; -} - static inline bool fw_writes_is_enabled(struct kvm_vcpu *vcpu) { - return (vcpu_get_perf_capabilities(vcpu) & PMU_CAP_FW_WRITES) != 0; + return (vcpu->arch.perf_capabilities & PMU_CAP_FW_WRITES) != 0; } static inline struct kvm_pmc *get_fw_gp_pmc(struct kvm_pmu *pmu, u32 msr) @@ -207,13 +199,13 @@ static bool intel_is_valid_msr(struct kvm_vcpu *vcpu, u32 msr) case MSR_CORE_PERF_FIXED_CTR_CTRL: return kvm_pmu_has_perf_global_ctrl(pmu); case MSR_IA32_PEBS_ENABLE: - ret = vcpu_get_perf_capabilities(vcpu) & PERF_CAP_PEBS_FORMAT; + ret = vcpu->arch.perf_capabilities & PERF_CAP_PEBS_FORMAT; break; case MSR_IA32_DS_AREA: ret = guest_cpuid_has(vcpu, X86_FEATURE_DS); break; case MSR_PEBS_DATA_CFG: - perf_capabilities = vcpu_get_perf_capabilities(vcpu); + perf_capabilities = vcpu->arch.perf_capabilities; ret = (perf_capabilities & PERF_CAP_PEBS_BASELINE) && ((perf_capabilities & PERF_CAP_PEBS_FORMAT) > 3); break; @@ -577,7 +569,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) bitmap_set(pmu->all_valid_pmc_idx, INTEL_PMC_MAX_GENERIC, pmu->nr_arch_fixed_counters); - perf_capabilities = vcpu_get_perf_capabilities(vcpu); + perf_capabilities = vcpu->arch.perf_capabilities; if (cpuid_model_is_consistent(vcpu) && (perf_capabilities & PMU_CAP_LBR_FMT)) x86_perf_get_lbr(&lbr_desc->records); -- 2.43.0.429.g432eaa2c6b-goog