All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/prime: Iterate SG DMA addresses separately
@ 2018-04-11 17:11 Robin Murphy
  2018-04-11 17:11 ` [PATCH 2/2] drm/amdgpu: Allow dma_map_sg() coalescing Robin Murphy
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Robin Murphy @ 2018-04-11 17:11 UTC (permalink / raw)
  To: amd-gfx, dri-devel; +Cc: okaya, alexander.deucher, christian.koenig

For dma_map_sg(), DMA API implementations are free to merge consecutive
segments into a single DMA mapping if conditions are suitable, thus the
resulting DMA addresses may be packed into fewer entries than
ttm->sg->nents implies.

drm_prime_sg_to_page_addr_arrays() does not account for this, meaning
its callers either have to reject the 0 < count < nents case or risk
getting bogus addresses back later. Fortunately this is relatively easy
to deal with having to rejig structures to also store the mapped count,
since the total DMA length should still be equal to the total buffer
length. All we need is a separate scatterlist cursor to iterate the DMA
addresses separately from the CPU addresses.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---

Off the back of Sinan's proposal for a workaround, I took a closer look
and this jumped out - I have no hardware to test it, nor do I really
know my way around this code, so I'm probably missing something, but at
face value this seems like the only obvious problem, and worth fixing
either way.

These patches are based on drm-next, and compile-tested (for arm64) only.

Robin.

 drivers/gpu/drm/drm_prime.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 7856a9b3f8a8..db3dc8489afc 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -933,16 +933,18 @@ int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
 				     dma_addr_t *addrs, int max_entries)
 {
 	unsigned count;
-	struct scatterlist *sg;
+	struct scatterlist *sg, *dma_sg;
 	struct page *page;
-	u32 len, index;
+	u32 len, dma_len, index;
 	dma_addr_t addr;
 
 	index = 0;
+	dma_sg = sgt->sgl;
+	dma_len = sg_dma_len(dma_sg);
+	addr = sg_dma_address(dma_sg);
 	for_each_sg(sgt->sgl, sg, sgt->nents, count) {
 		len = sg->length;
 		page = sg_page(sg);
-		addr = sg_dma_address(sg);
 
 		while (len > 0) {
 			if (WARN_ON(index >= max_entries))
@@ -957,6 +959,12 @@ int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
 			len -= PAGE_SIZE;
 			index++;
 		}
+
+		if (dma_len == 0) {
+			dma_sg = sg_next(dma_sg);
+			dma_len = sg_dma_len(dma_sg);
+			addr = sg_dma_address(dma_sg);
+		}
 	}
 	return 0;
 }
-- 
2.16.1.dirty

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2018-04-12 19:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-11 17:11 [PATCH 1/2] drm/prime: Iterate SG DMA addresses separately Robin Murphy
2018-04-11 17:11 ` [PATCH 2/2] drm/amdgpu: Allow dma_map_sg() coalescing Robin Murphy
2018-04-11 18:28   ` Christian König
2018-04-12 17:53     ` Robin Murphy
     [not found]       ` <24948fc1-ff01-1276-e3fa-c2b0e5713b5b-5wv7dgnIgG8@public.gmane.org>
2018-04-12 19:08         ` Christian König
2018-04-11 17:45 ` [1/2] drm/prime: Iterate SG DMA addresses separately Robin Murphy
     [not found] ` <0901c8c3b9adbcb851ba58dfca6b16d12ccbcb0f.1523465719.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2018-04-11 18:26   ` [PATCH 1/2] " Christian König
     [not found]     ` <67b1875d-9f77-5fb8-bfc6-53d34c15ab16-5C7GfCeVMHo@public.gmane.org>
2018-04-12  9:11       ` Lucas Stach
     [not found]         ` <1523524317.4981.24.camel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2018-04-12  9:35           ` Christian König
     [not found]             ` <58ef1aab-6c3a-8e69-0a7e-98218ba9fe96-5C7GfCeVMHo@public.gmane.org>
2018-04-12  9:49               ` Lucas Stach
     [not found]                 ` <1523526540.4981.26.camel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2018-04-12 10:33                   ` Christian König
     [not found]                     ` <9e55076e-56dd-d553-63d6-2ce018199f84-5C7GfCeVMHo@public.gmane.org>
2018-04-12 11:48                       ` okaya-sgV2jX0FEOL9JmXXK+q4OQ
2018-04-12 13:18                     ` Robin Murphy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.