dma-buf: heaps: remove duplicated cache sync
PATCH 1/1 dma-buf: heaps: remove duplicated cache sync
From: Guangming Cao <[email protected]>
Current flow, one dmabuf maybe call cache sync many times if it has beed mapped more than one time.
Is there any case that attachments of one dmabuf will points to different memory? If not, seems do sync only one time is more better.
--- drivers/dma-buf/heaps/system_heap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/dma-buf/heaps/system_heap.c +8 -6
@@ -162,9 +162,10 @@ static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,invalidate_kernel_vmap_range (buffer->vaddr, buffer->len);list_for_each_entry (a, &buffer->attachments, list) { -if (!a->mapped) -continue ; -dma_sync_sgtable_for_cpu (a->dev, a->table, direction); +if (a->mapped) { +dma_sync_sgtable_for_cpu (a->dev, a->table, direction); +break ; + } }mutex_unlock (&buffer->lock);
@@ -183,9 +184,10 @@ static int system_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf,flush_kernel_vmap_range (buffer->vaddr, buffer->len);list_for_each_entry (a, &buffer->attachments, list) { -if (!a->mapped) -continue ; -dma_sync_sgtable_for_device (a->dev, a->table, direction); +if (!a->mapped) { +dma_sync_sgtable_for_device (a->dev, a->table, direction); +break ; + } }mutex_unlock (&buffer->lock);
Signature · 1 line
2.17.1
Christian König
maintainerAm 30.08.21 um 12:01 schrieb [email protected]:
Quoted 4 lines
From: Guangming Cao <[email protected]>
Current flow, one dmabuf maybe call cache sync many times if it has beed mapped more than one time.
Well I'm not an expert on DMA heaps, but this will most likely not work correctly.
Quoted 2 lines
Is there any case that attachments of one dmabuf will points to different memory? If not, seems do sync only one time is more better.
I think that this can happen, yes.
Christian.
Quoted 38 lines
Signed-off-by Guangming Cao <[email protected]>--- drivers/dma-buf/heaps/system_heap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/dma-buf/heaps/system_heap.c +8
-6@@ -162,9 +162,10 @@ static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,invalidate_kernel_vmap_range (buffer->vaddr, buffer->len);list_for_each_entry (a, &buffer->attachments, list) { -if (!a->mapped) -continue ; -dma_sync_sgtable_for_cpu (a->dev, a->table, direction); +if (a->mapped) { +dma_sync_sgtable_for_cpu (a->dev, a->table, direction); +break ; + } }mutex_unlock (&buffer->lock);@@ -183,9 +184,10 @@ static int system_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf,flush_kernel_vmap_range (buffer->vaddr, buffer->len);list_for_each_entry (a, &buffer->attachments, list) { -if (!a->mapped) -continue ; -dma_sync_sgtable_for_device (a->dev, a->table, direction); +if (!a->mapped) { +dma_sync_sgtable_for_device (a->dev, a->table, direction); +break ; + } }mutex_unlock (&buffer->lock);
From: Guangming Cao <[email protected]>
Quoted 9 lines
Am 30.08.21 um 12:01 schrieb [email protected]:
Quoted 4 lines
From: Guangming Cao <[email protected]>
Current flow, one dmabuf maybe call cache sync many times if it has beed mapped more than one time.
Well I'm not an expert on DMA heaps, but this will most likely not work correctly.
All attachments of one dmabuf will add into a list, I think it means dmabuf supports map more than one time. Could you tell me more about it?
Quoted 7 lines
Quoted 2 lines
Is there any case that attachments of one dmabuf will points to different memory? If not, seems do sync only one time is more better.
I think that this can happen, yes.
Christian.
Seems it's a very special case on Android, if you don't mind, could you tell me more about it?
Quoted 39 lines
Quoted 39 lines
Signed-off-by Guangming Cao <[email protected]>--- drivers/dma-buf/heaps/system_heap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/dma-buf/heaps/system_heap.c +8
-6@@ -162,9 +162,10 @@ static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,invalidate_kernel_vmap_range (buffer->vaddr, buffer->len);list_for_each_entry (a, &buffer->attachments, list) { -if (!a->mapped) -continue ; -dma_sync_sgtable_for_cpu (a->dev, a->table, direction); +if (a->mapped) { +dma_sync_sgtable_for_cpu (a->dev, a->table, direction); +break ; + } }mutex_unlock (&buffer->lock);@@ -183,9 +184,10 @@ static int system_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf,flush_kernel_vmap_range (buffer->vaddr, buffer->len);list_for_each_entry (a, &buffer->attachments, list) { -if (!a->mapped) -continue ; -dma_sync_sgtable_for_device (a->dev, a->table, direction); +if (!a->mapped) { +dma_sync_sgtable_for_device (a->dev, a->table, direction); +break ; + } }mutex_unlock (&buffer->lock);
Christian König
maintainerAm 31.08.21 um 05:44 schrieb [email protected]:
Quoted 5 lines
From: Guangming Cao <[email protected]>
Quoted 3 lines
Am 30.08.21 um 12:01 schrieb [email protected]:
Quoted 2 lines
From: Guangming Cao <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Current flow, one dmabuf maybe call cache sync many times if it has beed mapped more than one time.
Well I'm not an expert on DMA heaps, but this will most likely not work correctly.
All attachments of one dmabuf will add into a list, I think it means dmabuf supports map more than one time. Could you tell me more about it?
Yes, that's correct and all of those needs to be synced as far as I know.
See the dma_sync_sgtable_for_cpu() is intentionally for each SG table given out.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Is there any case that attachments of one dmabuf will points to different memory? If not, seems do sync only one time is more better.
I think that this can happen, yes.
Christian.
Seems it's a very special case on Android, if you don't mind, could you tell me more about it?
That might be the case, nevertheless this change here is illegal from the DMA API point of view as far as I can see.
Regards,
Christian.
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Signed-off-by Guangming Cao <[email protected]>--- drivers/dma-buf/heaps/system_heap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/dma-buf/heaps/system_heap.c +8
-6@@ -162,9 +162,10 @@ static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,invalidate_kernel_vmap_range (buffer->vaddr, buffer->len);list_for_each_entry (a, &buffer->attachments, list) { -if (!a->mapped) -continue ; -dma_sync_sgtable_for_cpu (a->dev, a->table, direction); +if (a->mapped) { +dma_sync_sgtable_for_cpu (a->dev, a->table, direction); +break ; + } }mutex_unlock (&buffer->lock);@@ -183,9 +184,10 @@ static int system_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf,flush_kernel_vmap_range (buffer->vaddr, buffer->len);list_for_each_entry (a, &buffer->attachments, list) { -if (!a->mapped) -continue ; -dma_sync_sgtable_for_device (a->dev, a->table, direction); +if (!a->mapped) { +dma_sync_sgtable_for_device (a->dev, a->table, direction); +break ; + } }mutex_unlock (&buffer->lock);