[RFC][PATCH 17/34] x86/cpu: Move virtual address limit out of cpuinfo_x86

Dave Hansen
2024-02-22T18:39:49Z

There are no longer any direct references to
cpuinfo_x86->x86_virt_bits. The only remaining references are to
'boot_cpu_data' via the x86_virt_bits() helper.

This means the farce that x86_virt_bits is per-cpu data can end.
Remove it from cpuinfo_x86 and add it to 'x86_config'.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---

b/arch/x86/include/asm/processor.h | 6 +++---
b/arch/x86/kernel/cpu/common.c | 8 +++-----
b/arch/x86/mm/maccess.c | 9 +++++----
3 files changed, 11 insertions(+), 12 deletions(-)

diff -puN arch/x86/include/asm/processor.h~no-cpu-data-virt_bits arch/x86/include/asm/processor.h
--- a/arch/x86/include/asm/processor.h~no-cpu-data-virt_bits 2024-02-22 10:08:56.748778725 -0800
+++ b/arch/x86/include/asm/processor.h 2024-02-22 10:08:56.752778882 -0800
@@ -117,7 +117,6 @@ struct cpuinfo_x86 {
#ifdef CONFIG_X86_VMX_FEATURE_NAMES
__u32 vmx_capability[NVMXINTS];
#endif
- __u8 x86_virt_bits;
/* CPUID returned core id bits: */
__u8 x86_coreid_bits;
/* Max extended CPUID function supported: */
@@ -182,8 +181,9 @@ struct x86_addr_config {
* modified after that.
*/
struct x86_sys_config {
- /* Physical address bits supported by all processors */
+ /* Address bits supported by all processors */
u8 phys_bits;
+ u8 virt_bits;
};

extern struct x86_sys_config x86_config;
@@ -800,7 +800,7 @@ static inline u8 x86_phys_bits(void)

static inline u8 x86_virt_bits(void)
{
- return boot_cpu_data.x86_virt_bits;
+ return x86_config.virt_bits;
}

static inline u8 x86_clflush_size(void)
diff -puN arch/x86/kernel/cpu/common.c~no-cpu-data-virt_bits arch/x86/kernel/cpu/common.c
--- a/arch/x86/kernel/cpu/common.c~no-cpu-data-virt_bits 2024-02-22 10:08:56.748778725 -0800
+++ b/arch/x86/kernel/cpu/common.c 2024-02-22 10:08:56.752778882 -0800
@@ -1106,17 +1106,17 @@ void get_cpu_address_sizes(struct cpuinf
if (vp_bits_from_cpuid) {
cpuid(0x80000008, &eax, &ebx, &ecx, &edx);

- c->x86_virt_bits = (eax >> 8) & 0xff;
+ x86_config.virt_bits = (eax >> 8) & 0xff;
x86_config.phys_bits = eax & 0xff;
} else {
if (IS_ENABLED(CONFIG_X86_64)) {
x86_config.phys_bits = 36;
+ x86_config.virt_bits = 48;
c->x86_clflush_size = 64;
- c->x86_virt_bits = 48;
} else {
x86_config.phys_bits = 32;
+ x86_config.virt_bits = 32;
c->x86_clflush_size = 32;
- c->x86_virt_bits = 32;

if (cpu_has(c, X86_FEATURE_PAE) ||
cpu_has(c, X86_FEATURE_PSE36))
@@ -1827,11 +1827,9 @@ static void identify_cpu(struct cpuinfo_
c->topo.l2c_id = BAD_APICID;
#ifdef CONFIG_X86_64
c->x86_clflush_size = 64;
- c->x86_virt_bits = 48;
#else
c->cpuid_level = -1; /* CPUID not detected */
c->x86_clflush_size = 32;
- c->x86_virt_bits = 32;
#endif
c->x86_cache_alignment = x86_clflush_size();
memset(&c->x86_capability, 0, sizeof(c->x86_capability));
diff -puN arch/x86/mm/maccess.c~no-cpu-data-virt_bits arch/x86/mm/maccess.c
--- a/arch/x86/mm/maccess.c~no-cpu-data-virt_bits 2024-02-22 10:08:56.752778882 -0800
+++ b/arch/x86/mm/maccess.c 2024-02-22 10:08:56.752778882 -0800
@@ -16,11 +16,12 @@ bool copy_from_kernel_nofault_allowed(co
return false;

/*
- * Allow everything during early boot before 'x86_virt_bits'
- * is initialized. Needed for instruction decoding in early
- * exception handlers.
+ * Allow everything during early boot before 'virt_bits' is
+ * initialized. Needed for instruction decoding in early
+ * exception handlers. Avoid the helper because it may do
+ * error checking for being uninitiazed.
*/
- if (!x86_virt_bits())
+ if (!x86_config.virt_bits)
return true;

return __is_canonical_address(vaddr, x86_virt_bits());
_