Skip to content

Commit

Permalink
drm/nouveau: fix dma syncing warning with debugging on.
Browse files Browse the repository at this point in the history
Since I wrote the below patch if you run a debug kernel you can a
dma debug warning like:
nouveau 0000:1f:00.0: DMA-API: device driver tries to sync DMA memory it has not allocated [device address=0x000000016e012000] [size=4096 bytes]

The old nouveau code wasn't consolidate the pages like the ttm code,
but the dma-debug expects the sync code to give it the same base/range
pairs as the allocator.

Fix the nouveau sync code to consolidate pages before calling the
sync code.

Fixes: bd549d3 ("nouveau: use ttm populate mapping functions. (v2)")
Reported-by: Lyude Paul <[email protected]>
Reviewed-by: Ben Skeggs <[email protected]>
Signed-off-by: Dave Airlie <[email protected]>
Link: https://patchwork.freedesktop.org/patch/417588/
  • Loading branch information
airlied committed Feb 3, 2021
1 parent 1048ba8 commit f295c8c
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions drivers/gpu/drm/nouveau/nouveau_bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ nouveau_bo_sync_for_device(struct nouveau_bo *nvbo)
{
struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
struct ttm_tt *ttm_dma = (struct ttm_tt *)nvbo->bo.ttm;
int i;
int i, j;

if (!ttm_dma)
return;
Expand All @@ -556,18 +556,29 @@ nouveau_bo_sync_for_device(struct nouveau_bo *nvbo)
if (nvbo->force_coherent)
return;

for (i = 0; i < ttm_dma->num_pages; i++)
for (i = 0; i < ttm_dma->num_pages; ++i) {
struct page *p = ttm_dma->pages[i];
size_t num_pages = 1;

for (j = i + 1; j < ttm_dma->num_pages; ++j) {
if (++p != ttm_dma->pages[j])
break;

++num_pages;
}
dma_sync_single_for_device(drm->dev->dev,
ttm_dma->dma_address[i],
PAGE_SIZE, DMA_TO_DEVICE);
num_pages * PAGE_SIZE, DMA_TO_DEVICE);
i += num_pages;
}
}

void
nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo)
{
struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
struct ttm_tt *ttm_dma = (struct ttm_tt *)nvbo->bo.ttm;
int i;
int i, j;

if (!ttm_dma)
return;
Expand All @@ -576,9 +587,21 @@ nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo)
if (nvbo->force_coherent)
return;

for (i = 0; i < ttm_dma->num_pages; i++)
for (i = 0; i < ttm_dma->num_pages; ++i) {
struct page *p = ttm_dma->pages[i];
size_t num_pages = 1;

for (j = i + 1; j < ttm_dma->num_pages; ++j) {
if (++p != ttm_dma->pages[j])
break;

++num_pages;
}

dma_sync_single_for_cpu(drm->dev->dev, ttm_dma->dma_address[i],
PAGE_SIZE, DMA_FROM_DEVICE);
num_pages * PAGE_SIZE, DMA_FROM_DEVICE);
i += num_pages;
}
}

void nouveau_bo_add_io_reserve_lru(struct ttm_buffer_object *bo)
Expand Down

0 comments on commit f295c8c

Please sign in to comment.