Skip to content

Commit 4797f6b

Browse files
Yinghai LuIngo Molnar
authored andcommitted
x86: read apic ID in the !acpi_lapic case
Ed found that on 32-bit, boot_cpu_physical_apicid is not read right, when the mptable is broken. Interestingly, actually three paths use/set it: 1. acpi: at that time that is already read from reg 2. mptable: only read from mptable 3. no madt, and no mptable, that use default apic id 0 for 64-bit, -1 for 32-bit so we could read the apic id for the 2/3 path. We trust the hardware register more than we trust a BIOS data structure (the mptable). We can also avoid the double set_fixmap() when acpi_lapic is used, and also need to move cpu_has_apic earlier and call apic_disable(). Also when need to update the apic id, we'd better read and set the apic version as well - so that quirks are applied precisely. v2: make path 3 with 64bit, use -1 as apic id, so could read it later. v3: fix whitespace problem pointed out by Ed Swierk v5: fix boot crash [ Impact: get correct apic id for bsp other than acpi path ] Reported-by: Ed Swierk <eswierk@aristanetworks.com> Signed-off-by: Yinghai Lu <yinghai@kernel.org> Acked-by: Cyrill Gorcunov <gorcunov@openvz.org> LKML-Reference: <49FC85A9.2070702@kernel.org> [ v4: sanity-check in the ACPI case too ] Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 6cda3eb commit 4797f6b

3 files changed

Lines changed: 28 additions & 25 deletions

File tree

‎arch/x86/include/asm/smp.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ extern int safe_smp_processor_id(void);
180180
static inline int logical_smp_processor_id(void)
181181
{
182182
/* we don't want to mark this access volatile - bad code generation */
183-
return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR));
183+
return GET_APIC_LOGICAL_ID(apic_read(APIC_LDR));
184184
}
185185

186186
#endif

‎arch/x86/kernel/apic/apic.c‎

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,24 @@ static int modern_apic(void)
242242
* bare function to substitute write operation
243243
* and it's _that_ fast :)
244244
*/
245-
void native_apic_write_dummy(u32 reg, u32 v)
245+
static void native_apic_write_dummy(u32 reg, u32 v)
246246
{
247247
WARN_ON_ONCE((cpu_has_apic || !disable_apic));
248248
}
249249

250+
static u32 native_apic_read_dummy(u32 reg)
251+
{
252+
WARN_ON_ONCE((cpu_has_apic || !disable_apic));
253+
return 0;
254+
}
255+
250256
/*
251-
* right after this call apic->write doesn't do anything
257+
* right after this call apic->write/read doesn't do anything
252258
* note that there is no restore operation it works one way
253259
*/
254260
void apic_disable(void)
255261
{
262+
apic->read = native_apic_read_dummy;
256263
apic->write = native_apic_write_dummy;
257264
}
258265

@@ -1576,32 +1583,23 @@ void __init init_apic_mappings(void)
15761583
return;
15771584
}
15781585

1579-
/*
1580-
* If no local APIC can be found then set up a fake all
1581-
* zeroes page to simulate the local APIC and another
1582-
* one for the IO-APIC.
1583-
*/
1586+
/* If no local APIC can be found return early */
15841587
if (!smp_found_config && detect_init_APIC()) {
1585-
apic_phys = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
1586-
apic_phys = __pa(apic_phys);
1587-
} else
1588+
/* lets NOP'ify apic operations */
1589+
pr_info("APIC: disable apic facility\n");
1590+
apic_disable();
1591+
} else {
15881592
apic_phys = mp_lapic_addr;
15891593

1590-
/*
1591-
* acpi lapic path already maps that address in
1592-
* acpi_register_lapic_address()
1593-
*/
1594-
if (!acpi_lapic)
1595-
set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
1596-
1597-
apic_printk(APIC_VERBOSE, "mapped APIC to %08lx (%08lx)\n",
1598-
APIC_BASE, apic_phys);
1594+
/*
1595+
* acpi lapic path already maps that address in
1596+
* acpi_register_lapic_address()
1597+
*/
1598+
if (!acpi_lapic)
1599+
set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
15991600

1600-
/* lets check if we may NOP'ify apic operations */
1601-
if (!cpu_has_apic) {
1602-
pr_info("APIC: disable apic facility\n");
1603-
apic_disable();
1604-
return;
1601+
apic_printk(APIC_VERBOSE, "mapped APIC to %08lx (%08lx)\n",
1602+
APIC_BASE, apic_phys);
16051603
}
16061604

16071605
/*

‎arch/x86/kernel/apic/io_apic.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,11 @@ __apicdebuginit(void) print_PIC(void)
18781878
__apicdebuginit(int) print_all_ICs(void)
18791879
{
18801880
print_PIC();
1881+
1882+
/* don't print out if apic is not there */
1883+
if (!cpu_has_apic || disable_apic)
1884+
return 0;
1885+
18811886
print_all_local_APICs();
18821887
print_IO_APIC();
18831888

0 commit comments

Comments
 (0)