From patchwork Mon May 22 07:14:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 97124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1269733vqo; Mon, 22 May 2023 00:37:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5T4zRBEVDYBb9v5IYT9n60QLGBNcrOgxCpKndu5bowclvp05LIvxp08Nw/WQUToCdBPRGp X-Received: by 2002:a17:903:185:b0:1af:b682:7a78 with SMTP id z5-20020a170903018500b001afb6827a78mr2473932plg.52.1684741047217; Mon, 22 May 2023 00:37:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684741047; cv=none; d=google.com; s=arc-20160816; b=bm2kTu9JA4TB0XMXPkFzz1pykLkONNB+EdUp/+d3Cg1wwk8RKdojTmUogTtfUfQpAe gEbzuR5cqVAu969A37Mx6wdpHQ+UXneVDGd/IKN9qsMAB9TXUaOfBKSqjn9eSjY9oU1z RiytkhBXjuSIQsAWhIroO4Y2yn5n0Z6Cwx8DLkvctcoCbITaemM4EH9DkDaOK3LQpWdm LwAj6FPSGAoIiVN80bkS5rGGack2ySa8NC01rQJmKIiL2mXCTui7MKok/bxnCUGAWaCd B3mkltE2g3Zy7N6UaVH3+XJZLY4FAn3kNOkG7HWA8fLp8T5u/ZthPYrM0WZA1mruQdfn JEHQ== 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=sQZhXDdW/Pt1TLOgC10hAFzrGwzWSSI2c8Hy68wku88=; b=EfuLQuTPKmZYqLuihBUrKsdiKEAqXkPb81eFaTotKxf3NBJao8/+dUeProP4XgKgL/ 95+BQ6Ds1A/OF2U5QJQhHNNHe4eDQLv8G3nAl5SytMyb3u68J3MNhpygkyxOmd1EgilC BETPviogxgG8mC/irwehdL9Vwmk0lE77NK1jknW41A/JFb/0HNXFtlIKlcvozKCK5aqn 4Mj3wJfPEi81h0uNigR/8BDSARhghwZdfJBNHRjpGKJ0czi9K/bqbnlOtD8TrXSZsgdv pu3clMJum+PMq5WnLDj5qqUqz8MOnmyc6ck9rvH7jPnlpYH2wed0nNA7nH+WmtsM/Mmp lrTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=B8PFMI8j; 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 y2-20020a17090264c200b001a51c26f601si4055913pli.627.2023.05.22.00.37.13; Mon, 22 May 2023 00:37:27 -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=B8PFMI8j; 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 S231135AbjEVHPq (ORCPT + 99 others); Mon, 22 May 2023 03:15:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229987AbjEVHPF (ORCPT ); Mon, 22 May 2023 03:15:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 204D791; Mon, 22 May 2023 00:15:04 -0700 (PDT) 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 AE44761DD3; Mon, 22 May 2023 07:15:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 670A6C4339B; Mon, 22 May 2023 07:14:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684739703; bh=4Bh3UcI6mBb60v5tgLvoAeGffUld7BrhFCXiRmmP3sE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B8PFMI8j/D51LvwF865+aX+iv+KDHkvt8iC4EiQ0I5a5plkeEOGknXXGhlLSVCdBk VejQ45+yCQrtU4u/hGOoy1OuEhq0NmMSI0i8QdnnFfkAz8UNd9WpBLADjT12WaVSvd RRlX1XYUOOVEafN9pN1wTvSXiJOJp/7tfJUmHb9pIiGrOGSufq1ANncvuh8eubQiQP 08jLV5QPB+HNvBkF3CEIBrmDfEqhFjKun10kvVrQ94fWodKSsFzt0sdh8Ksp2p6uzl uOLwsHkHT44yvjrvzsjDZQ4J5TiXTfhbORKXoRieGKBGmJtBrf4tRGlejT/W1VCGap u1DFoz+N1jZiA== 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 Subject: [PATCH v3 07/21] x86/decompressor: Call trampoline as a normal function Date: Mon, 22 May 2023 09:14:01 +0200 Message-Id: <20230522071415.501717-8-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230522071415.501717-1-ardb@kernel.org> References: <20230522071415.501717-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2554; i=ardb@kernel.org; h=from:subject; bh=4Bh3UcI6mBb60v5tgLvoAeGffUld7BrhFCXiRmmP3sE=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JISVbzPTyXcGvbvdk7s59zjTFLSjIQEnfS8e2IGX29+utW 1ncSkI6SlkYxDgYZMUUWQRm/3238/REqVrnWbIwc1iZQIYwcHEKwEQWPmX4X/zz6beN5SwCHx4L CT6Of3pzfUzP73c+guvUTitru/p8LWD4H64gNdtP63XgnDXiXh8fGXM4Lv4sUl68o3Hh5Tg7x91 xLAA= 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,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766579027889199516?= X-GMAIL-MSGID: =?utf-8?q?1766579027889199516?= Move the long return to switch to 32-bit mode into the trampoline code so it can be called as an ordinary function. This will allow it to be called directly from C code in a subsequent patch. Acked-by: Kirill A. Shutemov Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 25 +++++++++----------- arch/x86/boot/compressed/pgtable.h | 2 +- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 2d1b0ee94929f7ec..af45ddd8297a4a07 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -446,18 +446,9 @@ SYM_CODE_START(startup_64) /* Save the trampoline address in RCX */ movq %rax, %rcx - /* - * Load the address of trampoline_return() into RDI. - * It will be used by the trampoline to return to the main code. - */ - leaq trampoline_return(%rip), %rdi - - /* Switch to compatibility mode (CS.L = 0 CS.D = 1) via far return */ - pushq $__KERNEL32_CS leaq TRAMPOLINE_32BIT_CODE_OFFSET(%rax), %rax - pushq %rax - lretq -trampoline_return: + call *%rax + /* Restore the stack, the 32-bit trampoline uses its own stack */ leaq rva(boot_stack_end)(%rbx), %rsp @@ -540,16 +531,22 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) jmp *%rax SYM_FUNC_END(.Lrelocated) - .code32 /* * This is the 32-bit trampoline that will be copied over to low memory. * - * RDI contains the return address (might be above 4G). * ECX contains the base address of the trampoline memory. * Non zero RDX means trampoline needs to enable 5-level paging. */ SYM_CODE_START(trampoline_32bit_src) - /* Set up data and stack segments */ + popq %rdi + /* Switch to compatibility mode (CS.L = 0 CS.D = 1) via far return */ + pushq $__KERNEL32_CS + leaq 0f(%rip), %rax + pushq %rax + lretq + + .code32 +0: /* Set up data and stack segments */ movl $__KERNEL_DS, %eax movl %eax, %ds movl %eax, %ss diff --git a/arch/x86/boot/compressed/pgtable.h b/arch/x86/boot/compressed/pgtable.h index cc9b2529a08634b4..91dbb99203fbce2d 100644 --- a/arch/x86/boot/compressed/pgtable.h +++ b/arch/x86/boot/compressed/pgtable.h @@ -6,7 +6,7 @@ #define TRAMPOLINE_32BIT_PGTABLE_OFFSET 0 #define TRAMPOLINE_32BIT_CODE_OFFSET PAGE_SIZE -#define TRAMPOLINE_32BIT_CODE_SIZE 0x80 +#define TRAMPOLINE_32BIT_CODE_SIZE 0xA0 #define TRAMPOLINE_32BIT_STACK_END TRAMPOLINE_32BIT_SIZE