From patchwork Tue Dec 19 15:01:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 181049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2005693dyi; Tue, 19 Dec 2023 07:11:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmBctPJE1excGa3WZFKS13jPq9CSKP8+0Fn2O+hNk0jt+GVhsyRUSODvb3CruEAi59MeNX X-Received: by 2002:a50:a6db:0:b0:553:9e98:5178 with SMTP id f27-20020a50a6db000000b005539e985178mr260831edc.132.1702998708289; Tue, 19 Dec 2023 07:11:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702998708; cv=none; d=google.com; s=arc-20160816; b=QxJCSypWvr4KxBtWk99PdAT5Xf7I7Kuz6PqeNgEOgS6/3FgljZM1YqyRT/2IiFuc0J bRxCSBsijB+aZn4MohcM0i5O8cSQL+D2DN4den/swQRTNiTZkIJJngsxtd544yzyhCZg k2V7v2kppjfNGwIFsd4auh2ABRyJT4bLauZS7pLV/8P1Xi84e0AwEbTzJ/LLjRTj0coT D3CDe6gJDpFiEXj89mN0HwhPU5R241qMR68FObhAC8eKIeM7DFReqOn4latjTLVUDSZb qn0kFHadRTMBQE8A0NW4QPBNFONjODxZ1gEa40Up2FXWw9EEPeC5S3phfZcdFXTwXsKf x0+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=fAL0d2W8Fw/85Tr4wg52r52asMP99OpV6GmERAcBgPc=; fh=pN7/XQFRZsK72J15/yeFJQ9m+oDVLaTUD2JVQJnBEW8=; b=GdfY19K16mq+bsQUJaB5CSQWOQdGlsXM8wa0JF22s2XbSHSre/z8KrGUOU89iwBMvD uwagrPWIUAwYcV/hJIcVc2cA1Y1TE9PiRaRz/K0qVb6u/VrYRy08VKYbGhJJ0jXIS6nP lf+Sh/iKWlu1XpiXnwDFX5+POXWoNpnpIgaSBp1Sli8BOtNrY9n0Xuj/ekukkmT1hpp2 N9Wel/oA5XJxyN8OAnIL7X8eXqmNf4ZCWrIEv4AZq51s5z56CoNbRHDZzyDX5S/kkoP9 1cl0fLNabVc7NFuZQNRnCfbMxlz6yvgHRQzNMgXh4xQsj0fFxeo/OBuAahRMu3S+qrWM 0Htg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aAvdPHqP; spf=pass (google.com: domain of linux-kernel+bounces-5443-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5443-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z12-20020a05640235cc00b005530c6ae80dsi3043181edc.79.2023.12.19.07.11.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 07:11:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5443-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aAvdPHqP; spf=pass (google.com: domain of linux-kernel+bounces-5443-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5443-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3F0291F298DF for ; Tue, 19 Dec 2023 15:02:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01B4A1CF86; Tue, 19 Dec 2023 15:01:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="aAvdPHqP" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87CD41A727 for ; Tue, 19 Dec 2023 15:01:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702998087; x=1734534087; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=x/hOouRnXHqzAJhY4XZBKUTZlHJR4Hnky5lSeqocgM8=; b=aAvdPHqPXQMAiRd6SL70E5sRR4RmUvJqp6mczCwLTUbEW6K3cRJT+r85 s+Loe2VsZJ3haIaq7T0rFyhAqUNMOuzD+bef9UOrglEkwt9G+z8qATkZh reVmiyLzYAI4g7bVxTdbIXQO62acAX5Jn/Mpz4yPdno+K/mMbGzO/cTIu MAh/EUvIYtFzMohOJu+LQz4Zi4inxh/RUN/8QDERlcr8MvabKPP5wCHdS R8V5j0GCh1hKyj9BNLRmdDwqx7khgXYc/pWod8yCJwPa8oLeJZBm6mcRK mtDwV5a97c+a/dJiOXmvvHLbf7Mm5nC6IBEAmXi0HNcSiZNnhF/cWN8/J g==; X-IronPort-AV: E=McAfee;i="6600,9927,10929"; a="394548505" X-IronPort-AV: E=Sophos;i="6.04,288,1695711600"; d="scan'208";a="394548505" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2023 07:01:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10929"; a="769266333" X-IronPort-AV: E=Sophos;i="6.04,288,1695711600"; d="scan'208";a="769266333" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga007.jf.intel.com with ESMTP; 19 Dec 2023 07:01:26 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, joe.jin@oracle.com, likexu@tencent.com, linux-kernel@vger.kernel.org, Kan Liang , Dongli Zhang Subject: [PATCH V2] perf/x86/intel: Hide Topdown metrics events if the feature is not enumerated Date: Tue, 19 Dec 2023 07:01:09 -0800 Message-Id: <20231219150109.1596634-1-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785723573620682539 X-GMAIL-MSGID: 1785723573620682539 From: Kan Liang The below error is observed on Ice Lake VM. $ perf stat Error: The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (slots). /bin/dmesg | grep -i perf may provide additional information. In a virtualization env, the Topdown metrics and the slots event haven't been supported yet. The guest CPUID doesn't enumerate them. However, the current kernel unconditionally exposes the slots event and the Topdown metrics events to sysfs, which misleads the perf tool and triggers the error. Hide the perf-metrics topdown events and the slots event if the perf-metrics feature is not enumerated. The big core of a hybrid platform can also supports the perf-metrics feature. Fix the hybrid platform as well. Reported-by: Dongli Zhang Closes: https://lore.kernel.org/lkml/CAM9d7cj8z+ryyzUHR+P1Dcpot2jjW+Qcc4CPQpfafTXN=LEU0Q@mail.gmail.com/ Signed-off-by: Kan Liang Tested-by: Dongli Zhang --- Changes since V1: - Rebase on top of the 6.7-rc - Use the intel_cap.perf_metrics to repace the slots event to check the enumeration of the perf metrics feature arch/x86/events/intel/core.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index e068a96aeb54..e0822ede9ccb 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -5699,8 +5699,22 @@ exra_is_visible(struct kobject *kobj, struct attribute *attr, int i) return x86_pmu.version >= 2 ? attr->mode : 0; } +static umode_t +td_is_visible(struct kobject *kobj, struct attribute *attr, int i) +{ + /* + * Hide the perf metrics topdown events + * if the feature is not enumerated. + */ + if (x86_pmu.num_topdown_events) + return x86_pmu.intel_cap.perf_metrics ? attr->mode : 0; + + return attr->mode; +} + static struct attribute_group group_events_td = { .name = "events", + .is_visible = td_is_visible, }; static struct attribute_group group_events_mem = { @@ -5902,9 +5916,27 @@ static umode_t hybrid_format_is_visible(struct kobject *kobj, return (cpu >= 0) && (pmu->pmu_type & pmu_attr->pmu_type) ? attr->mode : 0; } +static umode_t hybrid_td_is_visible(struct kobject *kobj, + struct attribute *attr, int i) +{ + struct device *dev = kobj_to_dev(kobj); + struct x86_hybrid_pmu *pmu = + container_of(dev_get_drvdata(dev), struct x86_hybrid_pmu, pmu); + + if (!is_attr_for_this_pmu(kobj, attr)) + return 0; + + + /* Only the big core supports perf metrics */ + if (pmu->pmu_type == hybrid_big) + return pmu->intel_cap.perf_metrics ? attr->mode : 0; + + return attr->mode; +} + static struct attribute_group hybrid_group_events_td = { .name = "events", - .is_visible = hybrid_events_is_visible, + .is_visible = hybrid_td_is_visible, }; static struct attribute_group hybrid_group_events_mem = {