Module Name: src
Committed By: snj
Date: Tue Aug 11 05:13:45 UTC 2015
Modified Files:
src/sys/arch/x86/x86 [netbsd-7]: cpu_ucode_intel.c
Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #945):
sys/arch/x86/x86/cpu_ucode_intel.c: revisions 1.7, 1.8
Re-allocale buffer if a buffer for microcode is not 16byte aligned.
--
Use roundup2() and uintptr_t. Adviced by riastradh@.
To generate a diff of this commit:
cvs rdiff -u -r1.5.4.1 -r1.5.4.2 src/sys/arch/x86/x86/cpu_ucode_intel.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/x86/x86/cpu_ucode_intel.c
diff -u src/sys/arch/x86/x86/cpu_ucode_intel.c:1.5.4.1 src/sys/arch/x86/x86/cpu_ucode_intel.c:1.5.4.2
--- src/sys/arch/x86/x86/cpu_ucode_intel.c:1.5.4.1 Fri Jan 9 10:33:07 2015
+++ src/sys/arch/x86/x86/cpu_ucode_intel.c Tue Aug 11 05:13:44 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode_intel.c,v 1.5.4.1 2015/01/09 10:33:07 martin Exp $ */
+/* $NetBSD: cpu_ucode_intel.c,v 1.5.4.2 2015/08/11 05:13:44 snj Exp $ */
/*
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.5.4.1 2015/01/09 10:33:07 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.5.4.2 2015/08/11 05:13:44 snj Exp $");
#include "opt_xen.h"
#include "opt_cpu_ucode.h"
@@ -111,40 +111,54 @@ cpu_ucode_intel_apply(struct cpu_ucode_s
uint32_t ucodetarget, oucodeversion, nucodeversion;
int platformid;
struct intel1_ucode_header *uh;
+ size_t newbufsize = 0;
+ int rv = 0;
if (sc->loader_version != CPU_UCODE_LOADER_INTEL1
|| cpuno != CPU_UCODE_CURRENT_CPU)
return EINVAL;
- /* XXX relies on malloc alignment */
- if ((uintptr_t)(sc->sc_blob) & 15) {
- printf("ucode alignment bad\n");
- return EINVAL;
- }
-
uh = (struct intel1_ucode_header *)(sc->sc_blob);
if (uh->uh_header_ver != 1 || uh->uh_loader_rev != 1)
return EINVAL;
ucodetarget = uh->uh_rev;
+ if ((uintptr_t)(sc->sc_blob) & 15) {
+ /* Make the buffer 16 byte aligned */
+ newbufsize = sc->sc_blobsize + 15;
+ uh = kmem_alloc(newbufsize, KM_SLEEP);
+ if (uh == NULL) {
+ printf("%s: memory allocation failed\n", __func__);
+ return EINVAL;
+ }
+ uh = (struct intel1_ucode_header *)roundup2((uintptr_t)uh, 16);
+ /* Copy to the new area */
+ memcpy(uh, sc->sc_blob, sc->sc_blobsize);
+ }
+
kpreempt_disable();
intel_getcurrentucode(&oucodeversion, &platformid);
if (oucodeversion >= ucodetarget) {
kpreempt_enable();
- return EEXIST; /* ??? */
+ rv = EEXIST; /* ??? */
+ goto out;
}
wrmsr(MSR_BIOS_UPDT_TRIG, (uintptr_t)(sc->sc_blob) + 48);
intel_getcurrentucode(&nucodeversion, &platformid);
kpreempt_enable();
- if (nucodeversion != ucodetarget)
- return EIO;
+ if (nucodeversion != ucodetarget) {
+ rv = EIO;
+ goto out;
+ }
printf("cpu %d: ucode 0x%x->0x%x\n", curcpu()->ci_index,
oucodeversion, nucodeversion);
-
- return 0;
+out:
+ if (newbufsize != 0)
+ kmem_free(uh, newbufsize);
+ return rv;
}
#endif /* ! XEN */