x86/microcode/intel: Extend BDW late-loading further with LLC size check

Commit b94b73733171 ("x86/microcode/intel: Extend BDW late-loading with a
revision check") reduced the impact of erratum BDF90 for Broadwell model
79.

The impact can be reduced further by checking the size of the last level
cache portion per core.

Tony: "The erratum says the problem only occurs on the large-cache SKUs.
So we only need to avoid the update if we are on a big cache SKU that is
also running old microcode."

For more details, see erratum BDF90 in document #334165 (Intel Xeon
Processor E7-8800/4800 v4 Product Family Specification Update) from
September 2017.

Fixes: b94b73733171 ("x86/microcode/intel: Extend BDW late-loading with a revision check")
Signed-off-by: Jia Zhang <zhang.jia@linux.alibaba.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Tony Luck <tony.luck@intel.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1516321542-31161-1-git-send-email-zhang.jia@linux.alibaba.com

authored by Jia Zhang and committed by Thomas Gleixner 7e702d17 40d4071c

Changed files
+18 -2
arch
x86
kernel
cpu
microcode
+18 -2
arch/x86/kernel/cpu/microcode/intel.c
··· 45 45 /* Current microcode patch used in early patching on the APs. */ 46 46 static struct microcode_intel *intel_ucode_patch; 47 47 48 + /* last level cache size per core */ 49 + static int llc_size_per_core; 50 + 48 51 static inline bool cpu_signatures_match(unsigned int s1, unsigned int p1, 49 52 unsigned int s2, unsigned int p2) 50 53 { ··· 915 912 916 913 /* 917 914 * Late loading on model 79 with microcode revision less than 0x0b000021 918 - * may result in a system hang. This behavior is documented in item 919 - * BDF90, #334165 (Intel Xeon Processor E7-8800/4800 v4 Product Family). 915 + * and LLC size per core bigger than 2.5MB may result in a system hang. 916 + * This behavior is documented in item BDF90, #334165 (Intel Xeon 917 + * Processor E7-8800/4800 v4 Product Family). 920 918 */ 921 919 if (c->x86 == 6 && 922 920 c->x86_model == INTEL_FAM6_BROADWELL_X && 923 921 c->x86_mask == 0x01 && 922 + llc_size_per_core > 2621440 && 924 923 c->microcode < 0x0b000021) { 925 924 pr_err_once("Erratum BDF90: late loading with revision < 0x0b000021 (0x%x) disabled.\n", c->microcode); 926 925 pr_err_once("Please consider either early loading through initrd/built-in or a potential BIOS update.\n"); ··· 980 975 .apply_microcode = apply_microcode_intel, 981 976 }; 982 977 978 + static int __init calc_llc_size_per_core(struct cpuinfo_x86 *c) 979 + { 980 + u64 llc_size = c->x86_cache_size * 1024; 981 + 982 + do_div(llc_size, c->x86_max_cores); 983 + 984 + return (int)llc_size; 985 + } 986 + 983 987 struct microcode_ops * __init init_intel_microcode(void) 984 988 { 985 989 struct cpuinfo_x86 *c = &boot_cpu_data; ··· 998 984 pr_err("Intel CPU family 0x%x not supported\n", c->x86); 999 985 return NULL; 1000 986 } 987 + 988 + llc_size_per_core = calc_llc_size_per_core(c); 1001 989 1002 990 return &microcode_intel_ops; 1003 991 }