Skip to contentSkip to conversation

x86/trampoline: Change type of trampoline_phys to uint32_t

PATCH In review Andrew Cooper 2 participants 2 messages Nov 11, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/trampoline: Change type of trampoline_phys to uint32_t

As now documented, this variable holds a page aligned value less than 1M.

However, head.S fills it using 4-byte stores, and reloc_trampoline() is compiled for both 32bit and 64bit, where unsigned long is a different size.

This happens to work because of the range of the value, but switch to uint32_t to make it explicit.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Frediano Ziglio <[email protected]>

Bloat-o-meter reports a marginal code-gen improvement:

add/remove: 0/0 grow/shrink: 5/7 up/down: 26/-85 (-59)
Function old new delta

  enter_state_helper.cold                     1091    1100      +9
  __start_xen                                 8827    8835      +8
  __cpu_up.cold                                199     204      +5
  intel_unlock_cpuid_leaves                    102     104      +2
  acpi_enter_sleep_state                       397     399      +2
  efi_arch_memory_setup                        538     537      -1
  arch_init_memory                             632     631      -1
  trampoline_phys                                8       4      -4
  do_platform_op                              5439    5431      -8
  compat_platform_op                          5450    5442      -8
  reloc_trampoline64                           137     122     -15
  __cpu_up                                    1513    1465     -48
---
 xen/arch/x86/boot/reloc-trampoline.c  | 2 +-
 xen/arch/x86/efi/efi-boot.h           | 2 +-
 xen/arch/x86/include/asm/trampoline.h | 2 +-
 xen/arch/x86/smpboot.c                | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
xen/arch/x86/boot/reloc-trampoline.c +1 -1
index 0a74c1e75a4c..d5548eb08f85 100644
@@ -15,7 +15,7 @@ void reloc_trampoline64(void)
 #error Unknown architecture
 #endif
 {
-    unsigned long phys = trampoline_phys;
+    uint32_t phys = trampoline_phys;
     const int32_t *trampoline_ptr;
 
     /*
xen/arch/x86/efi/efi-boot.h +1 -1
index 3133985c88f8..7930b7c73892 100644
@@ -235,7 +235,7 @@ static void __init noreturn efi_arch_post_exit_boot(void)
     u64 cr4 = XEN_MINIMAL_CR4 & ~X86_CR4_PGE, efer;
 
     efi_arch_relocate_image(__XEN_VIRT_START - xen_phys_start);
-    memcpy((void *)trampoline_phys, trampoline_start, cfg.size);
+    memcpy(_p(trampoline_phys), trampoline_start, cfg.size);
 
     /*
      * We're in physical mode right now (i.e. identity map), so a regular
xen/arch/x86/include/asm/trampoline.h +1 -1
index 838c2f0b6fcd..8c1e0b48c2c9 100644
@@ -52,7 +52,7 @@ extern char trampoline_start[], trampoline_end[];
  * the 1M boundary (as the trampoline contains 16-bit code), and must be 4k
  * aligned (SIPI requirement for APs).
  */
-extern unsigned long trampoline_phys;
+extern uint32_t trampoline_phys;
 
 /*
  * Calculate the physical address of a symbol in the trampoline.
xen/arch/x86/smpboot.c +1 -1
index 9e79c1a6d6e6..7f0f57bb8ffe 100644
@@ -39,7 +39,7 @@
 #include <irq_vectors.h>
 #include <mach_apic.h>
 
-unsigned long __read_mostly trampoline_phys;
+uint32_t __ro_after_init trampoline_phys;
 enum ap_boot_method __read_mostly ap_boot_method = AP_BOOT_NORMAL;
 
 /* representing HT siblings of each logical CPU */
Signature · 1 line
2.39.5
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Andrew Cooper

As now documented, this variable holds a page aligned value less than 1M.

However, head.S fills it using 4-byte stores, and reloc_trampoline() is compiled for both 32bit and 64bit, where unsigned long is a different size.

This happens to work because of the range of the value, but switch to uint32_t to make it explicit.

noting that ...

xen/arch/x86/boot/reloc-trampoline.c void reloc_trampoline64(void) · line 19

Quoted 9 lines
xen/arch/x86/boot/reloc-trampoline.c +1 -1
@@ -15,7 +15,7 @@ void reloc_trampoline64(void)
 #error Unknown architecture
 #endif
 {
-    unsigned long phys = trampoline_phys;
+    uint32_t phys = trampoline_phys;
     const int32_t *trampoline_ptr;

... this change shouldn't really be needed (but is okay-ish to have).

Jan