Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp5444222rwb; Wed, 21 Sep 2022 07:57:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7JwtZnTeqyqEqqlVp5yg8QdE+maxV2WBuJnacrWGadAb0lYC8MXTiALq3rOtOrGswjCpK3 X-Received: by 2002:a62:2983:0:b0:54e:7cd5:adb3 with SMTP id p125-20020a622983000000b0054e7cd5adb3mr16538054pfp.38.1663772236909; Wed, 21 Sep 2022 07:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663772236; cv=none; d=google.com; s=arc-20160816; b=1ItOuLdPkIaLBo+5VlDPMvwhXT7ng0wjUeyIcKtGoveDZmyLoL88hR5FMfg6Muo2Df xMlSe+QUahWkBHpNxKtc3m6rrr0rQmApjO09ysWr45Fo4GFosgdQJwIe4LOeriQgYlB+ EtotBI1zgsvgDcTTtAk2gOSfxZnutj6PIAylHpW/OAc2mwsWMQPfs5idNrJ86eECoEEc EkNFWSTBDvYQMmnRMcIjvicGKBKpBZTuaObv9Ml+KMPldtPbgNBRqQvK8y+HMQbQqGqX PPqnA6J7RxfOn7ZyxDZG3vIFFfvoZCh1qvHR9fMy0yluxMUAtFmomxQ+k21nRMfPvfEW ifHg== 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=PACrZt6ShUOftXa5BhwTJ+GCKCA0lbatSJR5ylEAxPo=; b=aisLWnxEFcytUAb+gGqo8kRV0AtnH5zeU1SU+IsXBuo9m4dJCry39+R2kQm4ThR18X QvolzfZtq4zL6HveINtqOSlsaLLSn+KaCzmsGok//KM4WyDpzNbaI6E1swgnpjKNHX/7 RkOlLiVgNzsx87Lunz6F0+nJBBk0f+zrS1301puA7ZBTcxvOeYyeEowJV8u+BvhDKAep r8yvlVUVxw9bgY1SEFX1RbHON2RXP2NuwRmHkrZZkEJHkwiHm5/YoW9FT8bxAhaGw73L H0TNLTADGfJrANTgJEleW7jUUmxA4Lb3mja5YmQEEqUSC2pjVIOBsHKYPhrr+9cz/R/A jzAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DoiETaFS; 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 ba1-20020a170902720100b00177e7e14f66si2599087plb.624.2022.09.21.07.57.05; Wed, 21 Sep 2022 07:57:16 -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=DoiETaFS; 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 S230292AbiIUOz5 (ORCPT + 99 others); Wed, 21 Sep 2022 10:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230335AbiIUOzJ (ORCPT ); Wed, 21 Sep 2022 10:55:09 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 919D92F38D; Wed, 21 Sep 2022 07:54:56 -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 ams.source.kernel.org (Postfix) with ESMTPS id 305FEB83016; Wed, 21 Sep 2022 14:54:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D1DFC433B5; Wed, 21 Sep 2022 14:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663772093; bh=XGOv1f+E6PQRclir8TXJx9cDwDQezaGlv4nQIiVk7vs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DoiETaFSwfGSaAXMxwffH9Xxis1cYu8jMM3VSD21rYwOLkhCRBMoYjSw2kp0yhmTQ UOAN0EvbOIyq1GEl7hhUal2Hh+a8ZsAWF05by41gbMyiMNZAiQqInwNVRFNnrLFXCA 8/7G93J73LxoZRLJg5JATSgGLp+FnGHYzI/9k6bfF0CXWzx78I3RcnoUUurEhlb9Me 4lL7QXASEZfIwX0TlSOCotK1NGVpiBLnyy4ujKyJXfZ/SAz1r0KrlszTGsidNux/4H CXa4q/lVPBnkH0AlIvPjGHyX0yslxu9apw6rCYtWhHPXK4MCmk8gs57asm3lSu+/FD 3fQy6FGrXKSxw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth Subject: [PATCH v2 11/16] x86/compressed: move startup32_load_idt() into .text section Date: Wed, 21 Sep 2022 16:54:17 +0200 Message-Id: <20220921145422.437618-12-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220921145422.437618-1-ardb@kernel.org> References: <20220921145422.437618-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2494; i=ardb@kernel.org; h=from:subject; bh=XGOv1f+E6PQRclir8TXJx9cDwDQezaGlv4nQIiVk7vs=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjKyWVnp/7Hjms7eUQhcYnrLlxJDyZ+gJO3OZu8xtm WwvUe0CJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYysllQAKCRDDTyI5ktmPJLTvC/ 98A6Cxj06piaelMbbPTO924O3aPixByu15CpFLSTm7st2dVCjR6M+XbGBmbC5FhFk0q7WJqohOcn3B 3Kuv1sUyabIe/lXHlUHiIXa9bBwoH8JtoHPN/qlvpk+wKbr36pruah0bvNkSVz5632Ozd3y91qZay5 iQJ9UZ3h+KDlxpFfggar3TXgltclQmzZlSWnkDye7SglY0W5lVf2pnWuhSC5+XnylBnetQB4QQsf3S tnDYnIgVEFnLQ7pcyfmlJKffAJR7nGTNN3BdrN/gpTSuMP2AbIDDADLgrALU7aDRn4kj8QfiXZ98TV JsnMZMQvlm7v9F745bYlgnSPtyANaeQnbkiDG14XJqWt59runSYtM8BdsiVHG5tpy75zjztt966l+H kyuI18QVhXYXkj9fyzVC4FuKT1GQycCGHpLKm1wEglU75FhyKuv4n4UYehue15SSRCQL9ab0e0xf+L 9z7BtNYmaWy1TSnM0c64NQTtcAAk0MPUtgsAfkRMA+W0Y= 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 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 Convert startup32_load_idt() into an ordinary function and move it into the .text section. This involves turning the rva() immediates into ones derived from a local label, and preserving/restoring the %ebp and %ebx as per the calling convention. Also move the #ifdef to the only existing call site. This makes it clear that the function call does nothing if support for memory encryption is not compiled in. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 29 ++++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index a1f893dd5bbf..b4b2b76ed1af 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -118,7 +118,9 @@ SYM_FUNC_START(startup_32) 1: /* Setup Exception handling for SEV-ES */ +#ifdef CONFIG_AMD_MEM_ENCRYPT call startup32_load_idt +#endif /* Make sure cpu supports long mode. */ call verify_cpu @@ -719,7 +721,7 @@ SYM_DATA_END_LABEL(boot32_idt, SYM_L_GLOBAL, boot32_idt_end) #endif #ifdef CONFIG_AMD_MEM_ENCRYPT - __HEAD + .text .code32 /* * Write an IDT entry into boot32_idt @@ -752,24 +754,32 @@ SYM_FUNC_START_LOCAL(startup32_set_idt_entry) RET SYM_FUNC_END(startup32_set_idt_entry) -#endif SYM_FUNC_START(startup32_load_idt) -#ifdef CONFIG_AMD_MEM_ENCRYPT - leal rva(boot32_idt)(%ebp), %ecx + push %ebp + push %ebx + + call 1f +1: pop %ebp + + leal (boot32_idt - 1b)(%ebp), %ebx /* #VC handler */ - leal rva(startup32_vc_handler)(%ebp), %eax + leal (startup32_vc_handler - 1b)(%ebp), %eax movl $X86_TRAP_VC, %edx + movl %ebx, %ecx call startup32_set_idt_entry /* Load IDT */ - leal rva(boot32_idt)(%ebp), %eax - movl %eax, rva(boot32_idt_desc+2)(%ebp) - lidt rva(boot32_idt_desc)(%ebp) -#endif + leal (boot32_idt_desc - 1b)(%ebp), %ecx + movl %ebx, 2(%ecx) + lidt (%ecx) + + pop %ebx + pop %ebp RET SYM_FUNC_END(startup32_load_idt) +#endif /* * Check for the correct C-bit position when the startup_32 boot-path is used. @@ -788,6 +798,7 @@ SYM_FUNC_END(startup32_load_idt) * succeed. An incorrect C-bit position will map all memory unencrypted, so that * the compare will use the encrypted random data and fail. */ + __HEAD SYM_FUNC_START(startup32_check_sev_cbit) #ifdef CONFIG_AMD_MEM_ENCRYPT pushl %eax -- 2.35.1