Xen Microcode update driver for 2.6.38
Subsystems (3)
cover Xen Microcode update driver for 2.6.38
From: Jeremy Fitzhardinge <[email protected]>
Hi all,
This series adds a new microcode driver for Xen. The Xen hypervisor can deal with all the low-level details of doing a microcode update (Intel vs AMD, doing all the physical CPUs present on the system, current and future, etc), so all the driver has to do is make a hypercall to upload the microcode into Xen.
This only works on a privileged domain, of course. But the Xen driver also detects any time we're running paravirtualized under Xen to prevent any attempts at a microcode update from a non-privileged domain as well.
Thanks,
J
Jeremy Fitzhardinge (2):
xen: add CPU microcode update driver
xen/microcode: partially enable even for non-privileged kernels
Stephen Tweedie (1):
xen dom0: Add support for the platform_ops hypercall
arch/x86/include/asm/microcode.h | 9 ++ arch/x86/include/asm/xen/hypercall.h | 8 ++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/microcode_core.c | 5 +- arch/x86/kernel/microcode_xen.c | 201 ++++++++++++++++++++++++++++++ arch/x86/xen/Kconfig | 8 ++ include/xen/interface/platform.h | 222 ++++++++++++++++++++++++++++++++++ include/xen/interface/xen.h | 2 + 8 files changed, 455 insertions(+), 1 deletions(-) create mode 100644 arch/x86/kernel/microcode_xen.c create mode 100644 include/xen/interface/platform.h
Signature · 1 line
1.7.2.3
PATCH 1/3 xen dom0: Add support for the platform_ops hypercall
From: Stephen Tweedie <[email protected]>
Minimal changes to get platform ops (renamed dom0_ops on pv_ops) working on pv_ops builds. Pulls in upstream linux-2.6.18-xen.hg's platform.h
[ Impact: add Xen hypercall definitions ]
--- arch/x86/include/asm/xen/hypercall.h | 8 ++ include/xen/interface/platform.h | 222 ++++++++++++++++++++++++++++++++++ include/xen/interface/xen.h | 2 + 3 files changed, 232 insertions(+), 0 deletions(-) create mode 100644 include/xen/interface/platform.h
arch/x86/include/asm/xen/hypercall.h +8 -0
@@ -45,6 +45,7 @@#include <xen/interface/xen.h> #include <xen/interface/sched.h> #include <xen/interface/physdev.h> +#include <xen/interface/platform.h> /* * The hypercall asms have to meet several constraints:
@@ -299,6 +300,13 @@ HYPERVISOR_set_timer_op(u64 timeout) }static inline int +HYPERVISOR_dom0_op (struct xen_platform_op *platform_op) +{ + platform_op->interface_version =XENPF_INTERFACE_VERSION ; +return _hypercall1 (int, dom0_op, platform_op); +} + +static inline int HYPERVISOR_set_debugreg (int reg,unsigned long value) {return _hypercall2 (int, set_debugreg, reg, value);
include/xen/interface/platform.h new file +222 -0
222 lines not on this page · raw message
include/xen/interface/xen.h +2 -0
@@ -461,6 +461,8 @@ typedef uint8_t xen_domain_handle_t[16];#define __mk_unsigned_long (x) x ## UL#define mk_unsigned_long (x) __mk_unsigned_long(x) +DEFINE_GUEST_HANDLE (uint64_t); +#else /* __ASSEMBLY__ */ /* In assembly code we cannot use C numeric constant suffixes. */
Signature · 1 line
1.7.2.3
PATCH 2/3 xen: add CPU microcode update driver
In reply to Jeremy FitzhardingeFrom: Jeremy Fitzhardinge <[email protected]>
Xen does all the hard work for us, including choosing the right update method for this cpu type and actually doing it for all cpus. We just need to supply it with the firmware blob.
Because Xen updates all CPUs (and the kernel's virtual cpu numbers have no fixed relationship with the underlying physical cpus), we only bother doing anything for cpu "0".
--- arch/x86/include/asm/microcode.h | 9 ++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/microcode_core.c | 5 +- arch/x86/kernel/microcode_xen.c | 201 ++++++++++++++++++++++++++++++++++++++ arch/x86/xen/Kconfig | 4 + 5 files changed, 219 insertions(+), 1 deletions(-) create mode 100644 arch/x86/kernel/microcode_xen.c
arch/x86/include/asm/microcode.h +9 -0
@@ -55,4 +55,13 @@ static inline struct microcode_ops * __init init_amd_microcode(void) }#endif +#ifdef CONFIG_MICROCODE_XEN +extern struct microcode_ops *__init init_xen_microcode (void ); +#else +static inline struct microcode_ops *__init init_xen_microcode (void ) +{ +return NULL ; +} +#endif +#endif /* _ASM_X86_MICROCODE_H */
arch/x86/kernel/Makefile +1 -0
@@ -104,6 +104,7 @@ obj-$(CONFIG_PCSPKR_PLATFORM) += pcspeaker.o microcode-y := microcode_core.o microcode-$(CONFIG_MICROCODE_INTEL) += microcode_intel.o microcode-$(CONFIG_MICROCODE_AMD) += microcode_amd.o +microcode-$(CONFIG_MICROCODE_XEN) += microcode_xen.o obj-$(CONFIG_MICROCODE) += microcode.o obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
arch/x86/kernel/microcode_core.c +4 -1
@@ -83,6 +83,7 @@#include <linux/fs.h> #include <linux/mm.h> +#include <xen/xen.h> #include <asm/microcode.h> #include <asm/processor.h>
@@ -506,7 +507,9 @@ static int __init microcode_init(void)struct cpuinfo_x86 *c = &cpu_data (0 );int error; -if (c->x86_vendor ==X86_VENDOR_INTEL ) +if (xen_pv_domain ()) + microcode_ops =init_xen_microcode (); +else if (c->x86_vendor ==X86_VENDOR_INTEL ) microcode_ops =init_intel_microcode ();else if (c->x86_vendor ==X86_VENDOR_AMD ) microcode_ops =init_amd_microcode ();
arch/x86/kernel/microcode_xen.c new file +201 -0
201 lines not on this page · raw message
arch/x86/xen/Kconfig +4 -0
@@ -48,3 +48,7 @@ config XEN_DEBUG_FS help Enable statistics output and various tuning options in debugfs. Enabling this option may incur a significant performance overhead. + +config MICROCODE_XEN + def_bool y + depends on XEN_DOM0 && MICROCODE
Signature · 1 line
1.7.2.3
PATCH 3/3 xen/microcode: partially enable even for non-privileged kernels
In reply to Jeremy FitzhardingeFrom: Jeremy Fitzhardinge <[email protected]>
Don't attempt to load microcode on non-privileged kernels. Kernels compiled without privileged support just get vestigial Xen detection to skip loading altogether; kernels with privileged support will load microcode if running privileged. In either case, the normal Intel/AMD microcode loader is skipped under Xen.
--- arch/x86/include/asm/microcode.h | 2 +- arch/x86/kernel/Makefile | 2 +- arch/x86/xen/Kconfig | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-)
arch/x86/include/asm/microcode.h +1 -1
@@ -55,7 +55,7 @@ static inline struct microcode_ops * __init init_amd_microcode(void) }#endif -#ifdef CONFIG_MICROCODE_XEN +#ifdef CONFIG_MICROCODE_XEN_LOADER extern struct microcode_ops *__init init_xen_microcode (void );#else static inline struct microcode_ops *__init init_xen_microcode (void )
arch/x86/kernel/Makefile +1 -1
@@ -104,7 +104,7 @@ obj-$(CONFIG_PCSPKR_PLATFORM) += pcspeaker.o microcode-y := microcode_core.o microcode-$(CONFIG_MICROCODE_INTEL) += microcode_intel.o microcode-$(CONFIG_MICROCODE_AMD) += microcode_amd.o -microcode-$(CONFIG_MICROCODE_XEN) += microcode_xen.o +microcode-$(CONFIG_MICROCODE_XEN_LOADER) += microcode_xen.o obj-$(CONFIG_MICROCODE) += microcode.o obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
arch/x86/xen/Kconfig +5 -1
@@ -51,4 +51,8 @@ config XEN_DEBUG_FS config MICROCODE_XEN def_bool y - depends on XEN_DOM0 && MICROCODE + depends on XEN && MICROCODE + +config MICROCODE_XEN_LOADER + def_bool y + depends on MICROCODE_XEN && DOM0
Signature · 1 line
1.7.2.3
Re: [PATCH 1/3] xen dom0: Add support for the platform_ops hypercall
In reply to Jeremy Fitzhardingeinclude/xen/interface/platform.h line 46
Quoted 2 lines
include/xen/interface/platform.h new file +2
-0+typedef struct xenpf_settime xenpf_settime_t ; +DEFINE_GUEST_HANDLE_STRUCT (xenpf_settime_t);
We aren't using this..
include/xen/interface/platform.h line 66
Quoted 2 lines
include/xen/interface/platform.h new file +2
-0+typedef struct xenpf_add_memtype xenpf_add_memtype_t ; +DEFINE_GUEST_HANDLE_STRUCT (xenpf_add_memtype_t);
.. nor this..
include/xen/interface/platform.h line 82
Quoted 2 lines
include/xen/interface/platform.h new file +2
-0+typedef struct xenpf_del_memtype xenpf_del_memtype_t ; +DEFINE_GUEST_HANDLE_STRUCT (xenpf_del_memtype_t);
.. neither this one.
include/xen/interface/platform.h line 95
Quoted 2 lines
include/xen/interface/platform.h new file +2
-0+typedef struct xenpf_read_memtype xenpf_read_memtype_t ; +DEFINE_GUEST_HANDLE_STRUCT (xenpf_read_memtype_t);
..whoa, didn't know we had that many.
include/xen/interface/platform.h line 104
Quoted 9 lines
include/xen/interface/platform.h new file +9
-0+ +#define XENPF_microcode_update 35 +struct xenpf_microcode_update { +/* IN variables. */ +GUEST_HANDLE (void ) data;/* Pointer to microcode data */ +uint32_t length;/* Length of microcode data. */ +}; +typedef struct xenpf_microcode_update xenpf_microcode_update_t ; +DEFINE_GUEST_HANDLE_STRUCT (xenpf_microcode_update_t);
OK, we are using this one.
.. snip ..
Why not just introduce the one we are using (just one right now) and on subsequent patches that enable the functionality add it in this file?
Re: [PATCH 2/3] xen: add CPU microcode update driver
In reply to Jeremy FitzhardingeQuoted 20 lines
arch/x86/kernel/microcode_xen.c new file +20
-0+static enum ucode_state xen_request_microcode_user (int cpu, +const void __user *buf,size_t size) +{ +struct ucode_cpu_info *uci = ucode_cpu_info + cpu; +struct xen_microcode *uc; +enum ucode_state ret; +size_t unread; + +if (cpu !=0 ) { +/* No real firmware for non-zero cpus; just store a +placeholder */ + size =0 ; + } + +if (uci->mc !=NULL ) { +vfree (uci->mc); + uci->mc =NULL ; + } + + ret =UCODE_ERROR ;
arch/x86/kernel/microcode_xen.c line 150
Quoted 10 lines
arch/x86/kernel/microcode_xen.c new file +10
-0+ uc =vmalloc (sizeof (*uc) + size); +if (uc ==NULL ) + goto out; + + uc->len = size; + + ret =UCODE_NFOUND ; + +/* XXX This sporadically returns uncopied bytes, so we return +EFAULT. As far as I can see, the usermode code
^^^^^ UCODE_NFOUND.
arch/x86/kernel/microcode_xen.c line 151
Quoted 1 line
arch/x86/kernel/microcode_xen.c new file +1
-0+(microcode_ctl) isn't doing anything wrong... */
Is this still valid? Looking at AMD it checks for a magic key and the Intel just copies without checks.
Re: [PATCH 3/3] xen/microcode: partially enable even for non-privileged kernels
In reply to Jeremy FitzhardingeQuoted 3 lines · Jeremy Fitzhardinge
From: Jeremy Fitzhardinge <[email protected]>
Don't attempt to load microcode on non-privileged kernels. Kernels
The previous patch had this:
if (!xen_initial_domain())
+ return NULL;
which pretty much made non-priviliged kernels not do any micro code loading.
It sounds like this patch is just to not compile the Xen microcode code if CONFIG_DOM0 is not enabled?
Quoted 4 lines
compiled without privileged support just get vestigial Xen detection to skip loading altogether; kernels with privileged support will load microcode if running privileged. In either case, the normal Intel/AMD microcode loader is skipped under Xen.
Re: [Xen-devel] Re: [PATCH 1/3] xen dom0: Add support for the platform_ops hypercall
In reply to Konrad Rzeszutek WilkQuoted 23 lines · Konrad Rzeszutek Wilk
include/xen/interface/platform.h line 46
Quoted 2 lines
include/xen/interface/platform.h new file +2
-0+typedef struct xenpf_settime xenpf_settime_t ; +DEFINE_GUEST_HANDLE_STRUCT (xenpf_settime_t);We aren't using this..
include/xen/interface/platform.h line 66
Quoted 2 lines
include/xen/interface/platform.h new file +2
-0+typedef struct xenpf_add_memtype xenpf_add_memtype_t ; +DEFINE_GUEST_HANDLE_STRUCT (xenpf_add_memtype_t);.. nor this..
include/xen/interface/platform.h line 82
Quoted 2 lines
include/xen/interface/platform.h new file +2
-0+typedef struct xenpf_del_memtype xenpf_del_memtype_t ; +DEFINE_GUEST_HANDLE_STRUCT (xenpf_del_memtype_t);.. neither this one.
include/xen/interface/platform.h line 95
Quoted 2 lines
include/xen/interface/platform.h new file +2
-0+typedef struct xenpf_read_memtype xenpf_read_memtype_t ; +DEFINE_GUEST_HANDLE_STRUCT (xenpf_read_memtype_t);..whoa, didn't know we had that many.
include/xen/interface/platform.h line 104
Quoted 9 lines
include/xen/interface/platform.h new file +9
-0+ +#define XENPF_microcode_update 35 +struct xenpf_microcode_update { +/* IN variables. */ +GUEST_HANDLE (void ) data;/* Pointer to microcode data */ +uint32_t length;/* Length of microcode data. */ +}; +typedef struct xenpf_microcode_update xenpf_microcode_update_t ; +DEFINE_GUEST_HANDLE_STRUCT (xenpf_microcode_update_t);OK, we are using this one.
Quoted 4 lines
.. snip ..
Why not just introduce the one we are using (just one right now) and on subsequent patches that enable the functionality add it in this file?
The main reason is that if some other branch also brings in platform.h then its easier to merge two copies of the same file rather than two subsets.
J
Re: [Xen-devel] Re: [PATCH 2/3] xen: add CPU microcode update driver
In reply to Konrad Rzeszutek WilkQuoted 31 lines · Konrad Rzeszutek Wilk
Quoted 20 lines
arch/x86/kernel/microcode_xen.c new file +20
-0+static enum ucode_state xen_request_microcode_user (int cpu, +const void __user *buf,size_t size) +{ +struct ucode_cpu_info *uci = ucode_cpu_info + cpu; +struct xen_microcode *uc; +enum ucode_state ret; +size_t unread; + +if (cpu !=0 ) { +/* No real firmware for non-zero cpus; just store a +placeholder */ + size =0 ; + } + +if (uci->mc !=NULL ) { +vfree (uci->mc); + uci->mc =NULL ; + } + + ret =UCODE_ERROR ;arch/x86/kernel/microcode_xen.c line 150
Quoted 10 lines
arch/x86/kernel/microcode_xen.c new file +10
-0+ uc =vmalloc (sizeof (*uc) + size); +if (uc ==NULL ) + goto out; + + uc->len = size; + + ret =UCODE_NFOUND ; + +/* XXX This sporadically returns uncopied bytes, so we return +EFAULT. As far as I can see, the usermode code ^^^^^ UCODE_NFOUND.
Quoted 3 lines
arch/x86/kernel/microcode_xen.c line 151
Quoted 1 line
arch/x86/kernel/microcode_xen.c new file +1
-0+(microcode_ctl) isn't doing anything wrong... */ Is this still valid? Looking at AMD it checks for a magic key and the Intel just copies without checks.
Probably not.
J
Re: [Xen-devel] Re: [PATCH 3/3] xen/microcode: partially enable even for non-privileged kernels
In reply to Konrad Rzeszutek WilkQuoted 6 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Jeremy Fitzhardinge
From: Jeremy Fitzhardinge <[email protected]>
Don't attempt to load microcode on non-privileged kernels. Kernels
The previous patch had this:
Quoted 7 lines
if (!xen_initial_domain())
+ return NULL;which pretty much made non-priviliged kernels not do any micro code loading.
It sounds like this patch is just to not compile the Xen microcode code if
CONFIG_DOM0is not enabled?
Yeah, I think the patch is a brainfart, and the existing code already did the right thing.
J
Re: [Xen-devel] Re: [PATCH 1/3] xen dom0: Add support for the platform_ops hypercall
In reply to Jeremy FitzhardingeQuoted 6 lines
Quoted 2 lines
Why not just introduce the one we are using (just one right now) and on subsequent patches that enable the functionality add it in this file?
The main reason is that if some other branch also brings in
platform.hthen its easier to merge two copies of the same file rather than two subsets.
Sure, but in linux-next that is just one touch patch and Stephen said he is Ok with those.
I like doing it (just stick in those that we use), b/c that way you have an excellent view of when this feature went in the code and the relevant git commits to blame.