Re: [PATCH 15/16] dma-debug: x86 architecture bindings

From: FUJITA Tomonori
Date: Sun Feb 22 2009 - 01:51:37 EST


On Mon, 19 Jan 2009 15:47:02 +0100
Joerg Roedel <joerg.roedel@xxxxxxx> wrote:

> Impact: make use of DMA-API debugging code in x86
>
> Signed-off-by: Joerg Roedel <joerg.roedel@xxxxxxx>
> ---
> arch/x86/Kconfig | 1 +
> arch/x86/include/asm/dma-mapping.h | 45 +++++++++++++++++++++++++++++++----
> arch/x86/kernel/pci-dma.c | 6 ++++
> 3 files changed, 46 insertions(+), 6 deletions(-)

(snip)

> static inline int
> @@ -79,9 +86,13 @@ dma_map_sg(struct device *hwdev, struct scatterlist *sg,
> int nents, enum dma_data_direction dir)
> {
> struct dma_map_ops *ops = get_dma_ops(hwdev);
> + int ents;
>
> BUG_ON(!valid_dma_direction(dir));
> - return ops->map_sg(hwdev, sg, nents, dir, NULL);
> + ents = ops->map_sg(hwdev, sg, nents, dir, NULL);
> + debug_dma_map_sg(hwdev, sg, ents, dir);

The way to handle dma_map_sg and dma_unmap_sg looks wrong.

ents could be smaller than nents here with IOMMU implementations that
merge several sg entries into one.


> + return ents;
> }
>
> static inline void
> @@ -91,6 +102,7 @@ dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
> struct dma_map_ops *ops = get_dma_ops(hwdev);
>
> BUG_ON(!valid_dma_direction(dir));
> + debug_dma_unmap_sg(hwdev, sg, nents, dir);

Here the nents is the same one you passed into dma_map_sg call. It is
not the value returned from dma_map_sg (see DMA-mapping.txt).

So we call check_unmap for entries that we didn't call add_dma_entry
for on dma_map_sg. These entries are not initialized so we could get any
kinds of warnings from check_unmap.
--
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/