From nobody Mon Sep 15 09:30:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ED56C678D4 for ; Thu, 12 Jan 2023 20:07:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231814AbjALUHP (ORCPT ); Thu, 12 Jan 2023 15:07:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241674AbjALUEh (ORCPT ); Thu, 12 Jan 2023 15:04:37 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DFE615816 for ; Thu, 12 Jan 2023 12:01:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673553715; x=1705089715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L0LysSy+o68gZus5CsHds3iLhv9K3aJ1XZA9pHukedQ=; b=GnH1413EUyUY6n7jg6jRnSG0WBElisiyL4As58RoxS1/xDc2mHiMw9KN seBWGqibbHhBg0m9GzxZv3UyBfUXC6wpy2y63ldXGVOqSKxsV9iRhEYY4 /xlIHgsxykEUuq+kLEqMuz+9ydiYnozsKj1ga6JbPKVlDo/YIdXxOzDVC nioWVr9b55ksTwQmuAOTEQazdEJEFqI6aQmw06xegu9XSuwv6N7tVV8Dg QbWm//d+H/FEVRg+zJIXGbDg34AtCkPQe7SOe7ll7X1Oa8wliAW4lQAJf NDmlfkRyfRlUIc3Lr1cbSxpnrOHkiEUjxieyVxJL+b/b7cG1BAGlV/vp6 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="325867096" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="325867096" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 12:01:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="657959925" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="657959925" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2023 12:01:29 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: steve.wahl@hpe.com, alexander.antonov@linux.intel.com, ak@linux.intel.com, eranian@google.com, namhyung@kernel.org, Kan Liang Subject: [PATCH RESEND 1/5] perf/x86/uncore: Factor out uncore_device_to_die() Date: Thu, 12 Jan 2023 12:01:01 -0800 Message-Id: <20230112200105.733466-2-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230112200105.733466-1-kan.liang@linux.intel.com> References: <20230112200105.733466-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kan Liang The same code is used to retrieve the logical die ID with a given PCI device in both the discovery code and the code that supports a system with > 8 nodes. Factor out uncore_device_to_die() to replace the duplicate code. No functional change. Signed-off-by: Kan Liang Reviewed-by: Steve Wahl Tested-by: Michael Petlan Tested-by: Steve Wahl --- arch/x86/events/intel/uncore.c | 15 +++++++++++++++ arch/x86/events/intel/uncore.h | 1 + arch/x86/events/intel/uncore_discovery.c | 16 ++-------------- arch/x86/events/intel/uncore_snbep.c | 12 +----------- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c index 6f1ccc57a692..8caf253be1de 100644 --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -65,6 +65,21 @@ int uncore_die_to_segment(int die) return bus ? pci_domain_nr(bus) : -EINVAL; } =20 +int uncore_device_to_die(struct pci_dev *dev) +{ + int node =3D pcibus_to_node(dev->bus); + int cpu; + + for_each_cpu(cpu, cpumask_of_pcibus(dev->bus)) { + struct cpuinfo_x86 *c =3D &cpu_data(cpu); + + if (c->initialized && cpu_to_node(cpu) =3D=3D node) + return c->logical_die_id; + } + + return -1; +} + static void uncore_free_pcibus_map(void) { struct pci2phy_map *map, *tmp; diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h index e278e2e7c051..8d493bea9eb6 100644 --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -208,6 +208,7 @@ struct pci2phy_map { struct pci2phy_map *__find_pci2phy_map(int segment); int uncore_pcibus_to_dieid(struct pci_bus *bus); int uncore_die_to_segment(int die); +int uncore_device_to_die(struct pci_dev *dev); =20 ssize_t uncore_event_show(struct device *dev, struct device_attribute *attr, char *buf); diff --git a/arch/x86/events/intel/uncore_discovery.c b/arch/x86/events/int= el/uncore_discovery.c index 5fd72d4b8bbb..08af92af2be2 100644 --- a/arch/x86/events/intel/uncore_discovery.c +++ b/arch/x86/events/intel/uncore_discovery.c @@ -33,7 +33,7 @@ static int logical_die_id; =20 static int get_device_die_id(struct pci_dev *dev) { - int cpu, node =3D pcibus_to_node(dev->bus); + int node =3D pcibus_to_node(dev->bus); =20 /* * If the NUMA info is not available, assume that the logical die id is @@ -43,19 +43,7 @@ static int get_device_die_id(struct pci_dev *dev) if (node < 0) return logical_die_id++; =20 - for_each_cpu(cpu, cpumask_of_node(node)) { - struct cpuinfo_x86 *c =3D &cpu_data(cpu); - - if (c->initialized && cpu_to_node(cpu) =3D=3D node) - return c->logical_die_id; - } - - /* - * All CPUs of a node may be offlined. For this case, - * the PCI and MMIO type of uncore blocks which are - * enumerated by the device will be unavailable. - */ - return -1; + return uncore_device_to_die(dev); } =20 #define __node_2_type(cur) \ diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/u= ncore_snbep.c index 44c2f879f708..31acc96ccb69 100644 --- a/arch/x86/events/intel/uncore_snbep.c +++ b/arch/x86/events/intel/uncore_snbep.c @@ -1453,9 +1453,6 @@ static int snbep_pci2phy_map_init(int devid, int node= id_loc, int idmap_loc, bool } raw_spin_unlock(&pci2phy_map_lock); } else { - int node =3D pcibus_to_node(ubox_dev->bus); - int cpu; - segment =3D pci_domain_nr(ubox_dev->bus); raw_spin_lock(&pci2phy_map_lock); map =3D __find_pci2phy_map(segment); @@ -1465,15 +1462,8 @@ static int snbep_pci2phy_map_init(int devid, int nod= eid_loc, int idmap_loc, bool break; } =20 - die_id =3D -1; - for_each_cpu(cpu, cpumask_of_pcibus(ubox_dev->bus)) { - struct cpuinfo_x86 *c =3D &cpu_data(cpu); + map->pbus_to_dieid[bus] =3D die_id =3D uncore_device_to_die(ubox_dev); =20 - if (c->initialized && cpu_to_node(cpu) =3D=3D node) { - map->pbus_to_dieid[bus] =3D die_id =3D c->logical_die_id; - break; - } - } raw_spin_unlock(&pci2phy_map_lock); =20 if (WARN_ON_ONCE(die_id =3D=3D -1)) { --=20 2.35.1 From nobody Mon Sep 15 09:30:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C633C54EBE for ; Thu, 12 Jan 2023 20:07:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240883AbjALUHo (ORCPT ); Thu, 12 Jan 2023 15:07:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241659AbjALUEf (ORCPT ); Thu, 12 Jan 2023 15:04:35 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 671191C907 for ; Thu, 12 Jan 2023 12:01:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673553715; x=1705089715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NSeYAfZ211QEML4KPYcbjU+itn+gXqaZo2yeuqVu2i0=; b=ZqN7VJexBHZfN8YJl9CnAgzxHIDT1nPkmft+uksusGsE96RBnhAMszzl UUyfy1bgHOtnEZBAXlZQ5MwFLtR74exMcayAZldcWtYYYYpnXAC6cS6l3 fXIuc2mlbieo4H9pzN98t49ii5XZR8107sk9J2nDXk0m+Ug7DrkAHEu+W xFT3bKSa5Bl9ALtEaqcHcomA5OHz+dChhnY3HE2E+yfxTHrK9bXwYE70W X+A4lIcW08t0ITIrner0WU9DDsbRzQSA9mevhun3mN5kejl834v28zYcQ EvL4ENFlJ/Xb3kCRqkCQ/bTNcECCIHRqe6fbX+stbJeJASaVcv6MOJms7 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="325867103" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="325867103" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 12:01:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="657959928" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="657959928" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2023 12:01:29 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: steve.wahl@hpe.com, alexander.antonov@linux.intel.com, ak@linux.intel.com, eranian@google.com, namhyung@kernel.org, Kan Liang Subject: [PATCH RESEND 2/5] perf/x86/uncore: Fix potential NULL pointer in uncore_get_alias_name Date: Thu, 12 Jan 2023 12:01:02 -0800 Message-Id: <20230112200105.733466-3-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230112200105.733466-1-kan.liang@linux.intel.com> References: <20230112200105.733466-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kan Liang The current code assumes that the discovery table provides valid box_ids for the normal units. It's not the case anymore since some units in the discovery table are broken on some SPR variants. Factor out uncore_get_box_id(). Check the existence of the type->box_ids before using it. If it's not available, use pmu_idx. Signed-off-by: Kan Liang Reviewed-by: Steve Wahl Tested-by: Michael Petlan Tested-by: Steve Wahl --- arch/x86/events/intel/uncore.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c index 8caf253be1de..d63be6d1224e 100644 --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -857,6 +857,12 @@ static const struct attribute_group uncore_pmu_attr_gr= oup =3D { .attrs =3D uncore_pmu_attrs, }; =20 +static inline int uncore_get_box_id(struct intel_uncore_type *type, + struct intel_uncore_pmu *pmu) +{ + return type->box_ids ? type->box_ids[pmu->pmu_idx] : pmu->pmu_idx; +} + void uncore_get_alias_name(char *pmu_name, struct intel_uncore_pmu *pmu) { struct intel_uncore_type *type =3D pmu->type; @@ -865,7 +871,7 @@ void uncore_get_alias_name(char *pmu_name, struct intel= _uncore_pmu *pmu) sprintf(pmu_name, "uncore_type_%u", type->type_id); else { sprintf(pmu_name, "uncore_type_%u_%d", - type->type_id, type->box_ids[pmu->pmu_idx]); + type->type_id, uncore_get_box_id(type, pmu)); } } =20 @@ -892,7 +898,7 @@ static void uncore_get_pmu_name(struct intel_uncore_pmu= *pmu) * Use the box ID from the discovery table if applicable. */ sprintf(pmu->name, "uncore_%s_%d", type->name, - type->box_ids ? type->box_ids[pmu->pmu_idx] : pmu->pmu_idx); + uncore_get_box_id(type, pmu)); } } =20 --=20 2.35.1 From nobody Mon Sep 15 09:30:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1C96C678D4 for ; Thu, 12 Jan 2023 20:07:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240613AbjALUHY (ORCPT ); Thu, 12 Jan 2023 15:07:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241695AbjALUEl (ORCPT ); Thu, 12 Jan 2023 15:04:41 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BFFD1D0F0 for ; Thu, 12 Jan 2023 12:01:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673553720; x=1705089720; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k3olYJGDuAsTwkx4jY139eZ6Hwoc0t134R0hr6yBmNI=; b=CMU6RVdPWdQ/3ehsOAfEAJNsaooYRZUwVFuvEPfROvecaaiAmOZm2c9v TyX+FQdG1ZbMijiwq0Eaq4SbFzarQ2e+XTCmHBa/pq9oSlkSIPU7g6YhD faYoW7Md6LhQ7hpSt8E30GflrQSWDqTt9Qxc5aHtD4209K4QI7GAiBuXA haja8y/J625z5Q0xn3QugcpjhxLzAVlHsVTAoypTV9/eo7oaiyrS1tNA+ dBv17l6RXQJWNBjwlwjm77fwAotw/a0CYHZHZWe2D2lZ78L5ZbT6kUL7S rwJJnjWgNNYz2jNhmvHaMLWbR5JsMg3RddSaCYpHjKV7gDRhKyeYzI66Q Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="325867109" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="325867109" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 12:01:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="657959930" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="657959930" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2023 12:01:29 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: steve.wahl@hpe.com, alexander.antonov@linux.intel.com, ak@linux.intel.com, eranian@google.com, namhyung@kernel.org, Kan Liang Subject: [PATCH RESEND 3/5] perf/x86/uncore: Ignore broken units in discovery table Date: Thu, 12 Jan 2023 12:01:03 -0800 Message-Id: <20230112200105.733466-4-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230112200105.733466-1-kan.liang@linux.intel.com> References: <20230112200105.733466-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kan Liang Some units in a discovery table may be broken, e.g., UPI of SPR MCC. A generic method is required to ignore the broken units. Add uncore_units_ignore in the struct intel_uncore_init_fun, which indicates the type ID of broken units. It will be assigned by the platform-specific code later when the platform has a broken discovery table. Signed-off-by: Kan Liang Reviewed-by: Steve Wahl Tested-by: Michael Petlan Tested-by: Steve Wahl --- arch/x86/events/intel/uncore.c | 8 ++++++-- arch/x86/events/intel/uncore.h | 2 ++ arch/x86/events/intel/uncore_discovery.c | 26 +++++++++++++++++++++--- arch/x86/events/intel/uncore_discovery.h | 2 +- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c index d63be6d1224e..751df6460bff 100644 --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -1695,7 +1695,10 @@ struct intel_uncore_init_fun { void (*cpu_init)(void); int (*pci_init)(void); void (*mmio_init)(void); + /* Discovery table is required */ bool use_discovery; + /* The units in the discovery table should be ignored. */ + int *uncore_units_ignore; }; =20 static const struct intel_uncore_init_fun nhm_uncore_init __initconst =3D { @@ -1873,7 +1876,7 @@ static int __init intel_uncore_init(void) =20 id =3D x86_match_cpu(intel_uncore_match); if (!id) { - if (!uncore_no_discover && intel_uncore_has_discovery_tables()) + if (!uncore_no_discover && intel_uncore_has_discovery_tables(NULL)) uncore_init =3D (struct intel_uncore_init_fun *)&generic_uncore_init; else return -ENODEV; @@ -1881,7 +1884,8 @@ static int __init intel_uncore_init(void) uncore_init =3D (struct intel_uncore_init_fun *)id->driver_data; if (uncore_no_discover && uncore_init->use_discovery) return -ENODEV; - if (uncore_init->use_discovery && !intel_uncore_has_discovery_tables()) + if (uncore_init->use_discovery && + !intel_uncore_has_discovery_tables(uncore_init->uncore_units_ignore)) return -ENODEV; } =20 diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h index 8d493bea9eb6..bbaa57cd868d 100644 --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -34,6 +34,8 @@ =20 #define UNCORE_EVENT_CONSTRAINT(c, n) EVENT_CONSTRAINT(c, n, 0xff) =20 +#define UNCORE_IGNORE_END -1 + struct pci_extra_dev { struct pci_dev *dev[UNCORE_EXTRA_PCI_DEV_MAX]; }; diff --git a/arch/x86/events/intel/uncore_discovery.c b/arch/x86/events/int= el/uncore_discovery.c index 08af92af2be2..abb51191f5af 100644 --- a/arch/x86/events/intel/uncore_discovery.c +++ b/arch/x86/events/intel/uncore_discovery.c @@ -190,8 +190,25 @@ uncore_insert_box_info(struct uncore_unit_discovery *u= nit, =20 } =20 +static bool +uncore_ignore_unit(struct uncore_unit_discovery *unit, int *ignore) +{ + int i; + + if (!ignore) + return false; + + for (i =3D 0; ignore[i] !=3D UNCORE_IGNORE_END ; i++) { + if (unit->box_type =3D=3D ignore[i]) + return true; + } + + return false; +} + static int parse_discovery_table(struct pci_dev *dev, int die, - u32 bar_offset, bool *parsed) + u32 bar_offset, bool *parsed, + int *ignore) { struct uncore_global_discovery global; struct uncore_unit_discovery unit; @@ -246,6 +263,9 @@ static int parse_discovery_table(struct pci_dev *dev, i= nt die, if (unit.access_type >=3D UNCORE_ACCESS_MAX) continue; =20 + if (uncore_ignore_unit(&unit, ignore)) + continue; + uncore_insert_box_info(&unit, die, *parsed); } =20 @@ -254,7 +274,7 @@ static int parse_discovery_table(struct pci_dev *dev, i= nt die, return 0; } =20 -bool intel_uncore_has_discovery_tables(void) +bool intel_uncore_has_discovery_tables(int *ignore) { u32 device, val, entry_id, bar_offset; int die, dvsec =3D 0, ret =3D true; @@ -290,7 +310,7 @@ bool intel_uncore_has_discovery_tables(void) if (die < 0) continue; =20 - parse_discovery_table(dev, die, bar_offset, &parsed); + parse_discovery_table(dev, die, bar_offset, &parsed, ignore); } } =20 diff --git a/arch/x86/events/intel/uncore_discovery.h b/arch/x86/events/int= el/uncore_discovery.h index f4439357779a..41637022b5d1 100644 --- a/arch/x86/events/intel/uncore_discovery.h +++ b/arch/x86/events/intel/uncore_discovery.h @@ -122,7 +122,7 @@ struct intel_uncore_discovery_type { unsigned int *box_offset; /* Box offset */ }; =20 -bool intel_uncore_has_discovery_tables(void); +bool intel_uncore_has_discovery_tables(int *ignore); void intel_uncore_clear_discovery_tables(void); void intel_uncore_generic_uncore_cpu_init(void); int intel_uncore_generic_uncore_pci_init(void); --=20 2.35.1 From nobody Mon Sep 15 09:30:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C57C9C61DB3 for ; Thu, 12 Jan 2023 20:07:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240728AbjALUHg (ORCPT ); Thu, 12 Jan 2023 15:07:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241707AbjALUEo (ORCPT ); Thu, 12 Jan 2023 15:04:44 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C342C7 for ; Thu, 12 Jan 2023 12:01:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673553720; x=1705089720; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iAOm52S+zGz+4hb/ZX5jqXvAjhsP8kD0UOXj6xS3eys=; b=V+FYXX8nqLWh8xNWi0VCkU13o5bSOgnqERxu9WEuzCIaZNumrrELHuPW XciPiCqGQCH8MrXajpA2qQlmvUCkfKjftCTmH2UktChltH+GYITumy+xe M6fj6q9/e+OXVGQhF7aLQkuKwaIMuAnBPF0xJeppeO40+VoDIieDMlW6K QkUYZcayRW+LDtzbAVKGSRBJFkeRGjmAvnSItX6x1WhWUUfJE5jhtsBro nirBlDfzNH5yO4Zj+NW6/pSBFahNraxgRmRs1lECkOJ6C+FlPJ7Q6kvFC 41kiMs51mWWY5GHIVw/zLAt0FVdU12VrIqfPA3Q0siPKOcN6tA7oBhEji w==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="325867117" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="325867117" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 12:01:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="657959931" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="657959931" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2023 12:01:29 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: steve.wahl@hpe.com, alexander.antonov@linux.intel.com, ak@linux.intel.com, eranian@google.com, namhyung@kernel.org, Kan Liang Subject: [PATCH RESEND 4/5] perf/x86/uncore: Add a quirk for UPI on SPR Date: Thu, 12 Jan 2023 12:01:04 -0800 Message-Id: <20230112200105.733466-5-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230112200105.733466-1-kan.liang@linux.intel.com> References: <20230112200105.733466-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kan Liang The discovery table of UPI on some SPR variants, e.g., MCC, is broken. The third UPI table may includes a wrong address which points to a non-exists device. The bug impacts both UPI and M3UPI uncore PMON. Use a pre-defined UPI and M3UPI table to replace the broken table. Different BIOS may populate a device into a different domain or a different BUS. The accurate location can only be retrieved at load time. Add spr_update_device_location() to update the location of the UPI and M3UPI in the pre-defined table. Signed-off-by: Kan Liang Reviewed-by: Steve Wahl Tested-by: Michael Petlan Tested-by: Steve Wahl --- arch/x86/events/intel/uncore.c | 1 + arch/x86/events/intel/uncore.h | 1 + arch/x86/events/intel/uncore_discovery.h | 12 +- arch/x86/events/intel/uncore_snbep.c | 146 +++++++++++++++++++---- 4 files changed, 136 insertions(+), 24 deletions(-) diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c index 751df6460bff..0ac7ebfa1faa 100644 --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -1806,6 +1806,7 @@ static const struct intel_uncore_init_fun spr_uncore_= init __initconst =3D { .pci_init =3D spr_uncore_pci_init, .mmio_init =3D spr_uncore_mmio_init, .use_discovery =3D true, + .uncore_units_ignore =3D spr_uncore_units_ignore, }; =20 static const struct intel_uncore_init_fun generic_uncore_init __initconst = =3D { diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h index bbaa57cd868d..e76b945a079e 100644 --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -592,6 +592,7 @@ extern raw_spinlock_t pci2phy_map_lock; extern struct list_head pci2phy_map_head; extern struct pci_extra_dev *uncore_extra_pci_dev; extern struct event_constraint uncore_constraint_empty; +extern int spr_uncore_units_ignore[]; =20 /* uncore_snb.c */ int snb_uncore_pci_init(void); diff --git a/arch/x86/events/intel/uncore_discovery.h b/arch/x86/events/int= el/uncore_discovery.h index 41637022b5d1..6ee80ad3423e 100644 --- a/arch/x86/events/intel/uncore_discovery.h +++ b/arch/x86/events/intel/uncore_discovery.h @@ -21,9 +21,15 @@ /* Global discovery table size */ #define UNCORE_DISCOVERY_GLOBAL_MAP_SIZE 0x20 =20 -#define UNCORE_DISCOVERY_PCI_DOMAIN(data) ((data >> 28) & 0x7) -#define UNCORE_DISCOVERY_PCI_BUS(data) ((data >> 20) & 0xff) -#define UNCORE_DISCOVERY_PCI_DEVFN(data) ((data >> 12) & 0xff) +#define UNCORE_DISCOVERY_PCI_DOMAIN_OFFSET 28 +#define UNCORE_DISCOVERY_PCI_DOMAIN(data) \ + ((data >> UNCORE_DISCOVERY_PCI_DOMAIN_OFFSET) & 0x7) +#define UNCORE_DISCOVERY_PCI_BUS_OFFSET 20 +#define UNCORE_DISCOVERY_PCI_BUS(data) \ + ((data >> UNCORE_DISCOVERY_PCI_BUS_OFFSET) & 0xff) +#define UNCORE_DISCOVERY_PCI_DEVFN_OFFSET 12 +#define UNCORE_DISCOVERY_PCI_DEVFN(data) \ + ((data >> UNCORE_DISCOVERY_PCI_DEVFN_OFFSET) & 0xff) #define UNCORE_DISCOVERY_PCI_BOX_CTRL(data) (data & 0xfff) =20 =20 diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/u= ncore_snbep.c index 31acc96ccb69..b6ba76bc669d 100644 --- a/arch/x86/events/intel/uncore_snbep.c +++ b/arch/x86/events/intel/uncore_snbep.c @@ -6132,24 +6132,6 @@ static int spr_upi_get_topology(struct intel_uncore_= type *type) return discover_upi_topology(type, SPR_UBOX_DID, SPR_UPI_REGS_ADDR_DEVICE= _LINK0); } =20 -static struct intel_uncore_type spr_uncore_upi =3D { - .event_mask =3D SNBEP_PMON_RAW_EVENT_MASK, - .event_mask_ext =3D SPR_RAW_EVENT_MASK_EXT, - .format_group =3D &spr_uncore_raw_format_group, - .ops =3D &spr_uncore_pci_ops, - .name =3D "upi", - .attr_update =3D spr_upi_attr_update, - .get_topology =3D spr_upi_get_topology, - .set_mapping =3D spr_upi_set_mapping, - .cleanup_mapping =3D spr_upi_cleanup_mapping, -}; - -static struct intel_uncore_type spr_uncore_m3upi =3D { - SPR_UNCORE_PCI_COMMON_FORMAT(), - .name =3D "m3upi", - .constraints =3D icx_uncore_m3upi_constraints, -}; - static struct intel_uncore_type spr_uncore_mdf =3D { SPR_UNCORE_COMMON_FORMAT(), .name =3D "mdf", @@ -6158,7 +6140,13 @@ static struct intel_uncore_type spr_uncore_mdf =3D { #define UNCORE_SPR_NUM_UNCORE_TYPES 12 #define UNCORE_SPR_IIO 1 #define UNCORE_SPR_IMC 6 +#define UNCORE_SPR_UPI 8 +#define UNCORE_SPR_M3UPI 9 =20 +/* + * The uncore units, which are supported by the discovery table, + * are defined here. + */ static struct intel_uncore_type *spr_uncores[UNCORE_SPR_NUM_UNCORE_TYPES] = =3D { &spr_uncore_chabox, &spr_uncore_iio, @@ -6168,12 +6156,56 @@ static struct intel_uncore_type *spr_uncores[UNCORE= _SPR_NUM_UNCORE_TYPES] =3D { NULL, &spr_uncore_imc, &spr_uncore_m2m, - &spr_uncore_upi, - &spr_uncore_m3upi, + NULL, + NULL, NULL, &spr_uncore_mdf, }; =20 +/* + * The uncore units, which are not supported by the discovery table, + * are implemented from here. + */ +#define SPR_UNCORE_UPI_NUM_BOXES 4 + +static unsigned int spr_upi_pci_offsets[SPR_UNCORE_UPI_NUM_BOXES] =3D { + 0, 0x8000, 0x10000, 0x18000 +}; + +static struct intel_uncore_type spr_uncore_upi =3D { + .event_mask =3D SNBEP_PMON_RAW_EVENT_MASK, + .event_mask_ext =3D SPR_RAW_EVENT_MASK_EXT, + .format_group =3D &spr_uncore_raw_format_group, + .ops =3D &spr_uncore_pci_ops, + .name =3D "upi", + .attr_update =3D spr_upi_attr_update, + .get_topology =3D spr_upi_get_topology, + .set_mapping =3D spr_upi_set_mapping, + .cleanup_mapping =3D spr_upi_cleanup_mapping, + .type_id =3D UNCORE_SPR_UPI, + .num_counters =3D 4, + .num_boxes =3D SPR_UNCORE_UPI_NUM_BOXES, + .perf_ctr_bits =3D 48, + .perf_ctr =3D ICX_UPI_PCI_PMON_CTR0, + .event_ctl =3D ICX_UPI_PCI_PMON_CTL0, + .box_ctl =3D ICX_UPI_PCI_PMON_BOX_CTL, + .pci_offsets =3D spr_upi_pci_offsets, +}; + +static struct intel_uncore_type spr_uncore_m3upi =3D { + SPR_UNCORE_PCI_COMMON_FORMAT(), + .name =3D "m3upi", + .type_id =3D UNCORE_SPR_M3UPI, + .num_counters =3D 4, + .num_boxes =3D SPR_UNCORE_UPI_NUM_BOXES, + .perf_ctr_bits =3D 48, + .perf_ctr =3D ICX_M3UPI_PCI_PMON_CTR0, + .event_ctl =3D ICX_M3UPI_PCI_PMON_CTL0, + .box_ctl =3D ICX_M3UPI_PCI_PMON_BOX_CTL, + .pci_offsets =3D spr_upi_pci_offsets, + .constraints =3D icx_uncore_m3upi_constraints, +}; + enum perf_uncore_spr_iio_freerunning_type_id { SPR_IIO_MSR_IOCLK, SPR_IIO_MSR_BW_IN, @@ -6304,6 +6336,7 @@ static struct intel_uncore_type spr_uncore_imc_free_r= unning =3D { =20 #define UNCORE_SPR_MSR_EXTRA_UNCORES 1 #define UNCORE_SPR_MMIO_EXTRA_UNCORES 1 +#define UNCORE_SPR_PCI_EXTRA_UNCORES 2 =20 static struct intel_uncore_type *spr_msr_uncores[UNCORE_SPR_MSR_EXTRA_UNCO= RES] =3D { &spr_uncore_iio_free_running, @@ -6313,6 +6346,17 @@ static struct intel_uncore_type *spr_mmio_uncores[UN= CORE_SPR_MMIO_EXTRA_UNCORES] &spr_uncore_imc_free_running, }; =20 +static struct intel_uncore_type *spr_pci_uncores[UNCORE_SPR_PCI_EXTRA_UNCO= RES] =3D { + &spr_uncore_upi, + &spr_uncore_m3upi +}; + +int spr_uncore_units_ignore[] =3D { + UNCORE_SPR_UPI, + UNCORE_SPR_M3UPI, + UNCORE_IGNORE_END +}; + static void uncore_type_customized_copy(struct intel_uncore_type *to_type, struct intel_uncore_type *from_type) { @@ -6413,9 +6457,69 @@ void spr_uncore_cpu_init(void) spr_uncore_iio_free_running.num_boxes =3D uncore_type_max_boxes(uncore_ms= r_uncores, UNCORE_SPR_IIO); } =20 +#define SPR_UNCORE_UPI_PCIID 0x3241 +#define SPR_UNCORE_UPI0_DEVFN 0x9 +#define SPR_UNCORE_M3UPI_PCIID 0x3246 +#define SPR_UNCORE_M3UPI0_DEVFN 0x29 + +static void spr_update_device_location(int type_id) +{ + struct intel_uncore_type *type; + struct pci_dev *dev =3D NULL; + u32 device, devfn; + u64 *ctls; + int die; + + if (type_id =3D=3D UNCORE_SPR_UPI) { + type =3D &spr_uncore_upi; + device =3D SPR_UNCORE_UPI_PCIID; + devfn =3D SPR_UNCORE_UPI0_DEVFN; + } else if (type_id =3D=3D UNCORE_SPR_M3UPI) { + type =3D &spr_uncore_m3upi; + device =3D SPR_UNCORE_M3UPI_PCIID; + devfn =3D SPR_UNCORE_M3UPI0_DEVFN; + } else + return; + + ctls =3D kcalloc(__uncore_max_dies, sizeof(u64), GFP_KERNEL); + if (!ctls) { + type->num_boxes =3D 0; + return; + } + + while ((dev =3D pci_get_device(PCI_VENDOR_ID_INTEL, device, dev)) !=3D NU= LL) { + if (devfn !=3D dev->devfn) + continue; + + die =3D uncore_device_to_die(dev); + if (die < 0) + continue; + + ctls[die] =3D pci_domain_nr(dev->bus) << UNCORE_DISCOVERY_PCI_DOMAIN_OFF= SET | + dev->bus->number << UNCORE_DISCOVERY_PCI_BUS_OFFSET | + devfn << UNCORE_DISCOVERY_PCI_DEVFN_OFFSET | + type->box_ctl; + } + + type->box_ctls =3D ctls; +} + int spr_uncore_pci_init(void) { - uncore_pci_uncores =3D uncore_get_uncores(UNCORE_ACCESS_PCI, 0, NULL); + /* + * The discovery table of UPI on some SPR variant is broken, + * which impacts the detection of both UPI and M3UPI uncore PMON. + * Use the pre-defined UPI and M3UPI table to replace. + * + * The accurate location, e.g., domain and BUS number, + * can only be retrieved at load time. + * Update the location of UPI and M3UPI. + */ + spr_update_device_location(UNCORE_SPR_UPI); + spr_update_device_location(UNCORE_SPR_M3UPI); + uncore_pci_uncores =3D uncore_get_uncores(UNCORE_ACCESS_PCI, + UNCORE_SPR_PCI_EXTRA_UNCORES, + spr_pci_uncores); return 0; } =20 --=20 2.35.1 From nobody Mon Sep 15 09:30:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AB65C61DB3 for ; Thu, 12 Jan 2023 20:07:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240631AbjALUHb (ORCPT ); Thu, 12 Jan 2023 15:07:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241711AbjALUEo (ORCPT ); Thu, 12 Jan 2023 15:04:44 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C1EAF02 for ; Thu, 12 Jan 2023 12:01:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673553720; x=1705089720; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e37VGWZJt5D4i22LVtIZLifzbTAg/lau23PCib3BX/M=; b=bCMvjiTG/ho/kifhzeDmVRehAYdRxFh2ZXcDdv1oqo+7ia5aZ5CfH/qH BR7TLnw4SdEG76BvWX+LxjFj4QlDR2bf2TnGSw6NduG9py4nnjdTbDWJE yMOFOIpyyQCgfbjk/b4LqVhSSVOvC1ja4D3t8nqlwLXXt+eFeToFAEi4V f58xn9rlpYqM1ALoqG5EMwOeskDrDXNwoa6tJZGpKVmu4XRtadTRIEcJF jKdlfIrqUw1WVahJgYQxCFDP5SFV6dinWkINX/H0uqH9qFdi+psSYrjZp UQAbJZmMOLBgioR0B0bGe2akpHdiCbE38fZ8/dkrn262jY9dVIwqcGo9b g==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="325867126" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="325867126" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 12:01:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="657959932" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="657959932" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2023 12:01:29 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: steve.wahl@hpe.com, alexander.antonov@linux.intel.com, ak@linux.intel.com, eranian@google.com, namhyung@kernel.org, Kan Liang Subject: [PATCH RESEND 5/5] perf/x86/uncore: Don't WARN_ON_ONCE() for a broken discovery table Date: Thu, 12 Jan 2023 12:01:05 -0800 Message-Id: <20230112200105.733466-6-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230112200105.733466-1-kan.liang@linux.intel.com> References: <20230112200105.733466-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kan Liang The kernel warning message is triggered, when SPR MCC is used. [ 17.945331] ------------[ cut here ]------------ [ 17.946305] WARNING: CPU: 65 PID: 1 at arch/x86/events/intel/uncore_discovery.c:184 intel_uncore_has_discovery_tables+0x4c0/0x65c [ 17.946305] Modules linked in: [ 17.946305] CPU: 65 PID: 1 Comm: swapper/0 Not tainted 5.4.17-2136.313.1-X10-2c+ #4 It's caused by the broken discovery table of UPI. The discovery tables are from hardware. Except for dropping the broken information, there is nothing Linux can do. Using WARN_ON_ONCE() is overkilled. Use the pr_info() to replace WARN_ON_ONCE(), and specify what uncore unit is dropped and the reason. Signed-off-by: Kan Liang Reviewed-by: Steve Wahl Tested-by: Michael Petlan Tested-by: Steve Wahl --- arch/x86/events/intel/uncore_discovery.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/arch/x86/events/intel/uncore_discovery.c b/arch/x86/events/int= el/uncore_discovery.c index abb51191f5af..cb488e41807c 100644 --- a/arch/x86/events/intel/uncore_discovery.c +++ b/arch/x86/events/intel/uncore_discovery.c @@ -128,13 +128,21 @@ uncore_insert_box_info(struct uncore_unit_discovery *= unit, unsigned int *box_offset, *ids; int i; =20 - if (WARN_ON_ONCE(!unit->ctl || !unit->ctl_offset || !unit->ctr_offset)) + if (!unit->ctl || !unit->ctl_offset || !unit->ctr_offset) { + pr_info("Invalid address is detected for uncore type %d box %d, " + "Disable the uncore unit.\n", + unit->box_type, unit->box_id); return; + } =20 if (parsed) { type =3D search_uncore_discovery_type(unit->box_type); - if (WARN_ON_ONCE(!type)) + if (!type) { + pr_info("A spurious uncore type %d is detected, " + "Disable the uncore type.\n", + unit->box_type); return; + } /* Store the first box of each die */ if (!type->box_ctrl_die[die]) type->box_ctrl_die[die] =3D unit->ctl; @@ -169,8 +177,12 @@ uncore_insert_box_info(struct uncore_unit_discovery *u= nit, ids[i] =3D type->ids[i]; box_offset[i] =3D type->box_offset[i]; =20 - if (WARN_ON_ONCE(unit->box_id =3D=3D ids[i])) + if (unit->box_id =3D=3D ids[i]) { + pr_info("Duplicate uncore type %d box ID %d is detected, " + "Drop the duplicate uncore unit.\n", + unit->box_type, unit->box_id); goto free_ids; + } } ids[i] =3D unit->box_id; box_offset[i] =3D unit->ctl - type->box_ctrl; --=20 2.35.1