MA-21654 Use dma_alloc_pages in vb2_dma_sg_alloc_compacted
Subsystems (3)
PATCH 1/1 MA-21654 Use dma_alloc_pages in vb2_dma_sg_alloc_compacted
On system with "CONFIG_ZONE_DMA32=y", if the allocated physical address is greater than 4G, swiotlb will be used. It will lead below defects.
1) Impact performance due to an extra memcpy.
2) May meet below error due to swiotlb_max_mapping_size()
is 256K (IO_TLB_SIZE * IO_TLB_SEGSIZE).
"swiotlb buffer is full (sz: 393216 bytes), total 65536 (slots), used 2358 (slots)"
To avoid those defects, use dma_alloc_pages() instead of alloc_pages() in vb2_dma_sg_alloc_compacted().
--- drivers/media/common/videobuf2/videobuf2-dma-sg.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/media/common/videobuf2/videobuf2-dma-sg.c +7 -4
@@ -58,7 +58,7 @@ struct vb2_dma_sg_buf {static void vb2_dma_sg_put (void *buf_priv);static int vb2_dma_sg_alloc_compacted (struct vb2_dma_sg_buf *buf, -gfp_t gfp_flags) +gfp_t gfp_flags,struct device *dev) {unsigned int last_page =0 ;unsigned long size = buf->size;
@@ -67,6 +67,7 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf,struct page *pages;int order;int i; +dma_addr_t dma_handle; order =get_order (size);/* Don't over allocate*/
@@ -75,8 +76,9 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, pages =NULL ;while (!pages) { - pages =alloc_pages (GFP_KERNEL | __GFP_ZERO | - __GFP_NOWARN | gfp_flags, order); + pages =dma_alloc_pages (dev,PAGE_SIZE << order, &dma_handle, +DMA_BIDIRECTIONAL , +GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | gfp_flags);if (pages)break ;
@@ -96,6 +98,7 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, }return 0 ; + } static void *vb2_dma_sg_alloc(struct vb2_buffer *vb, struct device *dev,
@@ -130,7 +133,7 @@ static void *vb2_dma_sg_alloc(struct vb2_buffer *vb, struct device *dev,if (!buf->pages) goto fail_pages_array_alloc; - ret =vb2_dma_sg_alloc_compacted (buf, vb->vb2_queue->gfp_flags); + ret =vb2_dma_sg_alloc_compacted (buf, vb->vb2_queue->gfp_flags, dev);if (ret) goto fail_pages_alloc;
Signature · 1 line
2.17.1
Quoted 7 lines · Fang Hui
On system with "
CONFIG_ZONE_DMA32=y", if the allocated physical address is greater than 4G, swiotlb will be used. It will lead below defects.
1) Impact performance due to an extra memcpy.
2) May meet below error due toswiotlb_max_mapping_size()
is 256K (IO_TLB_SIZE*IO_TLB_SEGSIZE).
"swiotlb buffer is full (sz: 393216 bytes), total 65536 (slots), used 2358 (slots)"
Quoted 5 lines
To avoid those defects, use
dma_alloc_pages()instead ofalloc_pages()invb2_dma_sg_alloc_compacted().Suggested-by Tomasz Figa <[email protected]>Signed-off-by Fang Hui <[email protected]>
---
Two things.
1. For dma_data_direction para (DMA_BIDIRECTIONAL is used) of dma_alloc_pages(), maybe better pass from callers? In DeviceAsWebcam case, it's DMA_TO_DEVICE.
2. "MA-21654" (NXP ticket number) should be removed in the comment, need I re-push or it will be done on your side, thanks!
BRs,
Fang Hui
Quoted 8 lines · Fang Hui
Two things.
1. Fordma_data_directionpara (DMA_BIDIRECTIONALis used) ofdma_alloc_pages(),
maybe better pass from callers? In DeviceAsWebcam case, it'sDMA_TO_DEVICE.2. "MA-21654" (NXP ticket number) should be removed in the comment, need I re-push or it will be done on your side, thanks!
Keep google friends in the loop.
BRs,
Fang Hui
Quoted 10 lines · Fang Hui
---
Two things.
1. Fordma_data_directionpara (DMA_BIDIRECTIONALis used) ofdma_alloc_pages(),
maybe better pass from callers? In DeviceAsWebcam case, it'sDMA_TO_DEVICE.2. "MA-21654" (NXP ticket number) should be removed in the comment, need I re-push or it will be done on your side, thanks!
Another concern is that DMA memory is used up. Maybe first try allocating low buffer, if failed, fall back to high buffer.
BRs,
Fang Hui
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Fang,
kernel test robot noticed the following build errors:
[auto build test ERROR on media-tree/master]
[also build test ERROR on linus/master v6.6-rc2 next-20230918] [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#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Fang-Hui/MA-21654-Use-dma_alloc_pages-in-vb2_dma_sg_alloc_compacted/20230914-154333 base: git://linuxtv.org/media_tree.git master patch link: https://lore.kernel.org/r/20230914145812.12851-1-hui.fang%40nxp.com patch subject: [PATCH] MA-21654 Use dma_alloc_pages in vb2_dma_sg_alloc_compacted config: sh-randconfig-002-20230919 (https://download.01.org/0day-ci/archive/20230919/[email protected]/config) compiler: sh4-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230919/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
sh4-linux-ld: drivers/media/i2c/tc358746.o: in function `tc358746_probe':
tc358746.c:(.text+0x1b8c): undefined reference to `devm_clk_hw_register'
sh4-linux-ld: tc358746.c:(.text+0x1b90): undefined reference to `devm_of_clk_add_hw_provider'
sh4-linux-ld: tc358746.c:(.text+0x1b94): undefined reference to `of_clk_hw_simple_get'
sh4-linux-ld: drivers/media/common/videobuf2/videobuf2-dma-sg.o: in function `vb2_dma_sg_alloc_compacted':
>> videobuf2-dma-sg.c:(.text+0x57c): undefined reference to `dma_alloc_pages'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 88 lines · kernel test robot
Hi Fang,
kernel test robot noticed the following build errors:
[auto build test ERROR on media-tree/master] [also build test ERROR on linus/master v6.6-rc2 next-20230918] [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.c/
om%2Fdocs%2Fgit-format-patch%23_base_tree_information&data=05%7C01% 7Chui.fang%40nxp.com%7C3c6f14962ebc4483235308dbb8a12782%7C686ea1d 3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638306774533762887%7CUnknow n%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haW wiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=4Xf2y8dA7JGZF4hlEMdnLIIK b%2FIH2NS612ZNFvblqqo%3D&reserved=0]url:
https://github.co/
m%2Fintel-lab-lkp%2Flinux%2Fcommits%2FFang-Hui%2FMA-21654-Use-dma_all oc_pages-in-vb2_dma_sg_alloc_compacted%2F20230914-154333&data=05%7 C01%7Chui.fang%40nxp.com%7C3c6f14962ebc4483235308dbb8a12782%7C68 6ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638306774533762887%7CU nknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik 1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=uPPbnMqqO1X55H7tC bOlsfuO46dcErvJLxNSG5BslrU%3D&reserved=0
base:git://linuxtv.org/media_tree.gitmaster
patch link:
https://lore.kern/
el.org%2Fr%2F20230914145812.12851-1-hui.fang%2540nxp.com&data=05%7C 01%7Chui.fang%40nxp.com%7C3c6f14962ebc4483235308dbb8a12782%7C686 ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638306774533762887%7CUn known%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1 haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=6dYF2kk5ba0TE0B2jZM hNWPRTkdn2zhWgQZ7LHTE1cE%3D&reserved=0
patch subject: [PATCH] MA-21654 Usedma_alloc_pagesinvb2_dma_sg_alloc_compacted
config: sh-randconfig-002-20230919
(https://downloa/
d.01.org%2F0day-ci%2Farchive%2F20230919%2F202309190740.sIUYQTIq-lkp% 40intel.com%2Fconfig&data=05%7C01%7Chui.fang%40nxp.com%7C3c6f14962 ebc4483235308dbb8a12782%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7 C0%7C638306774533762887%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C %7C&sdata=PMZX%2F9gMPOGxPnC5cVSABHqa4Xfd%2Fa6sgyjcghRqfoI%3D&r eserved=0)
compiler: sh4-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build):
(https://downloa/
d.01.org%2F0day-ci%2Farchive%2F20230919%2F202309190740.sIUYQTIq-lkp% 40intel.com%2Freproduce&data=05%7C01%7Chui.fang%40nxp.com%7C3c6f14 962ebc4483235308dbb8a12782%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C 0%7C0%7C638306774533762887%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC 4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7 C%7C%7C&sdata=6pzcKMI%2By2W1bpAjntJ7eizgiNmtcCG7ti4oEF3R01g%3D&r eserved=0)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Closes: | https://lore/ | .kernel.org%2Foe-kbuild-all%2F202309190740.sIUYQTIq-lkp%40intel.com%2F |&data=05%7C01%7Chui.fang%40nxp.com%7C3c6f14962ebc4483235308dbb8a 12782%
| 7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638306774533762887 %7CUnkn
| own%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1ha Wwi
| LCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=45a%2FVY%2Fu8axIKigPCE3e WEXinD1EG
| dQQu9TCnBZ%2BMI0%3D&reserved=0All errors (new ones prefixed by >>):
sh4-linux-ld: drivers/media/i2c/tc358746.o: in function `tc358746_probe': tc358746.c:(.text+0x1b8c): undefined reference to `devm_clk_hw_register' sh4-linux-ld: tc358746.c:(.text+0x1b90): undefined reference to`devm_of_clk_add_hw_provider'
sh4-linux-ld: tc358746.c:(.text+0x1b94): undefined reference to
`of_clk_hw_simple_get'
sh4-linux-ld:drivers/media/common/videobuf2/videobuf2-dma-sg.o: in
function `vb2_dma_sg_alloc_compacted':Quoted 1 line
Quoted 1 line
videobuf2-dma-sg.c:(.text+0x57c): undefined reference to `dma_alloc_pages'
Quoted 9 lines
--
0-DAY CI Kernel Test Service
https://github.co/
m%2Fintel%2Flkp-tests%2Fwiki&data=05%7C01%7Chui.fang%40nxp.com%7C3c 6f14962ebc4483235308dbb8a12782%7C686ea1d3bc2b4c6fa92cd99c5c301635 %7C0%7C0%7C638306774533762887%7CUnknown%7CTWFpbGZsb3d8eyJWIjoi MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000 %7C%7C%7C&sdata=vA9h%2FGFfIel5hbcYVB0LgJGjHtDq1oF4SrfIvQcRm90%3D &reserved=0
I wonder if it's suitable to us the config (CONFIG_NO_DMA=y) to build? Also, there are other undefined references no related to the patch.
BRs,
Fang Hui
Le mardi 19 septembre 2023 à 06:43 +0000, Hui Fang a écrit :
Quoted 100 lines · kernel test robot
Quoted 88 lines
Hi Fang,
kernel test robot noticed the following build errors:
[auto build test ERROR on media-tree/master] [also build test ERROR on linus/master v6.6-rc2 next-20230918] [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.c/
om%2Fdocs%2Fgit-format-patch%23_base_tree_information&data=05%7C01% 7Chui.fang%40nxp.com%7C3c6f14962ebc4483235308dbb8a12782%7C686ea1d 3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638306774533762887%7CUnknow n%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haW wiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=4Xf2y8dA7JGZF4hlEMdnLIIK b%2FIH2NS612ZNFvblqqo%3D&reserved=0]url:
https://github.co/
m%2Fintel-lab-lkp%2Flinux%2Fcommits%2FFang-Hui%2FMA-21654-Use-dma_all oc_pages-in-vb2_dma_sg_alloc_compacted%2F20230914-154333&data=05%7 C01%7Chui.fang%40nxp.com%7C3c6f14962ebc4483235308dbb8a12782%7C68 6ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638306774533762887%7CU nknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik 1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=uPPbnMqqO1X55H7tC bOlsfuO46dcErvJLxNSG5BslrU%3D&reserved=0
base:git://linuxtv.org/media_tree.gitmaster
patch link:
https://lore.kern/
el.org%2Fr%2F20230914145812.12851-1-hui.fang%2540nxp.com&data=05%7C 01%7Chui.fang%40nxp.com%7C3c6f14962ebc4483235308dbb8a12782%7C686 ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638306774533762887%7CUn known%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1 haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=6dYF2kk5ba0TE0B2jZM hNWPRTkdn2zhWgQZ7LHTE1cE%3D&reserved=0
patch subject: [PATCH] MA-21654 Usedma_alloc_pagesinvb2_dma_sg_alloc_compacted
config: sh-randconfig-002-20230919
(https://downloa/
d.01.org%2F0day-ci%2Farchive%2F20230919%2F202309190740.sIUYQTIq-lkp% 40intel.com%2Fconfig&data=05%7C01%7Chui.fang%40nxp.com%7C3c6f14962 ebc4483235308dbb8a12782%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7 C0%7C638306774533762887%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C %7C&sdata=PMZX%2F9gMPOGxPnC5cVSABHqa4Xfd%2Fa6sgyjcghRqfoI%3D&r eserved=0)
compiler: sh4-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build):
(https://downloa/
d.01.org%2F0day-ci%2Farchive%2F20230919%2F202309190740.sIUYQTIq-lkp% 40intel.com%2Freproduce&data=05%7C01%7Chui.fang%40nxp.com%7C3c6f14 962ebc4483235308dbb8a12782%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C 0%7C0%7C638306774533762887%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC 4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7 C%7C%7C&sdata=6pzcKMI%2By2W1bpAjntJ7eizgiNmtcCG7ti4oEF3R01g%3D&r eserved=0)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
Quoted 5 lines
Reported-by kernel test robot <[email protected]>Closes:
https://lore/
.kernel.org%2Foe-kbuild-all%2F202309190740.sIUYQTIq-lkp%40intel.com%2F&data=05%7C01%7Chui.fang%40nxp.com%7C3c6f14962ebc4483235308dbb8a 12782%
Quoted 1 line
7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638306774533762887 %7CUnkn
Quoted 1 line
own%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1ha Wwi
Quoted 1 line
LCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=45a%2FVY%2Fu8axIKigPCE3e WEXinD1EG
Quoted 1 line
dQQu9TCnBZ%2BMI0%3D&reserved=0
All errors (new ones prefixed by >>):
sh4-linux-ld: drivers/media/i2c/tc358746.o: in function `tc358746_probe': tc358746.c:(.text+0x1b8c): undefined reference to `devm_clk_hw_register' sh4-linux-ld: tc358746.c:(.text+0x1b90): undefined reference to`devm_of_clk_add_hw_provider'
sh4-linux-ld: tc358746.c:(.text+0x1b94): undefined reference to
`of_clk_hw_simple_get'
sh4-linux-ld:drivers/media/common/videobuf2/videobuf2-dma-sg.o: in
function `vb2_dma_sg_alloc_compacted':Quoted 1 line
Quoted 1 line
videobuf2-dma-sg.c:(.text+0x57c): undefined reference to `dma_alloc_pages'
Quoted 9 lines
--
0-DAY CI Kernel Test Service
https://github.co/
m%2Fintel%2Flkp-tests%2Fwiki&data=05%7C01%7Chui.fang%40nxp.com%7C3c 6f14962ebc4483235308dbb8a12782%7C686ea1d3bc2b4c6fa92cd99c5c301635 %7C0%7C0%7C638306774533762887%7CUnknown%7CTWFpbGZsb3d8eyJWIjoi MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000 %7C%7C%7C&sdata=vA9h%2FGFfIel5hbcYVB0LgJGjHtDq1oF4SrfIvQcRm90%3D &reserved=0
Quoted 2 lines
I wonder if it's suitable to us the config (
CONFIG_NO_DMA=y) to build? Also, there are other undefined references no related to the patch.
May I suggest this ?
(quoted diff) +0 -0
b/drivers/media/common/videobuf2/Kconfig
index d2223a12c95f..7cf869e48246 100644
drivers/media/common/videobuf2/Kconfig +1 -0
@@ -26,6 +26,7 @@ config VIDEOBUF2_DMA_SG tristate select VIDEOBUF2_CORE select VIDEOBUF2_MEMOPS + select DMA_SHARED_BUFFER config VIDEOBUF2_DVB tristate
Quoted 3 lines
BRs,
Fang Hui
Tomasz Figa
maintainerHi Fang,
Quoted 2 lines · Fang Hui
On system with "
CONFIG_ZONE_DMA32=y", if the allocated physical address is
First of all, thanks a lot for the patch! Please check my review comments below.
Is CONFIG_ZONE_DMA32 really the factor that triggers the problem? My understanding was that the problem was that the hardware has 32-bit DMA, but the system has physical memory at addresses beyond the first 4G.
Quoted 7 lines
greater than 4G, swiotlb will be used. It will lead below defects.
1) Impact performance due to an extra memcpy.
2) May meet below error due toswiotlb_max_mapping_size()is 256K (IO_TLB_SIZE*IO_TLB_SEGSIZE).
"swiotlb buffer is full (sz: 393216 bytes), total 65536 (slots), used 2358 (slots)"
Quoted 9 lines
To avoid those defects, use
dma_alloc_pages()instead ofalloc_pages()invb2_dma_sg_alloc_compacted().Suggested-by Tomasz Figa <[email protected]>Signed-off-by Fang Hui <[email protected]>--- drivers/media/common/videobuf2/videobuf2-dma-sg.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
Please remove MA-21654 from the subject and prefix it with the right tags for the path (git log drivers/media/common/videobuf2 should be helpful to find the right one).
drivers/media/common/videobuf2/videobuf2-dma-sg.c struct vb2_dma_sg_buf { · line 61
Quoted 10 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-1@@ -58,7 +58,7 @@ struct vb2_dma_sg_buf {static void vb2_dma_sg_put (void *buf_priv);static int vb2_dma_sg_alloc_compacted (struct vb2_dma_sg_buf *buf, -gfp_t gfp_flags) +gfp_t gfp_flags,struct device *dev)
FWIW buf->dev already points to the right device - although we would need to move the assignment in vb2_dma_sg_alloc() to a place higher in that function before calling this function.
Quoted 12 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-0{unsigned int last_page =0 ;unsigned long size = buf->size;@@ -67,6 +67,7 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf,struct page *pages;int order;int i; +dma_addr_t dma_handle; order =get_order (size);/* Don't over allocate*/
drivers/media/common/videobuf2/videobuf2-dma-sg.c static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, · line 79
Quoted 6 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-2@@ -75,8 +76,9 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, pages =NULL ;while (!pages) { - pages =alloc_pages (GFP_KERNEL | __GFP_ZERO | - __GFP_NOWARN | gfp_flags, order); + pages = dma_alloc_pages(dev, PAGE_SIZE << order, &dma_handle,
Hmm, when I was proposing dma_alloc_pages(), I missed that it returns a DMA handle. That on its own can be handled by saving the returned handles somewhere in struct vb2_dma_sg_buf, but there is a bigger problem - the function would actually create a mapping if the DMA device requires some mapping management (e.g. is behind an IOMMU), which is undesirable, because we create the mapping ourselves below anyway...
@Christoph Hellwig @Robin Murphy I need your thoughts on this as well. Would it make sense to have a variant of dma_alloc_pages() that only allocates the pages, but doesn't perform the mapping? (Or a flag that tells the implementation to skip creating a mapping.)
drivers/media/common/videobuf2/videobuf2-dma-sg.c static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, · line 80
Quoted 1 line
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-0+ DMA_BIDIRECTIONAL,
The right value should be already available in buf->dma_dir.
drivers/media/common/videobuf2/videobuf2-dma-sg.c static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, · line 101
Quoted 9 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +2
-0+ GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | gfp_flags);if (pages)break ;@@ -96,6 +98,7 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, }return 0 ; +
Unnecessary blank line.
Quoted 13 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-2} static void *vb2_dma_sg_alloc(struct vb2_buffer *vb, struct device *dev,@@ -130,7 +133,7 @@ static void *vb2_dma_sg_alloc(struct vb2_buffer *vb, struct device *dev,if (!buf->pages) goto fail_pages_array_alloc; - ret =vb2_dma_sg_alloc_compacted (buf, vb->vb2_queue->gfp_flags); + ret =vb2_dma_sg_alloc_compacted (buf, vb->vb2_queue->gfp_flags, dev);if (ret) goto fail_pages_alloc; --
Quoted 2 lines
2.17.1
We also need to use dma_free_pages() to free the memory.
Best regards,
Tomasz
Quoted 3 lines · Tomasz Figa
Is
CONFIG_ZONE_DMA32really the factor that triggers the problem? My understanding was that the problem was that the hardware has 32-bit DMA, but the system has physical memory at addresses beyond the first 4G.
Yes, you are right. But CONFIG_ZONE_DMA32 may affect swiotlb_init_remap().
In arch/arm64/mm/init.c
static void __init zone_sizes_init(void)
{
......
#ifdef CONFIG_ZONE_DMA32 max_zone_pfns[ZONE_DMA32] = disable_dma32 ? 0 : PFN_DOWN(dma32_phys_limit); if (!arm64_dma_phys_limit) arm64_dma_phys_limit = dma32_phys_limit;
#endif
......
}
void __init mem_init(void)
{
swiotlb_init(max_pfn > PFN_DOWN(arm64_dma_phys_limit), SWIOTLB_VERBOSE);
}In kernel/dma/swiotlb.c
void __init swiotlb_init(bool addressing_limit, unsigned int flags)
{
swiotlb_init_remap(addressing_limit, flags, NULL);
}void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
int (*remap)(void *tlb, unsigned long nslabs))
{
struct io_tlb_mem *mem = &io_tlb_default_mem;
unsigned long nslabs;
size_t alloc_size;
size_t bytes;
void *tlb;
if (!addressing_limit && !swiotlb_force_bounce) return;
}
Also thanks for your suggestion, will refine my patch.
BRs,
Fang Hui
Robin Murphy
reviewerQuoted 4 lines · Tomasz Figa
Hi Fang,
Quoted 1 line · Fang Hui
Quoted 8 lines
Quoted 1 line
On system with "
CONFIG_ZONE_DMA32=y", if the allocated physical address isFirst of all, thanks a lot for the patch! Please check my review comments below.
Is
CONFIG_ZONE_DMA32really the factor that triggers the problem? My understanding was that the problem was that the hardware has 32-bit DMA, but the system has physical memory at addresses beyond the first 4G.
Indeed, without ZONE-DMA32 it would be difficult for any allocator to support this at all. SWIOTLB is merely a symptom - if it wasn't enabled, the dma_map_sgtable() operation would just fail entirely when any page is beyond the device's reach.
Quoted 63 lines
Quoted 7 lines
greater than 4G, swiotlb will be used. It will lead below defects.
1) Impact performance due to an extra memcpy.
2) May meet below error due toswiotlb_max_mapping_size()is 256K (IO_TLB_SIZE * IO_TLB_SEGSIZE)."swiotlb buffer is full (sz: 393216 bytes), total 65536 (slots), used 2358 (slots)"
Quoted 9 lines
To avoid those defects, use
dma_alloc_pages()instead ofalloc_pages()invb2_dma_sg_alloc_compacted().Suggested-by Tomasz Figa <[email protected]>Signed-off-by Fang Hui <[email protected]>--- drivers/media/common/videobuf2/videobuf2-dma-sg.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)Please remove MA-21654 from the subject and prefix it with the right tags for the path (
git log drivers/media/common/videobuf2should be helpful to find the right one).drivers/media/common/videobuf2/videobuf2-dma-sg.c struct vb2_dma_sg_buf { · line 61
Quoted 10 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-1@@ -58,7 +58,7 @@ struct vb2_dma_sg_buf {static void vb2_dma_sg_put (void *buf_priv);static int vb2_dma_sg_alloc_compacted (struct vb2_dma_sg_buf *buf, -gfp_t gfp_flags) +gfp_t gfp_flags,struct device *dev)FWIW
buf->devalready points to the right device - although we would need to move the assignment invb2_dma_sg_alloc()to a place higher in that function before calling this function.Quoted 12 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-0{unsigned int last_page =0 ;unsigned long size = buf->size;@@ -67,6 +67,7 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf,struct page *pages;int order;int i; +dma_addr_t dma_handle; order =get_order (size);/* Don't over allocate*/ drivers/media/common/videobuf2/videobuf2-dma-sg.c static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, · line 79
Quoted 6 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-2@@ -75,8 +76,9 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, pages =NULL ;while (!pages) { - pages =alloc_pages (GFP_KERNEL | __GFP_ZERO | - __GFP_NOWARN | gfp_flags, order); + pages = dma_alloc_pages(dev, PAGE_SIZE << order, &dma_handle,Hmm, when I was proposing
dma_alloc_pages(), I missed that it returns a DMA handle. That on its own can be handled by saving the returned handles somewhere in structvb2_dma_sg_buf, but there is a bigger problem - the function would actually create a mapping if the DMA device requires some mapping management (e.g. is behind an IOMMU), which is undesirable, because we create the mapping ourselves below anyway...
Quoted 4 lines
@Christoph Hellwig @Robin Murphy I need your thoughts on this as well. Would it make sense to have a variant of
dma_alloc_pages()that only allocates the pages, but doesn't perform the mapping? (Or a flag that tells the implementation to skip creating a mapping.)
As I mentioned before, I think it might make the most sense to make the whole thing into a "proper" dma_alloc_sgtable() function, which can then be used with dma_sync_sgtable_*() as dma_alloc_pages() is used with dma_sync_single_*() (and then dma_alloc_noncontiguous() clearly falls as the special in-between case).
Thanks,
Robin.
Quoted 36 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, · line 80
Quoted 1 line
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-0+ DMA_BIDIRECTIONAL,The right value should be already available in
buf->dma_dir.drivers/media/common/videobuf2/videobuf2-dma-sg.c static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, · line 101
Quoted 9 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +2
-0+ GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | gfp_flags);if (pages)break ;@@ -96,6 +98,7 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, }return 0 ; +Unnecessary blank line.
Quoted 13 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-2} static void *vb2_dma_sg_alloc(struct vb2_buffer *vb, struct device *dev,@@ -130,7 +133,7 @@ static void *vb2_dma_sg_alloc(struct vb2_buffer *vb, struct device *dev,if (!buf->pages) goto fail_pages_array_alloc; - ret =vb2_dma_sg_alloc_compacted (buf, vb->vb2_queue->gfp_flags); + ret =vb2_dma_sg_alloc_compacted (buf, vb->vb2_queue->gfp_flags, dev);if (ret) goto fail_pages_alloc; --Quoted 2 lines
2.17.1
We also need to use
dma_free_pages()to free the memory.Best regards,
Tomasz
Tomasz Figa
maintainerQuoted 88 lines · Robin Murphy
Quoted 4 lines · Tomasz Figa
Hi Fang,
Quoted 1 line · Fang Hui
Quoted 8 lines
Quoted 1 line
On system with "
CONFIG_ZONE_DMA32=y", if the allocated physical address isFirst of all, thanks a lot for the patch! Please check my review comments below.
Is
CONFIG_ZONE_DMA32really the factor that triggers the problem? My understanding was that the problem was that the hardware has 32-bit DMA, but the system has physical memory at addresses beyond the first 4G.Indeed, without ZONE-DMA32 it would be difficult for any allocator to support this at all. SWIOTLB is merely a symptom - if it wasn't enabled, the
dma_map_sgtable()operation would just fail entirely when any page is beyond the device's reach.Quoted 63 lines
Quoted 7 lines
greater than 4G, swiotlb will be used. It will lead below defects.
1) Impact performance due to an extra memcpy.
2) May meet below error due toswiotlb_max_mapping_size()is 256K (IO_TLB_SIZE * IO_TLB_SEGSIZE)."swiotlb buffer is full (sz: 393216 bytes), total 65536 (slots), used 2358 (slots)"
Quoted 9 lines
To avoid those defects, use
dma_alloc_pages()instead ofalloc_pages()invb2_dma_sg_alloc_compacted().Suggested-by Tomasz Figa <[email protected]>Signed-off-by Fang Hui <[email protected]>--- drivers/media/common/videobuf2/videobuf2-dma-sg.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)Please remove MA-21654 from the subject and prefix it with the right tags for the path (
git log drivers/media/common/videobuf2should be helpful to find the right one).drivers/media/common/videobuf2/videobuf2-dma-sg.c struct vb2_dma_sg_buf { · line 61
Quoted 10 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-1@@ -58,7 +58,7 @@ struct vb2_dma_sg_buf {static void vb2_dma_sg_put (void *buf_priv);static int vb2_dma_sg_alloc_compacted (struct vb2_dma_sg_buf *buf, -gfp_t gfp_flags) +gfp_t gfp_flags,struct device *dev)FWIW
buf->devalready points to the right device - although we would need to move the assignment invb2_dma_sg_alloc()to a place higher in that function before calling this function.Quoted 12 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-0{unsigned int last_page =0 ;unsigned long size = buf->size;@@ -67,6 +67,7 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf,struct page *pages;int order;int i; +dma_addr_t dma_handle; order =get_order (size);/* Don't over allocate*/ drivers/media/common/videobuf2/videobuf2-dma-sg.c static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, · line 79
Quoted 6 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-2@@ -75,8 +76,9 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, pages =NULL ;while (!pages) { - pages =alloc_pages (GFP_KERNEL | __GFP_ZERO | - __GFP_NOWARN | gfp_flags, order); + pages = dma_alloc_pages(dev, PAGE_SIZE << order, &dma_handle,Hmm, when I was proposing
dma_alloc_pages(), I missed that it returns a DMA handle. That on its own can be handled by saving the returned handles somewhere in structvb2_dma_sg_buf, but there is a bigger problem - the function would actually create a mapping if the DMA device requires some mapping management (e.g. is behind an IOMMU), which is undesirable, because we create the mapping ourselves below anyway...Quoted 4 lines
@Christoph Hellwig @Robin Murphy I need your thoughts on this as well. Would it make sense to have a variant of
dma_alloc_pages()that only allocates the pages, but doesn't perform the mapping? (Or a flag that tells the implementation to skip creating a mapping.)
Quoted 6 lines
As I mentioned before, I think it might make the most sense to make the whole thing into a "proper"
dma_alloc_sgtable()function, which can then be used with dma_sync_sgtable_*() asdma_alloc_pages()is used with dma_sync_single_*() (and thendma_alloc_noncontiguous()clearly falls as the special in-between case).
Okay, so that is the same thing that I was proposing from the beginning of the original thread that reported the swiotlb issues. Somehow I got convinced that it wasn't well received. Thanks for clarifying!
Then it sounds like we just need someone to implement it?
Let me CC +Sergey Senozhatsky for visibility as well.
Best regards,
Tomasz
Quoted 39 lines
Thanks,
Robin.Quoted 36 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, · line 80
Quoted 1 line
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-0+ DMA_BIDIRECTIONAL,The right value should be already available in
buf->dma_dir.drivers/media/common/videobuf2/videobuf2-dma-sg.c static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, · line 101
Quoted 9 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +2
-0+ GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | gfp_flags);if (pages)break ;@@ -96,6 +98,7 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, }return 0 ; +Unnecessary blank line.
Quoted 13 lines
drivers/media/common/videobuf2/videobuf2-dma-sg.c +1
-2} static void *vb2_dma_sg_alloc(struct vb2_buffer *vb, struct device *dev,@@ -130,7 +133,7 @@ static void *vb2_dma_sg_alloc(struct vb2_buffer *vb, struct device *dev,if (!buf->pages) goto fail_pages_array_alloc; - ret =vb2_dma_sg_alloc_compacted (buf, vb->vb2_queue->gfp_flags); + ret =vb2_dma_sg_alloc_compacted (buf, vb->vb2_queue->gfp_flags, dev);if (ret) goto fail_pages_alloc; --Quoted 2 lines
2.17.1
We also need to use
dma_free_pages()to free the memory.Best regards,
Tomasz
Quoted 5 lines · Robin Murphy
As I mentioned before, I think it might make the most sense to make the whole thing into a "proper"
dma_alloc_sgtable()function, which can then be used with dma_sync_sgtable_*() asdma_alloc_pages()is used with dma_sync_single_*() (and thendma_alloc_noncontiguous()clearly falls as the special in-between case).
Why not just use dma_alloc_noncontiguous if the caller wants an sgtable anyway?
Robin Murphy
reviewerQuoted 9 lines · Christoph Hellwig
Quoted 5 lines · Robin Murphy
As I mentioned before, I think it might make the most sense to make the whole thing into a "proper"
dma_alloc_sgtable()function, which can then be used with dma_sync_sgtable_*() asdma_alloc_pages()is used with dma_sync_single_*() (and thendma_alloc_noncontiguous()clearly falls as the special in-between case).Why not just use
dma_alloc_noncontiguousif the caller wants an sgtable anyway?
Because we don't need the restriction of the allocation being DMA-contiguous (and thus having to fall back to physically-contiguous in the absence of an IOMMU). That's what vb2_dma_contig already does, whereas IIUC vb2_dma_sg is for devices which can handle genuine scatter-gather DMA (and so are less likely to have an IOMMU, and more likely to need the best shot at piecing together large allocations).
Thanks,
Robin.
Quoted 11 lines · Robin Murphy
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Robin Murphy
As I mentioned before, I think it might make the most sense to make the whole thing into a "proper"
dma_alloc_sgtable()function, which can then be used with dma_sync_sgtable_*() asdma_alloc_pages()is used with dma_sync_single_*() (and thendma_alloc_noncontiguous()clearly falls as the special in-between case).Why not just use
dma_alloc_noncontiguousif the caller wants an sgtable anyway?
Quoted 6 lines
Because we don't need the restriction of the allocation being DMA-contiguous (and thus having to fall back to physically-contiguous in the absence of an IOMMU). That's what
vb2_dma_contigalready does, whereas IIUCvb2_dma_sgis for devices which can handle genuine scatter-gather DMA (and so are less likely to have an IOMMU, and more likely to need the best shot at piecing together large allocations).
Let's just extent dma_alloc_noncontiguous with a max_dma_segments parameter instead of adding yet another API.
Robin Murphy
reviewerQuoted 19 lines · Christoph Hellwig
Quoted 11 lines · Robin Murphy
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Robin Murphy
As I mentioned before, I think it might make the most sense to make the whole thing into a "proper"
dma_alloc_sgtable()function, which can then be used with dma_sync_sgtable_*() asdma_alloc_pages()is used with dma_sync_single_*() (and thendma_alloc_noncontiguous()clearly falls as the special in-between case).Why not just use
dma_alloc_noncontiguousif the caller wants an sgtable anyway?Quoted 6 lines
Because we don't need the restriction of the allocation being DMA-contiguous (and thus having to fall back to physically-contiguous in the absence of an IOMMU). That's what
vb2_dma_contigalready does, whereas IIUCvb2_dma_sgis for devices which can handle genuine scatter-gather DMA (and so are less likely to have an IOMMU, and more likely to need the best shot at piecing together large allocations).
Quoted 2 lines
Let's just extent
dma_alloc_noncontiguouswith amax_dma_segmentsparameter instead of adding yet another API.
Sure, that could work equally well, and might even help make its existing usage a bit clearer.
Cheers,
Robin.
Tomasz Figa
maintainerQuoted 20 lines · Robin Murphy
Quoted 19 lines · Christoph Hellwig
Quoted 17 lines · Robin Murphy
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Robin Murphy
As I mentioned before, I think it might make the most sense to make the whole thing into a "proper"
dma_alloc_sgtable()function, which can then be used with dma_sync_sgtable_*() asdma_alloc_pages()is used with dma_sync_single_*() (and thendma_alloc_noncontiguous()clearly falls as the special in-between case).Why not just use
dma_alloc_noncontiguousif the caller wants an sgtable anyway?Because we don't need the restriction of the allocation being DMA-contiguous (and thus having to fall back to physically-contiguous in the absence of an IOMMU). That's what
vb2_dma_contigalready does, whereas IIUCvb2_dma_sgis for devices which can handle genuine scatter-gather DMA (and so are less likely to have an IOMMU, and more likely to need the best shot at piecing together large allocations).
Quoted 5 lines
Quoted 2 lines
Let's just extent
dma_alloc_noncontiguouswith amax_dma_segmentsparameter instead of adding yet another API.Sure, that could work equally well, and might even help make its existing usage a bit clearer.
I have a crude (and untested) series of patches that extend dma_alloc_noncontiguous() with scatter-gather allocations according to the new max_dma_segments parameter.
Things that I don't like about it:
1) It adds more code than it removes (even if I factor in the custom allocation code removed from V4L2 vb2-dma-sg and dma-iommu).
2) The allocation scheme follows the current dma-iommu allocation code, which uses __GFP_NORETRY for allocation orders higher than the minimum allowed, which means that it's more likely to end up with smaller segments than the current vb2-dma-sg allocation code. However, I made it calculate the minimum order based on the allocation size and max_dma_segments, so it should still be able to satisfy the hardware constraints.
3) For platforms which use neither dma-direct nor dma-iommu (i.e. some custom platform-specific dma_map_ops), we don't have much of an idea on how to allocate the memory (but then neither vb2-dma-sg had), so it's assumed that plain alloc_pages_node() will just work.
4) ...and, some of those platforms (like ARM) may have their own IOMMU integration, which we have no idea about and we will unnecessarily allocate physically-contiguous memory.
Things that I like about it:
a) It basically reuses the allocation code from dma-iommu. (dma-iommu can be changed to call into dma_common_alloc_pages_noncontig().)
b) It handles most of the DMA constraints (GFP_DMA/32, max number of segments, max segment size), so one can use it quite confidently to allocate something that would work with their DMA engine without the need for swiotlb.
c) With it, I could remove the custom allocation from V4L2 vb2-dma-sg.
The following is just a snippet of the core code so you can tell me if it really makes sense going this way. If so, I can send a proper RFC with all the bits and also changes in the API users.
8<---
kernel/dma/direct.c +19 -0
@@ -7,6 +7,7 @@#include <linux/memblock.h> /* for max_pfn */ #include <linux/export.h> #include <linux/mm.h> +#include <linux/dma-mapping.h> #include <linux/dma-map-ops.h> #include <linux/scatterlist.h> #include <linux/pfn.h>
@@ -392,6 +393,24 @@ void dma_direct_free_pages(struct device *dev, size_t size,__dma_direct_free_pages (dev, page, size); } +struct sg_table *dma_direct_alloc_noncontiguous (struct device *dev,size_t size, +enum dma_data_direction dir,gfp_t gfp,unsigned long attrs, +unsigned int max_dma_segments) +{ +u64 phys_limit; + + gfp |=dma_direct_optimal_gfp_mask (dev, &phys_limit); + +return dma_common_alloc_noncontiguous (dev, size, dir, gfp, attrs, + max_dma_segments, phys_limit); +} + +void dma_direct_free_noncontiguous (struct device *dev,size_t size, +struct sg_table *sgt,enum dma_data_direction dir) +{ +dma_common_free_noncontiguous (dev, size, sgt, dir); +} +#if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE ) || \ defined(CONFIG_SWIOTLB ) void dma_direct_sync_sg_for_device(struct device *dev,
kernel/dma/mapping.c +13 -41
80 lines not on this page · raw message
kernel/dma/ops_helpers.c +203 -0
213 lines not on this page · raw message
-->8
Best,
Tomasz
Quoted 3 lines · Tomasz Figa
I have a crude (and untested) series of patches that extend
dma_alloc_noncontiguous()with scatter-gather allocations according to the newmax_dma_segmentsparameter.
Is the change merged? If merged, in which version, so I can test on my device. Thanks!
BRs,
Fang Hui
Tomasz Figa
maintainerQuoted 7 lines · Hui Fang
Quoted 3 lines · Tomasz Figa
I have a crude (and untested) series of patches that extend
dma_alloc_noncontiguous()with scatter-gather allocations according to the newmax_dma_segmentsparameter.Is the change merged? If merged, in which version, so I can test on my device. Thanks!
Sadly nothing really came out of it. The code I posted was just a quick attempt to implement what was suggested in the thread and still has some open items, which need some follow up. Maybe I should just go ahead and post it as a proper RFC series instead.
Quoted 10 lines · Tomasz Figa
Quoted 2 lines · Fang Hui
On system with "
CONFIG_ZONE_DMA32=y", if the allocated physical address isFirst of all, thanks a lot for the patch! Please check my review comments below.
Is
CONFIG_ZONE_DMA32really the factor that triggers the problem? My understanding was that the problem was that the hardware has 32-bit DMA, but the system has physical memory at addresses beyond the first 4G.
You should NEVER disable CONFIG_ZONE_DMA32 for a system that has memory > 4GB. I've made this point repeatedly, but the ARM64 maintainers insist on making it configurable instead of selecting it like most other 64-bit architetures that aren't guaranteed to always use a IOMMU.
We need to stop that.
Quoted 8 lines
Hmm, when I was proposing
dma_alloc_pages(), I missed that it returns a DMA handle. That on its own can be handled by saving the returned handles somewhere in structvb2_dma_sg_buf, but there is a bigger problem - the function would actually create a mapping if the DMA device requires some mapping management (e.g. is behind an IOMMU), which is undesirable, because we create the mapping ourselves below anyway...
Quoted 4 lines
@Christoph Hellwig @Robin Murphy I need your thoughts on this as well. Would it make sense to have a variant of
dma_alloc_pages()that only allocates the pages, but doesn't perform the mapping? (Or a flag that tells the implementation to skip creating a mapping.)
dma_map_pages needs to map the pages as part of finding out that the allocation actually works. So skipping it can't really be done.
So why do you want to create your own mapping anyway?