From: Vivek Goyal <vgoyal@in.ibm.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Horms <horms@verge.net.au>, "H. Peter Anvin" <hpa@zytor.com>,
fastboot@osdl.org, linux-kernel@vger.kernel.org,
Jan Kratochvil <lace@jankratochvil.net>,
Magnus Damm <magnus.damm@gmail.com>,
Linda Wang <lwang@redhat.com>
Subject: Re: [RFC] ELF Relocatable x86 and x86_64 bzImages
Date: Thu, 17 Aug 2006 14:44:01 -0400 [thread overview]
Message-ID: <20060817184401.GA18458@in.ibm.com> (raw)
In-Reply-To: <m18xlz8zdo.fsf@ebiederm.dsl.xmission.com>
On Tue, Aug 08, 2006 at 01:23:15AM -0600, Eric W. Biederman wrote:
> Horms <horms@verge.net.au> writes:
>
> > On Mon, Aug 07, 2006 at 09:32:23PM -0700, H. Peter Anvin wrote:
> >> Horms wrote:
> >> >
> >> >I also agree that it is non-intitive. But I wonder if a cleaner
> >> >fix would be to remove CONFIG_PHYSICAL_START all together. Isn't
> >> >it just a work around for the kernel not being relocatable, or
> >> >are there uses for it that relocation can't replace?
> >> >
> >>
> >> Yes, booting with the 2^n existing bootloaders.
> >
> > Ok, I must be confused then. I though CONFIG_PHYSICAL_START was
> > introduced in order to allow an alternative address to be provided for
> > kdump, and that previously it was hard-coded to some
> > architecture-specific value.
> >
> > What I was really getting as is if it needs to be configurable at
> > compile time or not. Obviously there needs to be some sane default
> > regardless.
>
> CONFIG_PHYSICAL_START has had 2 uses.
> 1) To allow a kernel to run a completely different address for use
> with kexec on panic.
> 2) To allow the kernel to be better aligned for better performance.
>
> For maintenance reasons I propose we introduce CONFIG_PHYSICAL_ALIGN.
> Which will round our load address up to the nearest aligned address
> and run the kernel there. That is roughly what I am doing on x86_64
> at this point.
>
> s/CONFIG_PHYSICAL_START/CONFIG_PHYSICAL_ALIGN/ gives me well defined
> behavior and allows the alignment optimization without getting into
> weird semantics.
>
> Before CONFIG_PHYSICAL_START we _always_ ran the arch/i386 kernel
> where it was loaded and I assumed we always would. Since people have
> realized better aligned kernels can run better this assumption became
> false. Going to CONFIG_PHYSICAL_ALIGN allows us to return to the
> simple assumption of always running the kernel where it is loaded
> modulo a little extra alignment.
>
Hi Eric,
I have tried implementing your idea of replacing CONFIG_PHYSICAL_START
with CONFIG_PHYSICAL_ALIGN. Please find attached the patch.
It applies on top of your relocatable kernel patch series.
I guess there should be a way for running kernel to tell user space
that what's the offset of the addr at which kernel is running to
the address for which kernel has been compiled. This info can be useful
for debuggers in case they happen to debug the core of a kernel which
was not running at compiled addr.
Thanks
Vivek
o Get rid of CONFIG_PHYSICAL_START and implement CONFIG_PHYSICAL_ALIGN
Signed-off-by: Vivek Goyal <vgoyal@in.ibm.com>
---
arch/i386/Kconfig | 34 ++++++++++++++++++----------------
arch/i386/boot/bootsect.S | 8 ++++----
arch/i386/boot/compressed/head.S | 28 ++++++++++++++++------------
arch/i386/boot/compressed/misc.c | 7 ++++---
arch/i386/boot/compressed/vmlinux.lds | 3 +++
arch/i386/kernel/vmlinux.lds.S | 5 +++--
include/asm-i386/boot.h | 6 +++++-
7 files changed, 53 insertions(+), 38 deletions(-)
diff -puN arch/i386/Kconfig~i386-implement-config-physical-align-option arch/i386/Kconfig
--- linux-2.6.18-rc3-1M/arch/i386/Kconfig~i386-implement-config-physical-align-option 2006-08-17 10:56:46.000000000 -0400
+++ linux-2.6.18-rc3-1M-root/arch/i386/Kconfig 2006-08-17 11:28:40.000000000 -0400
@@ -773,24 +773,26 @@ config RELOCATABLE
must live at a different physical address than the primary
kernel.
-config PHYSICAL_START
- hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
-
- default "0x1000000" if CRASH_DUMP
+config PHYSICAL_ALIGN
+ hex "Alignment value to which kernel should be aligned" if (EMBEDDED)
default "0x100000"
- range 0x100000 0x37c00000
+ range 0x2000 0x400000
help
- This gives the physical address where the kernel is loaded. Normally
- for regular kernels this value is 0x100000 (1MB). But in the case
- of kexec on panic the fail safe kernel needs to run at a different
- address than the panic-ed kernel. This option is used to set the load
- address for kernels used to capture crash dump on being kexec'ed
- after panic. The default value for crash dump kernels is
- 0x1000000 (16MB). This can also be set based on the "X" value as
- specified in the "crashkernel=YM@XM" command line boot parameter
- passed to the panic-ed kernel. Typically this parameter is set as
- crashkernel=64M@16M. Please take a look at
- Documentation/kdump/kdump.txt for more details about crash dumps.
+ This value puts the alignment restrictions on physical address
+ where kernel is loaded and run from. Kernel is compiled for an
+ address which meets above alignment restriction.
+
+ If bootloader loads the kernel at a non-aligned address and
+ CONFIG_RELOCATABLE is set, kernel will move itself to nearest
+ address aligned to above value and run from there.
+
+ If bootloader loads the kernel at a non-aligned address and
+ CONFIG_RELOCATABLE is not set, kernel will ignore the run time
+ load address and decompress itself to the address it has been
+ compiled for and run from there. The address for which kernel is
+ compiled already meets above alignment restrictions. Hence the
+ end result is that kernel runs from a physical address meeting above
+ alignment restrictions.
Don't change this unless you know what you are doing.
diff -puN include/asm-i386/boot.h~i386-implement-config-physical-align-option include/asm-i386/boot.h
--- linux-2.6.18-rc3-1M/include/asm-i386/boot.h~i386-implement-config-physical-align-option 2006-08-17 10:56:46.000000000 -0400
+++ linux-2.6.18-rc3-1M-root/include/asm-i386/boot.h 2006-08-17 10:56:46.000000000 -0400
@@ -12,4 +12,8 @@
#define EXTENDED_VGA 0xfffe /* 80x50 mode */
#define ASK_VGA 0xfffd /* ask for it at bootup */
-#endif
+/* Physical address where kenrel should be loaded. */
+#define LOAD_PHYSICAL_ADDR ((0x100000 + CONFIG_PHYSICAL_ALIGN - 1) \
+ & ~(CONFIG_PHYSICAL_ALIGN - 1))
+
+#endif /* _LINUX_BOOT_H */
diff -puN arch/i386/kernel/vmlinux.lds.S~i386-implement-config-physical-align-option arch/i386/kernel/vmlinux.lds.S
--- linux-2.6.18-rc3-1M/arch/i386/kernel/vmlinux.lds.S~i386-implement-config-physical-align-option 2006-08-17 10:56:46.000000000 -0400
+++ linux-2.6.18-rc3-1M-root/arch/i386/kernel/vmlinux.lds.S 2006-08-17 10:56:46.000000000 -0400
@@ -2,13 +2,14 @@
* Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>;
*/
-#define LOAD_OFFSET __PAGE_OFFSET
+#define LOAD_OFFSET __PAGE_OFFSET
#include <linux/config.h>
#include <asm-generic/vmlinux.lds.h>
#include <asm/thread_info.h>
#include <asm/page.h>
#include <asm/cache.h>
+#include <asm/boot.h>
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
@@ -16,7 +17,7 @@ ENTRY(phys_startup_32)
jiffies = jiffies_64;
SECTIONS
{
- . = LOAD_OFFSET + CONFIG_PHYSICAL_START;
+ . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
phys_startup_32 = startup_32 - LOAD_OFFSET;
/* read-only */
.text : AT(ADDR(.text) - LOAD_OFFSET) {
diff -puN arch/i386/boot/bootsect.S~i386-implement-config-physical-align-option arch/i386/boot/bootsect.S
--- linux-2.6.18-rc3-1M/arch/i386/boot/bootsect.S~i386-implement-config-physical-align-option 2006-08-17 10:56:46.000000000 -0400
+++ linux-2.6.18-rc3-1M-root/arch/i386/boot/bootsect.S 2006-08-17 12:37:19.000000000 -0400
@@ -69,7 +69,7 @@ ehdr:
#endif
.word EM_386 # e_machine
.int 1 # e_version
- .int CONFIG_PHYSICAL_START # e_entry
+ .int LOAD_PHYSICAL_ADDR # e_entry
.int phdr - _start # e_phoff
.int 0 # e_shoff
.int 0 # e_flags
@@ -90,12 +90,12 @@ normalize:
phdr:
.int PT_LOAD # p_type
.int (SETUPSECTS+1)*512 # p_offset
- .int __PAGE_OFFSET + CONFIG_PHYSICAL_START # p_vaddr
- .int CONFIG_PHYSICAL_START # p_paddr
+ .int LOAD_PHYSICAL_ADDR + __PAGE_OFFSET # p_vaddr
+ .int LOAD_PHYSICAL_ADDR # p_paddr
.int SYSSIZE*16 # p_filesz
.int 0 # p_memsz
.int PF_R | PF_W | PF_X # p_flags
- .int 4*1024*1024 # p_align
+ .int CONFIG_PHYSICAL_ALIGN # p_align
e_phdr1:
.int PT_NOTE # p_type
diff -puN arch/i386/boot/compressed/vmlinux.lds~i386-implement-config-physical-align-option arch/i386/boot/compressed/vmlinux.lds
--- linux-2.6.18-rc3-1M/arch/i386/boot/compressed/vmlinux.lds~i386-implement-config-physical-align-option 2006-08-17 10:56:46.000000000 -0400
+++ linux-2.6.18-rc3-1M-root/arch/i386/boot/compressed/vmlinux.lds 2006-08-17 10:56:46.000000000 -0400
@@ -3,6 +3,9 @@ OUTPUT_ARCH(i386)
ENTRY(startup_32)
SECTIONS
{
+ /* Be careful parts of head.S assume startup_32 is at
+ * address 0.
+ */
. = 0 ;
.text.head : {
_head = . ;
diff -puN arch/i386/boot/compressed/head.S~i386-implement-config-physical-align-option arch/i386/boot/compressed/head.S
--- linux-2.6.18-rc3-1M/arch/i386/boot/compressed/head.S~i386-implement-config-physical-align-option 2006-08-17 10:56:46.000000000 -0400
+++ linux-2.6.18-rc3-1M-root/arch/i386/boot/compressed/head.S 2006-08-17 11:12:51.000000000 -0400
@@ -27,6 +27,7 @@
#include <linux/linkage.h>
#include <asm/segment.h>
#include <asm/page.h>
+#include <asm/boot.h>
.section ".text.head"
.globl startup_32
@@ -53,17 +54,19 @@ startup_32:
1: popl %ebp
subl $1b, %ebp
-/* Compute the delta between where we were compiled to run at
- * and where the code will actually run at.
+
+/* %ebp contains the address we are loaded at by the boot loader and %ebx
+ * contains the address where we should move the kernel image temporarily
+ * for safe in-place decompression.
*/
- /* Start with the delta to where the kernel will run at. If we are
- * a relocatable kernel this is the delta to our load address otherwise
- * this is the delta to CONFIG_PHYSICAL start.
- */
+
#ifdef CONFIG_RELOCTABLE
- movl %ebp, %ebx
+ movl %ebp, %ebx
+ addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebx
+ andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebx
+
#else
- movl $(CONFIG_PHYSICAL_START - startup_32), %ebx
+ movl $LOAD_PHYSICAL_ADDR, %ebx
#endif
/* Replace the compressed data size with the uncompressed size */
@@ -95,9 +98,10 @@ startup_32:
/* Compute the kernel start address.
*/
#ifdef CONFIG_RELOCATABLE
- leal startup_32(%ebp), %ebp
+ addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebp
+ andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebp
#else
- movl $CONFIG_PHYSICAL_START, %ebp
+ movl $LOAD_PHYSICAL_ADDR, %ebp
#endif
/*
@@ -151,8 +155,8 @@ relocated:
* and where it was actually loaded.
*/
movl %ebp, %ebx
- subl $CONFIG_PHYSICAL_START, %ebx
-
+ subl $LOAD_PHYSICAL_ADDR, %ebx
+ jz 2f /* Nothing to be done if loaded at compiled addr. */
/*
* Process relocations.
*/
diff -puN arch/i386/boot/compressed/misc.c~i386-implement-config-physical-align-option arch/i386/boot/compressed/misc.c
--- linux-2.6.18-rc3-1M/arch/i386/boot/compressed/misc.c~i386-implement-config-physical-align-option 2006-08-17 10:56:46.000000000 -0400
+++ linux-2.6.18-rc3-1M-root/arch/i386/boot/compressed/misc.c 2006-08-17 11:19:05.000000000 -0400
@@ -18,6 +18,7 @@
#include <asm/io.h>
#include <asm/setup.h>
#include <asm/page.h>
+#include <asm/boot.h>
/* WARNING!!
* This code is compiled with -fPIC and it is relocated dynamically
@@ -585,12 +586,12 @@ asmlinkage void decompress_kernel(void *
insize = input_len;
inptr = 0;
- if (((u32)output - CONFIG_PHYSICAL_START) & 0x3fffff)
- error("Destination address not 4M aligned");
+ if ((u32)output & (CONFIG_PHYSICAL_ALIGN -1))
+ error("Destination address not CONFIG_PHYSICAL_ALIGN aligned");
if (end > ((-__PAGE_OFFSET-(512 <<20)-1) & 0x7fffffff))
error("Destination address too large");
#ifndef CONFIG_RELOCATABLE
- if ((u32)output != CONFIG_PHYSICAL_START)
+ if ((u32)output != LOAD_PHYSICAL_ADDR)
error("Wrong destination address");
#endif
_
next prev parent reply other threads:[~2006-08-17 18:44 UTC|newest]
Thread overview: 105+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-01 10:58 [RFC] ELF Relocatable x86 and x86_64 bzImages Eric W. Biederman
2006-08-01 11:03 ` [PATCH 1/33] i386: vmlinux.lds.S Distinguish absolute symbols Eric W. Biederman
2006-08-01 19:06 ` Sam Ravnborg
2006-08-01 11:03 ` [PATCH 2/33] i386: define __pa_symbol Eric W. Biederman
2006-08-01 19:06 ` Andi Kleen
2006-08-02 2:19 ` Eric W. Biederman
2006-08-02 3:04 ` Andi Kleen
2006-08-01 11:03 ` [PATCH 3/33] i386 setup.c: Reserve kernel memory starting from _text Eric W. Biederman
2006-08-01 11:03 ` [PATCH 4/33] i386: CONFIG_PHYSICAL_START cleanup Eric W. Biederman
2006-08-01 19:08 ` Sam Ravnborg
2006-08-02 2:23 ` Eric W. Biederman
2006-08-02 16:14 ` Eric W. Biederman
2006-08-03 14:05 ` Sam Ravnborg
2006-08-01 11:03 ` [PATCH 5/33] i386 Kconfig: Add a range definition to config PHYSICAL_START Eric W. Biederman
2006-08-01 11:03 ` [PATCH 6/33] Make linux/elf.h safe to be included in assembly files Eric W. Biederman
2006-08-01 11:03 ` [PATCH 7/33] elf: Add ELFOSABI_STANDALONE to elf.h Eric W. Biederman
2006-08-01 11:03 ` [PATCH 8/33] kallsyms.c: Generate relocatable symbols Eric W. Biederman
2006-08-01 11:36 ` Paulo Marques
2006-08-01 11:52 ` Eric W. Biederman
2006-08-01 11:03 ` [PATCH 9/33] i386 boot: Add serial output support to the decompressor Eric W. Biederman
2006-08-01 19:19 ` Andi Kleen
2006-08-02 2:30 ` Eric W. Biederman
2006-08-02 3:07 ` Andi Kleen
2006-08-02 4:57 ` Eric W. Biederman
2006-08-02 5:21 ` Andi Kleen
2006-08-02 6:44 ` Eric W. Biederman
2006-08-02 3:06 ` Eric W. Biederman
2006-08-02 3:10 ` Andi Kleen
2006-08-02 5:27 ` Eric W. Biederman
2006-08-02 5:44 ` Andi Kleen
2006-08-02 7:14 ` Eric W. Biederman
2006-08-01 11:03 ` [PATCH 10/33] i386: Relocatable kernel support Eric W. Biederman
2006-08-01 13:34 ` Mika Penttilä
2006-08-01 18:07 ` Eric W. Biederman
2006-08-01 18:11 ` Sam Ravnborg
2006-08-01 18:16 ` Mika Penttilä
2006-08-01 11:03 ` [PATCH 11/33] i386 boot: Add an ELF header to bzImage Eric W. Biederman
2006-08-01 22:10 ` Jeremy Fitzhardinge
2006-08-02 2:38 ` Eric W. Biederman
2006-08-01 11:03 ` [PATCH 12/33] x86_64: fixup indentation in e820.c Eric W. Biederman
2006-08-01 11:03 ` [PATCH 13/33] x86_64: Remove assumptions about the kernel start address from e820/bad_addr() Eric W. Biederman
2006-08-01 11:03 ` [PATCH 14/33] x86_64: Properly report in /proc/iomem the kernel address Eric W. Biederman
2006-08-01 11:03 ` [PATCH 15/33] x86_64: Fix kernel direct mapping size check Eric W. Biederman
2006-08-01 11:03 ` [PATCH 16/33] x86_64: Assembly safe page.h and pgtable.h Eric W. Biederman
2006-08-01 11:03 ` [PATCH 17/33] x86_64: Separate normal memory map initialization from the hotplug case Eric W. Biederman
2006-08-01 11:03 ` [PATCH 18/33] x86_64: Kill temp_boot_pmds Eric W. Biederman
2006-08-01 19:02 ` Andi Kleen
2006-08-02 2:08 ` Eric W. Biederman
2006-08-01 19:04 ` [PATCH 18/33] x86_64: Kill temp_boot_pmds II Andi Kleen
2006-08-02 2:11 ` Eric W. Biederman
2006-08-02 3:07 ` Andi Kleen
2006-08-02 5:35 ` Eric W. Biederman
2006-08-01 11:03 ` [PATCH 19/33] x86_64: Cleanup the early boot page table Eric W. Biederman
2006-08-01 11:03 ` [PATCH 20/33] x86_64: fix early_printk to use the standard ISA mapping Eric W. Biederman
2006-08-01 11:03 ` [PATCH 21/33] x86_64: modify copy_bootdata to use virtual addresses Eric W. Biederman
2006-08-01 11:03 ` [PATCH 22/33] x86_64: Fix gdt table size in trampoline.S Eric W. Biederman
2006-08-01 18:59 ` Andi Kleen
2006-08-01 11:03 ` [PATCH 23/33] x86_64: cleanup segments Eric W. Biederman
2006-08-01 11:03 ` [PATCH 24/33] x86_64: Add EFER to the set registers saved by save_processor_state Eric W. Biederman
2006-08-01 11:03 ` [PATCH 25/33] x86_64: 64bit PIC SMP trampoline Eric W. Biederman
2006-08-01 19:13 ` Andi Kleen
2006-08-01 11:03 ` [PATCH 26/33] x86_64: 64bit PIC ACPI wakeup Eric W. Biederman
2006-08-01 19:10 ` Andi Kleen
2006-08-01 11:03 ` [PATCH 27/33] x86_64: Modify discover_ebda to use virtual addresses Eric W. Biederman
2006-08-01 11:03 ` [PATCH 28/33] x86_64: Remove the identity mapping as early as possible Eric W. Biederman
2006-08-01 19:15 ` Andi Kleen
2006-08-01 11:03 ` [PATCH 29/33] x86_64: __pa and __pa_symbol address space separation Eric W. Biederman
2006-08-01 11:03 ` [PATCH 30/33] x86_64: Remove CONFIG_PHYSICAL_START Eric W. Biederman
2006-08-01 11:03 ` [PATCH 31/33] x86_64 boot: Add serial output support to the decompressor Eric W. Biederman
2006-08-01 11:03 ` [PATCH 32/33] x86_64: Relocatable kernel support Eric W. Biederman
2006-08-01 19:11 ` Andi Kleen
2006-08-02 2:25 ` Eric W. Biederman
2006-11-05 6:02 ` Yinghai Lu
2006-11-05 6:52 ` Eric W. Biederman
2006-11-05 7:15 ` Yinghai Lu
2006-08-01 11:03 ` [PATCH 33/33] x86_64: Make bzImage a valid 64bit elf executable Eric W. Biederman
2006-08-01 19:26 ` [RFC] ELF Relocatable x86 and x86_64 bzImages Vivek Goyal
2006-08-01 20:13 ` Jan Kratochvil
2006-08-01 20:25 ` H. Peter Anvin
2006-08-02 2:02 ` Eric W. Biederman
2006-08-01 20:40 ` Vivek Goyal
2006-08-02 2:40 ` Eric W. Biederman
2006-08-02 6:34 ` Magnus Damm
2006-08-02 7:09 ` Eric W. Biederman
2006-08-02 8:34 ` Magnus Damm
2006-08-02 9:59 ` Eric W. Biederman
2006-08-02 18:37 ` [Fastboot] " Don Zickus
2006-08-03 1:00 ` Eric W. Biederman
2006-08-03 4:53 ` H. Peter Anvin
2006-08-04 22:56 ` Vivek Goyal
2006-08-04 23:14 ` Eric W. Biederman
2006-08-04 23:38 ` Dave Jones
2006-08-04 23:47 ` H. Peter Anvin
2006-08-05 8:01 ` Eric W. Biederman
2006-08-08 3:34 ` Horms
2006-08-08 4:32 ` H. Peter Anvin
2006-08-08 4:57 ` Magnus Damm
2006-08-08 5:04 ` Eric W. Biederman
2006-08-08 6:09 ` Horms
2006-08-08 7:23 ` Eric W. Biederman
2006-08-08 7:58 ` Horms
2006-08-09 14:56 ` D. Hazelton
2006-08-17 18:44 ` Vivek Goyal [this message]
2006-08-11 13:11 ` [Fastboot] " Rachita Kothiyal
2006-08-11 13:36 ` Vivek Goyal
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=20060817184401.GA18458@in.ibm.com \
--to=vgoyal@in.ibm.com \
--cc=ebiederm@xmission.com \
--cc=fastboot@osdl.org \
--cc=horms@verge.net.au \
--cc=hpa@zytor.com \
--cc=lace@jankratochvil.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lwang@redhat.com \
--cc=magnus.damm@gmail.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