Skip to contentSkip to conversation

x86/microcode/intel: Squelch frame size warnings

PATCH In review [email protected] 4 participants 10 messages Jan 7, 2016 – Mar 9, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover x86/microcode/intel: Squelch frame size warnings

This patch set implements dynamic memory allocation for some over sized automatic variables. This code has been boot tested on a 2-way Sandy Bridge with the intel-microcode package installed, though I'm sure that isn't an exhaustive test.

rtg

Signature · 1 line
Tim Gardner [email protected]
#1 lore raw

PATCH 1/4 x86/microcode/intel: save_mc_for_early: Squelch frame size warning

From: Tim Gardner <[email protected]>

arch/x86/kernel/cpu/microcode/intel.c: In function 'save_mc_for_early':
arch/x86/kernel/cpu/microcode/intel.c:516:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]

gcc version 5.3.1 20160101 (Ubuntu 5.3.1-5ubuntu1)

Cc Borislav Petkov <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/cpu/microcode/intel.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/intel.c +7 -1
index ce47402..bee5e84 100644
@@ -463,13 +463,18 @@ static DEFINE_MUTEX(x86_cpu_microcode_mutex);
  */
 int save_mc_for_early(u8 *mc)
 {
-	struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT];
+	struct microcode_intel **mc_saved_tmp;
 	unsigned int mc_saved_count_init;
 	unsigned int mc_saved_count;
 	struct microcode_intel **mc_saved;
 	int ret = 0;
 	int i;
 
+	mc_saved_tmp = kcalloc(MAX_UCODE_COUNT, sizeof(*mc_saved_tmp),
+		GFP_KERNEL);
+	if (!mc_saved_tmp)
+		return -ENOMEM;
+
 	/*
 	 * Hold hotplug lock so mc_saved_data is not accessed by a CPU in
 	 * hotplug.
@@ -512,6 +517,7 @@ int save_mc_for_early(u8 *mc)
 out:
 	mutex_unlock(&x86_cpu_microcode_mutex);
 
+	kfree(mc_saved_tmp);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(save_mc_for_early);
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH v4.4-rc8 1/4] x86/microcode/intel: save_mc_for_early: Squelch frame size warning

Quoted 4 lines · On Thu, Jan 07, 2016 at 07:59:56AM -0700, [email protected] wrote:

From: Tim Gardner <[email protected]>

arch/x86/kernel/cpu/microcode/intel.c: In function 'save_mc_for_early':
arch/x86/kernel/cpu/microcode/intel.c:516:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]

Ok, so this looks like a 32-bit warning to me.

Hmm, so, on the one hand we do have:

$ git grep CONFIG_FRAME_WARN arch/x86/
arch/x86/configs/i386_defconfig:291:CONFIG_FRAME_WARN=2048

which came in with:

5cb04df8d3f0 ("x86: defconfig updates")

and OTOH:

config FRAME_WARN
int "Warn for stack frames larger than (needs gcc 4.4)" range 0 8192
default 0 if KASAN
default 1024 if !64BIT
^^^^

default 2048 if 64BIT
help
Tell gcc to warn at build time for stack frames larger than this. Setting this too low will cause a lot of warnings. Setting it to 0 disables the warning.
Requires gcc 4.4

which is still 1024.

tip guys, maybe it is time to update lib/Kconfig.debug too?

Signature · 4 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
#3 lore raw

Re: [PATCH v4.4-rc8 1/4] x86/microcode/intel: save_mc_for_early: Squelch frame size warning

Quoted 33 lines · Borislav Petkov
Quoted 4 lines · On Thu, Jan 07, 2016 at 07:59:56AM -0700, [email protected] wrote:

From: Tim Gardner <[email protected]>

arch/x86/kernel/cpu/microcode/intel.c: In function 'save_mc_for_early':
arch/x86/kernel/cpu/microcode/intel.c:516:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]

Ok, so this looks like a 32-bit warning to me.

Hmm, so, on the one hand we do have:

$ git grep CONFIG_FRAME_WARN arch/x86/
arch/x86/configs/i386_defconfig:291:CONFIG_FRAME_WARN=2048

which came in with:

5cb04df8d3f0 ("x86: defconfig updates")

and OTOH:

config FRAME_WARN
int "Warn for stack frames larger than (needs gcc 4.4)" range 0 8192
default 0 if KASAN
default 1024 if !64BIT
^^^^

default 2048 if 64BIT
help
Tell gcc to warn at build time for stack frames larger than this. Setting this too low will cause a lot of warnings. Setting it to 0 disables the warning.
Requires gcc 4.4

Quoted 3 lines

which is still 1024.

tip guys, maybe it is time to update lib/Kconfig.debug too?

I think we should rather update the 32-bit defconfig? 64-bit stacks are more generous, and a 2K stack footprint is pretty extreme on 32-bit I think ...

Thanks,

Ingo

maintainer
#4 lore raw

Re: [PATCH v4.4-rc8 1/4] x86/microcode/intel: save_mc_for_early: Squelch frame size warning

Quoted 3 lines · Ingo Molnar

I think we should rather update the 32-bit defconfig? 64-bit stacks are more generous, and a 2K stack footprint is pretty extreme on 32-bit I think ...

See reply to this message.

With it, i386 defconfig of tip/master builds fine and without warnings even though relevant stuff is selected:

$ grep -E "(MICROCODE|FRAME_WARN)" .config
CONFIG_MICROCODE=y
CONFIG_MICROCODE_INTEL=y
CONFIG_MICROCODE_AMD=y
CONFIG_MICROCODE_OLD_INTERFACE=y
CONFIG_FRAME_WARN=1024
Signature · 4 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
maintainer
#5 lore raw

PATCH 1/1 x86/i386-defconfig: Set CONFIG_FRAME_WARN to Kconfig default

Sync it to the Kconfig default for 32-bit.

---
 arch/x86/configs/i386_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/configs/i386_defconfig +1 -1
index 028be48c8839..e25a1630320c 100644
@@ -288,7 +288,7 @@ CONFIG_NLS_ISO8859_1=y
 CONFIG_NLS_UTF8=y
 CONFIG_PRINTK_TIME=y
 # CONFIG_ENABLE_WARN_DEPRECATED is not set
-CONFIG_FRAME_WARN=2048
+CONFIG_FRAME_WARN=1024
 CONFIG_MAGIC_SYSRQ=y
 # CONFIG_UNUSED_SYMBOLS is not set
 CONFIG_DEBUG_KERNEL=y
Signature · 7 lines
2.3.5

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
#6 lore raw

[tip:x86/build] x86/defconfigs/32: Set CONFIG_FRAME_WARN to the Kconfig default

x86/defconfigs/32: Set CONFIG_FRAME_WARN to the Kconfig default
Commit-ID:  8b30a8b3c636a155bab9176ad209964c9c22252d
Gitweb:     http://git.kernel.org/tip/8b30a8b3c636a155bab9176ad209964c9c22252d
Author:     Borislav Petkov <[email protected]>
AuthorDate: Wed, 9 Mar 2016 14:48:21 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 9 Mar 2016 14:53:41 +0100

x86/defconfigs/32: Set CONFIG_FRAME_WARN to the Kconfig default

Sync it to the Kconfig default for 32-bit.

---
 arch/x86/configs/i386_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/configs/i386_defconfig +1 -1
index 028be48..e25a163 100644
@@ -288,7 +288,7 @@ CONFIG_NLS_ISO8859_1=y
 CONFIG_NLS_UTF8=y
 CONFIG_PRINTK_TIME=y
 # CONFIG_ENABLE_WARN_DEPRECATED is not set
-CONFIG_FRAME_WARN=2048
+CONFIG_FRAME_WARN=1024
 CONFIG_MAGIC_SYSRQ=y
 # CONFIG_UNUSED_SYMBOLS is not set
 CONFIG_DEBUG_KERNEL=y
#7 lore raw

PATCH 2/4 x86/microcode/intel: save_microcode_in_initrd_intel: Squelch frame size warning

In reply to [email protected]

From: Tim Gardner <[email protected]>

arch/x86/kernel/cpu/microcode/intel.c: In function 'save_microcode_in_initrd_intel':
arch/x86/kernel/cpu/microcode/intel.c:705:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]

gcc version 5.3.1 20160101 (Ubuntu 5.3.1-5ubuntu1)

Cc Borislav Petkov <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/cpu/microcode/intel.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/intel.c +6 -1
index bee5e84..ebf5e66 100644
@@ -694,12 +694,16 @@ static int apply_microcode_early(struct ucode_cpu_info *uci, bool early)
 int __init save_microcode_in_initrd_intel(void)
 {
 	unsigned int count = mc_saved_data.mc_saved_count;
-	struct microcode_intel *mc_saved[MAX_UCODE_COUNT];
+	struct microcode_intel **mc_saved;
 	int ret = 0;
 
 	if (count == 0)
 		return ret;
 
+	mc_saved = kcalloc(MAX_UCODE_COUNT, sizeof(*mc_saved), GFP_KERNEL);
+	if (!mc_saved)
+		return -ENOMEM;
+
 	copy_initrd_ptrs(mc_saved, mc_saved_in_initrd, initrd_start, count);
 	ret = save_microcode(&mc_saved_data, mc_saved, count);
 	if (ret)
@@ -707,6 +711,7 @@ int __init save_microcode_in_initrd_intel(void)
 
 	show_saved_mc();
 
+	kfree(mc_saved);
 	return ret;
 }
 
Signature · 1 line
1.9.1
#8 lore raw

PATCH 3/4 x86/microcode/intel: load_microcode: Squelch frame size warning

In reply to [email protected]

From: Tim Gardner <[email protected]>

arch/x86/kernel/cpu/microcode/intel.c: In function 'load_microcode.isra.2.constprop':
arch/x86/kernel/cpu/microcode/intel.c:130:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]

gcc version 5.3.1 20160101 (Ubuntu 5.3.1-5ubuntu1)

Cc Borislav Petkov <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/cpu/microcode/intel.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +12 -4
index ebf5e66..e019c11 100644
@@ -111,22 +111,30 @@ static enum ucode_state
 load_microcode(struct mc_saved_data *mc_saved_data, unsigned long *initrd,
 	       unsigned long initrd_start, struct ucode_cpu_info *uci)
 {
-	struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT];
+	struct microcode_intel **mc_saved_tmp;
 	unsigned int count = mc_saved_data->mc_saved_count;
+	enum ucode_state state;
+
+	mc_saved_tmp = kcalloc(MAX_UCODE_COUNT, sizeof(*mc_saved_tmp),
+		GFP_KERNEL);
+	if (!mc_saved_tmp)
+		return UCODE_ERROR;
 
 	if (!mc_saved_data->mc_saved) {
 		copy_initrd_ptrs(mc_saved_tmp, initrd, initrd_start, count);
 
-		return load_microcode_early(mc_saved_tmp, count, uci);
+		state = load_microcode_early(mc_saved_tmp, count, uci);
 	} else {
 #ifdef CONFIG_X86_32
 		microcode_phys(mc_saved_tmp, mc_saved_data);
-		return load_microcode_early(mc_saved_tmp, count, uci);
+		state = load_microcode_early(mc_saved_tmp, count, uci);
 #else
-		return load_microcode_early(mc_saved_data->mc_saved,
+		state = load_microcode_early(mc_saved_data->mc_saved,
 						    count, uci);
 #endif
 	}
+	kfree(mc_saved_tmp);
+	return state;
 }
 
 /*
Signature · 1 line
1.9.1
#9 lore raw

PATCH 4/4 x86/microcode/intel: get_matching_model_microcode: Squelch frame size warning

In reply to [email protected]

From: Tim Gardner <[email protected]>

arch/x86/kernel/cpu/microcode/intel.c: In function 'get_matching_model_microcode.isra.3.constprop':
arch/x86/kernel/cpu/microcode/intel.c:348:1: warning: the frame size of 1080 bytes is larger than 1024 bytes [-Wframe-larger-than=]

gcc version 5.3.1 20160101 (Ubuntu 5.3.1-5ubuntu1)

Cc Borislav Petkov <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/cpu/microcode/intel.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +8 -2
index e019c11..03099ea 100644
@@ -303,11 +303,16 @@ get_matching_model_microcode(int cpu, unsigned long start,
 	enum ucode_state state = UCODE_OK;
 	unsigned int mc_size;
 	struct microcode_header_intel *mc_header;
-	struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT];
+	struct microcode_intel **mc_saved_tmp;
 	unsigned int mc_saved_count = mc_saved_data->mc_saved_count;
 	int i;
 
-	while (leftover && mc_saved_count < ARRAY_SIZE(mc_saved_tmp)) {
+	mc_saved_tmp = kcalloc(MAX_UCODE_COUNT, sizeof(*mc_saved_tmp),
+		GFP_KERNEL);
+	if (!mc_saved_tmp)
+		return UCODE_ERROR;
+
+	while (leftover && mc_saved_count < MAX_UCODE_COUNT) {
 
 		if (leftover < sizeof(mc_header))
 			break;
@@ -352,6 +357,7 @@ get_matching_model_microcode(int cpu, unsigned long start,
 
 	mc_saved_data->mc_saved_count = mc_saved_count;
 out:
+	kfree(mc_saved_tmp);
 	return state;
 }
 
Signature · 1 line
1.9.1