x86/acpi: Handle bogus MADT APIC tables gracefully

The recent fix to ignore invalid x2APIC entries inadvertently broke
systems with creative MADT APIC tables. The affected systems have APIC
MADT tables where all entries have invalid APIC IDs (0xFF), which means
they register exactly zero CPUs.

But the condition to ignore the entries of APIC IDs < 255 in the X2APIC
MADT table is solely based on the count of MADT APIC table entries.

As a consequence, the affected machines enumerate no secondary CPUs at
all because the APIC table has entries and therefore the X2APIC table
entries with APIC IDs < 255 are ignored.

Change the condition so that the APIC table preference for APIC IDs <
255 only becomes effective when the APIC table has valid APIC ID
entries.

IOW, an APIC table full of invalid APIC IDs is considered to be empty
which in consequence enables the X2APIC table entries with a APIC ID
< 255 and restores the expected behaviour.

Fixes: ec9aedb2aa1a ("x86/acpi: Ignore invalid x2APIC entries")
Reported-by: John Sperbeck <jsperbeck@google.com>
Reported-by: Andres Freund <andres@anarazel.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/169953729188.3135.6804572126118798018.tip-bot2@tip-bot2

authored by Thomas Gleixner and committed by Borislav Petkov (AMD) d5a10b97 2dc41961

Changed files
+1 -1
arch
x86
kernel
acpi
+1 -1
arch/x86/kernel/acpi/boot.c
··· 293 293 processor->processor_id, /* ACPI ID */ 294 294 processor->lapic_flags & ACPI_MADT_ENABLED); 295 295 296 + has_lapic_cpus = true; 296 297 return 0; 297 298 } 298 299 ··· 1135 1134 if (!count) { 1136 1135 count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC, 1137 1136 acpi_parse_lapic, MAX_LOCAL_APIC); 1138 - has_lapic_cpus = count > 0; 1139 1137 x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC, 1140 1138 acpi_parse_x2apic, MAX_LOCAL_APIC); 1141 1139 }