arm64: Obtain text offset from kernel image

Recent changes made to Linux 5.8 have outlined that kvmtool
hardcodes the text offset instead of reading it from the arm64
image itself.

To address this, import the image header structure into kvmtool
and do the right thing. 32bit guests are still loaded to their
usual locations.

While we're at it, check the image magic and default to the text
offset to be 0x80000 when image_size is 0, as described in the
kernel's booting.rst document.

Reported-by: Ard Biesheuvel <>
Signed-off-by: Marc Zyngier <>
Cc: Alexandru Elisei <>
Signed-off-by: Will Deacon <>
6 files changed