Skip to contentSkip to conversation

x86/trampoline: Header cleanup

PATCH In review Andrew Cooper 4 participants 19 messages Sep 5, 2024 – Sep 9, 2024

lore
Share & tools
lore
#0 lore raw

cover x86/trampoline: Header cleanup

This started while inspecting a preprossed file for bitops, but it turns out is relevant for Frediano's 32bit boot code changes too.

Its header file juggling, and documentation with observations relevant to both the ASI and Host UEFI Secureboot work, hence the extended CC list.

Andrew Cooper (3):
x86/acpi: Drop acpi_video_flags and use bootsym(video_flags) directly x86/trampoline: Move the trampoline declarations out of <asm/config.h> x86/trampoline: Collect other scattered trampoline symbols

 xen/arch/x86/acpi/power.c             |   4 +-
 xen/arch/x86/cpu/intel.c              |   2 +
 xen/arch/x86/dmi_scan.c               |  12 ---
 xen/arch/x86/efi/efi-boot.h           |   4 +-
 xen/arch/x86/guest/xen/pvh-boot.c     |   1 +
 xen/arch/x86/include/asm/acpi.h       |   1 -
 xen/arch/x86/include/asm/config.h     |  19 ----
 xen/arch/x86/include/asm/processor.h  |   2 -
 xen/arch/x86/include/asm/setup.h      |   2 -
 xen/arch/x86/include/asm/trampoline.h | 120 ++++++++++++++++++++++++++
 xen/arch/x86/mm.c                     |   1 +
 xen/arch/x86/platform_hypercall.c     |   2 +
 xen/arch/x86/setup.c                  |   1 +
 xen/arch/x86/smpboot.c                |   1 +
 xen/arch/x86/tboot.c                  |   2 +
 xen/arch/x86/x86_64/mm.c              |   2 +
 16 files changed, 136 insertions(+), 40 deletions(-)
 create mode 100644 xen/arch/x86/include/asm/trampoline.h

base-commit: a2de7dc4d845738e734b10fce6550c89c6b1092c

Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/3 x86/acpi: Drop acpi_video_flags and use bootsym(video_flags) directly

This removes a level of indirection, as well as removing a somewhat misleading name; the variable is really "S3 video quirks".

More importantly however it makes it very clear that, right now, parsing the cmdline and quirks depends on having already placed the trampoline; a dependency which is going to be gnarly to untangle.

That said, fixing the quirk is easy. The Toshiba Satellite 4030CDT has an Intel Celeron 300Mhz CPU (Pentium 2 era) from 1998 when MMX was the headline feature, sporting 64M of RAM. Being a 32-bit processor, it hasn't been able to run Xen for about a decade now, so drop the quirk entirely.

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

---
 xen/arch/x86/acpi/power.c       |  2 +-
 xen/arch/x86/dmi_scan.c         | 12 ------------
 xen/arch/x86/include/asm/acpi.h |  1 -
 3 files changed, 1 insertion(+), 14 deletions(-)
xen/arch/x86/acpi/power.c +1 -1
index 610937f42e95..557faf312b09 100644
@@ -56,7 +56,7 @@ static int __init cf_check parse_acpi_sleep(const char *s)
         s = ss + 1;
     } while ( *ss );
 
-    acpi_video_flags |= flag;
+    bootsym(video_flags) |= flag;
 
     return rc;
 }
xen/arch/x86/dmi_scan.c +0 -12
index 81f80c053a7a..9257aee2ab97 100644
@@ -499,13 +499,6 @@ static int __init cf_check ich10_bios_quirk(const struct dmi_system_id *d)
     return 0;
 }
 
-static __init int cf_check reset_videomode_after_s3(const struct dmi_blacklist *d)
-{
-	/* See wakeup.S */
-	acpi_video_flags |= 2;
-	return 0;
-}
-
 static __init int cf_check dmi_disable_acpi(const struct dmi_blacklist *d)
 { 
 	if (!acpi_force) { 
@@ -546,11 +539,6 @@ static __init int cf_check force_acpi_ht(const struct dmi_blacklist *d)
  
 static const struct dmi_blacklist __initconstrel dmi_blacklist[] = {
 
-	{ reset_videomode_after_s3, "Toshiba Satellite 4030cdt", { /* Reset video mode after returning from ACPI S3 sleep */
-			MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),
-			NO_MATCH, NO_MATCH, NO_MATCH
-			} },
-
 	{ ich10_bios_quirk, "Intel board & BIOS",
 		/*
 		 * BIOS leaves legacy USB emulation enabled while
xen/arch/x86/include/asm/acpi.h +0 -1
index 3c47b216d0e0..217819dd619c 100644
@@ -103,7 +103,6 @@ extern unsigned long acpi_wakeup_address;
 extern int8_t acpi_numa;
 
 extern struct acpi_sleep_info acpi_sinfo;
-#define acpi_video_flags bootsym(video_flags)
 struct xenpf_enter_acpi_sleep;
 extern int acpi_enter_sleep(const struct xenpf_enter_acpi_sleep *sleep);
 extern int acpi_enter_state(u32 state);
Signature · 1 line
2.39.2
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] x86/acpi: Drop acpi_video_flags and use bootsym(video_flags) directly

Quoted 7 lines · Andrew Cooper

This removes a level of indirection, as well as removing a somewhat misleading name; the variable is really "S3 video quirks".

More importantly however it makes it very clear that, right now, parsing the cmdline and quirks depends on having already placed the trampoline; a dependency which is going to be gnarly to untangle.

Quoted 6 lines

That said, fixing the quirk is easy. The Toshiba Satellite 4030CDT has an Intel Celeron 300Mhz CPU (Pentium 2 era) from 1998 when MMX was the headline feature, sporting 64M of RAM. Being a 32-bit processor, it hasn't been able to run Xen for about a decade now, so drop the quirk entirely.

Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] x86/acpi: Drop acpi_video_flags and use bootsym(video_flags) directly

In reply to Andrew Cooper
Quoted 2 lines · Andrew Cooper

This removes a level of indirection, as well as removing a somewhat misleading name; the variable is really "S3 video quirks".

nit: Would it be beneficial to rename video_flags to s3_video_flags?

Quoted 16 lines

More importantly however it makes it very clear that, right now, parsing the cmdline and quirks depends on having already placed the trampoline; a dependency which is going to be gnarly to untangle.

That said, fixing the quirk is easy. The Toshiba Satellite 4030CDT has an Intel Celeron 300Mhz CPU (Pentium 2 era) from 1998 when MMX was the headline feature, sporting 64M of RAM. Being a 32-bit processor, it hasn't been able to run Xen for about a decade now, so drop the quirk entirely.

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

Quoted 5 lines
---
 xen/arch/x86/acpi/power.c       |  2 +-
 xen/arch/x86/dmi_scan.c         | 12 ------------
 xen/arch/x86/include/asm/acpi.h |  1 -
 3 files changed, 1 insertion(+), 14 deletions(-)

Always nice to see old hacks disappear.

Cheers,
Alejandro

#4 lore raw

Re: [PATCH 1/3] x86/acpi: Drop acpi_video_flags and use bootsym(video_flags) directly

Quoted 4 lines · Alejandro Vallejo
Quoted 2 lines · Andrew Cooper

This removes a level of indirection, as well as removing a somewhat misleading name; the variable is really "S3 video quirks".

nit: Would it be beneficial to rename video_flags to s3_video_flags?

Probably.  Also to give it some named constants rather than magic numbers.

But I think I'll leave that as an exercise to someone with more time.

Quoted 21 lines
Quoted 16 lines

More importantly however it makes it very clear that, right now, parsing the cmdline and quirks depends on having already placed the trampoline; a dependency which is going to be gnarly to untangle.

That said, fixing the quirk is easy. The Toshiba Satellite 4030CDT has an Intel Celeron 300Mhz CPU (Pentium 2 era) from 1998 when MMX was the headline feature, sporting 64M of RAM. Being a 32-bit processor, it hasn't been able to run Xen for about a decade now, so drop the quirk entirely.

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

Quoted 5 lines
---
 xen/arch/x86/acpi/power.c       |  2 +-
 xen/arch/x86/dmi_scan.c         | 12 ------------
 xen/arch/x86/include/asm/acpi.h |  1 -
 3 files changed, 1 insertion(+), 14 deletions(-)
Quoted 3 lines

Always nice to see old hacks disappear.

Thanks.

~Andrew

#5 lore raw

PATCH 2/3 x86/trampoline: Move the trampoline declarations out of <asm/config.h>

In reply to Andrew Cooper

asm/config.h is included in every translation unit (via xen/config.h), while only a handful of functions actually interact with the trampoline.

Move the infrastructure into its own header, and take the opportunity to document everything.

Also change trampoline_realmode_entry() and wakeup_start() to be nocall functions, rather than char arrays.

No functional change.

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

---
 xen/arch/x86/acpi/power.c             |  2 +
 xen/arch/x86/cpu/intel.c              |  2 +
 xen/arch/x86/efi/efi-boot.h           |  1 +
 xen/arch/x86/guest/xen/pvh-boot.c     |  1 +
 xen/arch/x86/include/asm/config.h     | 19 ------
 xen/arch/x86/include/asm/trampoline.h | 98 +++++++++++++++++++++++++++
 xen/arch/x86/mm.c                     |  1 +
 xen/arch/x86/platform_hypercall.c     |  2 +
 xen/arch/x86/setup.c                  |  1 +
 xen/arch/x86/smpboot.c                |  1 +
 xen/arch/x86/tboot.c                  |  2 +
 xen/arch/x86/x86_64/mm.c              |  2 +
 12 files changed, 113 insertions(+), 19 deletions(-)
 create mode 100644 xen/arch/x86/include/asm/trampoline.h
xen/arch/x86/acpi/power.c +2 -0
index 557faf312b09..08a7fc250800 100644
@@ -31,6 +31,8 @@
 #include <asm/microcode.h>
 #include <asm/prot-key.h>
 #include <asm/spec_ctrl.h>
+#include <asm/trampoline.h>
+
 #include <acpi/cpufreq/cpufreq.h>
 
 uint32_t system_reset_counter = 1;
xen/arch/x86/cpu/intel.c +2 -0
index af56e57bd8ab..807b708217e9 100644
@@ -12,6 +12,8 @@
 #include <asm/mpspec.h>
 #include <asm/apic.h>
 #include <asm/i387.h>
+#include <asm/trampoline.h>
+
 #include <mach_apic.h>
 
 #include "cpu.h"
xen/arch/x86/efi/efi-boot.h +1 -0
index f282358435f1..23e510c77e2e 100644
@@ -9,6 +9,7 @@
 #include <asm/microcode.h>
 #include <asm/msr.h>
 #include <asm/setup.h>
+#include <asm/trampoline.h>
 
 static struct file __initdata ucode;
 static multiboot_info_t __initdata mbi = {
xen/arch/x86/guest/xen/pvh-boot.c +1 -0
index cc57ab2cbcde..e14d7e20e942 100644
@@ -12,6 +12,7 @@
 
 #include <asm/e820.h>
 #include <asm/guest.h>
+#include <asm/trampoline.h>
 
 #include <public/arch-x86/hvm/start_info.h>
 
xen/arch/x86/include/asm/config.h +0 -19
index 2a260a2581fd..1f828bfd52f4 100644
@@ -83,25 +83,6 @@
 #define LIST_POISON1  ((void *)0x0100100100100100UL)
 #define LIST_POISON2  ((void *)0x0200200200200200UL)
 
-#ifndef __ASSEMBLY__
-extern unsigned long trampoline_phys;
-#define bootsym_phys(sym)                                 \
-    (((unsigned long)&(sym)-(unsigned long)&trampoline_start)+trampoline_phys)
-#define bootsym(sym)                                      \
-    (*((typeof(sym) *)__va(bootsym_phys(sym))))
-
-extern char trampoline_start[], trampoline_end[];
-extern char trampoline_realmode_entry[];
-extern unsigned int trampoline_xen_phys_start;
-extern unsigned char trampoline_cpu_started;
-extern char wakeup_start[];
-
-extern unsigned char video_flags;
-
-extern unsigned short boot_edid_caps;
-extern unsigned char boot_edid_info[128];
-#endif
-
 #include <xen/const.h>
 
 #define PML4_ENTRY_BITS  39
xen/arch/x86/include/asm/trampoline.h new file +98 -0

98 lines not on this page · raw message

xen/arch/x86/mm.c +1 -0
index 608583a1134e..c735aaf0e823 100644
@@ -131,6 +131,7 @@
 #include <asm/guest.h>
 #include <asm/pv/domain.h>
 #include <asm/pv/mm.h>
+#include <asm/trampoline.h>
 
 #ifdef CONFIG_PV
 #include "pv/mm.h"
xen/arch/x86/platform_hypercall.c +2 -0
index 7e3278109300..67f851237def 100644
@@ -32,6 +32,8 @@
 #include <asm/mtrr.h>
 #include <asm/io_apic.h>
 #include <asm/setup.h>
+#include <asm/trampoline.h>
+
 #include "cpu/mcheck/mce.h"
 #include "cpu/mtrr/mtrr.h"
 #include <xsm/xsm.h>
xen/arch/x86/setup.c +1 -0
index cd69198326da..a6e77c9ed9fc 100644
@@ -59,6 +59,7 @@
 #include <asm/microcode.h>
 #include <asm/prot-key.h>
 #include <asm/pv/domain.h>
+#include <asm/trampoline.h>
 
 /* opt_nosmp: If true, secondary processors are ignored. */
 static bool __initdata opt_nosmp;
xen/arch/x86/smpboot.c +1 -0
index 0a89f22a3980..9e79c1a6d6e6 100644
@@ -35,6 +35,7 @@
 #include <asm/spec_ctrl.h>
 #include <asm/time.h>
 #include <asm/tboot.h>
+#include <asm/trampoline.h>
 #include <irq_vectors.h>
 #include <mach_apic.h>
 
xen/arch/x86/tboot.c +2 -0
index ba0700d2d5da..d5db60d335e3 100644
@@ -14,6 +14,8 @@
 #include <asm/e820.h>
 #include <asm/tboot.h>
 #include <asm/setup.h>
+#include <asm/trampoline.h>
+
 #include <crypto/vmac.h>
 
 /* tboot=<physical address of shared page> */
xen/arch/x86/x86_64/mm.c +2 -0
index b2a280fba369..0d8e60252962 100644
@@ -37,6 +37,8 @@ EMIT_FILE;
 #include <asm/numa.h>
 #include <asm/mem_paging.h>
 #include <asm/mem_sharing.h>
+#include <asm/trampoline.h>
+
 #include <public/memory.h>
 
 #ifdef CONFIG_PV32
Signature · 1 line
2.39.2
Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] x86/trampoline: Move the trampoline declarations out of <asm/config.h>

Quoted 6 lines · Andrew Cooper

asm/config.h is included in every translation unit (via xen/config.h), while only a handful of functions actually interact with the trampoline.

Move the infrastructure into its own header, and take the opportunity to document everything.

Quoted 6 lines

Also change trampoline_realmode_entry() and wakeup_start() to be nocall functions, rather than char arrays.

No functional change.

xen/arch/x86/include/asm/trampoline.h line 3

Quoted 6 lines
xen/arch/x86/include/asm/trampoline.h new file +3 -0
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef XEN_ASM_TRAMPOLINE_H
+#define XEN_ASM_TRAMPOLINE_H

Not exactly usual a guard name, but once the new naming scheme is finalized most will need renaming anyway.

xen/arch/x86/include/asm/trampoline.h line 65

Quoted 7 lines
xen/arch/x86/include/asm/trampoline.h new file +7 -0
+/*
+ * Calculate the physical address of a symbol in the trampoline.
+ *
+ * Should only be used on symbols declared later in this header.  Specifying
+ * other symbols will compile but malfunction when used, as will using this
+ * helper before the trampoline is placed.
+ */

As to the last point made - we could of course overcome this by setting trampoline_phys to a suitable value initially, and only to its low-mem value once the trampoline was moved there.

As to compiling but malfunctioning - I'd kind of expect relocation overflows to be flagged by the linker.

Jan

#7 lore raw

Re: [PATCH 2/3] x86/trampoline: Move the trampoline declarations out of <asm/config.h>

Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper

asm/config.h is included in every translation unit (via xen/config.h), while only a handful of functions actually interact with the trampoline.

Move the infrastructure into its own header, and take the opportunity to document everything.

Quoted 7 lines
Quoted 6 lines

Also change trampoline_realmode_entry() and wakeup_start() to be nocall functions, rather than char arrays.

No functional change.

Thanks.

Quoted 9 lines

xen/arch/x86/include/asm/trampoline.h line 3

Quoted 7 lines
xen/arch/x86/include/asm/trampoline.h new file +3 -0
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef XEN_ASM_TRAMPOLINE_H
+#define XEN_ASM_TRAMPOLINE_H

Not exactly usual a guard name, but once the new naming scheme is finalized most will need renaming anyway.

What would you prefer?

Quoted 11 lines

xen/arch/x86/include/asm/trampoline.h line 65

Quoted 8 lines
xen/arch/x86/include/asm/trampoline.h new file +7 -0
+/*
+ * Calculate the physical address of a symbol in the trampoline.
+ *
+ * Should only be used on symbols declared later in this header.  Specifying
+ * other symbols will compile but malfunction when used, as will using this
+ * helper before the trampoline is placed.
+ */

As to the last point made - we could of course overcome this by setting trampoline_phys to a suitable value initially, and only to its low-mem value once the trampoline was moved there.

Yes, but then we've got yet another variable needing to stay in sync with xen_phys_start (for a while at least).

Quoted 2 lines

As to compiling but malfunctioning - I'd kind of expect relocation overflows to be flagged by the linker.

What I meant by this is that things like bootsym(opt_cpu_info) will compile but may #PF when used or corrupt data if not.

I couldn't think of any good way to bounds check sym between trampoline_{start,end}[] at build time.

Doing it at runtime is possible, but some usage sites aren't printk/panic friendly.

~Andrew

#8 lore raw

Re: [PATCH 2/3] x86/trampoline: Move the trampoline declarations out of <asm/config.h>

Quoted 28 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper

asm/config.h is included in every translation unit (via xen/config.h), while only a handful of functions actually interact with the trampoline.

Move the infrastructure into its own header, and take the opportunity to document everything.

Quoted 7 lines
Quoted 6 lines

Also change trampoline_realmode_entry() and wakeup_start() to be nocall functions, rather than char arrays.

No functional change.

Thanks.

Quoted 9 lines

xen/arch/x86/include/asm/trampoline.h line 3

Quoted 7 lines
xen/arch/x86/include/asm/trampoline.h new file +3 -0
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef XEN_ASM_TRAMPOLINE_H
+#define XEN_ASM_TRAMPOLINE_H

Not exactly usual a guard name, but once the new naming scheme is finalized most will need renaming anyway.

Quoted 1 line

What would you prefer?

X86_ASM_TRAMPOLINE_H would likely be closer to what we use elsewhere.

Jan

#9 lore raw

Re: [PATCH 2/3] x86/trampoline: Move the trampoline declarations out of <asm/config.h>

Quoted 26 lines · Jan Beulich
Quoted 25 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper

asm/config.h is included in every translation unit (via xen/config.h), while only a handful of functions actually interact with the trampoline.

Move the infrastructure into its own header, and take the opportunity to document everything.

Quoted 7 lines
Quoted 6 lines

Also change trampoline_realmode_entry() and wakeup_start() to be nocall functions, rather than char arrays.

No functional change.

Thanks.

Quoted 8 lines

xen/arch/x86/include/asm/trampoline.h line 3

Quoted 6 lines
xen/arch/x86/include/asm/trampoline.h new file +3 -0
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef XEN_ASM_TRAMPOLINE_H
+#define XEN_ASM_TRAMPOLINE_H

Not exactly usual a guard name, but once the new naming scheme is finalized most will need renaming anyway.

Quoted 2 lines
Quoted 1 line

What would you prefer?

X86_ASM_TRAMPOLINE_H would likely be closer to what we use elsewhere.

Fine.  I'll adjust.

~Andrew

#10 lore raw

PATCH 3/3 x86/trampoline: Collect other scattered trampoline symbols

In reply to Andrew Cooper

... and document them too.

No functional change.

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

video.h, edd.h and e820.h also contain trampoline symbols, but they're pretty well contained headers already.

kbd_shift_flags seems especially dubious. It's a snapshot of the keyboard state when Xen happened to pass through the trampoline, and surely cannot be useful for dom0 in the slightest...

---
 xen/arch/x86/efi/efi-boot.h           |  3 ---
 xen/arch/x86/include/asm/processor.h  |  2 --
 xen/arch/x86/include/asm/setup.h      |  2 --
 xen/arch/x86/include/asm/trampoline.h | 22 ++++++++++++++++++++++
 4 files changed, 22 insertions(+), 7 deletions(-)
xen/arch/x86/efi/efi-boot.h +0 -3
index 23e510c77e2e..833e343a475e 100644
@@ -102,9 +102,6 @@ static void __init efi_arch_relocate_image(unsigned long delta)
     }
 }
 
-extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[];
-extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[];
-
 static void __init relocate_trampoline(unsigned long phys)
 {
     const s32 *trampoline_ptr;
xen/arch/x86/include/asm/processor.h +0 -2
index e71dbb8d3fbf..b8d8127e2dc3 100644
@@ -97,8 +97,6 @@ extern void ctxt_switch_levelling(const struct vcpu *next);
 extern void (*ctxt_switch_masking)(const struct vcpu *next);
 
 extern bool opt_cpu_info;
-extern u32 trampoline_efer;
-extern u64 trampoline_misc_enable_off;
 
 /* Maximum width of physical addresses supported by the hardware. */
 extern unsigned int paddr_bits;
xen/arch/x86/include/asm/setup.h +0 -2
index d75589178b91..4d88503fd2e6 100644
@@ -40,8 +40,6 @@ int remove_xen_ranges(struct rangeset *r);
 
 int cf_check stub_selftest(void);
 
-extern uint8_t kbd_shift_flags;
-
 #ifdef NDEBUG
 # define highmem_start 0
 #else
xen/arch/x86/include/asm/trampoline.h +22 -0
index cc3420ba3530..dc2c47946be4 100644
@@ -49,6 +49,13 @@
 /* SAF-0-safe */
 extern char trampoline_start[], trampoline_end[];
 
+/*
+ * Relocations for the trampoline.  Generated by the bootsym_{seg,}rel()
+ * macros, and collected by the linker.
+ */
+extern const int32_t __trampoline_rel_start[], __trampoline_rel_stop[];
+extern const int32_t __trampoline_seg_start[], __trampoline_seg_stop[];
+
 /*
  * The physical address of trampoline_start[] in low memory.  It must be below
  * the 1M boundary (as the trampoline contains 16-bit code), and must be 4k
@@ -87,9 +94,24 @@ extern uint32_t trampoline_xen_phys_start;
 /* A semaphore to indicate signs-of-life at the start of the AP boot path. */
 extern uint8_t trampoline_cpu_started;
 
+/*
+ * Extra MSR_EFER settings when activating Long Mode.  EFER_NXE is necessary
+ * for APs to boot if the BSP found and activated support.
+ */
+extern uint32_t trampoline_efer;
+
+/*
+ * When nonzero, clear the specified bits in MSR_MISC_ENABLE.  This is
+ * necessary to clobber XD_DISABLE before trying to set MSR_EFER.NXE.
+ */
+extern uint64_t trampoline_misc_enable_off;
+
 /* Quirks about video mode-setting on S3 resume. */
 extern uint8_t video_flags;
 
+/* BIOS Int 16h, Fn 02h.  The keyboard shift status. */
+extern uint8_t kbd_shift_flags;
+
 /* Extended Display Identification Data, gathered from the BIOS. */
 extern uint16_t boot_edid_caps;
 extern uint8_t boot_edid_info[128];
Signature · 1 line
2.39.2
#11 lore raw

Re: [PATCH 3/3] x86/trampoline: Collect other scattered trampoline symbols

Quoted 3 lines · Andrew Cooper

kbd_shift_flags seems especially dubious. It's a snapshot of the keyboard state when Xen happened to pass through the trampoline, and surely cannot be useful for dom0 in the slightest...

No more or less than if the kernel takes such a snapshot while booting natively. Whatever this is used for there (it's been too long - I don't recall).

xen/arch/x86/efi/efi-boot.h static void __init efi_arch_relocate_image(unsigned long delta) · line 106

Quoted 8 lines
xen/arch/x86/efi/efi-boot.h +0 -2
@@ -102,9 +102,6 @@ static void __init efi_arch_relocate_image(unsigned long delta)
     }
 }
 
-extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[];
-extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[];

I'd prefer if these stayed here, leaving the 4 symbols as minimally exposed as possible. Recall that efi-boot.h isn't really a header in that sense, but rather a .c file. Elsewhere we keep decls in .c files when they're used in just one CU.

Jan

#12 lore raw

Re: [PATCH 3/3] x86/trampoline: Collect other scattered trampoline symbols

Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
xen/arch/x86/efi/efi-boot.h +0 -0
@@ -102,9 +102,6 @@ static void __init efi_arch_relocate_image(unsigned long delta)
     }
 }
 
Quoted 6 lines

xen/arch/x86/efi/efi-boot.h static void __init efi_arch_relocate_image(unsigned long delta) · line 106

Quoted 2 lines
xen/arch/x86/efi/efi-boot.h +0 -2
-extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[];
-extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[];

I'd prefer if these stayed here, leaving the 4 symbols as minimally exposed as possible. Recall that efi-boot.h isn't really a header in that sense, but rather a .c file. Elsewhere we keep decls in .c files when they're used in just one CU.

See Frediano's RFC series, which needs to change this in order to move the 32bit relocation logic from asm to C.

The only reason efi-boot.h can get away with this right now is because the other logic is written entirely in asm.

Scope-limiting linker section boundaries more than regular variables is weird to me.  It's not as if they magically take more care to use than regular variables, and trampoline.h is not a wide scope by any means.

~Andrew

#13 lore raw

Re: [PATCH 3/3] x86/trampoline: Collect other scattered trampoline symbols

Quoted 15 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich

xen/arch/x86/efi/efi-boot.h static void __init efi_arch_relocate_image(unsigned

Quoted 3 lines · Andrew Cooper
xen/arch/x86/efi/efi-boot.h +0 -0
@@ -102,9 +102,6 @@ static void __init efi_arch_relocate_image(unsigned

long delta)

Quoted 6 lines

xen/arch/x86/efi/efi-boot.h static void __init efi_arch_relocate_image(unsigned long delta) · line 106

Quoted 5 lines
xen/arch/x86/efi/efi-boot.h +0 -2
     }
 }
 
-extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[];
-extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[];

I'd prefer if these stayed here, leaving the 4 symbols as minimally

exposed as

Quoted 2 lines

possible. Recall that efi-boot.h isn't really a header in that sense, but rather a .c file. Elsewhere we keep decls in .c files when they're used

Quoted 7 lines

in just

Quoted 1 line

one CU.

See Frediano's RFC series, which needs to change this in order to move the 32bit relocation logic from asm to C.

Not strictly necessary, I can declare in the C file as they were declared

in efi-boot.h (which is more a .c file as an header as Jan said). I think the idea of declaring into a source file is that if another file wants to use it has to declare it again, so a bit more friction. But any access to trampoline variables should be considered as something to limit in any case, so having in a separate header helps (this does not mean that removing from the header is still increasing the friction).

Personally, I'm not strong about the 2 options here. Slightly prefer having all variable declared in a single header.

The only reason efi-boot.h can get away with this right now is because

Quoted 8 lines

the other logic is written entirely in asm.

Scope-limiting linker section boundaries more than regular variables is weird to me. It's not as if they magically take more care to use than regular variables, and trampoline.h is not a wide scope by any means.

Frediano

#14 lore raw

Re: [PATCH 3/3] x86/trampoline: Collect other scattered trampoline symbols

Quoted 36 lines · Frediano Ziglio

On Thu, Sep 5, 2024 at 5:10 PM Andrew Cooper
<[email protected]> wrote:

    On 05/09/2024 4:42 pm, Jan Beulich wrote:
    > On 05.09.2024 15:06, Andrew Cooper wrote:
    >> --- a/xen/arch/x86/efi/efi-boot.h
    >> +++ b/xen/arch/x86/efi/efi-boot.h
    >> @@ -102,9 +102,6 @@ static void __init
    efi_arch_relocate_image(unsigned long delta)
    >>      }
    >>  }
    >> 
    >> -extern const s32 __trampoline_rel_start[],
    __trampoline_rel_stop[];
    >> -extern const s32 __trampoline_seg_start[],
    __trampoline_seg_stop[];
    > I'd prefer if these stayed here, leaving the 4 symbols as
    minimally exposed as
    > possible. Recall that efi-boot.h isn't really a header in that
    sense, but
    > rather a .c file. Elsewhere we keep decls in .c files when
    they're used in just
    > one CU.

    See Frediano's RFC series, which needs to change this in order to move
    the 32bit relocation logic from asm to C.

Not strictly necessary, I can declare in the C file as they were declared in efi-boot.h (which is more a .c file as an header as Jan said). I think the idea of declaring into a source file is that if another file wants to use it has to declare it again, so a bit more friction. But any access to trampoline variables should be considered as something to limit in any case, so having in a separate header helps (this does not mean that removing from the header is still increasing the friction).

Quoted 2 lines

Personally, I'm not strong about the 2 options here. Slightly prefer having all variable declared in a single header.

Declaring the same symbol in multiple places is a hard MISRA failure now.

Hence why I was trying to clean this up to simplify your patches.

~Andrew

#15 lore raw

Re: [PATCH 3/3] x86/trampoline: Collect other scattered trampoline symbols

In reply to Andrew Cooper
Quoted 15 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
xen/arch/x86/efi/efi-boot.h +0 -0
@@ -102,9 +102,6 @@ static void __init efi_arch_relocate_image(unsigned long delta)
     }
 }
 
Quoted 6 lines

xen/arch/x86/efi/efi-boot.h static void __init efi_arch_relocate_image(unsigned long delta) · line 106

Quoted 2 lines
xen/arch/x86/efi/efi-boot.h +0 -2
-extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[];
-extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[];

I'd prefer if these stayed here, leaving the 4 symbols as minimally exposed as possible. Recall that efi-boot.h isn't really a header in that sense, but rather a .c file. Elsewhere we keep decls in .c files when they're used in just one CU.

Quoted 2 lines

See Frediano's RFC series, which needs to change this in order to move the 32bit relocation logic from asm to C.

And it moves the declarations to the new .c file. Visibility still limited to that one file. And (afaics) no Misra violation, contrary to what your later reply to Frediano suggests.

Quoted 7 lines

The only reason efi-boot.h can get away with this right now is because the other logic is written entirely in asm.

Scope-limiting linker section boundaries more than regular variables is weird to me.  It's not as if they magically take more care to use than regular variables, and trampoline.h is not a wide scope by any means.

It's not "more than", it's "like" (i.e. no matter whether a linker script or assembly is the origin of the symbol).

Jan

#16 lore raw

Re: [PATCH 3/3] x86/trampoline: Collect other scattered trampoline symbols

Quoted 15 lines · Jan Beulich
Quoted 14 lines · Andrew Cooper
Quoted 13 lines · Jan Beulich

xen/arch/x86/efi/efi-boot.h static void __init efi_arch_relocate_image(unsigned long delta) · line 106

Quoted 8 lines · Andrew Cooper
xen/arch/x86/efi/efi-boot.h +0 -2
@@ -102,9 +102,6 @@ static void __init efi_arch_relocate_image(unsigned long delta)
     }
 }
 
-extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[];
-extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[];

I'd prefer if these stayed here, leaving the 4 symbols as minimally exposed as possible. Recall that efi-boot.h isn't really a header in that sense, but rather a .c file. Elsewhere we keep decls in .c files when they're used in just one CU.

Quoted 5 lines
Quoted 2 lines

See Frediano's RFC series, which needs to change this in order to move the 32bit relocation logic from asm to C.

And it moves the declarations to the new .c file. Visibility still limited to that one file. And (afaics) no Misra violation, contrary to what your later reply to Frediano suggests.

If only there were an easy way to answer the question.

https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/7766305370

Failure: 4 regressions found for clean guidelines
  service MC3R1.R8.5: (required) An external object or function shall be declared once in one and only one file:
   violation: 4

Quoted 9 lines
Quoted 7 lines

The only reason efi-boot.h can get away with this right now is because the other logic is written entirely in asm.

Scope-limiting linker section boundaries more than regular variables is weird to me.  It's not as if they magically take more care to use than regular variables, and trampoline.h is not a wide scope by any means.

It's not "more than", it's "like" (i.e. no matter whether a linker script or assembly is the origin of the symbol).

I'm asking why linker-section-boundary symbols should be treated specially, and not seeing an answer.

I assert they do not warrant special treatment, and should live in header files like every other extern symbol we use.

~Andrew

#17 lore raw

Re: [PATCH 3/3] x86/trampoline: Collect other scattered trampoline symbols

Quoted 22 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Andrew Cooper
Quoted 13 lines · Jan Beulich

xen/arch/x86/efi/efi-boot.h static void __init efi_arch_relocate_image(unsigned long delta) · line 106

Quoted 8 lines · Andrew Cooper
xen/arch/x86/efi/efi-boot.h +0 -2
@@ -102,9 +102,6 @@ static void __init efi_arch_relocate_image(unsigned long delta)
     }
 }
 
-extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[];
-extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[];

I'd prefer if these stayed here, leaving the 4 symbols as minimally exposed as possible. Recall that efi-boot.h isn't really a header in that sense, but rather a .c file. Elsewhere we keep decls in .c files when they're used in just one CU.

Quoted 5 lines
Quoted 2 lines

See Frediano's RFC series, which needs to change this in order to move the 32bit relocation logic from asm to C.

And it moves the declarations to the new .c file. Visibility still limited to that one file. And (afaics) no Misra violation, contrary to what your later reply to Frediano suggests.

Quoted 8 lines

If only there were an easy way to answer the question.

https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/7766305370

Failure: 4 regressions found for clean guidelines
  service MC3R1.R8.5: (required) An external object or function shall be declared once in one and only one file:
   violation: 4

I'm afraid I'm having trouble locating, in that .log file, where the actual regressions are pointed out. I guess I'm simply not used to reading such logs yet, and hence I just don't know what to search for. In any event, I think there's a set of issues here:
- Eclair apparently considered efi-boot.h a header file, which (as said earlier) isn't quite right.
- Declarations there are thus deemed okay (when they shouldn't, unless deviated).
- Movement to a proper .c file points out that those decls may have been missing "asmlinkage" already before.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The only reason efi-boot.h can get away with this right now is because the other logic is written entirely in asm.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Scope-limiting linker section boundaries more than regular variables is weird to me.  It's not as if they magically take more care to use than regular variables, and trampoline.h is not a wide scope by any means.

It's not "more than", it's "like" (i.e. no matter whether a linker script or assembly is the origin of the symbol).

I'm asking why linker-section-boundary symbols should be treated specially, and not seeing an answer.

IOW you're not taking "they're no different from symbols defined in .S files, and hence shouldn't be treated differently" as a possible position to take? See __page_tables_{start,end}, cpu0_stack[], or multiboot_ptr as examples.

Quoted 2 lines

I assert they do not warrant special treatment, and should live in header files like every other extern symbol we use.

Then the same would also apply to symbols coming from .S files. Which in turn were deliberately deviated (rather than moved) in the course of dealing with the Misra rule relevant here.

Jan

#18 lore raw
In reply to Andrew Cooper
Quoted 33 lines · Andrew Cooper

This started while inspecting a preprossed file for bitops, but it turns out
is relevant for Frediano's 32bit boot code changes too.

Its header file juggling, and documentation with observations relevant to both
the ASI and Host UEFI Secureboot work, hence the extended CC list.

Andrew Cooper (3):
x86/acpi: Drop acpi_video_flags and use bootsym(video_flags) directly x86/trampoline: Move the trampoline declarations out of <asm/config.h> x86/trampoline: Collect other scattered trampoline symbols

 xen/arch/x86/acpi/power.c             |   4 +-
 xen/arch/x86/cpu/intel.c              |   2 +
 xen/arch/x86/dmi_scan.c               |  12 ---
 xen/arch/x86/efi/efi-boot.h           |   4 +-
 xen/arch/x86/guest/xen/pvh-boot.c     |   1 +
 xen/arch/x86/include/asm/acpi.h       |   1 -
 xen/arch/x86/include/asm/config.h     |  19 ----
 xen/arch/x86/include/asm/processor.h  |   2 -
 xen/arch/x86/include/asm/setup.h      |   2 -
 xen/arch/x86/include/asm/trampoline.h | 120 ++++++++++++++++++++++++++
 xen/arch/x86/mm.c                     |   1 +
 xen/arch/x86/platform_hypercall.c     |   2 +
 xen/arch/x86/setup.c                  |   1 +
 xen/arch/x86/smpboot.c                |   1 +
 xen/arch/x86/tboot.c                  |   2 +
 xen/arch/x86/x86_64/mm.c              |   2 +
 16 files changed, 136 insertions(+), 40 deletions(-)
 create mode 100644 xen/arch/x86/include/asm/trampoline.h
Quoted 3 lines

base-commit: a2de7dc4d845738e734b10fce6550c89c6b1092c

Hi,
the series looks good to me.

Frediano