Source-Changes-HG archive

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

[src/pgoyette-compat]: src/sys Import christos's changes for the compat_60 cp...



details:   https://anonhg.NetBSD.org/src/rev/42cf6ba90a54
branches:  pgoyette-compat
changeset: 321059:42cf6ba90a54
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat Mar 17 21:37:52 2018 +0000

description:
Import christos's changes for the compat_60 cpu_ucode stuff

diffstat:

 sys/arch/x86/include/cpu_ucode.h   |    9 +-
 sys/arch/x86/x86/cpu_ucode.c       |   98 +++++++++++++++++------
 sys/arch/x86/x86/cpu_ucode_amd.c   |   35 ++-----
 sys/arch/x86/x86/cpu_ucode_intel.c |   18 ++--
 sys/arch/xen/conf/files.xen        |    4 +-
 sys/arch/xen/xen/xen_ucode.c       |  149 -------------------------------------
 sys/compat/common/Makefile.sysio   |    4 +-
 sys/compat/common/compat_mod.c     |   11 ++-
 sys/compat/common/kern_cpu_60.c    |   75 ++++++++++++++++++
 sys/compat/sys/cpuio.h             |    7 +-
 sys/kern/kern_cpu.c                |   25 +-----
 11 files changed, 191 insertions(+), 244 deletions(-)

diffs (truncated from 705 to 300 lines):

diff -r 006cd9a45ba8 -r 42cf6ba90a54 sys/arch/x86/include/cpu_ucode.h
--- a/sys/arch/x86/include/cpu_ucode.h  Sat Mar 17 06:50:55 2018 +0000
+++ b/sys/arch/x86/include/cpu_ucode.h  Sat Mar 17 21:37:52 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode.h,v 1.3 2012/10/17 20:19:55 drochner Exp $ */
+/* $NetBSD: cpu_ucode.h,v 1.3.36.1 2018/03/17 21:37:52 pgoyette Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -47,14 +47,11 @@
 #include <sys/cpuio.h>
 #include <dev/firmload.h>
 
-int cpu_ucode_amd_get_version(struct cpu_ucode_version *);
-#ifdef COMPAT_60
-int compat6_cpu_ucode_amd_get_version(struct compat6_cpu_ucode *);
-#endif
+int cpu_ucode_amd_get_version(struct cpu_ucode_version *, void *, size_t);
 int cpu_ucode_amd_firmware_open(firmware_handle_t *, const char *);
 int cpu_ucode_amd_apply(struct cpu_ucode_softc *, int);
 
-int cpu_ucode_intel_get_version(struct cpu_ucode_version *);
+int cpu_ucode_intel_get_version(struct cpu_ucode_version *, void *, size_t);
 int cpu_ucode_intel_firmware_open(firmware_handle_t *, const char *);
 int cpu_ucode_intel_apply(struct cpu_ucode_softc *, int);
 #endif /* _KERNEL */
diff -r 006cd9a45ba8 -r 42cf6ba90a54 sys/arch/x86/x86/cpu_ucode.c
--- a/sys/arch/x86/x86/cpu_ucode.c      Sat Mar 17 06:50:55 2018 +0000
+++ b/sys/arch/x86/x86/cpu_ucode.c      Sat Mar 17 21:37:52 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode.c,v 1.5.16.2 2018/03/17 06:49:56 pgoyette Exp $ */
+/* $NetBSD: cpu_ucode.c,v 1.5.16.3 2018/03/17 21:37:52 pgoyette Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,9 +29,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode.c,v 1.5.16.2 2018/03/17 06:49:56 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode.c,v 1.5.16.3 2018/03/17 21:37:52 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
+#include "opt_xen.h"
+
 #include "opt_cpu_ucode.h"
 #include "opt_compat_netbsd.h"
 #endif
@@ -47,39 +49,40 @@
 
 #include <x86/cpu_ucode.h>
 
+#ifdef XEN
+#include <xen/xen-public/xen.h>
+#include <xen/hypervisor.h>
+#endif
+
 static struct cpu_ucode_softc ucode_softc;
 
 int
 cpu_ucode_get_version(struct cpu_ucode_version *data)
 {
+       union {
+               struct cpu_ucode_version_amd a;
+               struct cpu_ucode_version_intel1 i;
+       } v;
+       size_t l;
+       int error;
+
+       if (!data->data)
+               return 0;
 
        switch (cpu_vendor) {
        case CPUVENDOR_AMD:
-               return cpu_ucode_amd_get_version(data);
+               error = cpu_ucode_amd_get_version(data, &v, l = sizeof(v.a));
        case CPUVENDOR_INTEL:
-               return cpu_ucode_intel_get_version(data);
+               error = cpu_ucode_intel_get_version(data, &v, l = sizeof(v.i));
        default:
                return EOPNOTSUPP;
        }
 
-       return 0;
-}
-
-#ifdef COMPAT_60
-int
-compat6_cpu_ucode_get_version(struct compat6_cpu_ucode *data)
-{
+       if (error)
+               return error;
 
-       switch (cpu_vendor) {
-       case CPUVENDOR_AMD:
-               return compat6_cpu_ucode_amd_get_version(data);
-       default:
-               return EOPNOTSUPP;
-       }
-
-       return 0;
+       return copyout(&v, data->data, l);
 }
-#endif /* COMPAT60 */
 
 int
 cpu_ucode_md_open(firmware_handle_t *fwh, int loader_version, const char *fwname)
@@ -94,6 +97,7 @@
        }
 }
 
+#ifndef XEN
 int
 cpu_ucode_apply(const struct cpu_ucode *data)
 {
@@ -114,7 +118,7 @@
                error = cpu_ucode_intel_apply(sc, data->cpu_nr);
                break;
        default:
-               return EOPNOTSUPP;
+               error = EOPNOTSUPP;
        }
 
        if (sc->sc_blob != NULL)
@@ -123,28 +127,66 @@
        sc->sc_blobsize = 0;
        return error;
 }
-
-#ifdef COMPAT_60
+#else
 int
-compat6_cpu_ucode_apply(const struct compat6_cpu_ucode *data)
+cpu_ucode_apply(const struct cpu_ucode *data)
 {
        struct cpu_ucode_softc *sc = &ucode_softc;
+       struct xen_platform_op op;
        int error;
 
-       if (cpu_vendor != CPUVENDOR_AMD)
+       /* Xen updates all??? */
+       if (data->cpu_nr != CPU_UCODE_ALL_CPUS)
                return EOPNOTSUPP;
 
-       sc->loader_version = CPU_UCODE_LOADER_AMD;
+       sc->loader_version = data->loader_version;
        error = cpu_ucode_load(sc, data->fwname);
        if (error)
                return error;
 
-       error = cpu_ucode_amd_apply(sc, CPU_UCODE_ALL_CPUS);
+       op.cmd = XENPF_microcode_update;
+       set_xen_guest_handle(op.u.microcode.data, sc->sc_blob);
+       op.u.microcode.length = sc->sc_blobsize;
 
-       if (sc->sc_blob != NULL)
+       error = -HYPERVISOR_platform_op(&op);
+
+       if (sc->sc_blob)
                firmware_free(sc->sc_blob, sc->sc_blobsize);
        sc->sc_blob = NULL;
        sc->sc_blobsize = 0;
        return error;
 }
+#endif
+
+#ifdef COMPAT_60
+int
+compat6_cpu_ucode_get_version(struct compat6_cpu_ucode *data)
+{
+       struct cpu_ucode_version ndata;
+
+       switch (cpu_vendor) {
+       case CPUVENDOR_AMD:
+               ndata.loader_version = CPU_UCODE_LOADER_AMD;
+               return cpu_ucode_amd_get_version(&ndata, &data->version,
+                   sizeof(data->version));
+       default:
+               return EOPNOTSUPP;
+       }
+}
+
+int
+compat6_cpu_ucode_apply(const struct compat6_cpu_ucode *data6)
+{
+
+       if (cpu_vendor != CPUVENDOR_AMD)
+               return EOPNOTSUPP;
+
+       struct cpu_ucode data;
+
+       data.loader_version = CPU_UCODE_LOADER_AMD;
+       data.cpu_nr = CPU_UCODE_ALL_CPUS;
+       strcpy(data.fwname, data6->fwname);
+
+       return cpu_ucode_apply(&data);
+}
 #endif /* COMPAT60 */
diff -r 006cd9a45ba8 -r 42cf6ba90a54 sys/arch/x86/x86/cpu_ucode_amd.c
--- a/sys/arch/x86/x86/cpu_ucode_amd.c  Sat Mar 17 06:50:55 2018 +0000
+++ b/sys/arch/x86/x86/cpu_ucode_amd.c  Sat Mar 17 21:37:52 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode_amd.c,v 1.7 2013/11/15 08:47:55 msaitoh Exp $ */
+/* $NetBSD: cpu_ucode_amd.c,v 1.7.28.1 2018/03/17 21:37:52 pgoyette Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,11 +29,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_amd.c,v 1.7 2013/11/15 08:47:55 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_amd.c,v 1.7.28.1 2018/03/17 21:37:52 pgoyette Exp $");
 
 #include "opt_xen.h"
 #include "opt_cpu_ucode.h"
-#include "opt_compat_netbsd.h"
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -101,33 +100,21 @@
 }
 
 int
-cpu_ucode_amd_get_version(struct cpu_ucode_version *ucode)
+cpu_ucode_amd_get_version(struct cpu_ucode_version *ucode, void *ptr,
+    size_t len)
 {
-       struct cpu_ucode_version_amd data;
-
-       if (ucode->loader_version != CPU_UCODE_LOADER_AMD || amd_cpufamily() < 0x10)
-               return EOPNOTSUPP;
-       if (!ucode->data)
-               return 0;
+       struct cpu_ucode_version_amd *data = ptr;
 
-       data.version = rdmsr(MSR_UCODE_AMD_PATCHLEVEL);
-       return copyout(&data, ucode->data, sizeof(data));
-}
-
-#ifdef COMPAT_60
-int
-compat6_cpu_ucode_amd_get_version(struct compat6_cpu_ucode *ucode)
-{
-       uint64_t uclevel;
-
-       if (amd_cpufamily() < 0x10)
+       if (ucode->loader_version != CPU_UCODE_LOADER_AMD
+           || amd_cpufamily() < 0x10)
                return EOPNOTSUPP;
 
-       uclevel = rdmsr(MSR_UCODE_AMD_PATCHLEVEL);
-       ucode->version = uclevel;
+       if (len < sizeof(*data))
+               return ENOSPC;
+
+       data->version = rdmsr(MSR_UCODE_AMD_PATCHLEVEL);
        return 0;
 }
-#endif /* COMPAT60 */
 
 int
 cpu_ucode_amd_firmware_open(firmware_handle_t *fwh, const char *fwname)
diff -r 006cd9a45ba8 -r 42cf6ba90a54 sys/arch/x86/x86/cpu_ucode_intel.c
--- a/sys/arch/x86/x86/cpu_ucode_intel.c        Sat Mar 17 06:50:55 2018 +0000
+++ b/sys/arch/x86/x86/cpu_ucode_intel.c        Sat Mar 17 21:37:52 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode_intel.c,v 1.12 2017/06/01 02:45:08 chs Exp $ */
+/* $NetBSD: cpu_ucode_intel.c,v 1.12.8.1 2018/03/17 21:37:52 pgoyette Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,11 +29,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.12 2017/06/01 02:45:08 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.12.8.1 2018/03/17 21:37:52 pgoyette Exp $");
 
 #include "opt_xen.h"
 #include "opt_cpu_ucode.h"
-#include "opt_compat_netbsd.h"
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -65,20 +64,21 @@
 }
 
 int
-cpu_ucode_intel_get_version(struct cpu_ucode_version *ucode)
+cpu_ucode_intel_get_version(struct cpu_ucode_version *ucode,
+    void *ptr, size_t len)
 {
        struct cpu_info *ci = curcpu();
-       struct cpu_ucode_version_intel1 data;
+       struct cpu_ucode_version_intel1 *data = ptr;
 
        if (ucode->loader_version != CPU_UCODE_LOADER_INTEL1 ||
            CPUID_TO_FAMILY(ci->ci_signature) < 6)
                return EOPNOTSUPP;



Home | Main Index | Thread Index | Old Index