All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] Fix the combination of CONFIG_RELOCATABLE=y and CONFIG_MIPS_ELF_APPENDED_DTB=y
@ 2019-03-08 12:58 Yasha Cherikovsky
  2019-03-08 12:58 ` [PATCH 1/1] MIPS: Ensure ELF appended dtb is relocated Yasha Cherikovsky
  0 siblings, 1 reply; 5+ messages in thread
From: Yasha Cherikovsky @ 2019-03-08 12:58 UTC (permalink / raw)
  To: Ralf Baechle, Paul Burton, James Hogan, linux-mips
  Cc: Yasha Cherikovsky, linux-kernel

Hi,

I sent this patch almost 5 months ago but received no response [1].
I'm sending it again now, on top of v5.0.

Full details are in the commit message.
Please review.

Thanks,
Yasha


[1] https://lkml.org/lkml/2018/10/20/175

Cc: linux-kernel@vger.kernel.org


Yasha Cherikovsky (1):
  MIPS: Ensure ELF appended dtb is relocated

 arch/mips/kernel/vmlinux.lds.S | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

-- 
2.21.0


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

* [PATCH 1/1] MIPS: Ensure ELF appended dtb is relocated
  2019-03-08 12:58 [PATCH 0/1] Fix the combination of CONFIG_RELOCATABLE=y and CONFIG_MIPS_ELF_APPENDED_DTB=y Yasha Cherikovsky
@ 2019-03-08 12:58 ` Yasha Cherikovsky
  2019-03-08 19:02   ` Paul Burton
  2019-03-11 18:14   ` Paul Burton
  0 siblings, 2 replies; 5+ messages in thread
From: Yasha Cherikovsky @ 2019-03-08 12:58 UTC (permalink / raw)
  To: Ralf Baechle, Paul Burton, James Hogan, linux-mips
  Cc: Yasha Cherikovsky, linux-kernel

This fixes booting with the combination of CONFIG_RELOCATABLE=y
and CONFIG_MIPS_ELF_APPENDED_DTB=y.

Sections that appear after the relocation table are not relocated
on system boot (except .bss, which has special handling).

With CONFIG_MIPS_ELF_APPENDED_DTB, the dtb is part of the
vmlinux ELF, so it must be relocated together with everything else.

Fixes: 069fd766271d ("MIPS: Reserve space for relocation table")
Signed-off-by: Yasha Cherikovsky <yasha.che3@gmail.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paul Burton <paul.burton@mips.com>
Cc: James Hogan <jhogan@kernel.org>
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
---
 arch/mips/kernel/vmlinux.lds.S | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index cb7e9ed7a453..33ee0d18fb0a 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -140,6 +140,13 @@ SECTIONS
 	PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
 #endif
 
+#ifdef CONFIG_MIPS_ELF_APPENDED_DTB
+	.appended_dtb : AT(ADDR(.appended_dtb) - LOAD_OFFSET) {
+		*(.appended_dtb)
+		KEEP(*(.appended_dtb))
+	}
+#endif
+
 #ifdef CONFIG_RELOCATABLE
 	. = ALIGN(4);
 
@@ -164,11 +171,6 @@ SECTIONS
 	__appended_dtb = .;
 	/* leave space for appended DTB */
 	. += 0x100000;
-#elif defined(CONFIG_MIPS_ELF_APPENDED_DTB)
-	.appended_dtb : AT(ADDR(.appended_dtb) - LOAD_OFFSET) {
-		*(.appended_dtb)
-		KEEP(*(.appended_dtb))
-	}
 #endif
 	/*
 	 * Align to 64K in attempt to eliminate holes before the
-- 
2.21.0


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

* Re: [PATCH 1/1] MIPS: Ensure ELF appended dtb is relocated
  2019-03-08 12:58 ` [PATCH 1/1] MIPS: Ensure ELF appended dtb is relocated Yasha Cherikovsky
@ 2019-03-08 19:02   ` Paul Burton
  2019-03-08 21:13     ` Yasha Cherikovsky
  2019-03-11 18:14   ` Paul Burton
  1 sibling, 1 reply; 5+ messages in thread
From: Paul Burton @ 2019-03-08 19:02 UTC (permalink / raw)
  To: Yasha Cherikovsky; +Cc: Ralf Baechle, James Hogan, linux-mips, linux-kernel

Hi Yasha,

On Fri, Mar 08, 2019 at 02:58:51PM +0200, Yasha Cherikovsky wrote:
> This fixes booting with the combination of CONFIG_RELOCATABLE=y
> and CONFIG_MIPS_ELF_APPENDED_DTB=y.
> 
> Sections that appear after the relocation table are not relocated
> on system boot (except .bss, which has special handling).
> 
> With CONFIG_MIPS_ELF_APPENDED_DTB, the dtb is part of the
> vmlinux ELF, so it must be relocated together with everything else.

Do you have any ideas how CONFIG_RELOCATABLE interacts with
CONFIG_MIPS_RAW_APPENDED_DTB? I'm wondering whether we should move both
variants of appended DTB to before .data.reloc, but haven't yet thought
it through.

Thanks,
    Paul

> Fixes: 069fd766271d ("MIPS: Reserve space for relocation table")
> Signed-off-by: Yasha Cherikovsky <yasha.che3@gmail.com>
> Cc: Ralf Baechle <ralf@linux-mips.org>
> Cc: Paul Burton <paul.burton@mips.com>
> Cc: James Hogan <jhogan@kernel.org>
> Cc: linux-mips@linux-mips.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  arch/mips/kernel/vmlinux.lds.S | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
> index cb7e9ed7a453..33ee0d18fb0a 100644
> --- a/arch/mips/kernel/vmlinux.lds.S
> +++ b/arch/mips/kernel/vmlinux.lds.S
> @@ -140,6 +140,13 @@ SECTIONS
>  	PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
>  #endif
>  
> +#ifdef CONFIG_MIPS_ELF_APPENDED_DTB
> +	.appended_dtb : AT(ADDR(.appended_dtb) - LOAD_OFFSET) {
> +		*(.appended_dtb)
> +		KEEP(*(.appended_dtb))
> +	}
> +#endif
> +
>  #ifdef CONFIG_RELOCATABLE
>  	. = ALIGN(4);
>  
> @@ -164,11 +171,6 @@ SECTIONS
>  	__appended_dtb = .;
>  	/* leave space for appended DTB */
>  	. += 0x100000;
> -#elif defined(CONFIG_MIPS_ELF_APPENDED_DTB)
> -	.appended_dtb : AT(ADDR(.appended_dtb) - LOAD_OFFSET) {
> -		*(.appended_dtb)
> -		KEEP(*(.appended_dtb))
> -	}
>  #endif
>  	/*
>  	 * Align to 64K in attempt to eliminate holes before the
> -- 
> 2.21.0
> 

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

* Re: [PATCH 1/1] MIPS: Ensure ELF appended dtb is relocated
  2019-03-08 19:02   ` Paul Burton
@ 2019-03-08 21:13     ` Yasha Cherikovsky
  0 siblings, 0 replies; 5+ messages in thread
From: Yasha Cherikovsky @ 2019-03-08 21:13 UTC (permalink / raw)
  To: Paul Burton; +Cc: Ralf Baechle, James Hogan, linux-mips, linux-kernel

Hi Paul,

On Fri, 2019-03-08 at 19:02 +0000, Paul Burton wrote:
> Hi Yasha,
> 
> On Fri, Mar 08, 2019 at 02:58:51PM +0200, Yasha Cherikovsky wrote:
> > This fixes booting with the combination of CONFIG_RELOCATABLE=y
> > and CONFIG_MIPS_ELF_APPENDED_DTB=y.
> > 
> > Sections that appear after the relocation table are not relocated
> > on system boot (except .bss, which has special handling).
> > 
> > With CONFIG_MIPS_ELF_APPENDED_DTB, the dtb is part of the
> > vmlinux ELF, so it must be relocated together with everything else.
> 
> Do you have any ideas how CONFIG_RELOCATABLE interacts with
> CONFIG_MIPS_RAW_APPENDED_DTB? I'm wondering whether we should move both
> variants of appended DTB to before .data.reloc, but haven't yet thought
> it through.
> 
> Thanks,
>     Paul
> 

I booted now a image with RELOCATABLE and MIPS_RAW_APPENDED_DTB and it
works.

Behind the scenes it's complicated:

1. MIPS_RAW_APPENDED_DTB works this way (the way I understand it):
   In run time, the dtb appears in memory right after the original
   vmlinux.bin image (the one that "make" created).
   If the dtb was concatenated to vmlinuz.bin: at run time, after vmlinuz
   extracts vmlinux.bin,
   it takes care of copying the dtb to the end of vmlinux.bin in memory.
   If the dtb was concatenated to vmlinux.bin at build time, no run-time
   work is needed.

2. Therefore, the __appended_dtb pointer in the linker script must point to
   the end of the actual data in vmlinux.bin.
   So we can't move it to before .data.reloc.

3. When the kernel relocates itself, it doesn't copy the appended dtb 
   along with the kernel.
   This behavior is documented, see this code comment: [1].


Yasha

[1] 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/mips/kernel/relocate.c?h=v5.0#n339


> > Fixes: 069fd766271d ("MIPS: Reserve space for relocation table")
> > Signed-off-by: Yasha Cherikovsky <yasha.che3@gmail.com>
> > Cc: Ralf Baechle <ralf@linux-mips.org>
> > Cc: Paul Burton <paul.burton@mips.com>
> > Cc: James Hogan <jhogan@kernel.org>
> > Cc: linux-mips@linux-mips.org
> > Cc: linux-kernel@vger.kernel.org
> > ---
> >  arch/mips/kernel/vmlinux.lds.S | 12 +++++++-----
> >  1 file changed, 7 insertions(+), 5 deletions(-)
> > 
> > diff --git a/arch/mips/kernel/vmlinux.lds.S
> > b/arch/mips/kernel/vmlinux.lds.S
> > index cb7e9ed7a453..33ee0d18fb0a 100644
> > --- a/arch/mips/kernel/vmlinux.lds.S
> > +++ b/arch/mips/kernel/vmlinux.lds.S
> > @@ -140,6 +140,13 @@ SECTIONS
> >  	PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
> >  #endif
> >  
> > +#ifdef CONFIG_MIPS_ELF_APPENDED_DTB
> > +	.appended_dtb : AT(ADDR(.appended_dtb) - LOAD_OFFSET) {
> > +		*(.appended_dtb)
> > +		KEEP(*(.appended_dtb))
> > +	}
> > +#endif
> > +
> >  #ifdef CONFIG_RELOCATABLE
> >  	. = ALIGN(4);
> >  
> > @@ -164,11 +171,6 @@ SECTIONS
> >  	__appended_dtb = .;
> >  	/* leave space for appended DTB */
> >  	. += 0x100000;
> > -#elif defined(CONFIG_MIPS_ELF_APPENDED_DTB)
> > -	.appended_dtb : AT(ADDR(.appended_dtb) - LOAD_OFFSET) {
> > -		*(.appended_dtb)
> > -		KEEP(*(.appended_dtb))
> > -	}
> >  #endif
> >  	/*
> >  	 * Align to 64K in attempt to eliminate holes before the
> > -- 
> > 2.21.0
> > 


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

* Re: [PATCH 1/1] MIPS: Ensure ELF appended dtb is relocated
  2019-03-08 12:58 ` [PATCH 1/1] MIPS: Ensure ELF appended dtb is relocated Yasha Cherikovsky
  2019-03-08 19:02   ` Paul Burton
@ 2019-03-11 18:14   ` Paul Burton
  1 sibling, 0 replies; 5+ messages in thread
From: Paul Burton @ 2019-03-11 18:14 UTC (permalink / raw)
  To: Yasha Cherikovsky
  Cc: Ralf Baechle, Paul Burton, James Hogan, linux-mips,
	Yasha Cherikovsky, linux-kernel, linux-mips

Hello,

Yasha Cherikovsky wrote:
> This fixes booting with the combination of CONFIG_RELOCATABLE=y
> and CONFIG_MIPS_ELF_APPENDED_DTB=y.
> 
> Sections that appear after the relocation table are not relocated
> on system boot (except .bss, which has special handling).
> 
> With CONFIG_MIPS_ELF_APPENDED_DTB, the dtb is part of the
> vmlinux ELF, so it must be relocated together with everything else.
> 
> Fixes: 069fd766271d ("MIPS: Reserve space for relocation table")
> Signed-off-by: Yasha Cherikovsky <yasha.che3@gmail.com>
> Cc: Ralf Baechle <ralf@linux-mips.org>
> Cc: Paul Burton <paul.burton@mips.com>
> Cc: James Hogan <jhogan@kernel.org>
> Cc: linux-mips@linux-mips.org
> Cc: linux-kernel@vger.kernel.org

Applied to mips-fixes.

Thanks,
    Paul

[ This message was auto-generated; if you believe anything is incorrect
  then please email paul.burton@mips.com to report it. ]

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

end of thread, other threads:[~2019-03-11 18:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-08 12:58 [PATCH 0/1] Fix the combination of CONFIG_RELOCATABLE=y and CONFIG_MIPS_ELF_APPENDED_DTB=y Yasha Cherikovsky
2019-03-08 12:58 ` [PATCH 1/1] MIPS: Ensure ELF appended dtb is relocated Yasha Cherikovsky
2019-03-08 19:02   ` Paul Burton
2019-03-08 21:13     ` Yasha Cherikovsky
2019-03-11 18:14   ` Paul Burton

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.