X-Received: by 2002:a17:90a:ae14:b0:1bc:c078:e02 with SMTP id t20-20020a17090aae1400b001bcc0780e02mr4110320pjq.167.1645721039078; Thu, 24 Feb 2022 08:43:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645721039; cv=none; d=google.com; s=arc-20160816; b=D453TPxxefPIoZQ8Vy3T7yjcV6ld8nG+Arg4i7yzILgwkGhHezQVku9ZtwtmniMgWD GlR4Py2zi1JI27WN/k5pNBdUNpO/yOitnYVbzst5tjAsrc30rSc33VP8b3oSwOzN/u0W dcd88IMDJ+VQXNdHvEk/TSQoHacW4e3MewM/1BIyJWU2Ovrrzlb72OkYTnLrjjpiUOxO Y8tRl+PyfTJu9vOz5k/vG+HqSHcaOTFMRDrL0iIsX0Q7axSFa9ZdFKHb68tvki5G07Ev 8qo512bht+yx6BTNa1Cu5dSYBfmHNDpxwGThp1QblcH3aJEZ2FR/+ecbfDcx9xo9TDv1 3lkw== 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=vs4VQ6uROoQiCSAYIodwjl/RJiTnw1qhNA8QlVAy9Zw=; b=IxQWCntMKuZ1kc23nzPC+R5cpWSkXgtkcsN6TDGcc7uvv2KBJt94+zkwjfX+I6SBXQ Pd4PlyqUmJsZu79DH/B15/TmQxy3sYP3O6kc6AkylXqoKEjFna3i08a70BresmSrwfOS 7B9VVd4sxXBCwyF0PRY9ooUZx69WpHIJb9rWeb29TbGoGPidZ2cYPRKaRTCDLqN/FOIp OprIxRnlyfIlNSpMvyf84Wx5ihw/Ry7ZymBcBUdLRpK9CK4LaCk4xsCcL+kPG+5r93PA Wb7kge3RezHPCgY+qC+rEYqyngRaZeuuE3SSVcaz9Qec1Kki7PT+cJRg3XccrVQphApZ nA1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WAKMSrUh; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id y192si2714043pgd.172.2022.02.24.08.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 08:43:59 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WAKMSrUh; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 7FD691D0D73; Thu, 24 Feb 2022 08:23:24 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234199AbiBXP60 (ORCPT + 99 others); Thu, 24 Feb 2022 10:58:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236755AbiBXP5Q (ORCPT ); Thu, 24 Feb 2022 10:57:16 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19A2722BD2 for ; Thu, 24 Feb 2022 07:56:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645718201; x=1677254201; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SwPKQO76m89JoirDvi2nnnrqzpm+q2wRGmsqNDkdK+4=; b=WAKMSrUhdXMwnmQuxKHDNT9Pok13nObHvgDoQml9W+2Cf0RJBWRNPFx7 opd4m2kXhDmGi79ttJ0nwRaMccFPDgyT9rq0+BK+VC1nRMjWyGRGCNU6A VinLkOV6MbDZi9nma6s/M8JXJJpWDEgRn77qqjbbMtCJLPKxIiWZ3U+G4 FEPmy2EK+kJTyT69XK90/3RZsLKnZhq/GiGP+yN38xrIxeK/BYuOcyJQv zhndTWjI/xuufq9z5kAD0QUFwly2rWKiN8BA33mELuRaFYMNMXq6itL26 iCXe+n5gJoFkl3DT3UwP82bpqOct5G0hbQ81aj6XCVSe1ouC17rHx6+mz Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="232241507" X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="232241507" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2022 07:56:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="707500703" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 24 Feb 2022 07:56:32 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 1D16CABE; Thu, 24 Feb 2022 17:56:35 +0200 (EET) 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" Subject: [PATCHv4 18/30] x86/tdx: Handle early boot port I/O Date: Thu, 24 Feb 2022 18:56:18 +0300 Message-Id: <20220224155630.52734-19-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220224155630.52734-1-kirill.shutemov@linux.intel.com> References: <20220224155630.52734-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). Signed-off-by: Andi Kleen Reviewed-by: Dan Williams Signed-off-by: Kuppuswamy Sathyanarayanan Signed-off-by: Kirill A. Shutemov Reviewed-by: Thomas Gleixner --- arch/x86/coco/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.c b/arch/x86/coco/tdx.c index 2e342760b1d2..0d2a4c947a6c 100644 --- a/arch/x86/coco/tdx.c +++ b/arch/x86/coco/tdx.c @@ -344,6 +344,22 @@ static bool handle_io(struct pt_regs *regs, u32 exit_qual) return ret; } +/* + * 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 54803cb6ccf5..ba0f8c2b185c 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -56,11 +56,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.34.1