Skip to contentSkip to conversation

dma-heap: Let dma heap use dma_map_attrs to map & unmap iova

PATCH New [email protected] 2 participants 8 messages Jul 8, 2021 – Aug 26, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-heap: Let dma heap use dma_map_attrs to map & unmap iova

From: Guangming Cao <[email protected]>

For dma-heap users, they can't bypass cache sync when map/unmap iova with dma heap. But they can do it by adding DMA_ATTR_SKIP_CPU_SYNC into dma_alloc_attrs.

To keep alignment, at dma_heap side, also use dma_buf_attachment.dma_map_attrs to do iova map & unmap.

---
 drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
 drivers/dma-buf/heaps/system_heap.c | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/dma-buf/heaps/cma_heap.c +4 -2
index 0c05b79870f9..2c9feb3bfc3e 100644
@@ -99,9 +99,10 @@ static struct sg_table *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = &a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(-ENOMEM);
 	a->mapped = true;
@@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
drivers/dma-buf/heaps/system_heap.c +4 -2
index 23a7e74ef966..fc7b1e02988e 100644
@@ -130,9 +130,10 @@ static struct sg_table *system_heap_map_dma_buf(struct dma_buf_attachment *attac
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(ret);
 
@@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				      enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 dma-heap: Let dma heap use dma_map_attrs to map & unmap iova

From: Guangming Cao <[email protected]>

On Thu, 2021-07-08 at 18:14 +0800, [email protected] wrote:

Hi Sumit, Christian, Matthias,

gentle ping for this patch :)

BRs!
Guangming

Quoted 84 lines

From: Guangming Cao <[email protected]>

For dma-heap users, they can't bypass cache sync when map/unmap iova with dma heap. But they can do it by adding DMA_ATTR_SKIP_CPU_SYNC into dma_alloc_attrs.

To keep alignment, at dma_heap side, also use dma_buf_attachment.dma_map_attrs to do iova map & unmap.

---
 drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
 drivers/dma-buf/heaps/system_heap.c | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/dma- renamed from drivers/dma-buf/heaps/cma_heap.c +0 -0

buf/heaps/cma_heap.c
index 0c05b79870f9..2c9feb3bfc3e 100644

drivers/dma-buf/heaps/cma_heap.c +2 -1
@@ -99,9 +99,10 @@ static struct sg_table
 *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = &a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction,
 attrs);
 	if (ret)
drivers/dma-buf/heaps/cma_heap.c +2 -1
 		return ERR_PTR(-ENOMEM);
 	a->mapped = true;
@@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct
 dma_buf_attachment *attachment,
 				   enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 

static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,

drivers/dma- renamed from drivers/dma-buf/heaps/system_heap.c +0 -0

buf/heaps/system_heap.c
index 23a7e74ef966..fc7b1e02988e 100644

drivers/dma-buf/heaps/system_heap.c +2 -1
@@ -130,9 +130,10 @@ static struct sg_table
 *system_heap_map_dma_buf(struct dma_buf_attachment *attac
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction,
 attrs);
 	if (ret)
drivers/dma-buf/heaps/system_heap.c +2 -1
 		return ERR_PTR(ret);
@@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct
 dma_buf_attachment *attachment,
 				      enum dma_data_direction
 direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }

static int system_heap_dma_buf_begin_cpu_access(struct dma_buf
*dmabuf,

Signature · 1 line
2.17.1
#2 lore raw

PATCH 1/1 dma-heap: Let dma heap use dma_map_attrs to map & unmap iova

From: Guangming Cao <[email protected]>

Quoted 7 lines · On Thu, 2021-07-15 at 14:24 +0800, [email protected] wrote:

From: Guangming Cao <[email protected]>

On Thu, 2021-07-08 at 18:14 +0800, [email protected] wrote:

Hi Sumit, Christian, Matthias,

gentle ping for this patch :)

move receviers to '--to' list.
gentle ping for this patch :)

Quoted 90 lines

BRs!
Guangming

Quoted 86 lines

From: Guangming Cao <[email protected]>

For dma-heap users, they can't bypass cache sync when map/unmap iova
with dma heap. But they can do it by adding DMA_ATTR_SKIP_CPU_SYNC into dma_alloc_attrs.

To keep alignment, at dma_heap side, also use dma_buf_attachment.dma_map_attrs to do iova map & unmap.

---
 drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
 drivers/dma-buf/heaps/system_heap.c | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/dma- renamed from drivers/dma-buf/heaps/cma_heap.c +0 -0

buf/heaps/cma_heap.c
index 0c05b79870f9..2c9feb3bfc3e 100644

drivers/dma-buf/heaps/cma_heap.c +2 -1
@@ -99,9 +99,10 @@ static struct sg_table
 *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = &a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction,
 attrs);
 	if (ret)
drivers/dma-buf/heaps/cma_heap.c +2 -1
 		return ERR_PTR(-ENOMEM);
 	a->mapped = true;
@@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct
 dma_buf_attachment *attachment,
 				   enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 

static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf
*dmabuf,

drivers/dma- renamed from drivers/dma-buf/heaps/system_heap.c +0 -0

buf/heaps/system_heap.c
index 23a7e74ef966..fc7b1e02988e 100644

drivers/dma-buf/heaps/system_heap.c +2 -1
@@ -130,9 +130,10 @@ static struct sg_table
 *system_heap_map_dma_buf(struct dma_buf_attachment *attac
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction,
 attrs);
 	if (ret)
drivers/dma-buf/heaps/system_heap.c +2 -1
 		return ERR_PTR(ret);
@@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct
 dma_buf_attachment *attachment,
 				      enum dma_data_direction
 direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }

static int system_heap_dma_buf_begin_cpu_access(struct dma_buf
*dmabuf,

Signature · 1 line
2.17.1
#3 lore raw

PATCH 1/1 dma_heap: enable map_attrs when (un)map_attachment

From: Guangming Cao <[email protected]>

For dma-heap users, they can't bypass cache sync when (un)map iova with dma heap. But they can do it by adding DMA_ATTR_SKIP_CPU_SYNC into dma_alloc_attrs.

To Keep alignment, add map_attrs support for dma_heap when (un)map_attachment.

---
 drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
 drivers/dma-buf/heaps/system_heap.c | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/dma-buf/heaps/cma_heap.c +4 -2
index 0c05b79870f9..2c9feb3bfc3e 100644
@@ -99,9 +99,10 @@ static struct sg_table *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = &a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(-ENOMEM);
 	a->mapped = true;
@@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
drivers/dma-buf/heaps/system_heap.c +4 -2
index 23a7e74ef966..fc7b1e02988e 100644
@@ -130,9 +130,10 @@ static struct sg_table *system_heap_map_dma_buf(struct dma_buf_attachment *attac
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(ret);
 
@@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				      enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH] dma_heap: enable map_attrs when (un)map_attachment

Thank you for the patch! Yet something to improve:

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.14-rc5 next-20210809]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/guangming-cao-mediatek-com/dma_heap-enable-map_attrs-when-un-map_attachment/20210810-100452
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 9a73fa375d58fee5262dd16473c8e7522bdf44de
config: alpha-buildonly-randconfig-r003-20210809 (attached as .config)
compiler: alpha-linux-gcc (GCC) 10.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/b1a5626566cf9a73b35a742151246017ac87556b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review guangming-cao-mediatek-com/dma_heap-enable-map_attrs-when-un-map_attachment/20210810-100452 git checkout b1a5626566cf9a73b35a742151246017ac87556b
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-10.3.0 make.cross O=build_dir ARCH=alpha SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/dma-buf/heaps/system_heap.c: In function 'system_heap_map_dma_buf':

>> drivers/dma-buf/heaps/system_heap.c:133:24: error: 'struct dma_buf_attachment' has no member named 'dma_map_attrs'
     133 |  int attrs = attachment->dma_map_attrs;
         |                        ^~
   drivers/dma-buf/heaps/system_heap.c: In function 'system_heap_unmap_dma_buf':
   drivers/dma-buf/heaps/system_heap.c:149:24: error: 'struct dma_buf_attachment' has no member named 'dma_map_attrs'
     149 |  int attrs = attachment->dma_map_attrs;
         |                        ^~

vim +133 drivers/dma-buf/heaps/system_heap.c

127
128 static struct sg_table *system_heap_map_dma_buf(struct dma_buf_attachment *attachment,
129 enum dma_data_direction direction)
130 {
131 struct dma_heap_attachment *a = attachment->priv;
132 struct sg_table *table = a->table;

 > 133		int attrs = attachment->dma_map_attrs;

134 int ret;
135
136 ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
137 if (ret)
138 return ERR_PTR(ret);
139
140 a->mapped = true;
141 return table;
142 }
143

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#5 lore raw

Re: [PATCH] dma_heap: enable map_attrs when (un)map_attachment

In reply to [email protected]
Thank you for the patch! Yet something to improve:

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.14-rc5 next-20210809]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/guangming-cao-mediatek-com/dma_heap-enable-map_attrs-when-un-map_attachment/20210810-100452
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 9a73fa375d58fee5262dd16473c8e7522bdf44de
config: x86_64-randconfig-a016-20210810 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 614c7d03877fd99c2de47429b15be3f00306a3bd)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/b1a5626566cf9a73b35a742151246017ac87556b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review guangming-cao-mediatek-com/dma_heap-enable-map_attrs-when-un-map_attachment/20210810-100452 git checkout b1a5626566cf9a73b35a742151246017ac87556b
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/dma-buf/heaps/cma_heap.c:102:26: error: no member named 'dma_map_attrs' in 'struct dma_buf_attachment'
           int attrs = attachment->dma_map_attrs;
                       ~~~~~~~~~~  ^
   drivers/dma-buf/heaps/cma_heap.c:117:26: error: no member named 'dma_map_attrs' in 'struct dma_buf_attachment'
           int attrs = attachment->dma_map_attrs;
                       ~~~~~~~~~~  ^

2 errors generated.

vim +102 drivers/dma-buf/heaps/cma_heap.c

96
97 static struct sg_table *cma_heap_map_dma_buf(struct dma_buf_attachment *attachment,
98 enum dma_data_direction direction)
99 {
100 struct dma_heap_attachment *a = attachment->priv;
101 struct sg_table *table = &a->table;

 > 102		int attrs = attachment->dma_map_attrs;

103 int ret;
104
105 ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
106 if (ret)
107 return ERR_PTR(-ENOMEM);
108 a->mapped = true;
109 return table;
110 }
111

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#6 lore raw

Re: [PATCH] dma_heap: enable map_attrs when (un)map_attachment

In reply to [email protected]
Thank you for the patch! Yet something to improve:

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.14-rc5 next-20210809]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/guangming-cao-mediatek-com/dma_heap-enable-map_attrs-when-un-map_attachment/20210810-100452
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 9a73fa375d58fee5262dd16473c8e7522bdf44de
config: hexagon-buildonly-randconfig-r002-20210809 (attached as .config)
compiler: clang version 12.0.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/b1a5626566cf9a73b35a742151246017ac87556b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review guangming-cao-mediatek-com/dma_heap-enable-map_attrs-when-un-map_attachment/20210810-100452 git checkout b1a5626566cf9a73b35a742151246017ac87556b
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=hexagon SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/dma-buf/heaps/system_heap.c:133:26: error: no member named 'dma_map_attrs' in 'struct dma_buf_attachment'
           int attrs = attachment->dma_map_attrs;
                       ~~~~~~~~~~  ^
   drivers/dma-buf/heaps/system_heap.c:149:26: error: no member named 'dma_map_attrs' in 'struct dma_buf_attachment'
           int attrs = attachment->dma_map_attrs;
                       ~~~~~~~~~~  ^

2 errors generated.

vim +133 drivers/dma-buf/heaps/system_heap.c

127
128 static struct sg_table *system_heap_map_dma_buf(struct dma_buf_attachment *attachment,
129 enum dma_data_direction direction)
130 {
131 struct dma_heap_attachment *a = attachment->priv;
132 struct sg_table *table = a->table;

 > 133		int attrs = attachment->dma_map_attrs;

134 int ret;
135
136 ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
137 if (ret)
138 return ERR_PTR(ret);
139
140 a->mapped = true;
141 return table;
142 }
143

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#7 lore raw

PATCH 1/1 dma-buf: Add support for mapping buffers with DMA attributes

In reply to [email protected]

From: Guangming Cao <[email protected]>

When mapping the memory represented by a dma-buf into a device's address space, it might be desireable to map the memory with certain DMA attributes. Thus, introduce the dma_mapping_attrs field in the dma_buf_attachment structure so that when the memory is mapped with dma_buf_map_attachment, it is mapped with the desired DMA attributes.

---
 drivers/dma-buf/heaps/cma_heap.c    | 6 ++++--
 drivers/dma-buf/heaps/system_heap.c | 6 ++++--
 include/linux/dma-buf.h             | 3 +++
 3 files changed, 11 insertions(+), 4 deletions(-)
drivers/dma-buf/heaps/cma_heap.c +4 -2
index 0c05b79870f9..2c9feb3bfc3e 100644
@@ -99,9 +99,10 @@ static struct sg_table *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = &a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(-ENOMEM);
 	a->mapped = true;
@@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
drivers/dma-buf/heaps/system_heap.c +4 -2
index 23a7e74ef966..fc7b1e02988e 100644
@@ -130,9 +130,10 @@ static struct sg_table *system_heap_map_dma_buf(struct dma_buf_attachment *attac
 {
 	struct dma_heap_attachment *a = attachment->priv;
 	struct sg_table *table = a->table;
+	int attrs = attachment->dma_map_attrs;
 	int ret;
 
-	ret = dma_map_sgtable(attachment->dev, table, direction, 0);
+	ret = dma_map_sgtable(attachment->dev, table, direction, attrs);
 	if (ret)
 		return ERR_PTR(ret);
 
@@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				      enum dma_data_direction direction)
 {
 	struct dma_heap_attachment *a = attachment->priv;
+	int attrs = attachment->dma_map_attrs;
 
 	a->mapped = false;
-	dma_unmap_sgtable(attachment->dev, table, direction, 0);
+	dma_unmap_sgtable(attachment->dev, table, direction, attrs);
 }
 
 static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
include/linux/dma-buf.h +3 -0
index efdc56b9d95f..4d650731766e 100644
@@ -379,6 +379,8 @@ struct dma_buf_attach_ops {
  * @importer_ops: importer operations for this attachment, if provided
  * dma_buf_map/unmap_attachment() must be called with the dma_resv lock held.
  * @importer_priv: importer specific attachment data.
+ * @dma_map_attrs: DMA attributes to be used when the exporter maps the buffer
+ * through dma_buf_map_attachment.
  *
  * This structure holds the attachment information between the dma_buf buffer
  * and its user device(s). The list contains one attachment struct per device
@@ -399,6 +401,7 @@ struct dma_buf_attachment {
 	const struct dma_buf_attach_ops *importer_ops;
 	void *importer_priv;
 	void *priv;
+	unsigned long dma_map_attrs;
 };
 
 /**
Signature · 1 line
2.17.1