linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Jarkko Sakkinen <jarkko.sakkinen@intel.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org,
	jarkko.sakkinen@intel.com, tglx@linutronix.de,
	hpa@linux.intel.com
Subject: [tip:x86/trampoline] x86, realmode: header for trampoline code
Date: Tue, 8 May 2012 15:29:58 -0700	[thread overview]
Message-ID: <tip-f37240f16bec91f15ce564515f70a6ca9715ce96@git.kernel.org> (raw)
In-Reply-To: <1336501366-28617-21-git-send-email-jarkko.sakkinen@intel.com>

Commit-ID:  f37240f16bec91f15ce564515f70a6ca9715ce96
Gitweb:     http://git.kernel.org/tip/f37240f16bec91f15ce564515f70a6ca9715ce96
Author:     Jarkko Sakkinen <jarkko.sakkinen@intel.com>
AuthorDate: Tue, 8 May 2012 21:22:43 +0300
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Tue, 8 May 2012 11:48:45 -0700

x86, realmode: header for trampoline code

Added header for trampoline code that can be used to supply
input data to it. This makes interface between real mode code
and kernel cleaner and simpler. Replaced two confusing pointers
to level4 pgt in trampoline_64.S with a single pointer to the
beginning of the page table.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@intel.com>
Link: http://lkml.kernel.org/r/1336501366-28617-21-git-send-email-jarkko.sakkinen@intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/include/asm/realmode.h          |   32 ++++++++++++++++----------
 arch/x86/kernel/realmode.c               |   27 ++++++++++++----------
 arch/x86/kernel/smpboot.c                |    2 +-
 arch/x86/realmode/rm/header.S            |   35 +++++++++++++---------------
 arch/x86/realmode/rm/trampoline_32.S     |   36 +++++-------------------------
 arch/x86/realmode/rm/trampoline_64.S     |   18 ++++----------
 arch/x86/realmode/rm/trampoline_common.S |   23 +++++++++++++++++++
 arch/x86/realmode/rm/wakeup_asm.S        |    2 +-
 8 files changed, 87 insertions(+), 88 deletions(-)

diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
index d3ae49f..1421eed 100644
--- a/arch/x86/include/asm/realmode.h
+++ b/arch/x86/include/asm/realmode.h
@@ -8,25 +8,33 @@
 struct real_mode_header {
 	u32	text_start;
 	u32	ro_end;
-	/* reboot */
-#ifdef CONFIG_X86_32
-	u32	machine_real_restart_asm;
-#endif
 	/* SMP trampoline */
-	u32	trampoline_data;
+	u32	trampoline_start;
 	u32	trampoline_status;
-#ifdef CONFIG_X86_32
-	u32	startup_32_smp;
-	u32	boot_gdt;
-#else
-	u32	startup_64_smp;
-	u32	level3_ident_pgt;
-	u32	level3_kernel_pgt;
+	u32	trampoline_header;
+#ifdef CONFIG_X86_64
+	u32	trampoline_pgd;
 #endif
+	/* ACPI S3 wakeup */
 #ifdef CONFIG_ACPI_SLEEP
 	u32	wakeup_start;
 	u32	wakeup_header;
 #endif
+	/* APM/BIOS reboot */
+#ifdef CONFIG_X86_32
+	u32	machine_real_restart_asm;
+#endif
+} __attribute__((__packed__));
+
+/* This must match data at trampoline_32/64.S */
+struct trampoline_header {
+#ifdef CONFIG_X86_32
+	u32 start;
+	u16 gdt_limit;
+	u32 gdt_base;
+#else
+	u64 start;
+#endif
 } __attribute__((__packed__));
 
 extern struct real_mode_header *real_mode_header;
diff --git a/arch/x86/kernel/realmode.c b/arch/x86/kernel/realmode.c
index 632c810..712fba8 100644
--- a/arch/x86/kernel/realmode.c
+++ b/arch/x86/kernel/realmode.c
@@ -17,8 +17,11 @@ void __init setup_real_mode(void)
 	u16 *seg;
 	int i;
 	unsigned char *base;
-
+	struct trampoline_header *trampoline_header;
 	size_t size = PAGE_ALIGN(real_mode_blob_end - real_mode_blob);
+#ifdef CONFIG_X86_64
+	u64 *trampoline_pgd;
+#endif
 
 	/* Has to be in very low memory so we can execute real-mode AP code. */
 	mem = memblock_find_in_range(0, 1<<20, size, PAGE_SIZE);
@@ -28,7 +31,6 @@ void __init setup_real_mode(void)
 	base = __va(mem);
 	memblock_reserve(mem, size);
 	real_mode_header = (struct real_mode_header *) base;
-
 	printk(KERN_DEBUG "Base memory trampoline at [%p] %llx size %zu\n",
 	       base, (unsigned long long)mem, size);
 
@@ -53,18 +55,19 @@ void __init setup_real_mode(void)
 		*ptr += __pa(base);
 	}
 
+	/* Must be perfomed *after* relocation. */
+	trampoline_header = (struct trampoline_header *)
+		__va(real_mode_header->trampoline_header);
+
 #ifdef CONFIG_X86_32
-	*((u32 *)__va(real_mode_header->startup_32_smp)) = __pa(startup_32_smp);
-	*((u32 *)__va(real_mode_header->boot_gdt)) = __pa(boot_gdt);
+	trampoline_header->start = __pa(startup_32_smp);
+	trampoline_header->gdt_limit = __BOOT_DS + 7;
+	trampoline_header->gdt_base = __pa(boot_gdt);
 #else
-	*((u64 *) __va(real_mode_header->startup_64_smp)) =
-		(u64)secondary_startup_64;
-
-	*((u64 *) __va(real_mode_header->level3_ident_pgt)) =
-		__pa(level3_ident_pgt) + _KERNPG_TABLE;
-
-	*((u64 *) __va(real_mode_header->level3_kernel_pgt)) =
-		__pa(level3_kernel_pgt) + _KERNPG_TABLE;
+	trampoline_header->start = (u64) secondary_startup_64;
+	trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
+	trampoline_pgd[0] = __pa(level3_ident_pgt) + _KERNPG_TABLE;
+	trampoline_pgd[511] = __pa(level3_kernel_pgt) + _KERNPG_TABLE;
 #endif
 }
 
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index b8c0661..757c4b1 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -667,7 +667,7 @@ 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_data;
+	unsigned long start_ip = real_mode_header->trampoline_start;
 
 	unsigned long boot_error = 0;
 	int timeout;
diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
index c83005c..b4c3263 100644
--- a/arch/x86/realmode/rm/header.S
+++ b/arch/x86/realmode/rm/header.S
@@ -7,28 +7,25 @@
 #include <linux/linkage.h>
 #include <asm/page_types.h>
 
-		.section ".header", "a"
+	.section ".header", "a"
 
 GLOBAL(real_mode_header)
-		.long	pa_text_start
-		.long	pa_ro_end
-#ifdef CONFIG_X86_32
-		.long	pa_machine_real_restart_asm
-#endif
-		/* SMP trampoline */
-		.long	pa_trampoline_data
-		.long	pa_trampoline_status
-#ifdef CONFIG_X86_32
-		.long	pa_startup_32_smp
-		.long	pa_boot_gdt
-#else
-		.long	pa_startup_64_smp
-		.long	pa_level3_ident_pgt
-		.long	pa_level3_kernel_pgt
+	.long	pa_text_start
+	.long	pa_ro_end
+	/* SMP trampoline */
+	.long	pa_trampoline_start
+	.long	pa_trampoline_status
+	.long	pa_trampoline_header
+#ifdef CONFIG_X86_64
+	.long	pa_trampoline_pgd;
 #endif
-		/* ACPI sleep */
+	/* ACPI S3 wakeup */
 #ifdef CONFIG_ACPI_SLEEP
-		.long	pa_wakeup_start
-		.long	pa_wakeup_header
+	.long	pa_wakeup_start
+	.long	pa_wakeup_header
+#endif
+	/* APM/BIOS reboot */
+#ifdef CONFIG_X86_32
+	.long	pa_machine_real_restart_asm
 #endif
 END(real_mode_header)
diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
index 1ecdbb5..6fc064b 100644
--- a/arch/x86/realmode/rm/trampoline_32.S
+++ b/arch/x86/realmode/rm/trampoline_32.S
@@ -13,16 +13,10 @@
  *
  *	We jump into arch/x86/kernel/head_32.S.
  *
- *	On entry to trampoline_data, the processor is in real mode
+ *	On entry to trampoline_start, the processor is in real mode
  *	with 16-bit addressing and 16-bit data.  CS has some value
  *	and IP is zero.  Thus, we load CS to the physical segment
  *	of the real mode code before doing anything further.
- *
- *	The structure real_mode_header includes entries that need
- *	to be set up before executing this code:
- *
- *	startup_32_smp
- *	boot_gdt
  */
 
 #include <linux/linkage.h>
@@ -35,7 +29,7 @@
 	.code16
 
 	.balign	PAGE_SIZE
-ENTRY(trampoline_data)
+ENTRY(trampoline_start)
 	wbinvd			# Needed for NUMA-Q should be harmless for others
 
 	LJMPW_RM(1f)
@@ -45,7 +39,7 @@ ENTRY(trampoline_data)
 
 	cli			# We should be safe anyway
 
-	movl	startup_32_smp, %eax	# where we need to go
+	movl	tr_start, %eax	# where we need to go
 
 	movl	$0xA5A5A5A5, trampoline_status
 				# write marker for master knows we're running
@@ -56,8 +50,8 @@ ENTRY(trampoline_data)
 	 * operand size is 16bit. Use lgdtl instead to force operand size
 	 * to 32 bit.
 	 */
-	lidtl	boot_idt_descr		# load idt with 0, 0
-	lgdtl	boot_gdt_descr		# load gdt with whatever is appropriate
+	lidtl	tr_idt			# load idt with 0, 0
+	lgdtl	tr_gdt			# load gdt with whatever is appropriate
 
 	movw	$1, %dx			# protected mode (PE) bit
 	lmsw	%dx			# into protected mode
@@ -69,22 +63,4 @@ ENTRY(trampoline_data)
 ENTRY(startup_32)			# note: also used from wakeup_asm.S
 	jmp	*%eax
 
-	.section ".rodata","a"
-
-	.balign	4
-boot_idt_descr:
-	.word	0				# idt limit = 0
-	.long	0				# idt base = 0L
-
-	.data
-
-boot_gdt_descr:
-	.word	__BOOT_DS + 7			# gdt limit
-GLOBAL(boot_gdt)
-	.long	0				# gdt base
-
-	.bss
-
-	.balign	4
-GLOBAL(trampoline_status)	.space	4
-GLOBAL(startup_32_smp)		.space	4
+#include "trampoline_common.S"
diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
index f71ea08..3f72932 100644
--- a/arch/x86/realmode/rm/trampoline_64.S
+++ b/arch/x86/realmode/rm/trampoline_64.S
@@ -10,7 +10,7 @@
  *	trampoline page to make our stack and everything else
  *	is a mystery.
  *
- *	On entry to trampoline_data, the processor is in real mode
+ *	On entry to trampoline_start, the processor is in real mode
  *	with 16-bit addressing and 16-bit data.  CS has some value
  *	and IP is zero.  Thus, data addresses need to be absolute
  *	(no relocation) and are taken with regard to r_base.
@@ -37,7 +37,7 @@
 	.balign PAGE_SIZE
 	.code16
 
-ENTRY(trampoline_data)
+ENTRY(trampoline_start)
 	cli			# We should be safe anyway
 	wbinvd
 
@@ -97,7 +97,7 @@ ENTRY(startup_32)
 	movl	%eax, %cr4		# Enable PAE mode
 
 	# Setup trampoline 4 level pagetables
-	movl	$pa_level3_ident_pgt, %eax
+	movl	$pa_trampoline_pgd, %eax
 	movl	%eax, %cr3
 
 	movl	$MSR_EFER, %ecx
@@ -122,7 +122,7 @@ ENTRY(startup_32)
 	.balign 4
 ENTRY(startup_64)
 	# Now jump into the kernel using virtual addresses
-	jmpq	*startup_64_smp(%rip)
+	jmpq	*tr_start(%rip)
 
 	.section ".rodata","a"
 	.balign	16
@@ -143,12 +143,4 @@ tgdt:
 	.quad	0x00cf93000000ffff	# __KERNEL_DS
 tgdt_end:
 
-	.bss
-
-	.balign	PAGE_SIZE
-GLOBAL(level3_ident_pgt)	.space	511*8
-GLOBAL(level3_kernel_pgt)	.space	8
-
-	.balign	8
-GLOBAL(startup_64_smp)		.space	8
-GLOBAL(trampoline_status)	.space	4
+#include "trampoline_common.S"
diff --git a/arch/x86/realmode/rm/trampoline_common.S b/arch/x86/realmode/rm/trampoline_common.S
new file mode 100644
index 0000000..c3f951c
--- /dev/null
+++ b/arch/x86/realmode/rm/trampoline_common.S
@@ -0,0 +1,23 @@
+	.section ".rodata","a"
+
+	.balign	4
+tr_idt: .fill 1, 6, 0
+
+	.bss
+
+	.balign	4
+GLOBAL(trampoline_status)	.space	4
+
+GLOBAL(trampoline_header)
+#ifdef CONFIG_X86_32
+	tr_start:		.space	4
+	tr_gdt:			.space	6
+#else
+	tr_start:		.space	8
+#endif
+END(trampoline_header)
+
+#ifdef CONFIG_X86_64
+	.balign	PAGE_SIZE
+GLOBAL(trampoline_pgd)		.space	PAGE_SIZE
+#endif
diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
index 8a57c5a..46108f0 100644
--- a/arch/x86/realmode/rm/wakeup_asm.S
+++ b/arch/x86/realmode/rm/wakeup_asm.S
@@ -132,7 +132,7 @@ ENTRY(wakeup_start)
 	ljmpl	$__KERNEL_CS, $pa_startup_32
 	/* -> jmp *%eax in trampoline_32.S */
 #else
-	jmp	trampoline_data
+	jmp	trampoline_start
 #endif
 
 bogus_real_magic:

  reply	other threads:[~2012-05-08 22:30 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-08 18:22 [PATCH 00/23] x86, realmode: new infrastructure for realmode code Jarkko Sakkinen
2012-05-08 18:22 ` [PATCH 01/23] x86, realmode: 16-bit real-mode code support for relocs tool Jarkko Sakkinen
2012-05-08 22:13   ` [tip:x86/trampoline] " tip-bot for H. Peter Anvin
2012-05-08 18:22 ` [PATCH 02/23] x86, realmode: realmode.bin infrastructure Jarkko Sakkinen
2012-05-08 18:53   ` Sam Ravnborg
2012-05-08 19:14     ` H. Peter Anvin
2012-05-08 20:15       ` H. Peter Anvin
2012-05-08 21:11         ` Sam Ravnborg
2012-05-08 21:21           ` H. Peter Anvin
2012-05-08 22:14   ` [tip:x86/trampoline] " tip-bot for Jarkko Sakkinen
2012-05-09 15:49   ` [PATCH 02/23] " H. Peter Anvin
     [not found]     ` <alpine.DEB.2.02.1205092256240.31031@jsakkine-mobl1.(null)>
2012-05-09 20:06       ` H. Peter Anvin
2012-05-08 18:22 ` [PATCH 03/23] x86, realmode: Relocator for realmode code Jarkko Sakkinen
2012-05-08 22:15   ` [tip:x86/trampoline] " tip-bot for Jarkko Sakkinen
2012-05-08 18:22 ` [PATCH 04/23] x86, realmode: Move reboot_32.S to unified " Jarkko Sakkinen
2012-05-08 22:16   ` [tip:x86/trampoline] x86, realmode: Move reboot_32. S " tip-bot for Jarkko Sakkinen
2012-05-09  7:12   ` [PATCH 04/23] x86, realmode: Move reboot_32.S " Paolo Bonzini
     [not found]     ` <alpine.DEB.2.02.1205091525100.6943@jsakkine-mobl2.(null)>
2012-05-09 13:53       ` H. Peter Anvin
2012-05-09 14:15         ` Paolo Bonzini
2012-05-09 14:18           ` H. Peter Anvin
2012-05-08 18:22 ` [PATCH 05/23] x86, realmode: Move SMP trampoline " Jarkko Sakkinen
2012-05-08 22:17   ` [tip:x86/trampoline] " tip-bot for Jarkko Sakkinen
2012-05-08 18:22 ` [PATCH 06/23] x86, realmode: Move ACPI wakeup " Jarkko Sakkinen
2012-05-08 22:18   ` [tip:x86/trampoline] " tip-bot for Jarkko Sakkinen
2012-05-08 18:22 ` [PATCH 07/23] x86, realmode: Set permission for real mode pages Jarkko Sakkinen
2012-05-08 22:19   ` [tip:x86/trampoline] " tip-bot for Jarkko Sakkinen
2012-05-08 18:22 ` [PATCH 08/23] x86, realmode: Allow absolute pa_* symbols in the realmode code Jarkko Sakkinen
2012-05-08 22:19   ` [tip:x86/trampoline] " tip-bot for H. Peter Anvin
2012-05-08 18:22 ` [PATCH 09/23] x86, realmode: Add .text64 section, make barrier symbols absolute Jarkko Sakkinen
2012-05-08 22:20   ` [tip:x86/trampoline] " tip-bot for H. Peter Anvin
2012-05-08 18:22 ` [PATCH 10/23] x86, realmode: Move bits to the proper sections in trampoline_64.S Jarkko Sakkinen
2012-05-08 22:21   ` [tip:x86/trampoline] " tip-bot for H. Peter Anvin
2012-05-08 18:22 ` [PATCH 11/23] x86, realmode: Align .data section in trampoline_32.S Jarkko Sakkinen
2012-05-08 22:22   ` [tip:x86/trampoline] x86, realmode: Align . data " tip-bot for H. Peter Anvin
2012-05-08 18:22 ` [PATCH 12/23] x86, realmode: Remove indirect jumps in trampoline_64.S Jarkko Sakkinen
2012-05-08 22:23   ` [tip:x86/trampoline] " tip-bot for H. Peter Anvin
2012-05-08 18:22 ` [PATCH 13/23] x86, realmode: Remove indirect jumps in trampoline_32 and wakeup_asm Jarkko Sakkinen
2012-05-08 22:24   ` [tip:x86/trampoline] " tip-bot for H. Peter Anvin
2012-05-08 18:22 ` [PATCH 14/23] x86, realmode: Replace open-coded ljmpw with a macro Jarkko Sakkinen
2012-05-08 22:24   ` [tip:x86/trampoline] " tip-bot for H. Peter Anvin
2012-05-08 18:22 ` [PATCH 15/23] x86, realmode: Move trampoline_*.S early in the link order Jarkko Sakkinen
2012-05-08 22:25   ` [tip:x86/trampoline] x86, realmode: Move trampoline_*. S " tip-bot for H. Peter Anvin
2012-05-08 18:22 ` [PATCH 16/23] x86, realmode: Fix always-zero test in reboot_32.S Jarkko Sakkinen
2012-05-08 22:26   ` [tip:x86/trampoline] " tip-bot for H. Peter Anvin
2012-05-08 18:22 ` [PATCH 17/23] x86, realmode: fix 64-bit wakeup sequence Jarkko Sakkinen
2012-05-08 22:27   ` [tip:x86/trampoline] " tip-bot for Jarkko Sakkinen
2012-05-08 18:22 ` [PATCH 18/23] x86, realmode: don't copy real_mode_header Jarkko Sakkinen
2012-05-08 22:28   ` [tip:x86/trampoline] " tip-bot for Jarkko Sakkinen
2012-05-08 18:22 ` [PATCH 19/23] x86, realmode: flattened rm hierachy Jarkko Sakkinen
2012-05-08 22:29   ` [tip:x86/trampoline] " tip-bot for Jarkko Sakkinen
2012-05-08 18:22 ` [PATCH 20/23] x86, realmode: header for trampoline code Jarkko Sakkinen
2012-05-08 22:29   ` tip-bot for Jarkko Sakkinen [this message]
2012-05-08 18:22 ` [PATCH 21/23] x86, realmode: move relocs from scripts/ to arch/x86/tools Jarkko Sakkinen
2012-05-08 22:30   ` [tip:x86/trampoline] " tip-bot for Jarkko Sakkinen
2012-05-08 18:22 ` [PATCH 22/23] x86, realmode: fixes compilation issue in tboot.c Jarkko Sakkinen
2012-05-08 22:31   ` [tip:x86/trampoline] " tip-bot for Jarkko Sakkinen
2012-05-08 18:22 ` [PATCH 23/23] x86, realmode: read cr4 and EFER from kernel for 64-bit trampoline Jarkko Sakkinen
2012-05-08 22:32   ` [tip:x86/trampoline] " tip-bot for Jarkko Sakkinen
2012-05-16 20:37   ` [tip:x86/trampoline] x86, realmode: Mask out EFER. LMA when saving trampoline EFER tip-bot for H. Peter Anvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-f37240f16bec91f15ce564515f70a6ca9715ce96@git.kernel.org \
    --to=jarkko.sakkinen@intel.com \
    --cc=hpa@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).