All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/apic: Fix APIC MSR access error when x2apic is disabled
@ 2024-01-30 14:56 Adrian Huang
  2024-02-13 16:47 ` Thomas Gleixner
  0 siblings, 1 reply; 7+ messages in thread
From: Adrian Huang @ 2024-01-30 14:56 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen
  Cc: x86, Adrian Huang, Adrian Huang

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-30  5:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-30 14:56 [PATCH] x86/apic: Fix APIC MSR access error when x2apic is disabled Adrian Huang
2024-02-13 16:47 ` 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
2024-04-29 12:35       ` [tip: x86/urgent] " tip-bot2 for Thomas Gleixner
2024-04-30  5:55         ` Ingo Molnar
2024-04-30  5:59       ` [tip: x86/urgent] x86/apic: Don't access the APIC when disabling x2APIC tip-bot2 for Thomas Gleixner

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.