Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp267616lqi; Wed, 6 Mar 2024 17:14:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV26C2AD9e0gIZkopkglazK4baZZVfJApt7NqANd/Kg557pzysu2FcHwL1JZuXtg/b2XOncIhUVBCBeI3op09OKj0wJToEXmRNR9VI36Q== X-Google-Smtp-Source: AGHT+IGy45THEcqd2DKPVmK85KPV3hWewIs2XMQHFOWIsftKHi2ZePmvcA9G6sYEBKuInNcva9zd X-Received: by 2002:ac2:548a:0:b0:513:59fb:1a4e with SMTP id t10-20020ac2548a000000b0051359fb1a4emr367684lfk.45.1709774055733; Wed, 06 Mar 2024 17:14:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709774055; cv=pass; d=google.com; s=arc-20160816; b=sp6e6So+/4NeSO4E1DZ3502CRU4sVTEimVlDyzoDJro+s26ysf8BYBpFparlbkAD+I W3kdxyhnBqA+aFFvEwoxKpSP/4Ia3T4eEgdRb3hypY1bxnBcFkThFjg+NMTsLy6lR7ON pKRH4PdJB35bFqLBmCeHRrV55LtMBceKl45BBW+HLF45s5SRJh9vAbDrodavC0V+UhdA hZumVDr9Q7B0IH6CnhlQPalWeKJ9eRHvW1iVJwUNekyOg3wojq2szo+wm42IR1hcmiV9 52mxYfK21vGSYjUD7K/BEtS6o7eglHdrI26xOsOiE/rdftSAU0OeGlE1rHlC8OimIa9S vxYg== 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=d9OkLWkUpGFKgtUTAFhUfP4KpjC4oBcPSpydtAFPWEY=; fh=RXUbBgVVb+xgr8r3eQLpUemABR+dfJLBVn0WVRVG4Js=; b=d0CgBOp71Bk27Ucb5OcnjIOUDBZ1ToOHAu8Z9ON81OlLoTVRkCWTyfRENo7PgaEgfF n8L0UfnItrfM5Ed0lzQyvIco8FB7r4Mj537Xf0ysMaZC1RjzcUo9aRZeG2mmcFQVpF3j Y+nfpd+Z8jZwetdrDxBGV1RawPXjlOHEoO9C6WBbD6KzTwf7XzKn4DKv2/PjmCljthEV CG/uBxorBnkb4BdmeawBWc70aztZBy0VesE8tPp34uIaEcRA65hQ3pPLFlcz14S7Fujk EWHgIL/v08YGBa6JGAMSWHoPJimfrG9CRMmIBBIv6B80y/UoB0iJ0bTNfnjnsyqycplu 6CtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Rx+W4kyP; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-94818-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94818-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q4-20020a170906770400b00a3eabc798basi6453163ejm.1019.2024.03.06.17.14.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 17:14:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94818-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Rx+W4kyP; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-94818-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94818-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4AF8A1F23F25 for ; Thu, 7 Mar 2024 01:14:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 23A366FC6; Thu, 7 Mar 2024 01:13:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Rx+W4kyP" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 A2E424A1E for ; Thu, 7 Mar 2024 01:13:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709774031; cv=none; b=jnuZIdG+BdGZ1m4biUGFwAflXC5eACXBjLQRXA6HG4u6WGTpjPeMcbZg6eqLhEHE1k1Iljnk3wophB/CqAM3wNgMgtGiz72kLvWbK8pgmzS1o7iLEKA4Pnp4WfauH5PULLjVr2rsZ9dH+xnnPvBAF856O0fjxzh97roeEj4dbko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709774031; c=relaxed/simple; bh=AVNvdObNYsvBPRRwBeScCDec7JNA2zRkhx+8VadcPaQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OxWKhWH/e5Cdz/CIZlz76K2xO/NvY383rVRU7r5uW8uDSXByBdWjq7Yw4xuqk7bUGBSWibYyXH1mfkINwLiyZnlMXr1h0x+EmiZ7fHw7fZIRXWmNlKaBmGUPI9vLgzolso+zcVpc05SoHdDAbBpev4anheuJ1mNsveyWbSkXFDQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Rx+W4kyP; arc=none smtp.client-ip=209.85.128.202 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--seanjc.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5ee22efe5eeso6158017b3.3 for ; Wed, 06 Mar 2024 17:13:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709774029; x=1710378829; 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=d9OkLWkUpGFKgtUTAFhUfP4KpjC4oBcPSpydtAFPWEY=; b=Rx+W4kyP8nbTCsQFCieZSroaLaXIGarCskUht94vg6kNKpZTE+W+gFdluMIxNo5XaT 5EXK1AlfSWXqb0AqX41Lrq9iP/hnN9/c8HaizZWKakq8wXiiJVnD5lWBbrfBnIxJXORG Qi8rSuWXg5CgxuS2WZIQ78iGiVoaj2Fv0AuIlUfFtaRI3ft2Z+oVOBdNIcJIEIFr+AAj gB3lnLq9v6CEPd7EyNdCK1Fe49LCSM6wulwMLwT4s45hupv+goeRNXJPSPOm4d7vtMEb 4HTCwipQBfw+P+2l+vYwxnEa/Zlw3g6UdZ24y1T0/cP/yYp5UczMfyG5QXZ1n+d/26lx ad5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709774029; x=1710378829; 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=d9OkLWkUpGFKgtUTAFhUfP4KpjC4oBcPSpydtAFPWEY=; b=ZjLh+Dord9F9IYeuKzVlXfve4cgu+XUeVf9JTh631SBXxiNvp7MOD+pY/4KlYJS0JJ +xztw7mbgbbocZAeu3WNJhwOG4mIdU7+Hbn9wInrjSsYYTVOi35t9X5LyH0yaXVtDb7R uOGqUqRYFYoBLv+bkXl4mtzmNYyrGuyCLx9228ETt7pW3V0DTX3QDc4tActptlrsbz0j bYkQczwVGUhm2nM2h+m28se9KmTFw4T2HX1gVkmzV/euOWMhBb5s/mR1UPqyHiF4mY30 VUpMPXOcfdTcj8VZCb+k5NDRYCv4TKDhho+ssQRItgB7FTNto0BQHXzwtavlmzfUjpYa 6gjw== X-Forwarded-Encrypted: i=1; AJvYcCXyNZeQ8aTirU8J+9hiX3j+JL9XZz5lxON0RrCr4Bj98qdMh517L1PutDrCBhhrL19L3jdBvXudNRL6Ayk/cqx06A6JPBrzaFMdO25d X-Gm-Message-State: AOJu0YystaWVoIVgAbaDYSSB8qW5KjFgQYayNZ4fcm0zBUiKtHNpIRCO lZllf7E0mMZZSmciwIluGctUiSHVqxvjYSOqYvO+rdgCMAi0+ZSTJCNGNxU+RBeQboEnwWcEBzJ JTA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:b9a:b0:609:6719:5660 with SMTP id ck26-20020a05690c0b9a00b0060967195660mr3471394ywb.9.1709774028810; Wed, 06 Mar 2024 17:13:48 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 6 Mar 2024 17:13:42 -0800 In-Reply-To: <20240307011344.835640-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240307011344.835640-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240307011344.835640-2-seanjc@google.com> Subject: [PATCH 1/3] KVM: VMX: Snapshot LBR capabilities during module initialization From: Sean Christopherson To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Sean Christopherson , Paolo Bonzini Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Mingwei Zhang , Jim Mattson Content-Type: text/plain; charset="UTF-8" Snapshot VMX's LBR capabilities once during module initialization instead of calling into perf every time a vCPU reconfigures its vPMU. This will allow massaging the LBR capabilities, e.g. if the CPU doesn't support callstacks, without having to remember to update multiple locations. Opportunistically tag vmx_get_perf_capabilities() with __init, as it's only called from vmx_set_cpu_caps(). Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/pmu_intel.c | 2 +- arch/x86/kvm/vmx/vmx.c | 9 +++++---- arch/x86/kvm/vmx/vmx.h | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 12ade343a17e..be40474de6e4 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -535,7 +535,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) perf_capabilities = vcpu_get_perf_capabilities(vcpu); if (cpuid_model_is_consistent(vcpu) && (perf_capabilities & PMU_CAP_LBR_FMT)) - x86_perf_get_lbr(&lbr_desc->records); + memcpy(&lbr_desc->records, &vmx_lbr_caps, sizeof(vmx_lbr_caps)); else lbr_desc->records.nr = 0; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 7a74388f9ecf..2a7cd66988a5 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -217,6 +217,8 @@ module_param(ple_window_max, uint, 0444); int __read_mostly pt_mode = PT_MODE_SYSTEM; module_param(pt_mode, int, S_IRUGO); +struct x86_pmu_lbr __ro_after_init vmx_lbr_caps; + static DEFINE_STATIC_KEY_FALSE(vmx_l1d_should_flush); static DEFINE_STATIC_KEY_FALSE(vmx_l1d_flush_cond); static DEFINE_MUTEX(vmx_l1d_flush_mutex); @@ -7844,10 +7846,9 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) vmx_update_exception_bitmap(vcpu); } -static u64 vmx_get_perf_capabilities(void) +static __init u64 vmx_get_perf_capabilities(void) { u64 perf_cap = PMU_CAP_FW_WRITES; - struct x86_pmu_lbr lbr; u64 host_perf_cap = 0; if (!enable_pmu) @@ -7857,8 +7858,8 @@ static u64 vmx_get_perf_capabilities(void) rdmsrl(MSR_IA32_PERF_CAPABILITIES, host_perf_cap); if (!cpu_feature_enabled(X86_FEATURE_ARCH_LBR)) { - x86_perf_get_lbr(&lbr); - if (lbr.nr) + x86_perf_get_lbr(&vmx_lbr_caps); + if (vmx_lbr_caps.nr) perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT; } diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index 65786dbe7d60..cc10df53966e 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -109,6 +109,8 @@ struct lbr_desc { bool msr_passthrough; }; +extern struct x86_pmu_lbr vmx_lbr_caps; + /* * The nested_vmx structure is part of vcpu_vmx, and holds information we need * for correct emulation of VMX (i.e., nested VMX) on this vcpu. -- 2.44.0.278.ge034bb2e1d-goog