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 X-Spam-Level: X-Spam-Status: No, score=-12.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C0DDC49EA6 for ; Sun, 27 Jun 2021 01:42:40 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A7BD161C35 for ; Sun, 27 Jun 2021 01:42:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7BD161C35 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 60B4B82C3F; Sun, 27 Jun 2021 03:42:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1624758156; bh=QrMNtUW2bti6q9fRo81iPhrKZOv2N2q/hitLR6oCmf0=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=NYZUsfJ6AsGjAxZ22kjiAjG3d+TIJNPCQKc2YekdGzMXY9cgIqsurqKb+BAsbmVv1 rPxDbDCZ26W50UNFZqozQaH8PeT/rG1tmn3kpJnrwK8FaUEpv1/SQhmDiOHo3mX9EX 1uyNDbDly4jfm2ZrwkLcWqGDWVSyokycDZ0ZayOzsIN9MQ7Crc3ic4kxBGl6TC54oJ nUfoOml45Utrs12j9fhzwVBRCmtweXiVsEZwjfnl9zC8449CdvNL6x3t/viR661yTG mttCHzbySQuL5VAfNmsO0BgYqGSHGy84TNpKNWFxjYss1KyQJUQmG2TznKuv8XMZlJ 9ejTqWbqWg7IQ== Received: from [IPv6:::1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 79A1A829A6; Sun, 27 Jun 2021 03:42:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1624758155; bh=QrMNtUW2bti6q9fRo81iPhrKZOv2N2q/hitLR6oCmf0=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=ELvmM9QWqsdnF3I1TygFJ/YLv6gJyziz/JI1p7xjnWIxpySBBQjXweZA3lkwnbv4O pm36A6CsZGDW/CX9eBv8OKM+Dp6WKrMFSk0wTAZOQJpc8hXB2vlMmOYPFLd9QBxSRg XDoJLbtiZfpuN8YAMHzFu9K6MwwTAH+tEKHAfU8ASrpJcg1dfQKYHNkfp47reZ8EG0 exW/Y0Jej+x63IRhpPOxv5B8/LC2QO54OkIaRkpQZQPXbN8Z2sLUXDLh67qxw8N6VM osMO+fsL8aR6rRiTic48O2mWgB0as9juE1TlT+wKx7ebHG3YS04fnz1E6dLyZrcw/r SimhfIlZ/48Bg== Subject: Re: [PATCH] arm64: Fix relocation of env_addr if POSITION_INDEPENDENT=y To: Kunihiko Hayashi , u-boot@lists.denx.de Cc: Stephen Warren , Michal Simek , Joe Hershberger , Tom Rini References: <1623738782-10072-1-git-send-email-hayashi.kunihiko@socionext.com> From: Marek Vasut Message-ID: Date: Sun, 27 Jun 2021 03:42:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <1623738782-10072-1-git-send-email-hayashi.kunihiko@socionext.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean On 6/15/21 8:33 AM, Kunihiko Hayashi wrote: > If both POSITION_INDEPENDENT and SYS_RELOC_GD_ENV_ADDR are enabled, > wherever original env is placed anywhere, it should be relocated to > the right address. > > Relocation offset gd->reloc_off is calculated with SYS_TEXT_BASE in > setup_reloc() and env address gd->env_addr is relocated by the offset in > initr_reloc_global_data(). > > gd->env_addr > = (orig env) + gd->reloc_off > = (orig env) + (gd->relocaddr - SYS_TEXT_BASE) > > However, SYS_TEXT_BASE isn't always runtime base address when > POSITION_INDEPENDENT is enabled. So the relocated env_addr might point to > wrong address. For example, if SYS_TEXT_BASE is zero, gd->env_addr is > out of memory location and memory exception will occur. > > There is a difference between linked address such as SYS_TEXT_BASE and > runtime base address. In _main, the difference is calculated as > "run-vs-link" offset. The env_addr should also be added to the offset > to fix the address. > > gd->env_addr > = (orig env) + ("run-vs-link" offset) + gd->reloc_off > = (orig env) + (SYS_TEXT_BASE - _start) + (gd->relocaddr - SYS_TEXT_BASE) > = (orig env) + (gd->relocaddr - _start) > > Cc: Marek Vasut > Signed-off-by: Kunihiko Hayashi Thank you for debugging and fixing this properly. Acked-by: Marek Vasut Tested-by: Marek Vasut I did manage to reproduce it on RCar3, and this patch fixes the crash on boot indeed. Tom, it would be good to include it in this release too.