linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Hui Fang <hui.fang@nxp.com>, Christoph Hellwig <hch@lst.de>
Cc: Tomasz Figa <tfiga@chromium.org>, Anle Pan <anle.pan@nxp.com>,
	"m.szyprowski@samsung.com" <m.szyprowski@samsung.com>,
	"mchehab@kernel.org" <mchehab@kernel.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Jindong Yue <jindong.yue@nxp.com>
Subject: Re: [EXT] Re: [PATCH] media: videobuf2-dma-sg: limit the sg segment size
Date: Wed, 30 Aug 2023 14:41:34 +0100	[thread overview]
Message-ID: <d99ebaf2-bd95-1213-6c33-584a8c944b33@arm.com> (raw)
In-Reply-To: <DB9PR04MB92841D8BC1122D5A4210F78987E6A@DB9PR04MB9284.eurprd04.prod.outlook.com>

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 <hch@lst.de>
> Sent: Tuesday, August 29, 2023 11:04 PM
> To: Robin Murphy <robin.murphy@arm.com>
> Cc: Tomasz Figa <tfiga@chromium.org>; Anle Pan <anle.pan@nxp.com>; Christoph Hellwig <hch@lst.de>; m.szyprowski@samsung.com <m.szyprowski@samsung.com>; mchehab@kernel.org <mchehab@kernel.org>; linux-media@vger.kernel.org <linux-media@vger.kernel.org>; linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>; Hui Fang <hui.fang@nxp.com>
> 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.
> 

  parent reply	other threads:[~2023-08-30 18:53 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-28  7:54 [PATCH] media: videobuf2-dma-sg: limit the sg segment size Anle Pan
2023-08-29 10:03 ` Tomasz Figa
2023-08-29 11:14   ` Robin Murphy
2023-08-29 15:04     ` Christoph Hellwig
2023-08-30  3:47       ` Tomasz Figa
2023-08-30 14:33         ` Christoph Hellwig
2023-08-30 16:43           ` Jason Gunthorpe
2023-08-31 12:35             ` Christoph Hellwig
2023-08-31 15:32               ` Jason Gunthorpe
2023-09-01  6:10                 ` Christoph Hellwig
2023-09-01 14:26                   ` Jason Gunthorpe
     [not found]       ` <DB9PR04MB92841D8BC1122D5A4210F78987E6A@DB9PR04MB9284.eurprd04.prod.outlook.com>
2023-08-30 13:41         ` Robin Murphy [this message]
2023-08-30  3:59     ` Tomasz Figa
2023-09-06  8:52     ` Hans Verkuil
2023-09-06  9:26       ` Tomasz Figa
2023-09-06  9:43         ` Hans Verkuil
2023-08-30  8:50 ` Hui Fang
2023-08-30  9:28   ` Tomasz Figa
2023-09-04  7:10     ` [EXT] " Hui Fang
2023-09-05  3:43       ` Tomasz Figa
2023-09-06  8:16         ` Hui Fang
2023-09-06  9:28           ` Tomasz Figa
2023-09-11  6:13             ` Hui Fang
2023-09-12  2:22               ` Tomasz Figa
2023-09-12  7:01                 ` Hui Fang
2023-09-12  7:10                   ` Tomasz Figa
2023-09-12  7:43                     ` Hui Fang
2023-09-12  7:51                       ` Tomasz Figa
2023-09-13  9:13                         ` Hui Fang
2023-09-13  9:44                           ` Tomasz Figa
2023-09-13 13:16                             ` Hui Fang
2023-09-18  2:28                               ` Hui Fang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d99ebaf2-bd95-1213-6c33-584a8c944b33@arm.com \
    --to=robin.murphy@arm.com \
    --cc=anle.pan@nxp.com \
    --cc=hch@lst.de \
    --cc=hui.fang@nxp.com \
    --cc=jindong.yue@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mchehab@kernel.org \
    --cc=tfiga@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).