Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1881897rwd; Wed, 17 May 2023 02:44:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7cFSQ+OpC2+/pxEYn83rzo5RsU/qLk3fAn6j2VZEmsa62AysYs+rhm6HDhCS20rNxjRKbQ X-Received: by 2002:a17:902:e810:b0:1a6:7ed0:147e with SMTP id u16-20020a170902e81000b001a67ed0147emr55212161plg.33.1684316670301; Wed, 17 May 2023 02:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684316670; cv=none; d=google.com; s=arc-20160816; b=I+bFiGSPQkogeKMHu7knXR4y2lXGu+BrzT049ZAMCWJLuLC1L08ddTFDyApNVOvcYa 7Lf+BwFaEwilk4o7fSC5vqV6iQDwghIMmxTAX/fwbg92Y/3cwelKkyllBEz74XbKHqBs KRw18h0eXKRW6itif9eo84ZiYGMyyl2Lr/esexdiIs9UOF0hoVL4imzSZRiC74mLjiOX rso09StARlgkBhf6BXwIvvSlqTmuKMkLD+OL9r6flaHLqhiQ6bcFWZ5JyoLj/HbkDKgw DDhjOlhfFVQKeq8WpWQfRVH2pOI3zRFPvcS6UmsDDTVD6A51ExPKR+8+l989XrBR5xLF SRow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=XI0lntzhLdG+QqIDZwkE3uf3MaCqsrmV5rfUZ7DB044=; b=CFziDYgbgPUuiMehL2V9HK7pHX+zFj9XkpSar17DPFtMeJSQt8WjuStDKd5nuAJ7Bn YCs2fsF+GhAyYXOlAzMzsnehX2vlP6NVfmcpsdhxCMm7ZVAGlTq/cA5Aknffkz0djMm9 q35/+ul6u6NIA5jcVtC+Z9V5OYhfYOuf6aiVeONwPV8YsjZqVPo2gv+i/n5IRyZPMkwZ Q4tl+utn1FlKjmrjmRQZ6XkqTp4ai6poc767uq4T2twBx7Xaj27JR4xoE1uzqhV45KwX rxg6wRvnYF7gW1uysjB+Y3J7u4N0EykumCVY6VPaPJJEj9KOzhaeI39nmNPxrI8psUXa IVxg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a1709026a8600b001a2a4eb10d6si20080284plk.58.2023.05.17.02.44.15; Wed, 17 May 2023 02:44:30 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230045AbjEQJlk (ORCPT + 99 others); Wed, 17 May 2023 05:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230151AbjEQJld (ORCPT ); Wed, 17 May 2023 05:41:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F14EC420A; Wed, 17 May 2023 02:41:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 801AA6445D; Wed, 17 May 2023 09:41:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC390C433EF; Wed, 17 May 2023 09:41:22 +0000 (UTC) Date: Wed, 17 May 2023 10:41:19 +0100 From: Catalin Marinas To: Christoph Hellwig Cc: Petr =?utf-8?B?VGVzYcWZw61r?= , "Michael Kelley (LINUX)" , Petr Tesarik , Jonathan Corbet , Greg Kroah-Hartman , "Rafael J. Wysocki" , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Marek Szyprowski , Robin Murphy , "Paul E. McKenney" , Borislav Petkov , Randy Dunlap , 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 Subject: Re: [PATCH v2 RESEND 4/7] swiotlb: Dynamically allocated bounce buffers Message-ID: References: <346abecdb13b565820c414ecf3267275577dbbf3.1683623618.git.petr.tesarik.ext@huawei.com> <20230516061309.GA7219@lst.de> <20230516083942.0303b5fb@meshulam.tesarici.cz> <20230517083510.0cd7fa1a@meshulam.tesarici.cz> <20230517065653.GA25016@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230517065653.GA25016@lst.de> X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, 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 Wed, May 17, 2023 at 08:56:53AM +0200, Christoph Hellwig wrote: > Just thinking out loud: > > - what if we always way overallocate the swiotlb buffer > - and then mark the second half / two thirds / of the thin air> slots as used, and make that region available > through a special CMA mechanism as ZONE_MOVABLE (but not allowing > other CMA allocations to dip into it). > > This allows us to have a single slot management for the entire > area, but allow reclaiming from it. We'd probably also need to make > this CMA variant irq safe. I think this could work. It doesn't need to be ZONE_MOVABLE (and we actually need this buffer in ZONE_DMA). But we can introduce a new migrate type, MIGRATE_SWIOTLB, and movable page allocations can use this range. The CMA allocations go to free_list[MIGRATE_CMA], so they won't overlap. One of the downsides is that migrating movable pages still needs a sleep-able context. Another potential confusion is is_swiotlb_buffer() for pages in this range allocated through the normal page allocator. We may need to check the slots as well rather than just the buffer boundaries. (we are actually looking at a MIGRATE_METADATA type for the arm64 memory tagging extension which uses a 3% carveout of the RAM for storing the tags and people want that reused somehow; we have some WIP patches but we'll post them later this summer) > This could still be combined with more aggressive use of per-device > swiotlb area, which is probably a good idea based on some hints. > E.g. device could hint an amount of inflight DMA to the DMA layer, > and if there are addressing limitations and the amout is large enough > that could cause the allocation of a per-device swiotlb area. If we go for one large-ish per-device buffer for specific cases, maybe something similar to the rmem_swiotlb_setup() but which can be dynamically allocated at run-time and may live alongside the default swiotlb. The advantage is that it uses a similar slot tracking to the default swiotlb, no need to invent another. This per-device buffer could also be allocated from the MIGRATE_SWIOTLB range if we make it large enough at boot. It would be seen just a local accelerator for devices that use bouncing frequently or from irq context. -- Catalin