Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3331341ybi; Fri, 19 Jul 2019 01:27:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzShJVD0T3N16F4PFM6pSi6wbwquA5l1RvHVThqaHvHtcoeFaBcM8w8246LWIgdOk+2fS0G X-Received: by 2002:a17:90a:109:: with SMTP id b9mr53626913pjb.112.1563524853529; Fri, 19 Jul 2019 01:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563524853; cv=none; d=google.com; s=arc-20160816; b=VGNwVpuQyY1Qmvb8o0vSoNwAntHEjHudkF00EAA8F24qRyfyr2kNx3jh1osqWWn2S0 s1igHvMJuArMQe+yonSkYuMGQmiC1zH1dGMKO8X06d4IZKN6SjlzkEt24wJvnZpG4f4z xSRgWqn2q9glmR9HKjjupqoN4rqK+CZyxjIkmecrqGhkQtvisgp2JT5av4w7pHln7Ckh oXVZuvb6RfydYTQeMYLfYah4IZrsYHE3F1cwjQpylzXDFoYjZ5lq3wgi2k84qdUX8zzx jNAB9ObA2W73FIXDIAUo6RTRAXR2joTC2oXZ4oc3BCO0HMrb6FKpnvgxICn0czCFHXrt LDSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :references:subject:cc:to:mime-version:user-agent:from:date :message-id; bh=5BizAIb9XdyGanJendp6R6vTOjQ7hY6ts0lLGRNhfPo=; b=xOdj9D3+NSKQxJMYOFQ0i9Uv1FmfVDhh86cGZ+oJRb1OG+i+SkXST69HeyAyd69ZGp 55chxku6oAJF02iHqQBoeOW5WszDdS5lgNsYzyFghwBMk7dQVTpsqPZr3lGbwTlYVu2Z Jxq3XuaWEEGQhjcXZTCxe0q7j5ob/Uoeunv9ztDzZqTS2Rcr8tYnvOb2CPBIfNUksua2 cmtFX7jXDaqmZTSuK1obLY0blF/qCifCTYRXMobaAFb/8PwWf+ECW/VCG4TrPXDHaUOc +5FYBTfl6tIDfSKflAetB+Ffdj8gqpP3T3Ig9mUUv5fsxQDm9B+DpFw8ZG5I4DoTziWo SKjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m37si539788pje.45.2019.07.19.01.27.17; Fri, 19 Jul 2019 01:27:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727005AbfGSI0W (ORCPT + 99 others); Fri, 19 Jul 2019 04:26:22 -0400 Received: from mga14.intel.com ([192.55.52.115]:51802 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725853AbfGSI0W (ORCPT ); Fri, 19 Jul 2019 04:26:22 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jul 2019 01:26:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,281,1559545200"; d="scan'208";a="319903679" Received: from unknown (HELO [10.239.13.7]) ([10.239.13.7]) by orsmga004.jf.intel.com with ESMTP; 19 Jul 2019 01:26:18 -0700 Message-ID: <5D317FFA.8000507@intel.com> Date: Fri, 19 Jul 2019 16:31:54 +0800 From: Wei Wang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Eric Hankland , Paolo Bonzini CC: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Stephane Eranian Subject: Re: [PATCH] KVM: x86: Add fixed counters to PMU filter References: <20190718183818.190051-1-ehankland@google.com> In-Reply-To: <20190718183818.190051-1-ehankland@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/19/2019 02:38 AM, Eric Hankland wrote: > From: ehankland > > Updates KVM_CAP_PMU_EVENT_FILTER so it can also whitelist or blacklist > fixed counters. > > Signed-off-by: ehankland > --- > Documentation/virtual/kvm/api.txt | 13 ++++++++----- > arch/x86/include/uapi/asm/kvm.h | 9 ++++++--- > arch/x86/kvm/pmu.c | 30 +++++++++++++++++++++++++----- > 3 files changed, 39 insertions(+), 13 deletions(-) > > diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt > index 2cd6250b2896..96bcf1aa1931 100644 > --- a/Documentation/virtual/kvm/api.txt > +++ b/Documentation/virtual/kvm/api.txt > @@ -4090,17 +4090,20 @@ Parameters: struct kvm_pmu_event_filter (in) > Returns: 0 on success, -1 on error > > struct kvm_pmu_event_filter { > - __u32 action; > - __u32 nevents; > - __u64 events[0]; > + __u32 action; > + __u32 nevents; > + __u32 fixed_counter_bitmap; > + __u32 flags; > + __u32 pad[4]; > + __u64 events[0]; > }; > > This ioctl restricts the set of PMU events that the guest can program. > The argument holds a list of events which will be allowed or denied. > The eventsel+umask of each event the guest attempts to program is compared > against the events field to determine whether the guest should have access. > -This only affects general purpose counters; fixed purpose counters can > -be disabled by changing the perfmon CPUID leaf. > +The events field only controls general purpose counters; fixed purpose > +counters are controlled by the fixed_counter_bitmap. > > Valid values for 'action': > #define KVM_PMU_EVENT_ALLOW 0 > diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h > index e901b0ab116f..503d3f42da16 100644 > --- a/arch/x86/include/uapi/asm/kvm.h > +++ b/arch/x86/include/uapi/asm/kvm.h > @@ -435,9 +435,12 @@ struct kvm_nested_state { > > /* for KVM_CAP_PMU_EVENT_FILTER */ > struct kvm_pmu_event_filter { > - __u32 action; > - __u32 nevents; > - __u64 events[0]; > + __u32 action; > + __u32 nevents; > + __u32 fixed_counter_bitmap; > + __u32 flags; > + __u32 pad[4]; > + __u64 events[0]; > }; > > #define KVM_PMU_EVENT_ALLOW 0 > diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c > index aa5a2597305a..ae5cd1b02086 100644 > --- a/arch/x86/kvm/pmu.c > +++ b/arch/x86/kvm/pmu.c > @@ -19,8 +19,8 @@ > #include "lapic.h" > #include "pmu.h" > > -/* This keeps the total size of the filter under 4k. */ > -#define KVM_PMU_EVENT_FILTER_MAX_EVENTS 63 > +/* This is enough to filter the vast majority of currently defined events. */ > +#define KVM_PMU_EVENT_FILTER_MAX_EVENTS 300 > > /* NOTE: > * - Each perf counter is defined as "struct kvm_pmc"; > @@ -206,12 +206,25 @@ void reprogram_fixed_counter(struct kvm_pmc *pmc, u8 ctrl, int idx) > { > unsigned en_field = ctrl & 0x3; > bool pmi = ctrl & 0x8; > + struct kvm_pmu_event_filter *filter; > + struct kvm *kvm = pmc->vcpu->kvm; > + unnecessary white space here, other part looks good to me. Reviewed-by: Wei Wang Best, Wei