2009-10-29 13:52:37

by Andreas Herrmann

[permalink] [raw]
Subject: [PATCH 1/2] x86, amd-ucode: Check UCODE_MAGIC before loading the container file

>From 5183dd763c6dc9f760e29f3313e0ae3dda5228a2 Mon Sep 17 00:00:00 2001
From: Borislav Petkov <[email protected]>
Date: Thu, 29 Oct 2009 14:00:54 +0100
Subject: [PATCH 1/2] x86, amd-ucode: Check UCODE_MAGIC before loading the container file

Signed-off-by: Borislav Petkov <[email protected]>
Signed-off-by: Andreas Herrmann <[email protected]>
---
arch/x86/kernel/microcode_amd.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
index 366baa1..f4c538b 100644
--- a/arch/x86/kernel/microcode_amd.c
+++ b/arch/x86/kernel/microcode_amd.c
@@ -317,6 +317,12 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
return UCODE_NFOUND;
}

+ if (*(u32 *)firmware->data != UCODE_MAGIC) {
+ printk(KERN_ERR "microcode: invalid UCODE_MAGIC (0x%08x)\n",
+ *(u32 *)firmware->data);
+ return UCODE_ERROR;
+ }
+
ret = generic_load_microcode(cpu, firmware->data, firmware->size);

release_firmware(firmware);
--
1.6.5.1


2009-10-29 13:47:43

by Andreas Herrmann

[permalink] [raw]
Subject: [PATCH 2/2] x86, amd-ucode: Remove needless log messages


Signed-off-by: Andreas Herrmann <[email protected]>
---
arch/x86/kernel/microcode_amd.c | 9 +--------
1 files changed, 1 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
index f4c538b..c043534 100644
--- a/arch/x86/kernel/microcode_amd.c
+++ b/arch/x86/kernel/microcode_amd.c
@@ -109,12 +109,8 @@ static int get_matching_microcode(int cpu, void *mc, int rev)
return 0;
}

- if (mc_header->processor_rev_id != equiv_cpu_id) {
- printk(KERN_ERR "microcode: CPU%d: patch mismatch "
- "(processor_rev_id: %x, equiv_cpu_id: %x)\n",
- cpu, mc_header->processor_rev_id, equiv_cpu_id);
+ if (mc_header->processor_rev_id != equiv_cpu_id)
return 0;
- }

/* ucode might be chipset specific -- currently we don't support this */
if (mc_header->nb_dev_id || mc_header->sb_dev_id) {
@@ -185,9 +181,6 @@ get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)

total_size = (unsigned long) (section_hdr[4] + (section_hdr[5] << 8));

- printk(KERN_DEBUG "microcode: size %u, total_size %u\n",
- size, total_size);
-
if (total_size > size || total_size > UCODE_MAX_SIZE) {
printk(KERN_ERR "microcode: error: size mismatch\n");
return NULL;
--
1.6.5.1

2009-11-08 12:04:29

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86, amd-ucode: Check UCODE_MAGIC before loading the container file


* Andreas Herrmann <[email protected]> wrote:

> >From 5183dd763c6dc9f760e29f3313e0ae3dda5228a2 Mon Sep 17 00:00:00 2001
> From: Borislav Petkov <[email protected]>
> Date: Thu, 29 Oct 2009 14:00:54 +0100
> Subject: [PATCH 1/2] x86, amd-ucode: Check UCODE_MAGIC before loading the container file
>
> Signed-off-by: Borislav Petkov <[email protected]>
> Signed-off-by: Andreas Herrmann <[email protected]>
> ---
> arch/x86/kernel/microcode_amd.c | 6 ++++++
> 1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
> index 366baa1..f4c538b 100644
> --- a/arch/x86/kernel/microcode_amd.c
> +++ b/arch/x86/kernel/microcode_amd.c
> @@ -317,6 +317,12 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
> return UCODE_NFOUND;
> }
>
> + if (*(u32 *)firmware->data != UCODE_MAGIC) {
> + printk(KERN_ERR "microcode: invalid UCODE_MAGIC (0x%08x)\n",
> + *(u32 *)firmware->data);
> + return UCODE_ERROR;
> + }
> +
> ret = generic_load_microcode(cpu, firmware->data, firmware->size);
>
> release_firmware(firmware);

hm, there's no changelog. How was it found, what's the significance, do
we want it for .32 - i suspect we want - but we need a better changelog
for that.

Thanks,

Ingo

2009-11-08 14:10:23

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86, amd-ucode: Check UCODE_MAGIC before loading the container file

Hi Ingo,

On Sun, Nov 08, 2009 at 01:04:18PM +0100, Ingo Molnar wrote:
> hm, there's no changelog. How was it found,

code staring :)

> what's the significance,

required by design.

> do we want it for .32 - i suspect we want - but we need a better
> changelog for that.

Yes. How's that?

--
>From f41bced57e05c8adc0d2c13864b6323c191d45d2 Mon Sep 17 00:00:00 2001
From: Borislav Petkov <[email protected]>
Date: Thu, 29 Oct 2009 14:00:54 +0100
Subject: [PATCH] x86, amd-ucode: Check UCODE_MAGIC before loading the container file

When loading a microcode binary, we should check the microcode magic
value embedded in the image before continuing loading. The original
check got lost somehow so re-add it to the firmware requesting path.

Signed-off-by: Borislav Petkov <[email protected]>
Signed-off-by: Andreas Herrmann <[email protected]>
---
arch/x86/kernel/microcode_amd.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
index 366baa1..f4c538b 100644
--- a/arch/x86/kernel/microcode_amd.c
+++ b/arch/x86/kernel/microcode_amd.c
@@ -317,6 +317,12 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
return UCODE_NFOUND;
}

+ if (*(u32 *)firmware->data != UCODE_MAGIC) {
+ printk(KERN_ERR "microcode: invalid UCODE_MAGIC (0x%08x)\n",
+ *(u32 *)firmware->data);
+ return UCODE_ERROR;
+ }
+
ret = generic_load_microcode(cpu, firmware->data, firmware->size);

release_firmware(firmware);
--
1.6.5


--
Regards/Gruss,
Boris.

2009-11-08 14:55:57

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86, amd-ucode: Check UCODE_MAGIC before loading the container file


* Borislav Petkov <[email protected]> wrote:

> Hi Ingo,
>
> On Sun, Nov 08, 2009 at 01:04:18PM +0100, Ingo Molnar wrote:
> > hm, there's no changelog. How was it found,
>
> code staring :)
>
> > what's the significance,
>
> required by design.
>
> > do we want it for .32 - i suspect we want - but we need a better
> > changelog for that.
>
> Yes. How's that?
>
> --
> >From f41bced57e05c8adc0d2c13864b6323c191d45d2 Mon Sep 17 00:00:00 2001
> From: Borislav Petkov <[email protected]>
> Date: Thu, 29 Oct 2009 14:00:54 +0100
> Subject: [PATCH] x86, amd-ucode: Check UCODE_MAGIC before loading the container file
>
> When loading a microcode binary, we should check the microcode magic
> value embedded in the image before continuing loading. The original
> check got lost somehow so re-add it to the firmware requesting path.
>
> Signed-off-by: Borislav Petkov <[email protected]>
> Signed-off-by: Andreas Herrmann <[email protected]>
> ---
> arch/x86/kernel/microcode_amd.c | 6 ++++++
> 1 files changed, 6 insertions(+), 0 deletions(-)

Looks good - thanks!

Ingo

2009-11-08 14:57:54

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH 2/2] x86, amd-ucode: Remove needless log messages


* Andreas Herrmann <[email protected]> wrote:

>
> Signed-off-by: Andreas Herrmann <[email protected]>
> ---
> arch/x86/kernel/microcode_amd.c | 9 +--------
> 1 files changed, 1 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
> index f4c538b..c043534 100644
> --- a/arch/x86/kernel/microcode_amd.c
> +++ b/arch/x86/kernel/microcode_amd.c
> @@ -185,9 +181,6 @@ get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)
>
> total_size = (unsigned long) (section_hdr[4] + (section_hdr[5] << 8));
>
> - printk(KERN_DEBUG "microcode: size %u, total_size %u\n",
> - size, total_size);
> -

we should remove this one indeed.

> @@ -109,12 +109,8 @@ static int get_matching_microcode(int cpu, void *mc, int rev)
> return 0;
> }
>
> - if (mc_header->processor_rev_id != equiv_cpu_id) {
> - printk(KERN_ERR "microcode: CPU%d: patch mismatch "
> - "(processor_rev_id: %x, equiv_cpu_id: %x)\n",
> - cpu, mc_header->processor_rev_id, equiv_cpu_id);
> + if (mc_header->processor_rev_id != equiv_cpu_id)
> return 0;
> - }
>
> /* ucode might be chipset specific -- currently we don't support this */
> if (mc_header->nb_dev_id || mc_header->sb_dev_id) {

but why remove this one? Someone tries to load a mismatching microcode
file, isnt that some sort of bug in user-space? (Which ought to find out
whether it has anything for the CPU at hand, and only attempt it if it's
matching - or so.)

maybe it's not a KERN_ERR but KERN_INFO, but still.

Ingo

2009-11-09 13:35:22

by Andreas Herrmann

[permalink] [raw]
Subject: Re: [PATCH 2/2] x86, amd-ucode: Remove needless log messages

On Sun, Nov 08, 2009 at 03:57:48PM +0100, Ingo Molnar wrote:
>
> * Andreas Herrmann <[email protected]> wrote:

[...]

> > - if (mc_header->processor_rev_id != equiv_cpu_id) {
> > - printk(KERN_ERR "microcode: CPU%d: patch mismatch "
> > - "(processor_rev_id: %x, equiv_cpu_id: %x)\n",
> > - cpu, mc_header->processor_rev_id, equiv_cpu_id);
> > + if (mc_header->processor_rev_id != equiv_cpu_id)
> > return 0;
> > - }
> >
> > /* ucode might be chipset specific -- currently we don't support this */
> > if (mc_header->nb_dev_id || mc_header->sb_dev_id) {
>
> but why remove this one? Someone tries to load a mismatching microcode
> file, isnt that some sort of bug in user-space? (Which ought to find out
> whether it has anything for the CPU at hand, and only attempt it if it's
> matching - or so.)

The ucode file that we provide contains many ucode patches -- its a
"container" file providing patches for several CPUs. Of course this
means that there are patches in the file which are not meant for that
CPU -- that is no error case but rather normal.

> maybe it's not a KERN_ERR but KERN_INFO, but still.

KERN_DEBUG at the most. It's simple as that: if the CPU has same
PATCH_LEVEL before and after microcode.ko tried to update the ucode,
there either was no ucode-file available or it just didn't contain a
newer ucode version for this CPU.

Andreas

Subject: [tip:x86/urgent] x86, amd-ucode: Check UCODE_MAGIC before loading the container file

Commit-ID: 506f90eeae682dc96c11c7aefac0262b3a560b49
Gitweb: http://git.kernel.org/tip/506f90eeae682dc96c11c7aefac0262b3a560b49
Author: Borislav Petkov <[email protected]>
AuthorDate: Thu, 29 Oct 2009 14:45:52 +0100
Committer: Ingo Molnar <[email protected]>
CommitDate: Tue, 10 Nov 2009 05:46:09 +0100

x86, amd-ucode: Check UCODE_MAGIC before loading the container file

Signed-off-by: Borislav Petkov <[email protected]>
Signed-off-by: Andreas Herrmann <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/kernel/microcode_amd.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
index 366baa1..f4c538b 100644
--- a/arch/x86/kernel/microcode_amd.c
+++ b/arch/x86/kernel/microcode_amd.c
@@ -317,6 +317,12 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
return UCODE_NFOUND;
}

+ if (*(u32 *)firmware->data != UCODE_MAGIC) {
+ printk(KERN_ERR "microcode: invalid UCODE_MAGIC (0x%08x)\n",
+ *(u32 *)firmware->data);
+ return UCODE_ERROR;
+ }
+
ret = generic_load_microcode(cpu, firmware->data, firmware->size);

release_firmware(firmware);

2009-11-10 05:15:59

by Andreas Herrmann

[permalink] [raw]
Subject: [tip:x86/microcode] x86, amd-ucode: Remove needless log messages

Commit-ID: 6e18da75c28b592594fd632cf3e6eb09d3d078de
Gitweb: http://git.kernel.org/tip/6e18da75c28b592594fd632cf3e6eb09d3d078de
Author: Andreas Herrmann <[email protected]>
AuthorDate: Thu, 29 Oct 2009 14:47:42 +0100
Committer: Ingo Molnar <[email protected]>
CommitDate: Tue, 10 Nov 2009 05:49:28 +0100

x86, amd-ucode: Remove needless log messages

Signed-off-by: Andreas Herrmann <[email protected]>
Cc: Borislav Petkov <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/kernel/microcode_amd.c | 9 +--------
1 files changed, 1 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
index f4c538b..c043534 100644
--- a/arch/x86/kernel/microcode_amd.c
+++ b/arch/x86/kernel/microcode_amd.c
@@ -109,12 +109,8 @@ static int get_matching_microcode(int cpu, void *mc, int rev)
return 0;
}

- if (mc_header->processor_rev_id != equiv_cpu_id) {
- printk(KERN_ERR "microcode: CPU%d: patch mismatch "
- "(processor_rev_id: %x, equiv_cpu_id: %x)\n",
- cpu, mc_header->processor_rev_id, equiv_cpu_id);
+ if (mc_header->processor_rev_id != equiv_cpu_id)
return 0;
- }

/* ucode might be chipset specific -- currently we don't support this */
if (mc_header->nb_dev_id || mc_header->sb_dev_id) {
@@ -185,9 +181,6 @@ get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)

total_size = (unsigned long) (section_hdr[4] + (section_hdr[5] << 8));

- printk(KERN_DEBUG "microcode: size %u, total_size %u\n",
- size, total_size);
-
if (total_size > size || total_size > UCODE_MAX_SIZE) {
printk(KERN_ERR "microcode: error: size mismatch\n");
return NULL;