[PATCH 5/6] perf/x86/intel/uncore: Fix uncore_die_to_cpu() for offline dies

From: Zide Chen

Date: Mon May 11 2026 - 19:15:17 EST


If the die is offline when uncore_die_to_cpu() is called, it silently
returns 0, which is misleading. Return -1 in this case to indicate
that all CPUs on the die are offline and the caller can take care of
it accordingly.

Opportunistically, replace -EPERM with -ENODEV, as -ENODEV is
the appropriate error when no CPUs are online across all dies.

Signed-off-by: Zide Chen <zide.chen@xxxxxxxxx>
---
arch/x86/events/intel/uncore.c | 2 +-
arch/x86/events/intel/uncore_snbep.c | 9 +++++++--
2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c
index 2bbe4cc1df3e..19056514b081 100644
--- a/arch/x86/events/intel/uncore.c
+++ b/arch/x86/events/intel/uncore.c
@@ -85,7 +85,7 @@ int uncore_device_to_die(struct pci_dev *dev)

int uncore_die_to_cpu(int die)
{
- int res = 0, cpu;
+ int res = -1, cpu;

/*
* Using cpus_read_lock() to ensure cpu is not going down between
diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index 30c6a9306c54..251c7bdbe30b 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -3772,11 +3772,16 @@ static void pmu_free_topology(struct intel_uncore_type *type)
static int skx_pmu_get_topology(struct intel_uncore_type *type,
int (*topology_cb)(struct intel_uncore_type*, int, int, u64))
{
- int die, ret = -EPERM;
+ int die, ret = -ENODEV;
u64 cpu_bus_msr;
+ int cpu;

for (die = 0; die < uncore_max_dies(); die++) {
- ret = skx_msr_cpu_bus_read(uncore_die_to_cpu(die), &cpu_bus_msr);
+ cpu = uncore_die_to_cpu(die);
+ if (cpu == -1)
+ continue;
+
+ ret = skx_msr_cpu_bus_read(cpu, &cpu_bus_msr);
if (ret)
break;

--
2.54.0