linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: videobuf2-dma-sg: limit the sg segment size
@ 2023-08-28  7:54 Anle Pan
  2023-08-29 10:03 ` Tomasz Figa
  2023-08-30  8:50 ` Hui Fang
  0 siblings, 2 replies; 32+ messages in thread
From: Anle Pan @ 2023-08-28  7:54 UTC (permalink / raw)
  To: tfiga, m.szyprowski, mchehab
  Cc: linux-media, linux-kernel, anle.pan, hui.fang

When allocating from pages, the size of the sg segment is unlimited and
the default is UINT_MAX. This will cause the DMA stream mapping failed
later with a "swiotlb buffer full" error. The default maximum mapping
size is 128 slots x 2K = 256K, determined by "IO_TLB_SEGSIZE".
To fix the issue, limit the sg segment size according to
"dma_max_mapping_size" to match the mapping limit.

Signed-off-by: Anle Pan <anle.pan@nxp.com>
---
 drivers/media/common/videobuf2/videobuf2-dma-sg.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
index fa69158a65b1..b608a7c5f240 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
@@ -105,6 +105,7 @@ static void *vb2_dma_sg_alloc(struct vb2_buffer *vb, struct device *dev,
 	struct sg_table *sgt;
 	int ret;
 	int num_pages;
+	size_t max_segment = 0;
 
 	if (WARN_ON(!dev) || WARN_ON(!size))
 		return ERR_PTR(-EINVAL);
@@ -134,8 +135,12 @@ static void *vb2_dma_sg_alloc(struct vb2_buffer *vb, struct device *dev,
 	if (ret)
 		goto fail_pages_alloc;
 
-	ret = sg_alloc_table_from_pages(buf->dma_sgt, buf->pages,
-			buf->num_pages, 0, size, GFP_KERNEL);
+	if (dev)
+		max_segment = dma_max_mapping_size(dev);
+	if (max_segment == 0)
+		max_segment = UINT_MAX;
+	ret = sg_alloc_table_from_pages_segment(buf->dma_sgt, buf->pages,
+		buf->num_pages, 0, size, max_segment, GFP_KERNEL);
 	if (ret)
 		goto fail_table_alloc;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2023-09-18  2:29 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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         ` [EXT] " Robin Murphy
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

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).