Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1752009pxm; Thu, 24 Feb 2022 08:42:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3IPdrJd4phmkw0yYjqiJOh7QTifH+mWlX4eophtJguofj0XL0/mAM4c6NWOy+vooy/9qA X-Received: by 2002:a63:e34a:0:b0:375:7489:1c63 with SMTP id o10-20020a63e34a000000b0037574891c63mr2893335pgj.526.1645720975842; Thu, 24 Feb 2022 08:42:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645720975; cv=none; d=google.com; s=arc-20160816; b=TTN1/5c8e5OLVaiN8I2IImRkwHSgNUY7Giat2RSycVgpYmqK3QDzGJvVlc80KaUoBE WtYMVgUy08KbLcpBsxBmDDn6PZc2PDBnGI2iv+BaEHWNhh11c04DnBKkexnrH+0gCC/4 jhENMZGwADhoRGbqXJi6G201/M9vwfUuIEctZ16YU5Vpp7tRItcdHhVz1jCDqXcPoFes CpXrrjKXCPzfDm6FC122Ft2JX3oglQ7fqs3U4hFXbCq8VMmx8UGYIjLRMpf+4hGhoOqn Kl65RCJW6F/6bNa9Zf+Ntp7l6paCSiIl5ijXogpy0UMPmy6Pf2CIC9WVwgyt9A1W4/le mi/A== 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=OoczlOPeRBOk7zvBzzquVy4dZRLkm8M7qnXPuLNrKVM=; b=HFm9Eg2/No3gNVLkhcVvjaEOMHj1CnDv3lcKvu6Ceg+9lKqruKVFdrdLru+1uu0Cu+ 0nTgxIVHmJYO3NjbljQsh4k87+O67aqqhWaMfGkDLIIUBxWyZNHFL677ZjcTwxCPVdSt MPjiZWalg5pYWzaGCBzq8mDQWePR+gLCuAFNS4ipjYuKpmoAfpAat6yPdGBYwr9bsZbM Toe23RL72bTR20apPIjXcf/e3W0lOfnjF4L3UDQbkuetd6wnQvvyFRHsV5CZ779P07DI tn6r4vWDqVrE5Pe0DKK64I1SFeoif1bMMJ2JunGN0qm7IPl9rEZCNIMA5gaHfMSuOghX 1ObQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="NMA/CIpR"; 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 bj8si3072465pgb.745.2022.02.24.08.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 08:42:55 -0800 (PST) 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="NMA/CIpR"; 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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4F001281984; Thu, 24 Feb 2022 08:22:35 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229503AbiBXP63 (ORCPT + 99 others); Thu, 24 Feb 2022 10:58:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236756AbiBXP5Q (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 34FBC2459A 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=XimhzMtjfzZRQ2oEagC60/R6lppXl0bYHqXI4i6UzHE=; b=NMA/CIpRvnQd4qbXKdNvwaTLFFD4+p8XSOxqjm9zxtOLW/xvSirD70W5 o9/pNueJuTgEUVcgyQrVsdP2rPZEtoNsKhW1m3dICsSJiGS0l4frjJt+y NiGEYPRZ72dR290hwbYoODEVrkWVNq4IHG0kXCnkM2E8stdbG1el9G8MK 2TDC5w+F3HHMnBe1fAJKaomNFQLNzQWX/FvjQ5uo89Uo+x+rSCFHtzfqN gSglJlSGHPQxoZY2Ubg4TZQpS/gGqWWcu5lEvgV4pCbeRUyHXvXoFGyrU p7KEdy8UEhVp7hQAZ8UCGeUVow0T2pqrm0IuBe84kF3J6V603ehPvk1KL w==; X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="232241514" X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="232241514" 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:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="707500705" 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 99C27BB6; 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 27/30] x86/kvm: Use bounce buffers for TD guest Date: Thu, 24 Feb 2022 18:56:27 +0300 Message-Id: <20220224155630.52734-28-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 Intel TDX doesn't allow VMM to directly access guest private memory. Any memory that is required for communication with the VMM must be shared explicitly. The same rule applies for any DMA to and from the TDX guest. All DMA pages have to be marked as shared pages. A generic way to achieve this without any changes to device drivers is to use the SWIOTLB framework. Force SWIOTLB on TD guest and make SWIOTLB buffer shared by generalizing mem_encrypt_init() to cover TDX. Co-developed-by: Kuppuswamy Sathyanarayanan Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Signed-off-by: Kirill A. Shutemov --- arch/x86/Kconfig | 2 +- arch/x86/coco/core.c | 1 + arch/x86/coco/tdx.c | 3 +++ arch/x86/mm/mem_encrypt.c | 9 ++++++++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 98efb35ed7b1..1312cefb927d 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -885,7 +885,7 @@ config INTEL_TDX_GUEST depends on X86_64 && CPU_SUP_INTEL depends on X86_X2APIC select ARCH_HAS_CC_PLATFORM - select DYNAMIC_PHYSICAL_MASK + select X86_MEM_ENCRYPT select X86_MCE help Support running as a guest under Intel TDX. Without this support, diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index 9778cf4c6901..b10326f91d4f 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -22,6 +22,7 @@ static bool intel_cc_platform_has(enum cc_attr attr) case CC_ATTR_GUEST_UNROLL_STRING_IO: case CC_ATTR_HOTPLUG_DISABLED: case CC_ATTR_GUEST_MEM_ENCRYPT: + case CC_ATTR_MEM_ENCRYPT: return true; default: return false; diff --git a/arch/x86/coco/tdx.c b/arch/x86/coco/tdx.c index da2ae399ea71..d33f65a58d7b 100644 --- a/arch/x86/coco/tdx.c +++ b/arch/x86/coco/tdx.c @@ -5,6 +5,7 @@ #define pr_fmt(fmt) "tdx: " fmt #include +#include #include #include #include @@ -587,5 +588,7 @@ void __init tdx_early_init(void) x86_platform.guest.enc_tlb_flush_required = tdx_tlb_flush_required; x86_platform.guest.enc_status_change_finish = tdx_enc_status_changed; + swiotlb_force = SWIOTLB_FORCE; + pr_info("Guest detected\n"); } diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 50d209939c66..10ee40b5204b 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -42,7 +42,14 @@ bool force_dma_unencrypted(struct device *dev) static void print_mem_encrypt_feature_info(void) { - pr_info("AMD Memory Encryption Features active:"); + pr_info("Memory Encryption Features active:"); + + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) { + pr_cont(" Intel TDX\n"); + return; + } + + pr_cont("AMD "); /* Secure Memory Encryption */ if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) { -- 2.34.1