Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36559729rwd; Tue, 11 Jul 2023 02:38:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlFi5/7yJBn1DYt8161VoNb6VIiELL12HrV46zvz94BA9BKVog5fBbip/5IcXbZ12ZVQN7hb X-Received: by 2002:a05:6358:5e02:b0:134:c8ee:e451 with SMTP id q2-20020a0563585e0200b00134c8eee451mr11743421rwn.13.1689068295552; Tue, 11 Jul 2023 02:38:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689068295; cv=none; d=google.com; s=arc-20160816; b=E/AGZ1KlmlTiz33tQcBzToZiagktEP409/JqI0aHOutz5umka51RuiP3823ZMgtK3A drjoZk0ePn/huDfxoRgHJq8GxBXkbxhSZlhlt3cTEto37VOKmdCveo4SZ9ejyDd8gMG2 6fDcm+1e77Slb9ktoXHPA5/t3H6Uk96R030ZSHSZGUKur5RFEg13enJycnjeIDtElqgq c0QgM0hLqQk/1rYhaBUhvkZJT4Q4RnDClpgVpAWOAn/Q7dhs3GRQFAWYsDum+hPj8g8m KRlnNSZyBS4vZs29YA++h1HloSL1b2Zyy6kLqUHp3oJO7vrLZtGBud5YYTvQX5PlDezx Saww== 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=; fh=UoPnrMfWVKGOqsML3Cwqzr4dYAyNRBpPmY/ITnBmPi0=; b=qrlwLk/dsYSyG4IqDtwy8OAOVDEp2eghrzk01V/M5mqe6PekRRJNvBGSJS5djzgy+G qxqzvU5s2pvMD+R32XTYM2PzAF00gfUi6S18qMIBhNUsjEfGfgjFPBT+IhXkmpmizpgY djLYl7/j7fBTlO37oIMJ3sOw2Fc6go5UuNeCRC03rfcuu7UsvzM/xSu5qNpqTjmNHdXO pujr0tF1xW2TXFkzBEREfclRK92kjQV7GZzPJ5QVbBsJjCEkv4zqOj6ik6LeQuwN+0o1 kO8qs7xRaoYlNK1gcHBfy+Op1Fxwk7aH+EDg303xrcQNLEEHITxXf2Iwy1VOt78kZvSM /j3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qAJETu4R; 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 z20-20020a634c14000000b0053fc3bc33e4si1099511pga.795.2023.07.11.02.38.03; Tue, 11 Jul 2023 02:38:15 -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=qAJETu4R; 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 S232067AbjGKJQ2 (ORCPT + 99 others); Tue, 11 Jul 2023 05:16:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231874AbjGKJP7 (ORCPT ); Tue, 11 Jul 2023 05:15:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 796C910EF; Tue, 11 Jul 2023 02:15:38 -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 08FB36141D; Tue, 11 Jul 2023 09:15:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98842C433CA; Tue, 11 Jul 2023 09:15:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689066937; bh=4Bh3UcI6mBb60v5tgLvoAeGffUld7BrhFCXiRmmP3sE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qAJETu4R6R4fSEZU+fFSE34tlJ0tsHAWD1UY5TgbVp2xJqf6h3nM3L1ImFv55RYGG LRjiDtKgqDP5wbSejQFfRldrBu6y73SDvn6Ot2HQ1PJOKezgVBCv5TlAsUZs7UBSMr j7vAzDqlkRJyx97jYIlTL4OQJAj6f6acG7nV/m5byk3XpIFvA9WptbcwwdWwjxTZfy QQGFJm6SI9OyQsgf1xYWsqie8uRcM3HECuPXCgDzNexCkNjhZ9oIvPMelZvGwUn6C4 WRMocomKCU1cJVtxis+gGRHr388fdvJoGk7kYVMs0YI6W/5Q0V+EJb0W5hpRQamGP+ e85uu9JR/h+0A== 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 08/21] x86/decompressor: Call trampoline as a normal function Date: Tue, 11 Jul 2023 11:14:40 +0200 Message-Id: <20230711091453.2543622-9-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=2554; i=ardb@kernel.org; h=from:subject; bh=4Bh3UcI6mBb60v5tgLvoAeGffUld7BrhFCXiRmmP3sE=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIWWtbN3lu4Jf3e7J3J37nGmKW1CQgZK+l45tQcrs79dbt 7K4lYR0lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgIloljAyvDB6E3wncu+ta7Mb Tt6c1nL0NX9k1hc+tgOtu8u7c8LMwhgZ3kmvDXiitnumc+/btZfWNap1XXkS++G2UuKfjR5p/w+ dZwQA X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 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 -- 2.39.2