From: Jean-Philippe Brucker <jean-philippe@linaro.org>
To: Gavin Shan <gshan@redhat.com>
Cc: "Itaru Kitayama" <itaru.kitayama@linux.dev>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
qemu-devel@nongnu.org, qemu-arm <qemu-arm@nongnu.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Ard Biesheuvel" <ardb@kernel.org>
Subject: Re: Unexpected error in rme_configure_one() at ../target/arm/kvm-rme.c:159
Date: Thu, 6 Jun 2024 12:03:34 +0100 [thread overview]
Message-ID: <20240606110334.GA3707954@myrica> (raw)
In-Reply-To: <1089f920-aff9-4d16-829d-5d058908a11e@redhat.com>
On Thu, Jun 06, 2024 at 03:05:02PM +1000, Gavin Shan wrote:
> > This commit moves the page tables from .rodata to .data. When linking
> > IdMap.obj into ArmPlatformPrePeiCore.dll, the alignment of the .text
> > section changes from 0x1000 to 0x800. This change comes from the linker
> > script putting .rodata into .text. I don't know why the included .rodata
> > alignment affects the .text alignment, but I don't think it matters here.
> >
> > In GenFw, ScanSections64() calculates a mCoffAlignment as the max
> > .text/.data/.hii section alignement. Since with this commit, .data
> > alignement (0x1000) becomes larger than .text (0x800), it picks 0x1000 as
> > the output text offset, and then WriteSections64() complains that this
> > offset isn't equal to the input .text alignment modulo 0x1000.
> >
> > The linker script says:
> >
> > /*
> > * The alignment of the .data section should be less than or equal to the
> > * alignment of the .text section. This ensures that the relative offset
> > * between these sections is the same in the ELF and the PE/COFF versions of
> > * this binary.
> > */
> >
> > but that's not what we're getting. I don't have a fix yet, other than
> > forcing the .text and .data alignment to 4k.
> >
>
> Jean, thanks for your explanation. Right, the issue is caused by mismatched
> alignments for ELF and PE/COFF sections. I ever dumped the variables at the
> failing point, showing the mismatched alignments (0x800 vs 0x1000). Apart from
> that, the virtual address of 'text' section is aligned to 0x800 instead of
> 0x1000 after ArmPlatformPrePeiCore.dll is dumped by 'readelf'.
>
> SecHdr->sh_addr: 0x800 <<< Mismatched alignment between ELF and PE/COFF
> SecOffset: 0x1000
> SymShdr->sh_addr: 0x800
> mCoffSectionsOffset[Sym->st_shndx]: 0x1000
> GenFw: ERROR 3000: Invalid
> WriteSections64(): /home/gavin/sandbox/CCA/edk2-guest/Build/ArmVirtQemu-AARCH64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.dll AARCH64 small code model requires identical ELF and PE/COFF section offsets modulo 4 KB.
>
> # readelf -S Build/ArmVirtQemu-AARCH64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore/DEBUG/ArmPlatformPrePeiCore.dll
> Section Headers:
> [Nr] Name Type Address Offset
> Size EntSize Flags Link Info Align
> [ 0] NULL 0000000000000000 00000000
> 0000000000000000 0000000000000000 0 0 0
> [ 1] .text PROGBITS 0000000000000800 00000800 <<< Aligned to 0x800
> 00000000000051b8 0000000000000000 AX 0 0 2048
>
> With the following changes, I'm able to build the firmware successfully. I don't
> see how COMMONPAGESIZE is sorted out because I don't find its definition in the
> source code.
It's a ld builtin, set on the command-line with "-z common-page-size=X" by
Conf/tools_def.txt, in this case I believe DEBUG_GCC5_AARCH64_DLINK_XIPFLAGS.
>
> diff --git a/BaseTools/Scripts/GccBase.lds b/BaseTools/Scripts/GccBase.lds
> index 9f27e83bb0..5463df47a9 100644
> --- a/BaseTools/Scripts/GccBase.lds
> +++ b/BaseTools/Scripts/GccBase.lds
> @@ -20,7 +20,8 @@ SECTIONS {
> */
> . = PECOFF_HEADER_SIZE;
> - .text : ALIGN(CONSTANT(COMMONPAGESIZE)) {
> + /* .text : ALIGN(CONSTANT(COMMONPAGESIZE)) { */^M
> + .text : ALIGN(4096) {^M
Build (after clean) fails for me if I only change the .text
alignment, I need .data as well. So changing Conf/tools_def.txt is easier.
I'll try to find a proper fix but it will take me some time to understand
GenFw.
> > > > Note that the guest edk2 is optional and experimental, you can use direct
> > > > kernel boot to get a working demo quicker.
> > > >
> > >
> > > I never did this before. Could you please provide the detailed steps on this?
> >
> > Removing the -bios parameter to QEMU should be enough. You can also add
> > 'earlycon' to -append to show early boot errors.
> >
>
> I didn't get a chance to try this yet since the host can't be brought up now.
> I will try this later. I originally thought some sort of boot wrapper is needed
> so that the kernel image has the capability to boot itself. For example, Mark
> Rutland's boot wrapper [1] can be leveraged in this case. I don't think Image has
> the capability to boot itself, right?
Yes QEMU can set up everything so that the Image boots on its own. What
the boot-wrapper does is minimal hardware initialization, handling PSCI
calls and passing the DTB pointer in x0. But that's only needed when using
the Arm FastModel (boot-wrapper is a lightweight firmware specifically for
the FastModel). QEMU can do all that itself so you can boot a kernel
without any firmware.
Using edk2 in the Realm guest will be needed for example to boot a distro
image which contains the kernel, but direct kernel boot is useful both for
prototyping and real-life use cases like confidential containers and some
cloud VMs.
Thanks,
Jean
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/mark/boot-wrapper-aarch64.git
>
> Thanks,
> Gavin
>
next prev parent reply other threads:[~2024-06-06 11:04 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-30 4:30 Unexpected error in rme_configure_one() at ../target/arm/kvm-rme.c:159 Itaru Kitayama
2024-05-30 13:30 ` Peter Maydell
2024-05-30 13:30 ` Philippe Mathieu-Daudé
2024-05-31 4:19 ` Itaru Kitayama
2024-05-31 6:23 ` Gavin Shan
2024-05-31 15:09 ` Jean-Philippe Brucker
2024-05-31 15:24 ` Ard Biesheuvel
2024-06-04 18:08 ` Jean-Philippe Brucker
2024-06-04 19:04 ` Ard Biesheuvel
2024-06-01 10:14 ` Gavin Shan
2024-06-03 8:24 ` Jean-Philippe Brucker
2024-06-04 3:02 ` Gavin Shan
2024-06-04 11:15 ` Jean-Philippe Brucker
2024-06-05 1:28 ` Gavin Shan
2024-06-05 15:56 ` Jean-Philippe Brucker
2024-06-06 5:05 ` Gavin Shan
2024-06-06 10:13 ` Gavin Shan
2024-06-06 11:03 ` Jean-Philippe Brucker [this message]
2024-05-31 9:57 ` Peter Maydell
2024-05-31 10:21 ` Jean-Philippe Brucker
2024-05-31 14:16 ` Itaru Kitayama
2024-05-31 16:09 ` Jean-Philippe Brucker
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=20240606110334.GA3707954@myrica \
--to=jean-philippe@linaro.org \
--cc=ardb@kernel.org \
--cc=gshan@redhat.com \
--cc=itaru.kitayama@linux.dev \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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 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 NNTP newsgroup(s).