public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>, edk2-devel@ml01.01.org
Cc: julien.grall@arm.com
Subject: Re: [PATCH] ArmVirtPkg/FdtParser: avoid unaligned accesses with the MMU off
Date: Tue, 13 Sep 2016 16:30:13 +0200	[thread overview]
Message-ID: <e67354cf-8df6-ddfb-973c-0c3fe4e63c97@redhat.com> (raw)
In-Reply-To: <1473776268-18207-1-git-send-email-ard.biesheuvel@linaro.org>

On 09/13/16 16:17, Ard Biesheuvel wrote:
> When parsing the device tree to find the memory node, we are still running
> with the MMU off, which means unaligned memory accesses are not allowed.
> Since the FDT only mandates 32-bit alignment, 64-bit quantities are not
> guaranteed to appear naturally aligned, and so should be accessed using
> 32-bit accesses instead.
> 
> Reported-by: Julien Grall <julien.grall@arm.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c | 14 ++++++--------
>  ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c  | 14 ++++++--------
>  2 files changed, 12 insertions(+), 16 deletions(-)
> 
> diff --git a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c
> index 46a5fe6409f6..afdc81a8839d 100644
> --- a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c
> +++ b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c
> @@ -65,17 +65,15 @@ FindMemnode (
>      return FALSE;
>    }
>  
> -  if (AddressCells == 1) {
> -    *SystemMemoryBase = fdt32_to_cpu (*Prop);
> -  } else {
> -    *SystemMemoryBase = fdt64_to_cpu (*(UINT64 *)Prop);
> +  *SystemMemoryBase = fdt32_to_cpu (Prop[0]);
> +  if (AddressCells > 1) {
> +    *SystemMemoryBase = (*SystemMemoryBase << 32) | fdt32_to_cpu (Prop[1]);
>    }
>    Prop += AddressCells;
>  
> -  if (SizeCells == 1) {
> -    *SystemMemorySize = fdt32_to_cpu (*Prop);
> -  } else {
> -    *SystemMemorySize = fdt64_to_cpu (*(UINT64 *)Prop);
> +  *SystemMemorySize = fdt32_to_cpu (Prop[0]);
> +  if (SizeCells > 1) {
> +    *SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);
>    }
>  
>    return TRUE;
> diff --git a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c
> index 992932ee9754..38fd5d3ed00c 100644
> --- a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c
> +++ b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c
> @@ -65,17 +65,15 @@ FindMemnode (
>      return FALSE;
>    }
>  
> -  if (AddressCells == 1) {
> -    *SystemMemoryBase = fdt32_to_cpu (*Prop);
> -  } else {
> -    *SystemMemoryBase = fdt64_to_cpu (*(UINT64 *)Prop);
> +  *SystemMemoryBase = fdt32_to_cpu (Prop[0]);
> +  if (AddressCells > 1) {
> +    *SystemMemoryBase = (*SystemMemoryBase << 32) | fdt32_to_cpu (Prop[1]);
>    }
>    Prop += AddressCells;
>  
> -  if (SizeCells == 1) {
> -    *SystemMemorySize = fdt32_to_cpu (*Prop);
> -  } else {
> -    *SystemMemorySize = fdt64_to_cpu (*(UINT64 *)Prop);
> +  *SystemMemorySize = fdt32_to_cpu (Prop[0]);
> +  if (SizeCells > 1) {
> +    *SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);
>    }
>  
>    return TRUE;
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>


      reply	other threads:[~2016-09-13 14:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-13 14:17 [PATCH] ArmVirtPkg/FdtParser: avoid unaligned accesses with the MMU off Ard Biesheuvel
2016-09-13 14:30 ` Laszlo Ersek [this message]

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-list 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=e67354cf-8df6-ddfb-973c-0c3fe4e63c97@redhat.com \
    --to=devel@edk2.groups.io \
    /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