Skip to content

Commit a4160c0

Browse files
ciq-sahlbergbmastbergen
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> Signed-off-by: Shreeya Patel <spatel@ciq.com> Signed-off-by: Jonathan Maple <jmaple@ciq.com> Signed-off-by: Roxana Nicolescu <rnicolescu@ciq.com> Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>
1 parent a0465a0 commit a4160c0

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

@@ -1485,15 +1500,6 @@ static void __init cpu_parse_early_param(void)
14851500
*/
14861501
static void __init early_identify_cpu(struct cpuinfo_x86 *c)
14871502
{
1488-
#ifdef CONFIG_X86_64
1489-
c->x86_clflush_size = 64;
1490-
c->x86_phys_bits = 36;
1491-
c->x86_virt_bits = 48;
1492-
#else
1493-
c->x86_clflush_size = 32;
1494-
c->x86_phys_bits = 32;
1495-
c->x86_virt_bits = 32;
1496-
#endif
14971503
c->x86_cache_alignment = c->x86_clflush_size;
14981504

14991505
memset(&c->x86_capability, 0, sizeof(c->x86_capability));
@@ -1505,7 +1511,6 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
15051511
get_cpu_vendor(c);
15061512
get_cpu_cap(c);
15071513
get_model_name(c); /* RHEL8: get model name for unsupported check */
1508-
get_cpu_address_sizes(c);
15091514
setup_force_cpu_cap(X86_FEATURE_CPUID);
15101515
cpu_parse_early_param();
15111516

@@ -1522,6 +1527,8 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
15221527
setup_clear_cpu_cap(X86_FEATURE_CPUID);
15231528
}
15241529

1530+
get_cpu_address_sizes(c);
1531+
15251532
setup_force_cpu_cap(X86_FEATURE_ALWAYS);
15261533

15271534
cpu_set_bug_bits(c);

0 commit comments

Comments
 (0)