From patchwork Tue Mar 1 10:53:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12764609 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD13FC433EF for ; Tue, 1 Mar 2022 10:59:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zoCjPL6pqSuWxOOCLa1Mn92gopAJC6K594HyGmaRLuY=; b=TSrXjkttq286BX yPrCNOAjKWqLnrcYxj/yc7WGoLieN0oXSaKGq1OKcVMWt9nf3Lm2hn35pOfNBAvL6oBJ5Gwp6ErQ3 Y8YPmEf2jxfhZ30GJLEdkDk6rPmkNQXVdWOLairEYItNxjl2EUO4Yd4FiqoasaUTmRAfRU+uGroGn 1DZQRMGUFJJMOTMei3nCMj8Jm0ll2EEQab/2KDmPpjAErVXNhbadAITyFI+EG/U3e8cGMD9NWCyC7 UdvDQZj/mCfxCfFmoecWgSV/uSb6DyDtqe4GOPeTl9zrw3l7HK2Nze6/ICWe8Gwz/IsaxHSH1Qjuo G6IxKfgGQjyH0aluGC9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nP0DZ-00GGUv-Pi; Tue, 01 Mar 2022 10:58:57 +0000 Received: from [2.53.44.23] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nP08W-00GDBz-Fe; Tue, 01 Mar 2022 10:53:45 +0000 From: Christoph Hellwig To: iommu@lists.linux-foundation.org Cc: x86@kernel.org, Anshuman Khandual , Tom Lendacky , Konrad Rzeszutek Wilk , Stefano Stabellini , Boris Ostrovsky , Juergen Gross , Joerg Roedel , David Woodhouse , Lu Baolu , Robin Murphy , linux-arm-kernel@lists.infradead.org, xen-devel@lists.xenproject.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-hyperv@vger.kernel.org, tboot-devel@lists.sourceforge.net, linux-pci@vger.kernel.org Subject: [PATCH 08/12] x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled Date: Tue, 1 Mar 2022 12:53:07 +0200 Message-Id: <20220301105311.885699-9-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220301105311.885699-1-hch@lst.de> References: <20220301105311.885699-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Move enabling SWIOTLB_FORCE for guest memory encryption into common code. Signed-off-by: Christoph Hellwig --- arch/x86/kernel/cpu/mshyperv.c | 8 -------- arch/x86/kernel/pci-dma.c | 7 +++++++ arch/x86/mm/mem_encrypt_amd.c | 3 --- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 5a99f993e6392..568274917f1cd 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -336,14 +336,6 @@ static void __init ms_hyperv_init_platform(void) swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary; #endif } - -#ifdef CONFIG_SWIOTLB - /* - * Enable swiotlb force mode in Isolation VM to - * use swiotlb bounce buffer for dma transaction. - */ - swiotlb_force = SWIOTLB_FORCE; -#endif } if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) { diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index 2ac0ef9c2fb76..7ab7002758396 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c @@ -53,6 +53,13 @@ static void __init pci_swiotlb_detect(void) if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) x86_swiotlb_enable = true; + /* + * Guest with guest memory encryption must always do I/O through a + * bounce buffer as the hypervisor can't access arbitrary VM memory. + */ + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) + swiotlb_force = SWIOTLB_FORCE; + if (swiotlb_force == SWIOTLB_FORCE) x86_swiotlb_enable = true; } diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index 2b2d018ea3450..a72942d569cf9 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -191,9 +191,6 @@ void __init sme_early_init(void) /* Update the protection map with memory encryption mask */ for (i = 0; i < ARRAY_SIZE(protection_map); i++) protection_map[i] = pgprot_encrypted(protection_map[i]); - - if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) - swiotlb_force = SWIOTLB_FORCE; } void __init sev_setup_arch(void)