Received: from eggs.gnu.org ([2001:4830:134:3::10]:60520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAdjB-0000pM-Mj for qemu-devel@nongnu.org; Mon, 23 Apr 2018 11:50:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAdj6-0000O0-NC for qemu-devel@nongnu.org; Mon, 23 Apr 2018 11:50:05 -0400 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:43957) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fAdj6-0000Nl-IV for qemu-devel@nongnu.org; Mon, 23 Apr 2018 11:50:00 -0400 Received: by mail-qt0-x241.google.com with SMTP id l11-v6so18204861qtj.10 for ; Mon, 23 Apr 2018 08:50:00 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= References: <20180421211652.14794-1-f4bug@amsat.org> <20180423031639.GB19804@umbus.fritz.box> <73a63694-d656-959c-cd68-a26c28fbbf72@amsat.org> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Message-ID: Date: Mon, 23 Apr 2018 12:49:56 -0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH] loader: Fix misaligned member access List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: David Gibson , =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , Paul Burton , QEMU Developers On 04/23/2018 12:32 PM, Peter Maydell wrote: > On 23 April 2018 at 15:26, Philippe Mathieu-Daudé wrote: >>> On 04/23/2018 11:04 AM, Peter Maydell wrote: >>>> On 23 April 2018 at 14:57, Philippe Mathieu-Daudé wrote: >>>>> On 04/23/2018 12:16 AM, David Gibson wrote: >>>>>> On Sun, Apr 22, 2018 at 11:41:20AM +0100, Peter Maydell wrote: >>>>>>> If we need to do an unaligned load, then ldl_p() is the >>>>>>> right way to do it. (We could also just do >>>>>>> *addr = ldl_be_p(prop) but we maybe don't want to >>>>>>> bake in knowledge that FDT is big-endian). >>>>> >>>>> Since it is, ldl_be_p() seems the clever/cleaner way indeed, but then we >>>>> assume we know the underlying type of fdt32_t; while using memcpy we >>>>> respect the FDT API. >>>> >>>> *addr = fdt32_to_cpu(ldl_p(prop)); >>>> >>>> is better than a raw memcpy still. >> >> ldl_p() is target-specific, I'd prefer loader code to be target agnostic. >> >> Since FDT is big-endian, are you OK I use, as you suggested, >> >> *addr = ldq_be_p(prop); >> >> (with a comment about FDT being BE)? > > Oops, yes, forgot that ldq_p is the target-endian version. > ldq_he_p() is the "load in host endianness" function, so > *addr = fdt64_to_cpu(ldq_he_p(prop)); I think I never noticed ldq_he_p(), good to know. $ git grep -E '(ld|st)._he_' net/checksum.c:130: stw_he_p(&tcp->th_sum, 0); net/checksum.c:151: stw_he_p(&udp->uh_sum, 0); util/bufferiszero.c:47: uint64_t t = ldq_he_p(buf); util/bufferiszero.c:61: t |= ldq_he_p(buf + len - 8); Not many users...