From patchwork Thu Nov 24 08:12:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 25352 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3258456wrr; Thu, 24 Nov 2022 00:13:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf70fmuTwSnRGeXchIlddcL5endfKB1PTsD0eNBzELAYqx1aDirzcefn1Hysse/+lETgfQjz X-Received: by 2002:a17:903:26d5:b0:185:51cc:8001 with SMTP id jg21-20020a17090326d500b0018551cc8001mr16667417plb.0.1669277625604; Thu, 24 Nov 2022 00:13:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669277625; cv=none; d=google.com; s=arc-20160816; b=jdNFNu/Ikhnuwf/teJqElUiR8WYJ+vH+k9y+dOYDPPh1yikwpFsXepUGl/Jwz6sw78 768jr8xKap+ZKAFBE4sQZGXTU/gDZUnz/F2OBENARsiqBr2Rp8uv/RuY3QdxGyR5RJNj B4asJJAIHMCUwCn1ccNWJzLHsyZ1nm47jDTy4HccMVvvFdiiHZ3s+jbCUoSPKGjcJzUt pF6mh8Y9ExlqAauP9ENJyM2RawRdW5iQCk3CGfPr7z6fbgUW8zqkQKovIedqIdtT7dnU rznHibVRqOsMOxNqt3lhtKqDILWr8TILLEeYiGRI1UlY8t3awD0VnLVM2GcAf1qNPKiS nohA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=W16cV/kWP+fIThZjFFj2xjte2SU0THI5eEfHMeThfPU=; b=pEnYS8J3iuVnOrxFyRBySvMHFNUAWZZ6F3+nDeoX5wgpBoJosR6rXaJqJPxLzrFBgX O/Bklyt0UWvzySRjW6HGt7I8sMXQhL20kVjwtisoZEWM5hq+QI/GRfoLWQeXb+GadzO0 7OvRVMs3Jpe5jN6pJll/lLziWtfaL78TF1lApFhT5QPRKwr+89fd9SkHFlcRbqAOvztB BrM1uLuTj9KZ3WnaRmilDEFYxA30wD/8Tug7mZnEWhPXUUR0nr5ThHFgkF8QqfIOPNSA R40+pQNRy4AgYErNhid3tvF2uJYpBeD/YwW2fnH7FTfyTfjDQKgmME0Dar+pyGENYG+i eqoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="UJg/W4Ri"; dkim=neutral (no key) header.i=@linutronix.de header.b=6vfxFs+I; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d15-20020a056a0010cf00b0053b36138dc5si515215pfu.222.2022.11.24.00.13.31; Thu, 24 Nov 2022 00:13:45 -0800 (PST) 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=@linutronix.de header.s=2020 header.b="UJg/W4Ri"; dkim=neutral (no key) header.i=@linutronix.de header.b=6vfxFs+I; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbiKXINR (ORCPT + 99 others); Thu, 24 Nov 2022 03:13:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbiKXIMV (ORCPT ); Thu, 24 Nov 2022 03:12:21 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71890ED703; Thu, 24 Nov 2022 00:12:06 -0800 (PST) Date: Thu, 24 Nov 2022 08:12:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669277525; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W16cV/kWP+fIThZjFFj2xjte2SU0THI5eEfHMeThfPU=; b=UJg/W4Ri/pQ71LlFOhxIROpYq27QSB9gGSCrI1CmoZpCSJEBN6ksFWfMtEZkTKf5r8HZ89 3XmMgEqw3BfbxFG+OnuBhGRBAr+TN6pZ+RL1cu4Kw0ZOj7WM/t7pqv0QoljYjMuc7Vil5f q+ChGGTd4ReI2dE6DC+pyTpjqENnzPM1ZxKBggZOKEZmljF97qo4WsLHIlsysuPxoB5CCc mp1A18ePFv6gYqnqsjWOEKPeNPqkqhpIoQLik/k46vnnIwVdnmRpHZwbPCR1b184ZCtn7L 64PqFMwEPjkoCepoO9X1ex9MUPLvZB67w+zf5TlGa/qLE512idYR1q/7inm1NA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669277525; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W16cV/kWP+fIThZjFFj2xjte2SU0THI5eEfHMeThfPU=; b=6vfxFs+I9tMy6rsWZxVFRYbo7uxwNBL/9FFXyeisYOG8FAoHtj7PSwHx9/yxffu7xIcnxR EtL7wMCx1hQUnOCw== From: "tip-bot2 for Ard Biesheuvel" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/boot] x86/boot/compressed: Move startup32_load_idt() out of head_64.S Cc: Ard Biesheuvel , Borislav Petkov , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221122161017.2426828-13-ardb@kernel.org> References: <20221122161017.2426828-13-ardb@kernel.org> MIME-Version: 1.0 Message-ID: <166927752388.4906.4488084064477649114.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750364455459760444?= X-GMAIL-MSGID: =?utf-8?q?1750364455459760444?= The following commit has been merged into the x86/boot branch of tip: Commit-ID: 9ea813be3d345dfb8ac5bf6fbb29e6a63647a39d Gitweb: https://git.kernel.org/tip/9ea813be3d345dfb8ac5bf6fbb29e6a63647a39d Author: Ard Biesheuvel AuthorDate: Tue, 22 Nov 2022 17:10:12 +01:00 Committer: Borislav Petkov CommitterDate: Thu, 24 Nov 2022 08:57:41 +01:00 x86/boot/compressed: Move startup32_load_idt() out of head_64.S 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 Signed-off-by: Borislav Petkov Link: https://lore.kernel.org/r/20221122161017.2426828-13-ardb@kernel.org --- arch/x86/boot/compressed/head_64.S | 72 +------------------------- arch/x86/boot/compressed/mem_encrypt.S | 72 ++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 73 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 7aa147f..16cccc2 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -707,78 +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) - - .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 a73e4d7..6747e5e 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