Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1072357rdf; Sat, 4 Nov 2023 05:41:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvT5YfqGoqEuylR6c0gXDZuMY1FOAlSf0w5xLjPaJ1vktjBAZwn5BaFNDFDlFWRIIbyljj X-Received: by 2002:a17:90b:4d12:b0:280:2b48:f264 with SMTP id mw18-20020a17090b4d1200b002802b48f264mr7882194pjb.0.1699101717034; Sat, 04 Nov 2023 05:41:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699101717; cv=none; d=google.com; s=arc-20160816; b=pDZ2qUCWMfpfC/6lss8cPcHdyOUIv7FUIutN42sENi+z7MJ/C75PUINnlQzLQ556zp +xhyM9X9yk9b6VHcw+F+v2alSg1I6vSQDxUoOttpUt0JOD6TjNR8uEnuXBuRUrv5i37m IzQeHIcs4a5VWyCwSWvhVxZevp8Q32B96PEWbGcCjGmRuIboKFmoiR3Hb0I7IeHOm7qp MrQ5t/NkrDvMulDDU88VVASt4TUGxLnal/Uk4Luvwk+5BE6ZW7EIBdCdlyXYwZ1ZLRMc xYZMBp7dEA69hdWl9zOM8aCMZ0ykLfSmYrDqTYAmxwo7ZAyNWg5shjccdxZ4QEHnhCNk FEMA== 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:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=UDLXHh1LCLlpUklSjpCr9GbpnRrH5B2wrUnHq5eFYtU=; fh=+P/YAw2zernQMYCM+6PO88cyfvFWVdhqutSbGYwZXbc=; b=U4XvLk4a5IJmlvcfKZ0mxT4bQs0mhtXMaPDcAh7V7tQp9mPBiu235aKO2ZHRJCk1XS 1uhMFVCM4wp6RuN7BqMkwqlntpJq4fmANngtIT0NwTNhGgFTbV+EW+7ZCojUD0+DSK8Q TVWksm5HTNkm8+3VgkCUWrB8wXSjTxkSNUwEAFqDWgfksdrFiVxxGcIiHvIdJba5JnHG xUZbGNHF/hSExQQhwFluvqfs7AWPrgKEiBBh+QoXcQvk1EOLAZw1drM17pEDS/AIN2mN qnCYKD3AzEvZVf4diea1Imr/3CsQGcJSkALSCbSLGO6y37REBAQSgYHbVvdhbUYw+IEA U/YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OS9v9fgo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id u14-20020a170903124e00b001c45291b6ebsi3824807plh.272.2023.11.04.05.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 05:41:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OS9v9fgo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 5639B8051B68; Sat, 4 Nov 2023 05:41:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbjKDMlp (ORCPT + 99 others); Sat, 4 Nov 2023 08:41:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjKDMlo (ORCPT ); Sat, 4 Nov 2023 08:41:44 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D51F3191 for ; Sat, 4 Nov 2023 05:41:41 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-54357417e81so6769a12.0 for ; Sat, 04 Nov 2023 05:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699101700; x=1699706500; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UDLXHh1LCLlpUklSjpCr9GbpnRrH5B2wrUnHq5eFYtU=; b=OS9v9fgop2zlPAwzYZQjlJNenTd3Cs9pbbyStQwKPvJgNMDzUI2H7jZgKEcNuGkYo2 C/owzWkJfe5ywnszlby2gbyoIDVqXlZyfeTJZFZGD2WIcoPD5mnfVmkQ2RpKGvBAju99 lc1jYp95c622/Or+T5G+hWuIaATrIudOE6k2ME1UKz/gUrXov+Xj0/ZbowoL3tAgFGEO aJFMM0UFQIg/py/QqIp3K09Ru4qTfWjCe/XKyCWbSp73V01ZsvH/b3PcFo/VvuDADXcu 4zOUUt1qTKGlwyj3MvmMktl3/Cb3c48H3R8GcYm+mOrmz+f83Y2YkJTo1yqeKVZ54WJJ bG6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699101700; x=1699706500; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UDLXHh1LCLlpUklSjpCr9GbpnRrH5B2wrUnHq5eFYtU=; b=LPtrNXbIfrRYZ4pEATA8+zUaRttFRr4P+XnXdtPKUhI4l4PFA5drLdJcv0CW6Hocbn H7b1mEvpa6mmy77Q1LEpkP1JyvoyN8843m5TREyn76JUUvCjwTZ/5X7S+tc8OdJUF4Fk Ib49zQ3eQBXWECgdvdXKOFF8awJgLUoCr23AG/krQMfheCzGj9E2GMcDAmTKMDFnwooU v42M2+9g38gs/HBRYHRF0D1T/rBUo845c5UEtxxNt4ApgIJO+OSuY9LbEMAPLBbV52/b qbnfWSsqOI9VeIgrSiK3lZ5g4YAtQ8qSGrrBb5GXVvtryWYpDY5447i97vQHsM5IYw7Q tqRQ== X-Gm-Message-State: AOJu0YwxbCYGqN7GLnqpoCVjxQjgJ2zi1tqmuNnrQRyIEIMNHUC/Tpdy leHNs7p7mqqflwXrRc8QOofOetqfGGlyPG0maxhjSw== X-Received: by 2002:a50:8757:0:b0:540:e4c3:430 with SMTP id 23-20020a508757000000b00540e4c30430mr83579edv.6.1699101699899; Sat, 04 Nov 2023 05:41:39 -0700 (PDT) MIME-Version: 1.0 References: <20231104000239.367005-1-seanjc@google.com> <20231104000239.367005-4-seanjc@google.com> In-Reply-To: <20231104000239.367005-4-seanjc@google.com> From: Jim Mattson Date: Sat, 4 Nov 2023 05:41:24 -0700 Message-ID: Subject: Re: [PATCH v6 03/20] KVM: x86/pmu: Don't enumerate arch events KVM doesn't support To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kan Liang , Dapeng Mi , Jinrong Liang , Like Xu , Aaron Lewis 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 agentk.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 (agentk.vger.email [0.0.0.0]); Sat, 04 Nov 2023 05:41:54 -0700 (PDT) On Fri, Nov 3, 2023 at 5:02=E2=80=AFPM Sean Christopherson wrote: > > Don't advertise support to userspace for architectural events that KVM > doesn't support, i.e. for "real" events that aren't listed in > intel_pmu_architectural_events. On current hardware, this effectively > means "don't advertise support for Top Down Slots". NR_REAL_INTEL_ARCH_EVENTS is only used in intel_hw_event_available(). As discussed (https://lore.kernel.org/kvm/ZUU12-TUR_1cj47u@google.com/), intel_hw_event_available() should go away. Aside from mapping fixed counters to event selector and unit mask (fixed_pmc_events[]), KVM has no reason to know when a new architectural event is defined. The variable that this change "fixes" is only used to feed CPUID.0AH:EBX in KVM_GET_SUPPORTED_CPUID, and kvm_pmu_cap.events_mask is already constructed from what host perf advertises support for. > Mask off the associated "unavailable" bits, as said bits for undefined > events are reserved to zero. Arguably the events _are_ defined, but from > a KVM perspective they might as well not exist, and there's absolutely no > reason to leave useless unavailable bits set. > > Fixes: a6c06ed1a60a ("KVM: Expose the architectural performance monitorin= g CPUID leaf") > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/vmx/pmu_intel.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c > index 3316fdea212a..8d545f84dc4a 100644 > --- a/arch/x86/kvm/vmx/pmu_intel.c > +++ b/arch/x86/kvm/vmx/pmu_intel.c > @@ -73,6 +73,15 @@ static void intel_init_pmu_capability(void) > int i; > > /* > + * Do not enumerate support for architectural events that KVM doe= sn't > + * support. Clear unsupported events "unavailable" bit as well, = as > + * architecturally such bits are reserved to zero. > + */ > + kvm_pmu_cap.events_mask_len =3D min(kvm_pmu_cap.events_mask_len, > + NR_REAL_INTEL_ARCH_EVENTS); > + kvm_pmu_cap.events_mask &=3D GENMASK(kvm_pmu_cap.events_mask_len = - 1, 0); > + > + /* > * Perf may (sadly) back a guest fixed counter with a general pur= pose > * counter, and so KVM must hide fixed counters whose associated > * architectural event are unsupported. On real hardware, this s= hould > -- > 2.42.0.869.gea05f2083d-goog >