All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: make head.S less dependent on the compile time PHYS_OFFSET define
@ 2011-01-13 22:04 Nicolas Pitre
  2011-01-13 23:23 ` Russell King - ARM Linux
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Pitre @ 2011-01-13 22:04 UTC (permalink / raw)
  To: linux-arm-kernel


In preparation to support a variable PHYS_OFFSET with the same kernel 
binary image, we need to get rid of the dependency on the compile time 
defined PHYS_OFFSET when establishing the initial page table.  The value 
of PHYS_OFFSET can be determined at run time by masking the pc value. A 
mask of 0xf8000000 is used to be consistent with the mask used by the 
CONFIG_AUTO_ZRELADDR feature.

If CONFIG_XIP_KERNEL is selected then the compile time PHYS_OFFSET is 
still used as before, as there is no point having a runtime determined 
PHYS_OFFSET in that case, and masking the pc value wouldn't be right 
anyway.

Signed-off-by: Nicolas Pitre <nicolas.pitre@linaro.org>

diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
index f17d9a0..be535b3 100644
--- a/arch/arm/kernel/head.S
+++ b/arch/arm/kernel/head.S
@@ -30,10 +30,6 @@
 #error "PHYS_OFFSET must be at an even 2MiB boundary!"
 #endif
 
-#define KERNEL_RAM_VADDR	(PAGE_OFFSET + TEXT_OFFSET)
-#define KERNEL_RAM_PADDR	(PHYS_OFFSET + TEXT_OFFSET)
-
-
 /*
  * swapper_pg_dir is the virtual address of the initial page table.
  * We place the page tables 16K below KERNEL_RAM_VADDR.  Therefore, we must
@@ -41,6 +37,7 @@
  * the least significant 16 bits to be 0x8000, but we could probably
  * relax this restriction to KERNEL_RAM_VADDR >= PAGE_OFFSET + 0x4000.
  */
+#define KERNEL_RAM_VADDR	(PAGE_OFFSET + TEXT_OFFSET)
 #if (KERNEL_RAM_VADDR & 0xffff) != 0x8000
 #error KERNEL_RAM_VADDR must start at 0xXXXX8000
 #endif
@@ -49,15 +46,29 @@
 	.equ	swapper_pg_dir, KERNEL_RAM_VADDR - 0x4000
 
 	.macro	pgtbl, rd
-	ldr	\rd, =(KERNEL_RAM_PADDR - 0x4000)
+	phys_offset \rd
+	add	\rd, \rd, #(TEXT_OFFSET - 0x4000)
 	.endm
 
 #ifdef CONFIG_XIP_KERNEL
+
 #define KERNEL_START	XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR)
 #define KERNEL_END	_edata_loc
+
+	.macro phys_offset, rd
+	ldr	\rd, =PHYS_OFFSET
+	.endm
+
 #else
+
 #define KERNEL_START	KERNEL_RAM_VADDR
 #define KERNEL_END	_end
+
+	.macro phys_offset, rd
+	mov	\rd, pc
+	and	\rd, \rd, #0xf8000000
+	.endm
+
 #endif
 
 /*
@@ -189,10 +200,9 @@ __create_page_tables:
 	/*
 	 * Map some ram to cover our .data and .bss areas.
 	 */
-	orr	r3, r7, #(KERNEL_RAM_PADDR & 0xff000000)
-	.if	(KERNEL_RAM_PADDR & 0x00f00000)
-	orr	r3, r3, #(KERNEL_RAM_PADDR & 0x00f00000)
-	.endif
+	phys_offset r3
+	add	r3, r3, #TEXT_OFFSET 
+	orr	r3, r3, r7
 	add	r0, r4,  #(KERNEL_RAM_VADDR & 0xff000000) >> 18
 	str	r3, [r0, #(KERNEL_RAM_VADDR & 0x00f00000) >> 18]!
 	ldr	r6, =(_end - 1)

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] ARM: make head.S less dependent on the compile time PHYS_OFFSET define
  2011-01-13 22:04 [PATCH] ARM: make head.S less dependent on the compile time PHYS_OFFSET define Nicolas Pitre
@ 2011-01-13 23:23 ` Russell King - ARM Linux
  2011-01-14  6:18   ` Nicolas Pitre
  0 siblings, 1 reply; 6+ messages in thread
From: Russell King - ARM Linux @ 2011-01-13 23:23 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Jan 13, 2011 at 05:04:28PM -0500, Nicolas Pitre wrote:
> +	.macro phys_offset, rd
> +	mov	\rd, pc
> +	and	\rd, \rd, #0xf8000000
> +	.endm

We can do loads better than that, as the p2v fixup code has proven.
Now that r8 has been eliminated, I may rebase the p2v stuff ontop of
that commit, and move the computation of phys_offset out of the p2v
fixup code - and have it in r8 for __create_page_tables to use.

FYI, the real PHYS_OFFSET value can be found by (eg):

1:	.long	.
	.long	PAGE_OFFSET

	adr	r0, 1b
	ldmia	r0, {r1, r2}
	sub	r1, r0, r1
	add	r3, r2, r1

r1 now contains the offset between virtual and physical spaces, r2
contains the compile-time PAGE_OFFSET constant, and r3 the runtime
equivalent of PHYS_OFFSET.

None of this uses troublesome masking which will trip up on platforms
such as MSM - we really must stop writing code which assumes that
physical memory is aligned to >= 32MB.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] ARM: make head.S less dependent on the compile time PHYS_OFFSET define
  2011-01-13 23:23 ` Russell King - ARM Linux
@ 2011-01-14  6:18   ` Nicolas Pitre
  2011-01-15  0:44     ` Russell King - ARM Linux
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Pitre @ 2011-01-14  6:18 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 13 Jan 2011, Russell King - ARM Linux wrote:

> On Thu, Jan 13, 2011 at 05:04:28PM -0500, Nicolas Pitre wrote:
> > +	.macro phys_offset, rd
> > +	mov	\rd, pc
> > +	and	\rd, \rd, #0xf8000000
> > +	.endm
> 
> We can do loads better than that, as the p2v fixup code has proven.
> Now that r8 has been eliminated, I may rebase the p2v stuff ontop of
> that commit, and move the computation of phys_offset out of the p2v
> fixup code - and have it in r8 for __create_page_tables to use.
> FYI, the real PHYS_OFFSET value can be found by (eg):
> 
> 1:	.long	.
> 	.long	PAGE_OFFSET
> 
> 	adr	r0, 1b
> 	ldmia	r0, {r1, r2}
> 	sub	r1, r0, r1
> 	add	r3, r2, r1
> 
> r1 now contains the offset between virtual and physical spaces, r2
> contains the compile-time PAGE_OFFSET constant, and r3 the runtime
> equivalent of PHYS_OFFSET.
> 
> None of this uses troublesome masking which will trip up on platforms
> such as MSM - we really must stop writing code which assumes that
> physical memory is aligned to >= 32MB.

That is more reliable indeed.  But without visibility into your reworked 
version of that code I opted for a less intrusive solution.

Unfortunately this trick can't work for CONFIG_AUTO_ZRELADDR.


Nicolas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] ARM: make head.S less dependent on the compile time PHYS_OFFSET define
  2011-01-14  6:18   ` Nicolas Pitre
@ 2011-01-15  0:44     ` Russell King - ARM Linux
  2011-01-15  4:49       ` Nicolas Pitre
  0 siblings, 1 reply; 6+ messages in thread
From: Russell King - ARM Linux @ 2011-01-15  0:44 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jan 14, 2011 at 01:18:20AM -0500, Nicolas Pitre wrote:
> On Thu, 13 Jan 2011, Russell King - ARM Linux wrote:
> 
> > On Thu, Jan 13, 2011 at 05:04:28PM -0500, Nicolas Pitre wrote:
> > > +	.macro phys_offset, rd
> > > +	mov	\rd, pc
> > > +	and	\rd, \rd, #0xf8000000
> > > +	.endm
> > 
> > We can do loads better than that, as the p2v fixup code has proven.
> > Now that r8 has been eliminated, I may rebase the p2v stuff ontop of
> > that commit, and move the computation of phys_offset out of the p2v
> > fixup code - and have it in r8 for __create_page_tables to use.
> > FYI, the real PHYS_OFFSET value can be found by (eg):
> > 
> > 1:	.long	.
> > 	.long	PAGE_OFFSET
> > 
> > 	adr	r0, 1b
> > 	ldmia	r0, {r1, r2}
> > 	sub	r1, r0, r1
> > 	add	r3, r2, r1
> > 
> > r1 now contains the offset between virtual and physical spaces, r2
> > contains the compile-time PAGE_OFFSET constant, and r3 the runtime
> > equivalent of PHYS_OFFSET.
> > 
> > None of this uses troublesome masking which will trip up on platforms
> > such as MSM - we really must stop writing code which assumes that
> > physical memory is aligned to >= 32MB.
> 
> That is more reliable indeed.  But without visibility into your reworked 
> version of that code I opted for a less intrusive solution.
> 
> Unfortunately this trick can't work for CONFIG_AUTO_ZRELADDR.

I've pushed it out under the branch p2v.  I think before this
goes upstream, "ARM: P2V: Use pv_fixup trick to get physical address"
needs merging with "ARM: P2V: make head.S use PLAT_PHYS_OFFSET" -
it doesn't really make sense to fix the same code twice for the same
underlying problem in the same patch set when it's possible to only
fix it once.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] ARM: make head.S less dependent on the compile time PHYS_OFFSET define
  2011-01-15  0:44     ` Russell King - ARM Linux
@ 2011-01-15  4:49       ` Nicolas Pitre
  2011-01-15 12:01         ` Russell King - ARM Linux
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Pitre @ 2011-01-15  4:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, 15 Jan 2011, Russell King - ARM Linux wrote:

> I've pushed it out under the branch p2v.  I think before this
> goes upstream, "ARM: P2V: Use pv_fixup trick to get physical address"
> needs merging with "ARM: P2V: make head.S use PLAT_PHYS_OFFSET" -
> it doesn't really make sense to fix the same code twice for the same
> underlying problem in the same patch set when it's possible to only
> fix it once.

Indeed.  You probably should fold the following with it as well:

diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
index f5fe0c4..02a7a84 100644
--- a/arch/arm/kernel/head.S
+++ b/arch/arm/kernel/head.S
@@ -26,10 +26,6 @@
 #include <mach/debug-macro.S>
 #endif
 
-#define KERNEL_RAM_VADDR	(PAGE_OFFSET + TEXT_OFFSET)
-#define KERNEL_RAM_PADDR	(PLAT_PHYS_OFFSET + TEXT_OFFSET)
-
-
 /*
  * swapper_pg_dir is the virtual address of the initial page table.
  * We place the page tables 16K below KERNEL_RAM_VADDR.  Therefore, we must
@@ -37,6 +33,7 @@
  * the least significant 16 bits to be 0x8000, but we could probably
  * relax this restriction to KERNEL_RAM_VADDR >= PAGE_OFFSET + 0x4000.
  */
+#define KERNEL_RAM_VADDR	(PAGE_OFFSET + TEXT_OFFSET)
 #if (KERNEL_RAM_VADDR & 0xffff) != 0x8000
 #error KERNEL_RAM_VADDR must start at 0xXXXX8000
 #endif
@@ -195,10 +192,8 @@ __create_page_tables:
 	/*
 	 * Map some ram to cover our .data and .bss areas.
 	 */
-	orr	r3, r7, #(KERNEL_RAM_PADDR & 0xff000000)
-	.if	(KERNEL_RAM_PADDR & 0x00f00000)
-	orr	r3, r3, #(KERNEL_RAM_PADDR & 0x00f00000)
-	.endif
+	add	r3, r8, #TEXT_OFFSET
+	orr	r3, r3, r7
 	add	r0, r4,  #(KERNEL_RAM_VADDR & 0xff000000) >> 18
 	str	r3, [r0, #(KERNEL_RAM_VADDR & 0x00f00000) >> 18]!
 	ldr	r6, =(_end - 1)

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] ARM: make head.S less dependent on the compile time PHYS_OFFSET define
  2011-01-15  4:49       ` Nicolas Pitre
@ 2011-01-15 12:01         ` Russell King - ARM Linux
  0 siblings, 0 replies; 6+ messages in thread
From: Russell King - ARM Linux @ 2011-01-15 12:01 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jan 14, 2011 at 11:49:31PM -0500, Nicolas Pitre wrote:
> On Sat, 15 Jan 2011, Russell King - ARM Linux wrote:
> 
> > I've pushed it out under the branch p2v.  I think before this
> > goes upstream, "ARM: P2V: Use pv_fixup trick to get physical address"
> > needs merging with "ARM: P2V: make head.S use PLAT_PHYS_OFFSET" -
> > it doesn't really make sense to fix the same code twice for the same
> > underlying problem in the same patch set when it's possible to only
> > fix it once.
> 
> Indeed.  You probably should fold the following with it as well:

Ok, done.

One other item which has been missed: the p2v build state between kernel
and modules must match to prevent incompatible modules being loaded.

This also applies for the 16-bit p2v stuff as well - an 8-bit p2v module
can't be loaded into a 16-bit p2v kernel as it will be missing bits
16-23 of the offset.

These dependencies are actually one-way:

		------- module -------
kernel		fixed	p2v-8	p2v-16
fixed		y	n*	n*
p2v-8		n	y	y
p2v-16		n	n	y

The 'n*' could be 'y' if we always include the fixup code, but I'm not
sure the complexity required for expressing these dependencies (which
can't be done with the vermagic method) is worth it.

So I've added a marker to the module version string, which will require
the build configuration of P2V for the kernel and modules to match.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-01-15 12:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-13 22:04 [PATCH] ARM: make head.S less dependent on the compile time PHYS_OFFSET define Nicolas Pitre
2011-01-13 23:23 ` Russell King - ARM Linux
2011-01-14  6:18   ` Nicolas Pitre
2011-01-15  0:44     ` Russell King - ARM Linux
2011-01-15  4:49       ` Nicolas Pitre
2011-01-15 12:01         ` Russell King - ARM Linux

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.