Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp41984pxb; Tue, 12 Apr 2022 16:14:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgTwHRocCqXFs2meHHBHdB1TcA9zhniX7nB5h6CgQ+QWRhPJsag8mo06Fm/L6mn1ZyTDB5 X-Received: by 2002:a17:90b:35c3:b0:1cb:8768:9fe with SMTP id nb3-20020a17090b35c300b001cb876809femr7662077pjb.80.1649805271688; Tue, 12 Apr 2022 16:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649805271; cv=none; d=google.com; s=arc-20160816; b=miQNPqm9qElZvwLfFLalEQK/z7aOx8VhZnnObvTWeJm9nkM2hMrL+6gDotfz3Cm8rx Xs/Ycae2BfzjMB7nRnVqHje95x+YH8iSPDFypvGfVwBI/sn89iPHtiR0wqasP9ii6Tgz uINMf+JEH0Hww3fsKxmz9P7SLdVPuGmD81QpYspvOi/OmVILh+ZKUU56YCgCLo+x0ht/ z2wVQw2357Cv+i+n3JuAgBFXj94Y3GSr6zIe2XcOHFU7f3+2y5j0AdaiDpyors3BYVbk Fn9TmHBswDiSFheGRErXaleRMWKG7CSrsMxMAN3X88G8z7+8DQCiqkgG15mBE8wfpFyF NWOw== 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=kCcjSmxo3YaeeAGPfrAgLuD0UJT6dIGVWimYWW+7ZFU=; b=XdpAT0BbP6gg7VqrIQvNIkoziSRnmxdvZPWAoooTB6Yg0iSAby9kAQ95zL0beHUfxT 6f49ql74cBZoErKUEUbAdmpjNAWNdDfFdTTG1uFfUq8tjLosspxhXjifKMKS+F9J20Vn xR41hyV6DO1hLSG5FXdMVSEThWNYLoc9zIMivFAIFWzqqfqIqq/1C7chz2r8VrLBUYxi 0wNLy1vOW9itBjIqso5zybnZpMBSGU+4S2alInLEpK+QxwQ/PBKGmVlQesYAxuQDTc6h u/Qj0/f9yH2/vWdSPERTbKywsFPKq+ByYuL57234v8CziVCAS061lAFUSwkIQsT08zIg g52A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZE6LLhsX; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i16-20020a170902c95000b001584eaeee5fsi4991189pla.7.2022.04.12.16.14.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 16:14:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZE6LLhsX; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 07184214167; Tue, 12 Apr 2022 14:58:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240472AbiDIBaj (ORCPT + 99 others); Fri, 8 Apr 2022 21:30:39 -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: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 The following commit has been merged into the x86/tdx branch of tip: Commit-ID: 32e72854fa5fef6bc72e27c54f31897db9092acb Gitweb: https://git.kernel.org/tip/32e72854fa5fef6bc72e27c54f31897db9092acb 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@linux.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_qual) return handle_out(regs, size, port); } +/* + * 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 != 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, struct ve_info *ve); void tdx_safe_halt(void); +bool tdx_early_handle_ve(struct pt_regs *regs); + #else static inline void tdx_early_init(void) { }; static inline void tdx_safe_halt(void) { }; +static inline bool tdx_early_handle_ve(struct pt_regs *regs) { return false; } + #endif /* CONFIG_INTEL_TDX_GUEST */ #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, int trapnr) trapnr == X86_TRAP_VC && handle_vc_boot_ghcb(regs)) return; + if (trapnr == X86_TRAP_VE && tdx_early_handle_ve(regs)) + return; + early_fixup_exception(regs, trapnr); }