Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4611268rwb; Tue, 8 Aug 2023 10:57:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE33MDp2JsUSCWypEHxKnZBFQgNjy6sOPTl9GVpYgvpYoNlwjNwAFVJf3V/SwLcFqf3HX3+ X-Received: by 2002:a05:6a20:100c:b0:140:ed6d:9251 with SMTP id gs12-20020a056a20100c00b00140ed6d9251mr212573pzc.27.1691517433191; Tue, 08 Aug 2023 10:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691517433; cv=none; d=google.com; s=arc-20160816; b=xiwJkSg70UEA/QBlqBaGZhsTAaGl0VRL2WAXifa5MA4vpjD6MpVJGAJu/KH/avCQJZ XROB6V5M2n+oc6HEJ4l323JVPc87UmWBk0KmetLz+gdFkiSA1Tt5utRtRamGe3Z/zuux 7KjCTeXXoXpliMfBnZD4jZLk7C20e4LIU22S87QIVa+KN8iT6L1G1YZ48IFEDnJ5Ub8X UfPvEXlihchudQ778OqEHLRSoAcYP4UwkQnhAjaozkDOoRRB5wLbjVkn5dCCEAZ630sy nUeyDObbPnsJO9PZxdU9gIX9gbYTr/NYrIRdVpTgH+YX+9e8/ymLFIvHmCb1x08/fxAK ok4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=uZlmaptKCOpdsLr8kN2LaHTEuYrrsk0jVhLTIREB6iU=; fh=upm4t26Ojn/J6N+Q9k8Qqzx52VymNDAlYlARzLeNh5s=; b=XQj1ZbaXWbLz6fV81xhUeC6OjeOkhBwg81Sg2jNzHcU6iSZxL7jgLWHzJXEUFaQt3S VSergtsYRvsHrALl/UBZKDjpDMsphLYzQxTIqANUVyY7SFDTOMICRKfKFpJDc0R4JYH0 m9VvpZrcqPJB5WUqT4V4TPH6mKcXACeTratdxu0zhFCpD/zEcYr2hbO+0ZzDPlcC/jEm TBbM6ejDBFqoRyqJM5dezxFvOZtfnlmdvd7HMZY++WAYy2UNBVbNicKUs6Pc2f/XBL74 OwSqsnj38h2erL/RWtaFFzHsT5NdahROgloZKBp0k7dSx2rDFL8rZH9D739z6OoJ7Sr8 dTMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=K7Gl5uQI; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dw12-20020a056a00368c00b006871d101748si5075957pfb.254.2023.08.08.10.57.00; Tue, 08 Aug 2023 10:57:13 -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=@linutronix.de header.s=2020 header.b=K7Gl5uQI; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233150AbjHHQf7 (ORCPT + 99 others); Tue, 8 Aug 2023 12:35:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232829AbjHHQev (ORCPT ); Tue, 8 Aug 2023 12:34:51 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E1C514248; Tue, 8 Aug 2023 08:52:36 -0700 (PDT) Date: Tue, 08 Aug 2023 08:44:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691484245; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uZlmaptKCOpdsLr8kN2LaHTEuYrrsk0jVhLTIREB6iU=; b=K7Gl5uQI2k7waQZYAEm+Jol6ANkgkBO7D2Z3MLBviLsK8kIhT68xyQ2Xm/c4GWq3jQkj5d Q7d9O+uCAE+bJtLNJXAolm/BKcpjE+9QTiL8Q4AKHj8w94wIYjCA0qQck3Z1DPkV6g+Oke VHlv04afJPBWz4T4NdD7pmfU/IRxDakKtijCR+A5DlzQ5wdXq6m8LepMgOMGMaibPACGo/ MKQh/KOd6slxnOoUAkPTS3Qm1PlVDuEX1dqb7gvxOIzjcG2VPShcK1tfFIWvziXgSjoNEh STdlTN929l8oUdzTqu3ACvCHHuBMqqcwFJrFUib5zmstepPE7suh0wAngw9Q9w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691484245; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uZlmaptKCOpdsLr8kN2LaHTEuYrrsk0jVhLTIREB6iU=; b=zpXVLuKGRGdTBg8j3X+EVRvNzE7XzaN7ML21GrwpZBTkuRngPblkp4ixm326JCJJ/1p7TC sbXHGSrII76gFgCA== From: "tip-bot2 for Ard Biesheuvel" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/boot] x86/decompressor: Store boot_params pointer in callee save register Cc: Ard Biesheuvel , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230807162720.545787-8-ardb@kernel.org> References: <20230807162720.545787-8-ardb@kernel.org> MIME-Version: 1.0 Message-ID: <169148424445.27769.5605999740207693312.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DATE_IN_PAST_06_12, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 The following commit has been merged into the x86/boot branch of tip: Commit-ID: 8b63cba746f86a754d66e302c43209cc9b9b6e39 Gitweb: https://git.kernel.org/tip/8b63cba746f86a754d66e302c43209cc9b9b6e39 Author: Ard Biesheuvel AuthorDate: Mon, 07 Aug 2023 18:27:04 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Mon, 07 Aug 2023 20:41:04 +02:00 x86/decompressor: Store boot_params pointer in callee save register 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 Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20230807162720.545787-8-ardb@kernel.org --- arch/x86/boot/compressed/head_64.S | 42 +++++++++++------------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index a3f764d..19bf810 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 /* @@ -419,12 +423,10 @@ SYM_CODE_START(startup_64) * CPUID instructions being issued, so go ahead and do that now via * sev_enable(), which will also handle the rest of the SEV-related * detection/setup to ensure that has been done in advance of any dependent - * code. + * code. Pass the boot_params pointer as the first argument. */ - pushq %rsi - movq %rsi, %rdi /* real mode address */ + movq %r15, %rdi call sev_enable - popq %rsi #endif /* @@ -437,13 +439,10 @@ 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. + * Pass the boot_params pointer as the first argument. */ - pushq %rsi - movq %rsi, %rdi /* real mode address */ + movq %r15, %rdi call paging_prepare - popq %rsi /* Save the trampoline address in RCX */ movq %rax, %rcx @@ -456,9 +455,9 @@ SYM_CODE_START(startup_64) * because the architecture does not guarantee that GPRs will retain * their full 64-bit values across a 32-bit mode switch. */ + pushq %r15 pushq %rbp pushq %rbx - pushq %rsi /* * Push the 64-bit address of trampoline_return() onto the new stack. @@ -475,9 +474,9 @@ SYM_CODE_START(startup_64) lretq trampoline_return: /* Restore live 64-bit registers */ - popq %rsi popq %rbx popq %rbp + popq %r15 /* Restore the stack, the 32-bit trampoline uses its own stack */ leaq rva(boot_stack_end)(%rbx), %rsp @@ -487,14 +486,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 @@ -504,7 +498,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 @@ -512,7 +505,6 @@ trampoline_return: std rep movsq cld - popq %rsi /* * The GDT may get overwritten either during the copy we just did or @@ -544,30 +536,28 @@ 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 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 */ + /* pass struct boot_params pointer */ + movq %r15, %rdi 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)