x86/microcode: split out apply_microcode() from cpu_request_microcode()
authorChao Gao <chao.gao@intel.com>
Fri, 27 Sep 2019 12:11:35 +0000 (14:11 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 27 Sep 2019 12:11:35 +0000 (14:11 +0200)
commit220f89505e77d716c412c8a7f8b20b3684b00160
tree53f5428ff8328b8015fce3397deffdedd30c7951
parenteb8ce7d5ca38565953faebb728179eebb00012bf
x86/microcode: split out apply_microcode() from cpu_request_microcode()

During late microcode loading, apply_microcode() is invoked in
cpu_request_microcode(). To make late microcode update more reliable,
we want to put the apply_microcode() into stop_machine context. So
we split out it from cpu_request_microcode(). In general, for both
early loading on BSP and late loading, cpu_request_microcode() is
called first to get the matching microcode update contained by
the blob and then apply_microcode() is invoked explicitly on each
cpu in common code.

Given that all CPUs are supposed to have the same signature, parsing
microcode only needs to be done once. So cpu_request_microcode() is
also moved out of microcode_update_cpu().

In some cases (e.g. a broken bios), the system may have multiple
revisions of microcode update. So we would try to load a microcode
update as long as it covers current cpu. And if a cpu loads this patch
successfully, the patch would be stored into the patch cache.

Note that calling ->apply_microcode() itself doesn't require any
lock being held. But the parameter passed to it may be protected
by some locks. E.g. microcode_update_cpu() acquires microcode_mutex
to avoid microcode_cache being updated by others.

Signed-off-by: Chao Gao <chao.gao@intel.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/microcode.c
xen/arch/x86/microcode_amd.c
xen/arch/x86/microcode_intel.c
xen/include/asm-x86/microcode.h