From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78EF928F7; Fri, 27 Jan 2023 11:28:35 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0D1D41682; Fri, 27 Jan 2023 03:29:17 -0800 (PST) Received: from e122027.cambridge.arm.com (e122027.cambridge.arm.com [10.1.35.16]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A49D33F64C; Fri, 27 Jan 2023 03:28:32 -0800 (PST) From: Steven Price To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: Steven Price , Catalin Marinas , Ard Biesheuvel , Marc Zyngier , Will Deacon , Suzuki K Poulose , James Morse , Oliver Upton , Zenghui Yu , linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev Subject: [RFC PATCH 09/14] arm64: Enforce bounce buffers for realm DMA Date: Fri, 27 Jan 2023 11:27:53 +0000 Message-Id: <20230127112758.37891-10-steven.price@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127112758.37891-1-steven.price@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127112758.37891-1-steven.price@arm.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Within a realm guest it's not possible for a device emulated by the VMM to access arbitrary guest memory. So force the use of bounce buffers to ensure that the memory the emulated devices are accessing is in memory which is explicitly shared with the host. Co-developed-by: Suzuki K Poulose Signed-off-by: Suzuki K Poulose Signed-off-by: Steven Price --- arch/arm64/kernel/rsi.c | 2 ++ arch/arm64/mm/init.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c index 49d36dfe0064..1a07eefdd2e9 100644 --- a/arch/arm64/kernel/rsi.c +++ b/arch/arm64/kernel/rsi.c @@ -5,6 +5,8 @@ #include #include +#include + #include struct realm_config __attribute((aligned(PAGE_SIZE))) config; diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index fa9088add624..32a4710ad861 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -472,7 +472,13 @@ void __init bootmem_init(void) */ void __init mem_init(void) { - swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE); + if (is_realm_world()) { + swiotlb_init(true, SWIOTLB_VERBOSE | SWIOTLB_FORCE); + swiotlb_update_mem_attributes(); + } else { + swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), + SWIOTLB_VERBOSE); + } /* this will put all unused low memory onto the freelists */ memblock_free_all(); -- 2.34.1 From mboxrd@z Thu Jan 1 00:00:00 1970 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 17811C54EAA for ; Fri, 27 Jan 2023 11:32:49 +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=1Qz2K77UW+pY8jCS7nsyZZ51VBSxMactMPGYeaOX2Xk=; b=KjTeXZlB8w1rIW OrPwLxgLeTJXdwHJ/DdLngFPHIjwLSFM4RiK845NlEMMSDqVLZroL9xHzv/79F6woq8Bs1YBC6YmV MseX8iPGs8rNXFVIx2GOUzfLS2z3WakyD5A3jDd0R+PB3XQwhbtOl7Il5uR/dQQsyM2Yn2TgeL2pW dSOwBKggs1sp/VnedpW4iBCIBoJcV4LwW4A3Or6CYzkHvFSNLfDQyg9lh9axsBT2yEOPNeGUAcmwS 4M1gW3Nnc+coyl3MkpBP/rttIbbrcrVg8yAEwrKTu8HGgcVOAZ6VMGEWg4nylCs6uYVbyJjam7/h5 BXSAgyusIUymM8sJYn5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLMxJ-00E8rQ-Kc; Fri, 27 Jan 2023 11:31:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLMuJ-00E7Id-N0 for linux-arm-kernel@lists.infradead.org; Fri, 27 Jan 2023 11:28:37 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0D1D41682; Fri, 27 Jan 2023 03:29:17 -0800 (PST) Received: from e122027.cambridge.arm.com (e122027.cambridge.arm.com [10.1.35.16]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A49D33F64C; Fri, 27 Jan 2023 03:28:32 -0800 (PST) From: Steven Price To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: Steven Price , Catalin Marinas , Ard Biesheuvel , Marc Zyngier , Will Deacon , Suzuki K Poulose , James Morse , Oliver Upton , Zenghui Yu , linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev Subject: [RFC PATCH 09/14] arm64: Enforce bounce buffers for realm DMA Date: Fri, 27 Jan 2023 11:27:53 +0000 Message-Id: <20230127112758.37891-10-steven.price@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127112758.37891-1-steven.price@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127112758.37891-1-steven.price@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230127_032835_852046_576FA116 X-CRM114-Status: GOOD ( 13.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Within a realm guest it's not possible for a device emulated by the VMM to access arbitrary guest memory. So force the use of bounce buffers to ensure that the memory the emulated devices are accessing is in memory which is explicitly shared with the host. Co-developed-by: Suzuki K Poulose Signed-off-by: Suzuki K Poulose Signed-off-by: Steven Price --- arch/arm64/kernel/rsi.c | 2 ++ arch/arm64/mm/init.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c index 49d36dfe0064..1a07eefdd2e9 100644 --- a/arch/arm64/kernel/rsi.c +++ b/arch/arm64/kernel/rsi.c @@ -5,6 +5,8 @@ #include #include +#include + #include struct realm_config __attribute((aligned(PAGE_SIZE))) config; diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index fa9088add624..32a4710ad861 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -472,7 +472,13 @@ void __init bootmem_init(void) */ void __init mem_init(void) { - swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE); + if (is_realm_world()) { + swiotlb_init(true, SWIOTLB_VERBOSE | SWIOTLB_FORCE); + swiotlb_update_mem_attributes(); + } else { + swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), + SWIOTLB_VERBOSE); + } /* this will put all unused low memory onto the freelists */ memblock_free_all(); -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel