Fwd: DMA problem with VIA EHCI controller

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---------- Forwarded message ----------
From: Ming Lei <tom.leiming@xxxxxxxxx>
Date: 2009/9/27
Subject: Re: DMA problem with VIA EHCI controller
To: Joris van Rantwijk <jorispubl@xxxxxxxxx>
Cc: linux-usb@xxxxxxxxxxxxxxx




2009/9/27 Joris van Rantwijk <jorispubl@xxxxxxxxx>:
> On 27 sep 2009, at 03:34, Ming Lei wrote:
>>
>> It is very odd, and how can you see the alignment of kmalloc is
>> violated if CONFIG_DEBUG_SLAB=y?
>
> I added
>  printk("%p\n", bulk_in_buffer);
> and it printed ffff880011b7cdf0.
> The size of the kmalloc was 512 bytes.
>
>> DMA transfer requires that the transfer buffer is cache aligned, or else
>> your problem is understandable.
>
> Yeah I have read that before. I don't get why cache alignment matters
> though.

The minimum unit of cpu cache operation(invalidate, clean or flush) is one
cache line, instead of one word or other.

If you don't use coherent dma mapping in usb transfer,  hcd will do the
dma mapping before starting a usb transfer and do dma unmapping after
the usb transfer is over. (see drivers/usb/core/hcd.c)

Operation of dma mapping and dma unmapping are very platform dependent.
As dma from device(read) as concerned, generally speaking, dma mapping
may do cache clean to writeback the data in cache to ram, and dma
unmapping may do cache invalidate to make cpu see the latest data in ram.

So if the transfer buffer is not cache line aligned, data near the unaligned
position may be insane.

>
>> The buffer allocated by kmalloc should be cache aligned, and it is a
>> basic requirement for kmalloc in fact.
>
> mm/slab.c:
>  * Usually, the kmalloc caches are cache_line_size() aligned, except when
>  * DEBUG and FORCED_DEBUG are enabled, then they are BYTES_PER_WORD aligned.

The intact comment should be:

/*
 * Enforce a minimum alignment for the kmalloc caches.
 * Usually, the kmalloc caches are cache_line_size() aligned, except when
 * DEBUG and FORCED_DEBUG are enabled, then they are BYTES_PER_WORD aligned.
 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
 * alignment larger than the alignment of a 64-bit integer.
 * ARCH_KMALLOC_MINALIGN allows that.
 * Note that increasing this value may disable some debug features.
 */

So if you want to enable DEBUG or FORCED_DEBUG in slab, and you want to
perform DMA into kmalloc allocated buffer, you can define
ARCH_KMALLOC_MINALIGN to get the alignment.

Thanks.
--
Lei Ming
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux