Skip to contentSkip to conversation

ACPI/PPTT: Check total CPU numbers when a CPU can't be found in PPTT table

PATCH In review Feng Tang 2 participants 3 messages Jan 16 – Jan 20 ACPI

lore
Share & tools
lore

Feng Tang

author
#0 lore raw

PATCH v3 1/1 ACPI/PPTT: Check total CPU numbers when a CPU can't be found in PPTT table

There was a bug that kernel printed error message:
" ACPI PPTT: PPTT table found, but unable to locate core 1 (1)" and later on the kernel met issues when building up scheduler domain.

Debug showed the kernel actually brought up all 8 CPUs successfully (MADT and other table worked fine), while the PPTT table was broken as it only had 4 CPUs in total.

Add check for number of CPU of PPTT table against system CPU number, and warn if they are not equal, to help debugging similar issues.

---
Changelog:

v3
* Only check the number of CPUs in PPTT table againt system CPU count when error happens, instead of dump all the CPU/cache entries (Sudeep/Rafael)

v2
* rebase againt 6.19 and refine the commit log

 drivers/acpi/pptt.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
drivers/acpi/pptt.c +40 -0
index de5f8c018333..9958c3961001 100644
@@ -529,6 +529,43 @@ static void acpi_pptt_warn_missing(void)
 	pr_warn_once("No PPTT table found, CPU and cache topology may be inaccurate\n");
 }
 
+static void pptt_verify_cpu_count(struct acpi_table_header *table_hdr)
+{
+	struct acpi_subtable_header *entry;
+	unsigned long end;
+	struct acpi_pptt_processor *cpu;
+	u8 len;
+	int nr_pptt_cpus = 0;
+	static bool checked;
+
+	if (checked)
+		return;
+
+	end = (unsigned long)table_hdr + table_hdr->length;
+	entry = ACPI_ADD_PTR(struct acpi_subtable_header, table_hdr,
+				sizeof(struct acpi_table_pptt));
+
+	while ((unsigned long)entry + sizeof(struct acpi_pptt_processor) <= end) {
+		len = entry->length;
+		if (!len) {
+			pr_warn("Invalid zero length subtable\n");
+			return;
+		}
+
+		cpu = (struct acpi_pptt_processor *)entry;
+		entry = ACPI_ADD_PTR(struct acpi_subtable_header, entry, len);
+		if (cpu->header.type == ACPI_PPTT_TYPE_PROCESSOR &&
+		    (cpu->flags & ACPI_PPTT_ACPI_LEAF_NODE))
+			nr_pptt_cpus++;
+	}
+
+	if (nr_pptt_cpus != num_possible_cpus())
+		pr_warn("The number of CPUs (%d) in PPTT table doesn't match system's CPU count (%d)!\n",
+			nr_pptt_cpus, num_possible_cpus());
+
+	checked = true;
+}
+
 /**
  * topology_get_acpi_cpu_tag() - Find a unique topology value for a feature
  * @table: Pointer to the head of the PPTT table
@@ -565,6 +602,9 @@ static int topology_get_acpi_cpu_tag(struct acpi_table_header *table,
 	}
 	pr_warn_once("PPTT table found, but unable to locate core %d (%d)\n",
 		    cpu, acpi_cpu_id);
+
+	/* Check whether PPTT table's CPU count match with system count */
+	pptt_verify_cpu_count(table);
 	return -ENOENT;
 }
 
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw
Quoted 56 lines · Feng Tang

There was a bug that kernel printed error message:
" ACPI PPTT: PPTT table found, but unable to locate core 1 (1)" and later on the kernel met issues when building up scheduler domain.

Debug showed the kernel actually brought up all 8 CPUs successfully (MADT and other table worked fine), while the PPTT table was broken as it only had 4 CPUs in total.

Add check for number of CPU of PPTT table against system CPU number, and warn if they are not equal, to help debugging similar issues.

---
Changelog:

v3
* Only check the number of CPUs in PPTT table againt system CPU count when error happens, instead of dump all the CPU/cache entries (Sudeep/Rafael)

v2
* rebase againt 6.19 and refine the commit log

 drivers/acpi/pptt.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
drivers/acpi/pptt.c +21 -0
index de5f8c018333..9958c3961001 100644
@@ -529,6 +529,43 @@ static void acpi_pptt_warn_missing(void)
 	pr_warn_once("No PPTT table found, CPU and cache topology may be inaccurate\n");
 }
 
+static void pptt_verify_cpu_count(struct acpi_table_header *table_hdr)
+{
+	struct acpi_subtable_header *entry;
+	unsigned long end;
+	struct acpi_pptt_processor *cpu;
+	u8 len;
+	int nr_pptt_cpus = 0;
+	static bool checked;
+
+	if (checked)
+		return;
+
+	end = (unsigned long)table_hdr + table_hdr->length;
+	entry = ACPI_ADD_PTR(struct acpi_subtable_header, table_hdr,
+				sizeof(struct acpi_table_pptt));
+
+	while ((unsigned long)entry + sizeof(struct acpi_pptt_processor) <= end) {
+		len = entry->length;
+		if (!len) {
+			pr_warn("Invalid zero length subtable\n");
+			return;

drivers/acpi/pptt.c static void acpi_pptt_warn_missing(void) · line 562

Quoted 10 lines
drivers/acpi/pptt.c +10 -0
+		}
+
+		cpu = (struct acpi_pptt_processor *)entry;
+		entry = ACPI_ADD_PTR(struct acpi_subtable_header, entry, len);
+		if (cpu->header.type == ACPI_PPTT_TYPE_PROCESSOR &&
+		    (cpu->flags & ACPI_PPTT_ACPI_LEAF_NODE))
+			nr_pptt_cpus++;
+	}
+
+	if (nr_pptt_cpus != num_possible_cpus())

This is going to be tricky. I recall some config option that sets all NR_CPUS as possible. In short it will break if that is enabled.

drivers/acpi/pptt.c static int topology_get_acpi_cpu_tag(struct acpi_table_header *table, · line 604

Quoted 13 lines
drivers/acpi/pptt.c +6 -0
+		pr_warn("The number of CPUs (%d) in PPTT table doesn't match system's CPU count (%d)!\n",
+			nr_pptt_cpus, num_possible_cpus());
+
+	checked = true;
+}
+
 /**
  * topology_get_acpi_cpu_tag() - Find a unique topology value for a feature
  * @table: Pointer to the head of the PPTT table
@@ -565,6 +602,9 @@ static int topology_get_acpi_cpu_tag(struct acpi_table_header *table,
 	}
 	pr_warn_once("PPTT table found, but unable to locate core %d (%d)\n",
 		    cpu, acpi_cpu_id);

I was expecting the above log will be improved to just say possible mismatch with cpu count.

drivers/acpi/pptt.c static int topology_get_acpi_cpu_tag(struct acpi_table_header *table, · line 607

Quoted 3 lines
drivers/acpi/pptt.c +3 -0
+
+	/* Check whether PPTT table's CPU count match with system count */
+	pptt_verify_cpu_count(table);

Today it is a request to check the CPU count; tomorrow it will be something else in the PPTT. Where do we draw the line on PPTT validation in the kernel? These issues ultimately need to be fixed in firmware, and the firmware should not depend on the kernel to precisely identify what is wrong in the PPTT tables.

Signature · 2 lines
Regards,
Sudeep
author
#2 lore raw
Quoted 14 lines · Sudeep Holla
Quoted 13 lines · Feng Tang

There was a bug that kernel printed error message:
" ACPI PPTT: PPTT table found, but unable to locate core 1 (1)" and later on the kernel met issues when building up scheduler domain.

Debug showed the kernel actually brought up all 8 CPUs successfully (MADT and other table worked fine), while the PPTT table was broken as it only had 4 CPUs in total.

Add check for number of CPU of PPTT table against system CPU number, and warn if they are not equal, to help debugging similar issues.

[...]

Quoted 11 lines

drivers/acpi/pptt.c static void acpi_pptt_warn_missing(void) · line 562

Quoted 8 lines
drivers/acpi/pptt.c +8 -0
+		cpu = (struct acpi_pptt_processor *)entry;
+		entry = ACPI_ADD_PTR(struct acpi_subtable_header, entry, len);
+		if (cpu->header.type == ACPI_PPTT_TYPE_PROCESSOR &&
+		    (cpu->flags & ACPI_PPTT_ACPI_LEAF_NODE))
+			nr_pptt_cpus++;
+	}
+
+	if (nr_pptt_cpus != num_possible_cpus())

This is going to be tricky. I recall some config option that sets all NR_CPUS as possible. In short it will break if that is enabled.

Thanks for the info.

Quoted 8 lines
Quoted 8 lines
drivers/acpi/pptt.c +6 -0
+		pr_warn("The number of CPUs (%d) in PPTT table doesn't match system's CPU count (%d)!\n",
+			nr_pptt_cpus, num_possible_cpus());
+
+	checked = true;
+}
+
 /**
  * topology_get_acpi_cpu_tag() - Find a unique topology value for a feature
Quoted 8 lines

drivers/acpi/pptt.c static int topology_get_acpi_cpu_tag(struct acpi_table_header *table, · line 604

Quoted 5 lines

* @table: Pointer to the head of the PPTT table

drivers/acpi/pptt.c +0 -0
@@ -565,6 +602,9 @@ static int topology_get_acpi_cpu_tag(struct acpi_table_header *table,
 	}
 	pr_warn_once("PPTT table found, but unable to locate core %d (%d)\n",
 		    cpu, acpi_cpu_id);

I was expecting the above log will be improved to just say possible mismatch with cpu count.

Yep. it should be more explicite about the source.

Quoted 6 lines

drivers/acpi/pptt.c static int topology_get_acpi_cpu_tag(struct acpi_table_header *table, · line 607

Quoted 3 lines
drivers/acpi/pptt.c +3 -0
+
+	/* Check whether PPTT table's CPU count match with system count */
+	pptt_verify_cpu_count(table);

Today it is a request to check the CPU count; tomorrow it will be something else in the PPTT. Where do we draw the line on PPTT validation in the kernel?

I had similar concern, so I listed all items in orignal patch for check.

Quoted 3 lines

These issues ultimately need to be fixed in firmware, and the firmware should not depend on the kernel to precisely identify what is wrong in the PPTT tables.

Ideally yes. But upon the sad experience of raising issue to BIOS vendor or engineers, the more precise info, the sooner it gets solved and not refused.

Thanks,
Feng