Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp3988768rdb; Wed, 30 Aug 2023 11:54:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGiRqMSf8Xdf76Y6svEyXe2oU+Wrlxobyl98wjbsNayjT+bh/paklL+1wi6YC1lD1GQybBv X-Received: by 2002:a05:6808:2202:b0:3a7:a14:ba07 with SMTP id bd2-20020a056808220200b003a70a14ba07mr3804638oib.7.1693421696162; Wed, 30 Aug 2023 11:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693421696; cv=none; d=google.com; s=arc-20160816; b=HZMo2NELm3/JjlvXXtcpy2euAvYefEaJGBygkGPihuwPTcVUzciNzlLDB7T0HJmJrS oROEE1T/B8bTx4HHbyVgR2PX7pC8ilvGbvbrK4nzuAD0nHcC1vqaswm913M+YSaaRQb/ 1HKLmzAHgG2aS6IP5IB45rwJufmW5aZV10jHSTeZ3yQ9uL9NtKMQ9Fu4wHu5ZJA4DNUc grWTbREZNOO4/CIazA15E1TGu07QUZz/Fm+SluqdLk/xQU3I59xqX9aj2e+IAQB6F5ZO HeRf707a8I0VMKIja9JWhW9exgFny4yloGYDkWMkjOD5NkdgflREvfopexG58U2kSObi 6JCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=HMHm8xsFiY3rCKXcUW9mKFfgaY2B66BTW3iU1zT7jq0=; fh=uCs+liPr7xgYgyYYQsm6N0Fp93zz9+DVyXKZaAOymsM=; b=nwuNqE1ki9ofQJ4GysWlz8L+EYXrIQBw3MUVVYFryaK1aAzplr29pvUiaMZmT19fox C5eF8NMP4l9nFK6FMiNWszSZviB8ursqnjN+0ORoB+ikxHT6LFD+Vi/Tr2SckvgdwYP3 M7g9FdiKGrAcHODH3h+ZEL4wxsmHpUH5mpSaZqllyrQs+Q5ehckZuOU+aGTHdqA9Bd9R FgjjhWIKD5KwgeeF3euDKAKYkqXxX+Vqh/KfmDrwJ54ZSErD6sikqKXfLpLVXkJt87QJ Vew1eYvXLqbF2QhtqkAG0PnrZwXmJpkpgug1ijRg6o9kAx6jk7wqyi6hui+CbyETTalP BBcg== 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 d25-20020a634f19000000b0056c4d97e157si3377859pgb.377.2023.08.30.11.54.28; Wed, 30 Aug 2023 11:54:56 -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 S244605AbjH3SvK (ORCPT + 99 others); Wed, 30 Aug 2023 14:51:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244665AbjH3Nlu (ORCPT ); Wed, 30 Aug 2023 09:41:50 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 791BD1B0; Wed, 30 Aug 2023 06:41:46 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9ECE72F4; Wed, 30 Aug 2023 06:42:25 -0700 (PDT) Received: from [10.57.4.99] (unknown [10.57.4.99]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D02AC3F738; Wed, 30 Aug 2023 06:41:44 -0700 (PDT) Message-ID: Date: Wed, 30 Aug 2023 14:41:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [EXT] Re: [PATCH] media: videobuf2-dma-sg: limit the sg segment size Content-Language: en-GB To: Hui Fang , Christoph Hellwig Cc: Tomasz Figa , Anle Pan , "m.szyprowski@samsung.com" , "mchehab@kernel.org" , "linux-media@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Jindong Yue References: <20230828075420.2009568-1-anle.pan@nxp.com> <20230829150442.GA3929@lst.de> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 2023-08-30 04:22, Hui Fang wrote: > Hi, guys > Thanks for your time. > I wonder if only NXP met the "swiotlb buffer full" issue. > In theory, when format is YUYV, those resolutions no greater than 320x240 (153600 bytes, which less than the max mapping size 256K ) can't meet the issue. > But resolutions no less than 640x480 (307200 bytes), may have chances to trigger the issue. > On our side, we tested on 1080p, easy to reproduce. > Or maybe "dma_max_mapping_size(dev)" is much bigger than 256K on your side? I would imagine that in most cases, people either have an IOMMU, or they don't have more RAM than the device can access directly. And in fact I think we've missed looking deep enough and that's the real problem here - the overall context is a buffer allocator, so if SWIOTLB is bouncing anything in that dma_map_sg() call, then it means we're allocating a buffer for a device out of pages that that device can't actually access, which seems fundamentally bad. Unfortunately there isn't currently an easy way to do the right thing - dma-debug would probably get very unhappy about scraping a bunch of dma_alloc_pages() allocations into a scatterlist and subsequently calling dma_sync_sg() on it, while dma_alloc_noncontiguous() does at least return a scatterlist but would be overly restrictive since we don't need it to be dma-contiguous either. I guess we could do with some sort of dma_alloc_sgt() API that joins the relevant internal bits together to replace vb2_dma_sg_alloc_compacted() with proper DMA-mask-aware allocation, and probably also allocates the sg_table as well? Thanks, Robin. > > BRs, > Fang Hui > ________________________________ > From: Christoph Hellwig > Sent: Tuesday, August 29, 2023 11:04 PM > To: Robin Murphy > Cc: Tomasz Figa ; Anle Pan ; Christoph Hellwig ; m.szyprowski@samsung.com ; mchehab@kernel.org ; linux-media@vger.kernel.org ; linux-kernel@vger.kernel.org ; Hui Fang > Subject: [EXT] Re: [PATCH] media: videobuf2-dma-sg: limit the sg segment size > > Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button > > > On Tue, Aug 29, 2023 at 12:14:44PM +0100, Robin Murphy wrote: >> dma_get_max_seg_size() represents a capability of the device itself, namely >> the largest contiguous range it can be programmed to access in a single DMA >> descriptor/register/whatever. > > Yes. In a way it's a bit odd that it ended up in a field in > struct device, as the feature might actually be different for different > DMA engines or features in a device. If I was to redesign it from > scratch I'd just pass it to dma_map_sg. > >>> Generally looking at videobuf2-dma-sg, I feel like we would benefit >>> from some kind of dma_alloc_table_from_pages() that simply takes the >>> struct dev pointer and does everything necessary. >> >> Possibly; this code already looks lifted from drm_prime_pages_to_sg(), and >> if it's needed here then presumably vb2_dma_sg_get_userptr() also needs it, >> at the very least. > > Yes, there's tons of them. But I'd feel really bad adding even more > struct scatterlist based APIs given how bad of a data structure that is. >