microcode: introduce a global cache of ucode patch
authorChao Gao <chao.gao@intel.com>
Fri, 13 Sep 2019 10:27:42 +0000 (12:27 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 13 Sep 2019 10:27:42 +0000 (12:27 +0200)
commit9da23943ccd557ddb6c34e96e3bc078a51ad8205
treedea59e9926ee720e7dee1b3087082f35ff64ea9f
parent68f94ef8e57cea82680b7bda2e03caabcba6d0a6
microcode: introduce a global cache of ucode patch

to replace the current per-cpu cache 'uci->mc'.

With the assumption that all CPUs in the system have the same signature
(family, model, stepping and 'pf'), one microcode update matches with
one cpu should match with others. Having differing microcode revisions
on cpus would cause system unstable and should be avoided. Hence, caching
one microcode update is good enough for all cases.

Introduce a global variable, microcode_cache, to store the newest
matching microcode update. Whenever we get a new valid microcode update,
its revision id is compared against that of the microcode update to
determine whether the "microcode_cache" needs to be replaced. And
this global cache is loaded to cpu in apply_microcode().

All operations on the cache is protected by 'microcode_mutex'.

Note that I deliberately avoid touching the old per-cpu cache ('uci->mc')
as I am going to remove it completely in the following patches. We copy
everything to create the new cache blob to avoid reusing some buffers
previously allocated for the old per-cpu cache. It is not so efficient,
but it is already corrected by a patch later in this series.

Signed-off-by: Chao Gao <chao.gao@intel.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-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