From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org, Mark Rutland <mark.rutland@arm.com>,
Richard Henderson <richard.henderson@linaro.org>
Subject: Re: [Qemu-devel] [PATCH v2 4/4] hw/arm/boot: Honour image size field in AArch64 Image format kernels
Date: Thu, 13 Jun 2019 13:55:27 +0100 [thread overview]
Message-ID: <87ftodejb4.fsf@zen.linaroharston> (raw)
In-Reply-To: <20190516144733.32399-5-peter.maydell@linaro.org>
Peter Maydell <peter.maydell@linaro.org> writes:
> Since Linux v3.17, the kernel's Image header includes a field image_size,
> which gives the total size of the kernel including unpopulated data
> sections such as the BSS). If this is present, then return it from
> load_aarch64_image() as the true size of the kernel rather than
> just using the size of the Image file itself. This allows the code
> which calculates where to put the initrd to avoid putting it in
> the kernel's BSS area.
>
> This means that we should be able to reliably load kernel images
> which are larger than 128MB without accidentally putting the
> initrd or dtb in locations that clash with the kernel itself.
>
> Fixes: https://bugs.launchpad.net/qemu/+bug/1823998
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> hw/arm/boot.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/hw/arm/boot.c b/hw/arm/boot.c
> index e441393fdf5..fc6f37ba6cf 100644
> --- a/hw/arm/boot.c
> +++ b/hw/arm/boot.c
> @@ -910,6 +910,7 @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
> hwaddr *entry, AddressSpace *as)
> {
> hwaddr kernel_load_offset = KERNEL64_LOAD_ADDR;
> + uint64_t kernel_size = 0;
> uint8_t *buffer;
> int size;
>
> @@ -937,7 +938,10 @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
> * is only valid if the image_size is non-zero.
> */
> memcpy(&hdrvals, buffer + ARM64_TEXT_OFFSET_OFFSET, sizeof(hdrvals));
> - if (hdrvals[1] != 0) {
> +
> + kernel_size = le64_to_cpu(hdrvals[1]);
> +
> + if (kernel_size != 0) {
> kernel_load_offset = le64_to_cpu(hdrvals[0]);
>
> /*
> @@ -955,12 +959,21 @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
> }
> }
>
> + /*
> + * Kernels before v3.17 don't populate the image_size field, and
> + * raw images have no header. For those our best guess at the size
> + * is the size of the Image file itself.
> + */
> + if (kernel_size == 0) {
> + kernel_size = size;
> + }
> +
> *entry = mem_base + kernel_load_offset;
> rom_add_blob_fixed_as(filename, buffer, size, *entry, as);
>
> g_free(buffer);
>
> - return size;
> + return kernel_size;
> }
>
> static void arm_setup_direct_kernel_boot(ARMCPU *cpu,
--
Alex Bennée
WARNING: multiple messages have this Message-ID (diff)
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: Mark Rutland <mark.rutland@arm.com>,
qemu-arm@nongnu.org,
Richard Henderson <richard.henderson@linaro.org>
Subject: Re: [Qemu-devel] [PATCH v2 4/4] hw/arm/boot: Honour image size field in AArch64 Image format kernels
Date: Thu, 13 Jun 2019 13:55:27 +0100 [thread overview]
Message-ID: <87ftodejb4.fsf@zen.linaroharston> (raw)
In-Reply-To: <20190516144733.32399-5-peter.maydell@linaro.org>
Peter Maydell <peter.maydell@linaro.org> writes:
> Since Linux v3.17, the kernel's Image header includes a field image_size,
> which gives the total size of the kernel including unpopulated data
> sections such as the BSS). If this is present, then return it from
> load_aarch64_image() as the true size of the kernel rather than
> just using the size of the Image file itself. This allows the code
> which calculates where to put the initrd to avoid putting it in
> the kernel's BSS area.
>
> This means that we should be able to reliably load kernel images
> which are larger than 128MB without accidentally putting the
> initrd or dtb in locations that clash with the kernel itself.
>
> Fixes: https://bugs.launchpad.net/qemu/+bug/1823998
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> hw/arm/boot.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/hw/arm/boot.c b/hw/arm/boot.c
> index e441393fdf5..fc6f37ba6cf 100644
> --- a/hw/arm/boot.c
> +++ b/hw/arm/boot.c
> @@ -910,6 +910,7 @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
> hwaddr *entry, AddressSpace *as)
> {
> hwaddr kernel_load_offset = KERNEL64_LOAD_ADDR;
> + uint64_t kernel_size = 0;
> uint8_t *buffer;
> int size;
>
> @@ -937,7 +938,10 @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
> * is only valid if the image_size is non-zero.
> */
> memcpy(&hdrvals, buffer + ARM64_TEXT_OFFSET_OFFSET, sizeof(hdrvals));
> - if (hdrvals[1] != 0) {
> +
> + kernel_size = le64_to_cpu(hdrvals[1]);
> +
> + if (kernel_size != 0) {
> kernel_load_offset = le64_to_cpu(hdrvals[0]);
>
> /*
> @@ -955,12 +959,21 @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
> }
> }
>
> + /*
> + * Kernels before v3.17 don't populate the image_size field, and
> + * raw images have no header. For those our best guess at the size
> + * is the size of the Image file itself.
> + */
> + if (kernel_size == 0) {
> + kernel_size = size;
> + }
> +
> *entry = mem_base + kernel_load_offset;
> rom_add_blob_fixed_as(filename, buffer, size, *entry, as);
>
> g_free(buffer);
>
> - return size;
> + return kernel_size;
> }
>
> static void arm_setup_direct_kernel_boot(ARMCPU *cpu,
--
Alex Bennée
next prev parent reply other threads:[~2019-06-13 12:55 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-16 14:47 [Qemu-arm] [PATCH v2 0/4] hw/arm/boot: handle large Images more gracefully Peter Maydell
2019-05-16 14:47 ` [Qemu-devel] " Peter Maydell
2019-05-16 14:47 ` [Qemu-devel] [PATCH v2 1/4] hw/arm/boot: Don't assume RAM starts at address zero Peter Maydell
2019-06-13 12:44 ` Alex Bennée
2019-06-13 12:44 ` Alex Bennée
2019-05-16 14:47 ` [Qemu-devel] [PATCH v2 2/4] hw/arm/boot: Diagnose layouts that put initrd or DTB off the end of RAM Peter Maydell
2019-06-13 12:47 ` Alex Bennée
2019-06-13 12:47 ` Alex Bennée
2019-05-16 14:47 ` [Qemu-arm] [PATCH v2 3/4] hw/arm/boot: Avoid placing the initrd on top of the kernel Peter Maydell
2019-05-16 14:47 ` [Qemu-devel] " Peter Maydell
2019-06-13 12:53 ` [Qemu-arm] " Alex Bennée
2019-06-13 12:53 ` [Qemu-devel] " Alex Bennée
2019-07-19 16:47 ` Mark Rutland
2019-07-19 16:47 ` [Qemu-devel] " Mark Rutland
2019-07-22 11:59 ` [Qemu-arm] " Peter Maydell
2019-07-22 11:59 ` [Qemu-devel] " Peter Maydell
2019-07-22 12:56 ` [Qemu-arm] " Mark Rutland
2019-07-22 12:56 ` [Qemu-devel] " Mark Rutland
2019-05-16 14:47 ` [Qemu-devel] [PATCH v2 4/4] hw/arm/boot: Honour image size field in AArch64 Image format kernels Peter Maydell
2019-06-13 12:55 ` Alex Bennée [this message]
2019-06-13 12:55 ` Alex Bennée
2019-06-07 13:07 ` [Qemu-devel] [PATCH v2 0/4] hw/arm/boot: handle large Images more gracefully Peter Maydell
2019-06-07 14:12 ` [Qemu-arm] " Philippe Mathieu-Daudé
2019-06-07 14:12 ` Philippe Mathieu-Daudé
2019-06-07 14:07 ` Mark Rutland
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=87ftodejb4.fsf@zen.linaroharston \
--to=alex.bennee@linaro.org \
--cc=mark.rutland@arm.com \
--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 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.