Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1238545
| From | Denys Vlasenko <dvlasenk@redhat.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 2/3] x86/apic: Make apic_version[] smaller |
| Date | 2015-10-02 21:20 +0200 |
| Message-ID | <qfe26-46r-11@gated-at.bofh.it> (permalink) |
| References | <qfe25-46r-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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@redhat.com>
CC: Ingo Molnar <mingo@kernel.org>
CC: Daniel J Blueman <daniel@numascale.com>
CC: Jiang Liu <jiang.liu@linux.intel.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Len Brown <len.brown@intel.com>
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
---
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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 1/3] x86/apic: Rename MAX_LOCAL_APIC to MAX_LOCAL_APICID Denys Vlasenko <dvlasenk@redhat.com> - 2015-10-02 21:20 +0200
[PATCH 2/3] x86/apic: Make apic_version[] smaller Denys Vlasenko <dvlasenk@redhat.com> - 2015-10-02 21:20 +0200
[PATCH 3/3] x86/apic: Use smaller array for __apicid_to_node[] mapping Denys Vlasenko <dvlasenk@redhat.com> - 2015-10-02 21:20 +0200
Re: [PATCH 3/3] x86/apic: Use smaller array for __apicid_to_node[] mapping Ingo Molnar <mingo@kernel.org> - 2015-10-03 09:50 +0200
Re: [PATCH 3/3] x86/apic: Use smaller array for __apicid_to_node[] mapping Denys Vlasenko <dvlasenk@redhat.com> - 2015-10-03 22:30 +0200
[PATCH v2] x86/apic: Use smaller array for __apicid_to_node[] mapping Daniel J Blueman <daniel@numascale.com> - 2015-10-05 06:40 +0200
csiph-web