U-boot Archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] sandbox: correct determination of the text base
@ 2021-05-15 17:29 Heinrich Schuchardt
  2021-05-19 15:34 ` Simon Glass
  2021-06-05 16:02 ` Simon Glass
  0 siblings, 2 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2021-05-15 17:29 UTC (permalink / raw
  To: u-boot

os_find_text_base() assumes that first line of /proc/self/maps holds
information about the text. Hence we must call the function before calling
os_malloc() which calls mmap(0x10000000,).

Failure to do so has led to incorrect values for pc_reloc when an
exception was reported

    => exception undefined

    Illegal instruction
    pc = 0x5628d82e9d3c, pc_reloc = 0x5628c82e9d3c

as well as incorrect output of the bdinfo command

    => bdinfo
    relocaddr   = 0x0000000007858000
    reloc off   = 0x0000000010000000

Fixes: b308d9fd18fa ("sandbox: Avoid using malloc() for system state")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
This patch must be applied after
[PATCH 1/1] sandbox: ensure that state->ram_buf is in low memory
---
 arch/sandbox/cpu/start.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index 1388dba895..4000bcc4f1 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -435,10 +435,13 @@ void sandbox_reset(void)
 int main(int argc, char *argv[])
 {
 	struct sandbox_state *state;
+	void * text_base;
 	gd_t data;
 	int size;
 	int ret;

+	text_base = os_find_text_base();
+
 	/*
 	 * This must be the first invocation of os_malloc() to have
 	 * state->ram_buf in the low 4 GiB.
@@ -459,7 +462,7 @@ int main(int argc, char *argv[])

 	memset(&data, '\0', sizeof(data));
 	gd = &data;
-	gd->arch.text_base = os_find_text_base();
+	gd->arch.text_base = text_base;

 	state = state_get_current();
 	if (os_parse_args(state, argc, argv))
--
2.30.2

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

* [PATCH 1/1] sandbox: correct determination of the text base
  2021-05-15 17:29 [PATCH 1/1] sandbox: correct determination of the text base Heinrich Schuchardt
@ 2021-05-19 15:34 ` Simon Glass
  2021-06-05 16:02 ` Simon Glass
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2021-05-19 15:34 UTC (permalink / raw
  To: u-boot

Hi Heinrich,

On Sat, 15 May 2021 at 11:29, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> os_find_text_base() assumes that first line of /proc/self/maps holds
> information about the text. Hence we must call the function before calling
> os_malloc() which calls mmap(0x10000000,).
>
> Failure to do so has led to incorrect values for pc_reloc when an
> exception was reported
>
>     => exception undefined
>
>     Illegal instruction
>     pc = 0x5628d82e9d3c, pc_reloc = 0x5628c82e9d3c
>
> as well as incorrect output of the bdinfo command
>
>     => bdinfo
>     relocaddr   = 0x0000000007858000
>     reloc off   = 0x0000000010000000
>
> Fixes: b308d9fd18fa ("sandbox: Avoid using malloc() for system state")
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> This patch must be applied after
> [PATCH 1/1] sandbox: ensure that state->ram_buf is in low memory
> ---
>  arch/sandbox/cpu/start.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

> diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
> index 1388dba895..4000bcc4f1 100644
> --- a/arch/sandbox/cpu/start.c
> +++ b/arch/sandbox/cpu/start.c
> @@ -435,10 +435,13 @@ void sandbox_reset(void)
>  int main(int argc, char *argv[])
>  {
>         struct sandbox_state *state;
> +       void * text_base;
>         gd_t data;
>         int size;
>         int ret;
>

I think you should have a comment about this needing to be first.

> +       text_base = os_find_text_base();
> +
>         /*
>          * This must be the first invocation of os_malloc() to have
>          * state->ram_buf in the low 4 GiB.
> @@ -459,7 +462,7 @@ int main(int argc, char *argv[])
>
>         memset(&data, '\0', sizeof(data));
>         gd = &data;
> -       gd->arch.text_base = os_find_text_base();
> +       gd->arch.text_base = text_base;
>
>         state = state_get_current();
>         if (os_parse_args(state, argc, argv))
> --
> 2.30.2
>

Regards,
Simon

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

* Re: [PATCH 1/1] sandbox: correct determination of the text base
  2021-05-15 17:29 [PATCH 1/1] sandbox: correct determination of the text base Heinrich Schuchardt
  2021-05-19 15:34 ` Simon Glass
@ 2021-06-05 16:02 ` Simon Glass
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2021-06-05 16:02 UTC (permalink / raw
  To: Simon Glass; +Cc: Patrick Delaunay, U-Boot Mailing List, Heinrich Schuchardt

Hi Heinrich,

On Sat, 15 May 2021 at 11:29, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> os_find_text_base() assumes that first line of /proc/self/maps holds
> information about the text. Hence we must call the function before calling
> os_malloc() which calls mmap(0x10000000,).
>
> Failure to do so has led to incorrect values for pc_reloc when an
> exception was reported
>
>     => exception undefined
>
>     Illegal instruction
>     pc = 0x5628d82e9d3c, pc_reloc = 0x5628c82e9d3c
>
> as well as incorrect output of the bdinfo command
>
>     => bdinfo
>     relocaddr   = 0x0000000007858000
>     reloc off   = 0x0000000010000000
>
> Fixes: b308d9fd18fa ("sandbox: Avoid using malloc() for system state")
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> This patch must be applied after
> [PATCH 1/1] sandbox: ensure that state->ram_buf is in low memory
> ---
>  arch/sandbox/cpu/start.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!

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

end of thread, other threads:[~2021-06-05 16:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-15 17:29 [PATCH 1/1] sandbox: correct determination of the text base Heinrich Schuchardt
2021-05-19 15:34 ` Simon Glass
2021-06-05 16:02 ` Simon Glass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).