From: Marek Szyprowski <m.szyprowski@samsung.com>
To: 'Hiroshi Doyu' <hdoyu@nvidia.com>, 'Krishna Reddy' <vdumpa@nvidia.com>
Cc: linux-arm-kernel@lists.infradead.org,
linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org,
linux-arch@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
iommu@lists.linux-foundation.org, shariq.hasnain@linaro.org,
arnd@arndb.de, benh@kernel.crashing.org,
kyungmin.park@samsung.com,
Andrzej Pietrasiewicz <andrzej.p@samsung.com>,
linux@arm.linux.org.uk, pullip.cho@samsung.com,
chunsang.jeong@linaro.org
Subject: RE: [PATCHv7 9/9] ARM: dma-mapping: add support for IOMMU mapper
Date: Wed, 07 Mar 2012 17:58:07 +0100 [thread overview]
Message-ID: <011701ccfc83$78030180$68090480$%szyprowski@samsung.com> (raw)
In-Reply-To: <20120307.091601.458605132780655792.hdoyu@nvidia.com>
Hello,
On Wednesday, March 07, 2012 8:16 AM Hiroshi Doyu wrote:
> From: Hiroshi DOYU <hdoyu@nvidia.com>
> Subject: Re: [PATCHv7 9/9] ARM: dma-mapping: add support for IOMMU mapper
> Date: Wed, 07 Mar 2012 08:37:06 +0200 (EET)
> Message-ID: <20120307.083706.2087121294965856946.hdoyu@nvidia.com>
>
> > From: Hiroshi DOYU <hdoyu@nvidia.com>
> > Subject: Re: [PATCHv7 9/9] ARM: dma-mapping: add support for IOMMU mapper
> > Date: Wed, 07 Mar 2012 08:09:52 +0200 (EET)
> > Message-ID: <20120307.080952.2152478004740487196.hdoyu@nvidia.com>
> >
> > > From: Krishna Reddy <vdumpa@nvidia.com>
> > > Subject: RE: [PATCHv7 9/9] ARM: dma-mapping: add support for IOMMU mapper
> > > Date: Tue, 6 Mar 2012 23:48:42 +0100
> > > Message-ID: <401E54CE964CD94BAE1EB4A729C7087E37970113FE@HQMAIL04.nvidia.com>
> > >
> > > > > > +struct dma_iommu_mapping *
> > > > > > +arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size,
> > > > > > + int order)
> > > > > > +{
> > > > > > + unsigned int count = (size >> PAGE_SHIFT) - order;
> > > > > > + unsigned int bitmap_size = BITS_TO_LONGS(count) * sizeof(long);
> > > >
> > > > The count calculation doesn't seem correct. "order" is log2 number and
> > > > size >> PAGE_SHIFT is number of pages.
> > > >
> > > > If size is passed as 64*4096(256KB) and order is 6(allocation granularity is 2^6
> pages=256KB),
> > > > just 1 bit is enough to manage allocations. So it should be 4 bytes or one long.
> > >
> > > Good catch!
> > >
> > > > But the calculation gives count = 64 - 6 = 58 and
> > > > Bitmap_size gets set to (58/(4*8)) * 4 = 8 bytes, which is incorrect.
> > >
> > > "order" isn't the order of size passed, which is minimal *page*
> > > allocation order which client decides whatever, just in case.
> > >
> > > > It should be as follows.
> > > > unsigned int count = 1 << get_order(size) - order;
> >
> > To be precise, as below?
> >
> > unsigned int count = 1 << (get_order(size) - order);
>
> This could be:
>
> From fd40740ef4bc4a3924fe1188ea6dd785be0fe859 Mon Sep 17 00:00:00 2001
> From: Hiroshi DOYU <hdoyu@nvidia.com>
> Date: Wed, 7 Mar 2012 08:14:38 +0200
> Subject: [PATCH 1/1] dma-mapping: Fix count calculation of iova space
>
> Fix count calculation of iova space.
> Pointed by Krishna Reddy <vdumpa@nvidia.com>
>
> Signed-off-by: Hiroshi DOYU <hdoyu@nvidia.com>
> ---
> arch/arm/mm/dma-mapping.c | 11 +++++++++--
> 1 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index 6c2f104..56f0af5 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -1483,11 +1483,18 @@ struct dma_iommu_mapping *
> arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size,
> int order)
> {
> - unsigned int count = (size >> PAGE_SHIFT) - order;
> - unsigned int bitmap_size = BITS_TO_LONGS(count) * sizeof(long);
> + unsigned int n, count;
> + unsigned int bitmap_size;
> struct dma_iommu_mapping *mapping;
> int err = -ENOMEM;
>
> + n = get_order(size);
> + if (n < order)
> + return ERR_PTR(-EINVAL);
> +
> + count = 1 << (n - order);
> + bitmap_size = BITS_TO_LONGS(count) * sizeof(long);
> +
> mapping = kzalloc(sizeof(struct dma_iommu_mapping), GFP_KERNEL);
> if (!mapping)
> goto err;
Thanks again for finding another bug. I thought that I've checked that code more
than twice, but it looks that I've missed something again.
IMHO the size of virtual memory area doesn't need to be aligned to the power of
two, so I will simplify it to the following code:
unsigned int count = size >> (PAGE_SHIFT + order);
unsigned int bitmap_size = BITS_TO_LONGS(count) * sizeof(long);
if (!count)
return ERR_PTR(-EINVAL);
...
Best regards
--
Marek Szyprowski
Samsung Poland R&D Center
next prev parent reply other threads:[~2012-03-07 16:58 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-29 15:04 [PATCHv7 0/9] ARM: DMA-mapping framework redesign Marek Szyprowski
2012-02-29 15:04 ` [PATCHv7 1/9] ARM: dma-mapping: introduce ARM_DMA_ERROR constant Marek Szyprowski
2012-02-29 15:04 ` [PATCHv7 2/9] ARM: dma-mapping: use pr_* instread of printk Marek Szyprowski
2012-02-29 15:04 ` Marek Szyprowski
2012-02-29 15:04 ` [PATCHv7 3/9] ARM: dma-mapping: remove offset parameter to prepare for generic dma_ops Marek Szyprowski
2012-02-29 15:04 ` Marek Szyprowski
[not found] ` <1330527862-16234-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-02-29 15:04 ` [PATCHv7 4/9] ARM: dma-mapping: use asm-generic/dma-mapping-common.h Marek Szyprowski
2012-02-29 15:04 ` Marek Szyprowski
2012-02-29 15:04 ` [PATCHv7 8/9] ARM: dma-mapping: use alloc, mmap, free from dma_ops Marek Szyprowski
2012-02-29 15:04 ` Marek Szyprowski
2012-03-22 13:45 ` Subash Patel
2012-03-23 12:12 ` Marek Szyprowski
2012-03-23 12:26 ` [PATCH 0/2] ARM: dma-mapping: Fix mmap support for coherent buffers Marek Szyprowski
2012-03-23 12:26 ` Marek Szyprowski
2012-03-23 12:26 ` [PATCH 1/2] common: add dma_mmap_from_coherent() function Marek Szyprowski
2012-03-23 12:26 ` Marek Szyprowski
2012-03-23 12:26 ` [PATCH 2/2] arm: dma-mapping: use dma_mmap_from_coherent() Marek Szyprowski
2012-03-23 12:26 ` Marek Szyprowski
[not found] ` <1332505563-17646-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-03-26 11:04 ` [PATCH 0/2] ARM: dma-mapping: Fix mmap support for coherent buffers Subash Patel
2012-03-26 11:04 ` Subash Patel
2012-02-29 15:04 ` [PATCHv7 5/9] ARM: dma-mapping: implement dma sg methods on top of any generic dma ops Marek Szyprowski
2012-02-29 15:04 ` Marek Szyprowski
2012-03-26 11:38 ` Subash Patel
2012-03-26 11:38 ` Subash Patel
2012-02-29 15:04 ` [PATCHv7 6/9] ARM: dma-mapping: move all dma bounce code to separate dma ops structure Marek Szyprowski
2012-02-29 15:04 ` [PATCHv7 7/9] ARM: dma-mapping: remove redundant code and cleanup Marek Szyprowski
2012-02-29 15:04 ` [PATCHv7 9/9] ARM: dma-mapping: add support for IOMMU mapper Marek Szyprowski
2012-03-02 8:05 ` KyongHo Cho
2012-03-02 8:05 ` KyongHo Cho
2012-03-02 11:07 ` Marek Szyprowski
2012-03-02 11:07 ` Marek Szyprowski
2012-03-20 13:50 ` Subash Patel
2012-03-20 13:50 ` Subash Patel
2012-03-20 23:56 ` KyongHo Cho
2012-03-20 23:56 ` KyongHo Cho
2012-03-22 13:59 ` Subash Patel
2012-03-22 13:59 ` Subash Patel
2012-03-30 7:14 ` Subash Patel
2012-03-30 7:14 ` Subash Patel
2012-03-05 11:47 ` Hiroshi Doyu
2012-03-05 11:47 ` Hiroshi Doyu
[not found] ` <20120305134721.0ab0d0e6de56fa30250059b1-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2012-03-05 16:07 ` Marek Szyprowski
2012-03-05 16:07 ` Marek Szyprowski
2012-03-06 22:48 ` Krishna Reddy
2012-03-06 22:48 ` Krishna Reddy
2012-03-07 6:09 ` Hiroshi Doyu
2012-03-07 6:09 ` Hiroshi Doyu
[not found] ` <20120307.080952.2152478004740487196.hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2012-03-07 6:37 ` Hiroshi Doyu
2012-03-07 6:37 ` Hiroshi Doyu
2012-03-07 7:06 ` Krishna Reddy
2012-03-07 7:06 ` Krishna Reddy
2012-03-07 7:16 ` Hiroshi Doyu
2012-03-07 7:16 ` Hiroshi Doyu
2012-03-07 16:58 ` Marek Szyprowski [this message]
2012-03-07 16:58 ` Marek Szyprowski
[not found] ` <011701ccfc83$78030180$68090480$%szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-03-09 14:53 ` [PATCH] ARM: dma-mapping: fix calculation of iova bitmap size Marek Szyprowski
2012-03-09 14:53 ` Marek Szyprowski
2012-03-06 23:21 ` [PATCHv7 9/9] ARM: dma-mapping: add support for IOMMU mapper Russell King - ARM Linux
2012-03-06 23:21 ` Russell King - ARM Linux
2012-03-06 23:36 ` Krishna Reddy
2012-03-06 23:36 ` Krishna Reddy
2012-03-07 16:17 ` Marek Szyprowski
2012-03-29 7:19 ` Hiroshi Doyu
2012-03-29 7:19 ` Hiroshi Doyu
2012-03-29 8:00 ` Marek Szyprowski
2012-03-29 8:00 ` Marek Szyprowski
2012-03-30 2:24 ` Krishna Reddy
2012-03-30 2:24 ` Krishna Reddy
2012-03-30 6:30 ` Marek Szyprowski
2012-03-30 6:30 ` Marek Szyprowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='011701ccfc83$78030180$68090480$%szyprowski@samsung.com' \
--to=m.szyprowski@samsung.com \
--cc=andrzej.p@samsung.com \
--cc=arnd@arndb.de \
--cc=benh@kernel.crashing.org \
--cc=chunsang.jeong@linaro.org \
--cc=hdoyu@nvidia.com \
--cc=iommu@lists.linux-foundation.org \
--cc=kyungmin.park@samsung.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-mm@kvack.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=pullip.cho@samsung.com \
--cc=shariq.hasnain@linaro.org \
--cc=vdumpa@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).