Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp996028pxb; Wed, 6 Apr 2022 06:18:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaDUIuNB8EM6n99CfGPEqnfIMv5wYUudpbohIYU9MySTEyxHyBcDMfO7/HUPwFUbra9MH8 X-Received: by 2002:a05:6a00:1f08:b0:4fa:8a47:cf35 with SMTP id be8-20020a056a001f0800b004fa8a47cf35mr8811425pfb.22.1649251098761; Wed, 06 Apr 2022 06:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649251098; cv=none; d=google.com; s=arc-20160816; b=z6s0UZPQM1Cfql++b62fMY0c2B7jfB3AiITJWrHy/MQAPfyPUtcKSBluBpbQ+PxvcW ysZqeAZUMtFpBbqFaofwMv1RNWJEsZ55/r56rpDQg8OIpaC2JLbm8NbZKj9HIwWs+T+N t2uFi3RIKVko0FlPBtSYe+6cW3aVMbeHakdtpI79zXZAO2KW4BUTeOQUoEWLSC1qW/fr 7ZF1GmuZ6ir+hTtNv1Pav1otirTAmGTB+tz9XN5ub9bxJtoFp0nJ56gF0KP7k8cUH9zz MQGDJ08E72PosfdG7XMgn7eqybwC5tAjgskAhmC+olm5wHbk5zNaeOaM3pL8Comv8vBX sY8w== 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=CG1QKmW2IIKF6nEmFuh9GtRniNKZ3zLUsUpv+PjxNAs=; b=ue4yVc0pQv+VJcrHeIR5Rht9IHQyeW6fudIZ3B2Z5Eq3b6hQq6Kd+CAEij5IQfAFZG RTlP3r5O0U7yTXotYiIBbBC+8mf7R7zLTR1jDc/LI/dhc4vYcN7nlk0OFIMqejzsiC/+ aAQEU2QLJvX3onRFjpXwT2YiRcll1LciyQCS9sy3bUvwRmdOz/wKD9zvdQJVn4IfCThy qxWcy9cGdbWO58QQEPPgzFpai+Y2HJqs2ammhdk0sMXUslKwIVNJeSvqy/dV7/zSoIrb iKhmuNcxWH603BFFqp2m1ZFEYLSoY6wt4saPtTfEcSDBQhaUceMtOfvTCZEBLN8th8F5 W8hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BNXkj0pX; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z6-20020a056a00240600b004fa3a8dff66si16281616pfh.29.2022.04.06.06.18.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:18:18 -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=@intel.com header.s=Intel header.b=BNXkj0pX; 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=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4A3C35149BD; Wed, 6 Apr 2022 03:54:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2359471AbiDFDOp (ORCPT + 99 others); Tue, 5 Apr 2022 23:14:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238358AbiDFCNb (ORCPT ); Tue, 5 Apr 2022 22:13:31 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47E3C1B254A for ; Tue, 5 Apr 2022 16:35:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649201716; x=1680737716; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QwTdFDQG+/3ER5tRS0Y6tai+Acbxq2W/0abbuIf6Yew=; b=BNXkj0pXJksRrmdl3oO8GbocfMnUpqcGHGISqmYVWphCrIFM/4M43nrs NT1nc4YAURsG2tf/zVQnV1pQPHGYwVmSn/ILh9FNUi4sPHHePtOaeBxkm S+NxCNMlGDX7rhpSuB0ISBSe/vUuCx6dEI3ivFyrqV1Ow+0G5d0Ur76a+ +cstk8NGgeDwKyPzc+DYrvqY2Rb7QZGUgAeZ9Prz05TK6K60ebYM+WF8J OX+0++JtKSvOrU2y+G/QSPDe6IhCif/MCejsQYORADPM/dvBmmXz8KYe/ 0v+1g9uQHU7InoqoaRoTmEQl7uITup/IzNKk4X4tb+rHptFJ7dHxaF2v1 A==; X-IronPort-AV: E=McAfee;i="6200,9189,10308"; a="240824212" X-IronPort-AV: E=Sophos;i="5.90,238,1643702400"; d="scan'208";a="240824212" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2022 16:34:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,238,1643702400"; d="scan'208";a="588136343" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 05 Apr 2022 16:34:48 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 6D057C13; Wed, 6 Apr 2022 02:29:46 +0300 (EEST) From: "Kirill A. Shutemov" To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org Cc: sathyanarayanan.kuppuswamy@linux.intel.com, aarcange@redhat.com, ak@linux.intel.com, dan.j.williams@intel.com, david@redhat.com, hpa@zytor.com, jgross@suse.com, jmattson@google.com, joro@8bytes.org, jpoimboe@redhat.com, knsathya@kernel.org, pbonzini@redhat.com, sdeep@vmware.com, seanjc@google.com, tony.luck@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, x86@kernel.org, linux-kernel@vger.kernel.org, "Kirill A . Shutemov" , Dave Hansen Subject: [PATCHv8 18/30] x86/tdx: Port I/O: add early boot support Date: Wed, 6 Apr 2022 02:29:27 +0300 Message-Id: <20220405232939.73860-19-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405232939.73860-1-kirill.shutemov@linux.intel.com> References: <20220405232939.73860-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 From: Andi Kleen 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 Reviewed-by: Dan Williams Signed-off-by: Kuppuswamy Sathyanarayanan Signed-off-by: Kirill A. Shutemov Reviewed-by: Thomas Gleixner Reviewed-by: Dave Hansen --- 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 e47e2ed6b03e..cc14b7c0c157 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 7944fd1ae07d..9ffd0d2e6e0f 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 6dff50c3edd6..ecbf50e5b8e0 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); } -- 2.35.1