Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp185395lqp; Wed, 22 May 2024 01:00:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUlr+0fFUKx5bDg0vceo5Q/3drj9Ehi79P5dc6Db7spdjioSvxc/Go6v+7eChS2w3i9pQLenJz4UgxpUjXxYAE/ho3ebE9EzTIv8Tiqsg== X-Google-Smtp-Source: AGHT+IEeEilthBriRgFR7hiJjiRJe8o65RxSKgcIzK5fvU56tuWYqnJ6JNhcW06Bjix0Gv3fUZ+C X-Received: by 2002:a05:6122:8c4:b0:4da:aabe:6f6c with SMTP id 71dfb90a1353d-4e21850aeefmr1223377e0c.7.1716364853045; Wed, 22 May 2024 01:00:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716364853; cv=pass; d=google.com; s=arc-20160816; b=EGPKACeicCVxvODwNpkfHXCB36bjSV/i9fieR7QmPpBW9YW6QfCCx4YXAm0cFUX8zQ 31hsyQQJTMI4BE3dCd87XyH1yW5qbso3T5Lus3vusTzAWTomrmC4piHRdp+hJcXKgJqS VhEOIrzSVl+xYuKwe2RBSnRNl+w9qmenHXRBRiQsMT4iwW1TrxyDMi04ebUYTcE3Bs1b 3ZuZl+YokWErP05tr7dvFn11vAqhwQ3/dhq03z2a+DbCsH47qNhRMrQGe1OlIesNKS8w k376LPTnHw03H4TnJBpqxNsctcY+tIknJAiFT9OCMNgX/AlBgHX4/CSwxtty5pS5JCEx 2aJQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=VjCNS7KbX2wuZBMHhrciMPwQEd8aMXdZVXZiCYh6q7c=; fh=Rn/upU4zkG9Jxp8UoYYlTfjGOpnYP2uAYBPrrZXYfp4=; b=MhPHVOWijxDtCmnw+P5DSR4s0WhL2ooyHxB/gnQE1S6dpRCLhpq42M7UoQ0pVL9uyr Iuqi2yIIuV5JtrT+9/LQE8qhdvMBIUeJuTusD4DrAg2KFLF7F9jDUdnzYVVJC603Xk8X ta/4etuW0FQow22H3dmfBxuB5w2jQj3+0gDEILTech374hRhWxK/Cpeg/YYRFfjLI8UR tRQO4gjAYoQvvGDfr//AzLLVzS+xUFWzfulIgG8BtGOVydQZM+4HOQwgM+Nlo3gWRVaU dBw3/u05fGFmgLjo/dvT/BBM4Pcwr4fWWtXGl90MWa0tRyp/tth0bTkEWyqxup5GmCqy C/Kw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="k2+/g0JC"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-185892-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185892-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6aacaffb4c0si65538686d6.542.2024.05.22.01.00.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 01:00:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185892-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="k2+/g0JC"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-185892-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185892-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C1F121C212D7 for ; Wed, 22 May 2024 08:00:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D5D87E579; Wed, 22 May 2024 08:00:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k2+/g0JC" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 543E8182DB; Wed, 22 May 2024 08:00:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716364842; cv=none; b=Rsd4OJXHGwixoPpsKBD5y/dtx4TNwxl9CylgXPQbW+mEQciCB0dAotMucz5AU8CgunpzUNxYUvN0GWM275owSOW2gSimf6/rjv+pvCEUc+NDXgUJH6jWaUBK5caBS41ozR01fLWpjhpNaiK5YyrJyJDu+ATEe7lcPXiIkZKCehw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716364842; c=relaxed/simple; bh=aV7NdtVB/SzBUj/d+kn2bUhxu2Qvmc8Xm3U4xn5YA3Q=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=V3cIOO/p7ji+gnAh0VWNHY7IwmoX+wpnpJp1xCfPcQ/3AQzn6vRxXJIKeOEjObIylCaK7x4wPPL6PhDt3BvBF3gwY6fVqr/BhiG+/HpC1dhvTEme8avge3a9U+MjvZXUMdulpfOk7kU1mC/P32ntMUtP1uEuaxgXVL5JbiDd8iE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k2+/g0JC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C107C32781; Wed, 22 May 2024 08:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716364842; bh=aV7NdtVB/SzBUj/d+kn2bUhxu2Qvmc8Xm3U4xn5YA3Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=k2+/g0JCirUhfOBiUEonbgEDaaTA+nXUollhqidvEQ+V0rOCM7bqkiEdg1d0mXeve NnhvCUndy/vQpprZQQZ9ZXrby+qNvJ65l9nnxXqfdLwxATBOWm5cJ4zsOXA4CD89H1 6VVoaBc5S0m/7xE2FubaLEPr5E4Zx+su482GaoiAGq5GCVrkG9CATqFQkIZAkArPJc M2O5CwvGOUpoZYKYQYXn76tOWSIgJMt58BeURUcJVQEKazq1kPz2nKx8oEOIcB8Wnb RrVCPS173Z+uA1niHUqmf+7oN6018eJo1TinQB2++q2Rtq3Iab85c9muTGEemmlT9s 0BAD+M4RwZnnw== Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-34d9c9f2cf0so530809f8f.3; Wed, 22 May 2024 01:00:42 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCVbUFKZjD+U3bK9afaEqpXx4+njt8196yWfWTAE6olDOIVR7xB+dLiV+UDTd/kdVSJ/NgqYOH+nkJCwZHx4zQU2RcMdTmJM/ABnHS6aOobuJPn+Pk6N8UpsMOtdA1wr1OdKTJ9c X-Gm-Message-State: AOJu0YylA8zSTz9pphnZKWMQPgTQF5B/nnSLTRIQHMeMIdsmWBamVVUW GKxR1WZxz+i2dt2hJPLet0rsi4Fhii7dKrKIyZIL6PstaSEMwYFlb3YF1lTDdvgLXsiLdIFlW97 y04AkqeLnTjJc8K5VR+29/ubYvnU= X-Received: by 2002:a05:6000:bd0:b0:34c:71d0:1151 with SMTP id ffacd0b85a97d-354d8c75e43mr1050070f8f.10.1716364840755; Wed, 22 May 2024 01:00:40 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240522-loongarch-booting-fixes-v2-0-727edb96e548@flygoat.com> <20240522-loongarch-booting-fixes-v2-3-727edb96e548@flygoat.com> In-Reply-To: <20240522-loongarch-booting-fixes-v2-3-727edb96e548@flygoat.com> From: Huacai Chen Date: Wed, 22 May 2024 16:00:29 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 3/4] LoongArch: Fix entry point in image header To: Jiaxun Yang Cc: Binbin Zhou , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Jiaxun, On Wed, May 22, 2024 at 2:30=E2=80=AFPM Jiaxun Yang wrote: > > Currently kernel entry in head.S is in DMW address range, > firmware is instructed to jump to this address after loading > the image. > > However kernel should not make any assumption on firmware's > DMW setting, thus the entry point should be a physical address > falls into direct translation region. > > Fix by applying a calculation to the entry and amend entry > calculation logic in libstub accordingly. > > Note that due to relocation restriction TO_PHYS can't be used > in assembly, we can only do plus and minus here. > > Cc: stable@vger.kernel.org > Signed-off-by: Jiaxun Yang > --- > v2: Fix efistub > --- > arch/loongarch/kernel/head.S | 2 +- > drivers/firmware/efi/libstub/loongarch.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/loongarch/kernel/head.S b/arch/loongarch/kernel/head.S > index c4f7de2e2805..1a83564023e1 100644 > --- a/arch/loongarch/kernel/head.S > +++ b/arch/loongarch/kernel/head.S > @@ -22,7 +22,7 @@ > _head: > .word MZ_MAGIC /* "MZ", MS-DOS header */ > .org 0x8 > - .dword kernel_entry /* Kernel entry point */ > + .dword PHYS_LINK_KADDR + (kernel_entry - _head) /* Kernel= entry point */ It could be better to calculate it in the link script, just as _kernel_asiz= e. Huacai > .dword _kernel_asize /* Kernel image effective size */ > .quad PHYS_LINK_KADDR /* Kernel image load offset from = start of RAM */ > .org 0x38 /* 0x20 ~ 0x37 reserved */ > diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/= efi/libstub/loongarch.c > index 684c9354637c..60c145121393 100644 > --- a/drivers/firmware/efi/libstub/loongarch.c > +++ b/drivers/firmware/efi/libstub/loongarch.c > @@ -41,7 +41,7 @@ static efi_status_t exit_boot_func(struct efi_boot_memm= ap *map, void *priv) > unsigned long __weak kernel_entry_address(unsigned long kernel_addr, > efi_loaded_image_t *image) > { > - return *(unsigned long *)(kernel_addr + 8) - VMLINUX_LOAD_ADDRESS= + kernel_addr; > + return *(unsigned long *)(kernel_addr + 8) - TO_PHYS(VMLINUX_LOAD= _ADDRESS) + kernel_addr; > } > > efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image, > > -- > 2.43.0 > >