All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robbie Harwood <rharwood@redhat.com>
To: Daniel Axtens <dja@axtens.net>, grub-devel@gnu.org
Cc: Daniel Axtens <dja@axtens.net>
Subject: Re: [PATCH 1/2] powerpc-ieee1275: load grub at 8MB, not 2MB
Date: Tue, 16 Nov 2021 10:17:20 -0500	[thread overview]
Message-ID: <jlg8rxoi0zj.fsf@redhat.com> (raw)
In-Reply-To: <20211116034205.463101-2-dja@axtens.net>

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

Daniel Axtens <dja@axtens.net> writes:

> RHEL9.0 builds were failing to boot with bizzare errors about module
> licensing.
>
> This was first reported under PFW but reproduces under SLOF.
>
> What is going wrong?
> --------------------
>
> Much debugging later, it turned out that this was because their image was
> greater than 2MB - 16KB in size:
>
>  - The core.elf was 2126152 = 0x207148 bytes in size with the following
>    program headers (per readelf):
>
> Entry point 0x200000
> There are 4 program headers, starting at offset 52
>
> Program Headers:
>   Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
>   LOAD           0x000160 0x00200000 0x00200000 0x21f98 0x2971c RWE 0x8
>   GNU_STACK      0x0220f8 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4
>   LOAD           0x0220f8 0x00232000 0x00232000 0x1e4e50 0x1e4e50 RWE 0x4
>   NOTE           0x206f48 0x00000000 0x00000000 0x00200 0x00000 R   0x4
>
>  - SLOF places the ELF file at 0x4000 (after the reserved space for
>    interrupt handlers etc.) upwards. The image was 2126152 = 0x207148
>    bytes in size, so it runs from 0x4000 - 0x20b148. We'll call 0x4000 the
>    load address.
>
> 0x0        0x4000         0x20b148
>  |----------|--------------|
>  | reserved | ELF contents |
>
>  - SLOF then copies the first LOAD program header (for .text). That runs
>    for 0x21f98 bytes. It runs from
>       (load addr + 0x160) to (load addr + 0x160 + 0x21f98)
>     = 0x4160 to 0x260f8
>    and we copy it to 0x200000 to 0x221f98. This overwrites the end of the
>    image:
>
> 0x0       0x4000     0x200000        0x221f98
>  |----------|------------|---------------|
>  | reserved | ELF cont.. | .text section |
>
>  - SLOF zeros the bss up to PhysAddr + MemSize = 0x22971c
>
> 0x0       0x4000      0x200000       0x221f98 0x22971c
>  |----------|------------|---------------|--------|
>  | reserved | ELF cont.. | .text section | bss 0s |
>
>  - SLOF then goes to fulfil the next LOAD header (for mods), which is
>    for 0x1e4e50 bytes. We copy from
>       (load addr + 0x220f8) to (load addr + 0x220f8 + 0x1e4e50)
>     = 0x260f8 to 0x20af48
>    and we copy it to 0x232000 to 0x416e50:
>
> 0x0       0x4000      0x200000       0x221f98 0x22971c
>  |----------|------------|---------------|--------|
>  | reserved | ELF cont.. | .text section | bss 0s |
>                |-------------|
>                | copied area |
>             0x260f8      0x20af48
>
>    This goes poorly:
>
> 0x0       0x4000      0x200000       0x221f98 0x22971c 0x232000 0x40bf08      0x416e50
>  |----------|------------|---------------|--------|-----|-----------|-------------|
>  | reserved | ELF cont.. | .text section | bss 0s | pad | some mods | .text start |
>
> This matches the observations on the running system - 0x40bf08 was where
> the contents of memory no longer matched the contents of the ELF file.
>
> This was reported as a license verification failure on SLOF as the
> last module's .module_license section fell past where the corruption
> began.
>
> load-base
> ---------
>
> From LoPAR:
>
> B.10.1 Load Address
>
>   The client’s load address is specified by the value of the load-base
>   Configuration Variable. The value of load-base defines the default
>   load address for client programs when using the load
>   method. Load-base shall be a real address in real mode or a virtual
>   address in virtual mode. Note that this address represents the area,
>   within the first LMB, into which the client program file will be
>   read by load; it does not correspond to the addresses at which the
>   program will be executed. All of physical memory from load-base to
>   either the start of OF physical memory or the end of physical
>   memory, whichever comes first, shall be available for loading the
>   client program.
>
>     Note: The load-base address represents the area into which the
>           client program will be read by load and does not correspond
>           to the address at which the program will be executed.
>
> We can specify load-base via setting a configuration variable, via
> CAS, or via an 1275 PowerPC Note.
>
> We can indeed override load-base and successfully load such a binary
> in SLOF. Drop to the OF shell and run:
>
> 0 > a000000 to load-base-override
> 0 > boot
>
> Sadly, asking people to drop to OF is not a super practical
> solution. SLOF ignores the 1275 PowerPC Note, which is the only thing
> we can (sanely) set in grub rather than in OF.
>
> PFW's load-base also defaults to 0x4000 but will honour the note. (The
> PFW team has been asking me to get grub to include the note and set
> appropriate values. See the next patch.)
>
> Fixing this
> -----------
>
> Unless I'm mistaken, if we want backwards compat with SLOF, we will
> need to change grub so that we ask the linker instruct the loader to
> load the program data somewhere else, giving us more headroom for the
> ELF image.
>
> This is fairly straight-forward to do. I've picked 8MB as that's a
> fairly common size for the PReP partition. We could potentially pick
> 4MB, I think I've seen some partitions that size too.
>
> The tests with powerpc32 using the OpenBIOS OF implementation seem to
> still work. I have no 32-bit Apple hardware to test on.
>
> Signed-off-by: Daniel Axtens <dja@axtens.net>

Shipping this one already.

Reviewed-by: Robbie Harwood <rharwood@redhat.com>

Be well,
--Robbie

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

  reply	other threads:[~2021-11-16 15:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16  3:42 [PATCH 0/2] powerpc-ieee1275: support larger core.elf images Daniel Axtens
2021-11-16  3:42 ` [PATCH 1/2] powerpc-ieee1275: load grub at 8MB, not 2MB Daniel Axtens
2021-11-16 15:17   ` Robbie Harwood [this message]
2021-11-16 15:31   ` Vladimir 'phcoder' Serbinenko
2021-11-16 16:37     ` Robbie Harwood
2021-11-16 16:48       ` John Paul Adrian Glaubitz
2021-11-16 17:19         ` John Paul Adrian Glaubitz
2021-11-16 18:07           ` Robbie Harwood
2021-11-16 21:02             ` Vladimir 'phcoder' Serbinenko
2021-11-22  9:31     ` John Paul Adrian Glaubitz
2021-11-16  3:42 ` [PATCH 2/2] ieee1275: set real-base in the PowerPC IEEE1275 Note to 32MB Daniel Axtens
2021-11-16  8:25   ` Michael Chang
2021-11-23 16:02 ` [PATCH 0/2] powerpc-ieee1275: support larger core.elf images John Paul Adrian Glaubitz
2021-11-24  0:51   ` Daniel Axtens
2021-11-25  7:53     ` John Paul Adrian Glaubitz
2022-01-14 16:43       ` Robbie Harwood
2022-01-14 16:54         ` John Paul Adrian Glaubitz
2022-01-14 18:30           ` John Paul Adrian Glaubitz
2022-05-17 13:30             ` Daniel Axtens

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=jlg8rxoi0zj.fsf@redhat.com \
    --to=rharwood@redhat.com \
    --cc=dja@axtens.net \
    --cc=grub-devel@gnu.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.