Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2776880lqp; Mon, 25 Mar 2024 08:58:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXMda3+Lntgm06lqLl8QzqG0jKoWlQt4ohUgMsXyo2nLoDlxY44Wa70yuPcxmkhAiJJpXfOnEvmhLDJYJuUk2khjIRu3MKOPqLeCifHNw== X-Google-Smtp-Source: AGHT+IGfCfABTZ+RXEw1pLU1Rm4i1ZcYufC9E2iynenj5aHTg6Pb1foKr1rCsLHm23+fu1iRkypn X-Received: by 2002:a05:622a:13c8:b0:42e:d5a3:e03e with SMTP id p8-20020a05622a13c800b0042ed5a3e03emr9175135qtk.53.1711382298722; Mon, 25 Mar 2024 08:58:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711382298; cv=pass; d=google.com; s=arc-20160816; b=cEqc7+F9Z0qEfXUOTD6quVI3T90G7Z3/YbEyPo6BWBlZMSsNbEVag0n7awPsjfFDXm tqMIa2KBOU8v3va+g1kqqPAdE8EHVx9uHokfaUwrE05V7pA6ivbEAEi4rlxrCnllrijN 8Q+MlG46/OA/vo4gaDunO74tUvafUrOvKp4MbVB92faozbvgamZ8VH/YzVuww8xsAzdE 1j9dLqAkoqDGNQDXDo11KkcQkmtcEw6rB/ah1z1n5I1QcoDwXNWbj7PUDWTsLUTheux5 SdF//tjAmgFmCoDd8T4tUFUxL2q1Zv5wEGgRB/eEr15Zn+/bKTAC7GisMQw2uTQ2VqOA Dyzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=E5l6Xsr6SpslaB5pq0ShD1moFA82HCbBvQgfMwAlvK4=; fh=39xIG24CbuIybD15+i89ViW6enCqBCRuMwyhE8gwDuo=; b=A/m4Wy9b8+WZDx+oKILMumzaofgaaEixtwucRjVBwVuuUO0kaXXRY04U55di6iCrrk EWhvzfC8ya/dZuhn33KitxG7BmmqHHaBUWgLTZqqETOoUzgtaP6zc3fUelafu2cjHD3c 9KYc1GPK65oNJFp/6NuLWPH4hY9Z40DJKLLezwlni+PdGDsc928vX5bxyQKDOse00Ink MxQ4XCnJ0ZiYNYw/ca9Ahss1YWWSSYFiAQdwaM8PfpMLlhbVtgGvObX0dfzicZdnthue oTYp5oy7g1U9Oh7w1l8hv8grgwG4QQ5uYN6Ku8VXiqJBJTFKJx26Giwj09ykJwLiGxdI xcvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Pp5dXZro; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-117139-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117139-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 fb25-20020a05622a481900b0043143ee64d8si4664206qtb.153.2024.03.25.08.58.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 08:58:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117139-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=Pp5dXZro; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-117139-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117139-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 467D91C61AF8 for ; Mon, 25 Mar 2024 15:54:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B1A114D71E; Mon, 25 Mar 2024 13:22:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Pp5dXZro" 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 0287486AD2; Mon, 25 Mar 2024 13:22:22 +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=1711372943; cv=none; b=T6bGBlepzj5hR/wQWEcGrdo9t2T3S9T87erPVVIYBIWpXMRcXS7HgePxB1bTxWfbQ2If/rFWhaL0rOjuh9AYogkwN4gB9gaOPwXtwD7kvnd+YT3UFvmMmRwFyIAFz3uzflam71PmjckdDZkP/OEwf7H/HSnT3HYsnuDVxrjPYjA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711372943; c=relaxed/simple; bh=gDfNLDwNK3vhReU1Xjnf+yFbmbGIUtPObU0OoBUTG4Y=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=px3pfqj8EPLJWpuWfITl9zJkV6TwJ23/ovuuQXmV0PGUsmKw+/MLOim1KyjyZDdm6iCmFOQ016GgZj/OagJcb4zWl8yq5nNM6sRq5olYUgNGmOuj/kSP7fIJrpDa7jOx8DRimWMwbe87r27FAQlb1jz17dI0OKSE7dC6SwHDwdI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Pp5dXZro; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8715AC43394; Mon, 25 Mar 2024 13:22:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711372942; bh=gDfNLDwNK3vhReU1Xjnf+yFbmbGIUtPObU0OoBUTG4Y=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Pp5dXZroXxSbf4pol9a4BzttJLuVe9BAfmgtcdZtZz3BVvUzcSjRuSqXZHRlVjyxg qoLEAgcg+RD8wLQpDiHVr9zKlNWCUi6KI+8GO/v+HOR+7SSIoLjYmx6OaqjJDUgOfe dk9Dr55aRY6c8474Gpfm5fd7W9OILkcSXK84sV8Fwqy45Y2i1W4clhbpymWnqqh2id guhzbmJsO4Coiu9vrXS0T9n8298wFdc1De4+WmYyRuAOaVbY2IvdEpS3idmXcKWfAe TetAcUAp/8prFR6LqEeOZXD9uB/FxW8aacPs2fW/ri+gmDpTZEEmeYqQmeMxMW/5a/ /YqS585xnQOdw== Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2d485886545so76098931fa.2; Mon, 25 Mar 2024 06:22:22 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCU83LnaqHmbBsltCxO1VvVfc2nUSqYHdQe2mX7VyL36XQcC+2oVlR3wZ85uO6vYl4LQyX95UYFT4sPsqeGVRWyntabPckdx0dmGV/753AMuaCp2RbY7pir+1LpjpzaMwmY6bHpVzoIW X-Gm-Message-State: AOJu0YwKTLdmrAvelSq5RjNna1NYvRvGr0HSErVrogwAFGkDpscqosWq +aNWiTs5/l3b6mz2VMfw4DZhzNCNBW7I2E7HO/C0D2SJUDoQ0i/ARYgaig/PzecDxMyDV27DWfE GhA7OAdTnY3mcTeTwVvvT7CSxj4M= X-Received: by 2002:a05:651c:1501:b0:2d4:707d:8b3c with SMTP id e1-20020a05651c150100b002d4707d8b3cmr7428132ljf.18.1711372940882; Mon, 25 Mar 2024 06:22:20 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240325083905.13163-2-ardb+git@google.com> <5b32b8c8-0a1b-44cf-aedf-cca1d6c83bd8@redhat.com> In-Reply-To: <5b32b8c8-0a1b-44cf-aedf-cca1d6c83bd8@redhat.com> From: Ard Biesheuvel Date: Mon, 25 Mar 2024 15:22:09 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] x86/efistub: Add missing boot_params for mixed mode compat entry To: Hans de Goede Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Clayton Craft Content-Type: text/plain; charset="UTF-8" On Mon, 25 Mar 2024 at 15:18, Hans de Goede wrote: > > Hi, > > On 3/25/24 9:39 AM, Ard Biesheuvel wrote: > > From: Ard Biesheuvel > > > > The native EFI stub entry point does not take a struct boot_params from > > the boot loader, but creates it from scratch, and populates only the > > fields that still have meaning in this context (command line, initrd > > base and size, etc) > > > > The original mixed mode implementation used the EFI handover protocol, > > where the boot loader (i.e., GRUB) populates a struct boot_params and > > passes it to a special EFI entry point that takes the struct boot_params > > pointer as the third argument. > > > > When the new mixed mode implementation was introduced, using a special > > 32-bit PE entrypoint in the 64-bit kernel, it adopted the usual > > prototype, and relied on the EFI stub to create the struct boot_params > > as usual. This is preferred because it makes the bootloader side much > > easier to implement, as it does not need any x86-specific knowledge on > > how struct boot_params and struct setup_header are put together. > > > > However, one thing was missed: EFI mixed mode goes through startup_32() > > *before* entering the 64-bit EFI stub, which is difficult to avoid given > > that 64-bit execution requires page tables, which can only be populated > > using 32-bit code, and this piece is what the mixed mode EFI stub relies > > on. startup_32() accesses a couple of struct boot_params fields to > > decide where to place the page tables. > > > > startup_32() turns out to be quite tolerant to bogus struct boot_params, > > given that ESI used to contain junk when entering via the new mixed mode > > protocol. Only when commit > > > > e2ab9eab324c ("x86/boot/compressed: Move 32-bit entrypoint code into .text section") > > > > started to zero ESI explicitly when entering via this boot path, boot > > failures started to appear on some systems, presumably ones that unmap > > page 0x0 or map it read-only. > > > > The solution is to pass a special, temporary struct boot_params to > > startup_32() via ESI, one that is sufficient for getting it to create > > the page tables correctly and is discarded right after. This means > > setting a minimal alignment of 4k, only to get the statically allocated > > page tables line up correctly, and setting init_size to the executable > > image size (_end - startup_32). This ensures that the page tables are > > covered by the static footprint of the PE image. > > > > Given that EFI boot no longer calls the decompressor and no longer pads > > the image to permit the decompressor to execute in place, the same > > temporary struct boot_params should be used in the EFI handover protocol > > based mixed mode implementation as well, to prevent the page tables from > > being placed outside of allocated memory. > > > > Cc: Hans de Goede > > Fixes: e2ab9eab324c ("x86/boot/compressed: Move 32-bit entrypoint code into .text section") > > Closes: https://lore.kernel.org/all/20240321150510.GI8211@craftyguy.net/ > > Reported-by: Clayton Craft > > Signed-off-by: Ard Biesheuvel > > I have given this a test run (on top of 6.9-rc1) on one of my > Bay Trail mixed mode tablets and the tablet still boots fine: > > Tested-by: Hans de Goede > Many thanks Hans.