* [PATCH RESEND] arm: dma-mapping: Fix mapping size value
@ 2014-04-21  6:47 Ritesh Harjani
       [not found] ` <1398062847-5770-1-git-send-email-ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 15+ messages in thread
From: Ritesh Harjani @ 2014-04-21  6:47 UTC (permalink / raw)
  To: laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw,
	m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ
  Cc: mp.vikram-Re5JQEeQqe8AvxtiuMwx3w, catalin.marinas-5wv7dgnIgG8,
	Will.Deacon-5wv7dgnIgG8, menon.vinayak-Re5JQEeQqe8AvxtiuMwx3w,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	rmk-lFZ/pmaqli7XmaaqVzeoHQ
Previous patch message got corrupted by my mail-server (copy-paste)
So resending it.
 
[history]: http://www.spinics.net/lists/arm-kernel/msg323904.html
Ritesh Harjani (1):
  arm: dma-mapping: Fix mapping size value
 arch/arm/mm/dma-mapping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
-- 
1.8.1.3
^ permalink raw reply	[flat|nested] 15+ messages in thread[parent not found: <1398062847-5770-1-git-send-email-ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* [PATCH] arm: dma-mapping: Fix mapping size value [not found] ` <1398062847-5770-1-git-send-email-ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2014-04-21 6:47 ` Ritesh Harjani [not found] ` <1398062847-5770-2-git-send-email-ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 0 siblings, 1 reply; 15+ messages in thread From: Ritesh Harjani @ 2014-04-21 6:47 UTC (permalink / raw) To: laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw, m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ Cc: mp.vikram-Re5JQEeQqe8AvxtiuMwx3w, catalin.marinas-5wv7dgnIgG8, Will.Deacon-5wv7dgnIgG8, menon.vinayak-Re5JQEeQqe8AvxtiuMwx3w, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, rmk-lFZ/pmaqli7XmaaqVzeoHQ 68efd7d2fb("arm: dma-mapping: remove order parameter from arm_iommu_create_mapping()") is causing kernel panic because it wrongly sets the value of mapping->size: Unable to handle kernel NULL pointer dereference at virtual address 000000a0 pgd = e7a84000 [000000a0] *pgd=00000000 ... PC is at bitmap_clear+0x48/0xd0 LR is at __iommu_remove_mapping+0x130/0x164 Fix it by correcting mapping->size value. Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> --- arch/arm/mm/dma-mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index f62aa06..6b00be1 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size) mapping->nr_bitmaps = 1; mapping->extensions = extensions; mapping->base = base; - mapping->size = bitmap_size << PAGE_SHIFT; mapping->bits = BITS_PER_BYTE * bitmap_size; + mapping->size = mapping->bits << PAGE_SHIFT; spin_lock_init(&mapping->lock); -- 1.8.1.3 ^ permalink raw reply related [flat|nested] 15+ messages in thread
[parent not found: <1398062847-5770-2-git-send-email-ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* Re: [PATCH] arm: dma-mapping: Fix mapping size value [not found] ` <1398062847-5770-2-git-send-email-ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2014-04-22 8:53 ` Will Deacon [not found] ` <20140422085307.GB5747-5wv7dgnIgG8@public.gmane.org> 2014-04-22 9:09 ` Marek Szyprowski 1 sibling, 1 reply; 15+ messages in thread From: Will Deacon @ 2014-04-22 8:53 UTC (permalink / raw) To: Ritesh Harjani Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, mp.vikram-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, Catalin Marinas, menon.vinayak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org, rmk-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org On Mon, Apr 21, 2014 at 07:47:27AM +0100, Ritesh Harjani wrote: > 68efd7d2fb("arm: dma-mapping: remove order parameter from > arm_iommu_create_mapping()") is causing kernel panic > because it wrongly sets the value of mapping->size: > > Unable to handle kernel NULL pointer dereference at virtual > address 000000a0 > pgd = e7a84000 > [000000a0] *pgd=00000000 > ... > PC is at bitmap_clear+0x48/0xd0 > LR is at __iommu_remove_mapping+0x130/0x164 > > Fix it by correcting mapping->size value. > > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> > --- > arch/arm/mm/dma-mapping.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > index f62aa06..6b00be1 100644 > --- a/arch/arm/mm/dma-mapping.c > +++ b/arch/arm/mm/dma-mapping.c > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size) > mapping->nr_bitmaps = 1; > mapping->extensions = extensions; > mapping->base = base; > - mapping->size = bitmap_size << PAGE_SHIFT; > mapping->bits = BITS_PER_BYTE * bitmap_size; > + mapping->size = mapping->bits << PAGE_SHIFT; Ok, but given that mapping->size is derived from mapping->bits, do we really need both of these fields in struct dma_iommu_mapping? Will ^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <20140422085307.GB5747-5wv7dgnIgG8@public.gmane.org>]
* Re: [PATCH] arm: dma-mapping: Fix mapping size value [not found] ` <20140422085307.GB5747-5wv7dgnIgG8@public.gmane.org> @ 2014-04-23 8:53 ` Marek Szyprowski [not found] ` <53577F84.1080101-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> 0 siblings, 1 reply; 15+ messages in thread From: Marek Szyprowski @ 2014-04-23 8:53 UTC (permalink / raw) To: Will Deacon, Ritesh Harjani Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, mp.vikram-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, Catalin Marinas, menon.vinayak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org, rmk-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org Hello, On 2014-04-22 10:53, Will Deacon wrote: > On Mon, Apr 21, 2014 at 07:47:27AM +0100, Ritesh Harjani wrote: > > 68efd7d2fb("arm: dma-mapping: remove order parameter from > > arm_iommu_create_mapping()") is causing kernel panic > > because it wrongly sets the value of mapping->size: > > > > Unable to handle kernel NULL pointer dereference at virtual > > address 000000a0 > > pgd = e7a84000 > > [000000a0] *pgd=00000000 > > ... > > PC is at bitmap_clear+0x48/0xd0 > > LR is at __iommu_remove_mapping+0x130/0x164 > > > > Fix it by correcting mapping->size value. > > > > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> > > --- > > arch/arm/mm/dma-mapping.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > > index f62aa06..6b00be1 100644 > > --- a/arch/arm/mm/dma-mapping.c > > +++ b/arch/arm/mm/dma-mapping.c > > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size) > > mapping->nr_bitmaps = 1; > > mapping->extensions = extensions; > > mapping->base = base; > > - mapping->size = bitmap_size << PAGE_SHIFT; > > mapping->bits = BITS_PER_BYTE * bitmap_size; > > + mapping->size = mapping->bits << PAGE_SHIFT; > > Ok, but given that mapping->size is derived from mapping->bits, do we really > need both of these fields in struct dma_iommu_mapping? You are right. I didn't notice this while I was refactoring the code. Ritesh, could you update your patch and simply replace all references of mapping->size with (mapping->bits << PAGE_SHIFT), probably with some temporary variable to make the code easier to understand? I've didn't apply your patch yet. Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland ^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <53577F84.1080101-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>]
* Re: [PATCH] arm: dma-mapping: Fix mapping size value [not found] ` <53577F84.1080101-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> @ 2014-04-23 9:30 ` Laurent Pinchart 2014-04-23 10:04 ` Ritesh Harjani 0 siblings, 1 reply; 15+ messages in thread From: Laurent Pinchart @ 2014-04-23 9:30 UTC (permalink / raw) To: Marek Szyprowski Cc: mp.vikram-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, Catalin Marinas, Will Deacon, menon.vinayak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, rmk-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org Hi Marek, On Wednesday 23 April 2014 10:53:24 Marek Szyprowski wrote: > On 2014-04-22 10:53, Will Deacon wrote: > > On Mon, Apr 21, 2014 at 07:47:27AM +0100, Ritesh Harjani wrote: > > > 68efd7d2fb("arm: dma-mapping: remove order parameter from > > > arm_iommu_create_mapping()") is causing kernel panic > > > because it wrongly sets the value of mapping->size: > > > > > > Unable to handle kernel NULL pointer dereference at virtual > > > address 000000a0 > > > pgd = e7a84000 > > > [000000a0] *pgd=00000000 > > > ... > > > PC is at bitmap_clear+0x48/0xd0 > > > LR is at __iommu_remove_mapping+0x130/0x164 > > > > > > Fix it by correcting mapping->size value. > > > > > > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> > > > --- > > > > > > arch/arm/mm/dma-mapping.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > > > index f62aa06..6b00be1 100644 > > > --- a/arch/arm/mm/dma-mapping.c > > > +++ b/arch/arm/mm/dma-mapping.c > > > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, > > > dma_addr_t base, size_t size)> > > > > mapping->nr_bitmaps = 1; > > > mapping->extensions = extensions; > > > mapping->base = base; > > > > > > - mapping->size = bitmap_size << PAGE_SHIFT; > > > > > > mapping->bits = BITS_PER_BYTE * bitmap_size; > > > > > > + mapping->size = mapping->bits << PAGE_SHIFT; > > > > Ok, but given that mapping->size is derived from mapping->bits, do we > > really need both of these fields in struct dma_iommu_mapping? > > You are right. I didn't notice this while I was refactoring the code. > Ritesh, could you update your patch and simply replace all references of > mapping->size with (mapping->bits << PAGE_SHIFT), probably with some > temporary variable to make the code easier to understand? I've didn't apply > your patch yet. As this patch fixes a v3.15 regression, shouldn't it be applied as-is and ASAP, with the cleanup that removes mapping->size coming in a later, less urgent patch ? -- Regards, Laurent Pinchart ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] arm: dma-mapping: Fix mapping size value 2014-04-23 9:30 ` Laurent Pinchart @ 2014-04-23 10:04 ` Ritesh Harjani [not found] ` <CAD15agYETzLJZ26wh8c=+PCSoQ9dR9vLgg7VmZTnQquXxoW+2Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 15+ messages in thread From: Ritesh Harjani @ 2014-04-23 10:04 UTC (permalink / raw) To: Laurent Pinchart Cc: mp.vikram-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, Catalin Marinas, Will Deacon, menon.vinayak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, rmk-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org Hi Marek/Will On Wed, Apr 23, 2014 at 3:00 PM, Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> wrote: > Hi Marek, > > On Wednesday 23 April 2014 10:53:24 Marek Szyprowski wrote: >> On 2014-04-22 10:53, Will Deacon wrote: >> > On Mon, Apr 21, 2014 at 07:47:27AM +0100, Ritesh Harjani wrote: >> > > 68efd7d2fb("arm: dma-mapping: remove order parameter from >> > > arm_iommu_create_mapping()") is causing kernel panic >> > > because it wrongly sets the value of mapping->size: >> > > >> > > Unable to handle kernel NULL pointer dereference at virtual >> > > address 000000a0 >> > > pgd = e7a84000 >> > > [000000a0] *pgd=00000000 >> > > ... >> > > PC is at bitmap_clear+0x48/0xd0 >> > > LR is at __iommu_remove_mapping+0x130/0x164 >> > > >> > > Fix it by correcting mapping->size value. >> > > >> > > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> > > Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> >> > > --- >> > > >> > > arch/arm/mm/dma-mapping.c | 2 +- >> > > 1 file changed, 1 insertion(+), 1 deletion(-) >> > > >> > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c >> > > index f62aa06..6b00be1 100644 >> > > --- a/arch/arm/mm/dma-mapping.c >> > > +++ b/arch/arm/mm/dma-mapping.c >> > > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, >> > > dma_addr_t base, size_t size)> > >> > > mapping->nr_bitmaps = 1; >> > > mapping->extensions = extensions; >> > > mapping->base = base; >> > > >> > > - mapping->size = bitmap_size << PAGE_SHIFT; >> > > >> > > mapping->bits = BITS_PER_BYTE * bitmap_size; >> > > >> > > + mapping->size = mapping->bits << PAGE_SHIFT; >> > >> > Ok, but given that mapping->size is derived from mapping->bits, do we >> > really need both of these fields in struct dma_iommu_mapping? >> >> You are right. I didn't notice this while I was refactoring the code. >> Ritesh, could you update your patch and simply replace all references of >> mapping->size with (mapping->bits << PAGE_SHIFT), probably with some >> temporary variable to make the code easier to understand? I've didn't apply >> your patch yet. > > As this patch fixes a v3.15 regression, shouldn't it be applied as-is and > ASAP, with the cleanup that removes mapping->size coming in a later, less > urgent patch ? I agree with Laurent. Anyway this cleanup can be taken care when we will be doing refactoring of common code to lib/iommu-helper.c. Anyways, if you still insist I can prepare and submit the patch. Let me know again on this. > > -- > Regards, > > Laurent Pinchart > Thanks Ritesh ^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <CAD15agYETzLJZ26wh8c=+PCSoQ9dR9vLgg7VmZTnQquXxoW+2Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [PATCH] arm: dma-mapping: Fix mapping size value [not found] ` <CAD15agYETzLJZ26wh8c=+PCSoQ9dR9vLgg7VmZTnQquXxoW+2Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2014-04-23 13:17 ` Marek Szyprowski [not found] ` <5357BD77.3060908-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> 0 siblings, 1 reply; 15+ messages in thread From: Marek Szyprowski @ 2014-04-23 13:17 UTC (permalink / raw) To: Ritesh Harjani, Laurent Pinchart Cc: mp.vikram-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, Catalin Marinas, Will Deacon, menon.vinayak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, rmk-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org Hello, On 2014-04-23 12:04, Ritesh Harjani wrote: > Hi Marek/Will > > On Wed, Apr 23, 2014 at 3:00 PM, Laurent Pinchart > <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> wrote: > > Hi Marek, > > > > On Wednesday 23 April 2014 10:53:24 Marek Szyprowski wrote: > >> On 2014-04-22 10:53, Will Deacon wrote: > >> > On Mon, Apr 21, 2014 at 07:47:27AM +0100, Ritesh Harjani wrote: > >> > > 68efd7d2fb("arm: dma-mapping: remove order parameter from > >> > > arm_iommu_create_mapping()") is causing kernel panic > >> > > because it wrongly sets the value of mapping->size: > >> > > > >> > > Unable to handle kernel NULL pointer dereference at virtual > >> > > address 000000a0 > >> > > pgd = e7a84000 > >> > > [000000a0] *pgd=00000000 > >> > > ... > >> > > PC is at bitmap_clear+0x48/0xd0 > >> > > LR is at __iommu_remove_mapping+0x130/0x164 > >> > > > >> > > Fix it by correcting mapping->size value. > >> > > > >> > > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> > > Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> > >> > > --- > >> > > > >> > > arch/arm/mm/dma-mapping.c | 2 +- > >> > > 1 file changed, 1 insertion(+), 1 deletion(-) > >> > > > >> > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > >> > > index f62aa06..6b00be1 100644 > >> > > --- a/arch/arm/mm/dma-mapping.c > >> > > +++ b/arch/arm/mm/dma-mapping.c > >> > > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, > >> > > dma_addr_t base, size_t size)> > > >> > > mapping->nr_bitmaps = 1; > >> > > mapping->extensions = extensions; > >> > > mapping->base = base; > >> > > > >> > > - mapping->size = bitmap_size << PAGE_SHIFT; > >> > > > >> > > mapping->bits = BITS_PER_BYTE * bitmap_size; > >> > > > >> > > + mapping->size = mapping->bits << PAGE_SHIFT; > >> > > >> > Ok, but given that mapping->size is derived from mapping->bits, do we > >> > really need both of these fields in struct dma_iommu_mapping? > >> > >> You are right. I didn't notice this while I was refactoring the code. > >> Ritesh, could you update your patch and simply replace all references of > >> mapping->size with (mapping->bits << PAGE_SHIFT), probably with some > >> temporary variable to make the code easier to understand? I've didn't apply > >> your patch yet. > > > > As this patch fixes a v3.15 regression, shouldn't it be applied as-is and > > ASAP, with the cleanup that removes mapping->size coming in a later, less > > urgent patch ? > > I agree with Laurent. Anyway this cleanup can be taken care when we will be > doing refactoring of common code to lib/iommu-helper.c. > > Anyways, if you still insist I can prepare and submit the patch. Let me know > again on this. Ok, I've merged the patch as is and I will send pull request soon. Please include the above discussed cleanup while refactoring common code to lib. Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland ^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <5357BD77.3060908-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>]
* Re: [PATCH] arm: dma-mapping: Fix mapping size value [not found] ` <5357BD77.3060908-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> @ 2014-04-23 13:22 ` Ritesh Harjani 0 siblings, 0 replies; 15+ messages in thread From: Ritesh Harjani @ 2014-04-23 13:22 UTC (permalink / raw) To: Marek Szyprowski Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, mp.vikram-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, Catalin Marinas, Will Deacon, menon.vinayak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, Laurent Pinchart, rmk-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org Ok thanks Marek, I was about to send a new patch (as I had now got hold of my system). Anyways, I will add this discussion of cleaning up this variable in my to-do list. Thanks Ritesh On Wed, Apr 23, 2014 at 6:47 PM, Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> wrote: > Hello, > > > On 2014-04-23 12:04, Ritesh Harjani wrote: >> >> Hi Marek/Will >> >> On Wed, Apr 23, 2014 at 3:00 PM, Laurent Pinchart >> <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> wrote: >> > Hi Marek, >> > >> > On Wednesday 23 April 2014 10:53:24 Marek Szyprowski wrote: >> >> On 2014-04-22 10:53, Will Deacon wrote: >> >> > On Mon, Apr 21, 2014 at 07:47:27AM +0100, Ritesh Harjani wrote: >> >> > > 68efd7d2fb("arm: dma-mapping: remove order parameter from >> >> > > arm_iommu_create_mapping()") is causing kernel panic >> >> > > because it wrongly sets the value of mapping->size: >> >> > > >> >> > > Unable to handle kernel NULL pointer dereference at virtual >> >> > > address 000000a0 >> >> > > pgd = e7a84000 >> >> > > [000000a0] *pgd=00000000 >> >> > > ... >> >> > > PC is at bitmap_clear+0x48/0xd0 >> >> > > LR is at __iommu_remove_mapping+0x130/0x164 >> >> > > >> >> > > Fix it by correcting mapping->size value. >> >> > > >> >> > > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> >> > > Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> >> >> > > --- >> >> > > >> >> > > arch/arm/mm/dma-mapping.c | 2 +- >> >> > > 1 file changed, 1 insertion(+), 1 deletion(-) >> >> > > >> >> > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c >> >> > > index f62aa06..6b00be1 100644 >> >> > > --- a/arch/arm/mm/dma-mapping.c >> >> > > +++ b/arch/arm/mm/dma-mapping.c >> >> > > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type >> >> > > *bus, >> >> > > dma_addr_t base, size_t size)> > >> >> > > mapping->nr_bitmaps = 1; >> >> > > mapping->extensions = extensions; >> >> > > mapping->base = base; >> >> > > >> >> > > - mapping->size = bitmap_size << PAGE_SHIFT; >> >> > > >> >> > > mapping->bits = BITS_PER_BYTE * bitmap_size; >> >> > > >> >> > > + mapping->size = mapping->bits << PAGE_SHIFT; >> >> > >> >> > Ok, but given that mapping->size is derived from mapping->bits, do we >> >> > really need both of these fields in struct dma_iommu_mapping? >> >> >> >> You are right. I didn't notice this while I was refactoring the code. >> >> Ritesh, could you update your patch and simply replace all references >> >> of >> >> mapping->size with (mapping->bits << PAGE_SHIFT), probably with some >> >> temporary variable to make the code easier to understand? I've didn't >> >> apply >> >> your patch yet. >> > >> > As this patch fixes a v3.15 regression, shouldn't it be applied as-is >> > and >> > ASAP, with the cleanup that removes mapping->size coming in a later, >> > less >> > urgent patch ? >> >> I agree with Laurent. Anyway this cleanup can be taken care when we will >> be >> doing refactoring of common code to lib/iommu-helper.c. >> >> Anyways, if you still insist I can prepare and submit the patch. Let me >> know >> again on this. > > > Ok, I've merged the patch as is and I will send pull request soon. > Please include the above discussed cleanup while refactoring common code to > lib. > > > Best regards > -- > Marek Szyprowski, PhD > Samsung R&D Institute Poland > ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] arm: dma-mapping: Fix mapping size value [not found] ` <1398062847-5770-2-git-send-email-ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2014-04-22 8:53 ` Will Deacon @ 2014-04-22 9:09 ` Marek Szyprowski 1 sibling, 0 replies; 15+ messages in thread From: Marek Szyprowski @ 2014-04-22 9:09 UTC (permalink / raw) To: Ritesh Harjani, laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw Cc: mp.vikram-Re5JQEeQqe8AvxtiuMwx3w, catalin.marinas-5wv7dgnIgG8, Will.Deacon-5wv7dgnIgG8, menon.vinayak-Re5JQEeQqe8AvxtiuMwx3w, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, rmk-lFZ/pmaqli7XmaaqVzeoHQ Hello, On 2014-04-21 08:47, Ritesh Harjani wrote: > 68efd7d2fb("arm: dma-mapping: remove order parameter from > arm_iommu_create_mapping()") is causing kernel panic > because it wrongly sets the value of mapping->size: > > Unable to handle kernel NULL pointer dereference at virtual > address 000000a0 > pgd = e7a84000 > [000000a0] *pgd=00000000 > ... > PC is at bitmap_clear+0x48/0xd0 > LR is at __iommu_remove_mapping+0x130/0x164 > > Fix it by correcting mapping->size value. > > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> Thanks for spotting this issue! I'm really sorry for introducing it. I will push it to the fixes branch asap. > --- > arch/arm/mm/dma-mapping.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > index f62aa06..6b00be1 100644 > --- a/arch/arm/mm/dma-mapping.c > +++ b/arch/arm/mm/dma-mapping.c > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size) > mapping->nr_bitmaps = 1; > mapping->extensions = extensions; > mapping->base = base; > - mapping->size = bitmap_size << PAGE_SHIFT; > mapping->bits = BITS_PER_BYTE * bitmap_size; > + mapping->size = mapping->bits << PAGE_SHIFT; > > spin_lock_init(&mapping->lock); Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] arm: dma-mapping: Fix mapping size value
@ 2014-04-21  4:01 Ritesh Harjani
       [not found] ` <CAD15agZwxTQOBZtJCmAkbBW6hXGfRgedSc_Fi_-nHOE5MeAjTw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 15+ messages in thread
From: Ritesh Harjani @ 2014-04-21  4:01 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Vikram MP, Catalin Marinas, Will Deacon, Vinayak Menon,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	Russell King
Fixed the commit message. Please find the new patch below:
68efd7d2fb("arm: dma-mapping: remove order parameter from
arm_iommu_create_mapping()") is causing kernel panic
because it wrongly sets the mapping->size value.
Unable to handle kernel NULL pointer dereference at virtual
address 000000a0
pgd = e7a84000
[000000a0] *pgd=00000000
...
PC is at bitmap_clear+0x48/0xd0
LR is at __iommu_remove_mapping+0x130/
0x164
Fix it by correcting the mapping->size value.
Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
---
 arch/arm/mm/dma-mapping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index f62aa06..6b00be1 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus,
dma_addr_t base, size_t size)
        mapping->nr_bitmaps = 1;
        mapping->extensions = extensions;
        mapping->base = base;
-       mapping->size = bitmap_size << PAGE_SHIFT;
        mapping->bits = BITS_PER_BYTE * bitmap_size;
+       mapping->size = mapping->bits << PAGE_SHIFT;
        spin_lock_init(&mapping->lock);
--
1.8.1.3
On Mon, Apr 21, 2014 at 4:06 AM, Laurent Pinchart
<laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> wrote:
> Hi Ritesh,
>
> On Saturday 19 April 2014 16:55:30 Ritesh Harjani wrote:
>> In explaining the issue below, made a mistake of taking PAGE_SIZE
>> instead of PAGE_SHIFT (mistake mentioned inline).
>> Although numerical values and patch is correct.
>
> I was about to send the same patch, so, provided you fix the commit message,
>
> Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
>
>> On Sat, Apr 19, 2014 at 4:49 PM, Ritesh Harjani
>>
>> <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> > I am finding an oops after following commit. I am on 3.10.30 kernel but
>> > applied all the latest patches from arch/arm/mm/dma-mapping.c
>> >
>> > I added some debug logs to see what is the error, on which I found that we
>> > are incorrectly setting mapping->size value.
>> > Please take a look at this and correct me if I am wrong here.
>> >
>> > FAULTY COMMIT:
>> > commit 68efd7d2fb32c2606f1da318b6a851
>> > d933813f27
>> > Author: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
>> > Date:   Tue Feb 25 13:01:09 2014 +0100
>> >
>> >     arm: dma-mapping: remove order parameter from
>> >     arm_iommu_create_mapping()
>> >
>> > OOPS LOGS:
>> > [26.898145] __alloc_iova#LINE: 1097 start = 0x3500
>> > [26.898159] __alloc_iova#LINE:1136 iova = 0x53500000
>> > [26.898170] __alloc_iova#LINE:1138 mapping->base= 0x50000000
>> > [26.898181] __alloc_iova#LINE:1140 mapping->size = 0x1000000, i = 0
>> > [26.924442] __free_iova, bitmap_index = 3
>> >
>> > [Ritesh]: bitmap_index should be 0 for address 0x53500000. see in
>> > alloc_iova above.
>> >
>> > [26.924454] __free_iova,addr = 0x53500000
>> > [26.924463] __free_iova,mapping->base = 0x50000000
>> > [26.924472] __free_iova,mapping->size = 0x1000000
>> > [26.924482] __free_iova,bitmap_base = 0x53000000
>> > [26.924490] __free_iova, start = 0x500
>> >
>> > [Ritesh]: start should be 0x3500 for address 0x53500000. see in alloc_iova
>> > above.
>> >
>> > [26.924533] Unable to handle kernel NULL pointer dereference at virtual
>> > address 000000a0
>> > [26.924543] pgd = e7a84000
>> > [26.924558] [000000a0] *pgd=00000000
>> > [26.924572] Internal error: Oops: 5 [#1] PREEMPT SMP ARM
>> > [26.924598] Modules linked in:
>> > [26.924613] CPU: 1 PID: 2263 Comm: BufferLiberator Not tainted 3.10.30+
>> > #144
>> > [26.924624] task: e7370a40 ti: e6e06000 task.ti: e6e06000
>> > [26.924644] PC is at bitmap_clear+0x48/0xd0
>> > [26.924659] LR is at __iommu_remove_mapping+0x130/0x164
>> > [26.924673] pc : [<c02d0814>]    lr : [<c001bd30>]    psr: 20000093
>> > [26.924673] sp : e6e07e20  ip : ffffffff  fp : e6e07e3c
>> > [26.924682] r10: 00000500  r9 : c1333ea8  r8 : 80000013
>> > [26.924692] r7 : ffffffff  r6 : 00000321  r5 : 000000a0  r4 : 00000028
>> > [26.924707] r3 : 00000000  r2 : 00000341  r1 : 00000500  r0 : 00000000
>> > [26.924730] Flags: nzCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment
>> > user
>> > [26.924742] Control: 10c5387d  Table: 77a8406a  DAC: 00000015
>> >
>> >
>> > See below on how this is wrong:
>> >
>> > here iova_base = 0x50000000
>> > iova_size = 0x20000000
>> > => bits needed to map = 131072.
>> >
>> >         => bitmap_size = 0x4000
>> >         since bitmap_size > PAGE_SIZE
>> >         => bitmap_size = PAGE_SIZE,  extensions = 4;
>> >
>> > Now, mapping->size is currently set as bitmap_size << PAGE_SHIFT.
>> >
>> >         =>mapping->size = 0x1000000.
>> >
>> > mapping->size is the IOVA size, which one bitmap can address.
>> >
>> > Now mapping->size * extensions should be size (0x20000000).
>> > which is not true, => our bitmap_size is set wrong.
>> >
>> > it should be (mapping->bits << PAGE_SIZE) or say
>>
>> It should be PAGE_SHIFT here.
>>
>> > (BITS_PER_BYTE * bitmap_size << PAGE_SIZE)
>>
>> It should be PAGE_SHIFT here.
>>
>> >         => (8 * 0x1000) << 12) = 0x8000000
>> >
>> > With this IOVA_SIZE = extensions * mapping->size = 0x20000000
>> >
>> >
>> >
>> > PATCH:
>> >
>> > Currently mapping->size is wrongly set resulting
>> > in OOPS (atleast we see OOPS with extension 4).
>> >
>> > Fix this.
>> >
>> > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> > ---
>> >
>> >  arch/arm/mm/dma-mapping.c | 2 +-
>> >  1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
>> > index f62aa06..d1701a2 100644
>> > --- a/arch/arm/mm/dma-mapping.c
>> > +++ b/arch/arm/mm/dma-mapping.c
>> > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus,
>> > dma_addr_t base, size_t size)
>> >         mapping->nr_bitmaps = 1;
>> >         mapping->extensions = extensions;
>> >         mapping->base = base;
>> > -       mapping->size = bitmap_size << PAGE_SHIFT;
>> >         mapping->bits = BITS_PER_BYTE * bitmap_size;
>> > +       mapping->size = mapping->bits << PAGE_SHIFT;
>> >
>> >         spin_lock_init(&mapping->lock);
>> >
>
> --
> Regards,
>
> Laurent Pinchart
>
^ permalink raw reply related	[flat|nested] 15+ messages in thread[parent not found: <CAD15agZwxTQOBZtJCmAkbBW6hXGfRgedSc_Fi_-nHOE5MeAjTw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [PATCH] arm: dma-mapping: Fix mapping size value [not found] ` <CAD15agZwxTQOBZtJCmAkbBW6hXGfRgedSc_Fi_-nHOE5MeAjTw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2014-04-21 9:53 ` Laurent Pinchart 2014-04-21 12:25 ` Laurent Pinchart 0 siblings, 1 reply; 15+ messages in thread From: Laurent Pinchart @ 2014-04-21 9:53 UTC (permalink / raw) To: Ritesh Harjani Cc: Vikram MP, Catalin Marinas, Will Deacon, Vinayak Menon, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, Russell King Hi Ritesh, On Monday 21 April 2014 09:31:38 Ritesh Harjani wrote: > Fixed the commit message. Please find the new patch below: Thank you. Your mail has wrapped lines and converted tabs to whitespaces. Could you please fix that and resubmit the patch on a mail of its own (use git send-email to avoid white space issues), with the subject set to "[PATCH v2] arm: dma-mapping: Fix mapping size value" ? > 68efd7d2fb("arm: dma-mapping: remove order parameter from > arm_iommu_create_mapping()") is causing kernel panic > because it wrongly sets the mapping->size value. > > Unable to handle kernel NULL pointer dereference at virtual > address 000000a0 > pgd = e7a84000 > [000000a0] *pgd=00000000 > ... > PC is at bitmap_clear+0x48/0xd0 > LR is at __iommu_remove_mapping+0x130/ > 0x164 > > > Fix it by correcting the mapping->size value. > > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> > --- > arch/arm/mm/dma-mapping.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > index f62aa06..6b00be1 100644 > --- a/arch/arm/mm/dma-mapping.c > +++ b/arch/arm/mm/dma-mapping.c > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, > dma_addr_t base, size_t size) > mapping->nr_bitmaps = 1; > mapping->extensions = extensions; > mapping->base = base; > - mapping->size = bitmap_size << PAGE_SHIFT; > mapping->bits = BITS_PER_BYTE * bitmap_size; > + mapping->size = mapping->bits << PAGE_SHIFT; > > spin_lock_init(&mapping->lock); > > > -- > 1.8.1.3 > > On Mon, Apr 21, 2014 at 4:06 AM, Laurent Pinchart > > <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> wrote: > > Hi Ritesh, > > > > On Saturday 19 April 2014 16:55:30 Ritesh Harjani wrote: > >> In explaining the issue below, made a mistake of taking PAGE_SIZE > >> instead of PAGE_SHIFT (mistake mentioned inline). > >> Although numerical values and patch is correct. > > > > I was about to send the same patch, so, provided you fix the commit > > message, > > > > Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> > > > >> On Sat, Apr 19, 2014 at 4:49 PM, Ritesh Harjani > >> > >> <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > I am finding an oops after following commit. I am on 3.10.30 kernel but > >> > applied all the latest patches from arch/arm/mm/dma-mapping.c > >> > > >> > I added some debug logs to see what is the error, on which I found that > >> > we > >> > are incorrectly setting mapping->size value. > >> > Please take a look at this and correct me if I am wrong here. > >> > > >> > FAULTY COMMIT: > >> > commit 68efd7d2fb32c2606f1da318b6a851 > >> > d933813f27 > >> > Author: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> > >> > Date: Tue Feb 25 13:01:09 2014 +0100 > >> > > >> > arm: dma-mapping: remove order parameter from > >> > arm_iommu_create_mapping() > >> > > >> > OOPS LOGS: > >> > [26.898145] __alloc_iova#LINE: 1097 start = 0x3500 > >> > [26.898159] __alloc_iova#LINE:1136 iova = 0x53500000 > >> > [26.898170] __alloc_iova#LINE:1138 mapping->base= 0x50000000 > >> > [26.898181] __alloc_iova#LINE:1140 mapping->size = 0x1000000, i = 0 > >> > [26.924442] __free_iova, bitmap_index = 3 > >> > > >> > [Ritesh]: bitmap_index should be 0 for address 0x53500000. see in > >> > alloc_iova above. > >> > > >> > [26.924454] __free_iova,addr = 0x53500000 > >> > [26.924463] __free_iova,mapping->base = 0x50000000 > >> > [26.924472] __free_iova,mapping->size = 0x1000000 > >> > [26.924482] __free_iova,bitmap_base = 0x53000000 > >> > [26.924490] __free_iova, start = 0x500 > >> > > >> > [Ritesh]: start should be 0x3500 for address 0x53500000. see in > >> > alloc_iova > >> > above. > >> > > >> > [26.924533] Unable to handle kernel NULL pointer dereference at virtual > >> > address 000000a0 > >> > [26.924543] pgd = e7a84000 > >> > [26.924558] [000000a0] *pgd=00000000 > >> > [26.924572] Internal error: Oops: 5 [#1] PREEMPT SMP ARM > >> > [26.924598] Modules linked in: > >> > [26.924613] CPU: 1 PID: 2263 Comm: BufferLiberator Not tainted 3.10.30+ > >> > #144 > >> > [26.924624] task: e7370a40 ti: e6e06000 task.ti: e6e06000 > >> > [26.924644] PC is at bitmap_clear+0x48/0xd0 > >> > [26.924659] LR is at __iommu_remove_mapping+0x130/0x164 > >> > [26.924673] pc : [<c02d0814>] lr : [<c001bd30>] psr: 20000093 > >> > [26.924673] sp : e6e07e20 ip : ffffffff fp : e6e07e3c > >> > [26.924682] r10: 00000500 r9 : c1333ea8 r8 : 80000013 > >> > [26.924692] r7 : ffffffff r6 : 00000321 r5 : 000000a0 r4 : 00000028 > >> > [26.924707] r3 : 00000000 r2 : 00000341 r1 : 00000500 r0 : 00000000 > >> > [26.924730] Flags: nzCv IRQs off FIQs on Mode SVC_32 ISA ARM > >> > Segment > >> > user > >> > [26.924742] Control: 10c5387d Table: 77a8406a DAC: 00000015 > >> > > >> > > >> > See below on how this is wrong: > >> > > >> > here iova_base = 0x50000000 > >> > iova_size = 0x20000000 > >> > => bits needed to map = 131072. > >> > > >> > => bitmap_size = 0x4000 > >> > since bitmap_size > PAGE_SIZE > >> > => bitmap_size = PAGE_SIZE, extensions = 4; > >> > > >> > Now, mapping->size is currently set as bitmap_size << PAGE_SHIFT. > >> > > >> > =>mapping->size = 0x1000000. > >> > > >> > mapping->size is the IOVA size, which one bitmap can address. > >> > > >> > Now mapping->size * extensions should be size (0x20000000). > >> > which is not true, => our bitmap_size is set wrong. > >> > > >> > it should be (mapping->bits << PAGE_SIZE) or say > >> > >> It should be PAGE_SHIFT here. > >> > >> > (BITS_PER_BYTE * bitmap_size << PAGE_SIZE) > >> > >> It should be PAGE_SHIFT here. > >> > >> > => (8 * 0x1000) << 12) = 0x8000000 > >> > > >> > With this IOVA_SIZE = extensions * mapping->size = 0x20000000 > >> > > >> > > >> > > >> > PATCH: > >> > > >> > Currently mapping->size is wrongly set resulting > >> > in OOPS (atleast we see OOPS with extension 4). > >> > > >> > Fix this. > >> > > >> > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> > --- > >> > > >> > arch/arm/mm/dma-mapping.c | 2 +- > >> > 1 file changed, 1 insertion(+), 1 deletion(-) > >> > > >> > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > >> > index f62aa06..d1701a2 100644 > >> > --- a/arch/arm/mm/dma-mapping.c > >> > +++ b/arch/arm/mm/dma-mapping.c > >> > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, > >> > dma_addr_t base, size_t size) > >> > > >> > mapping->nr_bitmaps = 1; > >> > mapping->extensions = extensions; > >> > mapping->base = base; > >> > > >> > - mapping->size = bitmap_size << PAGE_SHIFT; > >> > > >> > mapping->bits = BITS_PER_BYTE * bitmap_size; > >> > > >> > + mapping->size = mapping->bits << PAGE_SHIFT; > >> > > >> > spin_lock_init(&mapping->lock); -- Regards, Laurent Pinchart ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] arm: dma-mapping: Fix mapping size value 2014-04-21 9:53 ` Laurent Pinchart @ 2014-04-21 12:25 ` Laurent Pinchart 0 siblings, 0 replies; 15+ messages in thread From: Laurent Pinchart @ 2014-04-21 12:25 UTC (permalink / raw) To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r Cc: Vikram MP, Catalin Marinas, Will Deacon, Vinayak Menon, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, Russell King On Monday 21 April 2014 11:53:12 Laurent Pinchart wrote: > Hi Ritesh, > > On Monday 21 April 2014 09:31:38 Ritesh Harjani wrote: > > Fixed the commit message. Please find the new patch below: > Thank you. Your mail has wrapped lines and converted tabs to whitespaces. > Could you please fix that and resubmit the patch on a mail of its own (use > git send-email to avoid white space issues), with the subject set to > "[PATCH v2] arm: dma-mapping: Fix mapping size value" ? Please ignore this, I had missed that you have already resent the patch. > > > 68efd7d2fb("arm: dma-mapping: remove order parameter from > > arm_iommu_create_mapping()") is causing kernel panic > > because it wrongly sets the mapping->size value. > > > > Unable to handle kernel NULL pointer dereference at virtual > > address 000000a0 > > pgd = e7a84000 > > [000000a0] *pgd=00000000 > > ... > > PC is at bitmap_clear+0x48/0xd0 > > LR is at __iommu_remove_mapping+0x130/ > > 0x164 > > > > > > Fix it by correcting the mapping->size value. > > > > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> > > --- > > > > arch/arm/mm/dma-mapping.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > > index f62aa06..6b00be1 100644 > > --- a/arch/arm/mm/dma-mapping.c > > +++ b/arch/arm/mm/dma-mapping.c > > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, > > dma_addr_t base, size_t size) > > > > mapping->nr_bitmaps = 1; > > mapping->extensions = extensions; > > mapping->base = base; > > > > - mapping->size = bitmap_size << PAGE_SHIFT; > > > > mapping->bits = BITS_PER_BYTE * bitmap_size; > > > > + mapping->size = mapping->bits << PAGE_SHIFT; > > > > spin_lock_init(&mapping->lock); > > > > -- > > 1.8.1.3 > > > > On Mon, Apr 21, 2014 at 4:06 AM, Laurent Pinchart > > > > <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> wrote: > > > Hi Ritesh, > > > > > > On Saturday 19 April 2014 16:55:30 Ritesh Harjani wrote: > > >> In explaining the issue below, made a mistake of taking PAGE_SIZE > > >> instead of PAGE_SHIFT (mistake mentioned inline). > > >> Although numerical values and patch is correct. > > > > > > I was about to send the same patch, so, provided you fix the commit > > > message, > > > > > > Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> > > > > > >> On Sat, Apr 19, 2014 at 4:49 PM, Ritesh Harjani > > >> > > >> <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> > I am finding an oops after following commit. I am on 3.10.30 kernel > > >> > but > > >> > applied all the latest patches from arch/arm/mm/dma-mapping.c > > >> > > > >> > I added some debug logs to see what is the error, on which I found > > >> > that > > >> > we > > >> > are incorrectly setting mapping->size value. > > >> > Please take a look at this and correct me if I am wrong here. > > >> > > > >> > FAULTY COMMIT: > > >> > commit 68efd7d2fb32c2606f1da318b6a851 > > >> > d933813f27 > > >> > Author: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> > > >> > Date: Tue Feb 25 13:01:09 2014 +0100 > > >> > > > >> > arm: dma-mapping: remove order parameter from > > >> > arm_iommu_create_mapping() > > >> > > > >> > OOPS LOGS: > > >> > [26.898145] __alloc_iova#LINE: 1097 start = 0x3500 > > >> > [26.898159] __alloc_iova#LINE:1136 iova = 0x53500000 > > >> > [26.898170] __alloc_iova#LINE:1138 mapping->base= 0x50000000 > > >> > [26.898181] __alloc_iova#LINE:1140 mapping->size = 0x1000000, i = 0 > > >> > [26.924442] __free_iova, bitmap_index = 3 > > >> > > > >> > [Ritesh]: bitmap_index should be 0 for address 0x53500000. see in > > >> > alloc_iova above. > > >> > > > >> > [26.924454] __free_iova,addr = 0x53500000 > > >> > [26.924463] __free_iova,mapping->base = 0x50000000 > > >> > [26.924472] __free_iova,mapping->size = 0x1000000 > > >> > [26.924482] __free_iova,bitmap_base = 0x53000000 > > >> > [26.924490] __free_iova, start = 0x500 > > >> > > > >> > [Ritesh]: start should be 0x3500 for address 0x53500000. see in > > >> > alloc_iova > > >> > above. > > >> > > > >> > [26.924533] Unable to handle kernel NULL pointer dereference at > > >> > virtual > > >> > address 000000a0 > > >> > [26.924543] pgd = e7a84000 > > >> > [26.924558] [000000a0] *pgd=00000000 > > >> > [26.924572] Internal error: Oops: 5 [#1] PREEMPT SMP ARM > > >> > [26.924598] Modules linked in: > > >> > [26.924613] CPU: 1 PID: 2263 Comm: BufferLiberator Not tainted > > >> > 3.10.30+ > > >> > #144 > > >> > [26.924624] task: e7370a40 ti: e6e06000 task.ti: e6e06000 > > >> > [26.924644] PC is at bitmap_clear+0x48/0xd0 > > >> > [26.924659] LR is at __iommu_remove_mapping+0x130/0x164 > > >> > [26.924673] pc : [<c02d0814>] lr : [<c001bd30>] psr: 20000093 > > >> > [26.924673] sp : e6e07e20 ip : ffffffff fp : e6e07e3c > > >> > [26.924682] r10: 00000500 r9 : c1333ea8 r8 : 80000013 > > >> > [26.924692] r7 : ffffffff r6 : 00000321 r5 : 000000a0 r4 : > > >> > 00000028 > > >> > [26.924707] r3 : 00000000 r2 : 00000341 r1 : 00000500 r0 : > > >> > 00000000 > > >> > [26.924730] Flags: nzCv IRQs off FIQs on Mode SVC_32 ISA ARM > > >> > Segment > > >> > user > > >> > [26.924742] Control: 10c5387d Table: 77a8406a DAC: 00000015 > > >> > > > >> > > > >> > See below on how this is wrong: > > >> > > > >> > here iova_base = 0x50000000 > > >> > iova_size = 0x20000000 > > >> > => bits needed to map = 131072. > > >> > > > >> > => bitmap_size = 0x4000 > > >> > since bitmap_size > PAGE_SIZE > > >> > => bitmap_size = PAGE_SIZE, extensions = 4; > > >> > > > >> > Now, mapping->size is currently set as bitmap_size << PAGE_SHIFT. > > >> > > > >> > =>mapping->size = 0x1000000. > > >> > > > >> > mapping->size is the IOVA size, which one bitmap can address. > > >> > > > >> > Now mapping->size * extensions should be size (0x20000000). > > >> > which is not true, => our bitmap_size is set wrong. > > >> > > > >> > it should be (mapping->bits << PAGE_SIZE) or say > > >> > > >> It should be PAGE_SHIFT here. > > >> > > >> > (BITS_PER_BYTE * bitmap_size << PAGE_SIZE) > > >> > > >> It should be PAGE_SHIFT here. > > >> > > >> > => (8 * 0x1000) << 12) = 0x8000000 > > >> > > > >> > With this IOVA_SIZE = extensions * mapping->size = 0x20000000 > > >> > > > >> > > > >> > > > >> > PATCH: > > >> > > > >> > Currently mapping->size is wrongly set resulting > > >> > in OOPS (atleast we see OOPS with extension 4). > > >> > > > >> > Fix this. > > >> > > > >> > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > >> > --- > > >> > > > >> > arch/arm/mm/dma-mapping.c | 2 +- > > >> > 1 file changed, 1 insertion(+), 1 deletion(-) > > >> > > > >> > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > > >> > index f62aa06..d1701a2 100644 > > >> > --- a/arch/arm/mm/dma-mapping.c > > >> > +++ b/arch/arm/mm/dma-mapping.c > > >> > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, > > >> > dma_addr_t base, size_t size) > > >> > > > >> > mapping->nr_bitmaps = 1; > > >> > mapping->extensions = extensions; > > >> > mapping->base = base; > > >> > > > >> > - mapping->size = bitmap_size << PAGE_SHIFT; > > >> > > > >> > mapping->bits = BITS_PER_BYTE * bitmap_size; > > >> > > > >> > + mapping->size = mapping->bits << PAGE_SHIFT; > > >> > > > >> > spin_lock_init(&mapping->lock); -- Regards, Laurent Pinchart ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] arm: dma-mapping: Fix mapping size value
@ 2014-04-19 11:19 Ritesh Harjani
       [not found] ` <CAD15aga8DTuzYrPfHF3X=ZvCuCQxfx1nOTk90DdwdxeZvV5tdA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 15+ messages in thread
From: Ritesh Harjani @ 2014-04-19 11:19 UTC (permalink / raw)
  To: Marek Szyprowski
  Cc: Catalin Marinas, Will Deacon,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	Russell King
I am finding an oops after following commit. I am on 3.10.30 kernel but applied
all the latest patches from arch/arm/mm/dma-mapping.c
I added some debug logs to see what is the error, on which I found that we are
incorrectly setting mapping->size value.
Please take a look at this and correct me if I am wrong here.
FAULTY COMMIT:
commit 68efd7d2fb32c2606f1da318b6a851
d933813f27
Author: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Date:   Tue Feb 25 13:01:09 2014 +0100
    arm: dma-mapping: remove order parameter from arm_iommu_create_mapping()
OOPS LOGS:
[26.898145] __alloc_iova#LINE: 1097 start = 0x3500
[26.898159] __alloc_iova#LINE:1136 iova = 0x53500000
[26.898170] __alloc_iova#LINE:1138 mapping->base= 0x50000000
[26.898181] __alloc_iova#LINE:1140 mapping->size = 0x1000000, i = 0
[26.924442] __free_iova, bitmap_index = 3
[Ritesh]: bitmap_index should be 0 for address 0x53500000. see in alloc_iova
above.
[26.924454] __free_iova,addr = 0x53500000
[26.924463] __free_iova,mapping->base = 0x50000000
[26.924472] __free_iova,mapping->size = 0x1000000
[26.924482] __free_iova,bitmap_base = 0x53000000
[26.924490] __free_iova, start = 0x500
[Ritesh]: start should be 0x3500 for address 0x53500000. see in alloc_iova
above.
[26.924533] Unable to handle kernel NULL pointer dereference at virtual
address 000000a0
[26.924543] pgd = e7a84000
[26.924558] [000000a0] *pgd=00000000
[26.924572] Internal error: Oops: 5 [#1] PREEMPT SMP ARM
[26.924598] Modules linked in:
[26.924613] CPU: 1 PID: 2263 Comm: BufferLiberator Not tainted 3.10.30+
#144
[26.924624] task: e7370a40 ti: e6e06000 task.ti: e6e06000
[26.924644] PC is at bitmap_clear+0x48/0xd0
[26.924659] LR is at __iommu_remove_mapping+0x130/0x164
[26.924673] pc : [<c02d0814>]    lr : [<c001bd30>]    psr: 20000093
[26.924673] sp : e6e07e20  ip : ffffffff  fp : e6e07e3c
[26.924682] r10: 00000500  r9 : c1333ea8  r8 : 80000013
[26.924692] r7 : ffffffff  r6 : 00000321  r5 : 000000a0  r4 : 00000028
[26.924707] r3 : 00000000  r2 : 00000341  r1 : 00000500  r0 : 00000000
[26.924730] Flags: nzCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment
user
[26.924742] Control: 10c5387d  Table: 77a8406a  DAC: 00000015
See below on how this is wrong:
here iova_base = 0x50000000
iova_size = 0x20000000
=> bits needed to map = 131072.
        => bitmap_size = 0x4000
        since bitmap_size > PAGE_SIZE
        => bitmap_size = PAGE_SIZE,  extensions = 4;
Now, mapping->size is currently set as bitmap_size << PAGE_SHIFT.
        =>mapping->size = 0x1000000.
mapping->size is the IOVA size, which one bitmap can address.
Now mapping->size * extensions should be size (0x20000000).
which is not true, => our bitmap_size is set wrong.
it should be (mapping->bits << PAGE_SIZE) or say
(BITS_PER_BYTE * bitmap_size << PAGE_SIZE)
        => (8 * 0x1000) << 12) = 0x8000000
With this IOVA_SIZE = extensions * mapping->size = 0x20000000
PATCH:
Currently mapping->size is wrongly set resulting
in OOPS (atleast we see OOPS with extension 4).
Fix this.
Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 arch/arm/mm/dma-mapping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index f62aa06..d1701a2 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus,
dma_addr_t base, size_t size)
        mapping->nr_bitmaps = 1;
        mapping->extensions = extensions;
        mapping->base = base;
-       mapping->size = bitmap_size << PAGE_SHIFT;
        mapping->bits = BITS_PER_BYTE * bitmap_size;
+       mapping->size = mapping->bits << PAGE_SHIFT;
        spin_lock_init(&mapping->lock);
--
1.8.1.3
^ permalink raw reply related	[flat|nested] 15+ messages in thread[parent not found: <CAD15aga8DTuzYrPfHF3X=ZvCuCQxfx1nOTk90DdwdxeZvV5tdA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [PATCH] arm: dma-mapping: Fix mapping size value [not found] ` <CAD15aga8DTuzYrPfHF3X=ZvCuCQxfx1nOTk90DdwdxeZvV5tdA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2014-04-19 11:25 ` Ritesh Harjani [not found] ` <CAD15agbgOhK2b4WaWM4g45iiT7yH8HPYu=GmsOs7BkCnVvjcsw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 15+ messages in thread From: Ritesh Harjani @ 2014-04-19 11:25 UTC (permalink / raw) To: Marek Szyprowski Cc: Catalin Marinas, Will Deacon, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, Russell King In explaining the issue below, made a mistake of taking PAGE_SIZE instead of PAGE_SHIFT (mistake mentioned inline). Although numerical values and patch is correct. On Sat, Apr 19, 2014 at 4:49 PM, Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > I am finding an oops after following commit. I am on 3.10.30 kernel but applied > all the latest patches from arch/arm/mm/dma-mapping.c > > I added some debug logs to see what is the error, on which I found that we are > incorrectly setting mapping->size value. > Please take a look at this and correct me if I am wrong here. > > FAULTY COMMIT: > commit 68efd7d2fb32c2606f1da318b6a851 > d933813f27 > Author: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> > Date: Tue Feb 25 13:01:09 2014 +0100 > > arm: dma-mapping: remove order parameter from arm_iommu_create_mapping() > > > OOPS LOGS: > [26.898145] __alloc_iova#LINE: 1097 start = 0x3500 > [26.898159] __alloc_iova#LINE:1136 iova = 0x53500000 > [26.898170] __alloc_iova#LINE:1138 mapping->base= 0x50000000 > [26.898181] __alloc_iova#LINE:1140 mapping->size = 0x1000000, i = 0 > [26.924442] __free_iova, bitmap_index = 3 > > [Ritesh]: bitmap_index should be 0 for address 0x53500000. see in alloc_iova > above. > > [26.924454] __free_iova,addr = 0x53500000 > [26.924463] __free_iova,mapping->base = 0x50000000 > [26.924472] __free_iova,mapping->size = 0x1000000 > [26.924482] __free_iova,bitmap_base = 0x53000000 > [26.924490] __free_iova, start = 0x500 > > [Ritesh]: start should be 0x3500 for address 0x53500000. see in alloc_iova > above. > > [26.924533] Unable to handle kernel NULL pointer dereference at virtual > address 000000a0 > [26.924543] pgd = e7a84000 > [26.924558] [000000a0] *pgd=00000000 > [26.924572] Internal error: Oops: 5 [#1] PREEMPT SMP ARM > [26.924598] Modules linked in: > [26.924613] CPU: 1 PID: 2263 Comm: BufferLiberator Not tainted 3.10.30+ > #144 > [26.924624] task: e7370a40 ti: e6e06000 task.ti: e6e06000 > [26.924644] PC is at bitmap_clear+0x48/0xd0 > [26.924659] LR is at __iommu_remove_mapping+0x130/0x164 > [26.924673] pc : [<c02d0814>] lr : [<c001bd30>] psr: 20000093 > [26.924673] sp : e6e07e20 ip : ffffffff fp : e6e07e3c > [26.924682] r10: 00000500 r9 : c1333ea8 r8 : 80000013 > [26.924692] r7 : ffffffff r6 : 00000321 r5 : 000000a0 r4 : 00000028 > [26.924707] r3 : 00000000 r2 : 00000341 r1 : 00000500 r0 : 00000000 > [26.924730] Flags: nzCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment > user > [26.924742] Control: 10c5387d Table: 77a8406a DAC: 00000015 > > > See below on how this is wrong: > > here iova_base = 0x50000000 > iova_size = 0x20000000 > => bits needed to map = 131072. > => bitmap_size = 0x4000 > since bitmap_size > PAGE_SIZE > => bitmap_size = PAGE_SIZE, extensions = 4; > > Now, mapping->size is currently set as bitmap_size << PAGE_SHIFT. > =>mapping->size = 0x1000000. > mapping->size is the IOVA size, which one bitmap can address. > > Now mapping->size * extensions should be size (0x20000000). > which is not true, => our bitmap_size is set wrong. > > it should be (mapping->bits << PAGE_SIZE) or say It should be PAGE_SHIFT here. > (BITS_PER_BYTE * bitmap_size << PAGE_SIZE) It should be PAGE_SHIFT here. > => (8 * 0x1000) << 12) = 0x8000000 > With this IOVA_SIZE = extensions * mapping->size = 0x20000000 > > > > PATCH: > > Currently mapping->size is wrongly set resulting > in OOPS (atleast we see OOPS with extension 4). > > Fix this. > > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > --- > arch/arm/mm/dma-mapping.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > index f62aa06..d1701a2 100644 > --- a/arch/arm/mm/dma-mapping.c > +++ b/arch/arm/mm/dma-mapping.c > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, > dma_addr_t base, size_t size) > mapping->nr_bitmaps = 1; > mapping->extensions = extensions; > mapping->base = base; > - mapping->size = bitmap_size << PAGE_SHIFT; > mapping->bits = BITS_PER_BYTE * bitmap_size; > + mapping->size = mapping->bits << PAGE_SHIFT; > > spin_lock_init(&mapping->lock); > > -- > 1.8.1.3 ^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <CAD15agbgOhK2b4WaWM4g45iiT7yH8HPYu=GmsOs7BkCnVvjcsw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [PATCH] arm: dma-mapping: Fix mapping size value [not found] ` <CAD15agbgOhK2b4WaWM4g45iiT7yH8HPYu=GmsOs7BkCnVvjcsw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2014-04-20 22:36 ` Laurent Pinchart 0 siblings, 0 replies; 15+ messages in thread From: Laurent Pinchart @ 2014-04-20 22:36 UTC (permalink / raw) To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r Cc: Catalin Marinas, Will Deacon, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, Russell King Hi Ritesh, On Saturday 19 April 2014 16:55:30 Ritesh Harjani wrote: > In explaining the issue below, made a mistake of taking PAGE_SIZE > instead of PAGE_SHIFT (mistake mentioned inline). > Although numerical values and patch is correct. I was about to send the same patch, so, provided you fix the commit message, Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org> > On Sat, Apr 19, 2014 at 4:49 PM, Ritesh Harjani > > <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I am finding an oops after following commit. I am on 3.10.30 kernel but > > applied all the latest patches from arch/arm/mm/dma-mapping.c > > > > I added some debug logs to see what is the error, on which I found that we > > are incorrectly setting mapping->size value. > > Please take a look at this and correct me if I am wrong here. > > > > FAULTY COMMIT: > > commit 68efd7d2fb32c2606f1da318b6a851 > > d933813f27 > > Author: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> > > Date: Tue Feb 25 13:01:09 2014 +0100 > > > > arm: dma-mapping: remove order parameter from > > arm_iommu_create_mapping() > > > > OOPS LOGS: > > [26.898145] __alloc_iova#LINE: 1097 start = 0x3500 > > [26.898159] __alloc_iova#LINE:1136 iova = 0x53500000 > > [26.898170] __alloc_iova#LINE:1138 mapping->base= 0x50000000 > > [26.898181] __alloc_iova#LINE:1140 mapping->size = 0x1000000, i = 0 > > [26.924442] __free_iova, bitmap_index = 3 > > > > [Ritesh]: bitmap_index should be 0 for address 0x53500000. see in > > alloc_iova above. > > > > [26.924454] __free_iova,addr = 0x53500000 > > [26.924463] __free_iova,mapping->base = 0x50000000 > > [26.924472] __free_iova,mapping->size = 0x1000000 > > [26.924482] __free_iova,bitmap_base = 0x53000000 > > [26.924490] __free_iova, start = 0x500 > > > > [Ritesh]: start should be 0x3500 for address 0x53500000. see in alloc_iova > > above. > > > > [26.924533] Unable to handle kernel NULL pointer dereference at virtual > > address 000000a0 > > [26.924543] pgd = e7a84000 > > [26.924558] [000000a0] *pgd=00000000 > > [26.924572] Internal error: Oops: 5 [#1] PREEMPT SMP ARM > > [26.924598] Modules linked in: > > [26.924613] CPU: 1 PID: 2263 Comm: BufferLiberator Not tainted 3.10.30+ > > #144 > > [26.924624] task: e7370a40 ti: e6e06000 task.ti: e6e06000 > > [26.924644] PC is at bitmap_clear+0x48/0xd0 > > [26.924659] LR is at __iommu_remove_mapping+0x130/0x164 > > [26.924673] pc : [<c02d0814>] lr : [<c001bd30>] psr: 20000093 > > [26.924673] sp : e6e07e20 ip : ffffffff fp : e6e07e3c > > [26.924682] r10: 00000500 r9 : c1333ea8 r8 : 80000013 > > [26.924692] r7 : ffffffff r6 : 00000321 r5 : 000000a0 r4 : 00000028 > > [26.924707] r3 : 00000000 r2 : 00000341 r1 : 00000500 r0 : 00000000 > > [26.924730] Flags: nzCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment > > user > > [26.924742] Control: 10c5387d Table: 77a8406a DAC: 00000015 > > > > > > See below on how this is wrong: > > > > here iova_base = 0x50000000 > > iova_size = 0x20000000 > > => bits needed to map = 131072. > > > > => bitmap_size = 0x4000 > > since bitmap_size > PAGE_SIZE > > => bitmap_size = PAGE_SIZE, extensions = 4; > > > > Now, mapping->size is currently set as bitmap_size << PAGE_SHIFT. > > > > =>mapping->size = 0x1000000. > > > > mapping->size is the IOVA size, which one bitmap can address. > > > > Now mapping->size * extensions should be size (0x20000000). > > which is not true, => our bitmap_size is set wrong. > > > > it should be (mapping->bits << PAGE_SIZE) or say > > It should be PAGE_SHIFT here. > > > (BITS_PER_BYTE * bitmap_size << PAGE_SIZE) > > It should be PAGE_SHIFT here. > > > => (8 * 0x1000) << 12) = 0x8000000 > > > > With this IOVA_SIZE = extensions * mapping->size = 0x20000000 > > > > > > > > PATCH: > > > > Currently mapping->size is wrongly set resulting > > in OOPS (atleast we see OOPS with extension 4). > > > > Fix this. > > > > Signed-off-by: Ritesh Harjani <ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > --- > > > > arch/arm/mm/dma-mapping.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > > index f62aa06..d1701a2 100644 > > --- a/arch/arm/mm/dma-mapping.c > > +++ b/arch/arm/mm/dma-mapping.c > > @@ -1963,8 +1963,8 @@ arm_iommu_create_mapping(struct bus_type *bus, > > dma_addr_t base, size_t size) > > mapping->nr_bitmaps = 1; > > mapping->extensions = extensions; > > mapping->base = base; > > - mapping->size = bitmap_size << PAGE_SHIFT; > > mapping->bits = BITS_PER_BYTE * bitmap_size; > > + mapping->size = mapping->bits << PAGE_SHIFT; > > > > spin_lock_init(&mapping->lock); > > -- Regards, Laurent Pinchart ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2014-04-23 13:22 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-21  6:47 [PATCH RESEND] arm: dma-mapping: Fix mapping size value Ritesh Harjani
     [not found] ` <1398062847-5770-1-git-send-email-ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-04-21  6:47   ` [PATCH] " Ritesh Harjani
     [not found]     ` <1398062847-5770-2-git-send-email-ritesh.harjani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-04-22  8:53       ` Will Deacon
     [not found]         ` <20140422085307.GB5747-5wv7dgnIgG8@public.gmane.org>
2014-04-23  8:53           ` Marek Szyprowski
     [not found]             ` <53577F84.1080101-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-04-23  9:30               ` Laurent Pinchart
2014-04-23 10:04                 ` Ritesh Harjani
     [not found]                   ` <CAD15agYETzLJZ26wh8c=+PCSoQ9dR9vLgg7VmZTnQquXxoW+2Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-23 13:17                     ` Marek Szyprowski
     [not found]                       ` <5357BD77.3060908-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-04-23 13:22                         ` Ritesh Harjani
2014-04-22  9:09       ` Marek Szyprowski
  -- strict thread matches above, loose matches on Subject: below --
2014-04-21  4:01 Ritesh Harjani
     [not found] ` <CAD15agZwxTQOBZtJCmAkbBW6hXGfRgedSc_Fi_-nHOE5MeAjTw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-21  9:53   ` Laurent Pinchart
2014-04-21 12:25     ` Laurent Pinchart
2014-04-19 11:19 Ritesh Harjani
     [not found] ` <CAD15aga8DTuzYrPfHF3X=ZvCuCQxfx1nOTk90DdwdxeZvV5tdA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-19 11:25   ` Ritesh Harjani
     [not found]     ` <CAD15agbgOhK2b4WaWM4g45iiT7yH8HPYu=GmsOs7BkCnVvjcsw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-20 22:36       ` Laurent Pinchart
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).