Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp676683rwl; Fri, 7 Apr 2023 03:49:40 -0700 (PDT) X-Google-Smtp-Source: AKy350Ydu3KzVQEU18qgvHTrNs3IS9RkLZtxgY8r4HbUsgK8PFPtn3EN3EY0QA48LR25RTiOqj+I X-Received: by 2002:a05:6402:14c9:b0:4fa:57bf:141a with SMTP id f9-20020a05640214c900b004fa57bf141amr2123347edx.32.1680864580377; Fri, 07 Apr 2023 03:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680864580; cv=none; d=google.com; s=arc-20160816; b=UbGVg4v/RRugiAajIC8ijlzbWjHAcRvEXi8M/8ZPRznmX5/Ml4L0HRq4OGc9G4BSSZ 8I/uc19HygwEgU8bYLEBQ4dmrF5p18n4XM7Tn1RV/u7alF1ggOWOpL+MqZA6rNa70JsP lv3xhSKSk6a4i9QiQlY5LbXgSneQfUFVX/VTJcCi+iAoqOIW5v4+G+mrtiLDgqbc2iYY hnD2CL3VAeZXHcCAX6uyoctJ+6+drFtn3he+9iR7oqAvhL2v8bMSaWKELWdJYA7zmmm3 sX8QM+rV7VIjb/41DoKt5s0n56/MgnRE05Nd/82doZrRVKpwn+HKttTVk6YnVPrDpOC7 brcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=OziNlx/YOFTZ4QIW1VDAT+tM7EnWeZzjylnY4SAszjU=; b=JJV4eDCS0hjHuhMBPIZtTt7lMtrpb7b7oMUn84jPd4KoERXm/3I56puBaUMzTwPQqx ZhCn6NXcV/MQqSu/pz5pWX9RT76pzC1bjQlg5FykPOB6GOnhGybN2echLwvBpfO4i4Wv msS8P2EAyOK11E5Wb5hT2IP84470fPtO7Z8evwyQKYlE3KUrFaBAw1B7zNVtQVPmT9fX vuR7p2DAoi0Ifppp31dNRFcbMTgvVAfQEeG0PAylb8uDdqSyHRjMIREChS+9447RLk6N mJiRUkfHEdLH4HppXTrcfg8Ft/DG7aLY7bP5CSJkfXzwHQUuPnCOU7HtfTGVxt6gSnc4 Tm1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=4sM1CUkj; 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=pass (p=NONE sp=NONE dis=NONE) header.from=tesarici.cz Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a6-20020aa7d906000000b004fd2a2c6ff8si2890072edr.467.2023.04.07.03.49.15; Fri, 07 Apr 2023 03:49:40 -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; dkim=pass header.i=@tesarici.cz header.s=mail header.b=4sM1CUkj; 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=pass (p=NONE sp=NONE dis=NONE) header.from=tesarici.cz Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231827AbjDGKqd (ORCPT + 99 others); Fri, 7 Apr 2023 06:46:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230309AbjDGKqc (ORCPT ); Fri, 7 Apr 2023 06:46:32 -0400 Received: from bee.tesarici.cz (bee.tesarici.cz [IPv6:2a03:3b40:fe:2d4::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6540C8A6B; Fri, 7 Apr 2023 03:46:31 -0700 (PDT) Received: from meshulam.tesarici.cz (dynamic-2a00-1028-83b8-1e7a-4427-cc85-6706-c595.ipv6.o2.cz [IPv6:2a00:1028:83b8:1e7a:4427:cc85:6706:c595]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bee.tesarici.cz (Postfix) with ESMTPSA id 1092814C886; Fri, 7 Apr 2023 12:46:28 +0200 (CEST) Authentication-Results: mail.tesarici.cz; dmarc=fail (p=none dis=none) header.from=tesarici.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tesarici.cz; s=mail; t=1680864389; bh=fwSxeONAMiIQulvFLbEmRpW+yUKJFrnFHkYYi44Vd7I=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=4sM1CUkjmwVelOaTnEWeo9CIORmocDgOnSm0PWyS3bTKcFjrsk3FFguLF/n3mLz/E 3FoHV2DRuDICL7NYBgu8Ix0LvbyLUqJSmLyuyzj4H4Yy/7NQggJSL/YZLshclFDVkD P/4Jsb3ODIIc5bGUkHW2zYV644QtsGrzxmoKsn47ROm6bnfneRTtQU6TkIT0+OjH0z mzU6gVssjml8+15sN8QdeXwlMSr5YdeVfyNGqE0lvJWrnBAjwt4C3qk2Txo3w7ZqNh p5l2MT4qljaJSVYjPre2Ly1hog7j6GZDOapB+X486jTBzpSQlUK/VVPBrITo2W44fW sxVsi3ES64ziQ== Date: Fri, 7 Apr 2023 12:46:27 +0200 From: Petr =?UTF-8?B?VGVzYcWZw61r?= To: Christoph Hellwig Cc: Petr Tesarik , Jonathan Corbet , Marek Szyprowski , Robin Murphy , Borislav Petkov , "Paul E. McKenney" , Andrew Morton , Randy Dunlap , Damien Le Moal , Kim Phillips , "Steven Rostedt (Google)" , "open list:DOCUMENTATION" , open list , "open list:DMA MAPPING HELPERS" , Roberto Sassu , Alexander Graf Subject: Re: [RFC v1 3/4] swiotlb: Allow dynamic allocation of bounce buffers Message-ID: <20230407124627.74528415@meshulam.tesarici.cz> In-Reply-To: <20230407055548.GC6803@lst.de> References: <0334a54332ab75312c9de825548b616439dcc9f5.1679309810.git.petr.tesarik.ext@huawei.com> <20230328040724.GB25506@lst.de> <4268fa4e-4f0f-a2f6-a2a5-5b78ca4a073d@huaweicloud.com> <20230407055548.GC6803@lst.de> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 Fri, 7 Apr 2023 07:55:48 +0200 Christoph Hellwig wrote: > On Tue, Mar 28, 2023 at 09:54:35AM +0200, Petr Tesarik wrote: > > I tend to agree here. However, it's the DMABUF design itself that causes > > some trouble. The buffer is allocated by the v3d driver, which does not > > have the restriction, so the DMA API typically allocates an address > > somewhere near the 4G boundary. Userspace then exports the buffer, sends > > it to another process as a file descriptor and imports it into the vc4 > > driver, which requires DMA below 1G. In the beginning, v3d had no idea > > that the buffer would be exported to userspace, much less that it would > > be later imported into vc4. > > Then we need to either: > > a) figure out a way to communicate these addressing limitations AFAICS this would require a complete overhaul of the dma-buf userspace API so that intended imports are communicated at export time. In other words, it would be quite intrusive. Not my preferrence. > b) find a way to migrate a buffer into other memory, similar to > how page migration works for page cache Let me express the idea in my own words to make sure I get it right. When a DMA buffer is imported, but before it is ultimately pinned in memory, the importing device driver checks whether the buffer meets its DMA constraints. If not, it calls a function provided by the exporting device driver to migrate the buffer. This makes sense, but: 1) The operation must be implemented in the exporting driver; this will take some time. 2) In theory, there may be no overlap between the exporting device and the importing device. OTOH I'm not aware of any real-world example, so we can probably return a suitable error code, and that's it. Anyway, I have already written in another reply that my original use case is moot, because a more recent distribution can do the job without using dma-buf, so it has been fixed in user space, be it in GNOME, pipewire, or Mesa (I don't really have to know). At this point I would go with the assumption that large buffers allocated by media subsystems will not hit swiotlb. Consequently, I don't plan to spend more time on this branch of the story. > > BTW my testing also suggests that the streaming DMA API is quite > > inefficient, because UAS performance _improved_ with swiotlb=force. > > Sure, this should probably be addressed in the UAS and/or xHCI driver, > > but what I mean is that moving away from swiotlb may even cause > > performance regressions, which is counter-intuitive. At least I would > > _not_ have expected it. > > That is indeed very odd. Are you running with a very slow iommu > driver there? Or what is the actual use case there in general? This was on a Raspberry Pi 4, which does not have any IOMMU. IOW it looks like copying data around can be faster than sending it straight to the device. When I have some more time, I must investigate what is really happening there, because it does not make any sense to me. Petr T