From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8FAB91A1E2F for ; Tue, 13 Sep 2016 07:30:16 -0700 (PDT) Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 958B23DE3F; Tue, 13 Sep 2016 14:30:15 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-142.phx2.redhat.com [10.3.116.142]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8DEUEjc024659; Tue, 13 Sep 2016 10:30:14 -0400 To: Ard Biesheuvel , edk2-devel@ml01.01.org References: <1473776268-18207-1-git-send-email-ard.biesheuvel@linaro.org> Cc: julien.grall@arm.com From: Laszlo Ersek Message-ID: Date: Tue, 13 Sep 2016 16:30:13 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <1473776268-18207-1-git-send-email-ard.biesheuvel@linaro.org> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 13 Sep 2016 14:30:15 +0000 (UTC) Subject: Re: [PATCH] ArmVirtPkg/FdtParser: avoid unaligned accesses with the MMU off X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Sep 2016 14:30:16 -0000 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit 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 > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ard Biesheuvel > --- > 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