Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4826881rwb; Tue, 8 Aug 2023 14:45:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOx6LH9ObOIyZB7dwezAlzZw+nuHzbiB/Sg8CCqzSSVFiREMmuxp012Gc0gheSaye8lUFB X-Received: by 2002:a05:6a21:35c4:b0:13e:1712:4c01 with SMTP id ba4-20020a056a2135c400b0013e17124c01mr613385pzc.42.1691531148671; Tue, 08 Aug 2023 14:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691531148; cv=none; d=google.com; s=arc-20160816; b=g4WmvUS9Hkft6cSPbyQzvdg8oeV3RpIH8kF4hcf51vOD+b6KmyxztRKLZKsEHzR5cH 8N5XPHGwAKQtisMSGf3Y867hqJt/T3XPDeiBTjqx2WCDNretgHyGOZFCbL78OmpsaYoj tDfxHKURC17h5adiJ8rPMM4qGoZjEwo3asem+/P6dIY1BH6tAcV1jbXL38xUxKmQc45o qIY8acVDc1itAJLKFleWvMHF3mBHlmFDXWJ8QgOXHzEMGgBl6cWuxMhnme1Cj3ppi7a/ t7MG3OuBHL2xAuq3ybFQ1bFmMDxknS3hrZ/vkEeL0XqnXomP4mjU60b4yp96j8e9nkGr h3ZQ== 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=7OnvnQWhupjYWp1MgPVjQQ6/qDtRRqdDMe5rBy72aN4=; fh=89EtlG8OroDzV7Zs9C7yICUtoHnJiTR7I5L4uhfdSD4=; b=J1uUYpb/nxdPU6cHj3wTBnoAKdsmMdQPMvWAG1TIb9rDY9lDBOwurfIOjGsS5nn8jX 72wbGX9xvUnLIwX98JOrHW7WS7bqlgOLg1DU06uEbQXJHCiST6OWUJWx+T8g4EG26JRB jqNZgnZkmKuNtvESsN9WvbKW3SP1aa/NspRSptV9zIvhpnintPbZEljBlykcc+5k7tI9 OA328qegTM2Xl4JvZTfY32Ou9l6LRKba6A1f5gG5VFVdCVHoug8PLOP4TPhGRED1T/fX eVdDTxh+K/vk5S1sXPL9D39U6ZBARugTLf/7WfJlRADwS6A2rdy4Wnwx5LoUD99gOX7M yaEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0xY+wkB+; 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 b12-20020a6567cc000000b005600a533c7esi7548795pgs.89.2023.08.08.14.45.36; Tue, 08 Aug 2023 14:45:48 -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=0xY+wkB+; 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 S233007AbjHHQfL (ORCPT + 99 others); Tue, 8 Aug 2023 12:35:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233005AbjHHQeM (ORCPT ); Tue, 8 Aug 2023 12:34:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 385A31FF3; Tue, 8 Aug 2023 08:52:27 -0700 (PDT) Date: Tue, 08 Aug 2023 08:44:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691484243; 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=7OnvnQWhupjYWp1MgPVjQQ6/qDtRRqdDMe5rBy72aN4=; b=0xY+wkB+l1TsMEqOGglt+78JfbRTVXLbwhNiwk3q/6Y0M+F4ZaQFY0naFco1vxAct8S7do b0LFN+dDNbtB6RSQpjos3jKmZLTmZ3DjM/d/O+7lPiX3OwlMgUN9E7MD3L59mYLUCgnhEB CVuxatRsfxcwW5zB5dUhoAAsISjplUcl06q7zO+Z3xfaiHXi79h12vvqfZTqkQ5CJLN5T9 2MHzosC7NrmOzDk4w/R0bHM0/pg+6gK4OUyCJllJRO+1bcKwFJwAj4/WLyup9Bcsgs73nE C8NreI0kN0Vp6vWRBiU47wsn+acLwbLNiu0s3Y7O0X5wIRVGD8aOSq2SFwFVBg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691484243; 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=7OnvnQWhupjYWp1MgPVjQQ6/qDtRRqdDMe5rBy72aN4=; b=R0ip1rYHBfUYESlOctpK4iXatQW0xgbvJvVDPttr84ctu4GeEqC6WY8Daordl4hvRQqea0 K59lzXW+hXORtVDA== 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: Use standard calling convention for trampoline Cc: Ard Biesheuvel , "Borislav Petkov (AMD)" , "Kirill A. Shutemov" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230807162720.545787-11-ardb@kernel.org> References: <20230807162720.545787-11-ardb@kernel.org> MIME-Version: 1.0 Message-ID: <169148424322.27769.15495483249376498258.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: 918a7a04e71745e99a0efc6753e587439b794b29 Gitweb: https://git.kernel.org/tip/918a7a04e71745e99a0efc6753e587439b794b29 Author: Ard Biesheuvel AuthorDate: Mon, 07 Aug 2023 18:27:07 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Mon, 07 Aug 2023 20:43:59 +02:00 x86/decompressor: Use standard calling convention for trampoline Update the trampoline code so its arguments are passed via RDI and RSI, which matches the ordinary SysV calling convention for x86_64. This will allow this code to be called directly from C. Signed-off-by: Ard Biesheuvel Signed-off-by: Borislav Petkov (AMD) Acked-by: Kirill A. Shutemov Link: https://lore.kernel.org/r/20230807162720.545787-11-ardb@kernel.org --- arch/x86/boot/compressed/head_64.S | 27 +++++++++++++-------------- arch/x86/boot/compressed/pgtable.h | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 91b5eee..c475042 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -444,9 +444,9 @@ SYM_CODE_START(startup_64) movq %r15, %rdi call paging_prepare - /* Save the trampoline address in RCX */ - movq %rax, %rcx - + /* Pass the trampoline address and boolean flag as args #1 and #2 */ + movq %rax, %rdi + movq %rdx, %rsi leaq TRAMPOLINE_32BIT_CODE_OFFSET(%rax), %rax call *%rax @@ -531,11 +531,14 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) SYM_FUNC_END(.Lrelocated) /* - * This is the 32-bit trampoline that will be copied over to low memory. + * This is the 32-bit trampoline that will be copied over to low memory. It + * will be called using the ordinary 64-bit calling convention from code + * running in 64-bit mode. * * Return address is at the top of the stack (might be above 4G). - * ECX contains the base address of the trampoline memory. - * Non zero RDX means trampoline needs to enable 5-level paging. + * The first argument (EDI) contains the 32-bit addressable base of the + * trampoline memory. A non-zero second argument (ESI) means that the + * trampoline needs to enable 5-level paging. */ SYM_CODE_START(trampoline_32bit_src) /* @@ -582,7 +585,7 @@ SYM_CODE_START(trampoline_32bit_src) movl %eax, %cr0 /* Check what paging mode we want to be in after the trampoline */ - testl %edx, %edx + testl %esi, %esi jz 1f /* We want 5-level paging: don't touch CR3 if it already points to 5-level page tables */ @@ -597,21 +600,17 @@ SYM_CODE_START(trampoline_32bit_src) jz 3f 2: /* Point CR3 to the trampoline's new top level page table */ - leal TRAMPOLINE_32BIT_PGTABLE_OFFSET(%ecx), %eax + leal TRAMPOLINE_32BIT_PGTABLE_OFFSET(%edi), %eax movl %eax, %cr3 3: /* Set EFER.LME=1 as a precaution in case hypervsior pulls the rug */ - pushl %ecx - pushl %edx movl $MSR_EFER, %ecx rdmsr btsl $_EFER_LME, %eax /* Avoid writing EFER if no change was made (for TDX guest) */ jc 1f wrmsr -1: popl %edx - popl %ecx - +1: #ifdef CONFIG_X86_MCE /* * Preserve CR4.MCE if the kernel will enable #MC support. @@ -628,7 +627,7 @@ SYM_CODE_START(trampoline_32bit_src) /* Enable PAE and LA57 (if required) paging modes */ orl $X86_CR4_PAE, %eax - testl %edx, %edx + testl %esi, %esi jz 1f orl $X86_CR4_LA57, %eax 1: diff --git a/arch/x86/boot/compressed/pgtable.h b/arch/x86/boot/compressed/pgtable.h index 91dbb99..4e8cef1 100644 --- a/arch/x86/boot/compressed/pgtable.h +++ b/arch/x86/boot/compressed/pgtable.h @@ -14,7 +14,7 @@ extern unsigned long *trampoline_32bit; -extern void trampoline_32bit_src(void *return_ptr); +extern void trampoline_32bit_src(void *trampoline, bool enable_5lvl); #endif /* __ASSEMBLER__ */ #endif /* BOOT_COMPRESSED_PAGETABLE_H */