remove default fallbacks in dma_map_ops
Subsystems (18)
Hi all,
we have a few places where the DMA mapping layer has non-trivial default actions that are questionable and/or dangerous.
This series instead wires up the mmap, get_sgtable and get_required_mask methods explicitly and cleans up some surrounding areas. This also means we could get rid of the ARCH_NO_COHERENT_DMA_MMAP kconfig option, as we now require a mmap method wired up, or in case of non-coherent dma-direct the presence of the arch_dma_coherent_to_pfn hook. The only interesting case is that the sound code also checked the ARCH_NO_COHERENT_DMA_MMAP symbol in somewhat odd ways, so I'd like to see a review of the sound situation before going forward with that patch.
PATCH 1/5 m68knommu: add a pgprot_noncached stub
Provide a pgprot_noncached like all the other nommu ports so that common code can rely on it being able to be present. Note that this is generally code that is not actually run on nommu, but at least we can avoid nasty ifdefs by having a stub.
--- arch/m68k/include/asm/pgtable_no.h | 2 ++ 1 file changed, 2 insertions(+)
arch/m68k/include/asm/pgtable_no.h +2 -0
@@ -29,6 +29,8 @@#define PAGE_READONLY __pgprot(0)#define PAGE_KERNEL __pgprot(0) +#define pgprot_noncached (prot) (prot) +extern void paging_init (void );#define swapper_pg_dir ((pgd_t *) 0)
Signature · 1 line
2.20.1
PATCH 2/5 dma-mapping: move the dma_get_sgtable API comments from arm to common code
In reply to Christoph HellwigThe comments are spot on and should be near the central API, not just near a single implementation.
--- arch/arm/mm/dma-mapping.c | 11 ----------- kernel/dma/mapping.c | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-)
arch/arm/mm/dma-mapping.c +0 -11
@@ -877,17 +877,6 @@ static void arm_coherent_dma_free(struct device *dev, size_t size, void *cpu_add__arm_dma_free (dev, size, cpu_addr, handle, attrs, true); } -/* -* The whole dma_get_sgtable() idea is fundamentally unsafe - it seems -* that the intention is to allow exporting memory allocated via the -* coherent DMA APIs through the dma_buf API, which only accepts a -* scattertable. This presents a couple of problems: -* 1. Not all memory allocated via the coherent DMA APIs is backed by -* a struct page -* 2. Passing coherent DMA memory into the streaming APIs is not allowed -* as we will try to flush the memory through a different alias to that -* actually being used (and the flushes are redundant.) -*/ int arm_dma_get_sgtable (struct device *dev,struct sg_table *sgt,void *cpu_addr,dma_addr_t handle,size_t size,unsigned long attrs)
kernel/dma/mapping.c +11 -0
@@ -136,6 +136,17 @@ int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,return ret; } +/* +* The whole dma_get_sgtable() idea is fundamentally unsafe - it seems +* that the intention is to allow exporting memory allocated via the +* coherent DMA APIs through the dma_buf API, which only accepts a +* scattertable. This presents a couple of problems: +* 1. Not all memory allocated via the coherent DMA APIs is backed by +* a struct page +* 2. Passing coherent DMA memory into the streaming APIs is not allowed +* as we will try to flush the memory through a different alias to that +* actually being used (and the flushes are redundant.) +*/ int dma_get_sgtable_attrs (struct device *dev,struct sg_table *sgt,void *cpu_addr,dma_addr_t dma_addr,size_t size,unsigned long attrs)
Signature · 1 line
2.20.1
PATCH 3/5 dma-mapping: explicitly wire up ->mmap and ->get_sgtable
In reply to Christoph HellwigWhile the default ->mmap and ->get_sgtable implementations work for the majority of our dma_map_ops impementations they are inherently safe for others that don't use the page allocator or CMA and/or use their own way of remapping not covered by the common code. So remove the defaults if these methods are not wired up, but instead wire up the default implementations for all safe instances.
--- arch/alpha/kernel/pci_iommu.c | 2 ++ arch/ia64/hp/common/sba_iommu.c | 2 ++ arch/ia64/sn/pci/pci_dma.c | 2 ++ arch/mips/jazz/jazzdma.c | 2 ++ arch/powerpc/kernel/dma-iommu.c | 2 ++ arch/powerpc/platforms/ps3/system-bus.c | 4 ++++ arch/powerpc/platforms/pseries/vio.c | 2 ++ arch/s390/pci/pci_dma.c | 2 ++ arch/sparc/kernel/iommu.c | 2 ++ arch/sparc/kernel/pci_sun4v.c | 2 ++ arch/x86/kernel/amd_gart_64.c | 2 ++ arch/x86/kernel/pci-calgary_64.c | 2 ++ drivers/iommu/amd_iommu.c | 2 ++ drivers/iommu/intel-iommu.c | 2 ++ kernel/dma/mapping.c | 20 ++++++++++++-------- 15 files changed, 42 insertions(+), 8 deletions(-)
arch/alpha/kernel/pci_iommu.c +2 -0
@@ -955,5 +955,7 @@ const struct dma_map_ops alpha_pci_ops = { .map_sg = alpha_pci_map_sg, .unmap_sg = alpha_pci_unmap_sg, .dma_supported = alpha_pci_supported, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };EXPORT_SYMBOL (alpha_pci_ops);
arch/ia64/hp/common/sba_iommu.c +2 -0
@@ -2183,6 +2183,8 @@ const struct dma_map_ops sba_dma_ops = { .map_sg = sba_map_sg_attrs, .unmap_sg = sba_unmap_sg_attrs, .dma_supported = sba_dma_supported, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };void sba_dma_init (void )
arch/ia64/sn/pci/pci_dma.c +2 -0
@@ -438,6 +438,8 @@ static struct dma_map_ops sn_dma_ops = { .unmap_sg = sn_dma_unmap_sg, .dma_supported = sn_dma_supported, .get_required_mask = sn_dma_get_required_mask, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };void sn_dma_init (void )
arch/mips/jazz/jazzdma.c +2 -0
@@ -682,5 +682,7 @@ const struct dma_map_ops jazz_dma_ops = { .sync_sg_for_device = jazz_dma_sync_sg_for_device, .dma_supported = dma_direct_supported, .cache_sync = arch_dma_cache_sync, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };EXPORT_SYMBOL (jazz_dma_ops);
arch/powerpc/kernel/dma-iommu.c +2 -0
@@ -208,4 +208,6 @@ const struct dma_map_ops dma_iommu_ops = { .sync_single_for_device = dma_iommu_sync_for_device, .sync_sg_for_cpu = dma_iommu_sync_sg_for_cpu, .sync_sg_for_device = dma_iommu_sync_sg_for_device, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };
arch/powerpc/platforms/ps3/system-bus.c +4 -0
@@ -700,6 +700,8 @@ static const struct dma_map_ops ps3_sb_dma_ops = { .get_required_mask = ps3_dma_get_required_mask, .map_page = ps3_sb_map_page, .unmap_page = ps3_unmap_page, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };static const struct dma_map_ops ps3_ioc0_dma_ops = {
@@ -711,6 +713,8 @@ static const struct dma_map_ops ps3_ioc0_dma_ops = { .get_required_mask = ps3_dma_get_required_mask, .map_page = ps3_ioc0_map_page, .unmap_page = ps3_unmap_page, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };/**
arch/powerpc/platforms/pseries/vio.c +2 -0
@@ -605,6 +605,8 @@ static const struct dma_map_ops vio_dma_mapping_ops = { .unmap_page = vio_dma_iommu_unmap_page, .dma_supported = dma_iommu_dma_supported, .get_required_mask = dma_iommu_get_required_mask, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };/**
arch/s390/pci/pci_dma.c +2 -0
@@ -668,6 +668,8 @@ const struct dma_map_ops s390_pci_dma_ops = { .unmap_sg = s390_dma_unmap_sg, .map_page = s390_dma_map_pages, .unmap_page = s390_dma_unmap_pages, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable,/* dma_supported is unconditionally true without a callback */ };EXPORT_SYMBOL_GPL (s390_pci_dma_ops);
arch/sparc/kernel/iommu.c +2 -0
@@ -763,6 +763,8 @@ static const struct dma_map_ops sun4u_dma_ops = { .sync_single_for_cpu = dma_4u_sync_single_for_cpu, .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu, .dma_supported = dma_4u_supported, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
arch/sparc/kernel/pci_sun4v.c +2 -0
@@ -692,6 +692,8 @@ static const struct dma_map_ops sun4v_dma_ops = { .map_sg = dma_4v_map_sg, .unmap_sg = dma_4v_unmap_sg, .dma_supported = dma_4v_supported, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };static void pci_sun4v_scan_bus (struct pci_pbm_info *pbm,struct device *parent)
arch/x86/kernel/amd_gart_64.c +2 -0
@@ -678,6 +678,8 @@ static const struct dma_map_ops gart_dma_ops = { .alloc = gart_alloc_coherent, .free = gart_free_coherent, .dma_supported = dma_direct_supported, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };static void gart_iommu_shutdown (void )
arch/x86/kernel/pci-calgary_64.c +2 -0
@@ -468,6 +468,8 @@ static const struct dma_map_ops calgary_dma_ops = { .map_page = calgary_map_page, .unmap_page = calgary_unmap_page, .dma_supported = dma_direct_supported, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };static inline void __iomem *busno_to_bbar (unsigned char num)
drivers/iommu/amd_iommu.c +2 -0
@@ -2722,6 +2722,8 @@ static const struct dma_map_ops amd_iommu_dma_ops = { .map_sg = map_sg, .unmap_sg = unmap_sg, .dma_supported = amd_iommu_dma_supported, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };static int init_reserved_iova_ranges (void )
drivers/iommu/intel-iommu.c +2 -0
@@ -3737,6 +3737,8 @@ static const struct dma_map_ops intel_dma_ops = { .map_resource = intel_map_resource, .unmap_resource = intel_unmap_resource, .dma_supported = dma_direct_supported, + .mmap = dma_common_mmap, + .get_sgtable = dma_common_get_sgtable, };static inline int iommu_domain_cache_init (void )
kernel/dma/mapping.c +12 -8
@@ -153,11 +153,12 @@ int dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, {const struct dma_map_ops *ops =get_dma_ops (dev); -if (!dma_is_direct (ops) && ops->get_sgtable) -return ops->get_sgtable (dev, sgt, cpu_addr, dma_addr, size, - attrs); -return dma_common_get_sgtable (dev, sgt, cpu_addr, dma_addr, size, - attrs); +if (dma_is_direct (ops)) +return dma_common_get_sgtable (dev, sgt, cpu_addr, dma_addr, + size, attrs); +if (!ops->get_sgtable) +return -ENXIO ; +return ops->get_sgtable (dev, sgt, cpu_addr, dma_addr, size, attrs); }EXPORT_SYMBOL (dma_get_sgtable_attrs);
@@ -221,9 +222,12 @@ int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, {const struct dma_map_ops *ops =get_dma_ops (dev); -if (!dma_is_direct (ops) && ops->mmap) -return ops->mmap (dev, vma, cpu_addr, dma_addr, size, attrs); -return dma_common_mmap (dev, vma, cpu_addr, dma_addr, size, attrs); +if (dma_is_direct (ops)) +return dma_common_mmap (dev, vma, cpu_addr, dma_addr, size, + attrs); +if (!ops->mmap) +return -ENXIO ; +return ops->mmap (dev, vma, cpu_addr, dma_addr, size, attrs); }EXPORT_SYMBOL (dma_mmap_attrs);
Signature · 1 line
2.20.1
PATCH 4/5 dma-mapping: provide a better default ->get_required_mask
In reply to Christoph HellwigMost dma_map_ops instances are IOMMUs that work perfectly fine in 32-bits of IOVA space, and the generic direct mapping code already provides its own routines that is intelligent based on the amount of memory actually present. Wire up the dma-direct routine for the ARM direct mapping code as well, and otherwise default to the constant 32-bit mask. This way we only need to override it for the occasional odd IOMMU that requires 64-bit IOVA support, or IOMMU drivers that are more efficient if they can fall back to the direct mapping.
--- arch/arm/mm/dma-mapping.c | 3 +++ arch/powerpc/platforms/ps3/system-bus.c | 7 ------ arch/x86/kernel/amd_gart_64.c | 1 + kernel/dma/mapping.c | 30 +++++++++---------------- 4 files changed, 14 insertions(+), 27 deletions(-)
arch/arm/mm/dma-mapping.c +3 -0
@@ -14,6 +14,7 @@#include <linux/list.h> #include <linux/init.h> #include <linux/device.h> +#include <linux/dma-direct.h> #include <linux/dma-mapping.h> #include <linux/dma-noncoherent.h> #include <linux/dma-contiguous.h>
@@ -192,6 +193,7 @@ const struct dma_map_ops arm_dma_ops = { .sync_sg_for_cpu = arm_dma_sync_sg_for_cpu, .sync_sg_for_device = arm_dma_sync_sg_for_device, .dma_supported = arm_dma_supported, + .get_required_mask = dma_direct_get_required_mask, };EXPORT_SYMBOL (arm_dma_ops);
@@ -212,6 +214,7 @@ const struct dma_map_ops arm_coherent_dma_ops = { .map_sg = arm_dma_map_sg, .map_resource = dma_direct_map_resource, .dma_supported = arm_dma_supported, + .get_required_mask = dma_direct_get_required_mask, };EXPORT_SYMBOL (arm_coherent_dma_ops);
arch/powerpc/platforms/ps3/system-bus.c +0 -7
@@ -686,18 +686,12 @@ static int ps3_dma_supported(struct device *_dev, u64 mask)return mask >=DMA_BIT_MASK (32 ); } -static u64 ps3_dma_get_required_mask (struct device *_dev) -{ -return DMA_BIT_MASK (32 ); -} -static const struct dma_map_ops ps3_sb_dma_ops = { .alloc = ps3_alloc_coherent, .free = ps3_free_coherent, .map_sg = ps3_sb_map_sg, .unmap_sg = ps3_sb_unmap_sg, .dma_supported = ps3_dma_supported, - .get_required_mask = ps3_dma_get_required_mask, .map_page = ps3_sb_map_page, .unmap_page = ps3_unmap_page, .mmap = dma_common_mmap,
@@ -710,7 +704,6 @@ static const struct dma_map_ops ps3_ioc0_dma_ops = { .map_sg = ps3_ioc0_map_sg, .unmap_sg = ps3_ioc0_unmap_sg, .dma_supported = ps3_dma_supported, - .get_required_mask = ps3_dma_get_required_mask, .map_page = ps3_ioc0_map_page, .unmap_page = ps3_unmap_page, .mmap = dma_common_mmap,
arch/x86/kernel/amd_gart_64.c +1 -0
@@ -680,6 +680,7 @@ static const struct dma_map_ops gart_dma_ops = { .dma_supported = dma_direct_supported, .mmap = dma_common_mmap, .get_sgtable = dma_common_get_sgtable, + .get_required_mask = dma_direct_get_required_mask, };static void gart_iommu_shutdown (void )
kernel/dma/mapping.c +10 -20
@@ -231,25 +231,6 @@ int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, }EXPORT_SYMBOL (dma_mmap_attrs); -static u64 dma_default_get_required_mask (struct device *dev) -{ -u32 low_totalram = ((max_pfn -1 ) <<PAGE_SHIFT ); -u32 high_totalram = ((max_pfn -1 ) >> (32 -PAGE_SHIFT )); -u64 mask; - -if (!high_totalram) { -/* convert to mask just covering totalram */ - low_totalram = (1 << (fls (low_totalram) -1 )); - low_totalram += low_totalram -1 ; - mask = low_totalram; - }else { - high_totalram = (1 << (fls (high_totalram) -1 )); - high_totalram += high_totalram -1 ; - mask = (((u64 )high_totalram) <<32 ) +0xffffffff ; - } -return mask; -} -u64 dma_get_required_mask (struct device *dev) {const struct dma_map_ops *ops =get_dma_ops (dev);
@@ -258,7 +239,16 @@ u64 dma_get_required_mask(struct device *dev)return dma_direct_get_required_mask (dev);if (ops->get_required_mask)return ops->get_required_mask (dev); -return dma_default_get_required_mask (dev); + +/* +* We require every DMA ops implementation to at least support a 32-bit +* DMA mask (and use bounce buffering if that isn't supported in +* hardware). As the direct mapping code has its own routine to +* actually report an optimal mask we default to 32-bit here as that +* is the right thing for most IOMMUs, and at least not actively +* harmful in general. +*/ +return DMA_BIT_MASK (32 ); }EXPORT_SYMBOL_GPL (dma_get_required_mask);
Signature · 1 line
2.20.1
Geert Uytterhoeven
maintainerRe: [PATCH 4/5] dma-mapping: provide a better default ->get_required_mask
Hi Christoph,
Quoted 8 lines · Christoph Hellwig
Most
dma_map_opsinstances are IOMMUs that work perfectly fine in 32-bits of IOVA space, and the generic direct mapping code already provides its own routines that is intelligent based on the amount of memory actually present. Wire up the dma-direct routine for the ARM direct mapping code as well, and otherwise default to the constant 32-bit mask. This way we only need to override it for the occasional odd IOMMU that requires 64-bit IOVA support, or IOMMU drivers that are more efficient if they can fall back to the direct mapping.
As I know you like diving into cans of worms ;-)
Does 64-bit IOVA support actually work in general? Or only on 64-bit platforms, due to dma_addr_t to unsigned long truncation on 32-bit?
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH 4/5] dma-mapping: provide a better default ->get_required_mask
Quoted 12 lines · Geert Uytterhoeven
Hi Christoph,
Quoted 8 lines · Christoph Hellwig
Most
dma_map_opsinstances are IOMMUs that work perfectly fine in 32-bits of IOVA space, and the generic direct mapping code already provides its own routines that is intelligent based on the amount of memory actually present. Wire up the dma-direct routine for the ARM direct mapping code as well, and otherwise default to the constant 32-bit mask. This way we only need to override it for the occasional odd IOMMU that requires 64-bit IOVA support, or IOMMU drivers that are more efficient if they can fall back to the direct mapping.
Quoted 4 lines
As I know you like diving into cans of worms ;-)
Does 64-bit IOVA support actually work in general? Or only on 64-bit platforms, due to
dma_addr_tto unsigned long truncation on 32-bit?
Most IOMMUs use 32-bit IOVAs, and thus we default to the 32-bit mask because it is common and failsafe vs the normal linux assumptions. However the ia64 SGI SN2 platform, and the powerpc IBM ebus implementations seem to require a 64-bit mask already, so we keep that behavior as is.
PATCH 5/5 dma-mapping: remove ARCH_NO_COHERENT_DMA_MMAP
In reply to Christoph HellwigNow that we never use a default ->mmap implementation, and non-coherent architectures can control the presence of ->mmap support by enabling ARCH_HAS_DMA_COHERENT_TO_PFN for the dma direct implementation there is no need for a global config option to control the availability of dma_common_mmap.
--- arch/Kconfig | 3 --- arch/c6x/Kconfig | 1 - arch/m68k/Kconfig | 1 - arch/microblaze/Kconfig | 1 - arch/parisc/Kconfig | 1 - arch/sh/Kconfig | 1 - arch/xtensa/Kconfig | 1 - kernel/dma/mapping.c | 4 ---- sound/core/pcm_native.c | 10 +--------- 9 files changed, 1 insertion(+), 22 deletions(-)
arch/Kconfig +0 -3
@@ -790,9 +790,6 @@ config COMPAT_32BIT_TIME This is relevant on all 32-bit architectures, and 64-bit architectures as part of compat syscall handling. -config ARCH_NO_COHERENT_DMA_MMAP - bool - config ARCH_NO_PREEMPT bool
arch/c6x/Kconfig +0 -1
@@ -20,7 +20,6 @@ config C6X select OF_EARLY_FLATTREE select GENERIC_CLOCKEVENTS select MODULES_USE_ELF_RELA - select ARCH_NO_COHERENT_DMA_MMAP select MMU_GATHER_NO_RANGE if MMU config MMU
arch/m68k/Kconfig +0 -1
@@ -8,7 +8,6 @@ config M68K select ARCH_HAS_DMA_PREP_COHERENT if HAS_DMA && MMU && !COLDFIRE select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA select ARCH_MIGHT_HAVE_PC_PARPORT if ISA - select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_NO_PREEMPT if !COLDFIRE select BINFMT_FLAT_ARGVP_ENVP_ON_STACK select DMA_DIRECT_REMAP if HAS_DMA && MMU && !COLDFIRE
arch/microblaze/Kconfig +0 -1
@@ -9,7 +9,6 @@ config MICROBLAZE select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_MIGHT_HAVE_PC_PARPORT - select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_WANT_IPC_PARSE_VERSION select BUILDTIME_EXTABLE_SORT select TIMER_OF
arch/parisc/Kconfig +0 -1
@@ -52,7 +52,6 @@ config PARISC select GENERIC_SCHED_CLOCK select HAVE_UNSTABLE_SCHED_CLOCK if SMP select GENERIC_CLOCKEVENTS - select ARCH_NO_COHERENT_DMA_MMAP select CPU_NO_EFFICIENT_FFS select NEED_DMA_MAP_STATE select NEED_SG_DMA_LENGTH
arch/sh/Kconfig +0 -1
@@ -5,7 +5,6 @@ config SUPERH select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_MIGHT_HAVE_PC_PARPORT - select ARCH_NO_COHERENT_DMA_MMAP if !MMU select HAVE_PATA_PLATFORM select CLKDEV_LOOKUP select DMA_DECLARE_COHERENT
arch/xtensa/Kconfig +0 -1
@@ -5,7 +5,6 @@ config XTENSA select ARCH_HAS_BINFMT_FLAT if !MMU select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE - select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS select ARCH_WANT_FRAME_POINTERS
kernel/dma/mapping.c +0 -4
@@ -169,7 +169,6 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, void *cpu_addr, dma_addr_t dma_addr, size_t size, unsigned long attrs) { -#ifndef CONFIG_ARCH_NO_COHERENT_DMA_MMAP unsigned long user_count = vma_pages(vma);unsigned long count =PAGE_ALIGN (size) >>PAGE_SHIFT ;unsigned long off = vma->vm_pgoff;
@@ -198,9 +197,6 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,return remap_pfn_range (vma, vma->vm_start, pfn + vma->vm_pgoff, user_count <<PAGE_SHIFT , vma->vm_page_prot); -#else -return -ENXIO ; -#endif /* !CONFIG_ARCH_NO_COHERENT_DMA_MMAP */ }/**
sound/core/pcm_native.c +1 -9
@@ -218,15 +218,7 @@ int snd_pcm_info_user(struct snd_pcm_substream *substream,static bool hw_support_mmap (struct snd_pcm_substream *substream) { -if (!(substream->runtime->hw.info &SNDRV_PCM_INFO_MMAP )) -return false; -/* architecture supports dma_mmap_coherent()? */ -#if defined(CONFIG_ARCH_NO_COHERENT_DMA_MMAP ) || !defined(CONFIG_HAS_DMA ) -if (!substream->ops->mmap && - substream->dma_buffer.dev.type =SNDRV_DMA_TYPE_DEV ) -return false; -#endif -return true; +return substream->runtime->hw.info &SNDRV_PCM_INFO_MMAP ; } static int constrain_mask_params(struct snd_pcm_substream *substream,
Signature · 1 line
2.20.1
Re: [PATCH 5/5] dma-mapping: remove ARCH_NO_COHERENT_DMA_MMAP
Takashi,
any comments on the sounds/ side of this?
Quoted 156 lines · Christoph Hellwig
Now that we never use a default ->mmap implementation, and non-coherent architectures can control the presence of ->mmap support by enabling
ARCH_HAS_DMA_COHERENT_TO_PFNfor the dma direct implementation there is no need for a global config option to control the availability ofdma_common_mmap.Signed-off-by Christoph Hellwig <[email protected]>--- arch/Kconfig | 3 --- arch/c6x/Kconfig | 1 - arch/m68k/Kconfig | 1 - arch/microblaze/Kconfig | 1 - arch/parisc/Kconfig | 1 - arch/sh/Kconfig | 1 - arch/xtensa/Kconfig | 1 - kernel/dma/mapping.c | 4 ---- sound/core/pcm_native.c | 10 +--------- 9 files changed, 1 insertion(+), 22 deletions(-)arch/Kconfig +0
-3@@ -790,9 +790,6 @@ config COMPAT_32BIT_TIME This is relevant on all 32-bit architectures, and 64-bit architectures as part of compat syscall handling. -config ARCH_NO_COHERENT_DMA_MMAP - bool - config ARCH_NO_PREEMPT boolarch/c6x/Kconfig +0
-1@@ -20,7 +20,6 @@ config C6X select OF_EARLY_FLATTREE select GENERIC_CLOCKEVENTS select MODULES_USE_ELF_RELA - select ARCH_NO_COHERENT_DMA_MMAP select MMU_GATHER_NO_RANGE if MMU config MMUarch/m68k/Kconfig +0
-1@@ -8,7 +8,6 @@ config M68K select ARCH_HAS_DMA_PREP_COHERENT if HAS_DMA && MMU && !COLDFIRE select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA select ARCH_MIGHT_HAVE_PC_PARPORT if ISA - select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_NO_PREEMPT if !COLDFIRE select BINFMT_FLAT_ARGVP_ENVP_ON_STACK select DMA_DIRECT_REMAP if HAS_DMA && MMU && !COLDFIREarch/microblaze/Kconfig +0
-1@@ -9,7 +9,6 @@ config MICROBLAZE select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_MIGHT_HAVE_PC_PARPORT - select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_WANT_IPC_PARSE_VERSION select BUILDTIME_EXTABLE_SORT select TIMER_OFarch/parisc/Kconfig +0
-1@@ -52,7 +52,6 @@ config PARISC select GENERIC_SCHED_CLOCK select HAVE_UNSTABLE_SCHED_CLOCK if SMP select GENERIC_CLOCKEVENTS - select ARCH_NO_COHERENT_DMA_MMAP select CPU_NO_EFFICIENT_FFS select NEED_DMA_MAP_STATE select NEED_SG_DMA_LENGTHarch/sh/Kconfig +0
-1@@ -5,7 +5,6 @@ config SUPERH select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_MIGHT_HAVE_PC_PARPORT - select ARCH_NO_COHERENT_DMA_MMAP if !MMU select HAVE_PATA_PLATFORM select CLKDEV_LOOKUP select DMA_DECLARE_COHERENTarch/xtensa/Kconfig +0
-1@@ -5,7 +5,6 @@ config XTENSA select ARCH_HAS_BINFMT_FLAT if !MMU select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE - select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS select ARCH_WANT_FRAME_POINTERSkernel/dma/mapping.c +0
-4@@ -169,7 +169,6 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, void *cpu_addr, dma_addr_t dma_addr, size_t size, unsigned long attrs) { -#ifndef CONFIG_ARCH_NO_COHERENT_DMA_MMAP unsigned long user_count = vma_pages(vma);unsigned long count =PAGE_ALIGN (size) >>PAGE_SHIFT ;unsigned long off = vma->vm_pgoff;@@ -198,9 +197,6 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,return remap_pfn_range (vma, vma->vm_start, pfn + vma->vm_pgoff, user_count <<PAGE_SHIFT , vma->vm_page_prot); -#else -return -ENXIO ; -#endif /* !CONFIG_ARCH_NO_COHERENT_DMA_MMAP */ }/** sound/core/pcm_native.c +1
-9@@ -218,15 +218,7 @@ int snd_pcm_info_user(struct snd_pcm_substream *substream,static bool hw_support_mmap (struct snd_pcm_substream *substream) { -if (!(substream->runtime->hw.info &SNDRV_PCM_INFO_MMAP )) -return false; -/* architecture supports dma_mmap_coherent()? */ -#if defined(CONFIG_ARCH_NO_COHERENT_DMA_MMAP ) || !defined(CONFIG_HAS_DMA ) -if (!substream->ops->mmap && - substream->dma_buffer.dev.type =SNDRV_DMA_TYPE_DEV ) -return false; -#endif -return true; +return substream->runtime->hw.info &SNDRV_PCM_INFO_MMAP ; } static int constrain_mask_params(struct snd_pcm_substream *substream,Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
---end quoted text---
Re: [PATCH 5/5] dma-mapping: remove ARCH_NO_COHERENT_DMA_MMAP
Quoted 4 lines · Christoph Hellwig
Takashi,
any comments on the sounds/ side of this?
I wasn't careful enough to look at that change, sorry.
The code there tries to check whether dma_mmap_coherent() would always fail on some platforms. Then the driver clears the mmap capability flag at the device open time and notifies user-space to fall back to the dumb read/write mode.
So I'm afraid that simply dropping the check would cause the behavior regression, e.g. on PARISC.
Is there any simple way to test whether dma_mmap_coherent() would work or not in general on the target platform? It's not necessarily in an ifdef at all.
thanks,
Takashi
Quoted 159 lines · Christoph Hellwig
Quoted 156 lines
Now that we never use a default ->mmap implementation, and non-coherent architectures can control the presence of ->mmap support by enabling
ARCH_HAS_DMA_COHERENT_TO_PFNfor the dma direct implementation there is no need for a global config option to control the availability ofdma_common_mmap.Signed-off-by Christoph Hellwig <[email protected]>--- arch/Kconfig | 3 --- arch/c6x/Kconfig | 1 - arch/m68k/Kconfig | 1 - arch/microblaze/Kconfig | 1 - arch/parisc/Kconfig | 1 - arch/sh/Kconfig | 1 - arch/xtensa/Kconfig | 1 - kernel/dma/mapping.c | 4 ---- sound/core/pcm_native.c | 10 +--------- 9 files changed, 1 insertion(+), 22 deletions(-)arch/Kconfig +0
-3@@ -790,9 +790,6 @@ config COMPAT_32BIT_TIME This is relevant on all 32-bit architectures, and 64-bit architectures as part of compat syscall handling. -config ARCH_NO_COHERENT_DMA_MMAP - bool - config ARCH_NO_PREEMPT boolarch/c6x/Kconfig +0
-1@@ -20,7 +20,6 @@ config C6X select OF_EARLY_FLATTREE select GENERIC_CLOCKEVENTS select MODULES_USE_ELF_RELA - select ARCH_NO_COHERENT_DMA_MMAP select MMU_GATHER_NO_RANGE if MMU config MMUarch/m68k/Kconfig +0
-1@@ -8,7 +8,6 @@ config M68K select ARCH_HAS_DMA_PREP_COHERENT if HAS_DMA && MMU && !COLDFIRE select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA select ARCH_MIGHT_HAVE_PC_PARPORT if ISA - select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_NO_PREEMPT if !COLDFIRE select BINFMT_FLAT_ARGVP_ENVP_ON_STACK select DMA_DIRECT_REMAP if HAS_DMA && MMU && !COLDFIREarch/microblaze/Kconfig +0
-1@@ -9,7 +9,6 @@ config MICROBLAZE select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_MIGHT_HAVE_PC_PARPORT - select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_WANT_IPC_PARSE_VERSION select BUILDTIME_EXTABLE_SORT select TIMER_OFarch/parisc/Kconfig +0
-1@@ -52,7 +52,6 @@ config PARISC select GENERIC_SCHED_CLOCK select HAVE_UNSTABLE_SCHED_CLOCK if SMP select GENERIC_CLOCKEVENTS - select ARCH_NO_COHERENT_DMA_MMAP select CPU_NO_EFFICIENT_FFS select NEED_DMA_MAP_STATE select NEED_SG_DMA_LENGTHarch/sh/Kconfig +0
-1@@ -5,7 +5,6 @@ config SUPERH select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_MIGHT_HAVE_PC_PARPORT - select ARCH_NO_COHERENT_DMA_MMAP if !MMU select HAVE_PATA_PLATFORM select CLKDEV_LOOKUP select DMA_DECLARE_COHERENTarch/xtensa/Kconfig +0
-1@@ -5,7 +5,6 @@ config XTENSA select ARCH_HAS_BINFMT_FLAT if !MMU select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE - select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS select ARCH_WANT_FRAME_POINTERSkernel/dma/mapping.c +0
-4@@ -169,7 +169,6 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, void *cpu_addr, dma_addr_t dma_addr, size_t size, unsigned long attrs) { -#ifndef CONFIG_ARCH_NO_COHERENT_DMA_MMAP unsigned long user_count = vma_pages(vma);unsigned long count =PAGE_ALIGN (size) >>PAGE_SHIFT ;unsigned long off = vma->vm_pgoff;@@ -198,9 +197,6 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,return remap_pfn_range (vma, vma->vm_start, pfn + vma->vm_pgoff, user_count <<PAGE_SHIFT , vma->vm_page_prot); -#else -return -ENXIO ; -#endif /* !CONFIG_ARCH_NO_COHERENT_DMA_MMAP */ }/** sound/core/pcm_native.c +1
-9@@ -218,15 +218,7 @@ int snd_pcm_info_user(struct snd_pcm_substream *substream,static bool hw_support_mmap (struct snd_pcm_substream *substream) { -if (!(substream->runtime->hw.info &SNDRV_PCM_INFO_MMAP )) -return false; -/* architecture supports dma_mmap_coherent()? */ -#if defined(CONFIG_ARCH_NO_COHERENT_DMA_MMAP ) || !defined(CONFIG_HAS_DMA ) -if (!substream->ops->mmap && - substream->dma_buffer.dev.type =SNDRV_DMA_TYPE_DEV ) -return false; -#endif -return true; +return substream->runtime->hw.info &SNDRV_PCM_INFO_MMAP ; } static int constrain_mask_params(struct snd_pcm_substream *substream,Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel---end quoted text---
Re: [PATCH 5/5] dma-mapping: remove ARCH_NO_COHERENT_DMA_MMAP
Quoted 7 lines · Takashi Iwai
I wasn't careful enough to look at that change, sorry.
The code there tries to check whether
dma_mmap_coherent()would always fail on some platforms. Then the driver clears the mmap capability flag at the device open time and notifies user-space to fall back to the dumb read/write mode.
Quoted 6 lines
So I'm afraid that simply dropping the check would cause the behavior regression, e.g. on PARISC.
Is there any simple way to test whether
dma_mmap_coherent()would work or not in general on the target platform? It's not necessarily in an ifdef at all.
This isn't really a platform, but a per-device question. I can add a "bool dma_can_mmap(struct device *dev)" helper to check that. But how do I get at a suitable struct device in hw_support_mmap()?
Re: [PATCH 5/5] dma-mapping: remove ARCH_NO_COHERENT_DMA_MMAP
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Takashi Iwai
I wasn't careful enough to look at that change, sorry.
The code there tries to check whether
dma_mmap_coherent()would always fail on some platforms. Then the driver clears the mmap capability flag at the device open time and notifies user-space to fall back to the dumb read/write mode.So I'm afraid that simply dropping the check would cause the behavior regression, e.g. on PARISC.
Quoted 6 lines
Quoted 3 lines
Is there any simple way to test whether
dma_mmap_coherent()would work or not in general on the target platform? It's not necessarily in an ifdef at all.This isn't really a platform, but a per-device question. I can add a "bool
dma_can_mmap(struct device *dev)" helper to check that.
Yes, this would fit perfect.
Quoted 2 lines
But how
do I get at a suitable struct device inhw_support_mmap()?
substream->dma_buffer.dev.dev can be that, which is used in the mmap helper side, snd_pcm_lib_default_mmap().
Thanks!
Takashi