All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zhang, Rui" <rui.zhang@intel.com>
To: "jsperbeck@google.com" <jsperbeck@google.com>,
	"tip-bot2@linutronix.de" <tip-bot2@linutronix.de>
Cc: "tglx@linutronix.de" <tglx@linutronix.de>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-tip-commits@vger.kernel.org" 
	<linux-tip-commits@vger.kernel.org>,
	"x86@kernel.org" <x86@kernel.org>
Subject: Re: [tip: x86/urgent] x86/acpi: Ignore invalid x2APIC entries
Date: Fri, 1 Dec 2023 08:31:48 +0000	[thread overview]
Message-ID: <904ce2b870b8a7f34114f93adc7c8170420869d1.camel@intel.com> (raw)
In-Reply-To: <1e565bb08ebdd03897580a5905d1d2de01e15add.camel@intel.com>

On Thu, 2023-11-23 at 20:50 +0800, Exchange Online wrote:
> Hi, John,
> 
> Thanks for catching this issue.
> 
> On Wed, 2023-11-22 at 22:19 +0000, John Sperbeck wrote:
> > I have a platform with both LOCAL_APIC and LOCAL_X2APIC entries for
> > each CPU.  However, the ids for the LOCAL_APIC entries are all
> > invalid ids of 255, so they have always been skipped in
> > acpi_parse_lapic()
> > by this code from f3bf1dbe64b6 ("x86/acpi: Prevent LAPIC id 0xff
> > from
> > being
> > accounted"):
> > 
> >     /* Ignore invalid ID */
> >     if (processor->id == 0xff)
> >             return 0;
> > 
> > With the change in this thread, the return value of 0 means that
> > the
> > 'count' variable in acpi_parse_entries_array() is incremented.  The
> > positive return value means that 'has_lapic_cpus' is set, even
> > though
> > no entries were actually matched.
> 
> So in acpi_parse_madt_lapic_entries, without this patch,
> madt_proc[0].count is a positive value on this platform, right?
> 
> This sounds like a potential issue because the following checks to
> fall
> back to MPS mode can also break. (If all LOCAL_APIC entries have
> apic_id 0xff and all LOCAL_X2APIC entries have apic_id 0xffffffff)
> 
> >   Then, when the MADT is iterated
> > with acpi_parse_x2apic(), the x2apic entries with ids less than 255
> > are skipped and most of my CPUs aren't recognized.
> > 
> > I think the original version of this change was okay for this case
> > in
> > https://lore.kernel.org/lkml/87pm4bp54z.ffs@tglx/T/
> 
> Yeah.
> 
> But if we want to fix the potential issue above, we need to do
> something more.
> 
> Say we can still use acpi_table_parse_entries_array() and convert
> acpi_parse_lapic()/acpi_parse_x2apic() to
> acpi_subtable_proc.handler_arg and save the real valid entries via
> the
> parameter.
> 
> or can we just use num_processors & disabled_cpus to check if there
> is
> any CPU probed when parsing LOCAL_APIC/LOCAL_X2APIC entires?
> 

Hi, John,

As a quick fix, I'm not going to fix the "potential issue" describes
above because we have not seen a real problem caused by this yet.

Can you please try the below patch to confirm if the problem is gone on
your system? 
This patch falls back to the previous way as sent at
https://lore.kernel.org/lkml/87pm4bp54z.ffs@tglx/T/

thanks,
rui

From bdb45e241b4fea8a12b958e490979e96b064e43d Mon Sep 17 00:00:00 2001
From: Zhang Rui <rui.zhang@intel.com>
Date: Fri, 1 Dec 2023 15:06:34 +0800
Subject: [PATCH] x86/acpi: Do strict X2APIC ID check only when an enabled CPU
 is enumerated via LAPIC

Commit 8e9c42d776d6 ("x86/acpi: Ignore invalid x2APIC entries") does
strict X2APIC ID check if LAPIC contains valid CPUs by checking the
acpi_table_parse_madt() return value.

This is wrong because acpi_table_parse_madt() return value only
represents the number of legal entries parsed. For example, LAPIC entry
with LAPIC ID 0xff is counted as a legal entry, but it doesn't describe
a valid CPU.

This causes issues on a system which has 0xff LAPIC ID in all LAPIC
entries. Because the code does strict X2APIC IDs check and ignores most
of the CPUs in X2APIC entries.

Fix the problem by doing strict X2APIC ID check less aggressively, say
only when an enabled CPU is enumerated via LAPIC.

Fixes: 8e9c42d776d6 ("x86/acpi: Ignore invalid x2APIC entries")
Link: https://lore.kernel.org/all/20231122221947.781812-1-jsperbeck@google.com/
Reported-by: John Sperbeck <jsperbeck@google.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 arch/x86/kernel/acpi/boot.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 1a0dd80d81ac..8cc566ce486a 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -266,6 +266,7 @@ static int __init
 acpi_parse_lapic(union acpi_subtable_headers * header, const unsigned long end)
 {
 	struct acpi_madt_local_apic *processor = NULL;
+	int cpu;
 
 	processor = (struct acpi_madt_local_apic *)header;
 
@@ -289,9 +290,13 @@ acpi_parse_lapic(union acpi_subtable_headers * header, const unsigned long end)
 	 * to not preallocating memory for all NR_CPUS
 	 * when we use CPU hotplug.
 	 */
-	acpi_register_lapic(processor->id,	/* APIC ID */
-			    processor->processor_id, /* ACPI ID */
-			    processor->lapic_flags & ACPI_MADT_ENABLED);
+	cpu = acpi_register_lapic(processor->id,	/* APIC ID */
+				  processor->processor_id, /* ACPI ID */
+				  processor->lapic_flags & ACPI_MADT_ENABLED);
+
+	/* Do strict X2APIC ID check only when an enabled CPU is enumerated via LAPIC */
+	if (cpu >= 0 )
+		has_lapic_cpus = true;
 
 	return 0;
 }
@@ -1134,7 +1139,6 @@ static int __init acpi_parse_madt_lapic_entries(void)
 	if (!count) {
 		count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
 					acpi_parse_lapic, MAX_LOCAL_APIC);
-		has_lapic_cpus = count > 0;
 		x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
 					acpi_parse_x2apic, MAX_LOCAL_APIC);
 	}
-- 
2.34.1









  parent reply	other threads:[~2023-12-01  8:32 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-02 16:28 [RFC PATCH] x86/acpi: Ignore invalid x2APIC entries Zhang Rui
2023-07-28 12:51 ` Thomas Gleixner
2023-07-28 12:55   ` Thomas Gleixner
2023-07-28 16:47   ` Zhang, Rui
2023-07-29  7:07     ` Thomas Gleixner
2023-07-31 13:04       ` Zhang, Rui
2023-11-09 13:41 ` [tip: x86/urgent] " tip-bot2 for Zhang Rui
2023-11-22 22:17   ` [PATCH] platform/x86: intel_telemetry: Fix kernel doc descriptions John Sperbeck
2023-11-22 22:18   ` [tip: x86/urgent] x86/acpi: Ignore invalid x2APIC entries John Sperbeck
2023-11-22 22:19   ` John Sperbeck
2023-11-23 12:50     ` Zhang, Rui
2023-12-01  3:25       ` Ashok Raj
2023-12-01 18:08         ` Zhang, Rui
2023-12-01 20:23           ` Ashok Raj
2023-12-02  2:53             ` Zhang, Rui
2023-12-01  8:31       ` Zhang, Rui [this message]
2023-12-01 23:32         ` John Sperbeck
2023-12-06  6:58         ` Andres Freund
2023-12-07  2:41           ` Zhang, Rui
2023-12-07  5:10             ` Andres Freund
2023-12-12 17:34       ` Thomas Gleixner
2023-12-13  7:39         ` Zhang, Rui
2023-12-13 14:51           ` Thomas Gleixner
2023-12-14 15:00             ` Zhang, Rui
2023-12-14 21:11               ` Thomas Gleixner
2023-12-15 14:19         ` [PATCH] x86/acpi: Handle bogus MADT APIC tables gracefully Thomas Gleixner
2023-12-15 14:20         ` [tip: x86/urgent] x86/acpi: Ignore invalid x2APIC entries Andres Freund
2023-12-10 11:47     ` Linux regression tracking (Thorsten Leemhuis)
2023-12-18 13:57   ` [tip: x86/urgent] x86/acpi: Handle bogus MADT APIC tables gracefully tip-bot2 for Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=904ce2b870b8a7f34114f93adc7c8170420869d1.camel@intel.com \
    --to=rui.zhang@intel.com \
    --cc=jsperbeck@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=tip-bot2@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.