Re: [PATCH v2 4/8] KVM: arm64: Generate hyp relocation data

From: Marc Zyngier
Date: Sat Jan 30 2021 - 08:48:13 EST


On Fri, 29 Jan 2021 21:43:25 +0000,
Guenter Roeck <linux@xxxxxxxxxxxx> wrote:
>
> Hi,
>
> On Tue, Jan 05, 2021 at 06:05:37PM +0000, David Brazdil wrote:
> > Add a post-processing step to compilation of KVM nVHE hyp code which
> > calls a custom host tool (gen-hyprel) on the partially linked object
> > file (hyp sections' names prefixed).
> >
> > The tool lists all R_AARCH64_ABS64 data relocations targeting hyp
> > sections and generates an assembly file that will form a new section
> > .hyp.reloc in the kernel binary. The new section contains an array of
> > 32-bit offsets to the positions targeted by these relocations.
> >
> > Since these addresses of those positions will not be determined until
> > linking of `vmlinux`, each 32-bit entry carries a R_AARCH64_PREL32
> > relocation with addend <section_base_sym> + <r_offset>. The linker of
> > `vmlinux` will therefore fill the slot accordingly.
> >
> > This relocation data will be used at runtime to convert the kernel VAs
> > at those positions to hyp VAs.
> >
> > Signed-off-by: David Brazdil <dbrazdil@xxxxxxxxxx>
>
> This patch results in the following error for me.
>
> error: arch/arm64/kvm/hyp/nvhe/kvm_nvhe.tmp.o: assertion elf.ehdr->e_ident[5] == 1 failed (lhs=2, rhs=1, line=250)
>
> The problem is seen when trying to build aarch64 images in big endian
> mode.
>
> Te script used to reproduce the problem as well as bisect results are
> attached.

I came up with the following patch, which allows the kernel to link
and boot. I don't have any BE userspace, so I didn't verify that I
could boot a guest (the hypervisor does correctly initialise though).

It's not exactly pretty, but it does the job...

Thanks,

M.