Re: USB: free coherent buffer into atomic context

From: Wolfgang Mües
Date: Sun Sep 19 2010 - 13:43:32 EST


Hi Ming,

Am Samstag, 18. September 2010 10:50:20 schrieb Ming Lei:
> IMO, it is not necessary for a coherent buffer to be kept for
> the whole time a driver operates on a device.

>From DMA-mapping.txt:
>There are two types of DMA mappings:
>
>- Consistent DMA mappings which are usually mapped at driver
> initialization, unmapped at the end and for which the hardware should
> guarantee that the device and the CPU can access the data
> in parallel and will see updates made by each other without any
> explicit software flushing.

>- Streaming DMA mappings which are usually mapped for one DMA transfer,
> unmapped right after it (unless you use pci_dma_sync_* below) and for which
> hardware can optimize for sequential accesses.

You wrote:
> Also, coherent buffer
> is very limited in some arch(such as ARM), maybe we should use it
> more dynamically, instead of keeping it for long time.

No, this is against the design (see above).

If you want to be dynamic, please use streaming DMA mapping.

If a DMA buffer is needed often and you want to avoid the overhead of streaming
dma mapping, use a coherent buffer.

> irqs_disabled() doesn't mean the buffer is freed in an interrupt context.

I am very sure that the writer of this code has used irqs_disabled() as an
indication of interrupt context. Maybe in_interrupt() will be more precise.

> If it is only a misuse, seems WARN_ON can be removed.

How on earth will you detect the misuse if there is no visible indication at
runtime?

best regards
Wolfgang
--
Wahre Worte sind nicht schön - Schöne Worte sind nicht wahr. (Laotse)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/