x86/cpu: Prevent cpuinfo_x86::x86_phys_bits adjustment corruption

Some features (Intel MKTME, AMD SME) reduce the number of effectively
available physical address bits. cpuinfo_x86::x86_phys_bits is adjusted
accordingly during the early cpu feature detection.

Though if get_cpu_cap() is called later again then this adjustement is
overwritten. That happens in setup_pku(), which is called after
detect_tme().

To address this, extract the address sizes enumeration into a separate
function, which is only called only from early_identify_cpu() and from
generic_identify().

This makes get_cpu_cap() safe to be called later during boot proccess
without overwriting cpuinfo_x86::x86_phys_bits.

[ tglx: Massaged changelog ]

Fixes: cb06d8e3d020 ("x86/tme: Detect if TME and MKTME is activated by BIOS")
Reported-by: Kai Huang <kai.huang@linux.intel.com>
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: linux-mm@kvack.org
Cc: "H. Peter Anvin" <hpa@zytor.com>
Link: https://lkml.kernel.org/r/20180410092704.41106-1-kirill.shutemov@linux.intel.com

authored by Kirill A. Shutemov and committed by Thomas Gleixner d94a155c 92e830f2

+20 -12
+20 -12
arch/x86/kernel/cpu/common.c
··· 848 848 c->x86_power = edx; 849 849 } 850 850 851 - if (c->extended_cpuid_level >= 0x80000008) { 852 - cpuid(0x80000008, &eax, &ebx, &ecx, &edx); 853 - 854 - c->x86_virt_bits = (eax >> 8) & 0xff; 855 - c->x86_phys_bits = eax & 0xff; 856 - c->x86_capability[CPUID_8000_0008_EBX] = ebx; 857 - } 858 - #ifdef CONFIG_X86_32 859 - else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36)) 860 - c->x86_phys_bits = 36; 861 - #endif 862 - 863 851 if (c->extended_cpuid_level >= 0x8000000a) 864 852 c->x86_capability[CPUID_8000_000A_EDX] = cpuid_edx(0x8000000a); 865 853 ··· 860 872 * several times during CPU initialization. 861 873 */ 862 874 apply_forced_caps(c); 875 + } 876 + 877 + static void get_cpu_address_sizes(struct cpuinfo_x86 *c) 878 + { 879 + u32 eax, ebx, ecx, edx; 880 + 881 + if (c->extended_cpuid_level >= 0x80000008) { 882 + cpuid(0x80000008, &eax, &ebx, &ecx, &edx); 883 + 884 + c->x86_virt_bits = (eax >> 8) & 0xff; 885 + c->x86_phys_bits = eax & 0xff; 886 + c->x86_capability[CPUID_8000_0008_EBX] = ebx; 887 + } 888 + #ifdef CONFIG_X86_32 889 + else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36)) 890 + c->x86_phys_bits = 36; 891 + #endif 863 892 } 864 893 865 894 static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c) ··· 970 965 cpu_detect(c); 971 966 get_cpu_vendor(c); 972 967 get_cpu_cap(c); 968 + get_cpu_address_sizes(c); 973 969 setup_force_cpu_cap(X86_FEATURE_CPUID); 974 970 975 971 if (this_cpu->c_early_init) ··· 1102 1096 get_cpu_vendor(c); 1103 1097 1104 1098 get_cpu_cap(c); 1099 + 1100 + get_cpu_address_sizes(c); 1105 1101 1106 1102 if (c->cpuid_level >= 0x00000001) { 1107 1103 c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF;