From: Denys Vlasenko <dvlasenk@redhat.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: Denys Vlasenko <dvlasenk@redhat.com>,
Daniel J Blueman <daniel@numascale.com>,
Jiang Liu <jiang.liu@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Len Brown <len.brown@intel.com>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] x86/apic: Make apic_version[] smaller
Date: Fri, 2 Oct 2015 21:12:24 +0200 [thread overview]
Message-ID: <1443813145-29102-2-git-send-email-dvlasenk@redhat.com> (raw)
In-Reply-To: <1443813145-29102-1-git-send-email-dvlasenk@redhat.com>
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
next prev parent reply other threads:[~2015-10-02 19:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-02 19:12 [PATCH 1/3] x86/apic: Rename MAX_LOCAL_APIC to MAX_LOCAL_APICID Denys Vlasenko
2015-10-02 19:12 ` Denys Vlasenko [this message]
2015-10-02 19:12 ` [PATCH 3/3] x86/apic: Use smaller array for __apicid_to_node[] mapping Denys Vlasenko
2015-10-03 7:44 ` Ingo Molnar
2015-10-03 20:26 ` Denys Vlasenko
2015-10-05 4:32 ` [PATCH v2] " Daniel J Blueman
2015-10-09 14:15 ` Thomas Gleixner
2015-10-09 15:16 ` Jiang Liu
2015-10-09 20:40 ` Thomas Gleixner
2015-10-09 15:35 ` [PATCH 3/3] " Jiang Liu
2015-10-12 10:21 ` Daniel J Blueman
2015-10-12 10:25 ` Thomas Gleixner
2015-10-13 9:32 ` Jiang Liu
2015-10-13 12:55 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1443813145-29102-2-git-send-email-dvlasenk@redhat.com \
--to=dvlasenk@redhat.com \
--cc=daniel@numascale.com \
--cc=jiang.liu@linux.intel.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®