From: Adrian Huang <adrianhuang0701@gmail.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>
Cc: x86@kernel.org, Adrian Huang <adrianhuang0701@gmail.com>,
Adrian Huang <ahuang12@lenovo.com>
Subject: [PATCH] x86/apic: Fix APIC MSR access error when x2apic is disabled
Date: Tue, 30 Jan 2024 22:56:01 +0800 [thread overview]
Message-ID: <20240130145601.7063-1-adrianhuang0701@gmail.com> (raw)
From: Adrian Huang <ahuang12@lenovo.com>
When appending the 'iommu=off' kernel parameter, the kernel complains
about the following error message [1]:
unchecked MSR access error: RDMSR from 0x802 at rIP: 0xffffffff94079992 (native_apic_msr_read+0x12/0x50)
The root cause is that:
1. x2apic_mode is configured as '1' in check_x2apic().
2. apic_x2apic_cluster (assigned to global variable 'apic') is
selected in default_acpi_madt_oem_check().
3. x2apic_disable() is invoked in try_to_enable_x2apic().
Call path:
enable_IR_x2apic
|- try_to_enable_x2apic
|- x2apic_disable
|- __x2apic_disable
|- apic_set_fixmap
|- apic_read_boot_cpu_id(false)
4. read_apic_id() in apic_read_boot_cpu_id() invokes
native_apic_msr_read(), which leads to the error message.
Call path:
apic_read_boot_cpu_id
|- read_apic_id
|- apic_read
|- apic->read() ['apic' points to apic_x2apic_cluster]
|- native_apic_msr_read
Since x2apic mode has been disabled by writing MSR_IA32_APICBASE in
__x2apic_disable, the upcoming MSR accesses will trigger the MSR
access error. Note that APIC and x2APIC registers are accessed via
MMIO in xapic mode and those regiters are access via the MSR-based
interface in x2apic mode [2].
Fix the issue by checking if boot_cpu_physical_apicid has been
initialized.
[1] https://gist.github.com/AdrianHuang/9e5ce38d410af3ccd0b5ac1703e032bc
[2] Chapter 16, AMD64 Architecture Programmer’s Manual Volume 2:
System Programming
Fixes: d10a904435fa ("x86/apic: Consolidate boot_cpu_physical_apicid initialization sites")
Signed-off-by: Adrian Huang <ahuang12@lenovo.com>
---
arch/x86/kernel/apic/apic.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 4667bc4b00ab..6700d6f266ca 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1703,6 +1703,9 @@ static __init void apic_read_boot_cpu_id(bool x2apic)
boot_cpu_physical_apicid = native_apic_msr_read(APIC_ID);
boot_cpu_apic_version = GET_APIC_VERSION(native_apic_msr_read(APIC_LVR));
} else {
+ if (boot_cpu_physical_apicid != BAD_APICID)
+ return;
+
boot_cpu_physical_apicid = read_apic_id();
boot_cpu_apic_version = GET_APIC_VERSION(apic_read(APIC_LVR));
}
--
2.25.1
next reply other threads:[~2024-04-28 18:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-30 14:56 Adrian Huang [this message]
2024-02-13 16:47 ` [PATCH] x86/apic: Fix APIC MSR access error when x2apic is disabled Thomas Gleixner
2024-02-15 6:53 ` Adrian Huang12
2024-04-25 22:30 ` [PATCH] x86/apic: Don't access the APIC when disabling X2APIC 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=20240130145601.7063-1-adrianhuang0701@gmail.com \
--to=adrianhuang0701@gmail.com \
--cc=ahuang12@lenovo.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=mingo@redhat.com \
--cc=tglx@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox