From patchwork Tue Nov 22 16:10:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24447 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2301481wrr; Tue, 22 Nov 2022 08:13:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ptsi+AEQB8M4SZKrn0f2HnX3wyfjur/iU2NXJMJ5WUmpLkmAx8yF/JqTcD7fM22kEReid X-Received: by 2002:a63:5724:0:b0:46f:9c0c:8674 with SMTP id l36-20020a635724000000b0046f9c0c8674mr6676520pgb.26.1669133584059; Tue, 22 Nov 2022 08:13:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133584; cv=none; d=google.com; s=arc-20160816; b=RP3KT9PMlz0u3tpQoC/MDB73rOIE30lHuoJL1L1NDjlujM5ia5bM88bK69i+N4OJkM 6QzIwEossdicZ+Ezw1U1/zAoDV5UFJWh61ExgyN4plbXG7IA44kh14DJDuee88Jdt3gE k61Wv7ekG3qWcWlGk/xLuS8CxRRn3vKSkIe91PMDytqgm01ifz9B3SCuwxCdqZ1xWoMq wLX+hJnCySctJbdC8V7spl49grsy5iEkUCxowed75fQDCWUcDhg/AkI/NFe9V7tnsqNJ pSV+REqNvAxntsv/xrrhPhflIMox38uitN0T8tyKKZD29vXq5d2ALGMh6fV5LILLCWg9 7now== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GymIN5mREcsEMrkrgg8hKigjTp5TrmRFsGW+qrPLigE=; b=FPKJE1OnKc54hriladkNk3S6fL8a7N9XsVcgjn8ZOqRcjSAQYny1mCkE+acltkJiel Pm2bkgT+AxVxdQORqs/w2O5JyEw1MH/npWngXuw9B5z9mMAd07nVxTNoePYTkd9JYuQF tqFUHe6N2gFsHLu1bcaIPCOIrR6A0R0je1ZqJvQRbDejRbE7ON8iUF6ifsrYuOmMfeOj FXZplaWN8GGqewTzzIZB4SQ6+ltSofTm6Ji+bD/UqXSuYs8Zu1ADmuE9p6g11rZKg+0k 0IJl+ynqbsLGl8Ekq/oUCHTIlwBAAXCKkDtkMwilNOm3uMEvvmRZhIii4Au0EvVl/GEe cgTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Haz5xahk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n21-20020a056a0007d500b00546ce9189b1si12376598pfu.65.2022.11.22.08.12.49; Tue, 22 Nov 2022 08:13:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Haz5xahk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234174AbiKVQKr (ORCPT + 99 others); Tue, 22 Nov 2022 11:10:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234186AbiKVQKi (ORCPT ); Tue, 22 Nov 2022 11:10:38 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA9AD73421; Tue, 22 Nov 2022 08:10:37 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6E2B1B81C12; Tue, 22 Nov 2022 16:10:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FF16C433C1; Tue, 22 Nov 2022 16:10:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133435; bh=wDRs75zTAHjH3XwxSS7HuA7vyVpCwR1hlLp7hTGnUFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Haz5xahkdshlBU/tRr1O4ZnSpYOxX3bxkfza8v1TsQcZ4lMCI9qJ1KM8Lb3FAGcJQ o0RkclgkoVbumV79RLi3iVyHmRbhfQHailej8zQhhfrdqFm1FTmB3o5+kZ51nayvu8 n2aqgIzHAtrDbSEOvSAvmBDa369Ctdd9h9inzeP46OsDo3cZYJxiICuXm7uciseWlB /TLgPGpfJdaifs0CXoGJSzaLzIE9UGda4T4dP1+O9DkO9Yk+q60zWOXWrxV6sw8uUg oNz7Nu4bp8Uanr83MiA7vUjNzQe03ZpY6/pDJvzf1SqR0z997M3rPB4KeXaMUfViIm xOBxti+UdhdTQ== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 01/17] x86/compressed: efi-mixed: rename efi_thunk_64.S to efi-mixed.S Date: Tue, 22 Nov 2022 17:10:01 +0100 Message-Id: <20221122161017.2426828-2-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1576; i=ardb@kernel.org; h=from:subject; bh=wDRs75zTAHjH3XwxSS7HuA7vyVpCwR1hlLp7hTGnUFQ=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRP2cVMH4lvpZYQzGmsO4SCnQ5TYAbG9swSZYuk aYpQndyJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0TwAKCRDDTyI5ktmPJF6UC/ 9BDabprUrkL/8MHA1NYfeEFcxm0F80tRYJR18ArKn7XZL1lIaI7H8gIjlDpkkMwVhnLz6l0H+1cGkl RjuLYE0Mw1g4+mqc+vfhiFxwcR4NxL8KH62C1+MjiF1oe7LoTnDWwB1dB01FA4pwJVfLGbwQ+pm4Rt /XJVU/Y1xczQvY6SjM2B1ZkOA8z8b9G3pwSFiqgKXAdfyX6MJ5A6bdfkhnjJafN74SlbIIYu/DS5LL lIO6xlfBUuz6vmdKgak9m2bN/Z2caFUj2+RtaZepIAEeFbmKgEsEeGfAPpA3J8Gjho+YpmF2Pswyhk i0HlZD9bYErdUa3BP3gbBG0iaDLFq/j1q4zX041vJdzt6eT8OYIlRcYRufTmdzHgNefkNEgV0aT/u4 1vcuyzeh5e5yGxB0h7To97JEJferfJwy1bM54Kh3Vypin+jRc3uqVOaYvLIkuzKPeHjyyJ7TKJhpgO ZXwKwZRWiktn+JJbmig4mlt6PuSmJf5rfEnoWzTo69tU0= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213417031333008?= X-GMAIL-MSGID: =?utf-8?q?1750213417031333008?= In preparation for moving the mixed mode specific code out of head_64.S, rename the existing file to clarify that it contains more than just the mixed mode thunk. While at it, clean up the Makefile rules that add it to the build. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/Makefile | 6 +++--- arch/x86/boot/compressed/{efi_thunk_64.S => efi_mixed.S} | 0 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 3a261abb6d158d62..cd1a6295b957ea1d 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -108,11 +108,11 @@ endif vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o vmlinux-objs-$(CONFIG_INTEL_TDX_GUEST) += $(obj)/tdx.o $(obj)/tdcall.o -vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o -efi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a +vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o +vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a -$(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE +$(obj)/vmlinux: $(vmlinux-objs-y) FORCE $(call if_changed,ld) OBJCOPYFLAGS_vmlinux.bin := -R .comment -S diff --git a/arch/x86/boot/compressed/efi_thunk_64.S b/arch/x86/boot/compressed/efi_mixed.S similarity index 100% rename from arch/x86/boot/compressed/efi_thunk_64.S rename to arch/x86/boot/compressed/efi_mixed.S From patchwork Tue Nov 22 16:10:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24448 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2301502wrr; Tue, 22 Nov 2022 08:13:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf6RBetsB+Kgqy/oEcJ7VCr8f6ozx+bjXtrmhwSyD7wiDbUYl8OgsWnSBwVhBPuLCKGx9A2j X-Received: by 2002:a17:90a:d3d4:b0:212:e52e:dfeb with SMTP id d20-20020a17090ad3d400b00212e52edfebmr31807772pjw.227.1669133587866; Tue, 22 Nov 2022 08:13:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133587; cv=none; d=google.com; s=arc-20160816; b=jlXj0Qofv7aHGi16Lv4gKN9ZjmCvJjuMeUD6BntghHUrpbVBwbsM3gM47cFBGM+j7/ n2Fu2N1M4Vv3m4uRa9i+JyHnK+vUNWEN0qpgsulhJtE7pOXfIgE6PpkO0jr5HkWgMavr Xc/rCfnTsOxNsTdMhELEFTY8YmLlWdCa6BsnPADpIzj7Bl+w07C1FF+3mgvNH3moGJ/M 19qxzbw6SB+omb1+gOstWN4A01kcxsoW9+qiCK0aLOf5yVw+QTB487D7F64emOPUdW03 Pdpvp5s0CoaPP6ki/2aPkNBhcXf3FJ6o24H8j+C5zaVbPdJGm1Em1GjLpv6UzPfZ7McJ 4/fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jhj4iI+MlCkJcSsEtJgPuH9dWsTRXtwlXbKqf21SgXE=; b=yCAqKd5yUmvvaE8cF0MLTUk9FFstdtPY4naJQIrfHTJ2hKwy7jvGI6GtFD+IXDHNx4 n4U7LgS7R3kSl9ank0fNuJsOzji08zV9XmpEvrRwWWX+KjY18EQFEgInQKUfXsmMlhv5 r1O6F8IC+l3hYZTU56lo6M+gKbvQPkNCUKp8ym9UfsbPxqk8g+ys9hUNkT80RTLvVg2I UBS5cn4ByveMNVIQsjKY8TKJIjX3jl+kc/IzGvt418hBiLPl5c/7dA44tt7tmCL6d9wc 4yidHM836QLapaiqUz+r/0rCtFxF8ww3Yn2v6SISV7Lsibukf0lLaCHzgYSeYufKXAvK H+9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SV9XRYW0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n3-20020a170902e54300b00186af7a393asi15633567plf.327.2022.11.22.08.12.53; Tue, 22 Nov 2022 08:13:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SV9XRYW0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233369AbiKVQKv (ORCPT + 99 others); Tue, 22 Nov 2022 11:10:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234189AbiKVQKi (ORCPT ); Tue, 22 Nov 2022 11:10:38 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D9187342F; Tue, 22 Nov 2022 08:10:38 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DE05A61790; Tue, 22 Nov 2022 16:10:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85371C433D6; Tue, 22 Nov 2022 16:10:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133437; bh=sEJvhCQxeDCcI3Wh1P1C49BRYqX5Djj4f/natWFpYe8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SV9XRYW0O18IJlBXy7lIv08oVHUL/FtEJw7NFQjMF3iG86/d7BS2ekDBpJ+k461Pl Z6o9EhvO18shfI/TB2tD4Dif54y1lhgvHYk5Jz9rD1+iLjeeeMbfjFcwuc/FPoDb5V hrUPaXGgjgz0gkw0+ru5Ft70d/tfDSZIjr3R7EEpjmaSqoxCtsIPL/YBBVLilc7Wp+ WFv7bQ4LD6fXuuIew6uuWW8qF/waWXTCVJ59T4M8CuKrmj2Sk+Fu/4qLb1pWtkGgsg +0lfBmRdrDwd/88Klps0p0EwyVsn0HR/EkAtgtAeWMAq8pZX/ec/MsAQbKuqSdhzc/ Nw9HPxP5FBNTw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 02/17] x86/compressed: efi-mixed: move 32-bit entrypoint code into .text section Date: Tue, 22 Nov 2022 17:10:02 +0100 Message-Id: <20221122161017.2426828-3-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2725; i=ardb@kernel.org; h=from:subject; bh=sEJvhCQxeDCcI3Wh1P1C49BRYqX5Djj4f/natWFpYe8=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRQtQpikiqIcg3GsEynnGIf0E0BXR9vhKHMTNMA ubl/JByJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0UAAKCRDDTyI5ktmPJN81C/ wKlnKRZktDzn6/J/fnPFJYeZqn0QJ5lycWp1uJOecLHgijPegOrMDDmrn8Hp5ZjbUdEY/dImsbyQoT XVAhWCeJux0/0dQRDQ8QisYP2IjPdkMYPtWExtqKNdxmyES89JK4P+HZIhjipRPNCmx/2NMNbNqmlE 5pWqJAU7f0GjzHe8ZCU5C+rplYk5TekvTuYIZihEGsYtEAVkFvhotbHli6ijd12v9/kWqiPL3jOpNc E+KqvOQ6FiFH4VG7E0SpY3kzqdVY//zNtXCR2X5tDbXmYNKLWAYunuHX9/CsUy1rnhPKTwh6Hnv3BU mR4+4otxW7ny2isBdou/WGdplFFx+Yigs8XBfzJo5NNzWdq1RfxIIlPeKmGsfCe+HDrdjxsb0MpnC2 A4pxKHr7KNvXrUtrVkGMfMNSaNJdPacDo4lY2sLYwqqzBua2VAV5CJ8TJvUIvv6ahtE9QPMrGv+MO8 32cS/k7Er70o+lPIMaxl3UTJTvbEd7ZA1Kr+trNWdnkmI= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213420695971583?= X-GMAIL-MSGID: =?utf-8?q?1750213420695971583?= Move the code that stores the arguments passed to the EFI entrypoint into the .text section, so that it can be moved into a separate compilation unit in a subsequent patch. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 48 ++++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 190b803eb78712e0..74aaffd22b7425f4 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -311,24 +311,41 @@ SYM_FUNC_START(efi32_stub_entry) popl %ecx popl %edx popl %esi + jmp efi32_entry +SYM_FUNC_END(efi32_stub_entry) + .text +/* + * This is the common EFI stub entry point for mixed mode. + * + * Arguments: %ecx image handle + * %edx EFI system table pointer + * %esi struct bootparams pointer (or NULL when not using + * the EFI handover protocol) + * + * Since this is the point of no return for ordinary execution, no registers + * are considered live except for the function parameters. [Note that the EFI + * stub may still exit and return to the firmware using the Exit() EFI boot + * service.] + */ +SYM_FUNC_START_LOCAL(efi32_entry) call 1f -1: pop %ebp - subl $ rva(1b), %ebp - - movl %esi, rva(efi32_boot_args+8)(%ebp) -SYM_INNER_LABEL(efi32_pe_stub_entry, SYM_L_LOCAL) - movl %ecx, rva(efi32_boot_args)(%ebp) - movl %edx, rva(efi32_boot_args+4)(%ebp) - movb $0, rva(efi_is64)(%ebp) +1: pop %ebx /* Save firmware GDTR and code/data selectors */ - sgdtl rva(efi32_boot_gdt)(%ebp) - movw %cs, rva(efi32_boot_cs)(%ebp) - movw %ds, rva(efi32_boot_ds)(%ebp) + sgdtl (efi32_boot_gdt - 1b)(%ebx) + movw %cs, (efi32_boot_cs - 1b)(%ebx) + movw %ds, (efi32_boot_ds - 1b)(%ebx) /* Store firmware IDT descriptor */ - sidtl rva(efi32_boot_idt)(%ebp) + sidtl (efi32_boot_idt - 1b)(%ebx) + + /* Store boot arguments */ + leal (efi32_boot_args - 1b)(%ebx), %ebx + movl %ecx, 0(%ebx) + movl %edx, 4(%ebx) + movl %esi, 8(%ebx) + movb $0x0, 12(%ebx) // efi_is64 /* Disable paging */ movl %cr0, %eax @@ -336,7 +353,8 @@ SYM_INNER_LABEL(efi32_pe_stub_entry, SYM_L_LOCAL) movl %eax, %cr0 jmp startup_32 -SYM_FUNC_END(efi32_stub_entry) +SYM_FUNC_END(efi32_entry) + __HEAD #endif .code64 @@ -839,7 +857,9 @@ SYM_FUNC_START(efi32_pe_entry) */ subl %esi, %ebx movl %ebx, rva(image_offset)(%ebp) // save image_offset - jmp efi32_pe_stub_entry + xorl %esi, %esi + jmp efi32_entry // pass %ecx, %edx, %esi + // no other registers remain live 2: popl %edi // restore callee-save registers popl %ebx From patchwork Tue Nov 22 16:10:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2301522wrr; Tue, 22 Nov 2022 08:13:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf5u8vx0+5nOtxNMtRNMRl77pv1u0Tzlv7fTP4faAkkMCbPYbB+MQs/jbf2qw7LMYvK/cu1N X-Received: by 2002:a62:5281:0:b0:561:efcf:1d21 with SMTP id g123-20020a625281000000b00561efcf1d21mr4616002pfb.68.1669133590470; Tue, 22 Nov 2022 08:13:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133590; cv=none; d=google.com; s=arc-20160816; b=KJb1+9BY+N8/U83sO2ETRH/Z8EFzVCLNz7qmBlSB8vFEsVHWqsB0YUAEcxN20dGEt9 F41mpwfo3U52N0OdwzoBZqDB3BK5UPuJsZwyLQijRj9bx2KXNubcG6EGzHpdIln333zZ eOiyScA30K5FMsfAt7Qb18lRLdhKZbZlsBAK3d/VVXiJeotFS8QiSlcoHFWHzdVKGC4L t23aCfzu7lpbHmnb5FEBPcwcoL4aqK8O1IMS8YU5Fvlyw4UusebapDkiX3q5wv9rn4Dd rRJIu9OeW42cGbvfQTOlnXbfxWW3crxYCFMk2WEUxeXjL7d27Q8t2p6EO6zduBQwzQi2 KwJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BBKyNBPclgdhtR6LAdJKX5XjZqGOGYmS92l6cZARc4g=; b=yO6XucUWRVfUhwTfjVDED4vlhA3nWChF68UrlVhCM+VJRc0yDGhZto+P9Uh7o8tv/w 6arbpQUXdI5df129524D56O94MJ3yjGVM6sPVfXfIr9sgPHYSg83BmchlhNFv0Zx7N9H 4TeJucrszYcjUzfEykUf1cZeku3W1pAJIB0UXeYmXg9Z9xkTCOUq5wmpbhjNQFj54dyZ Kx2l0d0cZTVaHT/V+NISoZ9T+nX8zR7cGWZuMeL75FuY0akdopfsEFSLQnjLl0IGPn6p ByqePFH5gN8jOjqHdum6QmDyvvl67T7PT6RauY1qXBED/HcWkJw21HtMyqs6YYTaQ0VR /reA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EK5sUHYb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o6-20020a17090a5b0600b0021305bbcb6bsi12122559pji.90.2022.11.22.08.12.55; Tue, 22 Nov 2022 08:13:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EK5sUHYb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232893AbiKVQKy (ORCPT + 99 others); Tue, 22 Nov 2022 11:10:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234100AbiKVQKl (ORCPT ); Tue, 22 Nov 2022 11:10:41 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A3CC73429; Tue, 22 Nov 2022 08:10:40 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1787A61791; Tue, 22 Nov 2022 16:10:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAAD1C433D7; Tue, 22 Nov 2022 16:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133439; bh=KfvrPoaWkzJRvf0XbOy9qU26LYABFuWZ+uOX59kfanM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EK5sUHYbCPyg44a5QEdcfzPTUijM/x+sAhz1052brecEma88JVGdzct71DQVNIMcd S6S0S4NqwvlZylQTyj1eY1w5vC34plwGdN0hy5vl7wzSVf4W1RGcdor+W9bG0F+tgz pWXvaZ8NAJ1Gm2/v42TRqTiT+dmgMLLYZ08PVVZO+/51GmCT6B+jX5xj+6IVsDKMGW VDML93SJ/pB5c8TXzGDO6x+VNkXG52Ss26p7h0w1lUx0+mY3QwZv/LgznxJ0OLyplE mlu8owWhf8yMVKo9XtbT8vIvjpowaqKCu24IpVo9Dm7vq0ssJTE9b3M2gTTnKdkAC8 F/GS9+y5Pi/uA== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 03/17] x86/compressed: efi-mixed: move bootargs parsing out of 32-bit startup code Date: Tue, 22 Nov 2022 17:10:03 +0100 Message-Id: <20221122161017.2426828-4-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4635; i=ardb@kernel.org; h=from:subject; bh=KfvrPoaWkzJRvf0XbOy9qU26LYABFuWZ+uOX59kfanM=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRShXyE1GvhFiSLXTLUcUldPrqnDBDLhfLxB4Aa F9dYrG+JAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0UgAKCRDDTyI5ktmPJDu9C/ 9ESxGwyIL6L1ilqx93mfMCQz6rAjCDYRrhkNB15R9N9XJtfEewGixWk2sE8Nac5z/X1RaXXeIs+6O5 TT7RUk2K9mm3lPDk3Vm8jiR7NVu7xV5ZEX9Cus+3y3v9xmUJArOfr7Lv97nrASuJpNG4BPiwDQjXny 2Zk77aQfOVBc3ryGOXWpArOWKQxQBNUeYwWpRX2iGhg8dG4ufZdEt26dAq1MZYW1N8TlmI7R37jaCT b/pZ93YYFPsiyx9IGE0vqBLoxj1FLighmYq0elMdO4OuEAxiMb8/8bLSJfsFokRttwQZL+jemY5Xg5 VK0TH+CzAhq7joaEm+yCczEd6atxKC1EHzgaLpfikCRkHyi6+XsFpBE55awF1zO9MOFvAYRTMWyKRG bhy+2g6Y60Pvf6ACoy0BUfa2fg7QXou6m+5+ayLvapEtWO2+3pglJps9RiikqccJ/CH2dRaxas/XSi oDV1tZpwsg6paewplofTbvLKpxPjNw5cRWRO2gK9nL/a0= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213423539784687?= X-GMAIL-MSGID: =?utf-8?q?1750213423539784687?= Move the logic that chooses between the different EFI entrypoints out of the 32-bit boot path, and into a 64-bit helper that can perform the same task much more cleanly. While at it, document the mixed mode boot flow in a code comment. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/efi_mixed.S | 43 ++++++++++++++++++++ arch/x86/boot/compressed/head_64.S | 24 ++--------- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S index 67e7edcdfea8fa44..58ab2e1ffd92afbc 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -22,6 +22,49 @@ .code64 .text +/* + * When booting in 64-bit mode on 32-bit EFI firmware, startup_64_mixed_mode() + * is the first thing that runs after switching to long mode. Depending on + * whether the EFI handover protocol or the compat entry point was used to + * enter the kernel, it will either branch to the 64-bit EFI handover + * entrypoint at offset 0x390 in the image, or to the 64-bit EFI PE/COFF + * entrypoint efi_pe_entry(). In the former case, the bootloader must provide a + * struct bootparams pointer as the third argument, so the presence of such a + * pointer is used to disambiguate. + * + * +--------------+ + * +------------------+ +------------+ +------>| efi_pe_entry | + * | efi32_pe_entry |---->| | | +-----------+--+ + * +------------------+ | | +------+----------------+ | + * | startup_32 |---->| startup_64_mixed_mode | | + * +------------------+ | | +------+----------------+ V + * | efi32_stub_entry |---->| | | +------------------+ + * +------------------+ +------------+ +---->| efi64_stub_entry | + * +-------------+----+ + * +------------+ +----------+ | + * | startup_64 |<----| efi_main |<--------------+ + * +------------+ +----------+ + */ +SYM_FUNC_START(startup_64_mixed_mode) + lea efi32_boot_args(%rip), %rdx + mov 0(%rdx), %edi + mov 4(%rdx), %esi + mov 8(%rdx), %edx // saved bootparams pointer + test %edx, %edx + jnz efi64_stub_entry + /* + * efi_pe_entry uses MS calling convention, which requires 32 bytes of + * shadow space on the stack even if all arguments are passed in + * registers. We also need an additional 8 bytes for the space that + * would be occupied by the return address, and this also results in + * the correct stack alignment for entry. + */ + sub $40, %rsp + mov %rdi, %rcx // MS calling convention + mov %rsi, %rdx + jmp efi_pe_entry +SYM_FUNC_END(startup_64_mixed_mode) + SYM_FUNC_START(__efi64_thunk) push %rbp push %rbx diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 74aaffd22b7425f4..b9dbc8127038c315 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -269,25 +269,9 @@ SYM_FUNC_START(startup_32) */ leal rva(startup_64)(%ebp), %eax #ifdef CONFIG_EFI_MIXED - movl rva(efi32_boot_args)(%ebp), %edi - testl %edi, %edi - jz 1f - leal rva(efi64_stub_entry)(%ebp), %eax - movl rva(efi32_boot_args+4)(%ebp), %esi - movl rva(efi32_boot_args+8)(%ebp), %edx // saved bootparams pointer - testl %edx, %edx - jnz 1f - /* - * efi_pe_entry uses MS calling convention, which requires 32 bytes of - * shadow space on the stack even if all arguments are passed in - * registers. We also need an additional 8 bytes for the space that - * would be occupied by the return address, and this also results in - * the correct stack alignment for entry. - */ - subl $40, %esp - leal rva(efi_pe_entry)(%ebp), %eax - movl %edi, %ecx // MS calling convention - movl %esi, %edx + cmpb $1, rva(efi_is64)(%ebp) + je 1f + leal rva(startup_64_mixed_mode)(%ebp), %eax 1: #endif /* Check if the C-bit position is correct when SEV is active */ @@ -787,7 +771,7 @@ SYM_DATA_END_LABEL(boot32_idt, SYM_L_GLOBAL, boot32_idt_end) SYM_DATA(image_offset, .long 0) #endif #ifdef CONFIG_EFI_MIXED -SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0, 0) +SYM_DATA(efi32_boot_args, .long 0, 0, 0) SYM_DATA(efi_is64, .byte 1) #define ST32_boottime 60 // offsetof(efi_system_table_32_t, boottime) From patchwork Tue Nov 22 16:10:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24454 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302214wrr; Tue, 22 Nov 2022 08:14:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf4hBlJiwDsSadnxnZlOhbXFZjdCUlR0bky1X5c5/140u6tdQ8Risccq+pZWSzmydjS74YYA X-Received: by 2002:a62:1d05:0:b0:56b:a0f4:decc with SMTP id d5-20020a621d05000000b0056ba0f4deccmr4628900pfd.33.1669133668469; Tue, 22 Nov 2022 08:14:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133668; cv=none; d=google.com; s=arc-20160816; b=avwLWOD7qooeE96xqzPa6adLesjBMCzktNxuH6RPvYex2DHL6rTwT+LiU9ZJ0Ycb5a zlRWvzUcsYFKdhIRrB3NFLZN9+AeV1moTvPxoj7Rg371FhQfqHNH6FyoeV+vpSGdXDSo OWVPSK3k7hu9VxKX/RkT58gPen+wuPGrnUkYf+8W9+goFcTzvVbClWCI9MSWaFxJDTKb RLozAkvO8olJCnLcBq4H0qj5lISb0rvueGmmOSIWe/Fkvf6zwqBISc4Bcl4JqnL4cjP4 JTErmJb9eN/gbzs4kI/xmkCCNL7NANotFsDxo1JE42X2qcNrCMpVHIukjgBEZjSrG0nf ihbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2foFmAgi7GriMLTTuHx3ErMhaJFUBhKZn4kLnZeD/2s=; b=PjsNr3EE4AzOgVr/Vp9sIHIf86qcvdz2C3fHZUfjAPfu7giGlwl0yo52WIASp4WNuw 9Mu/NObEfktRby95aR04m3A4+EmfFG4/gJpHyVZT/BiFcXRLCmL+mStxJME2Di8eJ0Eg OjltefZd/CHdo4BDRkwQ73+ZxzpvB9Vp7cFcs+KFKJZeczFQjWJiP8OEAxQSa5NjBYuM PSKPvyMkGUQjjXMwVgUsP6G9gIh89t4l+k4/sbd5zwWBBNhOHh6SnptBpdCa5hxFZOJP BLacDKgWik9E9nxyLHZBBciakqS7fy/SxF8Cyj67sH8NFDVo3qs5DraFc2Zcicq5Olxj Lq8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uQ+tTtbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j70-20020a638b49000000b00439f026cf5dsi14185224pge.612.2022.11.22.08.14.14; Tue, 22 Nov 2022 08:14:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uQ+tTtbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234104AbiKVQLH (ORCPT + 99 others); Tue, 22 Nov 2022 11:11:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234218AbiKVQKr (ORCPT ); Tue, 22 Nov 2022 11:10:47 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B82DD73B9E; Tue, 22 Nov 2022 08:10:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5480D6178F; Tue, 22 Nov 2022 16:10:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF810C433D6; Tue, 22 Nov 2022 16:10:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133441; bh=Ff5jCPG7xec1bYIqVhOuQrRSDrmeAGMIZG5Ihg2Q08o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uQ+tTtbAAF3gK1Z6QRv+7Rua8R7XrcZdrvKax7QpETrOgkP1VQlxLolXvht/ciO8O d+de/y8s3jBkTNAC13F/qQKQxm+QbyHXfSwWk0YIn3cDSkC//L5Rji0brkgNYn4e4E rpTPnuiEMdujYFmubTEaNXeamv7qe0L8fZt9YPIvcqrdjbu1BRkkWQzfW8v9YI0Oqp rkX/rU+toIj0kaSvENvVtvgBODb8DbqLkEexk2c3RTrPyIo50DDjj4CWesYeEzVKvi ufg3ZjWJRXAqKgGaS90MAijfmzwZhO2M89xSkmIqPtBVAQuUndSOwXioZlhfcICXll C2TH6rT1Zl8Ug== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 04/17] x86/compressed: efi-mixed: move efi32_pe_entry into .text section Date: Tue, 22 Nov 2022 17:10:04 +0100 Message-Id: <20221122161017.2426828-5-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2019; i=ardb@kernel.org; h=from:subject; bh=Ff5jCPG7xec1bYIqVhOuQrRSDrmeAGMIZG5Ihg2Q08o=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRU1Ky0OuKT3C0YzcqKH54TQ0hcBdzSXviTD0O7 qRY21+aJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0VAAKCRDDTyI5ktmPJAIKDA CjCnzWb+eCyL4Ncuo9hhAheTq2FnzM8m9qA7gAzdx5U8kOyllXOxNTzHBlEKOy3R9VBbrrMuMXO8iD /tL5oTNLSNF2G3jrz7f3broaBBy6YDICuj7a173PMQbObuhCavTAp+iTn7ktiPokRPhYSFBreNORHp lOdy48mVsL4blMjJ7JbjUBHoVt53G0j3GMg69PzfcYUk7dhTXJ5S+x+ik/kGVMlGi8kotybbZ/SQgD EuC7EXoRQKvFp3TO/K3J1DI9vFghLvg2CZaa9m3d8SfSk8NCOq75eRZN+49YQ19Gs/3ZgkU1t9E/xZ aVBXM7A6CQV7vmDrajWyEHwVhN6artR4sM9U5v18gzPLl3ZsyszB6W2Je2qeVV7b++rOee3qPweOBB EMRhA5IrRzcUtG9RiCPK0ZvsVIGypyORoDC49E6TJOzwjAZPzptFRfXu7r3/HV7iR1ED5RHPqjmafL 9aUa3WCOk4fVkJMrFDkVwitBSaX8qyHlZtk4Wv9rUaQzU= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213505655423608?= X-GMAIL-MSGID: =?utf-8?q?1750213505655423608?= Move efi32_pe_entry() into the .text section, so that it can be moved out of head_64.S and into a separate compilation unit in a subsequent patch. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index b9dbc8127038c315..8192ab1c308567ce 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -778,7 +778,7 @@ SYM_DATA(efi_is64, .byte 1) #define BS32_handle_protocol 88 // offsetof(efi_boot_services_32_t, handle_protocol) #define LI32_image_base 32 // offsetof(efi_loaded_image_32_t, image_base) - __HEAD + .text .code32 SYM_FUNC_START(efi32_pe_entry) /* @@ -800,12 +800,11 @@ SYM_FUNC_START(efi32_pe_entry) call 1f 1: pop %ebx - subl $ rva(1b), %ebx /* Get the loaded image protocol pointer from the image handle */ leal -4(%ebp), %eax pushl %eax // &loaded_image - leal rva(loaded_image_proto)(%ebx), %eax + leal (loaded_image_proto - 1b)(%ebx), %eax pushl %eax // pass the GUID address pushl 8(%ebp) // pass the image handle @@ -834,13 +833,13 @@ SYM_FUNC_START(efi32_pe_entry) movl 12(%ebp), %edx // sys_table movl -4(%ebp), %esi // loaded_image movl LI32_image_base(%esi), %esi // loaded_image->image_base - movl %ebx, %ebp // startup_32 for efi32_pe_stub_entry + leal (startup_32 - 1b)(%ebx), %ebp // runtime address of startup_32 /* * We need to set the image_offset variable here since startup_32() will * use it before we get to the 64-bit efi_pe_entry() in C code. */ - subl %esi, %ebx - movl %ebx, rva(image_offset)(%ebp) // save image_offset + subl %esi, %ebp // calculate image_offset + movl %ebp, (image_offset - 1b)(%ebx) // save image_offset xorl %esi, %esi jmp efi32_entry // pass %ecx, %edx, %esi // no other registers remain live From patchwork Tue Nov 22 16:10:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24456 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302326wrr; Tue, 22 Nov 2022 08:14:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf6WP2XDR6MzNp8I+y+hMtWstggmXcB65ULg58nwIbHzEU2KEIYyqupV6f2I2OBo0qePDhAs X-Received: by 2002:a63:5a02:0:b0:477:15c9:423b with SMTP id o2-20020a635a02000000b0047715c9423bmr21757418pgb.374.1669133684384; Tue, 22 Nov 2022 08:14:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133684; cv=none; d=google.com; s=arc-20160816; b=Iru4u0+H0Pwg+sGpt25AF4M7nauYKn29FpZocSRjwSC4Skwf/Vm4A5aj6wgT6j5V4O 97Fb2d9I5ZgCWrzLfuSdwY26zqQnDQWyP4PxQVWqZeGKWeFAWdbXArPDRfm9V6XaMfkb ItFdXff3cUlZw+NlGNUz+Ca8am42hbVR/jU2576fFGRvwMNJBtF/0hDavJKIGA6hM/fm ix1VxlHE5ZfUYYrb1Mz8FsHEmKOvgl2ejTyZEWzAGsBfBOqykDGx/ajeteUrhwgmwsUS hOSE1rWuXDvuX4bbJ3zIWQOdDys5LBKX6yT2CpO/hftCVsmUMuXsJuI6Va7HZYgWiKgP bJ3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=piwe8K75UkalF/Vu3HztiOcs6R8jniAYxlqed8CEXBM=; b=y/2WBFTfYL9fqAZ4hrt+e9rI+qOeKk7PsE1TnBDT3SAn5sU182JRKCrkLoXrfbIaNs ek/4hhnN/jYDsvGhWxR0WViHegM0zd0MZZpkYx9nO8RIfHApitbTAtF3MWcv61rea+cr 0TKJ1L1E4zzTnCUuCWGfG50ZQmksSgpUd9efBUGelAXx20EUshiMFDT4X2KDaCE/YR/I vKw2xS2IPMX3UkufK0bQ+Rtx5eHIJ//PABa4fFZ+fBewVkJIwSHhtJFnssFC/r4vYHRD kKTjlvS6bM9KnqDMKavRODm8sjnZNvtHNfOPTjBdcWlfangu30UDtMxggKRIdA8pGRrb EEbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KasLeOcV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020a056a00114200b00557eeeb099csi15194377pfm.339.2022.11.22.08.14.26; Tue, 22 Nov 2022 08:14:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KasLeOcV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233358AbiKVQLL (ORCPT + 99 others); Tue, 22 Nov 2022 11:11:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234205AbiKVQLD (ORCPT ); Tue, 22 Nov 2022 11:11:03 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91272742CB; Tue, 22 Nov 2022 08:10:46 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 434A0B81C0D; Tue, 22 Nov 2022 16:10:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31F17C433D7; Tue, 22 Nov 2022 16:10:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133444; bh=tZGzPcZmAcGsWu7+zFKgxe2N03AY23KDGmZFylxg1pw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KasLeOcVIxriQma5aHt7FjrY54w9HG/jfjpYCQAnvLgcRI+e1Ba5vxJqGqJ0+qMAT tSapIi4LRGoSwU1eoFrGhJBoqkqVPqH2ubaNNGPKYm4BQ67oyEGdKeYpVqhkmBVClm vsFwlprf212IYPyfM77CFRXkmTgibgquvD7l996RnsWf8z0eupycBBMNWFDdsYteUy t7jwMqwJdbhELhmePiiuu5zPquyMLuGoiUOWhucjm2MjVEjQ7rQSsdKiHDDtImHd4d oaIZr7hclo/3o5effQ8pODCMLLFNcOJ9JTNGenE5MLkxDwUQVhXFncczZEAbwEKeY4 7YxA0fHYlowwg== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 05/17] x86/compressed: efi-mixed: move efi32_entry out of head_64.S Date: Tue, 22 Nov 2022 17:10:05 +0100 Message-Id: <20221122161017.2426828-6-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4945; i=ardb@kernel.org; h=from:subject; bh=tZGzPcZmAcGsWu7+zFKgxe2N03AY23KDGmZFylxg1pw=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRVvLVcT2XQ/GHHG/VENjFiTSdl7lZ35vBnkfbI JTrxCIaJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0VQAKCRDDTyI5ktmPJPcCC/ 98FrxNmvlO1mtu+HHPbrIllxlSyVNnVqrA4M+I2uawGhlAMQoGEaFsIo36jghE3ejgPhavycmvjI7e p3zHiALSK8T8ekTwwfGGaK4AcCFcUPjzr25D/ka0lJnMoq7Jtt1qPzft3n7bCo4yGedh5F3rluu8lg u8P8i/S++sq8Mnq3dzF8XHnXogE7V/e1a/P42Q8vKj3sb0DWmKzO3VnirAyTR+1Z+4kB5UEWR5THW+ XAc2uPg8FCLHxonSn7jtECB9mgl8RJdoT/mk77yUC7e9T9kb0TfqyqSjaI029B4hoRHeoQMlVxgPAh PiSXxGzCpPjOWqTFxyTw8Vmiyuh1LLo9A09BJdP3hppk2gHwSCIwkKFg98NupUVZb9hULE9/4fGjDL pDL6pYa+aIvsCbyKtsEnIh/npJNZM31cvLBMpelvgHGsa8GZt+3uzYovwV1tZ2sQXRP62XV6J59E29 32WaILJrHCIsNoeNcAM4XmJRIo84qo9cXxCY2PbUqDyTg= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213522503931678?= X-GMAIL-MSGID: =?utf-8?q?1750213522503931678?= Move the efi32_entry() routine out of head_64.S and into efi-mixed.S, which reduces clutter in the complicated startup routines. It also permits linkage of some symbols used by code to be made local. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/efi_mixed.S | 57 ++++++++++++++++---- arch/x86/boot/compressed/head_64.S | 45 ---------------- 2 files changed, 47 insertions(+), 55 deletions(-) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S index 58ab2e1ffd92afbc..3487484ac1fd5c6c 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -105,7 +105,7 @@ SYM_FUNC_START(__efi64_thunk) /* * Switch to IDT and GDT with 32-bit segments. This is the firmware GDT * and IDT that was installed when the kernel started executing. The - * pointers were saved at the EFI stub entry point in head_64.S. + * pointers were saved by the efi32_entry() routine below. * * Pass the saved DS selector to the 32-bit code, and use far return to * restore the saved CS selector. @@ -217,22 +217,59 @@ SYM_FUNC_START_LOCAL(efi_enter32) lret SYM_FUNC_END(efi_enter32) +/* + * This is the common EFI stub entry point for mixed mode. + * + * Arguments: %ecx image handle + * %edx EFI system table pointer + * %esi struct bootparams pointer (or NULL when not using + * the EFI handover protocol) + * + * Since this is the point of no return for ordinary execution, no registers + * are considered live except for the function parameters. [Note that the EFI + * stub may still exit and return to the firmware using the Exit() EFI boot + * service.] + */ +SYM_FUNC_START(efi32_entry) + call 1f +1: pop %ebx + + /* Save firmware GDTR and code/data selectors */ + sgdtl (efi32_boot_gdt - 1b)(%ebx) + movw %cs, (efi32_boot_cs - 1b)(%ebx) + movw %ds, (efi32_boot_ds - 1b)(%ebx) + + /* Store firmware IDT descriptor */ + sidtl (efi32_boot_idt - 1b)(%ebx) + + /* Store boot arguments */ + leal (efi32_boot_args - 1b)(%ebx), %ebx + movl %ecx, 0(%ebx) + movl %edx, 4(%ebx) + movl %esi, 8(%ebx) + movb $0x0, 12(%ebx) // efi_is64 + + /* Disable paging */ + movl %cr0, %eax + btrl $X86_CR0_PG_BIT, %eax + movl %eax, %cr0 + + jmp startup_32 +SYM_FUNC_END(efi32_entry) + .data .balign 8 -SYM_DATA_START(efi32_boot_gdt) +SYM_DATA_START_LOCAL(efi32_boot_gdt) .word 0 .quad 0 SYM_DATA_END(efi32_boot_gdt) -SYM_DATA_START(efi32_boot_idt) +SYM_DATA_START_LOCAL(efi32_boot_idt) .word 0 .quad 0 SYM_DATA_END(efi32_boot_idt) -SYM_DATA_START(efi32_boot_cs) - .word 0 -SYM_DATA_END(efi32_boot_cs) - -SYM_DATA_START(efi32_boot_ds) - .word 0 -SYM_DATA_END(efi32_boot_ds) +SYM_DATA_LOCAL(efi32_boot_cs, .word 0) +SYM_DATA_LOCAL(efi32_boot_ds, .word 0) +SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0, 0) +SYM_DATA(efi_is64, .byte 1) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 8192ab1c308567ce..8fa92ce5610e5329 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -297,48 +297,6 @@ SYM_FUNC_START(efi32_stub_entry) popl %esi jmp efi32_entry SYM_FUNC_END(efi32_stub_entry) - - .text -/* - * This is the common EFI stub entry point for mixed mode. - * - * Arguments: %ecx image handle - * %edx EFI system table pointer - * %esi struct bootparams pointer (or NULL when not using - * the EFI handover protocol) - * - * Since this is the point of no return for ordinary execution, no registers - * are considered live except for the function parameters. [Note that the EFI - * stub may still exit and return to the firmware using the Exit() EFI boot - * service.] - */ -SYM_FUNC_START_LOCAL(efi32_entry) - call 1f -1: pop %ebx - - /* Save firmware GDTR and code/data selectors */ - sgdtl (efi32_boot_gdt - 1b)(%ebx) - movw %cs, (efi32_boot_cs - 1b)(%ebx) - movw %ds, (efi32_boot_ds - 1b)(%ebx) - - /* Store firmware IDT descriptor */ - sidtl (efi32_boot_idt - 1b)(%ebx) - - /* Store boot arguments */ - leal (efi32_boot_args - 1b)(%ebx), %ebx - movl %ecx, 0(%ebx) - movl %edx, 4(%ebx) - movl %esi, 8(%ebx) - movb $0x0, 12(%ebx) // efi_is64 - - /* Disable paging */ - movl %cr0, %eax - btrl $X86_CR0_PG_BIT, %eax - movl %eax, %cr0 - - jmp startup_32 -SYM_FUNC_END(efi32_entry) - __HEAD #endif .code64 @@ -771,9 +729,6 @@ SYM_DATA_END_LABEL(boot32_idt, SYM_L_GLOBAL, boot32_idt_end) SYM_DATA(image_offset, .long 0) #endif #ifdef CONFIG_EFI_MIXED -SYM_DATA(efi32_boot_args, .long 0, 0, 0) -SYM_DATA(efi_is64, .byte 1) - #define ST32_boottime 60 // offsetof(efi_system_table_32_t, boottime) #define BS32_handle_protocol 88 // offsetof(efi_boot_services_32_t, handle_protocol) #define LI32_image_base 32 // offsetof(efi_loaded_image_32_t, image_base) From patchwork Tue Nov 22 16:10:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24457 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302391wrr; Tue, 22 Nov 2022 08:14:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf6KWPaS0+JVUote/wm8uyscG4CMMlh7aPXGxJWNp9fXJuZs+3FNnz0qdDVQiPb66EnDFTUn X-Received: by 2002:aa7:9546:0:b0:562:5026:b136 with SMTP id w6-20020aa79546000000b005625026b136mr6190312pfq.84.1669133691793; Tue, 22 Nov 2022 08:14:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133691; cv=none; d=google.com; s=arc-20160816; b=xlZNPyN0XjxcWikV2xhuiRZo4qe7urXQFnqlKCs0n5ib7Th73mX7CTYzfx1iho5eVT EjIuTU3p1lhOXFKzg8SWvhHQpzYEb/5kqMUnThmcbj8uNOCpyiUbaTnzCDbe38QdMMT2 UQS/t6hDUYUK2ooWTdVzFvFmWpz4jHvrvCIT5MOQR+BvSBZw/lEuud8qnYO7p8nXaGEz 836I/e71sJg7Ei/XUiSrJcWAJM7JeIkgFAn3yBhgtbS/iNoN8Oip9Gw48mddZWihphF1 ykwpZ+N8gyQE2/1NA0yAzeisSXb9LiGOJQXultGfw2paUKsvXPbi7lCngzIhhND9vgXQ h1gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=P5Kpadsoqu98XvtuR5TkzqNT6nMJ6DT/lINikgy87JQ=; b=HBFllVzTv7P3yrEN+Fts5zgE3zqsRPa7VIuvxA5idlldqijFWdcefNeeM8pZRpnyCs 1XXLcBsYRHm0lY3FkgTFiZa9klKLt45rVoN2dEIhvH0iUsU0V2aCr+XA3YsMcQDspEUj /dPtB+6fRpQ4vLacCNh1llprk2GTxgOjej9DljdMMVe/0ccZLorTkln8nm0HJHLcxa1u BHBAEmTODZuGmI3e7saK1PdZN/93r9dmXFFXddCYtHadMoiv1La8ulAqyBQa/vYC2Eho qU1WFiSW7r78RwCdgTtAcU3F/h0AT6fpc/Q6IYUp7uc7YqQrfnQDyW0Pz/85DjvrAd2O ktsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wmbz6c7s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jb22-20020a170903259600b0017c0d822437si759023plb.82.2022.11.22.08.14.35; Tue, 22 Nov 2022 08:14:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wmbz6c7s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233973AbiKVQLQ (ORCPT + 99 others); Tue, 22 Nov 2022 11:11:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233821AbiKVQLD (ORCPT ); Tue, 22 Nov 2022 11:11:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C539742D2; Tue, 22 Nov 2022 08:10:47 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B864461740; Tue, 22 Nov 2022 16:10:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 677BDC433D6; Tue, 22 Nov 2022 16:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133446; bh=Hw2/NHAhXb/vWGw1F6zOY2IxnO/vI56SXymPfFRSUKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wmbz6c7s/QjSXFggLzZ4w1sGHWgtUImVrkPWB/n2JEspTcOqnBTUwL30pVtjkLd5g nqHnme2/N5IEx2ipvrQ5bbhiROhegasy5KvUwug5TOUZMkPW0nTIJuvUy9PF+LUx7I UwOhS6ku/Tqjabtz9k6EXybxeipy7w6TfmBaabakeWHdJ9wYRPRYdixE2MjS9KMuHd I8xtBRUffBZEjhGU2UNAIEP1l0xeV2U1FZcqr4Hi7T6ewyzEttEpWV8QRmMeZWuis0 li6xSlhd+5Zxepd1qYM3+u2Vwmd+8+gsrpopPhJJTiFtXJkXTXf6Fz6yFa2FMoN52P 3v3ywoO2gcQ1A== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 06/17] x86/compressed: efi-mixed: move efi32_pe_entry() out of head_64.S Date: Tue, 22 Nov 2022 17:10:06 +0100 Message-Id: <20221122161017.2426828-7-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6730; i=ardb@kernel.org; h=from:subject; bh=Hw2/NHAhXb/vWGw1F6zOY2IxnO/vI56SXymPfFRSUKQ=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRXpdaBO49FmkrTW40LuSlfKSo3t3bQsuE4oOGM nwvgMuyJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0VwAKCRDDTyI5ktmPJFa9C/ 4nGoOyFT2p0SubaaT/MMeYHxRqD9638ZAXP9/Ijfb8Im8HOUrwAKxyJeOHiVOZql+xkiqUjjrV+mLC xeP15VWd00MxkDtYspoGEBhbuSASdKxCE+77M1wSYTDjX5Mu2EpdA2+vYiezj8KM0bo3qur8rJDJf/ pGL5qw0jThhSzQa9DM0xu2EAs+O91gqa12w4tc1bhZTjZ7mCWfvGpHVgPHZwNd/UYhGixgYQzpNeHm YBlCBUlh5CfcWV9xgbZoQCh6AJ5F/zfwIfCygyFtW/4drymqkh9S7YBxQawa18wtXzu+KjDDA7AXWu 0c96UNWj+Iut5mgXZAI/YP/X5pYBrAA4Q02TkBABOfPrVxlHhWM6lir9QxmNFXrJqyUGht8I8SHdT7 riJgksOdV4hjcBMCpHk169KbWPPnZoxO5K1J3LFtvzlyN85yPTh/vQb0ESZ3J9eP2zZV0lWlbbE/KG E13CuE6uNqrkoiyp+PvubD4DpqH4+rd3IdWvc9Hx/ccoc= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213529617975092?= X-GMAIL-MSGID: =?utf-8?q?1750213529617975092?= Move the implementation of efi32_pe_entry() into efi-mixed.S, which is a more suitable location that only gets built if EFI mixed mode is actually enabled. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/efi_mixed.S | 82 ++++++++++++++++++ arch/x86/boot/compressed/head_64.S | 87 +------------------- 2 files changed, 83 insertions(+), 86 deletions(-) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S index 3487484ac1fd5c6c..8844d8ed4b1c7561 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -257,6 +257,88 @@ SYM_FUNC_START(efi32_entry) jmp startup_32 SYM_FUNC_END(efi32_entry) +#define ST32_boottime 60 // offsetof(efi_system_table_32_t, boottime) +#define BS32_handle_protocol 88 // offsetof(efi_boot_services_32_t, handle_protocol) +#define LI32_image_base 32 // offsetof(efi_loaded_image_32_t, image_base) + +/* + * efi_status_t efi32_pe_entry(efi_handle_t image_handle, + * efi_system_table_32_t *sys_table) + */ +SYM_FUNC_START(efi32_pe_entry) + pushl %ebp + movl %esp, %ebp + pushl %eax // dummy push to allocate loaded_image + + pushl %ebx // save callee-save registers + pushl %edi + + call verify_cpu // check for long mode support + testl %eax, %eax + movl $0x80000003, %eax // EFI_UNSUPPORTED + jnz 2f + + call 1f +1: pop %ebx + + /* Get the loaded image protocol pointer from the image handle */ + leal -4(%ebp), %eax + pushl %eax // &loaded_image + leal (loaded_image_proto - 1b)(%ebx), %eax + pushl %eax // pass the GUID address + pushl 8(%ebp) // pass the image handle + + /* + * Note the alignment of the stack frame. + * sys_table + * handle <-- 16-byte aligned on entry by ABI + * return address + * frame pointer + * loaded_image <-- local variable + * saved %ebx <-- 16-byte aligned here + * saved %edi + * &loaded_image + * &loaded_image_proto + * handle <-- 16-byte aligned for call to handle_protocol + */ + + movl 12(%ebp), %eax // sys_table + movl ST32_boottime(%eax), %eax // sys_table->boottime + call *BS32_handle_protocol(%eax) // sys_table->boottime->handle_protocol + addl $12, %esp // restore argument space + testl %eax, %eax + jnz 2f + + movl 8(%ebp), %ecx // image_handle + movl 12(%ebp), %edx // sys_table + movl -4(%ebp), %esi // loaded_image + movl LI32_image_base(%esi), %esi // loaded_image->image_base + leal (startup_32 - 1b)(%ebx), %ebp // runtime address of startup_32 + /* + * We need to set the image_offset variable here since startup_32() will + * use it before we get to the 64-bit efi_pe_entry() in C code. + */ + subl %esi, %ebp // calculate image_offset + movl %ebp, (image_offset - 1b)(%ebx) // save image_offset + xorl %esi, %esi + jmp efi32_entry // pass %ecx, %edx, %esi + // no other registers remain live + +2: popl %edi // restore callee-save registers + popl %ebx + leave + RET +SYM_FUNC_END(efi32_pe_entry) + + .section ".rodata" + /* EFI loaded image protocol GUID */ + .balign 4 +SYM_DATA_START_LOCAL(loaded_image_proto) + .long 0x5b1b31a1 + .word 0x9562, 0x11d2 + .byte 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b +SYM_DATA_END(loaded_image_proto) + .data .balign 8 SYM_DATA_START_LOCAL(efi32_boot_gdt) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 8fa92ce5610e5329..987f0a3c284fad43 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -681,6 +681,7 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lno_longmode) jmp 1b SYM_FUNC_END(.Lno_longmode) + .globl verify_cpu #include "../../kernel/verify_cpu.S" .data @@ -728,92 +729,6 @@ SYM_DATA_END_LABEL(boot32_idt, SYM_L_GLOBAL, boot32_idt_end) #ifdef CONFIG_EFI_STUB SYM_DATA(image_offset, .long 0) #endif -#ifdef CONFIG_EFI_MIXED -#define ST32_boottime 60 // offsetof(efi_system_table_32_t, boottime) -#define BS32_handle_protocol 88 // offsetof(efi_boot_services_32_t, handle_protocol) -#define LI32_image_base 32 // offsetof(efi_loaded_image_32_t, image_base) - - .text - .code32 -SYM_FUNC_START(efi32_pe_entry) -/* - * efi_status_t efi32_pe_entry(efi_handle_t image_handle, - * efi_system_table_32_t *sys_table) - */ - - pushl %ebp - movl %esp, %ebp - pushl %eax // dummy push to allocate loaded_image - - pushl %ebx // save callee-save registers - pushl %edi - - call verify_cpu // check for long mode support - testl %eax, %eax - movl $0x80000003, %eax // EFI_UNSUPPORTED - jnz 2f - - call 1f -1: pop %ebx - - /* Get the loaded image protocol pointer from the image handle */ - leal -4(%ebp), %eax - pushl %eax // &loaded_image - leal (loaded_image_proto - 1b)(%ebx), %eax - pushl %eax // pass the GUID address - pushl 8(%ebp) // pass the image handle - - /* - * Note the alignment of the stack frame. - * sys_table - * handle <-- 16-byte aligned on entry by ABI - * return address - * frame pointer - * loaded_image <-- local variable - * saved %ebx <-- 16-byte aligned here - * saved %edi - * &loaded_image - * &loaded_image_proto - * handle <-- 16-byte aligned for call to handle_protocol - */ - - movl 12(%ebp), %eax // sys_table - movl ST32_boottime(%eax), %eax // sys_table->boottime - call *BS32_handle_protocol(%eax) // sys_table->boottime->handle_protocol - addl $12, %esp // restore argument space - testl %eax, %eax - jnz 2f - - movl 8(%ebp), %ecx // image_handle - movl 12(%ebp), %edx // sys_table - movl -4(%ebp), %esi // loaded_image - movl LI32_image_base(%esi), %esi // loaded_image->image_base - leal (startup_32 - 1b)(%ebx), %ebp // runtime address of startup_32 - /* - * We need to set the image_offset variable here since startup_32() will - * use it before we get to the 64-bit efi_pe_entry() in C code. - */ - subl %esi, %ebp // calculate image_offset - movl %ebp, (image_offset - 1b)(%ebx) // save image_offset - xorl %esi, %esi - jmp efi32_entry // pass %ecx, %edx, %esi - // no other registers remain live - -2: popl %edi // restore callee-save registers - popl %ebx - leave - RET -SYM_FUNC_END(efi32_pe_entry) - - .section ".rodata" - /* EFI loaded image protocol GUID */ - .balign 4 -SYM_DATA_START_LOCAL(loaded_image_proto) - .long 0x5b1b31a1 - .word 0x9562, 0x11d2 - .byte 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b -SYM_DATA_END(loaded_image_proto) -#endif #ifdef CONFIG_AMD_MEM_ENCRYPT __HEAD From patchwork Tue Nov 22 16:10:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24450 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2301820wrr; Tue, 22 Nov 2022 08:13:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf5uULus9x4PSQ3+eZ90x8MJWpX4daQas7BiJOkk/0jSvjx/i8kA6MEXxT2vplzv52+ew4jc X-Received: by 2002:a17:902:f391:b0:188:abcc:249f with SMTP id f17-20020a170902f39100b00188abcc249fmr5001626ple.44.1669133623004; Tue, 22 Nov 2022 08:13:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133622; cv=none; d=google.com; s=arc-20160816; b=Rc0aerSTV0J6IEgOH3U910oAbgDrlNH7ENVPuDHoe1d2DE5/wXMAzvwU6+3jQQXaGC sA9oH9XANg9UvCiYRiAxroq2MYAZJCZvgnMOBpkn++jzMRUlAOcDzgVclu/6YgK6Y6e7 ykn7bmm3rv1OKZrzHTEEIbeKAd3zngEie0OjfoZ583olNMAbyKD2zAf5LXLleEXL9xGz YbmqjIStZGDmZ/3+lUsVYE87UHkTUIpA+X/ybnm64x08csd0tjG6QVCUjMoy72INijOR /q8QUM/8b6ivR0WVpiv/9zG8uadsmVPvH8HHdaOiEVZGXBX3pO28VRzJ69DDEdEPz8qq vaGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kBw+2xOxAHAb0ZJqI2nCOf9TcEuR8bVYqp/JmLm2nbE=; b=0UCN0lD8DSDW5BgCFrrVC44K1Mt4GxaVuPDCef6141qfgu75ASfoIEIX6ep3z0guew 4cBAxUDiOmD6hGPt9T7bUKFBnetGW/zy5KQHe0RdPOsyvZMB+fNB81iHdR4QiB1WOZNh a7cVpC+/nGiRNifful6x+f/if8NxY6nUa9HoxOR35LRNp4D+Kq7MJqWyIhVV0aKWPRL5 W6jqcXzffC5KYco+DrecmMaVLGnqQDWnrAS57kJUFPOc+lJsR5sW/MSXuPl9tecirIq0 0uKQgAQArHboKKulo1Ny7lZYSIabKGMLWpmr8I/Z2/fUaORyXDNNhFQwYffMtMRFvd0G FCjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BiufXI+m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i189-20020a6387c6000000b00477b4b68f09si497250pge.258.2022.11.22.08.13.28; Tue, 22 Nov 2022 08:13:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BiufXI+m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234282AbiKVQLY (ORCPT + 99 others); Tue, 22 Nov 2022 11:11:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234224AbiKVQLF (ORCPT ); Tue, 22 Nov 2022 11:11:05 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AEED742DA; Tue, 22 Nov 2022 08:10:51 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 988C5B81C10; Tue, 22 Nov 2022 16:10:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C880C433B5; Tue, 22 Nov 2022 16:10:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133448; bh=tOdWUuW+7rgqllOBTMdmkxOryu+AGCsLR6dgpWQteso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BiufXI+mj44YUUusTzdntIlg0lRmgwZYJPkPpwLrUsCR8FBC+urQixAow657MZ5QW CefK9ug9CnRFw8SbUFp+/CII3Zge+H426s8CUgwsJoEJ2WDM5xfERDkex3DknWnJXE gcx85eg+sh9YXyyRTcOy+yAf+GjtKhu7kJ1JCe5Bttfb8F18WaSr8nENWtPKqepLLj ykaqG7c8+06m2HVtvxEdHHhKdM3XgitW1YRsswnVjrwHw7n8r6af9kVH3bfkn89KOO TE+3/6tvztwMbs0DycWr500DEizlVVgMpz1rh5csu5nasd2MscRDD/MPeLlbomsj2g /QL8HHe7ziJbg== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 07/17] x86/compressed: efi: merge multiple definitions of image_offset into one Date: Tue, 22 Nov 2022 17:10:07 +0100 Message-Id: <20221122161017.2426828-8-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1868; i=ardb@kernel.org; h=from:subject; bh=tOdWUuW+7rgqllOBTMdmkxOryu+AGCsLR6dgpWQteso=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRYC6Q2FjOROO3g/kYMKd+j9GKGxB5vZLG55iXf a8HbgceJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0WAAKCRDDTyI5ktmPJMJoC/ 9tRpz6EuotfivDhIcQDtygpLQicCtE3UjIExGFiK0FyZ9yappBSj+HZXMRE7UK2j9VvkxNB+6fubLx HPXGIWaFPass4WDoo+RPCJjtrMhyQ8o+Tvaf9BglY981Bikni+FdPVomUa2FVTmWeitHLY2EjyldVb HM+gMQFyFwbssI85/Hhm7RiLr6BF6Qo47Dj2rvrOfzVgnMYy4q44RZJ9lGfNIzZhkRB9lndQC7ksb+ 6u5UbObuRQh20g+49oLscw8CybFdLj7T8k1AHX5Wv3W7/rFl5z1qU1hT61bwXglm82elPDhxqvekXM PzK0lnEWOBzXn1jCC6T77I64FUQPiP6DGyaWJ3TJ82VACxjBoBTOK8dw+CeYdA2KGRC6rOkX/SaXaQ pkq9Cg00EY8HinC+0SWf3PJgOnTVEXQ/az5HRkUhbFNhdV/Jx5WxKPOFkHjlk3v0GjGfNS2anD++Rc XukCkruMnp+ffXQlSPydA036uiPwNKmvXkPKMax5kjc7A= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213457644406144?= X-GMAIL-MSGID: =?utf-8?q?1750213457644406144?= There is no need for head_32.S and head_64.S both declaring a copy of the globale 'image_offset' variable, so drop those and make the extern C declaration the definition. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_32.S | 4 ---- arch/x86/boot/compressed/head_64.S | 4 ---- drivers/firmware/efi/libstub/x86-stub.c | 2 +- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index 3b354eb9516df416..6589ddd4cfaf2cb6 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S @@ -208,10 +208,6 @@ SYM_DATA_START_LOCAL(gdt) .quad 0x00cf92000000ffff /* __KERNEL_DS */ SYM_DATA_END_LABEL(gdt, SYM_L_LOCAL, gdt_end) -#ifdef CONFIG_EFI_STUB -SYM_DATA(image_offset, .long 0) -#endif - /* * Stack and heap for uncompression */ diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 987f0a3c284fad43..66ad3ab802ca9d0c 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -726,10 +726,6 @@ SYM_DATA_START(boot32_idt) SYM_DATA_END_LABEL(boot32_idt, SYM_L_GLOBAL, boot32_idt_end) #endif -#ifdef CONFIG_EFI_STUB -SYM_DATA(image_offset, .long 0) -#endif - #ifdef CONFIG_AMD_MEM_ENCRYPT __HEAD .code32 diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 33a7811e12c65642..cb5f0befee57d2ec 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -23,7 +23,7 @@ const efi_system_table_t *efi_system_table; const efi_dxe_services_table_t *efi_dxe_table; -extern u32 image_offset; +u32 image_offset; static efi_loaded_image_t *image = NULL; static efi_status_t From patchwork Tue Nov 22 16:10:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24451 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302080wrr; Tue, 22 Nov 2022 08:14:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf79SqmArcZbSe07nr3VNlu1XfyxGDeCBbJIweGydCRG8ypOdlx+M0xeTelYzxRmfzAFRNKx X-Received: by 2002:a17:90a:ae0f:b0:20d:b124:33b1 with SMTP id t15-20020a17090aae0f00b0020db12433b1mr25846194pjq.202.1669133654972; Tue, 22 Nov 2022 08:14:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133654; cv=none; d=google.com; s=arc-20160816; b=fBiZwB+e399rEcM3+gC+g6tzHbix+A9WspkQdSINGi/rxJbigtLr1cBF5lC1Qe5TcY Og0ETSZTCYNwq04EL1Xs/EmG7dPhKFDNcwKDcUiiBPmcHqIoJEY+zc+zXnx2wksX23aT iCPGkUmjnShxcnDgue5fBK96TqA7znDAzuNVClKsFimmlIFKEgCYRtVmsSjgKPnmG6Kq xGND0n+yzJvuzhN7GX3bYesfS0ye9Dp41DJNsPGLe256eMMRzbojSLl4TTFsF5pOli6b w2KNSc+AahnHTwGGOfvFwhwH/nsRNIbdAn4PFUGkc0WaUYHSFvXqjdwaP7xOV3a2wmsc bL7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=THcQIWKNjc8aYvog99Ju0rQTJDpP1oBswH1xDPyCyHk=; b=MXNhp01jM/yyV4nGr9eZhKVdSAHliA24D2+z0EXC92wcXlAwB2EKJ8kledQ1/RFy9o fycWWd7ilSxuNViHwVZL3jEaRiT4bKI7eJFlmLFkhPbhCpKJ9XDVKPw6MhDKLeiu0jor 71S+GYglAkK7Ywoin+0zzqg55glSzwt1Iv8jBdm4mt+Muidpah2SLkF9gyBe4GmPx+hK 7ck3eEOj8BFvXBXu6EgL+5jUW8uF53l/GZOR3YzfOJE3ofqg51t4H4BCgh49QAnZ8vq2 NbLxTCs+0BcsZQFxHa76kLy/uwpf0g4jC7cymawkW5tGTSTN4Sxp5B9o/uW1Z/lsWvBL brVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SiQbk7Da; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k4-20020a63d104000000b0046fb2a57348si14102017pgg.84.2022.11.22.08.13.59; Tue, 22 Nov 2022 08:14:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SiQbk7Da; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229628AbiKVQLi (ORCPT + 99 others); Tue, 22 Nov 2022 11:11:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234227AbiKVQLG (ORCPT ); Tue, 22 Nov 2022 11:11:06 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D6A2742F5; Tue, 22 Nov 2022 08:10:53 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CE5E7B81BEE; Tue, 22 Nov 2022 16:10:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1F77C433C1; Tue, 22 Nov 2022 16:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133450; bh=9jyxmHpzfRCJJf9xQ03iz+bA0Xb5QCrz4P3JHsC5SMM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SiQbk7Da54coI7gkcSa+od6Hd1M1+JjCaNn0sFqcdZG0cdtYNtk4vB1aTINWnfSt9 8rfTyvgy6vUlGqeeu5V9XjhwRYFk6HMOy3qCTv95SmUw5yT9d2q+aVSqDvls4VeF+X lsf6RLOVRNnFynZZZTkLyDyUO0XyFuDkCkvd8Pph1wBlGyUwdNnYA6Z6TQtrDqCNQw deqfbqofQxcCxHpuCxXeZIaoZ9daJ8BSrPgtgAVDx9kFudVMdf27mkrsWFvKRLD1gy TMFtctu/fcOjmw2cjOIIr+yUMzat1AipaE3kkWTNRTQobTcd8bdfxCZyltHtVEubWI QAjbhcijIwlUw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 08/17] x86/compressed: efi-mixed: simplify IDT/GDT preserve/restore Date: Tue, 22 Nov 2022 17:10:08 +0100 Message-Id: <20221122161017.2426828-9-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1663; i=ardb@kernel.org; h=from:subject; bh=9jyxmHpzfRCJJf9xQ03iz+bA0Xb5QCrz4P3JHsC5SMM=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRabAmNoz2lPub2d3CamZQemKR8yASDbUtdoT/H Brr43omJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0WgAKCRDDTyI5ktmPJPUKC/ 4t4JhAxm00y83U+Wvv2lAqOINuqkTuhkErVDG15v2jHR+wYw30ix4IghLOwk1iSHqDv0w/bCgPztVD Vw40lqEejjuygLaA/IDUXmKps3vkdJ67GWwpm2mflPDVvXO9gkh9KcU5EmUbPNZIuzO8DBkI45Tfrx wPpTaTILzpbYKv3YH11CzTBHkd8rx8eE+rN4Gd6olfriIBjDReEb6sHyWZKk/kq8iGNDLiPrukp/+s ssN1Upypo9IgxpqwnBR/hAE4BU/uoGabIvrYVpZK7l9J8DiFa82SdRCyIzUcgGBUwkessJq8KMokyT htyKWur2fjznZRSYRAGPsP3xXAbciPsZQFTkTozwyeV3AuFdJldcTsLXLoIez2YElX/Epm0RhwOaUJ Zt5RvDMgD36pIqAN5xYqx/T40dY74SZaG9w4GQGMwUz+AX1gKo9DnYze0fxdNd2ATExubRqB7cv/i/ 2SxSKLq80PD+MvCg8gRWoksHrI7ioxnnKHmJrYSwvEj2c= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213491274907223?= X-GMAIL-MSGID: =?utf-8?q?1750213491274907223?= Tweak the asm and remove some redundant instructions. While at it, fix the associated comment for style and correctness. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/efi_mixed.S | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S index 8844d8ed4b1c7561..8b02e507d3bb055a 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -96,24 +96,20 @@ SYM_FUNC_START(__efi64_thunk) leaq 0x20(%rsp), %rbx sgdt (%rbx) - - addq $16, %rbx - sidt (%rbx) + sidt 16(%rbx) leaq 1f(%rip), %rbp /* - * Switch to IDT and GDT with 32-bit segments. This is the firmware GDT - * and IDT that was installed when the kernel started executing. The - * pointers were saved by the efi32_entry() routine below. + * Switch to IDT and GDT with 32-bit segments. These are the firmware + * GDT and IDT that were installed when the kernel started executing. + * The pointers were saved by the efi32_entry() routine below. * * Pass the saved DS selector to the 32-bit code, and use far return to * restore the saved CS selector. */ - leaq efi32_boot_idt(%rip), %rax - lidt (%rax) - leaq efi32_boot_gdt(%rip), %rax - lgdt (%rax) + lidt efi32_boot_idt(%rip) + lgdt efi32_boot_gdt(%rip) movzwl efi32_boot_ds(%rip), %edx movzwq efi32_boot_cs(%rip), %rax @@ -187,9 +183,7 @@ SYM_FUNC_START_LOCAL(efi_enter32) */ cli - lidtl (%ebx) - subl $16, %ebx - + lidtl 16(%ebx) lgdtl (%ebx) movl %cr4, %eax From patchwork Tue Nov 22 16:10:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24452 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302130wrr; Tue, 22 Nov 2022 08:14:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf5xBCybP+rfRKMCNSD2U0bqp0NFuIpfEF01rBgTM6QRjiVv/UvJwvGhNZjs94nDwKTTeISw X-Received: by 2002:a17:903:31cd:b0:179:f88b:f288 with SMTP id v13-20020a17090331cd00b00179f88bf288mr4629950ple.44.1669133662047; Tue, 22 Nov 2022 08:14:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133662; cv=none; d=google.com; s=arc-20160816; b=uGl4u1mZ9gDCqEYi0svzv4foLzqUAz0gyrac1Rt3tAl3145b+5SJg/MXiuJ95TrO+V TM+ouD0SavDAi3I0Pd71D6jaVT3zmLfpp6x3BMqmBagYMi8M8Fg9elZTMqQv7GhwvgQx ZCbp7aDjRsRjBWOaf0LS4u2ADWxvSAjZ+NcGp5UozfjfPy5ILlbqhO09sgG2NPwfyVKy iNj3rRkGaSGHzqi5Yy4dKQ8mQwsd+PMK9BtxLiJFp2e6R3NwvOY32CzBIWYQrqM1wwba B6g2K+kCQv9HCIV5vy85sfx0UVEFFUALa5CmpWOFHYF8Pkp1TBTl6yWk5/t9ci/Z6D2E YwOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eGmtjH1DYmdXTysjVmKBPajcgK4WcVX2EMZGVsuvpmU=; b=p6cEozTRW2KLWO4D4bUj/CcwUGL5AZ2eKCFQJTJzXyESLKbqdxmYs8Fzvd/fsxBvud Pko/rMKe3BnEuJV6fmK6CQB7X7U5GcmWTVdqywnp/FcQzW8ZxXwTvcy//CyQU4CoupwD 2YFtZAWSYP823PZvs11fDotYWVnW221rDgItpAXt1lt/zsc9Ysldp4kvc/x2Phaoi24o 4rxsoutvIJKJ0SqZb6CaWjWfRHYiNJDwUI9iaWdEF/Z9PUn+cdJGLGdPi1yOQypbretX N4r0WMT/vjav6otaHDjmwX/bfYpAkJsNA6M23qEh5AQCX2g6djzAwq5gWVz0SGTfwSD0 t1KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rP8QYEhs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a056a00141300b005659a66d652si15370369pfu.229.2022.11.22.08.14.07; Tue, 22 Nov 2022 08:14:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rP8QYEhs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234301AbiKVQLk (ORCPT + 99 others); Tue, 22 Nov 2022 11:11:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234252AbiKVQLG (ORCPT ); Tue, 22 Nov 2022 11:11:06 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0B7A742FA; Tue, 22 Nov 2022 08:10:53 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 69CDE61740; Tue, 22 Nov 2022 16:10:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13562C4347C; Tue, 22 Nov 2022 16:10:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133452; bh=ZQv9+X1iJK9wCaH0UdAvPwmkreYOyHzQ5yoM8JDBf4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rP8QYEhs/Yv0vTP+DydzJhp++6EoqkR+xXkXY9SUY5zVuPKW1OBmTPtU0HKQx9RfQ l8QCamavVEscgs9v9wyLMTuoMUeqMnoayuFBcYlKI15qaAyZD15DJlYJJxqlTmRr7N 1N2iMl0xAskzGmrLhzq7+E3uyNBBy9aP6jve3ps7wf3SB1xOHQDIBLrxAlQ8bKSd9+ Ggt/pt5ISA0QROeCTn4ygrZ8dAs1BNJlchPnuhJsFVAPD6fsUSLnpOGBgV5wMT0thI WD/d367a/gVrSUGleowaH3aEm3ohjc2xSP/Hkagm+Fh2D/AR+Obbvtrj9EFve4I9Xv DXcMAPhz2tPiQ== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 09/17] x86/compressed: avoid touching ECX in startup32_set_idt_entry() Date: Tue, 22 Nov 2022 17:10:09 +0100 Message-Id: <20221122161017.2426828-10-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1572; i=ardb@kernel.org; h=from:subject; bh=ZQv9+X1iJK9wCaH0UdAvPwmkreYOyHzQ5yoM8JDBf4A=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRbNOEMtTo47vx2jAN2Z59KRsBmjvCYdb205ac7 Cv/CzdaJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0WwAKCRDDTyI5ktmPJMBhC/ 9YvZjPjTtVifhaj3PVkOErn74GJ54+p0Yk1QiI2OSd+mr6sNcibNqgldEtqhOUXOpWxoNUld2Na7sx TbCsuvenJqmE6G3NX3B/qpnikHYnLm9vjgoZPxIgGFkBA5iIf9WF3wY3kl/31Pw7XkGoFFGyXODjs0 tWeAVgmWJE5S0RQodZ6fQUuESapXpwcobXuJUslwDqhgtUMKm8o9itj+FCEb1XuWU98LzzMJFLa48D Yek7l/df2rVTYUcybGjCVVBqqUMoAeoU6/5oQRTW9k7OmccRfXY1KimPLtujCGYwdD4mVjGHyWxnZP o3szwaE70Fp6vDbxvjLslV4Z0yadrsVJu/O9EdMLpSwuT3AFi3T505Vv0EcN97T59J2rRWDnKUr/AC L9EvMhOsePPNQo7NdixlnvUVCjR1D9gdTQ+tyejktKrDnL2pX41YPpeq6f8Zu7yJ1mX+efsXDluYz8 cbNV+G80miTg9qaZX2m3WE9CTqQsGRBr2xpwCkI0d8Mf0= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213498667931812?= X-GMAIL-MSGID: =?utf-8?q?1750213498667931812?= Avoid touching register %ecx in startup32_set_idt_entry(), by folding the MOV, SHL and ORL instructions into a single ORL which no longer requires a temp register. This permits ECX to be used as a function argument in a subsequent patch. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 66ad3ab802ca9d0c..f31277f455e63f5f 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -741,7 +741,6 @@ SYM_DATA_END_LABEL(boot32_idt, SYM_L_GLOBAL, boot32_idt_end) */ SYM_FUNC_START(startup32_set_idt_entry) push %ebx - push %ecx /* IDT entry address to %ebx */ leal rva(boot32_idt)(%ebp), %ebx @@ -750,10 +749,8 @@ SYM_FUNC_START(startup32_set_idt_entry) /* Build IDT entry, lower 4 bytes */ movl %eax, %edx - andl $0x0000ffff, %edx # Target code segment offset [15:0] - movl $__KERNEL32_CS, %ecx # Target code segment selector - shl $16, %ecx - orl %ecx, %edx + andl $0x0000ffff, %edx # Target code segment offset [15:0] + orl $(__KERNEL32_CS << 16), %edx # Target code segment selector /* Store lower 4 bytes to IDT */ movl %edx, (%ebx) @@ -766,7 +763,6 @@ SYM_FUNC_START(startup32_set_idt_entry) /* Store upper 4 bytes to IDT */ movl %edx, 4(%ebx) - pop %ecx pop %ebx RET SYM_FUNC_END(startup32_set_idt_entry) From patchwork Tue Nov 22 16:10:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24453 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302175wrr; Tue, 22 Nov 2022 08:14:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf6iVU3AjK8cdyFdE3J2je5+8jcJNjz7J6Lb2LSHw4mROIKe2XH7fGRRFOmPzPHg7yAMnhQR X-Received: by 2002:a17:90a:8a82:b0:210:7cd5:db0e with SMTP id x2-20020a17090a8a8200b002107cd5db0emr27386432pjn.30.1669133664938; Tue, 22 Nov 2022 08:14:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133664; cv=none; d=google.com; s=arc-20160816; b=Vb365HzaWbwO3eE9WxdgmBA3nQT2MSIMzBsAnUP+U5rwWp1Ln6SS+JudVIkiq/xwuP hkMm+cZRuHvbDF+LMoX6Eu/qXntYpE0ecd53DFQ40BAJDFh5U6CEfNDJWyiLVJFppgu4 0Dh8OKQveeiXijRcaeoCt4D6bbLLSrvvpm1BGEiJ7hqr0YheNwaDspr5gzOD6Q4ToCVR T1fezib/EWLW0C6ITZl1QU9+EUk1TD4AQ5mcVK01kF6+VCHddVnwI2NNBc8f3CFf9NYE 7Qh7QxbXL/fBcxH+tK9x7Pk0F6TKD1eLStaW6gE5ydyVpVelAcyUeb1M/BEXgPcdGx1y 90Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=l4W9SMLEGMM7PQrWkglCXAQUGZxuBFG4akQH1BB5gOE=; b=06J9KArPe7l7JNfHwSL0Oy1l8iwaHwIM+egaK52vuuWCGIBfdiYRS1g1qaweZN4/ne 7UosyfkEt0XM/M4SvcnelZaWdduqtA+3Q5c4t521Oi5vdLlX3N8xj6USCnaImaHgwGJh 6QAktUciRkda68cZKs4KsyOYneVG2jpzVFE3pco0hFzgWtWUR9cBBeluizGP/2148K8f LPkQt/Fr2T+lpsZq/dZQnqdsZu5q/H61zGRwDzEyXaqExc/nzT5kFimPitRZoLp1UR/o PGHooVufsSbim4k5yX+7PHoiROCorNpkb0wqLzV9JcVh3BmndsCfZqXZXJmSangFd2yQ N/0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XGRVsVzu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pc3-20020a17090b3b8300b00218ac70fdefsi6482317pjb.183.2022.11.22.08.14.10; Tue, 22 Nov 2022 08:14:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XGRVsVzu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233821AbiKVQLo (ORCPT + 99 others); Tue, 22 Nov 2022 11:11:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234090AbiKVQLI (ORCPT ); Tue, 22 Nov 2022 11:11:08 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14B3C742EF; Tue, 22 Nov 2022 08:10:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A425861791; Tue, 22 Nov 2022 16:10:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48367C433B5; Tue, 22 Nov 2022 16:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133455; bh=ZGYYMFhXkrZn+e+cVgRjzokBYpzkxMdbl7BhlbBHuq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XGRVsVzu72nJRrh0T5N78o3GOA+eT5mhSHei+3/rUxm1yaxZE+poMMlUdq6ZactgT AeOgWuHY6np+zLuLXpVRsyq0dF41Iab+ADu0YLEoAytpWqOPLygFWND/Gp1N+SrVNp ujh2x4K7XY41ddIiU8X19SX4odzbLvagQlWSBTsirmKILfnF6hQ8vpf54Z0YB+buis sMeETGVJqHbeYQOlQtpe7/0TErZ5av7oajrF8I9AVp4N1wbh7VFiKpY8LWlfHWHJGf 0+P4679VcYhSojADDfVxwou+CNpBt+apUVaV9G48YSO4xZVJd24GS6wkj2FT93p8/L 4bp5pQVas2ivw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 10/17] x86/compressed: pull global variable ref up into startup32_load_idt() Date: Tue, 22 Nov 2022 17:10:10 +0100 Message-Id: <20221122161017.2426828-11-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2238; i=ardb@kernel.org; h=from:subject; bh=ZGYYMFhXkrZn+e+cVgRjzokBYpzkxMdbl7BhlbBHuq8=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRdh332hSmcyhnd6dWI3Fifx3u18Y9Dg3Bb6nFH 9BBqP/uJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0XQAKCRDDTyI5ktmPJNm3C/ 9t+i6/g+lskjGTDa4HQhq9OhoxKARAIBnekDSTufrRwq7UaYLrC70H2L/MCGzmVfYLB1mMfe+8fs05 4xAtilR1uWESgx3d9uCVVJSZ+ZPKJwirreG5+QYLr3UYwmIGnrQI9b4Q7xAHqqA9DvlXx0Snde9WSV SXk4/5AU6FQ55APrINmR9NgGPypvZhypy1CCyKxTUwRfynt7D8CSukxQpWtniES9Pe3XAMtrAxDYsm H0rQjMgT/XW7BaBFCx/GLHxJh13msz4Ye06DuT8MPnT46e5M9e8JPTtftw+cKfkarb7gSN5zvmNw/U FcCCDilzI5Rki3EDNGlCa/KP4+qoABbC1HepzwlDmJirE5PwVSQ7ug1FcnyWHHq2BhpM76O6uPxMiL aUqYchuPuatfBFGeZfVLu88K5atAk8p63BOFjF5hxJwV1vb4W+MmwW1D0OXMzjCEf+eccGmGzyspD7 PrLCXG0boJOGtG614NiQODtGnvpyZPvcOQ1p0mNEa0IHE= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213501774872871?= X-GMAIL-MSGID: =?utf-8?q?1750213501774872871?= In preparation for moving startup32_load_idt() out of head_64.S and turning it into an ordinary function using the ordinary 32-bit calling convention, pull the global variable reference to boot32_idt up into startup32_load_idt() so that startup32_set_idt_entry() does not need to discover its own runtime physical address, which will no longer be correlated with startup_32 once this code is moved into .text. While at it, give startup32_set_idt_entry() static linkage. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index f31277f455e63f5f..82d7fab99422129f 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -736,16 +736,11 @@ SYM_DATA_END_LABEL(boot32_idt, SYM_L_GLOBAL, boot32_idt_end) * * %eax: Handler address * %edx: Vector number - * - * Physical offset is expected in %ebp + * %ecx: IDT address */ -SYM_FUNC_START(startup32_set_idt_entry) - push %ebx - - /* IDT entry address to %ebx */ - leal rva(boot32_idt)(%ebp), %ebx - shl $3, %edx - addl %edx, %ebx +SYM_FUNC_START_LOCAL(startup32_set_idt_entry) + /* IDT entry address to %ecx */ + leal (%ecx, %edx, 8), %ecx /* Build IDT entry, lower 4 bytes */ movl %eax, %edx @@ -753,7 +748,7 @@ SYM_FUNC_START(startup32_set_idt_entry) orl $(__KERNEL32_CS << 16), %edx # Target code segment selector /* Store lower 4 bytes to IDT */ - movl %edx, (%ebx) + movl %edx, (%ecx) /* Build IDT entry, upper 4 bytes */ movl %eax, %edx @@ -761,15 +756,16 @@ SYM_FUNC_START(startup32_set_idt_entry) orl $0x00008e00, %edx # Present, Type 32-bit Interrupt Gate /* Store upper 4 bytes to IDT */ - movl %edx, 4(%ebx) + movl %edx, 4(%ecx) - pop %ebx RET SYM_FUNC_END(startup32_set_idt_entry) #endif SYM_FUNC_START(startup32_load_idt) #ifdef CONFIG_AMD_MEM_ENCRYPT + leal rva(boot32_idt)(%ebp), %ecx + /* #VC handler */ leal rva(startup32_vc_handler)(%ebp), %eax movl $X86_TRAP_VC, %edx From patchwork Tue Nov 22 16:10:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302257wrr; Tue, 22 Nov 2022 08:14:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf6rMPM+pLL0q3M9ZYDlQ/EqLjd3CGevo/d1S7HhR4Etu3ORpqd65Gg8aDZ5jqqb4uDWJrM0 X-Received: by 2002:a17:902:e8c3:b0:186:5de2:e17e with SMTP id v3-20020a170902e8c300b001865de2e17emr6964822plg.35.1669133675612; Tue, 22 Nov 2022 08:14:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133675; cv=none; d=google.com; s=arc-20160816; b=t4YUvJUZxviehky5+RbDPn3KOIRkpDAxVgL7ZxH/Fwfl5/tWRPlQTQkVOl+uw75e7Q wtFiX+6IPIh7jcR8VMqrQYXprl04TehesLgnGznkxVVR9N7EFYuOn3bXMwErqNBTx334 blXUk8vi+YTjoCw6sgVAobvnaI4JnNq94Znb7hvgsgUkLJ1o5EBam1T5yR0OUSJ97U9p hvdHSoAn93gPe5kIH93dcbNM7D3TiNy93ZhJLIffaH78UVvGc0a/sfR4taEqrcUiZvVW 8/LtrMNtSS/jgxAwZS/wjtfzl/TYWqcmcGs9iv1KhlTZNIY6clMMGwo7kvA2BLZrAkHN BkqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Sfpg+O7Yoq8uVnV5niK+ayvQVIvQ58sz5sqZTPyw6/0=; b=Of9RY6K0E4gqwgNMswWWTxThZibGCu+vEQv1BzgxOMukv2KQkbuRuYHhqQ2H3y+UgY xOSMRLNwRGQ3Cg5TiUvdxAKkO//9vYlPcLk1IzOfMzq5+xG8FPnyfDSwn9nWZ3nLFUV2 /PDs+N9FqunoU1tPHFRlbbzWJ426ynEFNI5B8rQQ1iHFCtaXPOVigRxgMI1jLH6zrCsQ VHCkWVqHzkVHzzDgkizHrM46hUGTVV/KFBps1AwMhBccyHP034y8dMfKq0cTsbMKfgkZ OL67SG+YhVvr5Xs+oirxgVE5Vt+vtPtkKJwqHLwA1814hNg7gQlTwekkiw6xa2TzMBuM sWLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N9Ejx0kb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i129-20020a625487000000b005731d316830si11625465pfb.23.2022.11.22.08.14.21; Tue, 22 Nov 2022 08:14:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N9Ejx0kb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234307AbiKVQLr (ORCPT + 99 others); Tue, 22 Nov 2022 11:11:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234213AbiKVQLK (ORCPT ); Tue, 22 Nov 2022 11:11:10 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04194748FB; Tue, 22 Nov 2022 08:11:00 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 85C39B81C13; Tue, 22 Nov 2022 16:10:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E52EC433C1; Tue, 22 Nov 2022 16:10:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133457; bh=SrH5jbYTxjPDhorKLJI/pQ/HZBcFhclTx5SIgKR45/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N9Ejx0kbSXA96CEjy61IkPDqpmm1iw1V1KwL0o2BrG4acpyUjnYU9usTt6Ls8cLzD kMlFz8uxuQ6dZg87fNyuT0XWjepFVa2cyw6oM1OfAVOqlZ805x2tFTuC3g5ZkZ5iPy YBNDpze0/sxPDOrc4iRNXj87GS46gTDMSKudG7AxDcJX3Ndofcmsk2ve1HVVNDiMBE 1iH8VIlxbPJqRATMm90hIlBRSKyQrTE+XiMnNwPSAVPSlfEDS20au70UuKKV9bKyuY gKYePZbTQ+MwyLH12YPPBIVy40anPo86w4EKJhWO9f2kzjFsgHQxaZmPBjhAXjhf8f xaOwx+Iv2igHw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 11/17] x86/compressed: move startup32_load_idt() into .text section Date: Tue, 22 Nov 2022 17:10:11 +0100 Message-Id: <20221122161017.2426828-12-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2553; i=ardb@kernel.org; h=from:subject; bh=SrH5jbYTxjPDhorKLJI/pQ/HZBcFhclTx5SIgKR45/I=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRegW+LXkyS9XpbbTToVmr/bYaRmK4xRgfZVjFu VylwNGuJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0XgAKCRDDTyI5ktmPJPAbDA C1qWwSmTQMOLDl4vc3rYbsHc2TXkRVTM6lA1KrxI5apzzolEqlcBxQp7wlhWptFkcUfEl0u+eeFjK6 vqr+IMvzXMi3jC7BUkDw/FtaqOUhnJk4bFhgxcE36OqHyPrPDNh9iDUHjvGYpLZcQhyn128xnRxv18 Al1yWVFu3MisoXr4ZqRo3rkOvjrsNYLfVsTn6y3+kjr5msePHR5qxALRb9z/NClK/JYafkS8sFvRrN A3Nv9GhYBoR92f2W2hCM8zYUtdCXM2MsVwW3VBKcyBgHQROshPacOUXj3CYLhHcwJ7CMMpgBAQwMQG lVXjXzBtq16sj8KLefvjpeD256WhOa9kTr3m5RRhaI9P70TzkQcF0EHsd7MjPnvOI8Jkc1T/qkYRbA CYxgX+Nlq8EyMOD1Lfz5niaZG3m3sIPPh8vsnTDpju0EjAmvYDJNJYRb+h3pwazRvVUBU27kS+Kv2g Mz2MqRTCxZNCOgDxgYi4ANIbp3NLlBxa8IFHWUIcU2cmk= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213513432236951?= X-GMAIL-MSGID: =?utf-8?q?1750213513432236951?= Convert startup32_load_idt() into an ordinary function and move it into the .text section. This involves turning the rva() immediates into ones derived from a local label, and preserving/restoring the %ebp and %ebx as per the calling convention. Also move the #ifdef to the only existing call site. This makes it clear that the function call does nothing if support for memory encryption is not compiled in. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 31 +++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 82d7fab99422129f..2d42852d5b828209 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -126,7 +126,9 @@ SYM_FUNC_START(startup_32) 1: /* Setup Exception handling for SEV-ES */ +#ifdef CONFIG_AMD_MEM_ENCRYPT call startup32_load_idt +#endif /* Make sure cpu supports long mode. */ call verify_cpu @@ -724,10 +726,8 @@ SYM_DATA_START(boot32_idt) .quad 0 .endr SYM_DATA_END_LABEL(boot32_idt, SYM_L_GLOBAL, boot32_idt_end) -#endif -#ifdef CONFIG_AMD_MEM_ENCRYPT - __HEAD + .text .code32 /* * Write an IDT entry into boot32_idt @@ -760,24 +760,32 @@ SYM_FUNC_START_LOCAL(startup32_set_idt_entry) RET SYM_FUNC_END(startup32_set_idt_entry) -#endif SYM_FUNC_START(startup32_load_idt) -#ifdef CONFIG_AMD_MEM_ENCRYPT - leal rva(boot32_idt)(%ebp), %ecx + push %ebp + push %ebx + + call 1f +1: pop %ebp + + leal (boot32_idt - 1b)(%ebp), %ebx /* #VC handler */ - leal rva(startup32_vc_handler)(%ebp), %eax + leal (startup32_vc_handler - 1b)(%ebp), %eax movl $X86_TRAP_VC, %edx + movl %ebx, %ecx call startup32_set_idt_entry /* Load IDT */ - leal rva(boot32_idt)(%ebp), %eax - movl %eax, rva(boot32_idt_desc+2)(%ebp) - lidt rva(boot32_idt_desc)(%ebp) -#endif + leal (boot32_idt_desc - 1b)(%ebp), %ecx + movl %ebx, 2(%ecx) + lidt (%ecx) + + pop %ebx + pop %ebp RET SYM_FUNC_END(startup32_load_idt) +#endif /* * Check for the correct C-bit position when the startup_32 boot-path is used. @@ -796,6 +804,7 @@ SYM_FUNC_END(startup32_load_idt) * succeed. An incorrect C-bit position will map all memory unencrypted, so that * the compare will use the encrypted random data and fail. */ + __HEAD SYM_FUNC_START(startup32_check_sev_cbit) #ifdef CONFIG_AMD_MEM_ENCRYPT pushl %eax From patchwork Tue Nov 22 16:10:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24463 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302926wrr; Tue, 22 Nov 2022 08:15:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf4yTEHiadLuxu/feesDL9/vtJdp/S7v/zedrl9V0gavGBJPJXVfmyJfg6kKJ84TL2Z5+FlO X-Received: by 2002:a17:902:b682:b0:188:f8bd:9589 with SMTP id c2-20020a170902b68200b00188f8bd9589mr8117583pls.91.1669133744601; Tue, 22 Nov 2022 08:15:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133744; cv=none; d=google.com; s=arc-20160816; b=Pm3L7V4gQTzeNGaL/qOtuUN3yz55dOMGrfzn3jG13ld+cZu65zkyZIeuBKXGNZvBZa lmkC8DCukDM0nru9CX092/tUMeWyOccXSMR2VfBmBugwqLkgCHFd4bBa2N4U4qmeHvkw nioo5gqicV9tEKwM91uI8+RnKfgZx3DjNYK7IOXD7mwdiQDdeEY5ZPj1VWwQFO2oPrkf wagw1CptIiuqoAKMo9rnZq46/edQ7gwUB23GWTrL9dfpbzamT0P6sfzKb2M2v45VxCT/ cPQsYoIGaCvrqKI0Ps1FSch57MoxoB0i4AAlDqt50bKIiysCuvKWPxwmIldhsx84PnIA LYqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=X9OYwjsYNYZd52ICZMe1O+IWrVbrkjdSSqB3aoeg6sc=; b=UATlOjs68hMjT/3APZK/B/wcYOgxT4DdvUDph7TimS0jkNQMQ6mir/WMvLYOHfEPOI 6G0qxLlLa+ZqVGICDZ/dsy+OLV407nMqCzxBtBOhTSYV+gRVEuYQ05ldqZl1xf0i/Ytf YgX9659w6W4Yw0zs9oLSkGICA+71dxPTyK0m9IzQYzFKDSJGgp6DbsW39Eq6wFTg5ZsR zLzEIO8x/6EmcsI2F6uE6XlyF5dGD7gU4SP9ipEyOMgdLYt6uusPDHf0uR26nh+rgm1G VxJH8murQwulTajl6GZSI3ZCi8MEf3atJsSsS/t23c71Zo7dGJDmjeurAYmfmtmUw/i8 3ReA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hVxTisLD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 129-20020a630187000000b00476c6e96225si13865277pgb.539.2022.11.22.08.15.28; Tue, 22 Nov 2022 08:15:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hVxTisLD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234278AbiKVQLy (ORCPT + 99 others); Tue, 22 Nov 2022 11:11:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232132AbiKVQLT (ORCPT ); Tue, 22 Nov 2022 11:11:19 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15F2973421; Tue, 22 Nov 2022 08:11:02 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C70C0B81C10; Tue, 22 Nov 2022 16:11:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4559C433D7; Tue, 22 Nov 2022 16:10:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133459; bh=ReDXv/q3k9hMwnrrtZAWhC5ghMLwcJr6hIjqxuAEllw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hVxTisLDPi7J+oQOfFOl1fJpuNdgrmJW8coJidIe/CYMFZZcTQbWQ/wT4GY+a+eLo yOdMlFjLDpziqPyztfgWOqy7U4CSTZBgvD6w6TIRvDaZAePZLyDW5MKIUNVnfiJ9kG x9YZnLWgL+4E6ILgsoeHep4Sdi5kbdOzwq83D36GVm7pwpLvOtFNnECFu7ryXv2Qq6 Lg8myt7Mx0yFuqy09b6a/n1Xi6OdYfaAgIu3fp5/nkyMwIQpMr4m69Tj/PiB3+Is3q P2PtJ/gsrd8Y+3F1hX9PzhHOzv16koy/uF4QbImqVhtlZa9unIqTs0cRTDqWoaBHjk JzwblZLWQWkuw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 12/17] x86/compressed: move startup32_load_idt() out of head_64.S Date: Tue, 22 Nov 2022 17:10:12 +0100 Message-Id: <20221122161017.2426828-13-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4967; i=ardb@kernel.org; h=from:subject; bh=ReDXv/q3k9hMwnrrtZAWhC5ghMLwcJr6hIjqxuAEllw=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRgzwGVx/T1BBAR2+PJz9BwCwj6JuS5em6yTyOg pxvocYGJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0YAAKCRDDTyI5ktmPJNw4C/ 9lFituVzfi6BkQa27qIpp8Newy0/YneL6tT8/bLqyrVdIM3vdLP5KcIJ7ctN0zS6DXQyf0JVCj2zKm pVSnVCjviTU7PouBCLtGlRRSFPoftPlFpiSVGFTmm6H/H0u8sCNSIO38hUSJCr5X7JUSJSMpwaif5K c0xrpoQk9oX8PaHxpqOZt57lAtt178he8jE3U9iDwA7tWtbZ85Wtr4EFGwykVEqB6ZxJOsZNTsScos +M3yU97f1ph+lm32dHQSw2IDaNQ44R8EiV2Dc+WX70Y5h/eXYNu4M4xG4yYASV0eM8MGRRWC1b4pAs zPOsEhylMW8ZJO3lkCVHg7Sos8Zvw3BHIe2gx2Y7KwozUzhTBF5iqq/WGtvSG/8uCJDm7ecGyvuzuD AIdaDaM5FsVLqvxtD4fEANHtp1YcC+34uW54Ohp3eywjof2GRB9q9BOizvHfwiR/amqiaA1Z122k8m fbQgDOfU4WIG2ee9D0FRNf6qq1HQ0bMd5oNAPfQIVmKGQ= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213585355147208?= X-GMAIL-MSGID: =?utf-8?q?1750213585355147208?= Now that startup32_load_idt() has been refactored into an ordinary callable function, move it into mem-encrypt.S where it belongs. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 72 -------------------- arch/x86/boot/compressed/mem_encrypt.S | 72 +++++++++++++++++++- 2 files changed, 71 insertions(+), 73 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 2d42852d5b828209..97b2167f128cbefe 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -715,78 +715,6 @@ SYM_DATA_START(boot_idt) .endr SYM_DATA_END_LABEL(boot_idt, SYM_L_GLOBAL, boot_idt_end) -#ifdef CONFIG_AMD_MEM_ENCRYPT -SYM_DATA_START(boot32_idt_desc) - .word boot32_idt_end - boot32_idt - 1 - .long 0 -SYM_DATA_END(boot32_idt_desc) - .balign 8 -SYM_DATA_START(boot32_idt) - .rept 32 - .quad 0 - .endr -SYM_DATA_END_LABEL(boot32_idt, SYM_L_GLOBAL, boot32_idt_end) - - .text - .code32 -/* - * Write an IDT entry into boot32_idt - * - * Parameters: - * - * %eax: Handler address - * %edx: Vector number - * %ecx: IDT address - */ -SYM_FUNC_START_LOCAL(startup32_set_idt_entry) - /* IDT entry address to %ecx */ - leal (%ecx, %edx, 8), %ecx - - /* Build IDT entry, lower 4 bytes */ - movl %eax, %edx - andl $0x0000ffff, %edx # Target code segment offset [15:0] - orl $(__KERNEL32_CS << 16), %edx # Target code segment selector - - /* Store lower 4 bytes to IDT */ - movl %edx, (%ecx) - - /* Build IDT entry, upper 4 bytes */ - movl %eax, %edx - andl $0xffff0000, %edx # Target code segment offset [31:16] - orl $0x00008e00, %edx # Present, Type 32-bit Interrupt Gate - - /* Store upper 4 bytes to IDT */ - movl %edx, 4(%ecx) - - RET -SYM_FUNC_END(startup32_set_idt_entry) - -SYM_FUNC_START(startup32_load_idt) - push %ebp - push %ebx - - call 1f -1: pop %ebp - - leal (boot32_idt - 1b)(%ebp), %ebx - - /* #VC handler */ - leal (startup32_vc_handler - 1b)(%ebp), %eax - movl $X86_TRAP_VC, %edx - movl %ebx, %ecx - call startup32_set_idt_entry - - /* Load IDT */ - leal (boot32_idt_desc - 1b)(%ebp), %ecx - movl %ebx, 2(%ecx) - lidt (%ecx) - - pop %ebx - pop %ebp - RET -SYM_FUNC_END(startup32_load_idt) -#endif - /* * Check for the correct C-bit position when the startup_32 boot-path is used. * diff --git a/arch/x86/boot/compressed/mem_encrypt.S b/arch/x86/boot/compressed/mem_encrypt.S index a73e4d783cae20b6..6747e5e4c696637c 100644 --- a/arch/x86/boot/compressed/mem_encrypt.S +++ b/arch/x86/boot/compressed/mem_encrypt.S @@ -12,6 +12,8 @@ #include #include #include +#include +#include .text .code32 @@ -98,7 +100,7 @@ SYM_CODE_START_LOCAL(sev_es_req_cpuid) jmp 1b SYM_CODE_END(sev_es_req_cpuid) -SYM_CODE_START(startup32_vc_handler) +SYM_CODE_START_LOCAL(startup32_vc_handler) pushl %eax pushl %ebx pushl %ecx @@ -184,6 +186,63 @@ SYM_CODE_START(startup32_vc_handler) jmp .Lfail SYM_CODE_END(startup32_vc_handler) +/* + * Write an IDT entry into boot32_idt + * + * Parameters: + * + * %eax: Handler address + * %edx: Vector number + * %ecx: IDT address + */ +SYM_FUNC_START_LOCAL(startup32_set_idt_entry) + /* IDT entry address to %ecx */ + leal (%ecx, %edx, 8), %ecx + + /* Build IDT entry, lower 4 bytes */ + movl %eax, %edx + andl $0x0000ffff, %edx # Target code segment offset [15:0] + orl $(__KERNEL32_CS << 16), %edx # Target code segment selector + + /* Store lower 4 bytes to IDT */ + movl %edx, (%ecx) + + /* Build IDT entry, upper 4 bytes */ + movl %eax, %edx + andl $0xffff0000, %edx # Target code segment offset [31:16] + orl $0x00008e00, %edx # Present, Type 32-bit Interrupt Gate + + /* Store upper 4 bytes to IDT */ + movl %edx, 4(%ecx) + + RET +SYM_FUNC_END(startup32_set_idt_entry) + +SYM_FUNC_START(startup32_load_idt) + push %ebp + push %ebx + + call 1f +1: pop %ebp + + leal (boot32_idt - 1b)(%ebp), %ebx + + /* #VC handler */ + leal (startup32_vc_handler - 1b)(%ebp), %eax + movl $X86_TRAP_VC, %edx + movl %ebx, %ecx + call startup32_set_idt_entry + + /* Load IDT */ + leal (boot32_idt_desc - 1b)(%ebp), %ecx + movl %ebx, 2(%ecx) + lidt (%ecx) + + pop %ebx + pop %ebp + RET +SYM_FUNC_END(startup32_load_idt) + .code64 #include "../../kernel/sev_verify_cbit.S" @@ -195,4 +254,15 @@ SYM_CODE_END(startup32_vc_handler) SYM_DATA(sme_me_mask, .quad 0) SYM_DATA(sev_status, .quad 0) SYM_DATA(sev_check_data, .quad 0) + +SYM_DATA_START_LOCAL(boot32_idt) + .rept 32 + .quad 0 + .endr +SYM_DATA_END(boot32_idt) + +SYM_DATA_START_LOCAL(boot32_idt_desc) + .word . - boot32_idt - 1 + .long 0 +SYM_DATA_END(boot32_idt_desc) #endif From patchwork Tue Nov 22 16:10:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24458 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302605wrr; Tue, 22 Nov 2022 08:15:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf47IkUJedvIVtrv96mL8cAy6e2bUtq0uJ8apTTU95nh+A/DPELHiblG156khF//IEidVrhY X-Received: by 2002:a65:60c9:0:b0:470:48c1:aae9 with SMTP id r9-20020a6560c9000000b0047048c1aae9mr4717660pgv.4.1669133715094; Tue, 22 Nov 2022 08:15:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133715; cv=none; d=google.com; s=arc-20160816; b=YirVDHYcBURK1sff1WwjBIFPUpbyYMVSqyoaWycbqBHjTkwy4iH+wSsVd48nvR+j9c bN7HoRgfLaxuQuSTR33PhexyVuij9U3ontND4WZHTemX7LTT0qC9lEBmIIqOwNUI1mgm +BCAoHFoqsJ+t01SnKIxueNer4ZheMmL1is2zQhe7pc48fZJyoktSEyVyRcbaIfrqyof 2FSNtyHLt8Rt8Orgs3o/t2zt8C3ei+XheRYj+cBknedoQo4OOrhFEzC/vTTjPsdbQtnO Ag7ClZYBuZu/8Jp+fCJ0qNrfSeVsyN1p4QkzKHLPFRRhvXlcyk9kt9JhpBGLF2xDp4yL UPXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zVXOY6Q8p0Y2tOhTV68By6nPW/IV5OmgfxHEH9FdIgc=; b=XVGV2OWGvJTTjrSdGOUZjVxAMAcxkeK0aS/nIAYiipJ++TZccmYRM+++QzQAloJv17 9fdr6UEUbymixR7S0iq2VwnePu3KICESf/V/HI0rcYatP2WIU9M4hcQOOuSiPu3Q8UTV CP8RR1g22CY6Ms+jVCPa60hA5YO4s/Z4QNGBtA1wwyYbSmEmIO9G20ksFFzBHwpJfzUW 9JHBmfWWx9l16VoPJalG58UjBbyYObTisGmskVCjWSVXcRo+k6eBW3LOvSxnmBUUuTC6 BAas1bbh2Dd8VsW8JM6ZJm0FhmzzKDywO5GCYBnx1qrFQYnhShgZrVPCv/nONrymLTNm drvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="I//ZrAZm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s21-20020a056a00195500b00573f637f57asi2102797pfk.238.2022.11.22.08.15.01; Tue, 22 Nov 2022 08:15:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="I//ZrAZm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233254AbiKVQMS (ORCPT + 99 others); Tue, 22 Nov 2022 11:12:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234221AbiKVQLU (ORCPT ); Tue, 22 Nov 2022 11:11:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5926B73B99; Tue, 22 Nov 2022 08:11:04 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 050F8B81BEE; Tue, 22 Nov 2022 16:11:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB187C433D6; Tue, 22 Nov 2022 16:10:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133461; bh=85eC+ySfoxQeQEcBlvmMcXBwdjRppgUeZ0M247EDQDM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I//ZrAZmTJ1txf5Y/1fGo5drBOkN5LfXiNxXkPgDHW9xs+Mwma6Paqk0dRAlCMezo pJRkZ21Q0uONcvkn6d/29R83VdXOJIZ5IDyBdiZ+bFi9zH+o0hQOIovG2qBMlFt8Ow /Ybg6mBDfBFhdxrr2hm8LB4/ZRjA7D2KohdILSamCXkVDX+0FbUVHBlSk52Hq3fd1H /kbo3bKmZb2Zot5CW7V1+PAV3P2CwfQgFP2Rzfz2rGCp4NWp2xfWu3a4aivzBaxjdh aajqA1Ie9SDomu5DJtlX7uqv2WIR82cU9x6zW+oPYz8v8rwaNFyiedmUdylQTRmELR WJRv2ROATtP/Q== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 13/17] x86/compressed: move startup32_check_sev_cbit() into .text Date: Tue, 22 Nov 2022 17:10:13 +0100 Message-Id: <20221122161017.2426828-14-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3035; i=ardb@kernel.org; h=from:subject; bh=85eC+ySfoxQeQEcBlvmMcXBwdjRppgUeZ0M247EDQDM=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRhxAUgWKtkqItF3n9UJ4nYtoljvO9zCeQ4S9+k up0wnf+JAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0YQAKCRDDTyI5ktmPJJBSC/ 9q9Wltr368Rkd3nUNyrxiuLzJKyXgPONP0594v0bUzNK/F5fmL8ncG+SKYY1AkUj8IKUYm+4KGeSb5 jArtd/pqC03Go1JdiIkirTqiT1V+bD/2o1qsBxxe/D+ofktJAzDJ/0Gp2gf9dL/vRiIy4LTubQJoZY Fto2/7imcoAgpHwwoZ8j454Ryp3l3gwT+o+FVTSS2IHGtaW6USmH1VU1cfx21tOmDNbwD7GTNETBls UIW15ILLM/l1vdJBSrQC7Q8mbxv/Lg7ZAubZ4WWj0spI4b8dd5rVu3dOJOk1qdO9O9jsyPJXqVohxW ZXo3TQutG1SGLlQmwOPmklOdmoS0/Z5Kn56dG+S1oOvLaBImwSsETj1Pjsyvmel1nYtC1i4wSTZwe3 MEgLCDcDVeLUjNkvt7Kvb3ddq3Qug+6uD7frW6IEh37/ceW7+sDEG/RmFnGlKHQeEKiU0St7BldID8 a5TfvP5ufkzrtn+N6u7lu3RWn3JcmgwhLEKXvmVc3IQvw= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213554296480845?= X-GMAIL-MSGID: =?utf-8?q?1750213554296480845?= Move startup32_check_sev_cbit() into the .text section and turn it into an ordinary function using the ordinary 32-bit calling convention, instead of saving/restoring the registers that are known to be live at the only call site. This improves maintainability, and makes it possible to move this function out of head_64.S and into a separate compilation unit that is specific to memory encryption. Note that this requires the call site to be moved before the mixed mode check, as %eax will be live otherwise. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 35 +++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 97b2167f128cbefe..272b2e97456f0dcf 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -259,6 +259,11 @@ SYM_FUNC_START(startup_32) movl $__BOOT_TSS, %eax ltr %ax +#ifdef CONFIG_AMD_MEM_ENCRYPT + /* Check if the C-bit position is correct when SEV is active */ + call startup32_check_sev_cbit +#endif + /* * Setup for the jump to 64bit mode * @@ -276,8 +281,6 @@ SYM_FUNC_START(startup_32) leal rva(startup_64_mixed_mode)(%ebp), %eax 1: #endif - /* Check if the C-bit position is correct when SEV is active */ - call startup32_check_sev_cbit pushl $__KERNEL_CS pushl %eax @@ -732,16 +735,17 @@ SYM_DATA_END_LABEL(boot_idt, SYM_L_GLOBAL, boot_idt_end) * succeed. An incorrect C-bit position will map all memory unencrypted, so that * the compare will use the encrypted random data and fail. */ - __HEAD -SYM_FUNC_START(startup32_check_sev_cbit) #ifdef CONFIG_AMD_MEM_ENCRYPT - pushl %eax + .text +SYM_FUNC_START(startup32_check_sev_cbit) pushl %ebx - pushl %ecx - pushl %edx + pushl %ebp + + call 0f +0: popl %ebp /* Check for non-zero sev_status */ - movl rva(sev_status)(%ebp), %eax + movl (sev_status - 0b)(%ebp), %eax testl %eax, %eax jz 4f @@ -756,17 +760,18 @@ SYM_FUNC_START(startup32_check_sev_cbit) jnc 2b /* Store to memory and keep it in the registers */ - movl %eax, rva(sev_check_data)(%ebp) - movl %ebx, rva(sev_check_data+4)(%ebp) + leal (sev_check_data - 0b)(%ebp), %ebp + movl %eax, 0(%ebp) + movl %ebx, 4(%ebp) /* Enable paging to see if encryption is active */ movl %cr0, %edx /* Backup %cr0 in %edx */ movl $(X86_CR0_PG | X86_CR0_PE), %ecx /* Enable Paging and Protected mode */ movl %ecx, %cr0 - cmpl %eax, rva(sev_check_data)(%ebp) + cmpl %eax, 0(%ebp) jne 3f - cmpl %ebx, rva(sev_check_data+4)(%ebp) + cmpl %ebx, 4(%ebp) jne 3f movl %edx, %cr0 /* Restore previous %cr0 */ @@ -778,13 +783,11 @@ SYM_FUNC_START(startup32_check_sev_cbit) jmp 3b 4: - popl %edx - popl %ecx + popl %ebp popl %ebx - popl %eax -#endif RET SYM_FUNC_END(startup32_check_sev_cbit) +#endif /* * Stack and heap for uncompression From patchwork Tue Nov 22 16:10:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24459 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302639wrr; Tue, 22 Nov 2022 08:15:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf6NrNhQ+MtkY6/F6lyZtb3yb0wCOBkfbNXxfBOs9CPJvTiUr9UcZUWIfE5W2V0eEYUpAktZ X-Received: by 2002:a17:90a:2b8c:b0:212:f4f1:96ee with SMTP id u12-20020a17090a2b8c00b00212f4f196eemr33356377pjd.72.1669133717503; Tue, 22 Nov 2022 08:15:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133717; cv=none; d=google.com; s=arc-20160816; b=nhJuLF/k0CiMIo0zeSf6gLl1WNOCk0NIvnn1SfnI/cpJyXgsbjqdB9EUfxjK1+5fi/ /hJxQ05yQzQHw53VstZKdAEa9ZJnTjLMFv3mpc9fccdRLs6X7jUJyUdfz4E5u7TiiR5n X8+pEDVH1ZR2ze3ZTyK8ED+xnoQ37Y/yFPAJJkIP9I4CumO5yh7W8P3oCjah3aAluJ96 D6tRru9dtL4Xfgq47p5YOzp/WYjxD4DabpPBsN1hVpQzHIjBJapKzGkM/go/6mctP8DE O4WxJJNaEgjQZwA385pyomJAtKWBjHfc7Bi9nYxjDXEwV9GpZp0nSbvBt9b1y5r9LPae 4XXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wF3o4Tmx3dYOSzFmMS4tOv/Jx6OXrOHjB+rtDBf1uBU=; b=yksidDKHln9tzNPSTqS3hettD7+kMpgyqFYmylY/2YnJ2JFjvwA7uxjU5CMVoesOLD sEAOftum7JrJbnbEyFQWIxP3Iw40EEUxG1SRby1KYSZX/3SiaMFlj+Aiz0IGWjdcNrVK 4a7fNZPUfRHIB2hGAprPAGLoLlliHyt69BeTBMnvcKfafqUhGJVkGrB3DICyq33xyDFf +AVypyvzgAJ94mWWjzB8v7GsTDakbJvx4h9zeenUHJELZR4UgUBl96FhKrz7LUITZSuC kQdfDOqT3/1wRyTpLfxWl0sZVmpiG7D6OLuD4+VzamI6e3L8VqdQQOfsU/mNA8JbkRBu LnLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=InX5b41L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lb8-20020a17090b4a4800b0020d2d8c9a84si15030895pjb.137.2022.11.22.08.15.03; Tue, 22 Nov 2022 08:15:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=InX5b41L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232879AbiKVQMX (ORCPT + 99 others); Tue, 22 Nov 2022 11:12:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234232AbiKVQLU (ORCPT ); Tue, 22 Nov 2022 11:11:20 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E6FB74A89; Tue, 22 Nov 2022 08:11:05 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8948461767; Tue, 22 Nov 2022 16:11:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C2F6C433C1; Tue, 22 Nov 2022 16:11:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133463; bh=iYbIjrknrGRSBysYjlJW1iQdlzPwOmOOE6edC0L0zHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=InX5b41Lk7aO+j7mr91zm2S094vIgHGRu96RW42bGv7bTu209E7UZ/BemYc3mANJr JmVMGJLFjRElkY3sL+cAaHNXRv1ZXmkIiVs8XQzLiLkUiTe8YlV4Vykdomvd0QdcMj r5bUYIFsLOCv0dxQo4GetJL75n9C59S+zN/muNWveo9WerIqqca9MSfaJ8t1GUhgoT 0aYLeI/E9zItK+NIsdTC8YkMdtmPtshl+TQIZQOwNgyeE3CENgcVU0/Jf1k3/aJpja OAKGjIjAbBzCR+YERcFP85AxH6IezpgbufDzYWEyFxDtcgZKJoGhCElZCqaaWUlIEA 3WZfxWT8tVcfA== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 14/17] x86/compressed: move startup32_check_sev_cbit() out of head_64.S Date: Tue, 22 Nov 2022 17:10:14 +0100 Message-Id: <20221122161017.2426828-15-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5291; i=ardb@kernel.org; h=from:subject; bh=iYbIjrknrGRSBysYjlJW1iQdlzPwOmOOE6edC0L0zHc=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRjYXZDaUISly8JZvkN6lWigmkVa29XxkMwdVUp 3JxEe9mJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0YwAKCRDDTyI5ktmPJOWuDA CyuwiYOaZkQCmzL2X7SSqPNjEpNsTbNtIsntl6ESJ6uEYBcUbZEMVksW98EGtXOlE1vRyxi2NgJwML D7Qdtl8+mVR8lXEv12WOXVyz9A38ycBSAt+TLdNlG0mwVyROKiMZflyfNPKGGlwtaaJ2Nryg2ugyKP uTcoBYaLegt4jDGDHWZN66opymyizekQf1qaO9bEiMlfdmbzCAGS/ieTGfLURHwBGDJkuHv27WHWeb gpYgSp39fD1cvY4xckmBwTg5aC+D/QiUQ1xv31X7WBoX5/eFRj7wGdIkwg+5lC1yPDdJyb9DmuVlo9 WRkBAazwQNWbBOhB3aU/aQ6OaAzmCSl9yqECBEAM8PNMX/Ftn/k67FAfLIOCyqlTA0W050mdry+Svn 4q8svDEvfyYTkbOxtGz/b4zQ/3RsoD3BywJdz/tELS3GRYsyjBdOgxr6IMGOqUYmuLOz9WrKIV92GR pfykD6yymOP+I4htLWJP3EKGf/QqtA7ilmrDc05ukFXBs= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213556806174987?= X-GMAIL-MSGID: =?utf-8?q?1750213556806174987?= Now that the startup32_check_sev_cbit() routine can execute from anywhere and behaves like an ordinary function, we no longer need to keep it in head_64.S. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 71 -------------------- arch/x86/boot/compressed/mem_encrypt.S | 68 +++++++++++++++++++ 2 files changed, 68 insertions(+), 71 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 272b2e97456f0dcf..0cfc8ce273a2731c 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -718,77 +718,6 @@ SYM_DATA_START(boot_idt) .endr SYM_DATA_END_LABEL(boot_idt, SYM_L_GLOBAL, boot_idt_end) -/* - * Check for the correct C-bit position when the startup_32 boot-path is used. - * - * The check makes use of the fact that all memory is encrypted when paging is - * disabled. The function creates 64 bits of random data using the RDRAND - * instruction. RDRAND is mandatory for SEV guests, so always available. If the - * hypervisor violates that the kernel will crash right here. - * - * The 64 bits of random data are stored to a memory location and at the same - * time kept in the %eax and %ebx registers. Since encryption is always active - * when paging is off the random data will be stored encrypted in main memory. - * - * Then paging is enabled. When the C-bit position is correct all memory is - * still mapped encrypted and comparing the register values with memory will - * succeed. An incorrect C-bit position will map all memory unencrypted, so that - * the compare will use the encrypted random data and fail. - */ -#ifdef CONFIG_AMD_MEM_ENCRYPT - .text -SYM_FUNC_START(startup32_check_sev_cbit) - pushl %ebx - pushl %ebp - - call 0f -0: popl %ebp - - /* Check for non-zero sev_status */ - movl (sev_status - 0b)(%ebp), %eax - testl %eax, %eax - jz 4f - - /* - * Get two 32-bit random values - Don't bail out if RDRAND fails - * because it is better to prevent forward progress if no random value - * can be gathered. - */ -1: rdrand %eax - jnc 1b -2: rdrand %ebx - jnc 2b - - /* Store to memory and keep it in the registers */ - leal (sev_check_data - 0b)(%ebp), %ebp - movl %eax, 0(%ebp) - movl %ebx, 4(%ebp) - - /* Enable paging to see if encryption is active */ - movl %cr0, %edx /* Backup %cr0 in %edx */ - movl $(X86_CR0_PG | X86_CR0_PE), %ecx /* Enable Paging and Protected mode */ - movl %ecx, %cr0 - - cmpl %eax, 0(%ebp) - jne 3f - cmpl %ebx, 4(%ebp) - jne 3f - - movl %edx, %cr0 /* Restore previous %cr0 */ - - jmp 4f - -3: /* Check failed - hlt the machine */ - hlt - jmp 3b - -4: - popl %ebp - popl %ebx - RET -SYM_FUNC_END(startup32_check_sev_cbit) -#endif - /* * Stack and heap for uncompression */ diff --git a/arch/x86/boot/compressed/mem_encrypt.S b/arch/x86/boot/compressed/mem_encrypt.S index 6747e5e4c696637c..14cf04a1ed091655 100644 --- a/arch/x86/boot/compressed/mem_encrypt.S +++ b/arch/x86/boot/compressed/mem_encrypt.S @@ -243,6 +243,74 @@ SYM_FUNC_START(startup32_load_idt) RET SYM_FUNC_END(startup32_load_idt) +/* + * Check for the correct C-bit position when the startup_32 boot-path is used. + * + * The check makes use of the fact that all memory is encrypted when paging is + * disabled. The function creates 64 bits of random data using the RDRAND + * instruction. RDRAND is mandatory for SEV guests, so always available. If the + * hypervisor violates that the kernel will crash right here. + * + * The 64 bits of random data are stored to a memory location and at the same + * time kept in the %eax and %ebx registers. Since encryption is always active + * when paging is off the random data will be stored encrypted in main memory. + * + * Then paging is enabled. When the C-bit position is correct all memory is + * still mapped encrypted and comparing the register values with memory will + * succeed. An incorrect C-bit position will map all memory unencrypted, so that + * the compare will use the encrypted random data and fail. + */ +SYM_FUNC_START(startup32_check_sev_cbit) + pushl %ebx + pushl %ebp + + call 0f +0: popl %ebp + + /* Check for non-zero sev_status */ + movl (sev_status - 0b)(%ebp), %eax + testl %eax, %eax + jz 4f + + /* + * Get two 32-bit random values - Don't bail out if RDRAND fails + * because it is better to prevent forward progress if no random value + * can be gathered. + */ +1: rdrand %eax + jnc 1b +2: rdrand %ebx + jnc 2b + + /* Store to memory and keep it in the registers */ + leal (sev_check_data - 0b)(%ebp), %ebp + movl %eax, 0(%ebp) + movl %ebx, 4(%ebp) + + /* Enable paging to see if encryption is active */ + movl %cr0, %edx /* Backup %cr0 in %edx */ + movl $(X86_CR0_PG | X86_CR0_PE), %ecx /* Enable Paging and Protected mode */ + movl %ecx, %cr0 + + cmpl %eax, 0(%ebp) + jne 3f + cmpl %ebx, 4(%ebp) + jne 3f + + movl %edx, %cr0 /* Restore previous %cr0 */ + + jmp 4f + +3: /* Check failed - hlt the machine */ + hlt + jmp 3b + +4: + popl %ebp + popl %ebx + RET +SYM_FUNC_END(startup32_check_sev_cbit) + .code64 #include "../../kernel/sev_verify_cbit.S" From patchwork Tue Nov 22 16:10:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24460 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302714wrr; Tue, 22 Nov 2022 08:15:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf61VtlGPapPSl5hpTSQPv+UnLsWFBPg2QbbEuCF8PFRMxUxfj1RlQkmSDmdM7qwrgx1y4df X-Received: by 2002:a63:6f4b:0:b0:470:5619:4d7d with SMTP id k72-20020a636f4b000000b0047056194d7dmr22564405pgc.301.1669133724137; Tue, 22 Nov 2022 08:15:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133724; cv=none; d=google.com; s=arc-20160816; b=GznCwyrfd5a3ciPssYdcEBn5FPfR+1jxk82/Suc08MtmzWhMhZW5FgjTz0c3ydaEBi SJIXBtYMlRA7iVNLfnh52Bby1D0DbRZGb5yApyw+i720ecnO46DFTYKqlKTKZ1BkMQog dbJcG+Z9OKFcSlp0IB0dtJY45CCjSkkf944SACyOTJ8sGpFPcEaEW0F12jGOXTlGzQ6H AXuMuzkqqzsx9LVwta5xXvIM56XZUlMCTRFsOVthLS4MxAUMOpWVkkg60+york0D0v4m OK7GgEvcqRFPXG4LWMLiYqRN3RiI4oWD6cOIg1IgRjX74vPe+SbEe7Nhi0JS/MQ3V1ZS zIMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Uur1aI143OsiWvJLgs7lKDLl573P209B1NQCkER1zmw=; b=gQNZ51S74zpeijYuy4jOtUR4K7SOVdGkT9h8/JpUmIUrry2jZz8Jg3VJg5Y+heL4tf yVjsZX2S1AxnR2odImS3S7x5H9F3u7Val2ybNxZ8n87tIa3BKF21oF+90lsgy9bXp8iK Wy6Xa92ZN5TgGvn9Pan5zKujK/i4KHNmBhp7yV0XUua3CDe7SrwT0vZfmnkDE4R81zga 4dnfA5XRoSQ1+fv5O4TUEyP9ZY384VTbBM9G8vkkdSXstIlN2DAUqt+h/Jf9mqIr8n4n 03Eu8VQ+bP4xwDGmFFx+vks8SyzPwwi1Sssm3FM0TYGps91ue2cRNUdi4dWeQYCQmTdL ljSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hl5LV4DC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e14-20020a6558ce000000b0046f5ffcfc1dsi15692883pgu.324.2022.11.22.08.15.09; Tue, 22 Nov 2022 08:15:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hl5LV4DC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233878AbiKVQM1 (ORCPT + 99 others); Tue, 22 Nov 2022 11:12:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232852AbiKVQLh (ORCPT ); Tue, 22 Nov 2022 11:11:37 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC30E74AA4; Tue, 22 Nov 2022 08:11:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 856FEB81C10; Tue, 22 Nov 2022 16:11:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62FFEC433D7; Tue, 22 Nov 2022 16:11:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133466; bh=WzgruzR/v1MEVPGvMfLbw7xCwZPOIioiFXKbArp2e20=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hl5LV4DCJoQbDIyuHOaHIoqt7NLovhtjIM9BVLXENuDhZK8U/Tdr8ErYt6C8UGPRl ekPienlBAffkk4JnJy+2qvhrYbP2gIw03vtJ/qWdIV2T/iw1UNhOZVRrQPaSe7wyec 4LIpSpGSaTFELxo/6SZIhqHYvmmy1KgODJ+rldbgCvUzYwbjduhynFHkGRS77txH8l wYS2NP3f0QlY9CY1O6eBScPmzdXJyQIAQiyiePRP3O1lAR57qEdGwM1aFF1ePpD/Tj TvCOZsATwQ9DIE8wMrDmAhJIbOh2MzvAq6axyZy9t39AP7DIpc1Q+bjzdXG3oGKbzE c3FXW9faPaYuw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 15/17] x86/compressed: adhere to calling convention in get_sev_encryption_bit() Date: Tue, 22 Nov 2022 17:10:15 +0100 Message-Id: <20221122161017.2426828-16-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1909; i=ardb@kernel.org; h=from:subject; bh=WzgruzR/v1MEVPGvMfLbw7xCwZPOIioiFXKbArp2e20=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRlRjCxfUGcb8bUP8866wWUGhLDdGiyfHOFhXH7 xfd5BRmJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0ZQAKCRDDTyI5ktmPJGPtC/ 91APxkHaUNp4yBkeDxwprSCH28epIzimrD0vGJf9LbPi5dn6uj76y3+T4vrgtHhAYZnNO/Nw4dwzzR 14AJNAGQmmU5stvmBSm9ioWr5fHNym/ks4TYcPtA2EGDDRERG4jMI//3JpMznmg+sAm6qmiG0x6/+R JRgAU2Bu1xVw8qvnfwz722rD9r9E1zo+StiSMIYFtmRwSeVHt0F1/StamR8Ct7NW79oWFfCpi3v8bj V/+VcvkxZDTDtUWsGMVdAjVQvwq/KJqcALXNynkjfkBZEkmdcvOCRYooQ/l8e6nW/3Ih6DAxGC3f7u J+5WZeZKMAUQWsXoLYEKLEIe2bXFRNuPrYIK45sn809agJgilov8zYP/zl70UYYgRHPBFXPBD+6BMB 9Dg9cXWdGNAkUyiqJAxtG4FBqShNzg96C3R1n91sJjUnFrZa6eQ8q5NGOXR21m33tF9+LJcFYqB9Rb +stxkVfyllEXg3zFeg2EuZ9D7WppYsUGfNVjuE6iMDmLY= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213563858603838?= X-GMAIL-MSGID: =?utf-8?q?1750213563858603838?= Make get_sev_encryption_bit() follow the ordinary i386 calling convention, and only call it if CONFIG_AMD_MEM_ENCRYPT is actually enabled. This clarifies the calling code, and makes it more maintainable. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 5 +++-- arch/x86/boot/compressed/mem_encrypt.S | 10 ---------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 0cfc8ce273a2731c..dd18216cff5c37e0 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -188,12 +188,13 @@ SYM_FUNC_START(startup_32) */ /* * If SEV is active then set the encryption mask in the page tables. - * This will insure that when the kernel is copied and decompressed + * This will ensure that when the kernel is copied and decompressed * it will be done so encrypted. */ - call get_sev_encryption_bit xorl %edx, %edx #ifdef CONFIG_AMD_MEM_ENCRYPT + call get_sev_encryption_bit + xorl %edx, %edx testl %eax, %eax jz 1f subl $32, %eax /* Encryption bit is always above bit 31 */ diff --git a/arch/x86/boot/compressed/mem_encrypt.S b/arch/x86/boot/compressed/mem_encrypt.S index 14cf04a1ed091655..e69674588a31c81f 100644 --- a/arch/x86/boot/compressed/mem_encrypt.S +++ b/arch/x86/boot/compressed/mem_encrypt.S @@ -18,12 +18,7 @@ .text .code32 SYM_FUNC_START(get_sev_encryption_bit) - xor %eax, %eax - -#ifdef CONFIG_AMD_MEM_ENCRYPT push %ebx - push %ecx - push %edx movl $0x80000000, %eax /* CPUID to check the highest leaf */ cpuid @@ -54,12 +49,7 @@ SYM_FUNC_START(get_sev_encryption_bit) xor %eax, %eax .Lsev_exit: - pop %edx - pop %ecx pop %ebx - -#endif /* CONFIG_AMD_MEM_ENCRYPT */ - RET SYM_FUNC_END(get_sev_encryption_bit) From patchwork Tue Nov 22 16:10:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302806wrr; Tue, 22 Nov 2022 08:15:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf4EqSmAVS/bk6ocgllojmaZrYWIFa5TcMx49qm1xjUqf0VdOtsgDO2dRDzY7e5BamVjq9vA X-Received: by 2002:a17:90b:793:b0:218:9c4f:e97 with SMTP id l19-20020a17090b079300b002189c4f0e97mr16101488pjz.2.1669133733195; Tue, 22 Nov 2022 08:15:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133733; cv=none; d=google.com; s=arc-20160816; b=ws2401IdgQhfm8a2apvvsalL1qGHQx73cf8QVm6uvB5KxOiOtjItQZPIBNR6whyF+2 5SxL1Jv8BESOL4AV9qMRy5+UAqjMa0WsjMJSloBJB2bEI+Kc+xmgtjt9HbAcbX7s/a0r UjNuXq2ViHL9JIteOthp2UMWt7kni82yLcM0d6vuEuxdip3Ao3romtOWMn72Cd5wEPVq +GzxwAigXKJH0n/S5n3azvufOC/uGTF1s3dDBPBzpW8uuAtWsTJQxz73LTO4YK1u34UO YrSzc6FjqJZ+dL5OIv8aGqbaVFUfaz8+XN8OjMWlZIEmwWGV3FErLAWAvwRk25DZEJNk Ml6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3UIu6RDudLqV86iRWrwHeaZ6M7OcmJL4rSolI0ao3m4=; b=LpQdFxKUMNKN33qSQ4YFkz7Cd+gfOuuO8AigOgHDfERsNTCrXwUo23k7vRlBcGknLm JmlxAEiNxk0RfD82LO6H7KGe6HkLJ7q+KB09RruXR/80A7eB092yEsl31vABHw1uycJt g5wReFK7KZjAgUqbgNFuSedelCEv5srYOfsoO75VnBh3be4ajo5Yp07zxhl5t4rSfs9v YfC27eZanFeIxFoR8XGxocuLgzkWcM6Cw6U/HeyMftWPQUN/n3XSwolnHg52Ky4avp5N 56jU0JFg4PPDZQb6ZDlYVSTCpMGFTgAWUxmFvpw8QhZY62BDT3ZkCP0M+hMEwzIP66iC F+8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XP2d5Vn5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s12-20020a056a00178c00b0052e4de9b806si14951703pfg.342.2022.11.22.08.15.15; Tue, 22 Nov 2022 08:15:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XP2d5Vn5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232869AbiKVQMa (ORCPT + 99 others); Tue, 22 Nov 2022 11:12:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234297AbiKVQLi (ORCPT ); Tue, 22 Nov 2022 11:11:38 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66EAB74AA5; Tue, 22 Nov 2022 08:11:09 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EB0526178F; Tue, 22 Nov 2022 16:11:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98F21C433B5; Tue, 22 Nov 2022 16:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133468; bh=WhXdkD4dUeFlbCa2uQ7/WXKYDJLeVqOD82K+vPxNRBU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XP2d5Vn5IhYOWUComKlIB6Z9cXXN/cA51C1aeGE9gGN8yeNbmQRq1ICdueb71n0lH obE7QRwE3PL44uUF9iCUvBppYz/p3rsCzWPsPAOnMa/cjNsCIlQwIsrJKVa7mptG6J 3K0iR9VKg97H5GHa10EkGRiPp4/jy9qoW+kyovoGqWrewCTfC+PVBlCtoVtrtnNKrF hP46x1yNmA4pxsd08Hlxx0jM1nJ+jpcVyJIImgIdBTbOwnDnBYMj+gMEVXZT646uQI vNWOzqoeSG2rOb2eLvu9krtCbJPnR8tf105bt+sEt9SiYVAD9DOlL3fOZnZ3JYa/ob 3Ha6DFMdavgKw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 16/17] x86/compressed: only build mem_encrypt.S if AMD_MEM_ENCRYPT=y Date: Tue, 22 Nov 2022 17:10:16 +0100 Message-Id: <20221122161017.2426828-17-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1513; i=ardb@kernel.org; h=from:subject; bh=WhXdkD4dUeFlbCa2uQ7/WXKYDJLeVqOD82K+vPxNRBU=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRmkT6ecGA/cAN7llRJkxgNCUnGuU4XlPtqQLSt MJfoSUKJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0ZgAKCRDDTyI5ktmPJIROC/ 47FixYSC5DsCya9EY2tPWjzFOO3btlyqulJ0T+UDx2P378vfkSo7epzYht6hTrbu0eyKl8sbBbOJod HOzI5it103YIBtch6jbzm+ecyPY/6Liuku1ipJgc7uCOmfoHVUWa4/2CUinI0+lPqV2ZQmOlPXw9eS VeowN57ItdpLsaYa4kph88PLKON7dl7eZlIAi/lATz1moiBiuiHHo+HUQBQw+V6NW0feamxq7zD+cS XLotitFVa3AccaAAzAI1Pw960takGXHX7h+fVe60wZVHwI9LedRUcESNqpnjZKqZpPkvdotIQsyHaW 78iubNh1PsE8xpHF1GlcaCqaMg1iXb652wywgjIySJg8lmIAo5dM8hUUPtTRUHb69VOQJnYDiv/O8Q 7WnF4vfyjCRDhMqSy+ofLnqY2SS+flxH/p/8TTX+afsj8e63dc/WmCfIjPqfU955GIg2Flj1oSPi1S DVK98PcqjDCeIfDfwDzWB3sEh/W64p5dt4vTlomv+Qc3Q= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213573209103047?= X-GMAIL-MSGID: =?utf-8?q?1750213573209103047?= Avoid building the mem_encrypt.o object if memory encryption support is not enabled to begin with. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/boot/compressed/mem_encrypt.S | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index cd1a6295b957ea1d..3dc5db651dd0a197 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -100,7 +100,7 @@ vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o ifdef CONFIG_X86_64 vmlinux-objs-y += $(obj)/ident_map_64.o vmlinux-objs-y += $(obj)/idt_64.o $(obj)/idt_handlers_64.o - vmlinux-objs-y += $(obj)/mem_encrypt.o + vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/mem_encrypt.o vmlinux-objs-y += $(obj)/pgtable_64.o vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev.o endif diff --git a/arch/x86/boot/compressed/mem_encrypt.S b/arch/x86/boot/compressed/mem_encrypt.S index e69674588a31c81f..32f7cc8a862547e4 100644 --- a/arch/x86/boot/compressed/mem_encrypt.S +++ b/arch/x86/boot/compressed/mem_encrypt.S @@ -307,7 +307,6 @@ SYM_FUNC_END(startup32_check_sev_cbit) .data -#ifdef CONFIG_AMD_MEM_ENCRYPT .balign 8 SYM_DATA(sme_me_mask, .quad 0) SYM_DATA(sev_status, .quad 0) @@ -323,4 +322,3 @@ SYM_DATA_START_LOCAL(boot32_idt_desc) .word . - boot32_idt - 1 .long 0 SYM_DATA_END(boot32_idt_desc) -#endif From patchwork Tue Nov 22 16:10:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 24462 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2302854wrr; Tue, 22 Nov 2022 08:15:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf4cPcpt6OUdfPMpbvgI0uPmfmlf8Kkaci5jhrunkuiiOIAJPOBj+RqOs11UK3bb7eCW4J2H X-Received: by 2002:a63:67c2:0:b0:46f:d2d4:bac4 with SMTP id b185-20020a6367c2000000b0046fd2d4bac4mr22375853pgc.178.1669133738597; Tue, 22 Nov 2022 08:15:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669133738; cv=none; d=google.com; s=arc-20160816; b=kZpm0YHcEE3lR8zQA+4bQZLj2ZfoYf+PtadiGsGhL03H8o2UQBI6uFQsnp6/i77Leh /bOObx7r8rca/+ZtWBpb7Bp1YuMWM4bHMCnYvFryOkUnzIMlJILwlEYkkzsFGIC1nIZu eYrB0sUmV6ik5OOSlVYbmDSWChbbgqVrTJHrtHz+VptVnDprkrW5HswaIbVjKXnxVXuV m64JVS6ICL5k4KHG8m+7vF1DWukPyEZ0xlEdCfZ+6z7mhUDOEXc3bjeTNUVYo4z8j4b6 OKlycr5gQFKg3wC8K6Kblgl8f+Wv7IGoBRR5uT+nRwmcJVnrNxWnz2cbI3LMaz0P8WhB 15YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Kpq9STCtNS5sGCCoafH61FuUuLVWDUIe6svQYKCx3Hg=; b=CCmBEhGTrdvdcgIGwkZmjpVwULu9koQRCe+ueOkYKcB6OdW+52KRooUkkeqv2bsNl3 Mk6FMVsvMyqtKClmPzJKlfUj07dKtrsOp+6iq6SGRTLgl3AfYpdZ6O/1my/HUUdD0ERG f1qrrL0AyZGBcMe3maFXBJicQZLOAj/moIScAjgL968cgsik5Ge2V97ebVm2lbs2aRUe IpITQn2flsQqBHJcJduOpc05otSgN/a+9O57qk+DZ9WlR1RmsmF5KE32Xb8yq8dL7fyo wFen0UCkG7ZyR77LD9SRLsMaaB8Zt0q0U90U/LXEW8lC9f8RQ5/osdVks6QnbdF6omzC xF1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ghf5qSEj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b17-20020a056a000a9100b005634d0b379dsi15236855pfl.115.2022.11.22.08.15.22; Tue, 22 Nov 2022 08:15:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ghf5qSEj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234164AbiKVQMc (ORCPT + 99 others); Tue, 22 Nov 2022 11:12:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233774AbiKVQLn (ORCPT ); Tue, 22 Nov 2022 11:11:43 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A07374ABB; Tue, 22 Nov 2022 08:11:11 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3379D61792; Tue, 22 Nov 2022 16:11:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF4A0C433D6; Tue, 22 Nov 2022 16:11:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669133470; bh=del+B43pK6TaccphvXJ28jvfSBKGUxy0I/ywjkZvIh4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ghf5qSEjhCwO8mImCexfclPr2cgk8g7ybZwCCDfsU2JnXT9uDwY22pj+sXZVrItjy gO3ZiYewO5cehMYcpk6b0fJKtmYzUEXYmxTYNvtceezVHPzFCTV3w7heQyfqAGs7RL aPPm5fYdZV4dKcAgWbWoqnukRCpcK0pgxjTk9GfbnCwmHD2O+yD1lx52n5Tl5F+lfb ox+ylrMMBqTPNwOMsjdjN3MgGT+7JLW7ncndCFDn2AZ0IOB34mZkIqd3ZlVqbIQcaw ag6ZvVY269JHRuHj7dhFSvA2XLV8BzG915R8giWuoegS/Qv1s5sCsKDvSxWMUvLv5v hzIpjPQTRIr/g== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v3 17/17] efi: x86: Make the deprecated EFI handover protocol optional Date: Tue, 22 Nov 2022 17:10:17 +0100 Message-Id: <20221122161017.2426828-18-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221122161017.2426828-1-ardb@kernel.org> References: <20221122161017.2426828-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5730; i=ardb@kernel.org; h=from:subject; bh=del+B43pK6TaccphvXJ28jvfSBKGUxy0I/ywjkZvIh4=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjfPRoPMfnVKZwz5TVDvfM40lKX97xivaJebCGV9yg 0jObB5uJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY3z0aAAKCRDDTyI5ktmPJAiEC/ 0WnKjV6l38MPlBU5LQOa2epZox5wXjIBSu8wF6UL6c4k/Zx24rnjzt3ZHyakoT5fqvVxFlRiSiLXSd oGqf7/kd+/rzlJTZkpFiXXU8Lvy0uFQNY+MDCWkEavdh9cr5KcR8+WMbYnlZVXE+LMBo77h5Wg8J5F /kwUsYxFROg31iCQ6bKEOFSS4qvH9uGApGyY9+Mzci45PfrmgN6N3JAffKBnePjQAE6inOvojvRdc8 uDzX7Qf0yofJuJXlxze2kNQC4JXQfbF45oz9N88sboM4xy1D/kpN1mHP0nWtbyaVBDUBtUmPItOU2G OR1Mu8QCYSM3EpharKpESrb9J/A2YDiV3S/MN+pfz8SoNEZbamfulQs8+ojdcIE+OA/uz5rnwy6+aU 6E693wigxKwYEsEPsPgxBtd6N1SlirYo0sLqrJzH3hHPK2vGx3dlJlqt2QGDj7ofJXRW+yN9gTMpzQ pV6cOaIHtCL/RGw310nCHzrSTUtyg42DV2CLmijs7xt9E= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750213579148219669?= X-GMAIL-MSGID: =?utf-8?q?1750213579148219669?= The EFI handover protocol permits a bootloader to invoke the kernel as a EFI PE/COFF application, while passing a bootparams struct as a third argument to the entrypoint function call. This has no basis in the UEFI specification, and there are better ways to pass additional data to a UEFI application (UEFI configuration tables, UEFI variables, UEFI protocols) than going around the StartImage() boot service and jumping to a fixed offset in the loaded image, just to call a different function that takes a third parameter. The reason for handling struct bootparams in the bootloader was that the EFI stub could only load initrd images from the EFI system partition, and so passing it via struct bootparams was needed for loaders like GRUB, which pass the initrd in memory, and may load it from anywhere, including from the network. Another motivation was EFI mixed mode, which could not use the initrd loader in the EFI stub at all due to 32/64 bit incompatibilities (which will be fixed shortly [0]), and could not invoke the ordinary PE/COFF entry point either, for the same reasons. Given that loaders such as GRUB already carried the bootparams handling in order to implement non-EFI boot, retaining that code and just passing bootparams to the EFI stub was a reasonable choice (although defining an alternate entrypoint could have been avoided.) However, the GRUB side changes never made it upstream, and are only shipped by some of the distros in their downstream versions. In the meantime, EFI support has been added to other Linux architecture ports, as well as to U-boot and systemd, including arch-agnostic methods for passing initrd images in memory [1], and for doing mixed mode boot [2], none of them requiring anything like the EFI handover protocol. So given that only out-of-tree distro GRUB relies on this, let's permit it to be omitted from the build, in preparation for retiring it completely at a later date. (Note that systemd-boot does have an implementation as well, but only uses it as a fallback for booting images that do not implement the LoadFile2 based initrd loading method, i.e., v5.8 or older) [0] https://lore.kernel.org/all/20220927085842.2860715-1-ardb@kernel.org/ [1] ec93fc371f01 ("efi/libstub: Add support for loading the initrd ...") [2] 97aa276579b2 ("efi/x86: Add true mixed mode entry point into ...") Signed-off-by: Ard Biesheuvel --- arch/x86/Kconfig | 17 +++++++++++++++++ arch/x86/boot/compressed/head_64.S | 4 +++- arch/x86/boot/header.S | 2 +- arch/x86/boot/tools/build.c | 2 ++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 8c6da5e42d5a6c25..121f1fdca3145fd2 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1981,6 +1981,23 @@ config EFI_STUB See Documentation/admin-guide/efi-stub.rst for more information. +config EFI_HANDOVER_PROTOCOL + bool "EFI handover protocol (DEPRECATED)" + depends on EFI_STUB + default y + help + Select this in order to include support for the deprecated EFI + handover protocol, which defines alternative entry points into the + EFI stub. This is a practice that has no basis in the UEFI + specification, and requires a priori knowledge on the part of the + bootloader about Linux/x86 specific ways of passing the command line + and initrd, and where in memory those assets may be loaded. + + If in doubt, say Y. Even though he corresponding support is not + present in upstream GRUB or other bootloaders, most distros build + GRUB with numerous downstream patches applied, and may rely on the + handover protocol as as result. + config EFI_MIXED bool "EFI mixed-mode support" depends on EFI_STUB && X86_64 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index dd18216cff5c37e0..a75712991df3e936 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -294,7 +294,7 @@ SYM_FUNC_START(startup_32) lret SYM_FUNC_END(startup_32) -#ifdef CONFIG_EFI_MIXED +#if IS_ENABLED(CONFIG_EFI_MIXED) && IS_ENABLED(CONFIG_EFI_HANDOVER_PROTOCOL) .org 0x190 SYM_FUNC_START(efi32_stub_entry) add $0x4, %esp /* Discard return address */ @@ -524,7 +524,9 @@ trampoline_return: SYM_CODE_END(startup_64) #ifdef CONFIG_EFI_STUB +#ifdef CONFIG_EFI_HANDOVER_PROTOCOL .org 0x390 +#endif SYM_FUNC_START(efi64_stub_entry) and $~0xf, %rsp /* realign the stack */ movq %rdx, %rbx /* save boot_params pointer */ diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S index f912d777013052ea..d31982509654dcb1 100644 --- a/arch/x86/boot/header.S +++ b/arch/x86/boot/header.S @@ -406,7 +406,7 @@ xloadflags: # define XLF1 0 #endif -#ifdef CONFIG_EFI_STUB +#ifdef CONFIG_EFI_HANDOVER_PROTOCOL # ifdef CONFIG_EFI_MIXED # define XLF23 (XLF_EFI_HANDOVER_32|XLF_EFI_HANDOVER_64) # else diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index a3725ad46c5a0b49..bd247692b70174f0 100644 --- a/arch/x86/boot/tools/build.c +++ b/arch/x86/boot/tools/build.c @@ -290,6 +290,7 @@ static void efi_stub_entry_update(void) { unsigned long addr = efi32_stub_entry; +#ifdef CONFIG_EFI_HANDOVER_PROTOCOL #ifdef CONFIG_X86_64 /* Yes, this is really how we defined it :( */ addr = efi64_stub_entry - 0x200; @@ -298,6 +299,7 @@ static void efi_stub_entry_update(void) #ifdef CONFIG_EFI_MIXED if (efi32_stub_entry != addr) die("32-bit and 64-bit EFI entry points do not match\n"); +#endif #endif put_unaligned_le32(addr, &buf[0x264]); }