Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86/x86 Re-allocale buffer if a buffer for microcod...



details:   https://anonhg.NetBSD.org/src/rev/f1c7c9b85b50
branches:  trunk
changeset: 808262:f1c7c9b85b50
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Mon May 11 08:24:50 2015 +0000

description:
Re-allocale buffer if a buffer for microcode is not 16byte aligned.

diffstat:

 sys/arch/x86/x86/cpu_ucode_intel.c |  41 +++++++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 13 deletions(-)

diffs (85 lines):

diff -r 73aad08428ad -r f1c7c9b85b50 sys/arch/x86/x86/cpu_ucode_intel.c
--- a/sys/arch/x86/x86/cpu_ucode_intel.c        Mon May 11 06:58:13 2015 +0000
+++ b/sys/arch/x86/x86/cpu_ucode_intel.c        Mon May 11 08:24:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode_intel.c,v 1.6 2014/12/12 02:25:55 msaitoh Exp $ */
+/* $NetBSD: cpu_ucode_intel.c,v 1.7 2015/05/11 08:24:50 msaitoh 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.6 2014/12/12 02:25:55 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.7 2015/05/11 08:24:50 msaitoh Exp $");
 
 #include "opt_xen.h"
 #include "opt_cpu_ucode.h"
@@ -111,40 +111,55 @@
        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 *)
+                   (((unsigned long)uh + 15) & ~0x0000000f);
+               /* 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 */



Home | Main Index | Thread Index | Old Index