All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Redfearn <matt.redfearn@imgtec.com>
To: <linux-mips@linux-mips.org>
Cc: Matt Redfearn <matt.redfearn@imgtec.com>
Subject: [PATCH 3/9] MIPS: Reserve space for relocation table
Date: Thu, 3 Dec 2015 10:08:11 +0000	[thread overview]
Message-ID: <1449137297-30464-4-git-send-email-matt.redfearn@imgtec.com> (raw)
In-Reply-To: <1449137297-30464-1-git-send-email-matt.redfearn@imgtec.com>

When CONFIG_RELOCATABLE is enabled, add a new section in the memory map
to be filled with relocation data.

CONFIG_RELOCATION_TABLE_SIZE allows the amount of space reserved to be
adjusted if necessary.

The relocs tool will populate this reserved space with relocation
information. The space is reserved within the elf by filling it with
0's, and an invalid entry is left at the start of the space such that
kernel relocation will be aborted if the table is empty.

Signed-off-by: Matt Redfearn <matt.redfearn@imgtec.com>
---
 arch/mips/Kconfig              | 14 ++++++++++++++
 arch/mips/kernel/vmlinux.lds.S | 20 ++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index e3aa5b0b4ef1..b8ed64dfaafc 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2431,6 +2431,20 @@ config NUMA
 config SYS_SUPPORTS_NUMA
 	bool
 
+config RELOCATION_TABLE_SIZE
+	hex "Relocation table size"
+	depends on RELOCATABLE
+	range 0x0 0x01000000
+	default "0x00100000"
+	---help---
+	  A table of relocation data will be appended to the kernel binary
+	  and parsed at boot to fix up the relocated kernel.
+
+	  This option allows the amount of space reserved for the table to be
+	  adjusted, although the default of 1Mb should be ok in most cases.
+
+	  If unsure, leave at the default value.
+
 config NODES_SHIFT
 	int
 	default "6"
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index 07d32a4aea60..27d70423f1dd 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -128,6 +128,26 @@ SECTIONS
 #ifdef CONFIG_SMP
 	PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
 #endif
+
+#ifdef CONFIG_RELOCATABLE
+	. = ALIGN(4);
+
+	.data.reloc : {
+		_relocation_start = .;
+		/* Space for relocation table
+		 * This needs to be filled so that the
+		 * relocs tool can overwrite the content.
+		 * An invalid value is left at the start of the
+		 * section to abort relocation if the table
+		 * has not been filled in.
+		 */
+		LONG(0xFFFFFFFF);
+		FILL(0);
+		. += CONFIG_RELOCATION_TABLE_SIZE - 4;
+		_relocation_end = .;
+	}
+#endif
+
 #ifdef CONFIG_MIPS_RAW_APPENDED_DTB
 	__appended_dtb = .;
 	/* leave space for appended DTB */
-- 
2.1.4

WARNING: multiple messages have this Message-ID (diff)
From: Matt Redfearn <matt.redfearn@imgtec.com>
To: linux-mips@linux-mips.org
Cc: Matt Redfearn <matt.redfearn@imgtec.com>
Subject: [PATCH 3/9] MIPS: Reserve space for relocation table
Date: Thu, 3 Dec 2015 10:08:11 +0000	[thread overview]
Message-ID: <1449137297-30464-4-git-send-email-matt.redfearn@imgtec.com> (raw)
Message-ID: <20151203100811.AnV3OcOXnuDyMieX1MIwzTV2Zxibg1nQZ8cQkWNLqUc@z> (raw)
In-Reply-To: <1449137297-30464-1-git-send-email-matt.redfearn@imgtec.com>

When CONFIG_RELOCATABLE is enabled, add a new section in the memory map
to be filled with relocation data.

CONFIG_RELOCATION_TABLE_SIZE allows the amount of space reserved to be
adjusted if necessary.

The relocs tool will populate this reserved space with relocation
information. The space is reserved within the elf by filling it with
0's, and an invalid entry is left at the start of the space such that
kernel relocation will be aborted if the table is empty.

Signed-off-by: Matt Redfearn <matt.redfearn@imgtec.com>
---
 arch/mips/Kconfig              | 14 ++++++++++++++
 arch/mips/kernel/vmlinux.lds.S | 20 ++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index e3aa5b0b4ef1..b8ed64dfaafc 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2431,6 +2431,20 @@ config NUMA
 config SYS_SUPPORTS_NUMA
 	bool
 
+config RELOCATION_TABLE_SIZE
+	hex "Relocation table size"
+	depends on RELOCATABLE
+	range 0x0 0x01000000
+	default "0x00100000"
+	---help---
+	  A table of relocation data will be appended to the kernel binary
+	  and parsed at boot to fix up the relocated kernel.
+
+	  This option allows the amount of space reserved for the table to be
+	  adjusted, although the default of 1Mb should be ok in most cases.
+
+	  If unsure, leave at the default value.
+
 config NODES_SHIFT
 	int
 	default "6"
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index 07d32a4aea60..27d70423f1dd 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -128,6 +128,26 @@ SECTIONS
 #ifdef CONFIG_SMP
 	PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
 #endif
+
+#ifdef CONFIG_RELOCATABLE
+	. = ALIGN(4);
+
+	.data.reloc : {
+		_relocation_start = .;
+		/* Space for relocation table
+		 * This needs to be filled so that the
+		 * relocs tool can overwrite the content.
+		 * An invalid value is left at the start of the
+		 * section to abort relocation if the table
+		 * has not been filled in.
+		 */
+		LONG(0xFFFFFFFF);
+		FILL(0);
+		. += CONFIG_RELOCATION_TABLE_SIZE - 4;
+		_relocation_end = .;
+	}
+#endif
+
 #ifdef CONFIG_MIPS_RAW_APPENDED_DTB
 	__appended_dtb = .;
 	/* leave space for appended DTB */
-- 
2.1.4

  parent reply	other threads:[~2015-12-03 10:09 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-03 10:08 [PATCH 0/9] MIPS Relocatable kernel & KASLR Matt Redfearn
2015-12-03 10:08 ` Matt Redfearn
2015-12-03 10:08 ` [PATCH 1/9] MIPS: tools: Add relocs tool Matt Redfearn
2015-12-03 10:08   ` Matt Redfearn
2015-12-03 10:08 ` [PATCH 2/9] MIPS: tools: Build " Matt Redfearn
2015-12-03 10:08   ` Matt Redfearn
2015-12-03 10:08 ` Matt Redfearn [this message]
2015-12-03 10:08   ` [PATCH 3/9] MIPS: Reserve space for relocation table Matt Redfearn
2015-12-03 10:08 ` [PATCH 4/9] MIPS: Generate relocation table when CONFIG_RELOCATABLE Matt Redfearn
2015-12-03 10:08   ` Matt Redfearn
2015-12-03 10:08 ` [PATCH 5/9] MIPS: Kernel: Add relocate.c Matt Redfearn
2015-12-03 10:08   ` Matt Redfearn
2015-12-03 10:08 ` [PATCH 6/9] MIPS: Call relocate_kernel if CONFIG_RELOCATABLE=y Matt Redfearn
2015-12-03 10:08   ` Matt Redfearn
2015-12-03 14:24   ` Sergei Shtylyov
2015-12-03 14:53     ` Matt Redfearn
2015-12-03 14:53       ` Matt Redfearn
2015-12-03 17:46       ` Sergei Shtylyov
2015-12-03 18:54         ` James Hogan
2015-12-04  8:20           ` Matt Redfearn
2015-12-04  8:20             ` Matt Redfearn
2015-12-04 15:37             ` Ralf Baechle
2015-12-04 15:45               ` Matt Redfearn
2015-12-04 15:45                 ` Matt Redfearn
2015-12-03 10:08 ` [PATCH 7/9] MIPS: bootmem: When relocatable, free memory below kernel Matt Redfearn
2015-12-03 10:08   ` Matt Redfearn
2015-12-03 10:08 ` [PATCH 8/9] MIPS: Add CONFIG_RELOCATABLE Kconfig option Matt Redfearn
2015-12-03 10:08   ` Matt Redfearn
2015-12-03 10:08 ` [PATCH 9/9] MIPS: Kernel: Implement kASLR using CONFIG_RELOCATABLE Matt Redfearn
2015-12-03 10:08   ` Matt Redfearn
2015-12-03 22:23 ` [PATCH 0/9] MIPS Relocatable kernel & KASLR Joshua Kinard
2015-12-04  8:14   ` Matt Redfearn
2015-12-04  8:14     ` Matt Redfearn
2015-12-04 13:14     ` Joshua Kinard

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=1449137297-30464-4-git-send-email-matt.redfearn@imgtec.com \
    --to=matt.redfearn@imgtec.com \
    --cc=linux-mips@linux-mips.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.