Skip to contentSkip to conversation

x86: Move SMP #defines from apic-defs.h to smp.h

PATCH Applied Sean Christopherson 1 participant 2 messages Feb 21, 2025 – Feb 24, 2025 KVM

lore
Share & tools
lore

Sean Christopherson

author reviewer
#0 lore raw

PATCH 1/1 x86: Move SMP #defines from apic-defs.h to smp.h

Now that the __ASSEMBLY__ versus __ASSEMBLER_ mess is sorted out, move the SMP related #defines from apic-defs.h to smp.h, and drop the comment that explains the hackery.

Opportunistically make REALMODE_GDT_LOWMEM visible to assembly code as well, and drop efistart64.S's local copy.

---

This applies on top of two combined series:

https://lore.kernel.org/all/[email protected]
https://lore.kernel.org/all/[email protected]

 lib/x86/apic-defs.h  |  8 --------
 lib/x86/apic.h       |  2 ++
 lib/x86/smp.h        | 18 +++++++++++++++---
 x86/cstart.S         |  1 +
 x86/cstart64.S       |  1 +
 x86/efi/efistart64.S |  3 +--
 x86/trampolines.S    |  1 +
 7 files changed, 21 insertions(+), 13 deletions(-)
lib/x86/apic-defs.h +0 -8
index 5a1dff3a..fd82b815 100644
@@ -1,14 +1,6 @@
 #ifndef _X86_APIC_DEFS_H_
 #define _X86_APIC_DEFS_H_
 
-/*
- * Abuse this header file to hold the number of max-cpus and the size of the
- * per-CPU stack/data area, making them available both in C and ASM.  One page
- * for per-CPU, and two pages for the stack (plus some buffer in-between).
- */
-#define MAX_TEST_CPUS (255)
-#define PER_CPU_SIZE  (3 * 4096)
-
 /*
  * Constants for various Intel APICs. (local APIC, IOAPIC, etc.)
  *
lib/x86/apic.h +2 -0
index 8df889b2..23c771ed 100644
@@ -3,7 +3,9 @@
 
 #include <bitops.h>
 #include <stdint.h>
+
 #include "apic-defs.h"
+#include "smp.h"
 
 extern u8 id_map[MAX_TEST_CPUS];
 
lib/x86/smp.h +15 -3
index 08a440b3..bbe90daa 100644
@@ -1,15 +1,25 @@
 #ifndef _X86_SMP_H_
 #define _X86_SMP_H_
 
+#define MAX_TEST_CPUS (255)
+
+/*
+ * Allocate 12KiB of data for per-CPU usage.  One page for per-CPU data, and
+ * two pages for the stack (plus some buffer in-between).
+ */
+#define PER_CPU_SIZE  (3 * 4096)
+
+/* Address where to store the address of realmode GDT descriptor. */
+#define REALMODE_GDT_LOWMEM (PAGE_SIZE - 2)
+
+#ifndef __ASSEMBLER__
+
 #include <stddef.h>
 #include <asm/spinlock.h>
 #include "libcflat.h"
 #include "atomic.h"
 #include "apic-defs.h"
 
-/* Address where to store the address of realmode GDT descriptor. */
-#define REALMODE_GDT_LOWMEM (PAGE_SIZE - 2)
-
 /* Offsets into the per-cpu page. */
 struct percpu_data {
 	uint32_t  smp_id;
@@ -90,4 +100,6 @@ void ap_online(void);
 extern atomic_t cpu_online_count;
 extern unsigned char online_cpus[(MAX_TEST_CPUS + 7) / 8];
 
+#endif /* __ASSEMBLER__ */
+
 #endif
x86/cstart.S +1 -0
index 2e396e52..96e79a47 100644
@@ -1,5 +1,6 @@
 
 #include "apic-defs.h"
+#include "smp.h"
 
 .global online_cpus
 
x86/cstart64.S +1 -0
index 018bac98..f3c398a5 100644
@@ -1,5 +1,6 @@
 #include "apic-defs.h"
 #include "desc.h"
+#include "smp.h"
 
 ipi_vector = 0x20
 
x86/efi/efistart64.S +1 -2
index 3fc16016..6025dc2f 100644
@@ -3,7 +3,7 @@
 #include "apic-defs.h"
 #include "asm-generic/page.h"
 #include "crt0-efi-x86_64.S"
-
+#include "smp.h"
 
 /* Reserve stack in .data */
 .data
@@ -36,7 +36,6 @@ ptl4:
 .text
 
 .code16
-REALMODE_GDT_LOWMEM = PAGE_SIZE - 2
 
 .globl rm_trampoline
 rm_trampoline:
x86/trampolines.S +1 -0
index 02d9f321..c3f2bd29 100644
@@ -3,6 +3,7 @@
  * transition from 32-bit to 64-bit code (x86-64 only)
  */
 #include "apic-defs.h"
+#include "smp.h"
 
 per_cpu_size = PER_CPU_SIZE
 

base-commit: 42bbd80783ab0985dbd195358aa89de8a69cb0ab

Signature · 1 line
2.48.1.601.g30ceb7b040-goog
author reviewer Applied
#1 lore raw
Quoted 8 lines · Sean Christopherson

Now that the __ASSEMBLY__ versus __ASSEMBLER_ mess is sorted out, move the SMP related #defines from apic-defs.h to smp.h, and drop the comment that explains the hackery.

Opportunistically make REALMODE_GDT_LOWMEM visible to assembly code as well, and drop efistart64.S's local copy.

[...]

Applied to kvm-x86 next (and now pulled by Paolo), thanks!

[1/1] x86: Move SMP #defines from apic-defs.h to smp.h

      https://github.com/kvm-x86/kvm-unit-tests/commit/d467e659b2b1

--
https://github.com/kvm-x86/kvm-unit-tests/tree/next