All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/dma: make a zero length mapping length not dma capable
@ 2011-09-20 17:44 Sebastian Andrzej Siewior
  2011-09-27 12:49 ` Felipe Balbi
  2011-09-27 14:47 ` FUJITA Tomonori
  0 siblings, 2 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2011-09-20 17:44 UTC (permalink / raw)
  To: FUJITA Tomonori; +Cc: linux-kernel, balbi, Sebastian Andrzej Siewior

The following ooops happens during a call to dma_map_single():

| ------------[ cut here ]------------
| kernel BUG at lib/swiotlb.c:409!
| invalid opcode: 0000 [#1] SMP
| CPU 1
|
| RIP: 0010:[<ffffffff811a00c9>]  [<ffffffff811a00c9>] swiotlb_tbl_map_single+0x87/0x1e0
| Call Trace:
|  [<ffffffff813170e0>] ? printk+0x43/0x48
|  [<ffffffff8100d027>] ? load_TLS+0x7/0xa
|  [<ffffffff811a0261>] ? map_single+0x3f/0x3f
|  [<ffffffff811a02be>] ? swiotlb_map_page+0x5d/0xcd
|  [<ffffffff811a0261>] ? map_single+0x3f/0x3f
|  [<ffffffffa02946ca>] ? dwc3_map_buffer_to_dma+0x8a/0xe2 [dwc3]

As you know from the line 409 the size parameter was 0. This happens
because the upper layer sends a zero length packet which the dwc3 driver
tried to map.
The memory is not really used and the hardware should not really issue a
dma request however we must setup a dma descriptor which contains an
address field and a size field which is set to 0 for the zero length
packet to be sent. So the unconditional mapping was kinda convenient to
do. ARM does not complain about length == 0, the swiotlb which is
used on x86 makes trouble. Looking at other udc drivers, they either
ignore this case or workaround it by incrementing the size by 1 which
looks nasty.
For now I fixed this by not mapping zero packets at all. Anything what I
should expect from the DMA API? I.e. should it be okay to call
dma_map_single() with size = 0?
This patch is untested due to -ENODEV. Changing each implementation of
dma_map_single() will result in large patch and it is also question if
this is worth the effort.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/x86/include/asm/dma-mapping.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index d4c419f..e73d921 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -65,6 +65,8 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
 {
 	if (!dev->dma_mask)
 		return 0;
+	if (!size)
+		return 0;
 
 	return addr + size - 1 <= *dev->dma_mask;
 }
-- 
1.7.6.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/dma: make a zero length mapping length not dma capable
  2011-09-20 17:44 [PATCH] x86/dma: make a zero length mapping length not dma capable Sebastian Andrzej Siewior
@ 2011-09-27 12:49 ` Felipe Balbi
  2011-09-27 14:47 ` FUJITA Tomonori
  1 sibling, 0 replies; 3+ messages in thread
From: Felipe Balbi @ 2011-09-27 12:49 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: FUJITA Tomonori, linux-kernel, balbi

[-- Attachment #1: Type: text/plain, Size: 2500 bytes --]

hi,

On Tue, Sep 20, 2011 at 07:44:25PM +0200, Sebastian Andrzej Siewior wrote:
> The following ooops happens during a call to dma_map_single():
> 
> | ------------[ cut here ]------------
> | kernel BUG at lib/swiotlb.c:409!
> | invalid opcode: 0000 [#1] SMP
> | CPU 1
> |
> | RIP: 0010:[<ffffffff811a00c9>]  [<ffffffff811a00c9>] swiotlb_tbl_map_single+0x87/0x1e0
> | Call Trace:
> |  [<ffffffff813170e0>] ? printk+0x43/0x48
> |  [<ffffffff8100d027>] ? load_TLS+0x7/0xa
> |  [<ffffffff811a0261>] ? map_single+0x3f/0x3f
> |  [<ffffffff811a02be>] ? swiotlb_map_page+0x5d/0xcd
> |  [<ffffffff811a0261>] ? map_single+0x3f/0x3f
> |  [<ffffffffa02946ca>] ? dwc3_map_buffer_to_dma+0x8a/0xe2 [dwc3]
> 
> As you know from the line 409 the size parameter was 0. This happens
> because the upper layer sends a zero length packet which the dwc3 driver
> tried to map.
> The memory is not really used and the hardware should not really issue a
> dma request however we must setup a dma descriptor which contains an
> address field and a size field which is set to 0 for the zero length
> packet to be sent. So the unconditional mapping was kinda convenient to
> do. ARM does not complain about length == 0, the swiotlb which is
> used on x86 makes trouble. Looking at other udc drivers, they either
> ignore this case or workaround it by incrementing the size by 1 which
> looks nasty.
> For now I fixed this by not mapping zero packets at all. Anything what I
> should expect from the DMA API? I.e. should it be okay to call
> dma_map_single() with size = 0?
> This patch is untested due to -ENODEV. Changing each implementation of
> dma_map_single() will result in large patch and it is also question if
> this is worth the effort.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

This helps my dwc3 driver:

Acked-by: Felipe Balbi <balbi@ti.com>

> ---
>  arch/x86/include/asm/dma-mapping.h |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
> index d4c419f..e73d921 100644
> --- a/arch/x86/include/asm/dma-mapping.h
> +++ b/arch/x86/include/asm/dma-mapping.h
> @@ -65,6 +65,8 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
>  {
>  	if (!dev->dma_mask)
>  		return 0;
> +	if (!size)
> +		return 0;
>  
>  	return addr + size - 1 <= *dev->dma_mask;
>  }
> -- 
> 1.7.6.3
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/dma: make a zero length mapping length not dma capable
  2011-09-20 17:44 [PATCH] x86/dma: make a zero length mapping length not dma capable Sebastian Andrzej Siewior
  2011-09-27 12:49 ` Felipe Balbi
@ 2011-09-27 14:47 ` FUJITA Tomonori
  1 sibling, 0 replies; 3+ messages in thread
From: FUJITA Tomonori @ 2011-09-27 14:47 UTC (permalink / raw)
  To: bigeasy; +Cc: fujita.tomonori, linux-kernel, balbi

On Tue, 20 Sep 2011 19:44:25 +0200
Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:

> The following ooops happens during a call to dma_map_single():
> 
> | ------------[ cut here ]------------
> | kernel BUG at lib/swiotlb.c:409!
> | invalid opcode: 0000 [#1] SMP
> | CPU 1
> |
> | RIP: 0010:[<ffffffff811a00c9>]  [<ffffffff811a00c9>] swiotlb_tbl_map_single+0x87/0x1e0
> | Call Trace:
> |  [<ffffffff813170e0>] ? printk+0x43/0x48
> |  [<ffffffff8100d027>] ? load_TLS+0x7/0xa
> |  [<ffffffff811a0261>] ? map_single+0x3f/0x3f
> |  [<ffffffff811a02be>] ? swiotlb_map_page+0x5d/0xcd
> |  [<ffffffff811a0261>] ? map_single+0x3f/0x3f
> |  [<ffffffffa02946ca>] ? dwc3_map_buffer_to_dma+0x8a/0xe2 [dwc3]
> 
> As you know from the line 409 the size parameter was 0. This happens
> because the upper layer sends a zero length packet which the dwc3 driver
> tried to map.
> The memory is not really used and the hardware should not really issue a
> dma request however we must setup a dma descriptor which contains an
> address field and a size field which is set to 0 for the zero length
> packet to be sent. So the unconditional mapping was kinda convenient to
> do. ARM does not complain about length == 0, the swiotlb which is
> used on x86 makes trouble. Looking at other udc drivers, they either
> ignore this case or workaround it by incrementing the size by 1 which
> looks nasty.
> For now I fixed this by not mapping zero packets at all. Anything what I
> should expect from the DMA API? I.e. should it be okay to call
> dma_map_single() with size = 0?

I don't think so. I know that some dma API implementations are ok with
it and some are not though. Drivers should calling dma_map_* with a
size that they do DMA with.

Accepting zero means that you can't catch a bug that passes zero. If
calling dma_map_* with zero size returns an address that nicely leads
to a system crash when a driver starts DMA (like calling kmalloc with
zero), then accepting zero size would be ok. But I don't think that
we can implement something like that.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-09-27 14:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-20 17:44 [PATCH] x86/dma: make a zero length mapping length not dma capable Sebastian Andrzej Siewior
2011-09-27 12:49 ` Felipe Balbi
2011-09-27 14:47 ` FUJITA Tomonori

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.