Skip to contentSkip to conversation

x86 trampoline rework for 3.5

GIT PULL H. Peter Anvin 3 participants 5 messages May 29, 2012 – May 30, 2012

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

Hi Linus,

This code reworks all the "trampoline"/"realmode" code (various bits that need to live in the first megabyte of memory, most but not all of which runs in real mode at some point) in the kernel into a single object. The main reason for doing this is that it eliminates the last place in the kernel where we needed pages to be mapped RWX. This code separates all that code into proper R/RW/RX pages.

The rework of relocs.c is already in upstream. I know you don't like lambda merges, but I did one for this branch, because I found that without it git will silently mismerge relocs.c between your tree and this branch; with the lambda merge in place it merges correctly.

If you prefer to do this manually, you can instead pull 61f5446169046c217a5479517edac3a890c3bee7; however, make sure that arch/x86/tools/relocs.c ends up being the one from your current upstream tree.

The following changes since commit ea17e7414bc62e8d3bde8d08e3df1d921c518c17:

x86, relocs: Add jiffies and jiffies_64 to the relative whitelist (2012-05-24 07:16:18 -0700)

are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86-trampoline-for-linus

The head of this branch is 015dc188a8c1bf47390be50e942e0b1a2f6fb3c5.

H. Peter Anvin (22):
x86, realmode: 16-bit real-mode code support for relocs tool x86, realmode: Allow absolute pa_* symbols in the realmode code x86, realmode: Add .text64 section, make barrier symbols absolute x86, realmode: Move bits to the proper sections in trampoline_64.S x86, realmode: Align .data section in trampoline_32.S
x86, realmode: Remove indirect jumps in trampoline_64.S
x86, realmode: Remove indirect jumps in trampoline_32 and wakeup_asm x86, realmode: Replace open-coded ljmpw with a macro
x86, realmode: Move trampoline_*.S early in the link order x86, realmode: Fix always-zero test in reboot_32.S
x86, realmode: Make sure all generated files are listed in targets x86, realmode: Mask out EFER.LMA when saving trampoline EFER x86, realmode: Move not-common bits out of trampoline_common.S x86, realmode: Move kernel/realmode.c to realmode/init.c
x86, realmode: Change EFER to a single u64 field
acpi, bgrd: Add missing <linux/io.h> to drivers/acpi/bgrt.c
xen-acpi-processor: Add missing #include <xen/xen.h>
x86, relocs: Workaround for binutils 2.22.52.0.1 section bug x86, relocs: More relocations which may end up as absolute x86, relocs: When printing an error, say relative or absolute x86, realmode: Move end signature into header.S
Merge commit 'ea17e7414bc62e8d3bde8d08e3df1d921c518c17' into x86/trampoline

Jarkko Sakkinen (15):
x86, realmode: realmode.bin infrastructure
x86, realmode: Relocator for realmode code
x86, realmode: Move reboot_32.S to unified realmode code x86, realmode: Move SMP trampoline to unified realmode code x86, realmode: Move ACPI wakeup to unified realmode code x86, realmode: Set permission for real mode pages
x86, realmode: fix 64-bit wakeup sequence
x86, realmode: don't copy real_mode_header
x86, realmode: flattened rm hierachy
x86, realmode: header for trampoline code
x86, realmode: move relocs from scripts/ to arch/x86/tools x86, realmode: fixes compilation issue in tboot.c
x86, realmode: read cr4 and EFER from kernel for 64-bit trampoline x86, realmode: build fix: remove duplicate build
x86, realmode: Fix no cache bits test in reboot_32.S

 arch/x86/Kbuild                                    |    2 +-
 arch/x86/include/asm/acpi.h                        |    2 -
 arch/x86/include/asm/processor.h                   |    7 +-
 arch/x86/include/asm/realmode.h                    |   62 ++++++++
 arch/x86/include/asm/trampoline.h                  |   39 -----
 arch/x86/kernel/Makefile                           |    2 -
 arch/x86/kernel/acpi/Makefile                      |    9 +-
 arch/x86/kernel/acpi/realmode/.gitignore           |    3 -
 arch/x86/kernel/acpi/realmode/Makefile             |   59 --------
 arch/x86/kernel/acpi/realmode/bioscall.S           |    1 -
 arch/x86/kernel/acpi/realmode/copy.S               |    1 -
 arch/x86/kernel/acpi/realmode/regs.c               |    1 -
 arch/x86/kernel/acpi/realmode/video-bios.c         |    1 -
 arch/x86/kernel/acpi/realmode/video-mode.c         |    1 -
 arch/x86/kernel/acpi/realmode/video-vesa.c         |    1 -
 arch/x86/kernel/acpi/realmode/video-vga.c          |    1 -
 arch/x86/kernel/acpi/realmode/wakeup.lds.S         |   62 --------
 arch/x86/kernel/acpi/sleep.c                       |   33 +----
 arch/x86/kernel/acpi/sleep.h                       |    2 +-
 arch/x86/kernel/acpi/wakeup_rm.S                   |   12 --
 arch/x86/kernel/head32.c                           |    1 -
 arch/x86/kernel/head64.c                           |    1 -
 arch/x86/kernel/head_32.S                          |    5 +-
 arch/x86/kernel/head_64.S                          |    4 -
 arch/x86/kernel/mpparse.c                          |    1 -
 arch/x86/kernel/reboot.c                           |   25 +---
 arch/x86/kernel/setup.c                            |    6 +-
 arch/x86/kernel/smpboot.c                          |   18 ++-
 arch/x86/kernel/tboot.c                            |    7 +-
 arch/x86/kernel/trampoline.c                       |   42 ------
 arch/x86/kernel/trampoline_32.S                    |   83 -----------
 arch/x86/kernel/vmlinux.lds.S                      |   12 --
 arch/x86/realmode/Makefile                         |   18 +++
 arch/x86/realmode/init.c                           |  115 +++++++++++++++
 arch/x86/realmode/rm/.gitignore                    |    3 +
 arch/x86/realmode/rm/Makefile                      |   82 +++++++++++
 arch/x86/realmode/rm/bioscall.S                    |    1 +
 arch/x86/realmode/rm/copy.S                        |    1 +
 arch/x86/realmode/rm/header.S                      |   41 ++++++
 arch/x86/realmode/rm/realmode.h                    |   21 +++
 arch/x86/realmode/rm/realmode.lds.S                |   76 ++++++++++
 arch/x86/{kernel => realmode/rm}/reboot_32.S       |   89 ++++++------
 arch/x86/realmode/rm/regs.c                        |    1 +
 arch/x86/realmode/rm/stack.S                       |   19 +++
 arch/x86/realmode/rm/trampoline_32.S               |   74 ++++++++++
 arch/x86/{kernel => realmode/rm}/trampoline_64.S   |  148 +++++++++-----------
 arch/x86/realmode/rm/trampoline_common.S           |    7 +
 arch/x86/realmode/rm/video-bios.c                  |    1 +
 arch/x86/realmode/rm/video-mode.c                  |    1 +
 arch/x86/realmode/rm/video-vesa.c                  |    1 +
 arch/x86/realmode/rm/video-vga.c                   |    1 +
 .../acpi/realmode => realmode/rm}/wakemain.c       |    3 +-
 .../{kernel/acpi/realmode => realmode/rm}/wakeup.h |   10 +--
 .../realmode/wakeup.S => realmode/rm/wakeup_asm.S} |  131 +++++++++--------
 arch/x86/realmode/rmpiggy.S                        |   20 +++
 arch/x86/tools/relocs.c                            |    7 +
 drivers/acpi/bgrt.c                                |    1 +
 drivers/acpi/sleep.c                               |    8 +-
 drivers/xen/xen-acpi-processor.c                   |    1 +
 59 files changed, 774 insertions(+), 613 deletions(-)
arch/x86/Kbuild +1 -1
index 0e9dec6..e5287d8 100644
@@ -1,4 +1,3 @@
-
 obj-$(CONFIG_KVM) += kvm/
 
 # Xen paravirtualization support
@@ -7,6 +6,7 @@ obj-$(CONFIG_XEN) += xen/
 # lguest paravirtualization support
 obj-$(CONFIG_LGUEST_GUEST) += lguest/
 
+obj-y += realmode/
 obj-y += kernel/
 obj-y += mm/
 
arch/x86/include/asm/acpi.h +0 -2
index 610001d..724aa44 100644
@@ -29,7 +29,6 @@
 #include <asm/processor.h>
 #include <asm/mmu.h>
 #include <asm/mpspec.h>
-#include <asm/trampoline.h>
 
 #define COMPILER_DEPENDENT_INT64   long long
 #define COMPILER_DEPENDENT_UINT64  unsigned long long
@@ -118,7 +117,6 @@ static inline void acpi_disable_pci(void)
 extern int acpi_suspend_lowlevel(void);
 
 extern const unsigned char acpi_wakeup_code[];
-#define acpi_wakeup_address (__pa(TRAMPOLINE_SYM(acpi_wakeup_code)))
 
 /* early initialization routine */
 extern void acpi_reserve_wakeup_memory(void);
arch/x86/include/asm/processor.h +6 -1
index 4fa7dcc..404583c 100644
@@ -544,13 +544,16 @@ static inline void load_sp0(struct tss_struct *tss,
  * enable), so that any CPU's that boot up
  * after us can get the correct flags.
  */
-extern unsigned long		mmu_cr4_features;
+extern unsigned long mmu_cr4_features;
+extern u32 *trampoline_cr4_features;
 
 static inline void set_in_cr4(unsigned long mask)
 {
 	unsigned long cr4;
 
 	mmu_cr4_features |= mask;
+	if (trampoline_cr4_features)
+		*trampoline_cr4_features = mmu_cr4_features;
 	cr4 = read_cr4();
 	cr4 |= mask;
 	write_cr4(cr4);
@@ -561,6 +564,8 @@ static inline void clear_in_cr4(unsigned long mask)
 	unsigned long cr4;
 
 	mmu_cr4_features &= ~mask;
+	if (trampoline_cr4_features)
+		*trampoline_cr4_features = mmu_cr4_features;
 	cr4 = read_cr4();
 	cr4 &= ~mask;
 	write_cr4(cr4);
arch/x86/include/asm/realmode.h new file +62 -0

62 lines not on this page · raw message

arch/x86/include/asm/trampoline.h deleted +0 -39
deleted file mode 100644
index feca311..0000000
@@ -1,39 +0,0 @@
-#ifndef _ASM_X86_TRAMPOLINE_H
-#define _ASM_X86_TRAMPOLINE_H
-
-#ifndef __ASSEMBLY__
-
-#include <linux/types.h>
-#include <asm/io.h>
-
-/*
- * Trampoline 80x86 program as an array.  These are in the init rodata
- * segment, but that's okay, because we only care about the relative
- * addresses of the symbols.
- */
-extern const unsigned char x86_trampoline_start [];
-extern const unsigned char x86_trampoline_end   [];
-extern unsigned char *x86_trampoline_base;
-
-extern unsigned long init_rsp;
-extern unsigned long initial_code;
-extern unsigned long initial_gs;
-
-extern void __init setup_trampolines(void);
-
-extern const unsigned char trampoline_data[];
-extern const unsigned char trampoline_status[];
-
-#define TRAMPOLINE_SYM(x)						\
-	((void *)(x86_trampoline_base +					\
-		  ((const unsigned char *)(x) - x86_trampoline_start)))
-
-/* Address of the SMP trampoline */
-static inline unsigned long trampoline_address(void)
-{
-	return virt_to_phys(TRAMPOLINE_SYM(trampoline_data));
-}
-
-#endif /* __ASSEMBLY__ */
-
-#endif /* _ASM_X86_TRAMPOLINE_H */
arch/x86/kernel/Makefile +0 -2
index 532d2e0..0848433 100644
@@ -35,7 +35,6 @@ obj-y			+= tsc.o io_delay.o rtc.o
 obj-y			+= pci-iommu_table.o
 obj-y			+= resource.o
 
-obj-y				+= trampoline.o trampoline_$(BITS).o
 obj-y				+= process.o
 obj-y				+= i387.o xsave.o
 obj-y				+= ptrace.o
@@ -48,7 +47,6 @@ obj-$(CONFIG_STACKTRACE)	+= stacktrace.o
 obj-y				+= cpu/
 obj-y				+= acpi/
 obj-y				+= reboot.o
-obj-$(CONFIG_X86_32)		+= reboot_32.o
 obj-$(CONFIG_MCA)		+= mca_32.o
 obj-$(CONFIG_X86_MSR)		+= msr.o
 obj-$(CONFIG_X86_CPUID)		+= cpuid.o
arch/x86/kernel/acpi/Makefile +1 -8
index 6f35260..163b225 100644
@@ -1,14 +1,7 @@
-subdir-				:= realmode
-
 obj-$(CONFIG_ACPI)		+= boot.o
-obj-$(CONFIG_ACPI_SLEEP)	+= sleep.o wakeup_rm.o wakeup_$(BITS).o
+obj-$(CONFIG_ACPI_SLEEP)	+= sleep.o wakeup_$(BITS).o
 
 ifneq ($(CONFIG_ACPI_PROCESSOR),)
 obj-y				+= cstate.o
 endif
 
-$(obj)/wakeup_rm.o:    $(obj)/realmode/wakeup.bin
-
-$(obj)/realmode/wakeup.bin: FORCE
-	$(Q)$(MAKE) $(build)=$(obj)/realmode
-
arch/x86/kernel/acpi/realmode/.gitignore deleted +0 -3
deleted file mode 100644
index 58f1f48..0000000
@@ -1,3 +0,0 @@
-wakeup.bin
-wakeup.elf
-wakeup.lds
arch/x86/kernel/acpi/realmode/Makefile deleted +0 -59

59 lines not on this page · raw message

arch/x86/kernel/acpi/realmode/bioscall.S deleted +0 -1
deleted file mode 100644
index f51eb0b..0000000
@@ -1 +0,0 @@
-#include "../../../boot/bioscall.S"
arch/x86/kernel/acpi/realmode/copy.S deleted +0 -1
deleted file mode 100644
index dc59ebe..0000000
@@ -1 +0,0 @@
-#include "../../../boot/copy.S"
arch/x86/kernel/acpi/realmode/regs.c deleted +0 -1
deleted file mode 100644
index 6206033..0000000
@@ -1 +0,0 @@
-#include "../../../boot/regs.c"
arch/x86/kernel/acpi/realmode/video-bios.c deleted +0 -1
deleted file mode 100644
index 7deabc1..0000000
@@ -1 +0,0 @@
-#include "../../../boot/video-bios.c"
arch/x86/kernel/acpi/realmode/video-mode.c deleted +0 -1
deleted file mode 100644
index 328ad20..0000000
@@ -1 +0,0 @@
-#include "../../../boot/video-mode.c"
arch/x86/kernel/acpi/realmode/video-vesa.c deleted +0 -1
deleted file mode 100644
index 9dbb967..0000000
@@ -1 +0,0 @@
-#include "../../../boot/video-vesa.c"
arch/x86/kernel/acpi/realmode/video-vga.c deleted +0 -1
deleted file mode 100644
index bcc8125..0000000
@@ -1 +0,0 @@
-#include "../../../boot/video-vga.c"
arch/x86/kernel/acpi/realmode/wakeup.lds.S deleted +0 -62

62 lines not on this page · raw message

arch/x86/kernel/acpi/sleep.c +4 -29
index 146a49c..95bf99d 100644
@@ -14,8 +14,9 @@
 #include <asm/desc.h>
 #include <asm/pgtable.h>
 #include <asm/cacheflush.h>
+#include <asm/realmode.h>
 
-#include "realmode/wakeup.h"
+#include "../../realmode/rm/wakeup.h"
 #include "sleep.h"
 
 unsigned long acpi_realmode_flags;
@@ -36,13 +37,9 @@ asmlinkage void acpi_enter_s3(void)
  */
 int acpi_suspend_lowlevel(void)
 {
-	struct wakeup_header *header;
-	/* address in low memory of the wakeup routine. */
-	char *acpi_realmode;
+	struct wakeup_header *header =
+		(struct wakeup_header *) __va(real_mode_header->wakeup_header);
 
-	acpi_realmode = TRAMPOLINE_SYM(acpi_wakeup_code);
-
-	header = (struct wakeup_header *)(acpi_realmode + WAKEUP_HEADER_OFFSET);
 	if (header->signature != WAKEUP_HEADER_SIGNATURE) {
 		printk(KERN_ERR "wakeup header does not match\n");
 		return -EINVAL;
@@ -50,27 +47,6 @@ int acpi_suspend_lowlevel(void)
 
 	header->video_mode = saved_video_mode;
 
-	header->wakeup_jmp_seg = acpi_wakeup_address >> 4;
-
-	/*
-	 * Set up the wakeup GDT.  We set these up as Big Real Mode,
-	 * that is, with limits set to 4 GB.  At least the Lenovo
-	 * Thinkpad X61 is known to need this for the video BIOS
-	 * initialization quirk to work; this is likely to also
-	 * be the case for other laptops or integrated video devices.
-	 */
-
-	/* GDT[0]: GDT self-pointer */
-	header->wakeup_gdt[0] =
-		(u64)(sizeof(header->wakeup_gdt) - 1) +
-		((u64)__pa(&header->wakeup_gdt) << 16);
-	/* GDT[1]: big real mode-like code segment */
-	header->wakeup_gdt[1] =
-		GDT_ENTRY(0x809b, acpi_wakeup_address, 0xfffff);
-	/* GDT[2]: big real mode-like data segment */
-	header->wakeup_gdt[2] =
-		GDT_ENTRY(0x8093, acpi_wakeup_address, 0xfffff);
-
 #ifndef CONFIG_64BIT
 	store_gdt((struct desc_ptr *)&header->pmode_gdt);
 
@@ -95,7 +71,6 @@ int acpi_suspend_lowlevel(void)
 	header->pmode_cr3 = (u32)__pa(&initial_page_table);
 	saved_magic = 0x12345678;
 #else /* CONFIG_64BIT */
-	header->trampoline_segment = trampoline_address() >> 4;
 #ifdef CONFIG_SMP
 	stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
 	early_gdt_descr.address =
arch/x86/kernel/acpi/sleep.h +1 -1
index d68677a..5653a57 100644
@@ -2,8 +2,8 @@
  *	Variables and functions used by the code in sleep.c
  */
 
-#include <asm/trampoline.h>
 #include <linux/linkage.h>
+#include <asm/realmode.h>
 
 extern unsigned long saved_video_mode;
 extern long saved_magic;
arch/x86/kernel/acpi/wakeup_rm.S deleted +0 -12
deleted file mode 100644
index 63b8ab5..0000000
@@ -1,12 +0,0 @@
-/*
- * Wrapper script for the realmode binary as a transport object
- * before copying to low memory.
- */
-#include <asm/page_types.h>
-
-	.section ".x86_trampoline","a"
-	.balign PAGE_SIZE
-	.globl	acpi_wakeup_code
-acpi_wakeup_code:
-	.incbin	"arch/x86/kernel/acpi/realmode/wakeup.bin"
-	.size	acpi_wakeup_code, .-acpi_wakeup_code
arch/x86/kernel/head32.c +0 -1
index 51ff186..c18f59d 100644
@@ -14,7 +14,6 @@
 #include <asm/sections.h>
 #include <asm/e820.h>
 #include <asm/page.h>
-#include <asm/trampoline.h>
 #include <asm/apic.h>
 #include <asm/io_apic.h>
 #include <asm/bios_ebda.h>
arch/x86/kernel/head64.c +0 -1
index 3a3b779..037df57 100644
@@ -24,7 +24,6 @@
 #include <asm/sections.h>
 #include <asm/kdebug.h>
 #include <asm/e820.h>
-#include <asm/trampoline.h>
 #include <asm/bios_ebda.h>
 
 static void __init zap_identity_mappings(void)
arch/x86/kernel/head_32.S +1 -4
index ce0be7c..a3c2b4f 100644
@@ -273,10 +273,7 @@ num_subarch_entries = (. - subarch_entries) / 4
  * If cpu hotplug is not supported then this code can go in init section
  * which will be freed later
  */
-
 __CPUINIT
-
-#ifdef CONFIG_SMP
 ENTRY(startup_32_smp)
 	cld
 	movl $(__BOOT_DS),%eax
@@ -287,7 +284,7 @@ ENTRY(startup_32_smp)
 	movl pa(stack_start),%ecx
 	movl %eax,%ss
 	leal -__PAGE_OFFSET(%ecx),%esp
-#endif /* CONFIG_SMP */
+
 default_entry:
 
 /*
arch/x86/kernel/head_64.S +0 -4
index 40f4eb3..d70bc2e 100644
@@ -136,10 +136,6 @@ ident_complete:
 	/* Fixup phys_base */
 	addq	%rbp, phys_base(%rip)
 
-	/* Fixup trampoline */
-	addq	%rbp, trampoline_level4_pgt + 0(%rip)
-	addq	%rbp, trampoline_level4_pgt + (511*8)(%rip)
-
 	/* Due to ENTRY(), sometimes the empty space gets filled with
 	 * zeros. Better take a jmp than relying on empty space being
 	 * filled with 0x90 (nop)
arch/x86/kernel/mpparse.c +0 -1
index ca470e4..f44d311 100644
@@ -27,7 +27,6 @@
 #include <asm/proto.h>
 #include <asm/bios_ebda.h>
 #include <asm/e820.h>
-#include <asm/trampoline.h>
 #include <asm/setup.h>
 #include <asm/smp.h>
 
arch/x86/kernel/reboot.c +3 -22
index d840e69..658f856 100644
@@ -24,6 +24,7 @@
 #ifdef CONFIG_X86_32
 # include <linux/ctype.h>
 # include <linux/mc146818rtc.h>
+# include <asm/realmode.h>
 #else
 # include <asm/x86_init.h>
 #endif
@@ -332,15 +333,10 @@ static int __init reboot_init(void)
 }
 core_initcall(reboot_init);
 
-extern const unsigned char machine_real_restart_asm[];
-extern const u64 machine_real_restart_gdt[3];
-
 void machine_real_restart(unsigned int type)
 {
-	void *restart_va;
-	unsigned long restart_pa;
-	void (*restart_lowmem)(unsigned int);
-	u64 *lowmem_gdt;
+	void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
+		real_mode_header->machine_real_restart_asm;
 
 	local_irq_disable();
 
@@ -369,21 +365,6 @@ void machine_real_restart(unsigned int type)
 	   too. */
 	*((unsigned short *)0x472) = reboot_mode;
 
-	/* Patch the GDT in the low memory trampoline */
-	lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
-
-	restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
-	restart_pa = virt_to_phys(restart_va);
-	restart_lowmem = (void (*)(unsigned int))restart_pa;
-
-	/* GDT[0]: GDT self-pointer */
-	lowmem_gdt[0] =
-		(u64)(sizeof(machine_real_restart_gdt) - 1) +
-		((u64)virt_to_phys(lowmem_gdt) << 16);
-	/* GDT[1]: 64K real mode code segment */
-	lowmem_gdt[1] =
-		GDT_ENTRY(0x009b, restart_pa, 0xffff);
-
 	/* Jump to the identity-mapped low memory code */
 	restart_lowmem(type);
 }
arch/x86/kernel/setup.c +4 -2
index 1a29015..efcf305 100644
@@ -73,7 +73,7 @@
 
 #include <asm/mtrr.h>
 #include <asm/apic.h>
-#include <asm/trampoline.h>
+#include <asm/realmode.h>
 #include <asm/e820.h>
 #include <asm/mpspec.h>
 #include <asm/setup.h>
@@ -917,7 +917,7 @@ void __init setup_arch(char **cmdline_p)
 	printk(KERN_DEBUG "initial memory mapped : 0 - %08lx\n",
 			max_pfn_mapped<<PAGE_SHIFT);
 
-	setup_trampolines();
+	setup_real_mode();
 
 	init_gbpages();
 
@@ -975,6 +975,8 @@ void __init setup_arch(char **cmdline_p)
 	if (boot_cpu_data.cpuid_level >= 0) {
 		/* A CPU has %cr4 if and only if it has CPUID */
 		mmu_cr4_features = read_cr4();
+		if (trampoline_cr4_features)
+			*trampoline_cr4_features = mmu_cr4_features;
 	}
 
 #ifdef CONFIG_X86_32
arch/x86/kernel/smpboot.c +10 -8
index 6e1e406..757c4b1 100644
@@ -57,7 +57,7 @@
 #include <asm/nmi.h>
 #include <asm/irq.h>
 #include <asm/idle.h>
-#include <asm/trampoline.h>
+#include <asm/realmode.h>
 #include <asm/cpu.h>
 #include <asm/numa.h>
 #include <asm/pgtable.h>
@@ -73,6 +73,8 @@
 #include <asm/smpboot_hooks.h>
 #include <asm/i8259.h>
 
+#include <asm/realmode.h>
+
 /* State of each CPU */
 DEFINE_PER_CPU(int, cpu_state) = { 0 };
 
@@ -662,8 +664,12 @@ static void __cpuinit announce_cpu(int cpu, int apicid)
  */
 static int __cpuinit do_boot_cpu(int apicid, int cpu)
 {
+	volatile u32 *trampoline_status =
+		(volatile u32 *) __va(real_mode_header->trampoline_status);
+	/* start_ip had better be page-aligned! */
+	unsigned long start_ip = real_mode_header->trampoline_start;
+
 	unsigned long boot_error = 0;
-	unsigned long start_ip;
 	int timeout;
 	struct create_idle c_idle = {
 		.cpu	= cpu,
@@ -713,9 +719,6 @@ do_rest:
 	initial_code = (unsigned long)start_secondary;
 	stack_start  = c_idle.idle->thread.sp;
 
-	/* start_ip had better be page-aligned! */
-	start_ip = trampoline_address();
-
 	/* So we see what's up */
 	announce_cpu(cpu, apicid);
 
@@ -778,8 +781,7 @@ do_rest:
 			pr_debug("CPU%d: has booted.\n", cpu);
 		} else {
 			boot_error = 1;
-			if (*(volatile u32 *)TRAMPOLINE_SYM(trampoline_status)
-			    == 0xA5A5A5A5)
+			if (*trampoline_status == 0xA5A5A5A5)
 				/* trampoline started but...? */
 				pr_err("CPU%d: Stuck ??\n", cpu);
 			else
@@ -805,7 +807,7 @@ do_rest:
 	}
 
 	/* mark "stuck" area as not stuck */
-	*(volatile u32 *)TRAMPOLINE_SYM(trampoline_status) = 0;
+	*trampoline_status = 0;
 
 	if (get_uv_system_type() != UV_NON_UNIQUE_APIC) {
 		/*
arch/x86/kernel/tboot.c +4 -3
index 6410744..f84fe00 100644
@@ -32,7 +32,7 @@
 #include <linux/mm.h>
 #include <linux/tboot.h>
 
-#include <asm/trampoline.h>
+#include <asm/realmode.h>
 #include <asm/processor.h>
 #include <asm/bootparam.h>
 #include <asm/pgtable.h>
@@ -44,7 +44,7 @@
 #include <asm/e820.h>
 #include <asm/io.h>
 
-#include "acpi/realmode/wakeup.h"
+#include "../realmode/rm/wakeup.h"
 
 /* Global pointer to shared data; NULL means no measured launch. */
 struct tboot *tboot __read_mostly;
@@ -201,7 +201,8 @@ static int tboot_setup_sleep(void)
 		add_mac_region(e820.map[i].addr, e820.map[i].size);
 	}
 
-	tboot->acpi_sinfo.kernel_s3_resume_vector = acpi_wakeup_address;
+	tboot->acpi_sinfo.kernel_s3_resume_vector =
+		real_mode_header->wakeup_start;
 
 	return 0;
 }
arch/x86/kernel/trampoline.c deleted +0 -42

42 lines not on this page · raw message

arch/x86/kernel/trampoline_32.S deleted +0 -83

83 lines not on this page · raw message

arch/x86/kernel/vmlinux.lds.S +0 -12
index 0f703f1..22a1530 100644
@@ -197,18 +197,6 @@ SECTIONS
 
 	INIT_DATA_SECTION(16)
 
-	/*
-	 * Code and data for a variety of lowlevel trampolines, to be
-	 * copied into base memory (< 1 MiB) during initialization.
-	 * Since it is copied early, the main copy can be discarded
-	 * afterwards.
-	 */
-	 .x86_trampoline : AT(ADDR(.x86_trampoline) - LOAD_OFFSET) {
-		x86_trampoline_start = .;
-		*(.x86_trampoline)
-		x86_trampoline_end = .;
-	}
-
 	.x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
 		__x86_cpu_dev_start = .;
 		*(.x86_cpu_dev.init)
arch/x86/realmode/Makefile new file +18 -0
new file mode 100644
index 0000000..94f7fbe
@@ -0,0 +1,18 @@
+#
+# arch/x86/realmode/Makefile
+#
+# This file is subject to the terms and conditions of the GNU General Public
+# License.  See the file "COPYING" in the main directory of this archive
+# for more details.
+#
+#
+
+subdir- := rm
+
+obj-y += init.o
+obj-y += rmpiggy.o
+
+$(obj)/rmpiggy.o: $(obj)/rm/realmode.bin
+
+$(obj)/rm/realmode.bin: FORCE
+	$(Q)$(MAKE) $(build)=$(obj)/rm $@
arch/x86/realmode/init.c new file +115 -0

115 lines not on this page · raw message

arch/x86/realmode/rm/.gitignore new file +3 -0
new file mode 100644
index 0000000..b6ed3a2
@@ -0,0 +1,3 @@
+pasyms.h
+realmode.lds
+realmode.relocs
arch/x86/realmode/rm/Makefile new file +82 -0

82 lines not on this page · raw message

arch/x86/realmode/rm/bioscall.S new file +1 -0
new file mode 100644
index 0000000..16162d1
@@ -0,0 +1 @@
+#include "../../boot/bioscall.S"
arch/x86/realmode/rm/copy.S new file +1 -0
new file mode 100644
index 0000000..b785e6f
@@ -0,0 +1 @@
+#include "../../boot/copy.S"
arch/x86/realmode/rm/header.S new file +41 -0

41 lines not on this page · raw message

arch/x86/realmode/rm/realmode.h new file +21 -0
new file mode 100644
index 0000000..d74cff6
@@ -0,0 +1,21 @@
+#ifndef ARCH_X86_REALMODE_RM_REALMODE_H
+#define ARCH_X86_REALMODE_RM_REALMODE_H
+
+#ifdef __ASSEMBLY__
+
+/*
+ * 16-bit ljmpw to the real_mode_seg
+ *
+ * This must be open-coded since gas will choke on using a
+ * relocatable symbol for the segment portion.
+ */
+#define LJMPW_RM(to)	.byte 0xea ; .word (to), real_mode_seg
+
+#endif /* __ASSEMBLY__ */
+
+/*
+ * Signature at the end of the realmode region
+ */
+#define REALMODE_END_SIGNATURE	0x65a22c82
+
+#endif /* ARCH_X86_REALMODE_RM_REALMODE_H */
arch/x86/realmode/rm/realmode.lds.S new file +76 -0

76 lines not on this page · raw message

arch/x86/realmode/rm/reboot_32.S renamed from arch/x86/kernel/reboot_32.S +43 -46

143 lines not on this page · raw message

arch/x86/realmode/rm/regs.c new file +1 -0
new file mode 100644
index 0000000..fbb15b9
@@ -0,0 +1 @@
+#include "../../boot/regs.c"
arch/x86/realmode/rm/stack.S new file +19 -0
new file mode 100644
index 0000000..867ae87
@@ -0,0 +1,19 @@
+/*
+ * Common heap and stack allocations
+ */
+
+#include <linux/linkage.h>
+
+	.data
+GLOBAL(HEAP)
+	.long	rm_heap
+GLOBAL(heap_end)
+	.long	rm_stack
+
+	.bss
+	.balign	16
+GLOBAL(rm_heap)
+	.space	2048
+GLOBAL(rm_stack)
+	.space	2048
+GLOBAL(rm_stack_end)
arch/x86/realmode/rm/trampoline_32.S new file +74 -0

74 lines not on this page · raw message

arch/x86/realmode/rm/trampoline_64.S renamed from arch/x86/kernel/trampoline_64.S +65 -83

215 lines not on this page · raw message

arch/x86/realmode/rm/trampoline_common.S new file +7 -0
new file mode 100644
index 0000000..b1ecdb9
@@ -0,0 +1,7 @@
+	.section ".rodata","a"
+	.balign	16
+tr_idt: .fill 1, 6, 0
+
+	.bss
+	.balign	4
+GLOBAL(trampoline_status)	.space	4
arch/x86/realmode/rm/video-bios.c new file +1 -0
new file mode 100644
index 0000000..848b25a
@@ -0,0 +1 @@
+#include "../../boot/video-bios.c"
arch/x86/realmode/rm/video-mode.c new file +1 -0
new file mode 100644
index 0000000..2a98b7e
@@ -0,0 +1 @@
+#include "../../boot/video-mode.c"
arch/x86/realmode/rm/video-vesa.c new file +1 -0
new file mode 100644
index 0000000..413eddd
@@ -0,0 +1 @@
+#include "../../boot/video-vesa.c"
arch/x86/realmode/rm/video-vga.c new file +1 -0
new file mode 100644
index 0000000..3085f5c
@@ -0,0 +1 @@
+#include "../../boot/video-vga.c"
arch/x86/realmode/rm/wakemain.c renamed from arch/x86/kernel/acpi/realmode/wakemain.c +2 -1
similarity index 98%
rename from arch/x86/kernel/acpi/realmode/wakemain.c
rename to arch/x86/realmode/rm/wakemain.c
index 883962d..91405d5 100644
@@ -65,7 +65,8 @@ void main(void)
 {
 	/* Kill machine if structures are wrong */
 	if (wakeup_header.real_magic != 0x12345678)
-		while (1);
+		while (1)
+			;
 
 	if (wakeup_header.realmode_flags & 4)
 		send_morse("...-");
arch/x86/realmode/rm/wakeup.h renamed from arch/x86/kernel/acpi/realmode/wakeup.h +1 -9
similarity index 79%
rename from arch/x86/kernel/acpi/realmode/wakeup.h
rename to arch/x86/realmode/rm/wakeup.h
index 97a29e1..9317e00 100644
@@ -12,9 +12,8 @@
 /* This must match data at wakeup.S */
 struct wakeup_header {
 	u16 video_mode;		/* Video mode number */
-	u16 _jmp1;		/* ljmpl opcode, 32-bit only */
 	u32 pmode_entry;	/* Protected mode resume point, 32-bit only */
-	u16 _jmp2;		/* CS value, 32-bit only */
+	u16 pmode_cs;
 	u32 pmode_cr0;		/* Protected mode cr0 */
 	u32 pmode_cr3;		/* Protected mode cr3 */
 	u32 pmode_cr4;		/* Protected mode cr4 */
@@ -26,12 +25,6 @@ struct wakeup_header {
 	u32 pmode_behavior;	/* Wakeup routine behavior flags */
 	u32 realmode_flags;
 	u32 real_magic;
-	u16 trampoline_segment;	/* segment with trampoline code, 64-bit only */
-	u8  _pad1;
-	u8  wakeup_jmp;
-	u16 wakeup_jmp_off;
-	u16 wakeup_jmp_seg;
-	u64 wakeup_gdt[3];
 	u32 signature;		/* To check we have correct structure */
 } __attribute__((__packed__));
 
@@ -40,7 +33,6 @@ extern struct wakeup_header wakeup_header;
 
 #define WAKEUP_HEADER_OFFSET	8
 #define WAKEUP_HEADER_SIGNATURE 0x51ee1111
-#define WAKEUP_END_SIGNATURE	0x65a22c82
 
 /* Wakeup behavior bits */
 #define WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE     0
arch/x86/realmode/rm/wakeup_asm.S renamed from arch/x86/kernel/acpi/realmode/wakeup.S +69 -62

192 lines not on this page · raw message

arch/x86/realmode/rmpiggy.S new file +20 -0
new file mode 100644
index 0000000..204c6ec
@@ -0,0 +1,20 @@
+/*
+ * Wrapper script for the realmode binary as a transport object
+ * before copying to low memory.
+ */
+#include <linux/linkage.h>
+#include <asm/page_types.h>
+
+	.section ".init.data","aw"
+
+	.balign PAGE_SIZE
+
+GLOBAL(real_mode_blob)
+	.incbin	"arch/x86/realmode/rm/realmode.bin"
+END(real_mode_blob)
+
+GLOBAL(real_mode_blob_end);
+
+GLOBAL(real_mode_relocs)
+	.incbin	"arch/x86/realmode/rm/realmode.relocs"
+END(real_mode_relocs)
arch/x86/tools/relocs.c +7 -0
index b685296..5a1847d 100644
@@ -78,6 +78,13 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {
 
 static const char * const sym_regex_realmode[S_NSYMTYPES] = {
 /*
+ * These symbols are known to be relative, even if the linker marks them
+ * as absolute (typically defined outside any section in the linker script.)
+ */
+	[S_REL] =
+	"^pa_",
+
+/*
  * These are 16-bit segment symbols when compiling 16-bit code.
  */
 	[S_SEG] =
drivers/acpi/bgrt.c +1 -0
index 8cf6c46..6680df3 100644
@@ -11,6 +11,7 @@
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/sysfs.h>
+#include <linux/io.h>
 #include <acpi/acpi.h>
 #include <acpi/acpi_bus.h>
 
drivers/acpi/sleep.c +5 -3
index eb6fd23..0613900 100644
@@ -25,6 +25,8 @@
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
 
+#include <asm/realmode.h>
+
 #include "internal.h"
 #include "sleep.h"
 
@@ -91,13 +93,13 @@ static struct notifier_block tts_notifier = {
 static int acpi_sleep_prepare(u32 acpi_state)
 {
 #ifdef CONFIG_ACPI_SLEEP
+	unsigned long wakeup_pa = real_mode_header->wakeup_start;
 	/* do we have a wakeup address for S2 and S3? */
 	if (acpi_state == ACPI_STATE_S3) {
-		if (!acpi_wakeup_address) {
+		if (!wakeup_pa)
 			return -EFAULT;
-		}
 		acpi_set_firmware_waking_vector(
-				(acpi_physical_address)acpi_wakeup_address);
+				(acpi_physical_address)wakeup_pa);
 
 	}
 	ACPI_FLUSH_CPU_CACHE();
drivers/xen/xen-acpi-processor.c +1 -0
index 0b48579..7ff2569 100644
@@ -29,6 +29,7 @@
 #include <acpi/acpi_drivers.h>
 #include <acpi/processor.h>
 
+#include <xen/xen.h>
 #include <xen/interface/platform.h>
 #include <asm/xen/hypercall.h>
 
#1 lore raw
Quoted 5 lines · H. Peter Anvin

The rework of relocs.c is already in upstream.  I know you don't like lambda merges, but I did one for this branch, because I found that without it git will silently mismerge relocs.c between your tree and this branch; with the lambda merge in place it merges correctly.

So as far as I can tell, the merge does nothing useful. I merged both with and without your merge, and either way the result is dubious.

The reason I call it dubious is that when I do the merge by hand, it's ambigiuous what the resolution should be (but I have an opinion on what the correct thing likely is), and if I take yours that "resolves" the ambiguous case, but not in the way you then claim in this email.

Quoted 4 lines

If you prefer to do this manually, you can instead pull 61f5446169046c217a5479517edac3a890c3bee7; however, make sure that arch/x86/tools/relocs.c ends up being the one from your current upstream tree.

Both your merge, *and* mine end up having a simple issue: your original import of that file happened separately two different times, and they don't agree.

In particular, the two branches disagree about what the sym_regex_realmode[S_NSYMTYPES] array should look like. In my previous head (and the one you claim is the right one), it has just two patterns:

/*
* These are 16-bit segment symbols when compiling 16-bit code. */

        [S_SEG] =
        "^real_mode_seg$",

/*
* These are offsets belonging to segments, as opposed to linear addresses,
* when compiling 16-bit code.
*/

        [S_LIN] =
        "^pa_",

but in your branch that "^pa_" pattern is duplicated for S_REL:

/*
* These symbols are known to be relative, even if the linker marks them
* as absolute (typically defined outside any section in the linker script.) */

        [S_REL] =
        "^pa_",

/*
* These are 16-bit segment symbols when compiling 16-bit code. */

        [S_SEG] =
        "^real_mode_seg$",

/*
* These are offsets belonging to segments, as opposed to linear addresses,
* when compiling 16-bit code.
*/

        [S_LIN] =
        "^pa_",

which looks odd.

But that case with three patterns is the one you selected in your merge - *not* the current state of relocs.c that you claim should be selected.

So I'm not pulling or merging anything until I understand what's going on. Should I take the two-pattern one (which is what I have now, and that seems sensible), or should that "^pa_" pattern really be merged for two different cases (doesn't that just mean that the last one will effectively override the first one)?

Also, your branch adds an "x86-relocs" thing to the scripts/.gitignore file that you seem to have removed in the merge. What was going on there?

Linus

#2 lore raw
Quoted 20 lines · Linus Torvalds

but in your branch that "^pa_" pattern is duplicated for S_REL:

/*
* These symbols are known to be relative, even if the linker marks them
* as absolute (typically defined outside any section in the linker script.) */

        [S_REL] =
        "^pa_",

/*
* These are 16-bit segment symbols when compiling 16-bit code. */

        [S_SEG] =
        "^real_mode_seg$",

/*
* These are offsets belonging to segments, as opposed to linear addresses,
* when compiling 16-bit code.
*/

Quoted 9 lines
        [S_LIN] =
        "^pa_",

which looks odd.

But that case with three patterns is the one you selected in your merge - *not* the current state of relocs.c that you claim should be selected.

Sorry, you're right. The version with three patterns is correct. The "^pa_" patterns are linear addresses which should be treated as relative, and so belong both to S_REL and S_LIN. This didn't surface as a conflict, so I forgot to flag it.

Quoted 9 lines

So I'm not pulling or merging anything until I understand what's going on. Should I take the two-pattern one (which is what I have now, and that seems sensible), or should that "^pa_" pattern really be merged for two different cases (doesn't that just mean that the last one will effectively override the first one)?

Also, your branch adds an "x86-relocs" thing to the scripts/.gitignore file that you seem to have removed in the merge. What was going on there?

That line should have been removed in checkin f2604c14 but wasn't; since that was one of the checkins that got folded up into 6520fe55 I cleaned it up at that time.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#3 lore raw
Quoted 2 lines · H. Peter Anvin

Sorry, you're right.  The version with three patterns is correct.

Ok. So I pushed out my merge with that. I think that with the x86-relocs thing in scripts/.gitignore it then ends up being the same as yours.

I didn't see any git silent mis-merges, though. The fact that that relocs.c file had come in two different ways did make for a more interesting merge, since it didn't have any common ancestry - just two different original versions. But git seemed to do the right thing, and marked where they differed.

Linus

#4 lore raw
Quoted 7 lines · Linus Torvalds

I didn't see any git silent mis-merges, though. The fact that that relocs.c file had come in two different ways did make for a more interesting merge, since it didn't have any common ancestry - just two different original versions. But git seemed to do the right thing, and marked where they differed.

I don't know why, but when I did a test merge of my original branch into top of your tree, it silently merged everything (no markings) but incorrectly.

Perhaps it is a git version-specific thing.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.