Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36547496rwd; Tue, 11 Jul 2023 02:25:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlGjhwdB1wskA1icRoQyCUYKswoniPIdaCAadmpuv6VMNz3jmfpYit2VYJCLTDnGvUo7pq7J X-Received: by 2002:a17:90a:778c:b0:262:eb20:2dd8 with SMTP id v12-20020a17090a778c00b00262eb202dd8mr21948571pjk.20.1689067547508; Tue, 11 Jul 2023 02:25:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689067547; cv=none; d=google.com; s=arc-20160816; b=PrjI7nIM9MywQBE/p6AboNV6geaKo+FbhXc/PvNwX4i5antWaCZ4TjsbgSREUEqTZi R8Oo/irr+NFWBiOSnFYLvGwlLHq0UqwRbpSBdaO0KXVO+wUdro5ncugw3GIS8XUAdZsr oquQaqvhXtQhG1R1GygrG4g6c6i6VoXwnl4JYaM40k94w50H8FGohIDSta+ngWiLsjj8 +V+sbzYDRpPFeKM3jyItekR9Sa2qz09pQt2jTdOzZhXq4OsVHACBY4lFwY4+GLjBEfX7 uPNpbPCWqEMSQRckg8acuXZiTp1So71VxA+95C74JhumGAracfRj1qxjk0sAnmq7FeuE z7iw== 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=owkHrfGk6rkCsLR4jaeO3WUYAvrwcw7T/GSFdPTyMwM=; fh=UoPnrMfWVKGOqsML3Cwqzr4dYAyNRBpPmY/ITnBmPi0=; b=mAGVBtmKZWowCjLKwb1bEfUj4oqBYbv2G6E24xVDHtcoDFQD1nmtQWC/XVeZZXIGqC qVNCZg07NFtL/y0I92KdKIgYyUM8lntja/I7MKur/Ze5GYCHz96ew9+PFK+8xVcW3gm/ Ay/iZhOrRbPJBOb96C9VlYysQtzkqjmcBknpeHu0aKT9S8cbyyxoQ6b778w2yktkt2rm svsbKnHAPA3OxPcldPgQtcwTmVyd/fkraEFmbNNZubix/CbGhRjEvhfAGa0l3Lb5ANuC CbHAXEqFwRgyPO9wI0yD8H8cd77bwY5KVE3qiCG0s2gppmch8Eqm8Frv6Qa7Ey85nkdi xcPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=goIIuxR+; 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 hv15-20020a17090ae40f00b0025c0a65a763si1336478pjb.121.2023.07.11.02.25.35; Tue, 11 Jul 2023 02:25:47 -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=goIIuxR+; 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 S232084AbjGKJQl (ORCPT + 99 others); Tue, 11 Jul 2023 05:16:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231782AbjGKJQB (ORCPT ); Tue, 11 Jul 2023 05:16:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6D61199B; Tue, 11 Jul 2023 02:15:42 -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 55EBE6142D; Tue, 11 Jul 2023 09:15:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1A35C433CB; Tue, 11 Jul 2023 09:15:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689066941; bh=6LI2p3tMGpqgjf5Vh98U5/dlrPhBIFsp0XryDg0+x/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=goIIuxR+7oElBR6wClSl9nuOwBmexUWH39mbtcu3rA4guPecBJ4ZaLPauQipvboPE mxWBVwBPwkc2riFIWOjKvbjsxcK1GFjxc+gTbyzqwS9waJa2cUTN5p81xd7AF2VC8D wDC+9gmUK7qR9x6/7dln9nc9RRtYjTXw58XnVSKSd5UUaAZ1hl49t3hwwnBVppuyML lLkaSmAcg/G02hvEup+GaCdtgIcNo3KPmqvYYCiiFMkyVEFO0HkLdjRUQXUXj4xlI4 c34JL/0+2sVGENegoLjdw0/PF5yWWBeJXeM7N6mQwQ9zMUluks0plXA2wwT7ClcFdD F94U9NrXV5mwA== 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 09/21] x86/decompressor: Use standard calling convention for trampoline Date: Tue, 11 Jul 2023 11:14:41 +0200 Message-Id: <20230711091453.2543622-10-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=4143; i=ardb@kernel.org; h=from:subject; bh=6LI2p3tMGpqgjf5Vh98U5/dlrPhBIFsp0XryDg0+x/4=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIWWtbP3K1IsS52ucnFrZuk6dMu21jWv92ZqpsmumT4mdR PAbPtuOUhYGMQ4GWTFFFoHZf9/tPD1RqtZ5lizMHFYmkCEMXJwCMBGNVIb/BdU9i/d1dZgW2Bvu buRQPC1YtChdXcn1SuTjbOc702TMGBmOmRXXsky48OuBV+j79UGr1OZ8OXXy8Zu/coJX8wNePPn DDAA= 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 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. Acked-by: Kirill A. Shutemov Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 30 +++++++++----------- arch/x86/boot/compressed/pgtable.h | 2 +- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index af45ddd8297a4a07..a387cd80964e1a1e 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -443,9 +443,9 @@ SYM_CODE_START(startup_64) movq %r15, %rdi /* pass struct boot_params pointer */ 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 @@ -534,11 +534,11 @@ SYM_FUNC_END(.Lrelocated) /* * This is the 32-bit trampoline that will be copied over to low memory. * - * ECX contains the base address of the trampoline memory. - * Non zero RDX means trampoline needs to enable 5-level paging. + * EDI contains the base address of the trampoline memory. + * Non-zero ESI means trampoline needs to enable 5-level paging. */ SYM_CODE_START(trampoline_32bit_src) - popq %rdi + popq %r8 /* Switch to compatibility mode (CS.L = 0 CS.D = 1) via far return */ pushq $__KERNEL32_CS leaq 0f(%rip), %rax @@ -552,7 +552,7 @@ SYM_CODE_START(trampoline_32bit_src) movl %eax, %ss /* Set up new stack */ - leal TRAMPOLINE_32BIT_STACK_END(%ecx), %esp + leal TRAMPOLINE_32BIT_STACK_END(%edi), %esp /* Disable paging */ movl %cr0, %eax @@ -560,7 +560,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 */ @@ -575,21 +575,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. @@ -606,14 +602,14 @@ 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: movl %eax, %cr4 /* Calculate address of paging_enabled() once we are executing in the trampoline */ - leal .Lpaging_enabled - trampoline_32bit_src + TRAMPOLINE_32BIT_CODE_OFFSET(%ecx), %eax + leal .Lpaging_enabled - trampoline_32bit_src + TRAMPOLINE_32BIT_CODE_OFFSET(%edi), %eax /* Prepare the stack for far return to Long Mode */ pushl $__KERNEL_CS @@ -630,7 +626,7 @@ SYM_CODE_END(trampoline_32bit_src) .code64 SYM_FUNC_START_LOCAL_NOALIGN(.Lpaging_enabled) /* Return from the trampoline */ - jmp *%rdi + jmp *%r8 SYM_FUNC_END(.Lpaging_enabled) /* diff --git a/arch/x86/boot/compressed/pgtable.h b/arch/x86/boot/compressed/pgtable.h index 91dbb99203fbce2d..4e8cef135226bcbb 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 */ -- 2.39.2