Skip to content

Commit fbf6449

Browse files
AdamCDunlapIngo Molnar
authored and
Ingo Molnar
committed
x86/sev-es: Set x86_virt_bits to the correct value straight away, instead of a two-phase approach
Instead of setting x86_virt_bits to a possibly-correct value and then correcting it later, do all the necessary checks before setting it. At this point, the #VC handler references boot_cpu_data.x86_virt_bits, and in the previous version, it would be triggered by the CPUIDs between the point at which it is set to 48 and when it is set to the correct value. Suggested-by: Dave Hansen <[email protected]> Signed-off-by: Adam Dunlap <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Tested-by: Jacob Xu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f799365 commit fbf6449

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

arch/x86/kernel/cpu/common.c

+22-15
Original file line numberDiff line numberDiff line change
@@ -1114,17 +1114,32 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
11141114
void get_cpu_address_sizes(struct cpuinfo_x86 *c)
11151115
{
11161116
u32 eax, ebx, ecx, edx;
1117+
bool vp_bits_from_cpuid = true;
11171118

1118-
if (c->extended_cpuid_level >= 0x80000008) {
1119+
if (!cpu_has(c, X86_FEATURE_CPUID) ||
1120+
(c->extended_cpuid_level < 0x80000008))
1121+
vp_bits_from_cpuid = false;
1122+
1123+
if (vp_bits_from_cpuid) {
11191124
cpuid(0x80000008, &eax, &ebx, &ecx, &edx);
11201125

11211126
c->x86_virt_bits = (eax >> 8) & 0xff;
11221127
c->x86_phys_bits = eax & 0xff;
1128+
} else {
1129+
if (IS_ENABLED(CONFIG_X86_64)) {
1130+
c->x86_clflush_size = 64;
1131+
c->x86_phys_bits = 36;
1132+
c->x86_virt_bits = 48;
1133+
} else {
1134+
c->x86_clflush_size = 32;
1135+
c->x86_virt_bits = 32;
1136+
c->x86_phys_bits = 32;
1137+
1138+
if (cpu_has(c, X86_FEATURE_PAE) ||
1139+
cpu_has(c, X86_FEATURE_PSE36))
1140+
c->x86_phys_bits = 36;
1141+
}
11231142
}
1124-
#ifdef CONFIG_X86_32
1125-
else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36))
1126-
c->x86_phys_bits = 36;
1127-
#endif
11281143
c->x86_cache_bits = c->x86_phys_bits;
11291144
}
11301145

@@ -1579,15 +1594,6 @@ static void __init cpu_parse_early_param(void)
15791594
*/
15801595
static void __init early_identify_cpu(struct cpuinfo_x86 *c)
15811596
{
1582-
#ifdef CONFIG_X86_64
1583-
c->x86_clflush_size = 64;
1584-
c->x86_phys_bits = 36;
1585-
c->x86_virt_bits = 48;
1586-
#else
1587-
c->x86_clflush_size = 32;
1588-
c->x86_phys_bits = 32;
1589-
c->x86_virt_bits = 32;
1590-
#endif
15911597
c->x86_cache_alignment = c->x86_clflush_size;
15921598

15931599
memset(&c->x86_capability, 0, sizeof(c->x86_capability));
@@ -1601,7 +1607,6 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
16011607
cpu_detect(c);
16021608
get_cpu_vendor(c);
16031609
get_cpu_cap(c);
1604-
get_cpu_address_sizes(c);
16051610
setup_force_cpu_cap(X86_FEATURE_CPUID);
16061611
cpu_parse_early_param();
16071612

@@ -1617,6 +1622,8 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
16171622
setup_clear_cpu_cap(X86_FEATURE_CPUID);
16181623
}
16191624

1625+
get_cpu_address_sizes(c);
1626+
16201627
setup_force_cpu_cap(X86_FEATURE_ALWAYS);
16211628

16221629
cpu_set_bug_bits(c);

0 commit comments

Comments
 (0)