Skip to content

Commit

Permalink
staging: android: ion: do not clear dma_address of unmapped heap
Browse files Browse the repository at this point in the history
Since commit 54ef5b9 (staging: android: ion: Initialize dma_address
of new sg list") (Linux v4.17), the helper function dup_sg_table() called
by ion_dma_buf_attach() does not preserve the dma_address from the
original SG list. It is a problem for the unmapped heap, because
dma_buf_attach() followed by dma_buf_map_attachment() now returns a SG
table with NULL dma_address, which breaks tee_shm_register_fd().

This commit avoids the dma_address reset for the unmapped heap.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey960, SDP)
Tested-by: Etienne Carriere <etienne.carriere@linaro.org> (Qemu_v7/v8, SDP)
  • Loading branch information
jforissier authored and etienne-lms committed May 13, 2019
1 parent 17774a5 commit 9823b25
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/staging/android/ion/ion.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ static void ion_buffer_kmap_put(struct ion_buffer *buffer)
}
}

static struct sg_table *dup_sg_table(struct sg_table *table)
static struct sg_table *dup_sg_table(struct sg_table *table,
bool preserve_dma_address)
{
struct sg_table *new_table;
int ret, i;
Expand All @@ -190,7 +191,8 @@ static struct sg_table *dup_sg_table(struct sg_table *table)
new_sg = new_table->sgl;
for_each_sg(table->sgl, sg, table->nents, i) {
memcpy(new_sg, sg, sizeof(*sg));
new_sg->dma_address = 0;
if (!preserve_dma_address)
new_sg->dma_address = 0;
new_sg = sg_next(new_sg);
}

Expand Down Expand Up @@ -221,15 +223,15 @@ static int ion_dma_buf_attach(struct dma_buf *dmabuf,
if (!a)
return -ENOMEM;

table = dup_sg_table(buffer->sg_table);
if (buffer->heap->type == ION_HEAP_TYPE_UNMAPPED)
a->no_map = true;

table = dup_sg_table(buffer->sg_table, a->no_map);
if (IS_ERR(table)) {
kfree(a);
return -ENOMEM;
}

if (buffer->heap->type == ION_HEAP_TYPE_UNMAPPED)
a->no_map = true;

a->table = table;
a->dev = attachment->dev;
INIT_LIST_HEAD(&a->list);
Expand Down

0 comments on commit 9823b25

Please sign in to comment.