From: Joerg Roedel <joro@8bytes.org>
To: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: linux-kernel@vger.kernel.org, tony.luck@intel.com,
iommu@lists.linux-foundation.org, mingo@redhat.com,
kamezawa.hiroyu@jp.fujitsu.com
Subject: Re: [PATCH 1/3] x86: remove the NULL device hack in dma-mapping.h
Date: Wed, 3 Sep 2008 22:01:14 +0200 [thread overview]
Message-ID: <20080903200114.GC16706@8bytes.org> (raw)
In-Reply-To: <1220465065-10533-2-git-send-email-fujita.tomonori@lab.ntt.co.jp>
On Thu, Sep 04, 2008 at 03:04:23AM +0900, FUJITA Tomonori wrote:
> dma_alloc_coherent in dma-mapping.h has a hack to use
> x86_dma_fallback_dev if a pointer to a device is NULL. Some of IOMMUs
> don't need such hack. The hack also makes it difficult for IOMMUs to
> make a proper decision because the hack hides the information.
I don't think its the right way to work around shortcomings of the
generic code in the architecture specific implementations. Especially
when the generic code can be easily fixed like in this case.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> ---
> arch/x86/kernel/pci-swiotlb_64.c | 15 ++++++++++++++-
> include/asm-x86/dma-mapping.h | 9 +--------
> 2 files changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/arch/x86/kernel/pci-swiotlb_64.c b/arch/x86/kernel/pci-swiotlb_64.c
> index c4ce033..f3d8d0e 100644
> --- a/arch/x86/kernel/pci-swiotlb_64.c
> +++ b/arch/x86/kernel/pci-swiotlb_64.c
> @@ -11,6 +11,8 @@
>
> int swiotlb __read_mostly;
>
> +extern struct device x86_dma_fallback_dev;
> +
> static dma_addr_t
> swiotlb_map_single_phys(struct device *hwdev, phys_addr_t paddr, size_t size,
> int direction)
> @@ -18,9 +20,20 @@ swiotlb_map_single_phys(struct device *hwdev, phys_addr_t paddr, size_t size,
> return swiotlb_map_single(hwdev, phys_to_virt(paddr), size, direction);
> }
>
> +static void *x86_swiotlb_alloc_coherent(struct device *dev, size_t size,
> + dma_addr_t *dma_handle, gfp_t gfp)
> +{
> + if (!dev) {
> + dev = &x86_dma_fallback_dev;
> + gfp |= GFP_DMA;
> + }
This really should be checked in the generic x86 dma_alloc_coherent
function.
> +
> + return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
> +}
> +
> struct dma_mapping_ops swiotlb_dma_ops = {
> .mapping_error = swiotlb_dma_mapping_error,
> - .alloc_coherent = swiotlb_alloc_coherent,
> + .alloc_coherent = x86_swiotlb_alloc_coherent,
> .free_coherent = swiotlb_free_coherent,
> .map_single = swiotlb_map_single_phys,
> .unmap_single = swiotlb_unmap_single,
> diff --git a/include/asm-x86/dma-mapping.h b/include/asm-x86/dma-mapping.h
> index bc6c8df..3463702 100644
> --- a/include/asm-x86/dma-mapping.h
> +++ b/include/asm-x86/dma-mapping.h
> @@ -14,7 +14,6 @@
>
> extern dma_addr_t bad_dma_address;
> extern int iommu_merge;
> -extern struct device x86_dma_fallback_dev;
> extern int panic_on_overflow;
> extern int force_iommu;
>
> @@ -251,14 +250,8 @@ dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
> if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
> return memory;
>
> - if (!dev) {
> - dev = &x86_dma_fallback_dev;
> - gfp |= GFP_DMA;
> - }
Why do you move this check to swiotlb implemenation? This will break
existing IOMMU implementations which don't check for a valid dev
pointer?
> if (ops->alloc_coherent)
> - return ops->alloc_coherent(dev, size,
> - dma_handle, gfp);
> + return ops->alloc_coherent(dev, size, dma_handle, gfp);
> return NULL;
> }
>
> --
> 1.5.5.GIT
>
> _______________________________________________
> iommu mailing list
> iommu@lists.linux-foundation.org
> https://lists.linux-foundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2008-09-03 20:01 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-03 15:03 [PATCH] swiotlb: fix dma_alloc_coherent allocation failures with swiotlb Joerg Roedel
2008-09-03 18:04 ` [PATCH 0/3] fix swiotlb allocation gfp flag FUJITA Tomonori
2008-09-03 18:04 ` [PATCH 1/3] x86: remove the NULL device hack in dma-mapping.h FUJITA Tomonori
2008-09-03 18:04 ` [PATCH 2/3] x86: set gfp flag properly for swiotlb_alloc_coherent FUJITA Tomonori
2008-09-03 18:04 ` [PATCH 3/3] swiotlb: use GFP_DMA32 instead of GFP_DMA in swiotlb_alloc_coherent FUJITA Tomonori
2008-09-03 20:05 ` Joerg Roedel
2008-09-04 4:11 ` FUJITA Tomonori
2008-09-03 18:54 ` [PATCH 1/3] x86: remove the NULL device hack in dma-mapping.h FUJITA Tomonori
2008-09-03 20:01 ` Joerg Roedel [this message]
2008-09-04 4:11 ` FUJITA Tomonori
2008-09-04 10:00 ` Joerg Roedel
2008-09-04 12:50 ` FUJITA Tomonori
2008-09-03 18:05 ` [PATCH] swiotlb: fix dma_alloc_coherent allocation failures with swiotlb FUJITA Tomonori
2008-09-03 19:54 ` Joerg Roedel
2008-09-03 20:11 ` Joerg Roedel
2008-09-04 4:11 ` FUJITA Tomonori
2008-09-03 22:09 ` Andi Kleen
2008-09-04 4:11 ` FUJITA Tomonori
2008-09-04 7:44 ` Andi Kleen
2008-09-04 7:58 ` FUJITA Tomonori
2008-09-04 8:05 ` Andi Kleen
2008-09-04 8:18 ` FUJITA Tomonori
2008-09-04 8:31 ` Andi Kleen
2008-09-04 9:49 ` Joerg Roedel
[not found] <fa.Tx5o9n5qXlTiaMQNn2gICqrkVUA@ifi.uio.no>
[not found] ` <fa.RE+bYfvoWz/5NCC06intia3OFmo@ifi.uio.no>
[not found] ` <fa.kdqbjaJP+Pja+TaKDb/G9J79BTA@ifi.uio.no>
[not found] ` <fa.3x55VLi/XqDV2PUAW3SsqCnCKh4@ifi.uio.no>
2008-09-04 23:53 ` [PATCH 1/3] x86: remove the NULL device hack in dma-mapping.h Robert Hancock
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080903200114.GC16706@8bytes.org \
--to=joro@8bytes.org \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=iommu@lists.linux-foundation.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox