From nobody Mon May 11 11:29:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58830C433F5 for ; Sat, 9 Apr 2022 01:28:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240487AbiDIBal (ORCPT ); Fri, 8 Apr 2022 21:30:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240324AbiDIBaW (ORCPT ); Fri, 8 Apr 2022 21:30:22 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AA1410BD0A; Fri, 8 Apr 2022 18:27:30 -0700 (PDT) Date: Sat, 09 Apr 2022 01:27:28 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1649467649; 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=kCcjSmxo3YaeeAGPfrAgLuD0UJT6dIGVWimYWW+7ZFU=; b=ZE6LLhsX31qCdb4Ers5MBwrQA12s3Hyse7svGnFy5qcrZ8wzh8fS0WL5/hIVpJ+QCIzxtq gTAOm0iHstmZeVtn7hRQEK9OOAOylUfUG+f+BFyTQhheuIEmMoS81UfL2K28i7Qu5coEcS IQt8IBiDdzwYChrB6uqew5BqXJLT5pdM6xb8+5xh20UwIue7j83P2Zu8IIlmybsrqM+A8b Ans1b4Tmit+qIH202kWCMqfpuX8Z8CpMy55YC/7lPutGmcbxODFf82reLfrz6IOa65R/4L YBBI56PnF1nuDVsKmn21W5Yc0caV8SWGjWjjdRiTKsFDBiXT5RQHurTEnba92w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1649467649; 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=kCcjSmxo3YaeeAGPfrAgLuD0UJT6dIGVWimYWW+7ZFU=; b=qfGANgzSxdAVzcOhScuZtNrEkjFpFfJ2kG6pRxKZBGCW+riIfbm8QNDmGxVwGdRfYbCn/W ZR723G0AOPkxc4BA== From: "tip-bot2 for Andi Kleen" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] x86/tdx: Port I/O: Add early boot support Cc: Andi Kleen , Kuppuswamy Sathyanarayanan , "Kirill A. Shutemov" , Dave Hansen , Dan Williams , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220405232939.73860-19-kirill.shutemov@linux.intel.com> References: <20220405232939.73860-19-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Message-ID: <164946764822.4207.7568332192437587606.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/tdx branch of tip: Commit-ID: 32e72854fa5fef6bc72e27c54f31897db9092acb Gitweb: https://git.kernel.org/tip/32e72854fa5fef6bc72e27c54f31897db= 9092acb Author: Andi Kleen AuthorDate: Wed, 06 Apr 2022 02:29:27 +03:00 Committer: Dave Hansen CommitterDate: Thu, 07 Apr 2022 08:27:52 -07:00 x86/tdx: Port I/O: Add early boot support TDX guests cannot do port I/O directly. The TDX module triggers a #VE exception to let the guest kernel emulate port I/O by converting them into TDCALLs to call the host. But before IDT handlers are set up, port I/O cannot be emulated using normal kernel #VE handlers. To support the #VE-based emulation during this boot window, add a minimal early #VE handler support in early exception handlers. This is similar to what AMD SEV does. This is mainly to support earlyprintk's serial driver, as well as potentially the VGA driver. The early handler only supports I/O-related #VE exceptions. Unhandled or failed exceptions will be handled via early_fixup_exceptions() (like normal exception failures). At runtime I/O-related #VE exceptions (along with other types) handled by virt_exception_kernel(). Signed-off-by: Andi Kleen Signed-off-by: Kuppuswamy Sathyanarayanan Signed-off-by: Kirill A. Shutemov Signed-off-by: Dave Hansen Reviewed-by: Dan Williams Reviewed-by: Thomas Gleixner Reviewed-by: Dave Hansen Link: https://lkml.kernel.org/r/20220405232939.73860-19-kirill.shutemov@lin= ux.intel.com --- arch/x86/coco/tdx/tdx.c | 16 ++++++++++++++++ arch/x86/include/asm/tdx.h | 4 ++++ arch/x86/kernel/head64.c | 3 +++ 3 files changed, 23 insertions(+) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index e47e2ed..cc14b7c 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -418,6 +418,22 @@ static bool handle_io(struct pt_regs *regs, u32 exit_q= ual) return handle_out(regs, size, port); } =20 +/* + * Early #VE exception handler. Only handles a subset of port I/O. + * Intended only for earlyprintk. If failed, return false. + */ +__init bool tdx_early_handle_ve(struct pt_regs *regs) +{ + struct ve_info ve; + + tdx_get_ve_info(&ve); + + if (ve.exit_reason !=3D EXIT_REASON_IO_INSTRUCTION) + return false; + + return handle_io(regs, ve.exit_qual); +} + void tdx_get_ve_info(struct ve_info *ve) { struct tdx_module_output out; diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 7944fd1..9ffd0d2 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -65,11 +65,15 @@ bool tdx_handle_virt_exception(struct pt_regs *regs, st= ruct ve_info *ve); =20 void tdx_safe_halt(void); =20 +bool tdx_early_handle_ve(struct pt_regs *regs); + #else =20 static inline void tdx_early_init(void) { }; static inline void tdx_safe_halt(void) { }; =20 +static inline bool tdx_early_handle_ve(struct pt_regs *regs) { return fals= e; } + #endif /* CONFIG_INTEL_TDX_GUEST */ =20 #endif /* !__ASSEMBLY__ */ diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 6dff50c..ecbf50e 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -417,6 +417,9 @@ void __init do_early_exception(struct pt_regs *regs, in= t trapnr) trapnr =3D=3D X86_TRAP_VC && handle_vc_boot_ghcb(regs)) return; =20 + if (trapnr =3D=3D X86_TRAP_VE && tdx_early_handle_ve(regs)) + return; + early_fixup_exception(regs, trapnr); }