[PATCH 2/3] x86/apic: Make apic_version[] smaller

From: Denys Vlasenko
Date: Fri Oct 02 2015 - 15:12:56 EST


apic_version[] array is changed from int to u8 -
APIC version values as of year 2015 are no larger than 0x1f
on all known CPUs.

A bit of code added to ensure that the statement
apic_version[apicid] = version;
in generic_processor_info() is safe wrt bad values in both
'apicid' and 'version' variables.

This reduces apic_version[] from 128 kbytes to 32.

Signed-off-by: Denys Vlasenko <dvlasenk@xxxxxxxxxx>
CC: Ingo Molnar <mingo@xxxxxxxxxx>
CC: Daniel J Blueman <daniel@xxxxxxxxxxxxx>
CC: Jiang Liu <jiang.liu@xxxxxxxxxxxxxxx>
CC: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
CC: Len Brown <len.brown@xxxxxxxxx>
CC: x86@xxxxxxxxxx
CC: linux-kernel@xxxxxxxxxxxxxxx
---
arch/x86/include/asm/mpspec.h | 2 +-
arch/x86/kernel/apic/apic.c | 19 ++++++++++++++++++-
2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/mpspec.h b/arch/x86/include/asm/mpspec.h
index e84e542..83140ab 100644
--- a/arch/x86/include/asm/mpspec.h
+++ b/arch/x86/include/asm/mpspec.h
@@ -6,7 +6,7 @@
#include <asm/x86_init.h>
#include <asm/apicdef.h>

-extern int apic_version[];
+extern u8 apic_version[];
extern int pic_mode;

#ifdef CONFIG_X86_32
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index b08b447..d0f135c 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1798,7 +1798,7 @@ void __init register_lapic_address(unsigned long address)
}
}

-int apic_version[MAX_LOCAL_APICID];
+u8 apic_version[MAX_LOCAL_APICID];

/*
* Local APIC interrupts
@@ -2054,6 +2054,23 @@ int generic_processor_info(int apicid, int version)
return -EINVAL;
}

+ if ((unsigned)apicid >= ARRAY_SIZE(apic_version)) {
+ int thiscpu = max + disabled_cpus;
+ pr_warning("APIC: APIC id 0x%x is too large."
+ " Processor %d ignored.\n",
+ apicid, thiscpu);
+ disabled_cpus++;
+ return -EINVAL;
+ }
+ if ((unsigned)version > 255) {
+ int thiscpu = max + disabled_cpus;
+ pr_warning("APIC: APIC version 0x%x is too large."
+ " Processor %d ignored.\n",
+ version, thiscpu);
+ disabled_cpus++;
+ return -EINVAL;
+ }
+
num_processors++;
if (apicid == boot_cpu_physical_apicid) {
/*
--
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/