public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@linux.intel.com>
To: linux-kernel@vger.kernel.org
Cc: vgoyal@redhat.com, hbabu@us.ibm.com, kexec@lists.infradead.org,
	ying.huang@intel.com, mingo@elte.hu, tglx@linutronix.de,
	ebiederm@xmission.com, sam@ravnborg.org,
	"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH 04/14] x86, boot: unify use LOAD_PHYSICAL_ADDR and LOAD_PHYSICAL_ALIGN
Date: Thu,  7 May 2009 15:26:52 -0700	[thread overview]
Message-ID: <1241735222-6640-5-git-send-email-hpa@linux.intel.com> (raw)
In-Reply-To: <1241735222-6640-1-git-send-email-hpa@linux.intel.com>

From: H. Peter Anvin <hpa@zytor.com>

Instead of using CONFIG_PHYSICAL_ALIGN and CONFIG_PHYSICAL_START
directly, use LOAD_PHYSICAL_ALIGN (CONFIG_PHYSICAL_ALIGN or the
smallest valid number, whichever is greater) and LOAD_PHYSICAL_ADDR
(CONFIG_PHYSICAL_START rounded up to the nearest alignment datum) for
both 32 and 64-bit mode.

[ Impact: Avoids problems in case of kernel misconfiguration ]

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/boot/compressed/head_32.S |    4 ++--
 arch/x86/boot/compressed/head_64.S |   21 +++++++++------------
 arch/x86/boot/header.S             |    2 +-
 arch/x86/include/asm/boot.h        |   13 +++++++++++--
 4 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
index 31fc6dc..2d7cd0f 100644
--- a/arch/x86/boot/compressed/head_32.S
+++ b/arch/x86/boot/compressed/head_32.S
@@ -70,8 +70,8 @@ ENTRY(startup_32)
 	jbe 1f
 	movl %eax, %ebx
 1:
-	addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebx
-	andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebx
+	addl $(LOAD_PHYSICAL_ALIGN - 1), %ebx
+	andl $(~(LOAD_PHYSICAL_ALIGN - 1)), %ebx
 #else
 	movl $LOAD_PHYSICAL_ADDR, %ebx
 #endif
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index f4ddd02..201af02 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -22,7 +22,6 @@
 #include <linux/linkage.h>
 #include <asm/segment.h>
 #include <asm/pgtable_types.h>
-#include <asm/page_types.h>
 #include <asm/boot.h>
 #include <asm/msr.h>
 #include <asm/processor-flags.h>
@@ -72,19 +71,17 @@ ENTRY(startup_32)
  * contains the address where we should move the kernel image temporarily
  * for safe in-place decompression.
  */
-ALIGN_MASK	= (CONFIG_PHYSICAL_ALIGN-1) | (PMD_PAGE_SIZE-1)
-
 #ifdef CONFIG_RELOCATABLE
-	movl	$CONFIG_PHYSICAL_START, %eax
+	movl	$LOAD_PHYSICAL_ADDR, %eax
 	movl	%ebp, %ebx
-	addl	$ALIGN_MASK, %ebx
-	andl	$~ALIGN_MASK, %ebx
+	addl	$(LOAD_PHYSICAL_ALIGN - 1), %ebx
+	andl	$~(LOAD_PHYSICAL_ALIGN - 1), %ebx
 	cmpl	%ebx, %eax
 	jbe	1f
 	movl	%eax, %ebx
 1:
 #else
-	movl	$CONFIG_PHYSICAL_START, %ebx
+	movl	$LOAD_PHYSICAL_ADDR, %ebx
 #endif
 
 	/* Replace the compressed data size with the uncompressed size */
@@ -216,21 +213,21 @@ ENTRY(startup_64)
 	 *
 	 * If it is a relocatable kernel then decompress and run the kernel
 	 * from load address aligned to 2MB addr, otherwise decompress and
-	 * run the kernel from CONFIG_PHYSICAL_START
+	 * run the kernel from LOAD_PHYSICAL_ADDR
 	 */
 
 	/* Start with the delta to where the kernel will run at. */
 #ifdef CONFIG_RELOCATABLE
 	leaq	startup_32(%rip) /* - $startup_32 */, %rbp
-	movq	$CONFIG_PHYSICAL_START, %rax
-	addq	$ALIGN_MASK, %rbp
-	andq	$~ALIGN_MASK, %rbp
+	movq	$LOAD_PHYSICAL_ADDR, %rax
+	addq	$(LOAD_PHYSICAL_ALIGN - 1), %rbp
+	andq	$~(LOAD_PHYSICAL_ALIGN - 1), %rbp
 	cmpq	%rbp, %rax
 	jbe	1f
 	movq	%rax, %rbp
 1:
 #else
-	movq	$CONFIG_PHYSICAL_START, %rbp
+	movq	$LOAD_PHYSICAL_ADDR, %rbp
 #endif
 	movq	%rbp, %rbx
 
diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
index 5d84d1c..cfd3bc4 100644
--- a/arch/x86/boot/header.S
+++ b/arch/x86/boot/header.S
@@ -192,7 +192,7 @@ ramdisk_max:	.long 0x7fffffff
 					# but leave it at 2 GB to avoid
 					# possible bootloader bugs.
 
-kernel_alignment:  .long CONFIG_PHYSICAL_ALIGN	#physical addr alignment
+kernel_alignment:  .long LOAD_PHYSICAL_ALIGN	#physical addr alignment
 						#required for protected mode
 						#kernel
 #ifdef CONFIG_RELOCATABLE
diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
index 6ba23dd..641debb 100644
--- a/arch/x86/include/asm/boot.h
+++ b/arch/x86/include/asm/boot.h
@@ -8,10 +8,19 @@
 
 #ifdef __KERNEL__
 
+#include <asm/page_types.h>
+
+/* Permitted physical alignment of the kernel */
+#if defined(CONFIG_X86_64) && CONFIG_PHYSICAL_ALIGN < PMD_PAGE_SIZE
+#define LOAD_PHYSICAL_ALIGN	PMD_PAGE_SIZE
+#else
+#define LOAD_PHYSICAL_ALIGN	CONFIG_PHYSICAL_ALIGN
+#endif
+
 /* Physical address where kernel should be loaded. */
 #define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
-				+ (CONFIG_PHYSICAL_ALIGN - 1)) \
-				& ~(CONFIG_PHYSICAL_ALIGN - 1))
+				+ (LOAD_PHYSICAL_ALIGN - 1)) \
+				& ~(LOAD_PHYSICAL_ALIGN - 1))
 
 #ifdef CONFIG_KERNEL_BZIP2
 #define BOOT_HEAP_SIZE             0x400000
-- 
1.6.0.6


  parent reply	other threads:[~2009-05-07 22:29 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-07 22:26 [PATCH 00/14] RFC: x86: relocatable kernel changes H. Peter Anvin
2009-05-07 22:26 ` [PATCH 01/14] x86, boot: align the .bss section in the decompressor H. Peter Anvin
2009-05-08  7:17   ` Sam Ravnborg
2009-05-08  8:18     ` Eric Dumazet
2009-05-08 16:54     ` H. Peter Anvin
2009-05-08  7:53   ` Cyrill Gorcunov
2009-05-08 17:03     ` H. Peter Anvin
2009-05-08 17:15       ` Cyrill Gorcunov
2009-05-08 17:21         ` H. Peter Anvin
2009-05-07 22:26 ` [PATCH 02/14] x86, boot: honor CONFIG_PHYSICAL_START when relocatable H. Peter Anvin
2009-05-08  7:34   ` Sam Ravnborg
2009-05-08 16:58     ` H. Peter Anvin
2009-05-07 22:26 ` [PATCH 03/14] x86, config: change defaults PHYSICAL_START and PHYSICAL_ALIGN H. Peter Anvin
2009-05-08  7:36   ` Sam Ravnborg
2009-05-08  9:47     ` Ingo Molnar
2009-05-08 17:01     ` H. Peter Anvin
2009-05-07 22:26 ` H. Peter Anvin [this message]
2009-05-07 22:26 ` [PATCH 05/14] kbuild: allow compressors (gzip, bzip2, lzma) to take multiple inputs H. Peter Anvin
2009-05-08  7:42   ` Sam Ravnborg
2009-05-08 20:18     ` H. Peter Anvin
2009-05-08 20:47       ` Sam Ravnborg
2009-05-08 20:49         ` H. Peter Anvin
2009-05-08 21:33           ` Sam Ravnborg
2009-05-07 22:26 ` [PATCH 06/14] x86: add a Kconfig symbol for when relocations are needed H. Peter Anvin
2009-05-07 22:26 ` [PATCH 07/14] x86, boot: simplify arch/x86/boot/compressed/Makefile H. Peter Anvin
2009-05-08  7:45   ` Sam Ravnborg
2009-05-07 22:26 ` [PATCH 08/14] x86, boot: use BP_scratch in arch/x86/boot/compressed/head_*.S H. Peter Anvin
2009-05-07 22:26 ` [PATCH 09/14] x86, boot: add new runtime_address and runtime_size bzImage fields H. Peter Anvin
2009-05-08  7:55   ` Sam Ravnborg
2009-05-08 21:09     ` H. Peter Anvin
2009-05-08 21:35       ` Sam Ravnborg
2009-05-07 22:26 ` [PATCH 10/14] x86, doc: document the runtime_start " H. Peter Anvin
2009-05-07 22:26 ` [PATCH 11/14] x86, boot: use rep movsq to move kernel on 64 bits H. Peter Anvin
2009-05-07 22:27 ` [PATCH 12/14] x86, boot: zero EFLAGS on 32 bits H. Peter Anvin
2009-05-07 22:27 ` [PATCH 13/14] x86: make CONFIG_RELOCATABLE the default H. Peter Anvin
2009-05-07 22:27 ` [PATCH 14/14] x86, defconfig: update defconfigs to relocatable H. Peter Anvin
2009-05-08  1:23 ` [PATCH 00/14] RFC: x86: relocatable kernel changes Eric W. Biederman
2009-05-08  5:31   ` H. Peter Anvin
2009-05-08  6:54     ` Eric W. Biederman
2009-05-08 18:04       ` H. Peter Anvin
2009-05-08 18:47       ` H. Peter Anvin
2009-05-11  5:18         ` RFC: x86: relocatable kernel changes (revised spec) H. Peter Anvin
2009-05-11 11:54           ` Eric W. Biederman
2009-05-11 16:03             ` H. Peter Anvin
2009-05-11 17:56             ` RFC: x86: relocatable kernel changes (revised spec v2) 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=1241735222-6640-5-git-send-email-hpa@linux.intel.com \
    --to=hpa@linux.intel.com \
    --cc=ebiederm@xmission.com \
    --cc=hbabu@us.ibm.com \
    --cc=hpa@zytor.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=sam@ravnborg.org \
    --cc=tglx@linutronix.de \
    --cc=vgoyal@redhat.com \
    --cc=ying.huang@intel.com \
    /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