From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC6F0EB64D9 for ; Mon, 10 Jul 2023 21:40:02 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D3D9E867C0; Mon, 10 Jul 2023 23:39:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="Bzh/6cyP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E3B728679D; Mon, 10 Jul 2023 23:39:13 +0200 (CEST) Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2110886794 for ; Mon, 10 Jul 2023 23:39:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-4f76a0a19d4so7603331e87.2 for ; Mon, 10 Jul 2023 14:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689025141; x=1691617141; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=1vvEoSxn9XYwwfwrWLjdWTF8i0YYtj1Am1z6zdl6sBg=; b=Bzh/6cyPeh8rAOHznA5EgVBd4Mybod4Br0jyRvQ26kBSZMdQA909K9jfEdSYVwzl4t ptMlf9Bp9g/QtmQGUgEXZxSHX2N75tZHy7gK9B+xLzsIK/txxpKZeacpoWLjG9PbOcH0 Xj9FGQI8oKr6YfgOlwM/9SOrxBrbA0ffkReuB6D0HcmnZtGViIH5N7jKEpGgF1+0de3f lFgaSTnnJlIgny/6HsjSPotjP1bwUOPGGgeHGhZ485cKJytPTTWVKTbYmVOiHd1ePKJP /Z6U6yZdojNbt2RZQIAPOt5VPbVZ/jotvriQIVnCilmymKT8srZmnKAxOandRsHzOOrR TmeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689025141; x=1691617141; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1vvEoSxn9XYwwfwrWLjdWTF8i0YYtj1Am1z6zdl6sBg=; b=aefQxJsa9qZt9ncZTq9LUFgbSFjJGSRX287MwwqSaf7WXsK+04BcJNLq7K2AufM+4u j0o+PBBjKqczE16F9sY0cYEgFK4V8rtTHPvcc000d4JslnVKEd2SmsJt1OWOyuKmWD2r IMsEFMnTAvqyLIMofvak516+W/S7mxZYR/d6xyNEUXIYKjhvUraYMrsB5MPZSAlxRLye NYYgSbQmeS+QhSHfz/dzMJP1Ld5pHz3pM1Rd2vncZqCoFen5R3JOzR9r9tWD2RUYoXIs neJQKVia9K00iiGnvRPDQnWa4/xeaYIQe4okrdLqKeRt3X5B5CZji8xSyeF67dc9OxMX za9A== X-Gm-Message-State: ABy/qLYgKFjpeEFYXxpF65Pizl+NlY2gh3boFGUubeNSoqXGvmEezMtM kyVf0o3Ki2zamyqdiX+oQGCAwlT+xAV3l0VxeeU57w== X-Google-Smtp-Source: APBJJlGiIgyStC9tn6fnF+sK3fXt714qWdOFjsuCYLTvTPFvFs/amxiEbsJrOJVfwzhLLNAQICJZNvcdPJcco5Ealc0= X-Received: by 2002:a05:6512:3095:b0:4f4:b13a:d683 with SMTP id z21-20020a056512309500b004f4b13ad683mr12393633lfd.69.1689025141467; Mon, 10 Jul 2023 14:39:01 -0700 (PDT) MIME-Version: 1.0 References: <20230710201339.GZ148062@bill-the-cat> In-Reply-To: <20230710201339.GZ148062@bill-the-cat> From: Simon Glass Date: Mon, 10 Jul 2023 15:38:41 -0600 Message-ID: Subject: Re: [BUG] fdt_pack_reg in common/fdt_support.c can cause crash from unaligned access To: Tom Rini Cc: David Virag , u-boot@lists.denx.de Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Hi, On Mon, 10 Jul 2023 at 14:13, Tom Rini wrote: > > On Mon, Jul 10, 2023 at 01:45:46PM -0600, Simon Glass wrote: > > Hi David, > > > > On Sun, 9 Jul 2023 at 19:11, David Virag wrote: > > > > > > Hi, > > > > > > I'm trying to port U-Boot to a new board (Samsung JACKPOTLTE, ARMv8, > > > Exynos7885) but when CONFIG_ARCH_FIXUP_FDT_MEMORY is enabled, the bootm > > > command leads to an unaligned memory access, which results in a > > > synchronous abort. > > > > > > After a long debugging session, I concluded that fdt_pack_reg in > > > common/fdt_support.c writes to unaligned addresses in its for loop. > > > In the case of address_cells being 2, and size_cells being 1, the > > > buffer pointer gets incremented by 12 in each loop, making the second > > > iteration (i=1) write a 64bit value to a non 64bit aligned address. > > > > > > Turning the alignment check enable bit (A) off in SCTLR makes the > > > function work as intended. I couldn't find code that touches this bit, > > > but I may have missed something. I don't think writing in two parts > > > should be the fix, but something should be done about this. As far as I > > > understand, any arm64 board that has this bit turned on, either from > > > previous code or just the initial status of the bit after power on, > > > could crash here. > > > > > > This is on top of the latest commit as of now > > > (0beb649053b86b2cfd5cf55a0fc68bc2fe91a430) > > > > > > What should be done here? > > > > +Tom Rini > > ... I was hoping you had an idea Simon. Is this part of the code we > share with libfdt itself, or one of the helpers we made? Hmmm, is the DT itself 64-bit aligned? It needs to be. Looking at fdt_find_separate() it needs _end Looking at arch/arm/cpu/armv8/u-boot.lds I don't see an ALIGN before _end. So perhaps that is the problem? Regards, Simon