Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp552232rdf; Fri, 3 Nov 2023 08:13:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkmGqSrUBj56lufDMwScgK0l1cKUUGnr7lMyHHh3aJXmOBi96jmpEMUbHCYLRullcCgQn5 X-Received: by 2002:a17:902:fac3:b0:1cc:4eb1:edaa with SMTP id ld3-20020a170902fac300b001cc4eb1edaamr13270867plb.51.1699024412830; Fri, 03 Nov 2023 08:13:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699024412; cv=none; d=google.com; s=arc-20160816; b=vJemSxhktisIWOOsD6/2whhnwnKu7gY6ERsa5Jqt8WlG7YfpDQIjjtq5E7Hh5t6MZm 207X7gZpBW/ePBe+gxDccUeswB8i8suIV3TepTneqC2KhA31usGlrK2kYsGya7PDJzi8 nxt0FlN+2nXVDX9IY0DJlYsnPFsLa2HXyfMTKOHzeK1YftB3eoC+1uyXoFWHEm9qDjmQ 60GB4cEDv7VkiudNW8s1SGtIBrpoOIuBSm+37n3AZYdGjx0UO9/snUknB3Qvp8n7BzKg eWPJboAEEK08faQfeWfriTtMfb1eN4r12XGegyJkaotszfVUsos+2U94r7RS6DbcXGd2 jUMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=arq0hvu3lHkHKk69xIUo6o5RBTCgWgCvkN74pZ5AkFE=; fh=2VgSTwMAevFTBQBPbMzecJpl6otBDl3peSrnerSURiM=; b=Sc6TfAsX9T65XcLMKM8hR+ZAkwrdMXsLCpAc2dev7Ebwrp5o6Lgc8SgDkrB4bUHgf/ acy+IezzTmW0lBp1WEJ39tO+PREa7clqO/+NU7icS/3NDMugdM9gaMpSwacmOlrT2Bpc 3dA6hVFGIStQ/zrC5yFXajK5+txHMPyV+EXJhAZ35FoLQa/raXY/EY3IKkfeKiBBGPxo oKofEzAivbXxGtumtoFhx45vld/DbWosFfenIVypl+OEQwNg6ceR9xgEfpzAQvokq5hE 2UH8kK2NavCVUk7ywHC/Db50TpKDFaVTqAnxx4LwYV9GFRRcIVMVJLE5SMjggSV2TL2+ 9g+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Lj+wE/kz"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id l11-20020a170902f68b00b001c3fcfb8000si1661812plg.506.2023.11.03.08.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 08:13:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Lj+wE/kz"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id D58878243B64; Fri, 3 Nov 2023 08:13:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233151AbjKCPNJ (ORCPT + 99 others); Fri, 3 Nov 2023 11:13:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231825AbjKCPNI (ORCPT ); Fri, 3 Nov 2023 11:13:08 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20BFED52; Fri, 3 Nov 2023 08:13:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699024380; x=1730560380; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=jjAzBvdNqU+zJFD678xcgoXGtuJCwhpDnpe6k8NVQRE=; b=Lj+wE/kzKmjVdKopp6wEiopfZ8NG0/9tPXeEWjayPBuXAmkpflCPwC0P PPE8n8h5WQE+LfAQHmZdG4xD+aKTaPlN2+afGCyLGJ8DFbKRS7LE4VfZL e1NxnaB2U2nFv0t5f3974dVNRhtIFTx+S5l7KbL0jUVCm5uXrpE3kUr// kEzgtZo+X3JBiwX91QEfwbpwuMR1tfyXgGFiSMxpq5PgPfGFWP0I+TR70 NOWSDYhgYRSZzaUuxcoNREeAhCNSXxNxi04ch26gJ4RHH4phIdJVV1uux vVTmjVRqDT2cXahfF/di3oYAAT6DblQexkGPcPmPH4wh+RcusYFEAP4vQ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="373998421" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="373998421" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 08:12:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="2918519" Received: from linux.intel.com ([10.54.29.200]) by fmviesa002.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 08:12:58 -0700 Received: from [10.209.173.25] (kliang2-mobl1.ccr.corp.intel.com [10.209.173.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by linux.intel.com (Postfix) with ESMTPS id 54945580223; Fri, 3 Nov 2023 08:12:56 -0700 (PDT) Message-ID: <2004baa6-b494-462c-a11f-8104ea152c6a@linux.intel.com> Date: Fri, 3 Nov 2023 11:12:54 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [Patch 1/2] KVM: x86/pmu: Add Intel CPUID-hinted TopDown slots event To: Jim Mattson , "Mi, Dapeng" Cc: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhang Xiong , Mingwei Zhang , Like Xu , Dapeng Mi , Like Xu References: <20231031090613.2872700-1-dapeng1.mi@linux.intel.com> <20231031090613.2872700-2-dapeng1.mi@linux.intel.com> <85706bd7-7df0-4d4b-932c-d807ddb14f9e@linux.intel.com> Content-Language: en-US From: "Liang, Kan" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 03 Nov 2023 08:13:28 -0700 (PDT) On 2023-11-02 1:45 p.m., Jim Mattson wrote: > On Wed, Nov 1, 2023 at 7:07 PM Mi, Dapeng wrote: >> >> >> On 11/1/2023 9:33 PM, Liang, Kan wrote: >>> >>> On 2023-10-31 11:31 p.m., Mi, Dapeng wrote: >>>> On 11/1/2023 11:04 AM, Jim Mattson wrote: >>>>> On Tue, Oct 31, 2023 at 6:59 PM Mi, Dapeng >>>>> wrote: >>>>>> On 11/1/2023 2:22 AM, Jim Mattson wrote: >>>>>>> On Tue, Oct 31, 2023 at 1:58 AM Dapeng Mi >>>>>>> wrote: >>>>>>>> This patch adds support for the architectural topdown slots event >>>>>>>> which >>>>>>>> is hinted by CPUID.0AH.EBX. >>>>>>> Can't a guest already program an event selector to count event select >>>>>>> 0xa4, unit mask 1, unless the event is prohibited by >>>>>>> KVM_SET_PMU_EVENT_FILTER? >>>>>> Actually defining this new slots arch event is to do the sanity check >>>>>> for supported arch-events which is enumerated by CPUID.0AH.EBX. >>>>>> Currently vPMU would check if the arch event from guest is supported by >>>>>> KVM. If not, it would be rejected just like intel_hw_event_available() >>>>>> shows. >>>>>> >>>>>> If we don't add the slots event in the intel_arch_events[] array, guest >>>>>> may program the slots event and pass the sanity check of KVM on a >>>>>> platform which actually doesn't support slots event and program the >>>>>> event on a real GP counter and got an invalid count. This is not >>>>>> correct. >>>>> On physical hardware, it is possible to program a GP counter with the >>>>> event selector and unit mask of the slots event whether or not the >>>>> platform supports it. Isn't KVM wrong to disallow something that a >>>>> physical CPU allows? >>>> >>>> Yeah, I agree. But I'm not sure if this is a flaw on PMU driver. If an >>>> event is not supported by the hardware, we can't predict the PMU's >>>> behavior and a meaningless count may be returned and this could mislead >>>> the user. >>> The user can program any events on the GP counter. The perf doesn't >>> limit it. For the unsupported event, 0 should be returned. Please keep >>> in mind, the event list keeps updating. If the kernel checks for each >>> event, it could be a disaster. I don't think it's a flaw. >> >> >> Thanks Kan, it would be ok as long as 0 is always returned for >> unsupported events. IMO, it's a nice to have feature that KVM does this >> sanity check for supported arch events, it won't break anything. > > The hardware PMU most assuredly does not return 0 for unsupported events. > > For example, if I use host perf to sample event selector 0xa4 unit > mask 1 on a Broadwell host (406f1), I get... I think we have different understanding about the meaning of the "unsupported". There is no enumeration of the Architectural Topdown Slots, which only means the Topdown Slots/01a4 is not an architectural event on the platform. It doesn't mean that the event encoding is unsupported. It could be used by another event, especially on the previous platform. Except for the architectural events, the event encoding of model specific event is not guaranteed to be the same among different generations. On BDW, the 01a4 is a model specific event with other meanings. That's why you can observe some values. Please make sure to only test the event on an enumerated platform. Thanks, Kan > > # perf stat -e r01a4 sleep 10 > > Performance counter stats for 'sleep 10': > > 386,964 r01a4 > > 10.000907211 seconds time elapsed > > Broadwell does not advertise support for architectural event 7 in > CPUID.0AH:EBX, so KVM will refuse to measure this event inside a > guest. That seems broken to me. > >> >>> >>> Thanks, >>> Kan >>>> Add Kan to confirm this. >>>> >>>> Hi Kan, >>>> >>>> Have you any comments on this? Thanks. >>>> >>>> >>>>>>> AFAICT, this change just enables event filtering based on >>>>>>> CPUID.0AH:EBX[bit 7] (though it's not clear to me why two independent >>>>>>> mechanisms are necessary for event filtering). >>>>>> IMO, these are two different things. this change is just to enable the >>>>>> supported arch events check for slot events, the event filtering is >>>>>> another thing. >>>>> How is clearing CPUID.0AH:EBX[bit 7] any different from putting {event >>>>> select 0xa4, unit mask 1} in a deny list with the PMU event filter? >>>> I think there is no difference in the conclusion but with two different >>>> methods. >>>> >>>>