Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1195688 > unrolled thread

[PATCH] CMA: Don't return a valid cma for non-cma dev

Started byFeng Tang <feng.tang@intel.com>
First post2015-07-30 04:50 +0200
Last post2015-07-31 17:10 +0200
Articles 2 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] CMA: Don't return a valid cma for non-cma dev Feng Tang <feng.tang@intel.com> - 2015-07-30 04:50 +0200
    Re: [PATCH] CMA: Don't return a valid cma for non-cma dev Feng Tang <feng.tang@intel.com> - 2015-07-31 17:10 +0200

#1195688 — [PATCH] CMA: Don't return a valid cma for non-cma dev

FromFeng Tang <feng.tang@intel.com>
Date2015-07-30 04:50 +0200
Subject[PATCH] CMA: Don't return a valid cma for non-cma dev
Message-ID<pRM4W-1Xp-1@gated-at.bofh.it>
When system(one x86 soc) boot, we saw many normal dma allocation requests
goes to cma area. The call chain is
	dma_generic_alloc_coherent
	    dma_alloc_from_contiguous	-- arch/x86/kernel/pci-dma.c
	        cma_alloc(dev_get_cma_area(dev), count, align)

Current dev_get_cma_area() will return a valid "cma" anyway. Then all
these requests will be taken as valid cma request, and get pages from
cma area, which has 2 problems:
1. make the cma area fragmented
2. confuse the cma reservation, usually cma memory size is set according
   to the expectation of system scenario, these unexpected requests
   will affect the designed cma usage.

So this patch will enforce the judgement, and only return valid "cma"
for real cma user, thus make normal user like IO device driver not
abuse cma reserved region.

Signed-off-by: Feng Tang <feng.tang@intel.com>
---
 include/linux/dma-contiguous.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/dma-contiguous.h b/include/linux/dma-contiguous.h
index 569bbd0..d6ccc19 100644
--- a/include/linux/dma-contiguous.h
+++ b/include/linux/dma-contiguous.h
@@ -66,7 +66,8 @@ static inline struct cma *dev_get_cma_area(struct device *dev)
 {
 	if (dev && dev->cma_area)
 		return dev->cma_area;
-	return dma_contiguous_default_area;
+	else
+		return NULL;
 }
 
 static inline void dev_set_cma_area(struct device *dev, struct cma *cma)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1197084

FromFeng Tang <feng.tang@intel.com>
Date2015-07-31 17:10 +0200
Message-ID<pSk6C-Yx-21@gated-at.bofh.it>
In reply to#1195688
On Fri, Jul 31, 2015 at 02:05:17PM +0200, Michal Nazarewicz wrote:
> On Fri, Jul 31 2015, Feng Tang wrote:
> > Hi Michal Nazarewicz,
> >
> > Thanks for the review.
> >
> > On Thu, 2015-07-30 at 15:59 +0200, Michal Nazarewicz wrote:
> >> On Thu, Jul 30 2015, Feng Tang wrote:
> >> > When system(one x86 soc) boot, we saw many normal dma allocation requests
> >> > goes to cma area. The call chain is
> >> > 	dma_generic_alloc_coherent
> >> > 	    dma_alloc_from_contiguous	-- arch/x86/kernel/pci-dma.c
> >> > 	        cma_alloc(dev_get_cma_area(dev), count, align)
> >> >
> >> > Current dev_get_cma_area() will return a valid "cma" anyway. Then all
> >> > these requests will be taken as valid cma request, and get pages from
> >> > cma area, which has 2 problems:
> >> > 1. make the cma area fragmented
> >> > 2. confuse the cma reservation, usually cma memory size is set according
> >> >    to the expectation of system scenario, these unexpected requests
> >> >    will affect the designed cma usage.
> >> >
> >> > So this patch will enforce the judgement, and only return valid "cma"
> >> > for real cma user, thus make normal user like IO device driver not
> >> > abuse cma reserved region.
> >> 
> >> Just don’t set dma_contiguous_default_area.  This patch defeats the
> >> purpose of a *default* area.
> >
> > Yes! This is exactly what I tried when I first saw this problem, but
> > this failed as there 2 places inside drivers/base/dma-contiguous.c
> > which set the dma_contiguous_default_area
> >
> > 1) 
> > void __init dma_contiguous_reserve(phys_addr_t limit)
> > {
> >     ....
> >     dma_contiguous_reserve_area(selected_size, selected_base,
> >                                             selected_limit,
> >                                    &dma_contiguous_default_area,
> >                                             fixed);
> >      ....
> > }
> >
> > 2) 
> > static int __init rmem_cma_setup(struct reserved_mem *rmem)
> > {
> >     ...
> >     if (of_get_flat_dt_prop(node, "linux,cma-default", NULL))
> >                 dma_contiguous_set_default(cma);
> >     ...
> > }
> >
> > Are you suggesting me to remove them?
> 
> Set CONFIG_CMA_SIZE_MBYTES to zero (in Kconfig) or add ‘cma=0’ on
> command line, and don’t use ‘linux,cma-default’ in device tree.  Then
> you will end up with no default CMA area.

Maybe I didn't make my problem clear, for our platform, we do need
to use cma as we have camera ISP which has no IOMMU, so we cannot
set "cma=0".

The current situation is we have 2 kinds of request to call 
dma_alloc_from_contiguous():
1. Those general IO drivers like spi/i2c/emmc/audio which will
request 1 to dozen of pages for normal DMA use 
2. The camera ISP and other HW which needs from seveal MB to 
 20MB CMA buffer, total CMA number may reach 180MB or more

We don't want the 1st customers to go into CMA area, to fragment
the CMA area from time to time. That's why I finally came up
with this patch.

Any suggestions?

Thanks,
Feng


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web