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 5ED90C5321D for ; Mon, 26 Aug 2024 10:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vBHpjOb2AUkneCoqhWwXO+z0h2WhnqAsF/jUow9X1cM=; b=fdSUyqq7aYfHc5GSTgHNaU91TP N4uD4WpEvfde9GJDu4nnKrhSNtWug1Bvb6AHj7/rY6vcQb9OZr22/awCuVbSRJ+FfBj1JsNQM9xRW UVEWwXri3r2u1xuPeLq68IbXzaCiDmgynfUZCrjOERn36j2onNnt05L+iPeFOzE8a1/tYRxoJiNhS 4pJeww9Q5RYOu5LAi5LFPkpxNdxPVsnbWhwlsnPUqHd25AUF8IuJpJQDOe6/BzszwTk6rHYW/lHs8 TK9WyQH3EGPWJ4DwHawHdZUSaa6WboT3G6WfgSP/E1yz9/75GApElslp0fQ/KjhYCYa8JufEy1MJW z+v73ejQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1siX9B-00000006xuR-2bDq; Mon, 26 Aug 2024 10:40:29 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1siX8F-00000006xfN-2ap0 for linux-arm-kernel@lists.infradead.org; Mon, 26 Aug 2024 10:39:33 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 93BC1CE0B88; Mon, 26 Aug 2024 10:39:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 744F9C51401; Mon, 26 Aug 2024 10:39:24 +0000 (UTC) Date: Mon, 26 Aug 2024 13:39:32 +0300 From: Catalin Marinas To: Steven Price Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Gavin Shan , Shanker Donthineni , Alper Gun Subject: Re: [PATCH v5 14/19] arm64: Enforce bounce buffers for realm DMA Message-ID: References: <20240819131924.372366-1-steven.price@arm.com> <20240819131924.372366-15-steven.price@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240819131924.372366-15-steven.price@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240826_033932_027579_479F79DA X-CRM114-Status: GOOD ( 25.03 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Aug 19, 2024 at 02:19:19PM +0100, Steven Price wrote: > 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. > > This adds a call to swiotlb_update_mem_attributes() which calls > set_memory_decrypted() to ensure the bounce buffer memory is shared with > the host. For non-realm guests or hosts this is a no-op. > > Co-developed-by: Suzuki K Poulose > Signed-off-by: Suzuki K Poulose > Signed-off-by: Steven Price > --- > v3: Simplify mem_init() by using a 'flags' variable. > --- > arch/arm64/kernel/rsi.c | 1 + > arch/arm64/mm/init.c | 10 +++++++++- > 2 files changed, 10 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c > index 5c2c977a50fb..69d8d9791c65 100644 > --- a/arch/arm64/kernel/rsi.c > +++ b/arch/arm64/kernel/rsi.c > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > > #include > #include > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > index 9b5ab6818f7f..1d595b63da71 100644 > --- a/arch/arm64/mm/init.c > +++ b/arch/arm64/mm/init.c > @@ -41,6 +41,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -369,8 +370,14 @@ void __init bootmem_init(void) > */ > void __init mem_init(void) > { > + unsigned int flags = SWIOTLB_VERBOSE; > bool swiotlb = max_pfn > PFN_DOWN(arm64_dma_phys_limit); > > + if (is_realm_world()) { > + swiotlb = true; > + flags |= SWIOTLB_FORCE; > + } > + > if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb) { > /* > * If no bouncing needed for ZONE_DMA, reduce the swiotlb > @@ -382,7 +389,8 @@ void __init mem_init(void) > swiotlb = true; > } > > - swiotlb_init(swiotlb, SWIOTLB_VERBOSE); > + swiotlb_init(swiotlb, flags); > + swiotlb_update_mem_attributes(); IIRC Will mentioned on a previous version of this series: what do we do with the kmalloc() minalign bouncing (or other bouncing)? I think this would only work if the device is shared. I'm more and more inclined to only support shared devices with this series (no dev assignment) and make it a strict dependence on RMM 1.0. Running it in a different configuration with private devices will fall apart. With this condition, the patch looks fine: Reviewed-by: Catalin Marinas