Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp400156lqc; Fri, 8 Mar 2024 00:16:35 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWpR17hX0yeW61vVw5PCYdU/pjHhclUICfCMMixHyNT3Gtyjn7WVFagHTCny0riIPG2rdbUhdy1Z0f4CAbYmhZhHsPZqGMOHqKjoJuu9A== X-Google-Smtp-Source: AGHT+IG44z/ZMXy8qXArB7DPWJD8Hq5boGq5kflyHp4Ez47O1CM4EzYKgFTht+9bZitqXGNEukLp X-Received: by 2002:a92:ca0c:0:b0:365:ff00:dc6a with SMTP id j12-20020a92ca0c000000b00365ff00dc6amr11516969ils.13.1709885795029; Fri, 08 Mar 2024 00:16:35 -0800 (PST) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 139-20020a630091000000b005dc50605acfsi9192927pga.519.2024.03.08.00.16.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 00:16:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96635-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=AJEBJF65; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-96635-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96635-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AC90C28263E for ; Fri, 8 Mar 2024 08:16:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D0C451C28; Fri, 8 Mar 2024 08:16:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AJEBJF65" 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 29F992C85C; Fri, 8 Mar 2024 08:16:27 +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=1709885788; cv=none; b=E01/DpLkbH9EYdBnXzbVBILY/eZpZNvyhQZipHTCPvwMSJWwRQN/og54KF5LEetbJRyRSnXT6IwR7bmyKjtGvTVuD1EQgyDsrmRAxl22661lDPgPOzTkcAroov7N2tH4K4jtMX7oTh9z0etrDx8yAQtvrqMdeQCaWsWEwrLHBr4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709885788; c=relaxed/simple; bh=+KlByP7rf+bOfulZPxS+EKdSXzyhEgQiIoUkRNVAth0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=XC/lCe/fyFBmTQ6hzHH3MX6IumzL606ItjuYIEd2KxlfdEuZlsCGeC1WdG6ZzjK17vq06g/e4s0kzimTXHu9L80TbJxmVFUtgxUgkduB1Q7t5Sdaijyzq+jyfBY25R+ZLoLYK9bFbmmG0v5+04cvXEhIFMvUQORmSwAfNbBeXjo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AJEBJF65; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA060C43142; Fri, 8 Mar 2024 08:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709885787; bh=+KlByP7rf+bOfulZPxS+EKdSXzyhEgQiIoUkRNVAth0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=AJEBJF65mmnJlZwCUPpKFJYdzNJka13dBkz0edt4+/KqQdM7xUsiNLYeVYxnMrgt2 q+ehRfCaOtMGAyldwckSNhgvODgQReTpEl3zR9QqFbo3uY3bApcRnMHPrQ0Jz7CICf /dXmWydc0avlzbfadhLItkiAcm0UkiiFbC5UT9mmuEDm1vtLh7koBbseq3h8OqxMqs wkoWMTKjHqaRBj/tku/OkDmQo7tcmrc+F8KaDn5kdqbOAoKuIScNjFtabxUgiwPq26 HUDMaS0ENmScg89zDJ/noNVANFZ7cHVPYmrtjBFbgqxgS43RJMGbKnYX5cE3p8ZdVO TgMdERL4rmWaw== Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-512e4f4e463so2464373e87.1; Fri, 08 Mar 2024 00:16:27 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCX0p8qTYyZVBf2/15oS9KmhQ/8S/WaIrALpY/5Eeprzv+Gay1jSWLKNsReSwKu4etqlNJ1s4tVqv1oE09R9MInr+0HEzKnSYsAOvlw8zcEqbXM+AkIvl9wQQUk0jSQaj2tH6iqpIBtx X-Gm-Message-State: AOJu0YwJaKVR6iM08DesEWXxnWcgGdGv7hpLG71JrDwBD9Zk888Q4m/M xR0CBolYV09chPwJT4nnfXOFe0Q+1pHqz9Au/s+exHEM1xvUXu3vq+mBmw3mAMuLAxW5KPHoAEe BDGx6mpduVbFSPcWgkrNdsKHIwRE= X-Received: by 2002:a05:6512:4851:b0:513:54c6:9f68 with SMTP id ep17-20020a056512485100b0051354c69f68mr2751944lfb.18.1709885785595; Fri, 08 Mar 2024 00:16:25 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Ard Biesheuvel Date: Fri, 8 Mar 2024 09:16:14 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [External] Re: [PATCH 3/3] efistub: fix missed the initialization of gp To: yunhui cui Cc: Palmer Dabbelt , Paul Walmsley , aou@eecs.berkeley.edu, xuzhipeng.1973@bytedance.com, alexghiti@rivosinc.com, samitolvanen@google.com, bp@alien8.de, xiao.w.wang@intel.com, jan.kiszka@siemens.com, kirill.shutemov@linux.intel.com, nathan@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, Conor Dooley , Heinrich Schuchardt Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 8 Mar 2024 at 08:10, yunhui cui wrote: > > Hi Ard, > > On Fri, Mar 8, 2024 at 12:49=E2=80=AFAM Ard Biesheuvel = wrote: > > > > On Thu, 7 Mar 2024 at 04:19, yunhui cui wrote= : > > > .. > > > > > > From the logic of binutils, if "__global_pointer$" exists, it is > > > possible to use GP for optimization. For RISC-V, "__global_pointer$" > > > was introduced in commit "fbe934d69eb7e". Therefore, for the system a= s > > > a whole, we should keep using GP uniformly. > > > > There is no 'system as a whole' that can use GP 'uniformly' > > > > The EFI stub is a separate executable that runs from a different > > mapping of memory, in an execution context managed by the firmware. It > > happens to be linked into the same executable as the vmlinux kernel. > > > > > The root cause of this > > > problem is that GP is not loaded, rather than "On RISC-V, we also > > > avoid GP based relocations..." as commit "d2baf8cc82c17" said. > > > > GP is not loaded because in the EFI firmware context, there is no safe > > way to rely on it. > > > > > We need > > > to address problems head-on, rather than avoid them. > > > > > > > So what solution are you proposing for the potential GP conflicts > > between the boot loader, the Linux EFI stub and the firmware? > > > The GP register values are now loaded in the arch/riscv/kernel/head.S > and arch/riscv/kernel/suspend_entry.S files. > > Let's think about EFI runtimeservice. If the EFI firmware code uses GP > registers but the compiler does not avoid GP, and kernel uses the > callback function provided by EFI, is there a problem? Is it possible > to solve the problem only by making the firmware code not use GP at > all and compiling options to avoid using GP? > EFI runtime services do not use callbacks, and execute in a context that is entirely owned by the OS. So this is one place where EFI firmware cannot use GP at all even if the UEFI spec permitted it. > The same goes for efistub. > Not really. The UEFI spec seems to suggest that *system* firmware should not touch GP or make any assumptions about its value, but it doesn't say anything about EFI applications such as the EFI stub or GRUB. > So the way to solve this problem is that the firmware does not use GP > optimization. Does this allow efistub to load the GP register? > What about GRUB or other bootloaders that are loaded before the kernel, but are still active while the EFI stub is executing? Who gets to own GP in this scenario?