Skip to content

Commit 94e2012

Browse files
ciq-sahlbergPlaidCat
authored andcommitted
x86/sev-es: Set x86_virt_bits to the correct value straight away, instead of a two-phase approach
jira roc-2673 commit fbf6449 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 <dave.hansen@linux.intel.com> Signed-off-by: Adam Dunlap <acdunlap@google.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Tested-by: Jacob Xu <jacobhxu@google.com> Link: https://lore.kernel.org/r/20230912002703.3924521-3-acdunlap@google.com Signed-off-by: Ronnie Sahlberg <rsahlberg@ciq.com> Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 2e416d1 commit 94e2012

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

arch/x86/kernel/cpu/common.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,17 +1020,32 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
10201020
static void get_cpu_address_sizes(struct cpuinfo_x86 *c)
10211021
{
10221022
u32 eax, ebx, ecx, edx;
1023+
bool vp_bits_from_cpuid = true;
10231024

1024-
if (c->extended_cpuid_level >= 0x80000008) {
1025+
if (!cpu_has(c, X86_FEATURE_CPUID) ||
1026+
(c->extended_cpuid_level < 0x80000008))
1027+
vp_bits_from_cpuid = false;
1028+
1029+
if (vp_bits_from_cpuid) {
10251030
cpuid(0x80000008, &eax, &ebx, &ecx, &edx);
10261031

10271032
c->x86_virt_bits = (eax >> 8) & 0xff;
10281033
c->x86_phys_bits = eax & 0xff;
1034+
} else {
1035+
if (IS_ENABLED(CONFIG_X86_64)) {
1036+
c->x86_clflush_size = 64;
1037+
c->x86_phys_bits = 36;
1038+
c->x86_virt_bits = 48;
1039+
} else {
1040+
c->x86_clflush_size = 32;
1041+
c->x86_virt_bits = 32;
1042+
c->x86_phys_bits = 32;
1043+
1044+
if (cpu_has(c, X86_FEATURE_PAE) ||
1045+
cpu_has(c, X86_FEATURE_PSE36))
1046+
c->x86_phys_bits = 36;
1047+
}
10291048
}
1030-
#ifdef CONFIG_X86_32
1031-
else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36))
1032-
c->x86_phys_bits = 36;
1033-
#endif
10341049
c->x86_cache_bits = c->x86_phys_bits;
10351050
}
10361051

@@ -1468,15 +1483,6 @@ static void __init cpu_parse_early_param(void)
14681483
*/
14691484
static void __init early_identify_cpu(struct cpuinfo_x86 *c)
14701485
{
1471-
#ifdef CONFIG_X86_64
1472-
c->x86_clflush_size = 64;
1473-
c->x86_phys_bits = 36;
1474-
c->x86_virt_bits = 48;
1475-
#else
1476-
c->x86_clflush_size = 32;
1477-
c->x86_phys_bits = 32;
1478-
c->x86_virt_bits = 32;
1479-
#endif
14801486
c->x86_cache_alignment = c->x86_clflush_size;
14811487

14821488
memset(&c->x86_capability, 0, sizeof(c->x86_capability));
@@ -1488,7 +1494,6 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
14881494
get_cpu_vendor(c);
14891495
get_cpu_cap(c);
14901496
get_model_name(c); /* RHEL8: get model name for unsupported check */
1491-
get_cpu_address_sizes(c);
14921497
setup_force_cpu_cap(X86_FEATURE_CPUID);
14931498
cpu_parse_early_param();
14941499

@@ -1505,6 +1510,8 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
15051510
setup_clear_cpu_cap(X86_FEATURE_CPUID);
15061511
}
15071512

1513+
get_cpu_address_sizes(c);
1514+
15081515
setup_force_cpu_cap(X86_FEATURE_ALWAYS);
15091516

15101517
cpu_set_bug_bits(c);

0 commit comments

Comments
 (0)