All of lore.kernel.org
 help / color / mirror / Atom feed
From: Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>
To: Pavel Machek <pavel@denx.de>, Ulrich Hecht <uli@fpond.eu>
Cc: "cip-dev@lists.cip-project.org" <cip-dev@lists.cip-project.org>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Florian Bezdeka <florian.bezdeka@siemens.com>,
	Chris Paterson <Chris.Paterson2@renesas.com>,
	Hung Tran <hung.tran.jy@renesas.com>
Subject: RE: [cip-dev] ldconfig segfault on RZ/Five was Re: Preparing isar-cip-core for RZ/Five
Date: Tue, 29 Nov 2022 18:57:02 +0000	[thread overview]
Message-ID: <OSZPR01MB70191A1A9FD7FAE4EF4F8FF0AA129@OSZPR01MB7019.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <20221013214737.GC14791@duo.ucw.cz>

[-- Attachment #1: Type: text/plain, Size: 4032 bytes --]

Hi All,

> -----Original Message-----
> From: Pavel Machek <pavel@denx.de>
> Sent: 13 October 2022 22:48
> To: Ulrich Hecht <uli@fpond.eu>
> Cc: cip-dev@lists.cip-project.org; Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>;
> Jan Kiszka <jan.kiszka@siemens.com>; Florian Bezdeka <florian.bezdeka@siemens.com>; Chris Paterson
> <Chris.Paterson2@renesas.com>; Hung Tran <hung.tran.jy@renesas.com>; Pavel Machek <pavel@denx.de>
> Subject: Re: [cip-dev] ldconfig segfault on RZ/Five was Re: Preparing isar-cip-core for RZ/Five
> 
> Hi!
> 
> > > On 10/12/2022 11:50 AM CEST Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> > > I did a quick test with the patches pointed by Florian but unfortunately ldconfig still fails.
> >
> > I did some experiments on RZ/Five with this issue, and I'm almost positive that there is something
> wrong (or doesn't work as documented) with the icache handling on this SoC.
> >
> > 1. The issue only affects non-PIE executables (there are very few of those, basically just ldconfig,
> gcc, cpp and gcov* on the Debian system), and it occurs very early during the execution of the
> program. According to the datasheet, the cache on the ax45mp-1c core is virtually indexed, so it is
> unlikely that a PIE executable will ever hit anything in the cache when newly loaded, but it is much
> more likely with non-PIE executables.
> >
> 
> This is very good observation. Thanks!
> 
> And indeed it looks like _any_ non-PIE executable fails. See:
> 

Just a brief about the issue and solution:

TEXT_START_ADDR is the start of text segment of an application. This is being set to 0x10000 for RISCV platforms.

So when an application is compiled with the static flag the load would start from 0x10000 - xyz (depending on size of the application)

Entry point 0x101c0
There are 5 program headers, starting at offset 64Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000010000 0x0000000000010000
                 0x0000000000059b48 0x0000000000059b48  R E    0x1000
  LOAD           0x0000000000059b60 0x000000000006ab60 0x000000000006ab60
                 0x0000000000001f68 0x0000000000003528  RW     0x1000
So for the above application which is compiled statically we can see the entry point is 0x101c0 and load 0x0000000000010000.

Andes cores have local memories ILM and DLM that are mapped in the region H'0_0003_0000 - H'0_0004_FFFF on the RZ/Five SoC. When the virtual address falls in this range the MMU doesnt trigger a page fault and assume the virtual address as physical address and hence the application fails to run (panics somewhere).

So to avoid this issue we set the TEXT_START_ADDR to 0x50000 so that virtual address of any statically compiled application doesnt fall in the range of H'0_0003_0000 - H'0_0004_FFFF.

Elf file type is EXEC (Executable file)
Entry point 0x504e4
There are 5 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000050000 0x0000000000050000
                 0x0000000000057dc8 0x0000000000057dc8  R E    0x1000
  LOAD           0x00000000000585b8 0x00000000000a95b8 0x00000000000a95b8
                 0x0000000000004ee0 0x00000000000064b0  RW     0x1000
  NOTE           0x0000000000000158 0x0000000000050158 0x0000000000050158
                 0x0000000000000044 0x0000000000000044  R      0x4

So now with the fix for statically compiled application we can see its offsetted and entry point is 0x504e4 and load is at 0x0000000000050000. So with this we are for sure the MMU will always trigger a page fault.

I have attached a patch for binutils to the email. We plan to upstream this patch to binutils soon. 

Cheers,
Prabhakar

[-- Attachment #2: 0001-ld-emulparams-elf32lriscv-defs.sh-Adjust-TEXT_START_.patch --]
[-- Type: application/octet-stream, Size: 1307 bytes --]

From 91b9d727d696701bc0fa09a66a91fbfe3a639e55 Mon Sep 17 00:00:00 2001
From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Date: Tue, 29 Nov 2022 11:14:08 +0000
Subject: [PATCH] ld: emulparams: elf32lriscv-defs.sh: Adjust TEXT_START_ADDR
 for RZ/Five
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

With applications compiled with a static flag the virtual address for the
applications may fall within H’0_0003_0000 - H’0_0004_FFFF where the ILM
and DLM blocks of the AX45MP exist.

The MMU won't trigger page faults when the virtual address falls in the
range of AX45MP local memory. So to make sure statically compiled
applications run successfully, adjust the TEXT_START_ADDR to 0x50000.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 ld/emulparams/elf32lriscv-defs.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ld/emulparams/elf32lriscv-defs.sh b/ld/emulparams/elf32lriscv-defs.sh
index 91015d44..bba34c17 100644
--- a/ld/emulparams/elf32lriscv-defs.sh
+++ b/ld/emulparams/elf32lriscv-defs.sh
@@ -26,7 +26,7 @@ case "$target" in
     ;;
 esac
 
-TEXT_START_ADDR=0x10000
+TEXT_START_ADDR=0x50000
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
 
-- 
2.25.1


  reply	other threads:[~2022-11-29 18:57 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-03 18:36 Preparing isar-cip-core for RZ/Five Jan Kiszka
2022-10-03 20:12 ` Chris Paterson
2022-10-04  7:15   ` Jan Kiszka
2022-10-04 18:28     ` Jan Kiszka
2022-10-04 19:36       ` Jan Kiszka
2022-10-04 19:47         ` Jan Kiszka
2022-10-05 18:21           ` Pavel Machek
2022-10-06  6:29             ` Jan Kiszka
2022-10-06  6:49               ` Jan Kiszka
2022-10-06  7:07                 ` Jan Kiszka
2022-10-06  7:08                 ` Prabhakar Mahadev Lad
2022-10-06  7:26                   ` Jan Kiszka
2022-10-06 11:43               ` Pavel Machek
2022-10-06 11:51                 ` Jan Kiszka
2022-10-06 22:07                   ` ldconfig segfault on RZ/Five was " Pavel Machek
2022-10-06 22:32                     ` Pavel Machek
2022-10-07  8:18                       ` Jan Kiszka
2022-10-07 10:19                         ` Pavel Machek
2022-10-08  8:27                           ` Jan Kiszka
2022-10-09  8:29                             ` Jan Kiszka
2022-10-09  8:42                               ` [cip-dev] " Biju Das
2022-10-11  9:30                                 ` Jan Kiszka
2022-10-11 10:34                                   ` Biju Das
2022-10-11 18:51                                     ` Florian Bezdeka
2022-10-11 20:15                                       ` Jan Kiszka
2022-10-11 20:48                                         ` Prabhakar Mahadev Lad
2022-10-12  9:50                                           ` Prabhakar Mahadev Lad
2022-10-13  8:36                                             ` Ulrich Hecht
2022-10-13 10:35                                               ` Pavel Machek
2022-10-13 21:47                                               ` Pavel Machek
2022-11-29 18:57                                                 ` Prabhakar Mahadev Lad [this message]
2022-12-10  7:23                                                   ` Jan Kiszka
2022-12-10 20:25                                                     ` Pavel Machek
2022-12-12 13:51                                                       ` Prabhakar Mahadev Lad
2022-12-12 13:24                                                     ` Prabhakar Mahadev Lad
2022-10-09 19:20                               ` Chris Paterson
2022-10-05  5:43       ` [cip-dev] " Biju Das
2022-10-04 22:30   ` Prabhakar Mahadev Lad
2022-10-05  5:45     ` Jan Kiszka

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=OSZPR01MB70191A1A9FD7FAE4EF4F8FF0AA129@OSZPR01MB7019.jpnprd01.prod.outlook.com \
    --to=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=Chris.Paterson2@renesas.com \
    --cc=cip-dev@lists.cip-project.org \
    --cc=florian.bezdeka@siemens.com \
    --cc=hung.tran.jy@renesas.com \
    --cc=jan.kiszka@siemens.com \
    --cc=pavel@denx.de \
    --cc=uli@fpond.eu \
    /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.