Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1268437pxb; Sat, 15 Jan 2022 07:25:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDU5c0yn6PKe/6B5aEf3SnW8gbr44a+JMDMwWRB8syD/rLA/0HlefI2FN3qRWsRyX63ho+ X-Received: by 2002:a17:90b:4d88:: with SMTP id oj8mr16225010pjb.194.1642260337691; Sat, 15 Jan 2022 07:25:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642260337; cv=none; d=google.com; s=arc-20160816; b=c+Q2pYNFmyxosHhbd/iK5nlm3LCIVW6kn+uN44nYmb+AdsYTfpGSouXdML43G3LFNM krVKdldA8jtCpCXzQq7XNRJHSPKPCBEXuwolIsfgyuWsqHXar0Bw4e/Ry7uXHBuoOZ+r S/72X7ORmYdiukec2Kj9wuak2UT4t/BdjiBerU8RIu7+2w9bjTegdC1/EkLwIVrCzD/d WisGDIS6igty1dSqZ+H7K099lEq7X34nDpb52Sw9VvkLQpxDXNY4FEk7SFIiMVhgyI84 J2RRmuv1UWGgBkkzSG/Eu9ITq2QtL/WpKZbmynKUNnJ9WYLcwidn6EYkPDZLRuHN+emQ Jf0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=iGxhzdY+o8fZ08CLZJyGxW7d23UVHciFJHOknE38cZw=; b=ynvEN7f9z+k7EtPEknQUMi5lIZqk26lXCSXoduCOEKLyYHJgLCivuTMkSVodmewj3j osjyRs3bw778Q5ZJIbTYl0nYH+atR+itCDQhdlSGIWrMi4TMjg17kp1ni2VLlX9n8xLa d5i1rgxXBL7pd4VnvAHGWTfmBi3ASipZJiIbMKWLVvWeZHQvgJLQc0xMFajTbaGfUopD BclAyT/5cse82R2LjtYyNAzk1KRPkJjwVyXw0e42RQQuKW1ZG5dag4lF2l4KMuhk0EsF jdART/4Z6mtfg4K12E/81kJbIVcx5mEAJwMiHxZqMbIowqkJ8LU1uBHfag4qAHzO92lM npsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=iY7KJRBk; 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 202si117243pgg.750.2022.01.15.07.25.23; Sat, 15 Jan 2022 07:25:37 -0800 (PST) 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=20210112 header.b=iY7KJRBk; 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 S229580AbiAOB0c (ORCPT + 99 others); Fri, 14 Jan 2022 20:26:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbiAOB0b (ORCPT ); Fri, 14 Jan 2022 20:26:31 -0500 Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A095C06161C for ; Fri, 14 Jan 2022 17:26:31 -0800 (PST) Received: by mail-oo1-xc34.google.com with SMTP id q16-20020a4a3010000000b002dde2463e66so2959583oof.9 for ; Fri, 14 Jan 2022 17:26:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iGxhzdY+o8fZ08CLZJyGxW7d23UVHciFJHOknE38cZw=; b=iY7KJRBkntVU/rVadUv0PJdb2KFcPKF6PPUUe1IH2Di0GhGZ+a66TCmxaI27Sy6K+O xUleFpkSeSW8rDXQtCd/ZcIsHwxjTi2wj2abfIPaYDB0Gh1AdHQfRGa8ODwTfFypjeN3 h+iS6UO4wJDhB41ypCxmNXU1ZILBnL8je6tDO+mAMWOcI4iz+mBvbNDCxL1PqEQexXgr p8ojIWbPPFqewMueT3lthQW2KLwMTqbaScL87wYoUadMGXTaUX4i7SDAfUTUQ0+I7Iv4 c8bjM7BhMb7FrVn+cHVwma4ZPp1qBk1MbqcIlAiylmeRZelK0ikhu8JhhOd+ywqRpDEf Tf+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iGxhzdY+o8fZ08CLZJyGxW7d23UVHciFJHOknE38cZw=; b=UuKZU6UoF0N4lyI2/e8MIdvDsjxbvYB4SRxhgH1PGHTwrYRh0v3Q1WLu6n3tlx8+ip mobli78eQqaWhWj11M311K7Uj1XAWsMzmarChrl6uUavcL/SWNMnB+y8TjDtZx5J/kPN /LcupNQRBLx2lQJvzQe+Boop/H4rrj+JIb0qzTB7UVFMF8XX2pnl3ZzggFdjZrAPjqzl g5asOcyWkkmdNn9CiRkHdBCDuYuFRpuiosD7ey1k+DTcsAI+6r+ggKEaFJpQqA+yBlVZ qywCscjHIBOM3UbFLbjg7wpQGdAJagL2rjN20NTl3w8Ucg0EbisdhN6Okrl/fJNxgxWM 2dwg== X-Gm-Message-State: AOAM530Ii86hxjg66cDoLxD/+n5TrRvviCR1WINVGxDyYyDJLwqkr93P RL9l1JkHWZD55FyM2qPDxyUXRobelNiaMaXi3MuYGg== X-Received: by 2002:a4a:dc16:: with SMTP id p22mr8238076oov.85.1642209990389; Fri, 14 Jan 2022 17:26:30 -0800 (PST) MIME-Version: 1.0 References: <20211117080304.38989-1-likexu@tencent.com> In-Reply-To: From: Jim Mattson Date: Fri, 14 Jan 2022 17:26:19 -0800 Message-ID: Subject: Re: [PATCH] KVM: x86/svm: Add module param to control PMU virtualization To: Paolo Bonzini Cc: Like Xu , Maxim Levitsky , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 18, 2021 at 5:25 AM Paolo Bonzini wrote: > > On 11/17/21 09:03, Like Xu wrote: > > From: Like Xu > > > > For Intel, the guest PMU can be disabled via clearing the PMU CPUID. > > For AMD, all hw implementations support the base set of four > > performance counters, with current mainstream hardware indicating > > the presence of two additional counters via X86_FEATURE_PERFCTR_CORE. > > > > In the virtualized world, the AMD guest driver may detect > > the presence of at least one counter MSR. Most hypervisor > > vendors would introduce a module param (like lbrv for svm) > > to disable PMU for all guests. > > > > Another control proposal per-VM is to pass PMU disable information > > via MSR_IA32_PERF_CAPABILITIES or one bit in CPUID Fn4000_00[FF:00]. > > Both of methods require some guest-side changes, so a module > > parameter may not be sufficiently granular, but practical enough. > > > > Signed-off-by: Like Xu > > --- > > arch/x86/kvm/cpuid.c | 2 +- > > arch/x86/kvm/svm/pmu.c | 4 ++++ > > arch/x86/kvm/svm/svm.c | 11 +++++++++++ > > arch/x86/kvm/svm/svm.h | 1 + > > 4 files changed, 17 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > > index 2d70edb0f323..647af2a184ad 100644 > > --- a/arch/x86/kvm/cpuid.c > > +++ b/arch/x86/kvm/cpuid.c > > @@ -487,7 +487,7 @@ void kvm_set_cpu_caps(void) > > F(CR8_LEGACY) | F(ABM) | F(SSE4A) | F(MISALIGNSSE) | > > F(3DNOWPREFETCH) | F(OSVW) | 0 /* IBS */ | F(XOP) | > > 0 /* SKINIT, WDT, LWP */ | F(FMA4) | F(TBM) | > > - F(TOPOEXT) | F(PERFCTR_CORE) > > + F(TOPOEXT) | 0 /* PERFCTR_CORE */ > > ); > > > > kvm_cpu_cap_mask(CPUID_8000_0001_EDX, > > diff --git a/arch/x86/kvm/svm/pmu.c b/arch/x86/kvm/svm/pmu.c > > index fdf587f19c5f..a0bcf0144664 100644 > > --- a/arch/x86/kvm/svm/pmu.c > > +++ b/arch/x86/kvm/svm/pmu.c > > @@ -16,6 +16,7 @@ > > #include "cpuid.h" > > #include "lapic.h" > > #include "pmu.h" > > +#include "svm.h" > > > > enum pmu_type { > > PMU_TYPE_COUNTER = 0, > > @@ -100,6 +101,9 @@ static inline struct kvm_pmc *get_gp_pmc_amd(struct kvm_pmu *pmu, u32 msr, > > { > > struct kvm_vcpu *vcpu = pmu_to_vcpu(pmu); > > > > + if (!pmuv) > > + return NULL; > > + > > switch (msr) { > > case MSR_F15H_PERF_CTL0: > > case MSR_F15H_PERF_CTL1: > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > > index 21bb81710e0f..062e48c191ee 100644 > > --- a/arch/x86/kvm/svm/svm.c > > +++ b/arch/x86/kvm/svm/svm.c > > @@ -190,6 +190,10 @@ module_param(vgif, int, 0444); > > static int lbrv = true; > > module_param(lbrv, int, 0444); > > > > +/* enable/disable PMU virtualization */ > > +bool pmuv = true; > > +module_param(pmuv, bool, 0444); > > + > > static int tsc_scaling = true; > > module_param(tsc_scaling, int, 0444); > > > > @@ -952,6 +956,10 @@ static __init void svm_set_cpu_caps(void) > > boot_cpu_has(X86_FEATURE_AMD_SSBD)) > > kvm_cpu_cap_set(X86_FEATURE_VIRT_SSBD); > > > > + /* AMD PMU PERFCTR_CORE CPUID */ > > + if (pmuv && boot_cpu_has(X86_FEATURE_PERFCTR_CORE)) > > + kvm_cpu_cap_set(X86_FEATURE_PERFCTR_CORE); > > + > > /* CPUID 0x8000001F (SME/SEV features) */ > > sev_set_cpu_caps(); > > } > > @@ -1085,6 +1093,9 @@ static __init int svm_hardware_setup(void) > > pr_info("LBR virtualization supported\n"); > > } > > > > + if (!pmuv) > > + pr_info("PMU virtualization is disabled\n"); > > + > > svm_set_cpu_caps(); > > > > /* > > diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h > > index 0d7bbe548ac3..08e1c19ffbdf 100644 > > --- a/arch/x86/kvm/svm/svm.h > > +++ b/arch/x86/kvm/svm/svm.h > > @@ -32,6 +32,7 @@ > > extern u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly; > > extern bool npt_enabled; > > extern bool intercept_smi; > > +extern bool pmuv; > > > > /* > > * Clean bits in VMCB. > > > > Queued, thanks - just changed the parameter name to "pmu". Whoops! The global 'pmu' is hidden by a local 'pmu' in get_gp_pmc_amd().