Skip to contentSkip to conversation

platform/x86/intel/tpmi/plr: Fix CPU selection on partitioned systems

PATCH In review Qinyun Tan 2 participants 2 messages Nov 25 x86 platform drivers

lore
Share & tools
lore

Qinyun Tan

author
#0 lore raw

PATCH 1/1 platform/x86/intel/tpmi/plr: Fix CPU selection on partitioned systems

When a package has multiple TPMI partitions, PLR can report the same CPUs in more than one partition. For example, on a single-package system with 72 logical CPUs and two TPMI partitions, both partitions list CPUs 0-35 in their PLR status files. CPUs 36-71 are missing.

Each partition numbers its PLR resources from zero. The driver compares that index with the CPU's power domain ID from MSR_PM_LOGICAL_ID, which is unique within the package. As a result, both partitions select the same CPUs. A mailbox read or clear on the second partition then uses a module ID taken from a CPU in the first partition.

Use the partition's cdie_mask to map each PLR resource to its package power domain. For compatibility with older platforms, keep using the resource index for partition 0 when no mask is available. Skip per-CPU mailbox accesses if the resource has no valid CPU mapping.

Fixes 9e9397a41b7b ("platform/x86/intel/tpmi/plr: Add support for the plr mailbox")

---

Notes:
Tested on a single-package system with 72 logical CPUs and two TPMI partitions. The PLR status files now list the CPUs belonging to each partition.

 drivers/platform/x86/intel/plr_tpmi.c         | 31 ++++++++++++++++---
 .../platform/x86/intel/tpmi_power_domains.c   |  2 --
 .../platform/x86/intel/tpmi_power_domains.h   |  2 ++
 3 files changed, 29 insertions(+), 6 deletions(-)
drivers/platform/x86/intel/plr_tpmi.c +27 -4
index 785c279b4540..33066f4763ef 100644
@@ -51,7 +51,7 @@ struct tpmi_plr_die {
 	void __iomem *base;
 	struct mutex lock; /* Protect access to PLR mailbox */
 	int package_id;
-	int die_id;
+	int power_domain_id;
 	struct tpmi_plr *plr;
 };
 
@@ -201,10 +201,13 @@ static int plr_status_show(struct seq_file *s, void *unused)
 	seq_puts(s, "cpus");
 	plr_print_bits(s, val, 32);
 
+	if (plr_die->power_domain_id < 0)
+		return 0;
+
 	guard(mutex)(&plr_die->lock);
 
 	for (int cpu = 0; cpu < nr_cpu_ids; cpu++) {
-		if (plr_die->die_id != tpmi_get_power_domain_id(cpu))
+		if (plr_die->power_domain_id != tpmi_get_power_domain_id(cpu))
 			continue;
 
 		if (plr_die->package_id != topology_physical_package_id(cpu))
@@ -241,10 +244,13 @@ static ssize_t plr_status_write(struct file *filp, const char __user *ubuf,
 
 	plr_write(0, plr_die, PLR_DIE_LEVEL);
 
+	if (plr_die->power_domain_id < 0)
+		return count;
+
 	guard(mutex)(&plr_die->lock);
 
 	for (int cpu = 0; cpu < nr_cpu_ids; cpu++) {
-		if (plr_die->die_id != tpmi_get_power_domain_id(cpu))
+		if (plr_die->power_domain_id != tpmi_get_power_domain_id(cpu))
 			continue;
 
 		if (plr_die->package_id != topology_physical_package_id(cpu))
@@ -281,6 +287,23 @@ static void intel_plr_unregister_notifier(struct notifier_block *nb)
 	tpmi_unregister_notifier(nb);
 }
 
+static int plr_power_domain_id(const struct oobmsm_plat_info *plat_info, int index)
+{
+	u16 mask = plat_info->cdie_mask;
+	int id = index;
+
+	/* Resource indices are relative to the partition's first compute die. */
+	if (mask)
+		id += __ffs(mask);
+	else if (plat_info->partition)
+		return -ENODEV;
+
+	if (id >= MAX_POWER_DOMAINS || (mask && !(mask & BIT(id))))
+		return -ENODEV;
+
+	return id;
+}
+
 static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxiliary_device_id *id)
 {
 	struct oobmsm_plat_info *plat_info;
@@ -340,7 +363,7 @@ static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia
 
 		plr->die_info[i].base = base;
 		plr->die_info[i].package_id = plat_info->package_id;
-		plr->die_info[i].die_id = i;
+		plr->die_info[i].power_domain_id = plr_power_domain_id(plat_info, i);
 		plr->die_info[i].plr = plr;
 		mutex_init(&plr->die_info[i].lock);
 
drivers/platform/x86/intel/tpmi_power_domains.c +0 -2
index ebe052c3bbe4..f6a46b4571ec 100644
@@ -70,8 +70,6 @@ static DEFINE_PER_CPU(struct tpmi_cpu_info, tpmi_cpu_info);
 /* The dynamically assigned cpu hotplug state to free later */
 static enum cpuhp_state tpmi_hp_state __read_mostly;
 
-#define MAX_POWER_DOMAINS	8
-
 static cpumask_t *tpmi_power_domain_mask;
 
 static u16 *domain_die_map;
drivers/platform/x86/intel/tpmi_power_domains.h +2 -0
index 2fd0dd7afbd2..43a80b526133 100644
@@ -10,6 +10,8 @@
 
 #include <linux/cpumask.h>
 
+#define MAX_POWER_DOMAINS	8
+
 int tpmi_get_linux_cpu_number(int package_id, int die_id, int punit_core_id);
 int tpmi_get_punit_core_number(int cpu_no);
 int tpmi_get_power_domain_id(int cpu_no);

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f

Signature · 1 line
2.55.0
Acked-by on v1 1/1
#1 lore raw
Quoted 20 lines · Qinyun Tan

When a package has multiple TPMI partitions, PLR can report the same CPUs in more than one partition. For example, on a single-package system with 72 logical CPUs and two TPMI partitions, both partitions list CPUs 0-35 in their PLR status files. CPUs 36-71 are missing.

Each partition numbers its PLR resources from zero. The driver compares
that index with the CPU's power domain ID from MSR_PM_LOGICAL_ID, which
is unique within the package. As a result, both partitions select the same CPUs. A mailbox read or clear on the second partition then uses a
module ID taken from a CPU in the first partition.

Use the partition's cdie_mask to map each PLR resource to its package power domain. For compatibility with older platforms, keep using the resource index for partition 0 when no mask is available. Skip per- CPU
mailbox accesses if the resource has no valid CPU mapping.

Quoted 3 lines
Fixes 9e9397a41b7b ("platform/x86/intel/tpmi/plr: Add support for

the plr mailbox")

Hi Tan,

Thank you for submitting this change, similar change was in our queue waiting to test.

You have moved definition of MAX_POWER_DOMAINS to header file, but this there is no description of that in the commit description. If you happen to post update, add that.

Quoted 138 lines

---

Notes:
    Tested on a single-package system with 72 logical CPUs and two TPMI
    partitions. The PLR status files now list the CPUs belonging to each
    partition.

 drivers/platform/x86/intel/plr_tpmi.c         | 31 ++++++++++++++++- --
 .../platform/x86/intel/tpmi_power_domains.c   |  2 -- .../platform/x86/intel/tpmi_power_domains.h   |  2 ++

 3 files changed, 29 insertions(+), 6 deletions(-)
drivers/platform/x86/intel/plr_tpmi.c +0 -0
index 785c279b4540..33066f4763ef 100644
@@ -51,7 +51,7 @@ struct tpmi_plr_die {
  	void __iomem *base;

  struct mutex lock; /* Protect access to PLR mailbox */ int package_id;

drivers/platform/x86/intel/plr_tpmi.c +1 -1
-	int die_id;
+	int power_domain_id;

  struct tpmi_plr *plr;
 };

drivers/platform/x86/intel/plr_tpmi.c +0 -0
@@ -201,10 +201,13 @@ static int plr_status_show(struct seq_file *s,
 void *unused)
  	seq_puts(s, "cpus");
  	plr_print_bits(s, val, 32);

drivers/platform/x86/intel/plr_tpmi.c +3 -0
+	if (plr_die->power_domain_id < 0)
+		return 0;
+

  guard(mutex)(&plr_die->lock);

  for (int cpu = 0; cpu < nr_cpu_ids; cpu++) {

drivers/platform/x86/intel/plr_tpmi.c +0 -1
-		if (plr_die->die_id !=

tpmi_get_power_domain_id(cpu))

drivers/platform/x86/intel/plr_tpmi.c +1 -0
+		if (plr_die->power_domain_id !=

tpmi_get_power_domain_id(cpu))
  continue;

  if (plr_die->package_id !=
topology_physical_package_id(cpu))

drivers/platform/x86/intel/plr_tpmi.c +0 -0
@@ -241,10 +244,13 @@ static ssize_t plr_status_write(struct file
 *filp, const char __user *ubuf,


  plr_write(0, plr_die, PLR_DIE_LEVEL);

drivers/platform/x86/intel/plr_tpmi.c +3 -0
+	if (plr_die->power_domain_id < 0)
+		return count;
+

  guard(mutex)(&plr_die->lock);

  for (int cpu = 0; cpu < nr_cpu_ids; cpu++) {

drivers/platform/x86/intel/plr_tpmi.c +0 -1
-		if (plr_die->die_id !=

tpmi_get_power_domain_id(cpu))

drivers/platform/x86/intel/plr_tpmi.c +1 -0
+		if (plr_die->power_domain_id !=

tpmi_get_power_domain_id(cpu))
  continue;

  if (plr_die->package_id !=
topology_physical_package_id(cpu))

drivers/platform/x86/intel/plr_tpmi.c +0 -0
@@ -281,6 +287,23 @@ static void intel_plr_unregister_notifier(struct
 notifier_block *nb)
  	tpmi_unregister_notifier(nb);
  }


+static int plr_power_domain_id(const struct oobmsm_plat_info *plat_info, int index)

drivers/platform/x86/intel/plr_tpmi.c +5 -0
+{
+	u16 mask = plat_info->cdie_mask;
+	int id = index;
+
+	/* Resource indices are relative to the partition's first

compute die. */

drivers/platform/x86/intel/plr_tpmi.c +11 -0
+	if (mask)
+		id += __ffs(mask);
+	else if (plat_info->partition)
+		return -ENODEV;
+
+	if (id >= MAX_POWER_DOMAINS || (mask && !(mask & BIT(id))))
+		return -ENODEV;
+
+	return id;
+}
+

 static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxiliary_device_id *id)
 {
  struct oobmsm_plat_info *plat_info;

drivers/platform/x86/intel/plr_tpmi.c +0 -0
@@ -340,7 +363,7 @@ static int intel_plr_probe(struct

auxiliary_device *auxdev, const struct auxilia

  plr->die_info[i].base = base; plr->die_info[i].package_id = plat_info->package_id;

drivers/platform/x86/intel/plr_tpmi.c +1 -1
-		plr->die_info[i].die_id = i;
+		plr->die_info[i].power_domain_id =

plr_power_domain_id(plat_info, i); plr->die_info[i].plr = plr; mutex_init(&plr->die_info[i].lock);

drivers/platform/x86/intel/tpmi_power_domains.c +0 -0
index ebe052c3bbe4..f6a46b4571ec 100644
@@ -70,8 +70,6 @@ static DEFINE_PER_CPU(struct tpmi_cpu_info,
 tpmi_cpu_info);
  /* The dynamically assigned cpu hotplug state to free later */
  static enum cpuhp_state tpmi_hp_state __read_mostly;

drivers/platform/x86/intel/tpmi_power_domains.c +0 -2
-#define MAX_POWER_DOMAINS	8
-

 static cpumask_t *tpmi_power_domain_mask;

 static u16 *domain_die_map;

drivers/platform/x86/intel/tpmi_power_domains.h +0 -0
index 2fd0dd7afbd2..43a80b526133 100644
@@ -10,6 +10,8 @@


 #include <linux/cpumask.h>

drivers/platform/x86/intel/tpmi_power_domains.h +2 -0
+#define MAX_POWER_DOMAINS	8
+

 int tpmi_get_linux_cpu_number(int package_id, int die_id, int punit_core_id);
 int tpmi_get_punit_core_number(int cpu_no);
 int tpmi_get_power_domain_id(int cpu_no);

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f