Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36547431rwd; Tue, 11 Jul 2023 02:25:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlHZwHALNUviJpCjieKFem3+p4H40Rt4sS+Yk+e7MPqMWrRiCr212Lw6m72yGnp1ir3kuueU X-Received: by 2002:a17:90b:4c4f:b0:263:72fe:3ef7 with SMTP id np15-20020a17090b4c4f00b0026372fe3ef7mr14393166pjb.42.1689067542299; Tue, 11 Jul 2023 02:25:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689067542; cv=none; d=google.com; s=arc-20160816; b=GoAyqrZ9B8fC8Z4LQO/JN+Vyq17D01hlh44cFMfeRl1g6GZdKQZv4Hk6V6iv84VoWt K8kpZQvxFFcT//wZKtNmvDmpy4p6n5oK58MXQjlAx2wi03atsjgasq0anMV0o4FbQN/o 96cKh5TgF/b/dp0E6vpZwpw2WFqTq/pRjdug2B7toYV1v1KUpdVJJ3Cz3NtiBHybObDp wC3n59p2IyoXcjSXBJlcqaIBCTLH8wjobXlkXTxAG4q52vjhgT3BTg1AE2z5SzTttYKw CIx0Zz0AUDsmv0eBd2IgMxdxg7yez8Jg52vkHGoOezGlVjm4OVWkERIqYJjzweznQWcA CVkQ== 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=9LNa+G2wrQIjRvt2UCstrzgBbRTUvf6M5+JO2w9PXAw=; fh=UoPnrMfWVKGOqsML3Cwqzr4dYAyNRBpPmY/ITnBmPi0=; b=hoU6aU2A1GdDiDrE7w1zuDiHbjE/nu1v40PBq27EyKSCzx+4iQ36gnJ1QyzLbhZbdX jMTqCpxK/8fmxwBUUZMCfSHi0hrE6r4Z2X1+e+tJs38AJZRA8CC12aGtLJlHgkPH+Cig qg2aPEpvbDBrxaiAxpqae0zcouYfgJ8JsFFzC8KBKtT4UstuiCxKQok9stFN8Ka36Etr aoYKTLYD328i3OpPH0Fmy0VNfMP9PtE+F31Dk6Nut5Sxe1FSSkcwE6pslqniCDU5sgf2 DDU2r5NsFBjmHQ0s8SN2Rc8E34IgDW5dUsSOWJASt4S9Tn9sJZgnx5+VdfTHultCKzaJ CPbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Pl4+Fo/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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d14-20020a17090ad3ce00b00263b4a986cfsi8720219pjw.73.2023.07.11.02.25.30; Tue, 11 Jul 2023 02:25:42 -0700 (PDT) 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="Pl4+Fo/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 S232124AbjGKJQZ (ORCPT + 99 others); Tue, 11 Jul 2023 05:16:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbjGKJP5 (ORCPT ); Tue, 11 Jul 2023 05:15:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E35910E5; Tue, 11 Jul 2023 02:15:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B79B261422; Tue, 11 Jul 2023 09:15:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FF54C433CB; Tue, 11 Jul 2023 09:15:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689066933; bh=XH7auhXZovyO0ZjhIGuK6rXf321+XRWDmJGikLNf51o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pl4+Fo/mjOK6St6nCHvTGs5nkSaZR7NA1o0c367yMtjvqPKV126+GL29nsnZ58SHM ShxjC20zuV+qui5U7DdR6qaDxXp8SCJlWOmGbwvdUAwYvizqiCefGIwKGRFctAXPt/ I9ZGv14aw76j7/FSQi4aCmai/VlalqKPIP8+ICAsgDMf+MDQGWBgfXEPIJ0oZDKVZg S0xCQz915BzcYG1YLfIwPDsI5E4eHA48uiXnHvQUDYjgNQvAW1XjGbneqSE57La8g2 QoA5DAPTYr9MxgzNbISGEGPI5tBpNlbRqHE/JBNUI9WRcYgk1fEobTAvrJWqe87Svn dueAALLZrx0cw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Evgeniy Baskov , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , Gerd Hoffmann , Dave Young , Mario Limonciello , Kees Cook , Tom Lendacky , "Kirill A . Shutemov" , Linus Torvalds , Joerg Roedel Subject: [PATCH v6 07/21] x86/decompressor: Store boot_params pointer in callee save register Date: Tue, 11 Jul 2023 11:14:39 +0200 Message-Id: <20230711091453.2543622-8-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230711091453.2543622-1-ardb@kernel.org> References: <20230711091453.2543622-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3619; i=ardb@kernel.org; h=from:subject; bh=XH7auhXZovyO0ZjhIGuK6rXf321+XRWDmJGikLNf51o=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIWWtbO2iSCO7qzOsN4pOmPc/IOhV1+edyd4Xk17a6h4Rc FCbr27cUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACZSNpfhn06MuuaJQ2Fvg9yM Gbd5X2sq1TV/ee/moZzvb8UN6vftW8fwT/vJO6Wiczczclu+rbw0uUPkX+bBgq8190s4Jh3lY7h 2mAMA X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit 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,T_SCC_BODY_TEXT_LINE 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 Instead of pushing and popping %RSI several times to preserve the struct boot_params pointer across the execution of the startup code, move it into a callee save register before the first call into C, and copy it back when needed. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 34 +++++++------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 9f90661744741210..2d1b0ee94929f7ec 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -405,10 +405,14 @@ SYM_CODE_START(startup_64) lretq .Lon_kernel_cs: + /* + * RSI holds a pointer to a boot_params structure provided by the + * loader, and this needs to be preserved across C function calls. So + * move it into a callee saved register. + */ + movq %rsi, %r15 - pushq %rsi call load_stage1_idt - popq %rsi #ifdef CONFIG_AMD_MEM_ENCRYPT /* @@ -421,10 +425,8 @@ SYM_CODE_START(startup_64) * detection/setup to ensure that has been done in advance of any dependent * code. */ - pushq %rsi - movq %rsi, %rdi /* real mode address */ + movq %r15, %rdi /* pass struct boot_params pointer */ call sev_enable - popq %rsi #endif /* @@ -437,13 +439,9 @@ SYM_CODE_START(startup_64) * - Non zero RDX means trampoline needs to enable 5-level * paging. * - * RSI holds real mode data and needs to be preserved across - * this function call. */ - pushq %rsi - movq %rsi, %rdi /* real mode address */ + movq %r15, %rdi /* pass struct boot_params pointer */ call paging_prepare - popq %rsi /* Save the trampoline address in RCX */ movq %rax, %rcx @@ -468,14 +466,9 @@ trampoline_return: * * RDI is address of the page table to use instead of page table * in trampoline memory (if required). - * - * RSI holds real mode data and needs to be preserved across - * this function call. */ - pushq %rsi leaq rva(top_pgtable)(%rbx), %rdi call cleanup_trampoline - popq %rsi /* Zero EFLAGS */ pushq $0 @@ -485,7 +478,6 @@ trampoline_return: * Copy the compressed kernel to the end of our buffer * where decompression in place becomes safe. */ - pushq %rsi leaq (_bss-8)(%rip), %rsi leaq rva(_bss-8)(%rbx), %rdi movl $(_bss - startup_32), %ecx @@ -493,7 +485,6 @@ trampoline_return: std rep movsq cld - popq %rsi /* * The GDT may get overwritten either during the copy we just did or @@ -525,30 +516,27 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) shrq $3, %rcx rep stosq - pushq %rsi call load_stage2_idt /* Pass boot_params to initialize_identity_maps() */ - movq (%rsp), %rdi + movq %r15, %rdi /* pass struct boot_params pointer */ call initialize_identity_maps - popq %rsi /* * Do the extraction, and jump to the new kernel.. */ - pushq %rsi /* Save the real mode argument */ - movq %rsi, %rdi /* real mode address */ + movq %r15, %rdi /* pass struct boot_params pointer */ leaq boot_heap(%rip), %rsi /* malloc area for uncompression */ leaq input_data(%rip), %rdx /* input_data */ movl input_len(%rip), %ecx /* input_len */ movq %rbp, %r8 /* output target address */ movl output_len(%rip), %r9d /* decompressed length, end of relocs */ call extract_kernel /* returns kernel entry point in %rax */ - popq %rsi /* * Jump to the decompressed kernel. */ + movq %r15, %rsi jmp *%rax SYM_FUNC_END(.Lrelocated) -- 2.39.2