public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: edk2-devel@lists.01.org, lersek@redhat.com
Cc: julien.grall@arm.com, Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH] ArmVirtPkg/FdtParser: avoid unaligned accesses with the MMU off
Date: Tue, 13 Sep 2016 15:17:48 +0100	[thread overview]
Message-ID: <1473776268-18207-1-git-send-email-ard.biesheuvel@linaro.org> (raw)

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;
-- 
2.7.4



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

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

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=1473776268-18207-1-git-send-email-ard.biesheuvel@linaro.org \
    --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