Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp662012rdf; Fri, 3 Nov 2023 11:03:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGK9cbhdXd1kNkYYVcGYHVbte49ybFt6fiM/R+GTmpKtfyimtkTT3WX22lJYm90u6uBrWCW X-Received: by 2002:a17:90a:440d:b0:27d:9b5:d6f8 with SMTP id s13-20020a17090a440d00b0027d09b5d6f8mr16579370pjg.49.1699034632536; Fri, 03 Nov 2023 11:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699034632; cv=none; d=google.com; s=arc-20160816; b=OBbJNwukzBzN+vyRniHVbOqZyJd4MPhFtwMQxWJP8Q3DWfaY++sUzx9zhd/CEMLLvq SMvsWRPjJR0jbAhqJ1SM34zIEsR2HhSe40Am6NGmWd37I191MobQ+oS4eChps30mgLqT GQFq8F9iqF1B4V6PWFg3WFFRyw0jp9RPheoV2VWy3cvcmSxEW3fHIY+0mvNQ3E7bRqMF GEPnfw5CZxQChkcJdcnJ3qG4iOgMoROpfqcPkZCNFyGyF4JcRxtr7BkoOTkA3bQrhnR6 d+gy1HtryLUqNRc0FSoPi41g/xaypLZyIyyF6YJGtWEVi7/ChshBomKCchnicwhAHahH 2ndQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:dkim-signature; bh=yOW9lJ/pb/LNUWLip6vU1IMGdPjrtEEEy/T6WmZb0ws=; fh=oafBl1Lz04Uj+oaKYV0tIKOPzDqKxELFSScDg/b4xgU=; b=o0xA5cq3oTI7Sj5cAfhQSAX+28IogQRXOVvFNjvq9K8AJglniINd0s0e5p/GMiyK/2 dQCXhBDG61Vnxvu42+jDLaIfOVhn8KPhRuNrGjghcoRJ92HZ//kb8XPL1EP5VWkyOveO NuR9VzuXQa4C7ZMxlq3nLPfrwYX/8B2gnN8f6Z5up3LvsmNPdOFgA06bm3FTVw9rAX4y OmjAqL9OcTMKxaMRNYA5M6NR47tgXSSaXneFCwqnnHvmnlNgfj/vpXqbcU2G5EryYxdN JNWJZntBI5sJbbJvCYPl0lgPYKLGITQ46m64xPzWHYvymwEcjGl/up3/HYGInG0EhZfM OBRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=MuHx6ToR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id np8-20020a17090b4c4800b00280664dd1f4si2072080pjb.9.2023.11.03.11.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 11:03:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=MuHx6ToR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 9FDCB802070C; Fri, 3 Nov 2023 11:03:45 -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 S230220AbjKCSDN (ORCPT + 99 others); Fri, 3 Nov 2023 14:03:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbjKCSDM (ORCPT ); Fri, 3 Nov 2023 14:03:12 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF1E3194 for ; Fri, 3 Nov 2023 11:03:09 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5afe220cadeso31367717b3.3 for ; Fri, 03 Nov 2023 11:03:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699034589; x=1699639389; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=yOW9lJ/pb/LNUWLip6vU1IMGdPjrtEEEy/T6WmZb0ws=; b=MuHx6ToRr9TAkxyM5dcLrxh5PWM/ET52FZ38tbYhn8Bf9Nor2QjlAjlCenK7hvnJo9 JFYrW2zPioF0uDs+vLURWTrcyOhS9mSt+qhH6s27LL/VtM7SWXAUFl1BjWPQ2I40I9U/ 5eoM4Kz0mflCnnLB7WCC6zOzrHYFZUrPg/HTgKsuM6ScMZFMQTCSzKN1Zl/hueufHqkd W+VqQyW7gGE7qMniyblzpMdgYYZ1hX7efGo338vx+NfnqdcGyUAitd357s3oW5n5Ffxf 2KcFaJVgiJ8ZmiMStoAiqS993dZpX4K8twQ9IinN2XPer7QkZOZWgy3H+mrdq7fUFgYN hD8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699034589; x=1699639389; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=yOW9lJ/pb/LNUWLip6vU1IMGdPjrtEEEy/T6WmZb0ws=; b=nN1ejzz+oFs90xi5R+e2Y24XffLhFL6pjSf8YzblbaWgZGl0lrhFyrac/ZXnSL30C9 GBmYQCCMA9LvjfXGl0KMIwe/x4roEgZB67qyeGfc/620I+v1OMTfWzM7C2MJulo66/KQ bfQ3jN1KbddKm2EfvRoaRVD9x5A9nBl8tjsPzwHjO0Yg8FyuCu7dzdW9g9XtVymO2ejx VOCcQILl78Oh15jqXOBkteHv7Q6jAu1a7H1zBZB6pD6KruP4MJ9E79fK9I0h9rCcYLYC XUKlGO5lQpX8NS+aILS1PSpe8vgYEf80VlYEkuHDDWCi695k+LIJzia0WwpZWz5gxNEu Go1g== X-Gm-Message-State: AOJu0YwL0tRa3sxDgs6zPoq0YVlmHAxWE7STX0o9V4aUlyVoRymilsuh 7W+JD+tlPJI7hFim2EsPHYsP8AVcH3I= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:4dc2:0:b0:d9c:bdff:e45a with SMTP id a185-20020a254dc2000000b00d9cbdffe45amr380948ybb.12.1699034589126; Fri, 03 Nov 2023 11:03:09 -0700 (PDT) Date: Fri, 3 Nov 2023 11:03:07 -0700 In-Reply-To: Mime-Version: 1.0 References: <20231031090613.2872700-2-dapeng1.mi@linux.intel.com> <85706bd7-7df0-4d4b-932c-d807ddb14f9e@linux.intel.com> <2004baa6-b494-462c-a11f-8104ea152c6a@linux.intel.com> Message-ID: Subject: Re: [Patch 1/2] KVM: x86/pmu: Add Intel CPUID-hinted TopDown slots event From: Sean Christopherson To: Jim Mattson Cc: Kan Liang , Dapeng Mi , Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhang Xiong , Mingwei Zhang , Like Xu , Dapeng Mi , Like Xu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 11:03:45 -0700 (PDT) On Fri, Nov 03, 2023, Jim Mattson wrote: > On Fri, Nov 3, 2023 at 8:13=E2=80=AFAM Liang, Kan wrote: > > > > > > > > On 2023-11-02 1:45 p.m., Jim Mattson wrote: > > > On Wed, Nov 1, 2023 at 7:07=E2=80=AFPM 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=E2=80=AFPM Mi, Dapeng > > >>>>> wrote: > > >>>>>> On 11/1/2023 2:22 AM, Jim Mattson wrote: > > >>>>>>> On Tue, Oct 31, 2023 at 1:58=E2=80=AFAM Dapeng Mi > > >>>>>>> wrote: > > >>>>>>>> This patch adds support for the architectural topdown slots ev= ent > > >>>>>>>> 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 suppo= rted by > > >>>>>> KVM. If not, it would be rejected just like intel_hw_event_avail= able() > > >>>>>> 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 th= e > > >>>>> 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. I= f 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 mi= slead > > >>>> 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 k= eep > > >>> in mind, the event list keeps updating. If the kernel checks for ea= ch > > >>> 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 t= his > > >> sanity check for supported arch events, it won't break anything. > > > > > > The hardware PMU most assuredly does not return 0 for unsupported eve= nts. > > > > > > 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. >=20 > If the same event encoding could be used by a microarchitectural event > on a prior platform, then it is *definitely* wrong for KVM to refuse > to monitor the event just because it isn't enumerated as a supported > architectural event. +1000! Thanks Kan, this is exactly the info we need! I'll add a patch to build on "Always treat Fixed counters as available when supported"[*] and rip out intel_hw_event_available(). [*] https://lore.kernel.org/all/20231024002633.2540714-4-seanjc@google.com