This patch is to backport the patch below from linux kernel. commit 30ec26da9967d0d785abc24073129a34c3211777 Author: Ashok Raj <ashok....@intel.com> Date: Wed Feb 28 11:28:43 2018 +0100
x86/microcode: Do not upload microcode if CPUs are offline Avoid loading microcode if any of the CPUs are offline, and issue a warning. Having different microcode revisions on the system at any time is outright dangerous. [ Borislav: Massage changelog. ] Signed-off-by: Ashok Raj <ashok....@intel.com> Signed-off-by: Borislav Petkov <b...@suse.de> Signed-off-by: Thomas Gleixner <t...@linutronix.de> Tested-by: Tom Lendacky <thomas.lenda...@amd.com> Tested-by: Ashok Raj <ashok....@intel.com> Reviewed-by: Tom Lendacky <thomas.lenda...@amd.com> Cc: Arjan Van De Ven <arjan.van.de....@intel.com> Link: http://lkml.kernel.org/r/1519352533-15992-4-git-send-email-ashok....@intel.com Link: https://lkml.kernel.org/r/20180228102846.13447-5...@alien8.de Signed-off-by: Chao Gao <chao....@intel.com> Cc: Kevin Tian <kevin.t...@intel.com> Cc: Jun Nakajima <jun.nakaj...@intel.com> Cc: Ashok Raj <ashok....@intel.com> Cc: Borislav Petkov <b...@suse.de> Cc: Thomas Gleixner <t...@linutronix.de> --- xen/arch/x86/microcode.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c index 94c1ca2..25d9112 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -346,16 +346,27 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len) if ( microcode_ops == NULL ) return -EINVAL; + /* cpu_online_map must not change. */ + if ( !get_cpu_maps() ) + return -EBUSY; + + if ( num_present_cpus() != num_online_cpus() ) + { + ret = -EINVAL; + printk("Not all CPUs online, aborting microcode update\n"); + goto put; + } + info = xmalloc_bytes(sizeof(*info) + len); if ( info == NULL ) - return -ENOMEM; + { + ret = -ENOMEM; + goto put; + } ret = copy_from_guest(info->buffer, buf, len); if ( ret != 0 ) - { - xfree(info); - return ret; - } + goto err; info->buffer_size = len; info->error = 0; @@ -364,10 +375,7 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len) { ret = microcode_ops->start_update(); if ( ret != 0 ) - { - xfree(info); - return ret; - } + goto err; } atomic_set(&info->cpu_in, 0); @@ -393,7 +401,11 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len) watchdog_enable(); ret = info->error; + + err: xfree(info); + put: + put_cpu_maps(); return ret; } -- 1.8.3.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel