Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp217550rwd; Mon, 15 May 2023 23:22:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ww7bryA52CCCdj4BnpiwTbpvtWfDJvME3mSYBF5j17XRYbT+kKYfiQ1uw/Tt9e418aOui X-Received: by 2002:a17:903:234c:b0:1ab:109e:a553 with SMTP id c12-20020a170903234c00b001ab109ea553mr47043146plh.62.1684218146081; Mon, 15 May 2023 23:22:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684218146; cv=none; d=google.com; s=arc-20160816; b=DbrduPZK/l+VLNAk7G4EVgRuO/9mcl6GLsAk1Xn2WVyKtbynq0sty+xbOhn0I0o52P cxai0dNDkO8AY3yh8Bp8OOsP3EOV2rFqKXdU22TL+pUWxfpnCIQyR8/i4zkr2fDs35Se 5TNiOH4qD47dpYgxm+PQKBosbgDS0eJoLPS/aFasyJ2rp4CmAZXj3xVitTos3E9/n5K3 sYFoRyYOglLgJh9vrnedMB+EDjfyRUDo3u3ZS8xkw6kHY3iYNF990h7+/dgdX8XnWhe/ Dky1MZRaAYzOrxC86eKpA1V6gHE+nCHje3ImCq+jhPtNZRiEUyzDMG9nY6SP5MTa9zk2 TsWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=bLW0VZ+6cWjk9FNp6I4BnL3DidPtG3G9hpQFjfau9/M=; b=Wh8sSr2n8Li8JnPIppDAeLlTxl0MV5eT2iJLyaA6pKoey6nETWy7Re2HQXMcIMssP2 zAZvWn+u9yG0hzYs9tbRG0joaIi+5itYRtWSQT8fABDOPht8o5/Gyelit1M1LqB/pAvA P5drTJXl9Wrj7N/q+EQ/lvRvjK3RmGCcpQirys515GCJ/w2qU3eZsrrnx8hEXNwGT0So oyd+8XbbBg4oGqyyd1J0c/uYzX7cTMn8fIU1UAZ5Xv4NfLykaw3t1THRG35Y8iIwNtTC GHsAdSWpPkve22sm0vyEeZo03DfQjbnhiW4ddmMNDsFXnO5GLiN3NoYFhFdpidkP//Sl Hqmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o23-20020a170902779700b001a6f0eab385si17201861pll.55.2023.05.15.23.22.13; Mon, 15 May 2023 23:22:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230019AbjEPGNS (ORCPT + 99 others); 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) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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.