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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E969C77B75 for ; Tue, 16 May 2023 06:13:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230014AbjEPGNS (ORCPT ); Tue, 16 May 2023 02:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229619AbjEPGNR (ORCPT ); Tue, 16 May 2023 02:13:17 -0400 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 007B410C1; Mon, 15 May 2023 23:13:16 -0700 (PDT) Received: by verein.lst.de (Postfix, from userid 2407) id 1F6EB67373; Tue, 16 May 2023 08:13:10 +0200 (CEST) Date: Tue, 16 May 2023 08:13:09 +0200 From: Christoph Hellwig To: "Michael Kelley (LINUX)" Cc: Petr Tesarik , Jonathan Corbet , Greg Kroah-Hartman , "Rafael J. Wysocki" , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Christoph Hellwig , Marek Szyprowski , Robin Murphy , "Paul E. McKenney" , Borislav Petkov , Randy Dunlap , Catalin Marinas , Damien Le Moal , Kim Phillips , "Steven Rostedt (Google)" , Andy Shevchenko , Hans de Goede , Jason Gunthorpe , Kees Cook , Thomas Gleixner , "open list:DOCUMENTATION" , open list , "open list:DRM DRIVERS" , "open list:DMA MAPPING HELPERS" , Roberto Sassu , Kefeng Wang , "petr@tesarici.cz" Subject: Re: [PATCH v2 RESEND 4/7] swiotlb: Dynamically allocated bounce buffers Message-ID: <20230516061309.GA7219@lst.de> References: <346abecdb13b565820c414ecf3267275577dbbf3.1683623618.git.petr.tesarik.ext@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Mon, May 15, 2023 at 07:43:52PM +0000, Michael Kelley (LINUX) wrote: > FWIW, I don't think the approach you have implemented here will be > practical to use for CoCo VMs (SEV, TDX, whatever else). The problem > is that dma_direct_alloc_pages() and dma_direct_free_pages() must > call dma_set_decrypted() and dma_set_encrypted(), respectively. In CoCo > VMs, these calls are expensive because they require a hypercall to the host, > and the operation on the host isn't trivial either. I haven't measured the > overhead, but doing a hypercall on every DMA map operation and on > every unmap operation has long been something we thought we must > avoid. The fixed swiotlb bounce buffer space solves this problem by > doing set_decrypted() in batch at boot time, and never > doing set_encrypted(). I also suspect it doesn't really scale too well due to the number of allocations. I suspect a better way to implement things would be to add more large chunks that are used just like the main swiotlb buffers. That is when we run out of space try to allocate another chunk of the same size in the background, similar to what we do with the pool in dma-pool.c. This means we'll do a fairly large allocation, so we'll need compaction or even CMA to back it up, but the other big upside is that it also reduces the number of buffers that need to be checked in is_swiotlb_buffer or the free / sync side.