Commit a774635d authored by Li RongQing's avatar Li RongQing Committed by Thomas Gleixner

x86/apic: Fix signedness bug in APIC ID validity checks

The APIC ID as parsed from ACPI MADT is validity checked with the
apic->apic_id_valid() callback, which depends on the selected APIC type.

For non X2APIC types APIC IDs >= 0xFF are invalid, but values > 0x7FFFFFFF
are detected as valid. This happens because the 'apicid' argument of the
apic_id_valid() callback is type 'int'. So the resulting comparison

   apicid < 0xFF

evaluates to true for all unsigned int values > 0x7FFFFFFF which are handed
to default_apic_id_valid(). As a consequence, invalid APIC IDs in !X2APIC
mode are considered valid and accounted as possible CPUs.

Change the apicid argument type of the apic_id_valid() callback to u32 so
the evaluation is unsigned and returns the correct result.

[ tglx: Massaged changelog ]
Signed-off-by: default avatarLi RongQing <lirongqing@baidu.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Cc: jgross@suse.com
Cc: Dou Liyang <douly.fnst@cn.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: hpa@zytor.com
Link: https://lkml.kernel.org/r/1523322966-10296-1-git-send-email-lirongqing@baidu.com
parent d94a155c
...@@ -319,7 +319,7 @@ struct apic { ...@@ -319,7 +319,7 @@ struct apic {
/* Probe, setup and smpboot functions */ /* Probe, setup and smpboot functions */
int (*probe)(void); int (*probe)(void);
int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id); int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id);
int (*apic_id_valid)(int apicid); int (*apic_id_valid)(u32 apicid);
int (*apic_id_registered)(void); int (*apic_id_registered)(void);
bool (*check_apicid_used)(physid_mask_t *map, int apicid); bool (*check_apicid_used)(physid_mask_t *map, int apicid);
...@@ -492,7 +492,7 @@ static inline unsigned int read_apic_id(void) ...@@ -492,7 +492,7 @@ static inline unsigned int read_apic_id(void)
return apic->get_apic_id(reg); return apic->get_apic_id(reg);
} }
extern int default_apic_id_valid(int apicid); extern int default_apic_id_valid(u32 apicid);
extern int default_acpi_madt_oem_check(char *, char *); extern int default_acpi_madt_oem_check(char *, char *);
extern void default_setup_apic_routing(void); extern void default_setup_apic_routing(void);
......
...@@ -200,7 +200,7 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end) ...@@ -200,7 +200,7 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
{ {
struct acpi_madt_local_x2apic *processor = NULL; struct acpi_madt_local_x2apic *processor = NULL;
#ifdef CONFIG_X86_X2APIC #ifdef CONFIG_X86_X2APIC
int apic_id; u32 apic_id;
u8 enabled; u8 enabled;
#endif #endif
...@@ -222,10 +222,13 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end) ...@@ -222,10 +222,13 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
* to not preallocating memory for all NR_CPUS * to not preallocating memory for all NR_CPUS
* when we use CPU hotplug. * when we use CPU hotplug.
*/ */
if (!apic->apic_id_valid(apic_id) && enabled) if (!apic->apic_id_valid(apic_id)) {
printk(KERN_WARNING PREFIX "x2apic entry ignored\n"); if (enabled)
else pr_warn(PREFIX "x2apic entry ignored\n");
acpi_register_lapic(apic_id, processor->uid, enabled); return 0;
}
acpi_register_lapic(apic_id, processor->uid, enabled);
#else #else
printk(KERN_WARNING PREFIX "x2apic entry ignored\n"); printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
#endif #endif
......
...@@ -40,7 +40,7 @@ int default_check_phys_apicid_present(int phys_apicid) ...@@ -40,7 +40,7 @@ int default_check_phys_apicid_present(int phys_apicid)
return physid_isset(phys_apicid, phys_cpu_present_map); return physid_isset(phys_apicid, phys_cpu_present_map);
} }
int default_apic_id_valid(int apicid) int default_apic_id_valid(u32 apicid)
{ {
return (apicid < 255); return (apicid < 255);
} }
...@@ -56,7 +56,7 @@ static u32 numachip2_set_apic_id(unsigned int id) ...@@ -56,7 +56,7 @@ static u32 numachip2_set_apic_id(unsigned int id)
return id << 24; return id << 24;
} }
static int numachip_apic_id_valid(int apicid) static int numachip_apic_id_valid(u32 apicid)
{ {
/* Trust what bootloader passes in MADT */ /* Trust what bootloader passes in MADT */
return 1; return 1;
......
/* Common bits for X2APIC cluster/physical modes. */ /* Common bits for X2APIC cluster/physical modes. */
int x2apic_apic_id_valid(int apicid); int x2apic_apic_id_valid(u32 apicid);
int x2apic_apic_id_registered(void); int x2apic_apic_id_registered(void);
void __x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int dest); void __x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int dest);
unsigned int x2apic_get_apic_id(unsigned long id); unsigned int x2apic_get_apic_id(unsigned long id);
......
...@@ -101,7 +101,7 @@ static int x2apic_phys_probe(void) ...@@ -101,7 +101,7 @@ static int x2apic_phys_probe(void)
} }
/* Common x2apic functions, also used by x2apic_cluster */ /* Common x2apic functions, also used by x2apic_cluster */
int x2apic_apic_id_valid(int apicid) int x2apic_apic_id_valid(u32 apicid)
{ {
return 1; return 1;
} }
......
...@@ -557,7 +557,7 @@ static void uv_send_IPI_all(int vector) ...@@ -557,7 +557,7 @@ static void uv_send_IPI_all(int vector)
uv_send_IPI_mask(cpu_online_mask, vector); uv_send_IPI_mask(cpu_online_mask, vector);
} }
static int uv_apic_id_valid(int apicid) static int uv_apic_id_valid(u32 apicid)
{ {
return 1; return 1;
} }
......
...@@ -112,7 +112,7 @@ static int xen_madt_oem_check(char *oem_id, char *oem_table_id) ...@@ -112,7 +112,7 @@ static int xen_madt_oem_check(char *oem_id, char *oem_table_id)
return xen_pv_domain(); return xen_pv_domain();
} }
static int xen_id_always_valid(int apicid) static int xen_id_always_valid(u32 apicid)
{ {
return 1; return 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment