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,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 6F041C11F66 for ; Tue, 29 Jun 2021 12:38:22 +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 9CF5861C94 for ; Tue, 29 Jun 2021 12:38:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9CF5861C94 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.com 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 E1C2682E6C; Tue, 29 Jun 2021 14:38:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=konsulko.com header.i=@konsulko.com header.b="OaQO1b/K"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 493478314A; Tue, 29 Jun 2021 14:38:18 +0200 (CEST) Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) (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 7B07682E6C for ; Tue, 29 Jun 2021 14:38:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=trini@konsulko.com Received: by mail-qt1-x82f.google.com with SMTP id c13so279111qtb.12 for ; Tue, 29 Jun 2021 05:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=UbRfu94oK2dvQNq7he4dO85ierJyf34GSui1/4Wj4J4=; b=OaQO1b/KFLbuHa4RueeoYLzI5L55Trk8dQ+T5b5bx4027BS1xXRkZcMlmQ9P2nKsni eKieJFKkFzFpWKsbja479DXkkrJp//lAEJXOg9dZydVlT95Q89Kc9DShO1/W0bVzMfX0 ivXtedntOuhpVVapNjFk+z8gqrZ0R+X0IKdqc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=UbRfu94oK2dvQNq7he4dO85ierJyf34GSui1/4Wj4J4=; b=D5PkbGW5h23u9pXsfLdlRrJMf/iYY6Bim3ubG8Wrh8tXoe+mBoLrAB9mDWaH+zAVCQ wkn6RoQBnbFW12jHg1VOA4x6kaLh9v8jsHkSbcFpJhA1Nf4KO0Aib5FeGaNa+K4RMOIs J3URfM5EfNllV2/P00JpND7qtTr5G44dmZsNh7ZaXM52tEr61IlgDSl0eY4o+gU3ynkE c5xjn6uF0/gvKN9bxzQeCqtXKatii/Q3GM87Ky4CIOA2YB4yp1WdN1fAZayxHVgHfXSL eqJN2hvbOrzLxhYHNEMC7b7EkpJbkx8BhP2P21qBJxCvXXFD0aNbeviGOxZeVG3a2i5G 0nfg== X-Gm-Message-State: AOAM5309730iPTh+AFQH8yX5j4tqq7nAc1H8qB1fDZ83ZGJBK6MSraZl PNNssLeuuDmohIADorGP30pMcw== X-Google-Smtp-Source: ABdhPJw/YbLooLBFxNIj07lKpBZd92EqOGkTMv4E/9j1BDSsXouwPP6nEj/AVkGHGrLq/StV2QtDNg== X-Received: by 2002:a05:622a:15cc:: with SMTP id d12mr26147249qty.67.1624970294305; Tue, 29 Jun 2021 05:38:14 -0700 (PDT) Received: from bill-the-cat (2603-6081-7b01-cbda-1dab-ad46-3d7e-2f8f.res6.spectrum.com. [2603:6081:7b01:cbda:1dab:ad46:3d7e:2f8f]) by smtp.gmail.com with ESMTPSA id o15sm9191385qtw.5.2021.06.29.05.38.12 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jun 2021 05:38:12 -0700 (PDT) Date: Tue, 29 Jun 2021 08:38:10 -0400 From: Tom Rini To: Kunihiko Hayashi Cc: u-boot@lists.denx.de, Stephen Warren , Michal Simek , Joe Hershberger , Marek Vasut Subject: Re: [PATCH] arm64: Fix relocation of env_addr if POSITION_INDEPENDENT=y Message-ID: <20210629123810.GW9516@bill-the-cat> References: <1623738782-10072-1-git-send-email-hayashi.kunihiko@socionext.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="f9io/u4yptGpX9LF" Content-Disposition: inline In-Reply-To: <1623738782-10072-1-git-send-email-hayashi.kunihiko@socionext.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.4 (2018-02-28) 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 --f9io/u4yptGpX9LF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jun 15, 2021 at 03:33:02PM +0900, 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. >=20 > 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(). >=20 > gd->env_addr > =3D (orig env) + gd->reloc_off > =3D (orig env) + (gd->relocaddr - SYS_TEXT_BASE) >=20 > 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. >=20 > 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. >=20 > gd->env_addr > =3D (orig env) + ("run-vs-link" offset) + gd->reloc_off > =3D (orig env) + (SYS_TEXT_BASE - _start) + (gd->relocaddr - SYS_TEXT_B= ASE) > =3D (orig env) + (gd->relocaddr - _start) >=20 > Cc: Marek Vasut > Signed-off-by: Kunihiko Hayashi > Acked-by: Marek Vasut > Tested-by: Marek Vasut Applied to u-boot/master, thanks! --=20 Tom --f9io/u4yptGpX9LF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmDbFCgACgkQFHw5/5Y0 tyxzsQv/aZhoxW+9GaY3cN4zY+gXbMyzzWtttRglfk2BBQGyZlflr8a7y3DRUxFB NI5IaJYmTZNYSTnvVT/y+FrDnfwR4hPFqe+crXzv6o7QhcqGqZuMTVypBSZdUSP5 jwR5U1lc0sMOWdNAnz1I9NIXSFgjwoW+nKN04MUDFqG1ufjZTK8nW2Uj9ioCXZSL yEPpvCe9imiFW6I6bmPKKZ29rGQS7yZTPtAaijqqh8SAoYSS0GF/i6F10NXq/su7 1hSoCOxHnB2qBiiuPeEi06co/ZNtasZLfv8YU4egvvoRxTamriJfQ5eVktpB1Vhd X9a4BEZgc2skjaxO2Mom22Tjw1nDMtNYIrQmBd/N3MvE/ycKykVzqPeLQcRL5y8q WhGGv8Zz4jgjV+TssEzIrZzhdPhnEeUZUMuGcqrAcZK6kekO4jSNNfHRzYx5vq06 75jpvK/ZxFYlIxFRYldj0HeEBf6EW0zK3pHxduVGUK00wBVZ4cqUsgStkMkyjW0q D4ZKMQtp =oqsp -----END PGP SIGNATURE----- --f9io/u4yptGpX9LF--