Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp5444770rwb; Wed, 21 Sep 2022 07:57:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6RJmURYFtddN8IlgUmIG0iUKXjmtOL0yyUIvGOHPKE/Za64H/CdFa//aR95ia7HAe+AZLj X-Received: by 2002:a63:b4f:0:b0:439:cc64:50e6 with SMTP id a15-20020a630b4f000000b00439cc6450e6mr20356568pgl.483.1663772264140; Wed, 21 Sep 2022 07:57:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663772264; cv=none; d=google.com; s=arc-20160816; b=I6LQaW0dp3fj/smlFQyqHjgA3rnKdBbaJIGQmMgKlBa5Ld+Gh7v0gkC6Lrah6+q+16 Cv8mQ6RVEhp+Irz9QmCM8NQym0HgpxiF5W/N4hmPDqr8RhA5ByZUTJ8iH38dpmE2jyJv rAKyf2Uy9kSrhZTaswOFYbYv8FQZmySLf6YeHYiGP8COy1cNQPqES7yoZgkbdkszDGKy IVShcT/fNqC94InO5MyzUXv1SIUDZ7nTwfbp3grZVFq5zu7cEoE/JoWB7A1ZZ9i0TBB3 pVy32Hys+DM0yzRmRdGBFWicYAzZZ+oCK/wuW8S/uwh5Ga7pEV9OQtu9UphRKDxv+rrK 3p3w== 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=GnejxdElJ6yOIAVqh1oRGqrSBYp2mHawBLNOGWGfTHk=; b=mAs0lHEsIn/pRxNGUhY4AyC3Xhs8MM/QTI22F3nYEO6y4gqBi0F6ygeatfs9onxi+Y /ypquBEw6HCIEb6oSXc7hptrdcAjPeH3SK6oo57PNicLwsvfb9SzVM0a5o2K1o2uSeYE gGXXMqjQqWtMl8mKfOi7ryPWWez/SWBDgLSV9TrdrEKaaNFggb50xRjW18QLKiBpQVff 98mWjmQJ5hRxJ4A6oPIXbnS9PsPb7/f7p9F/vQYy2SEWoSi3yvaRlnEwv8QIgMO6vIvP 3BmHA5QU4DEj5JsLtPGXhFgwhSZGsuFDONgwglmXW67wQeJSmLwKOuy5BVEypRobbi/i fKeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=quVsnzRL; 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 q12-20020a056a00150c00b0052e3c38bcf9si3355209pfu.223.2022.09.21.07.57.32; Wed, 21 Sep 2022 07:57:44 -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=quVsnzRL; 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 S230236AbiIUO4F (ORCPT + 99 others); Wed, 21 Sep 2022 10:56:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230340AbiIUOzL (ORCPT ); Wed, 21 Sep 2022 10:55:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E38E836879; Wed, 21 Sep 2022 07:54:58 -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 71A7DB83032; Wed, 21 Sep 2022 14:54:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62DE7C433D6; Wed, 21 Sep 2022 14:54:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663772096; bh=nlSUhbGA0ylsVYAt77oav3fesjwMW7rDea8nZZxp6aA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=quVsnzRLyj9UipR5MACVwJzqUP03IWwXX5bo0ZlYa+ordoXKGVnhA06Pad2Yz07+6 mUk8Guu6/36opXySWRZ9eaKEtn1JUvoMHQV2rxhXOVfPqV8RJePcf//5ONP4HI2kso uI/pyPkfzktG3CDd4GtkjEf5hnI5Z6AxrIsYU+AUp+MkwqVeWK9430U+2ppI75o6mt GC3VOaOydX/tb87Srcn3H/w+2/v2c3Aoi0jH8qxj9vQICQ0AAcAorBhMyvdF5y9Vg3 iM5i/RWaqybmRjbe7CHyYB526FYdKCJqTfXHb6JANFMNgAGJvOo8Qkz6BoI0Is1NV1 61+k7PaYuuQAQ== 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 12/16] x86/compressed: move startup32_load_idt() out of head_64.S Date: Wed, 21 Sep 2022 16:54:18 +0200 Message-Id: <20220921145422.437618-13-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=4991; i=ardb@kernel.org; h=from:subject; bh=nlSUhbGA0ylsVYAt77oav3fesjwMW7rDea8nZZxp6aA=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjKyWXnT+thXk9WFAYzVZ5ocJoz5PcVuJHGitoDGwK HFoMHGCJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYysllwAKCRDDTyI5ktmPJIl/DA Cp2FqDmbmvyiQDd9MYzjBjQZ+P2LJxT2a6EOoIg1IB6VDrHhN9nF6nQm/8flEZIfPYTucjSPhMd1ll ieYowd0QfXV6HC1CUF9d4SY+wUaPLj9ZxgGpAeIrFfFWGouzrp0zKSwjCKBpQDymm4P1zySNrSdmYh Sck3Vyeu3Myo8rOkVQ4CiSMzm6Tx2GUAqyuRK2zoyxU0Ybq9nq2uXA9ynAyoBXBr3Ov+hy6u2N6NIZ r0TU7BQWAODxeHZGt3tInOIQ9n7Z4vhcpI6oUWnNeTuLmgGBO/z0bZnbeG1t50o4DitvO3j91Z6KtG miB2iXdMBz9oYWEh1DfW0w/xm3UepnDsFzQ96hfdaJ8eKk/k1zI41FlAMcDWnwy1pag94/6QdJpcn4 R+3w+r2MBwk3hrG55xbPHkS/OO7fL3m90oPuhAODw+n07+3BYGBpI12NS0OLzJNJyCnz6ZSwcfSn/7 RgpHPLpsgoim4Bv8y7H2NZZzJUE0k5cnp2zbgEbZFoxuk= 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 Now that startup32_load_idt() has been refactored into an ordinary callable function, move it into mem-encrypt.S where it belongs. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_64.S | 74 -------------------- arch/x86/boot/compressed/mem_encrypt.S | 72 ++++++++++++++++++- 2 files changed, 71 insertions(+), 75 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index b4b2b76ed1af..abb5a650a816 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -707,80 +707,6 @@ SYM_DATA_START(boot_idt) .endr SYM_DATA_END_LABEL(boot_idt, SYM_L_GLOBAL, boot_idt_end) -#ifdef CONFIG_AMD_MEM_ENCRYPT -SYM_DATA_START(boot32_idt_desc) - .word boot32_idt_end - boot32_idt - 1 - .long 0 -SYM_DATA_END(boot32_idt_desc) - .balign 8 -SYM_DATA_START(boot32_idt) - .rept 32 - .quad 0 - .endr -SYM_DATA_END_LABEL(boot32_idt, SYM_L_GLOBAL, boot32_idt_end) -#endif - -#ifdef CONFIG_AMD_MEM_ENCRYPT - .text - .code32 -/* - * Write an IDT entry into boot32_idt - * - * Parameters: - * - * %eax: Handler address - * %edx: Vector number - * %ecx: IDT address - */ -SYM_FUNC_START_LOCAL(startup32_set_idt_entry) - /* IDT entry address to %ecx */ - leal (%ecx, %edx, 8), %ecx - - /* Build IDT entry, lower 4 bytes */ - movl %eax, %edx - andl $0x0000ffff, %edx # Target code segment offset [15:0] - orl $(__KERNEL32_CS << 16), %edx # Target code segment selector - - /* Store lower 4 bytes to IDT */ - movl %edx, (%ecx) - - /* Build IDT entry, upper 4 bytes */ - movl %eax, %edx - andl $0xffff0000, %edx # Target code segment offset [31:16] - orl $0x00008e00, %edx # Present, Type 32-bit Interrupt Gate - - /* Store upper 4 bytes to IDT */ - movl %edx, 4(%ecx) - - RET -SYM_FUNC_END(startup32_set_idt_entry) - -SYM_FUNC_START(startup32_load_idt) - push %ebp - push %ebx - - call 1f -1: pop %ebp - - leal (boot32_idt - 1b)(%ebp), %ebx - - /* #VC handler */ - leal (startup32_vc_handler - 1b)(%ebp), %eax - movl $X86_TRAP_VC, %edx - movl %ebx, %ecx - call startup32_set_idt_entry - - /* Load IDT */ - 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. * diff --git a/arch/x86/boot/compressed/mem_encrypt.S b/arch/x86/boot/compressed/mem_encrypt.S index a73e4d783cae..6747e5e4c696 100644 --- a/arch/x86/boot/compressed/mem_encrypt.S +++ b/arch/x86/boot/compressed/mem_encrypt.S @@ -12,6 +12,8 @@ #include #include #include +#include +#include .text .code32 @@ -98,7 +100,7 @@ SYM_CODE_START_LOCAL(sev_es_req_cpuid) jmp 1b SYM_CODE_END(sev_es_req_cpuid) -SYM_CODE_START(startup32_vc_handler) +SYM_CODE_START_LOCAL(startup32_vc_handler) pushl %eax pushl %ebx pushl %ecx @@ -184,6 +186,63 @@ SYM_CODE_START(startup32_vc_handler) jmp .Lfail SYM_CODE_END(startup32_vc_handler) +/* + * Write an IDT entry into boot32_idt + * + * Parameters: + * + * %eax: Handler address + * %edx: Vector number + * %ecx: IDT address + */ +SYM_FUNC_START_LOCAL(startup32_set_idt_entry) + /* IDT entry address to %ecx */ + leal (%ecx, %edx, 8), %ecx + + /* Build IDT entry, lower 4 bytes */ + movl %eax, %edx + andl $0x0000ffff, %edx # Target code segment offset [15:0] + orl $(__KERNEL32_CS << 16), %edx # Target code segment selector + + /* Store lower 4 bytes to IDT */ + movl %edx, (%ecx) + + /* Build IDT entry, upper 4 bytes */ + movl %eax, %edx + andl $0xffff0000, %edx # Target code segment offset [31:16] + orl $0x00008e00, %edx # Present, Type 32-bit Interrupt Gate + + /* Store upper 4 bytes to IDT */ + movl %edx, 4(%ecx) + + RET +SYM_FUNC_END(startup32_set_idt_entry) + +SYM_FUNC_START(startup32_load_idt) + push %ebp + push %ebx + + call 1f +1: pop %ebp + + leal (boot32_idt - 1b)(%ebp), %ebx + + /* #VC handler */ + leal (startup32_vc_handler - 1b)(%ebp), %eax + movl $X86_TRAP_VC, %edx + movl %ebx, %ecx + call startup32_set_idt_entry + + /* Load IDT */ + leal (boot32_idt_desc - 1b)(%ebp), %ecx + movl %ebx, 2(%ecx) + lidt (%ecx) + + pop %ebx + pop %ebp + RET +SYM_FUNC_END(startup32_load_idt) + .code64 #include "../../kernel/sev_verify_cbit.S" @@ -195,4 +254,15 @@ SYM_CODE_END(startup32_vc_handler) SYM_DATA(sme_me_mask, .quad 0) SYM_DATA(sev_status, .quad 0) SYM_DATA(sev_check_data, .quad 0) + +SYM_DATA_START_LOCAL(boot32_idt) + .rept 32 + .quad 0 + .endr +SYM_DATA_END(boot32_idt) + +SYM_DATA_START_LOCAL(boot32_idt_desc) + .word . - boot32_idt - 1 + .long 0 +SYM_DATA_END(boot32_idt_desc) #endif -- 2.35.1