summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2019-08-06 08:01:50 -0400
committerChristoph Hellwig <hch@lst.de>2019-09-04 05:13:18 -0400
commitf9f3232a7d0ab73a33d11f4056c5823010f03d55 (patch)
tree021c07b01f104492a5d049a885bc8fb931839c34
parent14451467014b4c8aff6570b44b6d0ee68cd49bc0 (diff)
dma-mapping: explicitly wire up ->mmap and ->get_sgtable
While 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. Fixes: e1c7e324539a ("dma-mapping: always provide the dma_map_ops based implementation") Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r--arch/alpha/kernel/pci_iommu.c2
-rw-r--r--arch/ia64/hp/common/sba_iommu.c2
-rw-r--r--arch/ia64/sn/pci/pci_dma.c2
-rw-r--r--arch/mips/jazz/jazzdma.c2
-rw-r--r--arch/powerpc/kernel/dma-iommu.c2
-rw-r--r--arch/powerpc/platforms/ps3/system-bus.c4
-rw-r--r--arch/powerpc/platforms/pseries/vio.c2
-rw-r--r--arch/s390/pci/pci_dma.c2
-rw-r--r--arch/x86/kernel/amd_gart_64.c2
-rw-r--r--arch/x86/kernel/pci-calgary_64.c2
-rw-r--r--drivers/iommu/amd_iommu.c2
-rw-r--r--drivers/iommu/intel-iommu.c2
-rw-r--r--drivers/parisc/ccio-dma.c2
-rw-r--r--drivers/parisc/sba_iommu.c2
-rw-r--r--kernel/dma/mapping.c20
15 files changed, 42 insertions, 8 deletions
diff --git a/arch/alpha/kernel/pci_iommu.c b/arch/alpha/kernel/pci_iommu.c
index 242108439f42..7f1925a32c99 100644
--- a/arch/alpha/kernel/pci_iommu.c
+++ b/arch/alpha/kernel/pci_iommu.c
@@ -955,5 +955,7 @@ const struct dma_map_ops alpha_pci_ops = {
955 .map_sg = alpha_pci_map_sg, 955 .map_sg = alpha_pci_map_sg,
956 .unmap_sg = alpha_pci_unmap_sg, 956 .unmap_sg = alpha_pci_unmap_sg,
957 .dma_supported = alpha_pci_supported, 957 .dma_supported = alpha_pci_supported,
958 .mmap = dma_common_mmap,
959 .get_sgtable = dma_common_get_sgtable,
958}; 960};
959EXPORT_SYMBOL(alpha_pci_ops); 961EXPORT_SYMBOL(alpha_pci_ops);
diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
index 3d24cc43385b..4c0ea6c2833d 100644
--- a/arch/ia64/hp/common/sba_iommu.c
+++ b/arch/ia64/hp/common/sba_iommu.c
@@ -2183,6 +2183,8 @@ const struct dma_map_ops sba_dma_ops = {
2183 .map_sg = sba_map_sg_attrs, 2183 .map_sg = sba_map_sg_attrs,
2184 .unmap_sg = sba_unmap_sg_attrs, 2184 .unmap_sg = sba_unmap_sg_attrs,
2185 .dma_supported = sba_dma_supported, 2185 .dma_supported = sba_dma_supported,
2186 .mmap = dma_common_mmap,
2187 .get_sgtable = dma_common_get_sgtable,
2186}; 2188};
2187 2189
2188void sba_dma_init(void) 2190void sba_dma_init(void)
diff --git a/arch/ia64/sn/pci/pci_dma.c b/arch/ia64/sn/pci/pci_dma.c
index b7d42e4edc1f..12ffb9c0d738 100644
--- a/arch/ia64/sn/pci/pci_dma.c
+++ b/arch/ia64/sn/pci/pci_dma.c
@@ -438,6 +438,8 @@ static struct dma_map_ops sn_dma_ops = {
438 .unmap_sg = sn_dma_unmap_sg, 438 .unmap_sg = sn_dma_unmap_sg,
439 .dma_supported = sn_dma_supported, 439 .dma_supported = sn_dma_supported,
440 .get_required_mask = sn_dma_get_required_mask, 440 .get_required_mask = sn_dma_get_required_mask,
441 .mmap = dma_common_mmap,
442 .get_sgtable = dma_common_get_sgtable,
441}; 443};
442 444
443void sn_dma_init(void) 445void sn_dma_init(void)
diff --git a/arch/mips/jazz/jazzdma.c b/arch/mips/jazz/jazzdma.c
index 1804dc9d8136..a01e14955187 100644
--- a/arch/mips/jazz/jazzdma.c
+++ b/arch/mips/jazz/jazzdma.c
@@ -682,5 +682,7 @@ const struct dma_map_ops jazz_dma_ops = {
682 .sync_sg_for_device = jazz_dma_sync_sg_for_device, 682 .sync_sg_for_device = jazz_dma_sync_sg_for_device,
683 .dma_supported = dma_direct_supported, 683 .dma_supported = dma_direct_supported,
684 .cache_sync = arch_dma_cache_sync, 684 .cache_sync = arch_dma_cache_sync,
685 .mmap = dma_common_mmap,
686 .get_sgtable = dma_common_get_sgtable,
685}; 687};
686EXPORT_SYMBOL(jazz_dma_ops); 688EXPORT_SYMBOL(jazz_dma_ops);
diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
index a0879674a9c8..2f5a53874f6d 100644
--- a/arch/powerpc/kernel/dma-iommu.c
+++ b/arch/powerpc/kernel/dma-iommu.c
@@ -208,4 +208,6 @@ const struct dma_map_ops dma_iommu_ops = {
208 .sync_single_for_device = dma_iommu_sync_for_device, 208 .sync_single_for_device = dma_iommu_sync_for_device,
209 .sync_sg_for_cpu = dma_iommu_sync_sg_for_cpu, 209 .sync_sg_for_cpu = dma_iommu_sync_sg_for_cpu,
210 .sync_sg_for_device = dma_iommu_sync_sg_for_device, 210 .sync_sg_for_device = dma_iommu_sync_sg_for_device,
211 .mmap = dma_common_mmap,
212 .get_sgtable = dma_common_get_sgtable,
211}; 213};
diff --git a/arch/powerpc/platforms/ps3/system-bus.c b/arch/powerpc/platforms/ps3/system-bus.c
index 98410119c47b..70fcc9736a8c 100644
--- a/arch/powerpc/platforms/ps3/system-bus.c
+++ b/arch/powerpc/platforms/ps3/system-bus.c
@@ -700,6 +700,8 @@ static const struct dma_map_ops ps3_sb_dma_ops = {
700 .get_required_mask = ps3_dma_get_required_mask, 700 .get_required_mask = ps3_dma_get_required_mask,
701 .map_page = ps3_sb_map_page, 701 .map_page = ps3_sb_map_page,
702 .unmap_page = ps3_unmap_page, 702 .unmap_page = ps3_unmap_page,
703 .mmap = dma_common_mmap,
704 .get_sgtable = dma_common_get_sgtable,
703}; 705};
704 706
705static const struct dma_map_ops ps3_ioc0_dma_ops = { 707static const struct dma_map_ops ps3_ioc0_dma_ops = {
@@ -711,6 +713,8 @@ static const struct dma_map_ops ps3_ioc0_dma_ops = {
711 .get_required_mask = ps3_dma_get_required_mask, 713 .get_required_mask = ps3_dma_get_required_mask,
712 .map_page = ps3_ioc0_map_page, 714 .map_page = ps3_ioc0_map_page,
713 .unmap_page = ps3_unmap_page, 715 .unmap_page = ps3_unmap_page,
716 .mmap = dma_common_mmap,
717 .get_sgtable = dma_common_get_sgtable,
714}; 718};
715 719
716/** 720/**
diff --git a/arch/powerpc/platforms/pseries/vio.c b/arch/powerpc/platforms/pseries/vio.c
index 6601b9d404dc..3473eef7628c 100644
--- a/arch/powerpc/platforms/pseries/vio.c
+++ b/arch/powerpc/platforms/pseries/vio.c
@@ -605,6 +605,8 @@ static const struct dma_map_ops vio_dma_mapping_ops = {
605 .unmap_page = vio_dma_iommu_unmap_page, 605 .unmap_page = vio_dma_iommu_unmap_page,
606 .dma_supported = dma_iommu_dma_supported, 606 .dma_supported = dma_iommu_dma_supported,
607 .get_required_mask = dma_iommu_get_required_mask, 607 .get_required_mask = dma_iommu_get_required_mask,
608 .mmap = dma_common_mmap,
609 .get_sgtable = dma_common_get_sgtable,
608}; 610};
609 611
610/** 612/**
diff --git a/arch/s390/pci/pci_dma.c b/arch/s390/pci/pci_dma.c
index 9e52d1527f71..03d8c1c9f82f 100644
--- a/arch/s390/pci/pci_dma.c
+++ b/arch/s390/pci/pci_dma.c
@@ -668,6 +668,8 @@ const struct dma_map_ops s390_pci_dma_ops = {
668 .unmap_sg = s390_dma_unmap_sg, 668 .unmap_sg = s390_dma_unmap_sg,
669 .map_page = s390_dma_map_pages, 669 .map_page = s390_dma_map_pages,
670 .unmap_page = s390_dma_unmap_pages, 670 .unmap_page = s390_dma_unmap_pages,
671 .mmap = dma_common_mmap,
672 .get_sgtable = dma_common_get_sgtable,
671 /* dma_supported is unconditionally true without a callback */ 673 /* dma_supported is unconditionally true without a callback */
672}; 674};
673EXPORT_SYMBOL_GPL(s390_pci_dma_ops); 675EXPORT_SYMBOL_GPL(s390_pci_dma_ops);
diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
index a585ea6f686a..f72c487d68a8 100644
--- a/arch/x86/kernel/amd_gart_64.c
+++ b/arch/x86/kernel/amd_gart_64.c
@@ -677,6 +677,8 @@ static const struct dma_map_ops gart_dma_ops = {
677 .unmap_page = gart_unmap_page, 677 .unmap_page = gart_unmap_page,
678 .alloc = gart_alloc_coherent, 678 .alloc = gart_alloc_coherent,
679 .free = gart_free_coherent, 679 .free = gart_free_coherent,
680 .mmap = dma_common_mmap,
681 .get_sgtable = dma_common_get_sgtable,
680 .dma_supported = dma_direct_supported, 682 .dma_supported = dma_direct_supported,
681}; 683};
682 684
diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
index 9d4343aa481b..23fdec030c37 100644
--- a/arch/x86/kernel/pci-calgary_64.c
+++ b/arch/x86/kernel/pci-calgary_64.c
@@ -468,6 +468,8 @@ static const struct dma_map_ops calgary_dma_ops = {
468 .map_page = calgary_map_page, 468 .map_page = calgary_map_page,
469 .unmap_page = calgary_unmap_page, 469 .unmap_page = calgary_unmap_page,
470 .dma_supported = dma_direct_supported, 470 .dma_supported = dma_direct_supported,
471 .mmap = dma_common_mmap,
472 .get_sgtable = dma_common_get_sgtable,
471}; 473};
472 474
473static inline void __iomem * busno_to_bbar(unsigned char num) 475static inline void __iomem * busno_to_bbar(unsigned char num)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index b607a92791d3..2e74ad659985 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2722,6 +2722,8 @@ static const struct dma_map_ops amd_iommu_dma_ops = {
2722 .map_sg = map_sg, 2722 .map_sg = map_sg,
2723 .unmap_sg = unmap_sg, 2723 .unmap_sg = unmap_sg,
2724 .dma_supported = amd_iommu_dma_supported, 2724 .dma_supported = amd_iommu_dma_supported,
2725 .mmap = dma_common_mmap,
2726 .get_sgtable = dma_common_get_sgtable,
2725}; 2727};
2726 2728
2727static int init_reserved_iova_ranges(void) 2729static int init_reserved_iova_ranges(void)
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 12d094d08c0a..dca1b06ce4ec 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -3738,6 +3738,8 @@ static const struct dma_map_ops intel_dma_ops = {
3738 .map_resource = intel_map_resource, 3738 .map_resource = intel_map_resource,
3739 .unmap_resource = intel_unmap_resource, 3739 .unmap_resource = intel_unmap_resource,
3740 .dma_supported = dma_direct_supported, 3740 .dma_supported = dma_direct_supported,
3741 .mmap = dma_common_mmap,
3742 .get_sgtable = dma_common_get_sgtable,
3741}; 3743};
3742 3744
3743static inline int iommu_domain_cache_init(void) 3745static inline int iommu_domain_cache_init(void)
diff --git a/drivers/parisc/ccio-dma.c b/drivers/parisc/ccio-dma.c
index 217f15aafa4a..1d7125d29bee 100644
--- a/drivers/parisc/ccio-dma.c
+++ b/drivers/parisc/ccio-dma.c
@@ -1024,6 +1024,8 @@ static const struct dma_map_ops ccio_ops = {
1024 .unmap_page = ccio_unmap_page, 1024 .unmap_page = ccio_unmap_page,
1025 .map_sg = ccio_map_sg, 1025 .map_sg = ccio_map_sg,
1026 .unmap_sg = ccio_unmap_sg, 1026 .unmap_sg = ccio_unmap_sg,
1027 .mmap = dma_common_mmap,
1028 .get_sgtable = dma_common_get_sgtable,
1027}; 1029};
1028 1030
1029#ifdef CONFIG_PROC_FS 1031#ifdef CONFIG_PROC_FS
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index 296668caf7e5..fa4df65b7e28 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -1084,6 +1084,8 @@ static const struct dma_map_ops sba_ops = {
1084 .unmap_page = sba_unmap_page, 1084 .unmap_page = sba_unmap_page,
1085 .map_sg = sba_map_sg, 1085 .map_sg = sba_map_sg,
1086 .unmap_sg = sba_unmap_sg, 1086 .unmap_sg = sba_unmap_sg,
1087 .mmap = dma_common_mmap,
1088 .get_sgtable = dma_common_get_sgtable,
1087}; 1089};
1088 1090
1089 1091
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index a136932b8e6d..c8b4e46407ba 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -153,11 +153,12 @@ int dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt,
153{ 153{
154 const struct dma_map_ops *ops = get_dma_ops(dev); 154 const struct dma_map_ops *ops = get_dma_ops(dev);
155 155
156 if (!dma_is_direct(ops) && ops->get_sgtable) 156 if (dma_is_direct(ops))
157 return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size, 157 return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr,
158 attrs); 158 size, attrs);
159 return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size, 159 if (!ops->get_sgtable)
160 attrs); 160 return -ENXIO;
161 return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size, attrs);
161} 162}
162EXPORT_SYMBOL(dma_get_sgtable_attrs); 163EXPORT_SYMBOL(dma_get_sgtable_attrs);
163 164
@@ -240,9 +241,12 @@ int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma,
240{ 241{
241 const struct dma_map_ops *ops = get_dma_ops(dev); 242 const struct dma_map_ops *ops = get_dma_ops(dev);
242 243
243 if (!dma_is_direct(ops) && ops->mmap) 244 if (dma_is_direct(ops))
244 return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs); 245 return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size,
245 return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size, attrs); 246 attrs);
247 if (!ops->mmap)
248 return -ENXIO;
249 return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
246} 250}
247EXPORT_SYMBOL(dma_mmap_attrs); 251EXPORT_SYMBOL(dma_mmap_attrs);
248 252