* [v3 1/4] ARM: dma-mapping: atomic_pool with struct page **pages
2012-08-24 8:29 [v3 0/4] ARM: dma-mapping: IOMMU atomic allocation Hiroshi Doyu
@ 2012-08-24 8:29 ` Hiroshi Doyu
2012-08-24 11:13 ` Konrad Rzeszutek Wilk
2012-08-24 8:29 ` [v3 2/4] ARM: dma-mapping: Refactor out to introduce __in_atomic_pool Hiroshi Doyu
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Hiroshi Doyu @ 2012-08-24 8:29 UTC (permalink / raw)
To: m.szyprowski
Cc: Hiroshi Doyu, linux-arm-kernel, linaro-mm-sig, linux-mm,
linux-kernel, kyungmin.park, arnd, linux, chunsang.jeong, vdumpa,
konrad.wilk, subashrp, minchan, pullip.cho
struct page **pages is necessary to align with non atomic path in
__iommu_get_pages(). atomic_pool() has the intialized **pages instead
of just *page.
Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
---
arch/arm/mm/dma-mapping.c | 17 +++++++++++++----
1 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 601da7a..b14ee64 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -296,7 +296,7 @@ struct dma_pool {
unsigned long *bitmap;
unsigned long nr_pages;
void *vaddr;
- struct page *page;
+ struct page **pages;
};
static struct dma_pool atomic_pool = {
@@ -335,12 +335,16 @@ static int __init atomic_pool_init(void)
unsigned long nr_pages = pool->size >> PAGE_SHIFT;
unsigned long *bitmap;
struct page *page;
+ struct page **pages;
void *ptr;
int bitmap_size = BITS_TO_LONGS(nr_pages) * sizeof(long);
+ size_t size = nr_pages * sizeof(struct page *);
- bitmap = kzalloc(bitmap_size, GFP_KERNEL);
+ size += bitmap_size;
+ bitmap = kzalloc(size, GFP_KERNEL);
if (!bitmap)
goto no_bitmap;
+ pages = (void *)bitmap + bitmap_size;
if (IS_ENABLED(CONFIG_CMA))
ptr = __alloc_from_contiguous(NULL, pool->size, prot, &page);
@@ -348,9 +352,14 @@ static int __init atomic_pool_init(void)
ptr = __alloc_remap_buffer(NULL, pool->size, GFP_KERNEL, prot,
&page, NULL);
if (ptr) {
+ int i;
+
+ for (i = 0; i < nr_pages; i++)
+ pages[i] = page + i;
+
spin_lock_init(&pool->lock);
pool->vaddr = ptr;
- pool->page = page;
+ pool->pages = pages;
pool->bitmap = bitmap;
pool->nr_pages = nr_pages;
pr_info("DMA: preallocated %u KiB pool for atomic coherent allocations\n",
@@ -481,7 +490,7 @@ static void *__alloc_from_pool(size_t size, struct page **ret_page)
if (pageno < pool->nr_pages) {
bitmap_set(pool->bitmap, pageno, count);
ptr = pool->vaddr + PAGE_SIZE * pageno;
- *ret_page = pool->page + pageno;
+ *ret_page = pool->pages[pageno];
} else {
pr_err_once("ERROR: %u KiB atomic DMA coherent pool is too small!\n"
"Please increase it with coherent_pool= kernel parameter!\n",
--
1.7.5.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [v3 1/4] ARM: dma-mapping: atomic_pool with struct page **pages
2012-08-24 8:29 ` [v3 1/4] ARM: dma-mapping: atomic_pool with struct page **pages Hiroshi Doyu
@ 2012-08-24 11:13 ` Konrad Rzeszutek Wilk
2012-08-24 11:52 ` Hiroshi Doyu
0 siblings, 1 reply; 10+ messages in thread
From: Konrad Rzeszutek Wilk @ 2012-08-24 11:13 UTC (permalink / raw)
To: Hiroshi Doyu
Cc: m.szyprowski, linux-arm-kernel, linaro-mm-sig, linux-mm,
linux-kernel, kyungmin.park, arnd, linux, chunsang.jeong, vdumpa,
subashrp, minchan, pullip.cho
On Fri, Aug 24, 2012 at 11:29:02AM +0300, Hiroshi Doyu wrote:
> struct page **pages is necessary to align with non atomic path in
> __iommu_get_pages(). atomic_pool() has the intialized **pages instead
> of just *page.
>
> Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
> ---
> arch/arm/mm/dma-mapping.c | 17 +++++++++++++----
> 1 files changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index 601da7a..b14ee64 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -296,7 +296,7 @@ struct dma_pool {
> unsigned long *bitmap;
> unsigned long nr_pages;
> void *vaddr;
> - struct page *page;
> + struct page **pages;
> };
>
> static struct dma_pool atomic_pool = {
> @@ -335,12 +335,16 @@ static int __init atomic_pool_init(void)
> unsigned long nr_pages = pool->size >> PAGE_SHIFT;
> unsigned long *bitmap;
> struct page *page;
> + struct page **pages;
> void *ptr;
> int bitmap_size = BITS_TO_LONGS(nr_pages) * sizeof(long);
> + size_t size = nr_pages * sizeof(struct page *);
>
> - bitmap = kzalloc(bitmap_size, GFP_KERNEL);
> + size += bitmap_size;
> + bitmap = kzalloc(size, GFP_KERNEL);
> if (!bitmap)
> goto no_bitmap;
> + pages = (void *)bitmap + bitmap_size;
So you stuck a bitmap field in front of the array then?
Why not just define a structure where this is clearly defined
instead of doing the casting.
>
> if (IS_ENABLED(CONFIG_CMA))
> ptr = __alloc_from_contiguous(NULL, pool->size, prot, &page);
> @@ -348,9 +352,14 @@ static int __init atomic_pool_init(void)
> ptr = __alloc_remap_buffer(NULL, pool->size, GFP_KERNEL, prot,
> &page, NULL);
> if (ptr) {
> + int i;
> +
> + for (i = 0; i < nr_pages; i++)
> + pages[i] = page + i;
> +
> spin_lock_init(&pool->lock);
> pool->vaddr = ptr;
> - pool->page = page;
> + pool->pages = pages;
> pool->bitmap = bitmap;
> pool->nr_pages = nr_pages;
> pr_info("DMA: preallocated %u KiB pool for atomic coherent allocations\n",
> @@ -481,7 +490,7 @@ static void *__alloc_from_pool(size_t size, struct page **ret_page)
> if (pageno < pool->nr_pages) {
> bitmap_set(pool->bitmap, pageno, count);
> ptr = pool->vaddr + PAGE_SIZE * pageno;
> - *ret_page = pool->page + pageno;
> + *ret_page = pool->pages[pageno];
> } else {
> pr_err_once("ERROR: %u KiB atomic DMA coherent pool is too small!\n"
> "Please increase it with coherent_pool= kernel parameter!\n",
> --
> 1.7.5.4
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [v3 1/4] ARM: dma-mapping: atomic_pool with struct page **pages
2012-08-24 11:13 ` Konrad Rzeszutek Wilk
@ 2012-08-24 11:52 ` Hiroshi Doyu
2012-08-24 12:21 ` Marek Szyprowski
0 siblings, 1 reply; 10+ messages in thread
From: Hiroshi Doyu @ 2012-08-24 11:52 UTC (permalink / raw)
To: konrad.wilk@oracle.com
Cc: m.szyprowski@samsung.com, linux-arm-kernel@lists.infradead.org,
linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, kyungmin.park@samsung.com,
arnd@arndb.de, linux@arm.linux.org.uk, chunsang.jeong@linaro.org,
Krishna Reddy, subashrp@gmail.com, minchan@kernel.org,
pullip.cho@samsung.com
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> wrote @ Fri, 24 Aug 2012 13:13:23 +0200:
> On Fri, Aug 24, 2012 at 11:29:02AM +0300, Hiroshi Doyu wrote:
> > struct page **pages is necessary to align with non atomic path in
> > __iommu_get_pages(). atomic_pool() has the intialized **pages instead
> > of just *page.
> >
> > Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
> > ---
> > arch/arm/mm/dma-mapping.c | 17 +++++++++++++----
> > 1 files changed, 13 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> > index 601da7a..b14ee64 100644
> > --- a/arch/arm/mm/dma-mapping.c
> > +++ b/arch/arm/mm/dma-mapping.c
> > @@ -296,7 +296,7 @@ struct dma_pool {
> > unsigned long *bitmap;
> > unsigned long nr_pages;
> > void *vaddr;
> > - struct page *page;
> > + struct page **pages;
> > };
> >
> > static struct dma_pool atomic_pool = {
> > @@ -335,12 +335,16 @@ static int __init atomic_pool_init(void)
> > unsigned long nr_pages = pool->size >> PAGE_SHIFT;
> > unsigned long *bitmap;
> > struct page *page;
> > + struct page **pages;
> > void *ptr;
> > int bitmap_size = BITS_TO_LONGS(nr_pages) * sizeof(long);
> > + size_t size = nr_pages * sizeof(struct page *);
> >
> > - bitmap = kzalloc(bitmap_size, GFP_KERNEL);
> > + size += bitmap_size;
> > + bitmap = kzalloc(size, GFP_KERNEL);
> > if (!bitmap)
> > goto no_bitmap;
> > + pages = (void *)bitmap + bitmap_size;
>
> So you stuck a bitmap field in front of the array then?
> Why not just define a structure where this is clearly defined
> instead of doing the casting.
I just wanted to allocate only once for the members "pool->bitmap" and
"pool->pages" at once. Since the size of a whole bitmap isn't known in
advance, I couldn't find any fixed type for this bitmap, which pointer
can be shifted without casting. IOW, they are variable length.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [v3 1/4] ARM: dma-mapping: atomic_pool with struct page **pages
2012-08-24 11:52 ` Hiroshi Doyu
@ 2012-08-24 12:21 ` Marek Szyprowski
0 siblings, 0 replies; 10+ messages in thread
From: Marek Szyprowski @ 2012-08-24 12:21 UTC (permalink / raw)
To: 'Hiroshi Doyu', konrad.wilk
Cc: linux-arm-kernel, linaro-mm-sig, linux-mm, linux-kernel,
kyungmin.park, arnd, linux, chunsang.jeong,
'Krishna Reddy', subashrp, minchan, pullip.cho
Hello,
On Friday, August 24, 2012 1:52 PM Hiroshi Doyu wrote:
> Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> wrote @ Fri, 24 Aug 2012 13:13:23 +0200:
>
> > On Fri, Aug 24, 2012 at 11:29:02AM +0300, Hiroshi Doyu wrote:
> > > struct page **pages is necessary to align with non atomic path in
> > > __iommu_get_pages(). atomic_pool() has the intialized **pages instead
> > > of just *page.
> > >
> > > Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
> > > ---
> > > arch/arm/mm/dma-mapping.c | 17 +++++++++++++----
> > > 1 files changed, 13 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> > > index 601da7a..b14ee64 100644
> > > --- a/arch/arm/mm/dma-mapping.c
> > > +++ b/arch/arm/mm/dma-mapping.c
> > > @@ -296,7 +296,7 @@ struct dma_pool {
> > > unsigned long *bitmap;
> > > unsigned long nr_pages;
> > > void *vaddr;
> > > - struct page *page;
> > > + struct page **pages;
> > > };
> > >
> > > static struct dma_pool atomic_pool = {
> > > @@ -335,12 +335,16 @@ static int __init atomic_pool_init(void)
> > > unsigned long nr_pages = pool->size >> PAGE_SHIFT;
> > > unsigned long *bitmap;
> > > struct page *page;
> > > + struct page **pages;
> > > void *ptr;
> > > int bitmap_size = BITS_TO_LONGS(nr_pages) * sizeof(long);
> > > + size_t size = nr_pages * sizeof(struct page *);
> > >
> > > - bitmap = kzalloc(bitmap_size, GFP_KERNEL);
> > > + size += bitmap_size;
> > > + bitmap = kzalloc(size, GFP_KERNEL);
> > > if (!bitmap)
> > > goto no_bitmap;
> > > + pages = (void *)bitmap + bitmap_size;
> >
> > So you stuck a bitmap field in front of the array then?
> > Why not just define a structure where this is clearly defined
> > instead of doing the casting.
>
> I just wanted to allocate only once for the members "pool->bitmap" and
> "pool->pages" at once. Since the size of a whole bitmap isn't known in
> advance, I couldn't find any fixed type for this bitmap, which pointer
> can be shifted without casting. IOW, they are variable length.
IMHO it is better to avoid any non-trivial things in generic arch code. Merging
those 2 allocations doesn't save any significant bit of memory and might confuse
someone. Better just allocate them separately.
Best regards
--
Marek Szyprowski
Samsung Poland R&D Center
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [v3 2/4] ARM: dma-mapping: Refactor out to introduce __in_atomic_pool
2012-08-24 8:29 [v3 0/4] ARM: dma-mapping: IOMMU atomic allocation Hiroshi Doyu
2012-08-24 8:29 ` [v3 1/4] ARM: dma-mapping: atomic_pool with struct page **pages Hiroshi Doyu
@ 2012-08-24 8:29 ` Hiroshi Doyu
2012-08-24 11:14 ` Konrad Rzeszutek Wilk
2012-08-24 8:29 ` [v3 3/4] ARM: dma-mapping: Introduce __atomic_get_pages() for __iommu_get_pages() Hiroshi Doyu
2012-08-24 8:29 ` [v3 4/4] ARM: dma-mapping: IOMMU allocates pages from atomic_pool with GFP_ATOMIC Hiroshi Doyu
3 siblings, 1 reply; 10+ messages in thread
From: Hiroshi Doyu @ 2012-08-24 8:29 UTC (permalink / raw)
To: m.szyprowski
Cc: Hiroshi Doyu, linux-arm-kernel, linaro-mm-sig, linux-mm,
linux-kernel, kyungmin.park, arnd, linux, chunsang.jeong, vdumpa,
konrad.wilk, subashrp, minchan, pullip.cho
Check the given range("start", "size") is included in "atomic_pool" or not.
Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
---
arch/arm/mm/dma-mapping.c | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index b14ee64..508fde1 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -501,19 +501,32 @@ static void *__alloc_from_pool(size_t size, struct page **ret_page)
return ptr;
}
+static bool __in_atomic_pool(void *start, size_t size)
+{
+ struct dma_pool *pool = &atomic_pool;
+ void *end = start + size;
+ void *pool_start = pool->vaddr;
+ void *pool_end = pool->vaddr + pool->size;
+
+ if (start < pool_start || start > pool_end)
+ return false;
+
+ if (end > pool_end) {
+ WARN(1, "freeing wrong coherent size from pool\n");
+ return false;
+ }
+
+ return true;
+}
+
static int __free_from_pool(void *start, size_t size)
{
struct dma_pool *pool = &atomic_pool;
unsigned long pageno, count;
unsigned long flags;
- if (start < pool->vaddr || start > pool->vaddr + pool->size)
- return 0;
-
- if (start + size > pool->vaddr + pool->size) {
- WARN(1, "freeing wrong coherent size from pool\n");
+ if (!__in_atomic_pool(start, size))
return 0;
- }
pageno = (start - pool->vaddr) >> PAGE_SHIFT;
count = size >> PAGE_SHIFT;
--
1.7.5.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [v3 2/4] ARM: dma-mapping: Refactor out to introduce __in_atomic_pool
2012-08-24 8:29 ` [v3 2/4] ARM: dma-mapping: Refactor out to introduce __in_atomic_pool Hiroshi Doyu
@ 2012-08-24 11:14 ` Konrad Rzeszutek Wilk
2012-08-24 11:39 ` Hiroshi Doyu
0 siblings, 1 reply; 10+ messages in thread
From: Konrad Rzeszutek Wilk @ 2012-08-24 11:14 UTC (permalink / raw)
To: Hiroshi Doyu
Cc: m.szyprowski, linux-arm-kernel, linaro-mm-sig, linux-mm,
linux-kernel, kyungmin.park, arnd, linux, chunsang.jeong, vdumpa,
subashrp, minchan, pullip.cho
On Fri, Aug 24, 2012 at 11:29:03AM +0300, Hiroshi Doyu wrote:
> Check the given range("start", "size") is included in "atomic_pool" or not.
>
> Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
> ---
> arch/arm/mm/dma-mapping.c | 25 +++++++++++++++++++------
> 1 files changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index b14ee64..508fde1 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -501,19 +501,32 @@ static void *__alloc_from_pool(size_t size, struct page **ret_page)
> return ptr;
> }
>
> +static bool __in_atomic_pool(void *start, size_t size)
> +{
> + struct dma_pool *pool = &atomic_pool;
> + void *end = start + size;
> + void *pool_start = pool->vaddr;
> + void *pool_end = pool->vaddr + pool->size;
> +
> + if (start < pool_start || start > pool_end)
> + return false;
> +
> + if (end > pool_end) {
> + WARN(1, "freeing wrong coherent size from pool\n");
That does not tell what size or from what pool. Perhaps you should
include some details, such as the 'size' value, the pool used, the
range of the pool, etc. Something that will help _you_in the field
be able to narrow down what might be wrong.
> + return false;
> + }
> +
> + return true;
> +}
> +
> static int __free_from_pool(void *start, size_t size)
> {
> struct dma_pool *pool = &atomic_pool;
> unsigned long pageno, count;
> unsigned long flags;
>
> - if (start < pool->vaddr || start > pool->vaddr + pool->size)
> - return 0;
> -
> - if (start + size > pool->vaddr + pool->size) {
> - WARN(1, "freeing wrong coherent size from pool\n");
> + if (!__in_atomic_pool(start, size))
> return 0;
> - }
>
> pageno = (start - pool->vaddr) >> PAGE_SHIFT;
> count = size >> PAGE_SHIFT;
> --
> 1.7.5.4
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [v3 2/4] ARM: dma-mapping: Refactor out to introduce __in_atomic_pool
2012-08-24 11:14 ` Konrad Rzeszutek Wilk
@ 2012-08-24 11:39 ` Hiroshi Doyu
0 siblings, 0 replies; 10+ messages in thread
From: Hiroshi Doyu @ 2012-08-24 11:39 UTC (permalink / raw)
To: konrad.wilk@oracle.com
Cc: m.szyprowski@samsung.com, linux-arm-kernel@lists.infradead.org,
linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, kyungmin.park@samsung.com,
arnd@arndb.de, linux@arm.linux.org.uk, chunsang.jeong@linaro.org,
Krishna Reddy, subashrp@gmail.com, minchan@kernel.org,
pullip.cho@samsung.com
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> wrote @ Fri, 24 Aug 2012 13:14:55 +0200:
> On Fri, Aug 24, 2012 at 11:29:03AM +0300, Hiroshi Doyu wrote:
> > Check the given range("start", "size") is included in "atomic_pool" or not.
> >
> > Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
> > ---
> > arch/arm/mm/dma-mapping.c | 25 +++++++++++++++++++------
> > 1 files changed, 19 insertions(+), 6 deletions(-)
> >
> > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> > index b14ee64..508fde1 100644
> > --- a/arch/arm/mm/dma-mapping.c
> > +++ b/arch/arm/mm/dma-mapping.c
> > @@ -501,19 +501,32 @@ static void *__alloc_from_pool(size_t size, struct page **ret_page)
> > return ptr;
> > }
> >
> > +static bool __in_atomic_pool(void *start, size_t size)
> > +{
> > + struct dma_pool *pool = &atomic_pool;
> > + void *end = start + size;
> > + void *pool_start = pool->vaddr;
> > + void *pool_end = pool->vaddr + pool->size;
> > +
> > + if (start < pool_start || start > pool_end)
> > + return false;
> > +
> > + if (end > pool_end) {
> > + WARN(1, "freeing wrong coherent size from pool\n");
>
> That does not tell what size or from what pool. Perhaps you should
> include some details, such as the 'size' value, the pool used, the
> range of the pool, etc. Something that will help _you_in the field
> be able to narrow down what might be wrong.
True. I'll.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [v3 3/4] ARM: dma-mapping: Introduce __atomic_get_pages() for __iommu_get_pages()
2012-08-24 8:29 [v3 0/4] ARM: dma-mapping: IOMMU atomic allocation Hiroshi Doyu
2012-08-24 8:29 ` [v3 1/4] ARM: dma-mapping: atomic_pool with struct page **pages Hiroshi Doyu
2012-08-24 8:29 ` [v3 2/4] ARM: dma-mapping: Refactor out to introduce __in_atomic_pool Hiroshi Doyu
@ 2012-08-24 8:29 ` Hiroshi Doyu
2012-08-24 8:29 ` [v3 4/4] ARM: dma-mapping: IOMMU allocates pages from atomic_pool with GFP_ATOMIC Hiroshi Doyu
3 siblings, 0 replies; 10+ messages in thread
From: Hiroshi Doyu @ 2012-08-24 8:29 UTC (permalink / raw)
To: m.szyprowski
Cc: Hiroshi Doyu, linux-arm-kernel, linaro-mm-sig, linux-mm,
linux-kernel, kyungmin.park, arnd, linux, chunsang.jeong, vdumpa,
konrad.wilk, subashrp, minchan, pullip.cho
Support atomic allocation in __iommu_get_pages().
Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
---
arch/arm/mm/dma-mapping.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 508fde1..58a852b 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -501,6 +501,15 @@ static void *__alloc_from_pool(size_t size, struct page **ret_page)
return ptr;
}
+static struct page **__atomic_get_pages(void *addr)
+{
+ struct dma_pool *pool = &atomic_pool;
+ struct page **pages = pool->pages;
+ int offs = (addr - pool->vaddr) >> PAGE_SHIFT;
+
+ return pages + offs;
+}
+
static bool __in_atomic_pool(void *start, size_t size)
{
struct dma_pool *pool = &atomic_pool;
@@ -1184,6 +1193,9 @@ static struct page **__iommu_get_pages(void *cpu_addr, struct dma_attrs *attrs)
{
struct vm_struct *area;
+ if (__in_atomic_pool(cpu_addr, PAGE_SIZE))
+ return __atomic_get_pages(cpu_addr);
+
if (dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, attrs))
return cpu_addr;
--
1.7.5.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [v3 4/4] ARM: dma-mapping: IOMMU allocates pages from atomic_pool with GFP_ATOMIC
2012-08-24 8:29 [v3 0/4] ARM: dma-mapping: IOMMU atomic allocation Hiroshi Doyu
` (2 preceding siblings ...)
2012-08-24 8:29 ` [v3 3/4] ARM: dma-mapping: Introduce __atomic_get_pages() for __iommu_get_pages() Hiroshi Doyu
@ 2012-08-24 8:29 ` Hiroshi Doyu
3 siblings, 0 replies; 10+ messages in thread
From: Hiroshi Doyu @ 2012-08-24 8:29 UTC (permalink / raw)
To: m.szyprowski
Cc: Hiroshi Doyu, linux-arm-kernel, linaro-mm-sig, linux-mm,
linux-kernel, kyungmin.park, arnd, linux, chunsang.jeong, vdumpa,
konrad.wilk, subashrp, minchan, pullip.cho
Make use of the same atomic pool as DMA does, and skip a kernel page
mapping which can involve sleep'able operations at allocating a kernel
page table.
Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
---
arch/arm/mm/dma-mapping.c | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 58a852b..3ce152a 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1205,6 +1205,34 @@ static struct page **__iommu_get_pages(void *cpu_addr, struct dma_attrs *attrs)
return NULL;
}
+static void *__iommu_alloc_atomic(struct device *dev, size_t size,
+ dma_addr_t *handle)
+{
+ struct page *page;
+ void *addr;
+
+ addr = __alloc_from_pool(size, &page);
+ if (!addr)
+ return NULL;
+
+ *handle = __iommu_create_mapping(dev, &page, size);
+ if (*handle == DMA_ERROR_CODE)
+ goto err_mapping;
+
+ return addr;
+
+err_mapping:
+ __free_from_pool(addr, size);
+ return NULL;
+}
+
+static void __iommu_free_atomic(struct device *dev, struct page **pages,
+ dma_addr_t handle, size_t size)
+{
+ __iommu_remove_mapping(dev, handle, size);
+ __free_from_pool(page_address(pages[0]), size);
+}
+
static void *arm_iommu_alloc_attrs(struct device *dev, size_t size,
dma_addr_t *handle, gfp_t gfp, struct dma_attrs *attrs)
{
@@ -1215,6 +1243,9 @@ static void *arm_iommu_alloc_attrs(struct device *dev, size_t size,
*handle = DMA_ERROR_CODE;
size = PAGE_ALIGN(size);
+ if (gfp & GFP_ATOMIC)
+ return __iommu_alloc_atomic(dev, size, handle);
+
pages = __iommu_alloc_buffer(dev, size, gfp);
if (!pages)
return NULL;
@@ -1281,6 +1312,11 @@ void arm_iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr,
return;
}
+ if (__in_atomic_pool(cpu_addr, size)) {
+ __iommu_free_atomic(dev, pages, handle, size);
+ return;
+ }
+
if (!dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, attrs)) {
unmap_kernel_range((unsigned long)cpu_addr, size);
vunmap(cpu_addr);
--
1.7.5.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 10+ messages in thread