Received: by 2002:a05:7412:4e10:b0:e2:908c:2ebd with SMTP id gb16csp42016rdb; Mon, 6 Nov 2023 23:14:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEyrYRMQoWFJUPJLs58of5SJaHqEfrAanaJUOIaClnR9Y0IU8asepOzI/wL+4fDgTkGZHIZ X-Received: by 2002:a17:90a:c001:b0:280:a464:e9d4 with SMTP id p1-20020a17090ac00100b00280a464e9d4mr17306660pjt.8.1699341280473; Mon, 06 Nov 2023 23:14:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699341280; cv=none; d=google.com; s=arc-20160816; b=JAQJSMXSt+FzH25b+/Sn+c0MY4gApZ1GwdKfXy9eigTxKgqGYFDQP9P83dziudwIXO ipeo/OZvDaJNk8Fbbc9THb11aCxyqkfifSF9IWQECi/IFOzb79fGNk/SApedX3Q2B1oX 4l6dTqsw08As21fwMa4CcqDFACcv3bnr9NJW4pjKWn/nd/XHRQzdlR3/nvsZ8Rkg/xsl keFX+P0pKIHyEg9TidULWUZ3dBhOESmNzF8p8lyOm3G3SPVSC1hOhXT8nPxC0WiqWpk6 bkaP2Vt2kg9TQIkj2Zl5dy9kXjeULJv+ZZirHT21sUQoelo22iWYNo2YmlfwmACZ+LHG zqXA== 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=Y47jT8yt8O44EbO7QArOcLRk1qXXdPF+062D1IRvcsI=; fh=YK8hYUs3GXb9FOzWtng8SGY/erSMl258oXKsUB7AzHM=; b=jaExor9nhrY4eeT3N37QJT3BPFkq3MyBvgDNNgy2vfu4TtlllC4VnV0RCbFDLzHmOY BHwi0QQvnsGP4D8UVycg0BZhrJxAx4VyZT8XLkllqdfZUlFdVM2U2WaG67Jr6WIY2vGU uK/bwxnlMkp0mmvXXqhKWXxZ9JIJakqsh7G9nVtIM0N5manSonGiISNTa8bciEQUiltg M8G5yZGbiWitvJBklTRxuuth+nlo4hogQLK5dtSU7pjBhJTVPBvp+OctKpHumHH/QStJ n3J8v5+sM4VIEkLBqVZ+ECUCTVVhAP0cyeB+drOA3giYKbCB5wAmu3pqhVJhNUKme3NX WGoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ISuViZFV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id mr14-20020a17090b238e00b00274a5edad0csi9782889pjb.139.2023.11.06.23.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 23:14:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ISuViZFV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id C1CF1803AF73; Mon, 6 Nov 2023 23:14:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233439AbjKGHO1 (ORCPT + 99 others); Tue, 7 Nov 2023 02:14:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232666AbjKGHOZ (ORCPT ); Tue, 7 Nov 2023 02:14:25 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC49A126; Mon, 6 Nov 2023 23:14:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699341262; x=1730877262; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=rHg6ajGXoS1Qs9ap7LF+acWJjzz5Vz2IA6kFhHY2hAE=; b=ISuViZFVQ9WC3hOeCF9qSo7lO+3rZjP0AkveyOD4jw7mv3WAIMsXX6UO Uols207O/4Mk1WNVNCQmhyfoeJXu6O4ZdxL7TZNRQPC5bvEWd6BJhlJ9k yxruo5ROL7qT6RYBfEjRiYrtBoSIMYrzW1YVtTCXtc67WIDOklpZYk6+z 3wtKPf0p7B2+9fzUS/lsHyJ7VAS/1Ng0VCPMqJQM0Bxt8W89kFlPAQT9b y1GrCLdkwQYswq7vNU0tTCqw1D94nfOyNpW9DnH4Qbn4BhgXwCte4HXr1 kiPPrHnjBMP30l0kQdlrdmLJYe0CT64DYMsmcojCn2nDJUsfEQof/MdVY Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10886"; a="379838513" X-IronPort-AV: E=Sophos;i="6.03,282,1694761200"; d="scan'208";a="379838513" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2023 23:14:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10886"; a="906326673" X-IronPort-AV: E=Sophos;i="6.03,282,1694761200"; d="scan'208";a="906326673" Received: from dapengmi-mobl1.ccr.corp.intel.com (HELO [10.238.1.248]) ([10.238.1.248]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2023 23:14:18 -0800 Message-ID: <2c804098-af2b-4f1d-a39f-eb42f58635d7@linux.intel.com> Date: Tue, 7 Nov 2023 15:14:16 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 03/20] KVM: x86/pmu: Don't enumerate arch events KVM doesn't support To: Jim Mattson , Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kan Liang , Jinrong Liang , Like Xu , Aaron Lewis References: <20231104000239.367005-1-seanjc@google.com> <20231104000239.367005-4-seanjc@google.com> Content-Language: en-US From: "Mi, Dapeng" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 06 Nov 2023 23:14:37 -0800 (PST) On 11/4/2023 8:41 PM, Jim Mattson wrote: > On Fri, Nov 3, 2023 at 5:02 PM 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. Since intel_hw_event_available() would be removed, it looks the enum intel_pmu_architectural_events and intel_arch_events[] array become useless. We can directly simply modify current fixed_pmc_events[] array and use it to store fixed counter events code and umask. > > 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 monitoring 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 doesn't >> + * support. Clear unsupported events "unavailable" bit as well, as >> + * architecturally such bits are reserved to zero. >> + */ >> + kvm_pmu_cap.events_mask_len = min(kvm_pmu_cap.events_mask_len, >> + NR_REAL_INTEL_ARCH_EVENTS); >> + kvm_pmu_cap.events_mask &= GENMASK(kvm_pmu_cap.events_mask_len - 1, 0); >> + >> + /* >> * Perf may (sadly) back a guest fixed counter with a general purpose >> * counter, and so KVM must hide fixed counters whose associated >> * architectural event are unsupported. On real hardware, this should >> -- >> 2.42.0.869.gea05f2083d-goog >>