Skip to contentSkip to conversation

dma-mapping updates for Linux 6.12

GIT PULL Merged Christoph Hellwig 4 participants 17 messages Sep 19, 2024 – Sep 22, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

The following changes since commit 47ac09b91befbb6a235ab620c32af719f8208399:

Linux 6.11-rc4 (2024-08-18 13:17:27 -0700)

are available in the Git repository at:

git://git.infradead.org/users/hch/dma-mapping.git tags/dma-mapping-6.12-2024-09-19

for you to fetch changes up to a5fb217f13f74b2af2ab366ffad522bae717f93c:

dma-mapping: reflow dma_supported (2024-09-12 16:28:00 +0200)

----------------------------------------------------------------
dma-mapping updates for linux 6.12

- support DMA zones for arm64 systems where memory starts at > 4GB (Baruch Siach, Catalin Marinas)
- support direct calls into dma-iommu and thus obsolete dma_map_ops for many common configurations (Leon Romanovsky)
- add DMA-API tracing (Sean Anderson)
- remove the not very useful return value from various dma_set_* APIs (Christoph Hellwig)
- misc cleanups and minor optimizations (Chen Y, Yosry Ahmed, Christoph Hellwig)

----------------------------------------------------------------
Baruch Siach (2):
arm64: mm: fix DMA zone when dma-ranges is missing
arm64: mm: keep low RAM dma zone

Catalin Marinas (2):
dma-mapping: replace zone_dma_bits by zone_dma_limit
arm64: support DMA zone above 4GB

Chen Yu (1):
dma-direct: optimize page freeing when it is not addressable

Christoph Hellwig (7):
scsi: check that busses support the DMA API before setting dma parameters
dma-mapping: don't return errors from dma_set_min_align_mask
dma-mapping: don't return errors from dma_set_seg_boundary
dma-mapping: don't return errors from dma_set_max_seg_size
vdpa_sim: don't select DMA_OPS
dma-mapping: clearly mark DMA ops as an architecture feature
dma-mapping: reflow dma_supported

Leon Romanovsky (4):
dma-mapping: call ->unmap_page and ->unmap_sg unconditionally
dma-mapping: direct calls for dma-iommu
dma-mapping: use IOMMU DMA calls for common alloc/free page calls
dma-mapping: reliably inform about DMA support for IOMMU

Sean Anderson (1):
dma-mapping: add tracing for dma-mapping API calls

Yosry Ahmed (1):
dma-mapping: use bit masking to check VM_DMA_COHERENT

 MAINTAINERS                                        |   1 +
 arch/Kconfig                                       |   9 +
 arch/alpha/Kconfig                                 |   2 +-
 arch/arm/Kconfig                                   |   2 +-
 arch/arm64/Kconfig                                 |   1 +
 arch/arm64/mm/init.c                               |  39 ++-
 arch/mips/Kconfig                                  |   2 +-
 arch/parisc/Kconfig                                |   2 +-
 arch/powerpc/Kconfig                               |   2 +-
 arch/powerpc/mm/mem.c                              |   5 +-
 arch/s390/Kconfig                                  |   2 +-
 arch/s390/mm/init.c                                |   2 +-
 arch/sparc/Kconfig                                 |   2 +-
 arch/x86/Kconfig                                   |   2 +-
 drivers/accel/qaic/qaic_drv.c                      |   4 +-
 drivers/dma/idma64.c                               |   4 +-
 drivers/dma/pl330.c                                |   5 +-
 drivers/dma/qcom/bam_dma.c                         |   6 +-
 drivers/dma/sh/rcar-dmac.c                         |   4 +-
 drivers/dma/ste_dma40.c                            |   6 +-
 drivers/gpu/drm/mediatek/mtk_drm_drv.c             |   6 +-
 drivers/iommu/Kconfig                              |   2 +-
 drivers/iommu/dma-iommu.c                          | 104 +++----
 drivers/iommu/intel/Kconfig                        |   1 -
 drivers/macintosh/macio_asic.c                     |   4 +-
 .../media/common/videobuf2/videobuf2-dma-contig.c  |   3 +-
 drivers/media/pci/intel/ipu6/Kconfig               |   7 +-
 drivers/media/pci/intel/ipu6/ipu6.c                |   4 +-
 drivers/mmc/host/mmci_stm32_sdmmc.c                |   3 +-
 drivers/net/ethernet/microsoft/mana/gdma_main.c    |   6 +-
 drivers/scsi/lpfc/lpfc_init.c                      |   7 +-
 drivers/scsi/scsi_lib.c                            |  11 +-
 drivers/vdpa/Kconfig                               |  10 +-
 drivers/xen/Kconfig                                |   4 +-
 include/linux/device.h                             |   7 +-
 include/linux/dma-direct.h                         |   2 +-
 include/linux/dma-map-ops.h                        |  19 +-
 include/linux/dma-mapping.h                        |  25 +-
 include/linux/iommu-dma.h                          | 155 ++++++++++
 include/trace/events/dma.h                         | 341 +++++++++++++++++++++
 kernel/dma/Kconfig                                 |   7 +-
 kernel/dma/Makefile                                |   4 +-
 kernel/dma/direct.c                                |   8 +-
 kernel/dma/dummy.c                                 |  21 ++
 kernel/dma/mapping.c                               | 115 ++++++-
 kernel/dma/ops_helpers.c                           |  14 +-
 kernel/dma/pool.c                                  |   4 +-
 kernel/dma/remap.c                                 |   6 +-
 kernel/dma/swiotlb.c                               |   6 +-
 49 files changed, 782 insertions(+), 226 deletions(-)
 create mode 100644 include/linux/iommu-dma.h
 create mode 100644 include/trace/events/dma.h
merge bot Merged
#1 lore raw
The pull request you sent on Thu, 19 Sep 2024 09:54:05 +0200:

The pull request you sent on Thu, 19 Sep 2024 09:54:05 +0200:

Quoted 1 line

git://git.infradead.org/users/hch/dma-mapping.git tags/dma-mapping-6.12-2024-09-19

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/726e2d0cf2bbc14e3bf38491cddda1a56fe18663

Thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/prtracker.html
#2 lore raw
In reply to Christoph Hellwig
Quoted 15 lines · Christoph Hellwig

The following changes since commit 47ac09b91befbb6a235ab620c32af719f8208399:

  Linux 6.11-rc4 (2024-08-18 13:17:27 -0700)

are available in the Git repository at:

  git://git.infradead.org/users/hch/dma-mapping.git tags/dma-mapping-6.12-2024-09-19

for you to fetch changes up to a5fb217f13f74b2af2ab366ffad522bae717f93c:

  dma-mapping: reflow dma_supported (2024-09-12 16:28:00 +0200)

----------------------------------------------------------------
dma-mapping updates for linux 6.12

Quoted 9 lines

 - support DMA zones for arm64 systems where memory starts at > 4GB (Baruch Siach, Catalin Marinas)
 - support direct calls into dma-iommu and thus obsolete dma_map_ops for many common configurations (Leon Romanovsky)
 - add DMA-API tracing (Sean Anderson)
 - remove the not very useful return value from various dma_set_* APIs (Christoph Hellwig)
 - misc cleanups and minor optimizations (Chen Y, Yosry Ahmed, Christoph Hellwig)

Hi Christoph and Linus,

This breaks using my laptop camera with gstreamer (with "gst-launch-1.0 v4l2src ! videoconvert ! autovideosink" or GNOME snapshot).

"git bisect" gives:

The first bad commit could be any of:
b5a73bf4d1de95e620bf5f592557b81f71c76f0e
833bd284a45448f04ab9fcd4fdf7ef594d458eed
c42a01264ba1497eb3193c08ff3c2656d98250a6
560a861ab4174b42240157ab5cebe36b8c7bc418
b5c58b2fdc427e7958412ecb2de2804a1f7c1572
334304ac2baca7f3e821c47cf5129d90e7a6b1e6

(I had to use "git bisect skip" several times because I encountered kernel panic on boot at some revisions.)

Reverting the merge fixes the issue. I'm not sure if this is related to the camera model (I can borrow another camera to test tomorrow).

Signature · 2 lines
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University
#3 lore raw
Quoted 2 lines · Xi Ruoyao

This breaks using my laptop camera with gstreamer (with "gst-launch-1.0 v4l2src ! videoconvert ! autovideosink" or GNOME snapshot).

What camere and driver are you using?

Quoted 2 lines

(I had to use "git bisect skip" several times because I encountered kernel panic on boot at some revisions.)

Do you have any traces of that?

#4 lore raw
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Xi Ruoyao

This breaks using my laptop camera with gstreamer (with "gst-launch-1.0 v4l2src ! videoconvert ! autovideosink" or GNOME snapshot).

What camere and driver are you using?

And what architecture and platform are you on?

#5 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Xi Ruoyao

This breaks using my laptop camera with gstreamer (with "gst- launch-1.0
v4l2src ! videoconvert ! autovideosink" or GNOME snapshot).

What camere and driver are you using?

Bus 003 Device 003: ID 0c45:6366 Microdia Webcam Vitade AF

The driver is uvcvideo.

Quoted 1 line

And what architecture and platform are you on?

A x86_64 laptop (with Core i5-11300H CPU).

Signature · 2 lines
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University
#6 lore raw
Quoted 7 lines · Xi Ruoyao
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Xi Ruoyao

This breaks using my laptop camera with gstreamer (with "gst- launch-1.0
v4l2src ! videoconvert ! autovideosink" or GNOME snapshot).

Quoted 5 lines
Quoted 1 line
Quoted 1 line

What camere and driver are you using?

Bus 003 Device 003: ID 0c45:6366 Microdia Webcam Vitade AF

The driver is uvcvideo.

And I just borrowed a different camera:

Bus 003 Device 010: ID 1bcf:2283 Sunplus Innovation Technology Inc. FULL HD webcam

It suffers the same issue so it's unlikely to be related to a specific camera model. This camera is also driven by uvcvideo.

v4l2gl from v4l-utils-1.28.1 suffers the issue either, so it's unlikely to be related to a specific userspace v4l2 program too.

Quoted 4 lines
Quoted 1 line

And what architecture and platform are you on?

A x86_64 laptop (with Core i5-11300H CPU).

Signature · 2 lines
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University
#7 lore raw
In reply to Xi Ruoyao
Quoted 9 lines · Xi Ruoyao
Quoted 1 line
Quoted 1 line

What camere and driver are you using?

Bus 003 Device 003: ID 0c45:6366 Microdia Webcam Vitade AF

The driver is uvcvideo.

Quoted 1 line

And what architecture and platform are you on?

A x86_64 laptop (with Core i5-11300H CPU).

Oh, so it's not arm64, which has the most juicy changes this time around.

Can you try the following "manual bisect" for me?

First test f69e342eec008e1bab772d3963c3dd9979293e13 to see if that works. If it doesn't work come back as I'm a bit lost :)

If it does work, try b5c58b2fdc427e7958412ecb2de2804a1f7c1572 next, if it doesn't work can you send me your dmesg?

We'll then work from there.

#8 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Xi Ruoyao
Quoted 1 line
Quoted 1 line

What camere and driver are you using?

Bus 003 Device 003: ID 0c45:6366 Microdia Webcam Vitade AF

The driver is uvcvideo.

Quoted 1 line

And what architecture and platform are you on?

A x86_64 laptop (with Core i5-11300H CPU).

Quoted 7 lines

Oh, so it's not arm64, which has the most juicy changes this time around.

Can you try the following "manual bisect" for me?

First test f69e342eec008e1bab772d3963c3dd9979293e13 to see if that works.  If it doesn't work come back as I'm a bit lost :)

Yes it works (kernel boots fine and camera works fine).

Quoted 2 lines

If it does work, try b5c58b2fdc427e7958412ecb2de2804a1f7c1572 next, if it doesn't work can you send me your dmesg?

It behaves completely erratically on boot. I cannot get a full log because the laptop has no serial output. And the behavior seems not deterministic. I have some transcript of messages I photoed in several boot attempts though:

Oops: general protection fault, probably non-canonical address 0xf5c1150c090c1cc1: 0000 [#1] PREEMPT SMP

BUG: kernel NULL pointer dereference, address: 0000000000000078

BUG: Bad page map in process systemd-journal pte:150000000b pmd:1641dc067
Signature · 2 lines
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University
#9 lore raw
Quoted 3 lines · Xi Ruoyao

because the laptop has no serial output. And the behavior seems not deterministic. I have some transcript of messages I photoed in several boot attempts though:

Can you send me the photos of the messages? Probably best offlist as the lists don't like attachments.

#10 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Xi Ruoyao

because the laptop has no serial output.  And the behavior seems not deterministic.  I have some transcript of messages I photoed in several boot attempts though:

Can you send me the photos of the messages?  Probably best offlist as the lists don't like attachments.

I've got something better: one attempt to boot b5c58b2fdc427e7958412ecb2de2804a1f7c1572 succeeded and I got a dmesg containing some Oops traces.

The camera does *not* work. And when I rebooted the system it hung (presumably related to these Oops).

The dmesg output and kernel config attached.

Signature · 2 lines
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University
#11 lore raw
Quoted 9 lines · Xi Ruoyao
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Xi Ruoyao

because the laptop has no serial output.  And the behavior seems not deterministic.  I have some transcript of messages I photoed in several boot attempts though:

Can you send me the photos of the messages?  Probably best offlist as the lists don't like attachments.

Quoted 6 lines

I've got something better: one attempt to boot b5c58b2fdc427e7958412ecb2de2804a1f7c1572 succeeded and I got a dmesg containing some Oops traces.

The camera does *not* work. And when I rebooted the system it hung (presumably related to these Oops).

So that oops actually comes from the sounds code and looks unrelated to DMA. I suspect that oops is what caused your crashes and thus messed up the DMA bisection. Can you try to boot with CONFIG_SND disabled and see where the bisection for the video issues lands?

(Sorry that all this is such a mess)

#12 lore raw
Quoted 14 lines · Christoph Hellwig
Quoted 13 lines · Xi Ruoyao
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Xi Ruoyao

because the laptop has no serial output.  And the behavior seems not deterministic.  I have some transcript of messages I photoed in several boot attempts though:

Can you send me the photos of the messages?  Probably best offlist as the lists don't like attachments.

I've got something better: one attempt to boot b5c58b2fdc427e7958412ecb2de2804a1f7c1572 succeeded and I got a dmesg containing some Oops traces.

Quoted 7 lines
Quoted 2 lines

The camera does *not* work.  And when I rebooted the system it hung (presumably related to these Oops).

So that oops actually comes from the sounds code and looks unrelated to DMA.  I suspect that oops is what caused your crashes and thus messed up the DMA bisection.  Can you try to boot with CONFIG_SND disabled and see where the bisection for the video issues lands?

With SND disabled, b5c58b2fdc427e7958412ecb2de2804a1f7c1572 boots fine (no oops), but the camera does not work. f69e342eec008e1bab772d3963c3dd9979293e13 boots fine and the camera works fine.

So the first bad commit is b5c58b2fdc427e7958412ecb2de2804a1f7c1572.

Signature · 2 lines
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University
#13 lore raw
Quoted 6 lines · Xi Ruoyao

With SND disabled, b5c58b2fdc427e7958412ecb2de2804a1f7c1572 boots fine (no oops), but the camera does not work. f69e342eec008e1bab772d3963c3dd9979293e13 boots fine and the camera works fine.

So the first bad commit is b5c58b2fdc427e7958412ecb2de2804a1f7c1572.

Thanks a lot for the bisection!

I took a quitck look what is special in the intersection of uvcvideo and that commit, and what springs to meind is that uvcvideo is one of the very few users of dma_alloc_noncontiguous, and while that and the free call for it got converted correctly, the conversion was missed for the vmap and mmap callbacks.

Can you test the fix below?

drivers/iommu/dma-iommu.c +33 -0
index 3672d619bcb691..2a9fa0c8cc00fe 100644
@@ -1038,6 +1038,21 @@ static void *iommu_dma_alloc_remap(struct device *dev, size_t size,
 	return NULL;
 }
 
+/*
+ * This is the actual return value from the iommu_dma_alloc_noncontiguous.
+ *
+ * The users of the DMA API should only care about the sg_table, but to make
+ * the DMA-API internal vmaping and freeing easier we stash away the page
+ * array as well (except for the fallback case).  This can go away any time,
+ * e.g. when a vmap-variant that takes a scatterlist comes along.
+ */
+struct dma_sgt_handle {
+	struct sg_table sgt;
+	struct page **pages;
+};
+#define sgt_handle(sgt) \
+	container_of((sgt), struct dma_sgt_handle, sgt)
+
 struct sg_table *iommu_dma_alloc_noncontiguous(struct device *dev, size_t size,
 	       enum dma_data_direction dir, gfp_t gfp, unsigned long attrs)
 {
@@ -1066,6 +1081,24 @@ void iommu_dma_free_noncontiguous(struct device *dev, size_t size,
 	kfree(sh);
 }
 
+void *iommu_dma_vmap_noncontiguous(struct device *dev, size_t size,
+		struct sg_table *sgt)
+{
+	unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
+
+	return vmap(sgt_handle(sgt)->pages, count, VM_MAP, PAGE_KERNEL);
+}
+
+int iommu_dma_mmap_noncontiguous(struct device *dev, struct vm_area_struct *vma,
+		size_t size, struct sg_table *sgt)
+{
+	unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
+
+	if (vma->vm_pgoff >= count || vma_pages(vma) > count - vma->vm_pgoff)
+		return -ENXIO;
+	return vm_map_pages(vma, sgt_handle(sgt)->pages, count);
+}
+
 void iommu_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
 		size_t size, enum dma_data_direction dir)
 {
include/linux/dma-map-ops.h +0 -19
index 9668ddf3696e71..b7773201414c27 100644
@@ -24,11 +24,6 @@ struct dma_map_ops {
 			gfp_t gfp);
 	void (*free_pages)(struct device *dev, size_t size, struct page *vaddr,
 			dma_addr_t dma_handle, enum dma_data_direction dir);
-	struct sg_table *(*alloc_noncontiguous)(struct device *dev, size_t size,
-			enum dma_data_direction dir, gfp_t gfp,
-			unsigned long attrs);
-	void (*free_noncontiguous)(struct device *dev, size_t size,
-			struct sg_table *sgt, enum dma_data_direction dir);
 	int (*mmap)(struct device *, struct vm_area_struct *,
 			void *, dma_addr_t, size_t, unsigned long attrs);
 
@@ -206,20 +201,6 @@ static inline int dma_mmap_from_global_coherent(struct vm_area_struct *vma,
 }
 #endif /* CONFIG_DMA_GLOBAL_POOL */
 
-/*
- * This is the actual return value from the ->alloc_noncontiguous method.
- * The users of the DMA API should only care about the sg_table, but to make
- * the DMA-API internal vmaping and freeing easier we stash away the page
- * array as well (except for the fallback case).  This can go away any time,
- * e.g. when a vmap-variant that takes a scatterlist comes along.
- */
-struct dma_sgt_handle {
-	struct sg_table sgt;
-	struct page **pages;
-};
-#define sgt_handle(sgt) \
-	container_of((sgt), struct dma_sgt_handle, sgt)
-
 int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
 		void *cpu_addr, dma_addr_t dma_addr, size_t size,
 		unsigned long attrs);
include/linux/iommu-dma.h +6 -0
index 1bb55ca1ab79d7..7bf145a52d6a1a 100644
@@ -44,6 +44,12 @@ struct sg_table *iommu_dma_alloc_noncontiguous(struct device *dev, size_t size,
 		enum dma_data_direction dir, gfp_t gfp, unsigned long attrs);
 void iommu_dma_free_noncontiguous(struct device *dev, size_t size,
 		struct sg_table *sgt, enum dma_data_direction dir);
+void *iommu_dma_vmap_noncontiguous(struct device *dev, size_t size,
+		struct sg_table *sgt);
+#define iommu_dma_vunmap_noncontiguous(dev, vaddr) \
+	vunmap(vaddr);
+int iommu_dma_mmap_noncontiguous(struct device *dev, struct vm_area_struct *vma,
+		size_t size, struct sg_table *sgt);
 void iommu_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
 		size_t size, enum dma_data_direction dir);
 void iommu_dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
kernel/dma/mapping.c +10 -27
index b839683da0baf0..7911c754d9f42a 100644
@@ -750,7 +750,6 @@ static struct sg_table *alloc_single_sgt(struct device *dev, size_t size,
 struct sg_table *dma_alloc_noncontiguous(struct device *dev, size_t size,
 		enum dma_data_direction dir, gfp_t gfp, unsigned long attrs)
 {
-	const struct dma_map_ops *ops = get_dma_ops(dev);
 	struct sg_table *sgt;
 
 	if (WARN_ON_ONCE(attrs & ~DMA_ATTR_ALLOC_SINGLE_PAGES))
@@ -758,9 +757,7 @@ struct sg_table *dma_alloc_noncontiguous(struct device *dev, size_t size,
 	if (WARN_ON_ONCE(gfp & __GFP_COMP))
 		return NULL;
 
-	if (ops && ops->alloc_noncontiguous)
-		sgt = ops->alloc_noncontiguous(dev, size, dir, gfp, attrs);
-	else if (use_dma_iommu(dev))
+	if (use_dma_iommu(dev))
 		sgt = iommu_dma_alloc_noncontiguous(dev, size, dir, gfp, attrs);
 	else
 		sgt = alloc_single_sgt(dev, size, dir, gfp);
@@ -786,13 +783,10 @@ static void free_single_sgt(struct device *dev, size_t size,
 void dma_free_noncontiguous(struct device *dev, size_t size,
 		struct sg_table *sgt, enum dma_data_direction dir)
 {
-	const struct dma_map_ops *ops = get_dma_ops(dev);
-
 	trace_dma_unmap_sg(dev, sgt->sgl, sgt->orig_nents, dir, 0);
 	debug_dma_unmap_sg(dev, sgt->sgl, sgt->orig_nents, dir);
-	if (ops && ops->free_noncontiguous)
-		ops->free_noncontiguous(dev, size, sgt, dir);
-	else if (use_dma_iommu(dev))
+
+	if (use_dma_iommu(dev))
 		iommu_dma_free_noncontiguous(dev, size, sgt, dir);
 	else
 		free_single_sgt(dev, size, sgt, dir);
@@ -802,37 +796,26 @@ EXPORT_SYMBOL_GPL(dma_free_noncontiguous);
 void *dma_vmap_noncontiguous(struct device *dev, size_t size,
 		struct sg_table *sgt)
 {
-	const struct dma_map_ops *ops = get_dma_ops(dev);
-	unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
 
-	if (ops && ops->alloc_noncontiguous)
-		return vmap(sgt_handle(sgt)->pages, count, VM_MAP, PAGE_KERNEL);
+	if (use_dma_iommu(dev))
+		return iommu_dma_vmap_noncontiguous(dev, size, sgt);
+
 	return page_address(sg_page(sgt->sgl));
 }
 EXPORT_SYMBOL_GPL(dma_vmap_noncontiguous);
 
 void dma_vunmap_noncontiguous(struct device *dev, void *vaddr)
 {
-	const struct dma_map_ops *ops = get_dma_ops(dev);
-
-	if (ops && ops->alloc_noncontiguous)
-		vunmap(vaddr);
+	if (use_dma_iommu(dev))
+		iommu_dma_vunmap_noncontiguous(dev, vaddr);
 }
 EXPORT_SYMBOL_GPL(dma_vunmap_noncontiguous);
 
 int dma_mmap_noncontiguous(struct device *dev, struct vm_area_struct *vma,
 		size_t size, struct sg_table *sgt)
 {
-	const struct dma_map_ops *ops = get_dma_ops(dev);
-
-	if (ops && ops->alloc_noncontiguous) {
-		unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
-
-		if (vma->vm_pgoff >= count ||
-		    vma_pages(vma) > count - vma->vm_pgoff)
-			return -ENXIO;
-		return vm_map_pages(vma, sgt_handle(sgt)->pages, count);
-	}
+	if (use_dma_iommu(dev))
+		return iommu_dma_mmap_noncontiguous(dev, vma, size, sgt);
 	return dma_mmap_pages(dev, vma, size, sg_page(sgt->sgl));
 }
 EXPORT_SYMBOL_GPL(dma_mmap_noncontiguous);
#14 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Xi Ruoyao

With SND disabled, b5c58b2fdc427e7958412ecb2de2804a1f7c1572 boots fine (no oops), but the camera does not work. f69e342eec008e1bab772d3963c3dd9979293e13 boots fine and the camera works fine.

So the first bad commit is b5c58b2fdc427e7958412ecb2de2804a1f7c1572.

Thanks a lot for the bisection!

Christoph,

Another chunk that is missing according to this BZ
https://bugzilla.kernel.org/show_bug.cgi?id=219292:

kernel/dma/mapping.c +1 -1
index b839683da0ba..cf3b89e681a3 100644
@@ -926,7 +926,7 @@ bool dma_addressing_limited(struct device *dev)
                         dma_get_required_mask(dev))
                return true;
 
-       if (unlikely(ops))
+       if (unlikely(ops) || use_dma_iommu(dev)
                return false;
        return !dma_direct_all_ram_mapped(dev);
 }

Sorry for such a mess.

Thanks

#16 lore raw
In reply to Christoph Hellwig
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Xi Ruoyao

With SND disabled, b5c58b2fdc427e7958412ecb2de2804a1f7c1572 boots fine (no oops), but the camera does not work. f69e342eec008e1bab772d3963c3dd9979293e13 boots fine and the camera works fine.

So the first bad commit is b5c58b2fdc427e7958412ecb2de2804a1f7c1572.

Thanks a lot for the bisection!

Quoted 7 lines

I took a quitck look what is special in the intersection of uvcvideo and that commit, and what springs to meind is that uvcvideo is one of the very few users of dma_alloc_noncontiguous, and while that and the free call for it got converted correctly, the conversion was missed for the vmap and mmap callbacks.

Can you test the fix below?

Yes with the fix the camera is working fine now. Thanks!

Quoted 189 lines
drivers/iommu/dma-iommu.c +0 -0
index 3672d619bcb691..2a9fa0c8cc00fe 100644
@@ -1038,6 +1038,21 @@ static void *iommu_dma_alloc_remap(struct device *dev, size_t size,
  	return NULL;
  }

drivers/iommu/dma-iommu.c +15 -0
+/*
+ * This is the actual return value from the iommu_dma_alloc_noncontiguous.
+ *
+ * The users of the DMA API should only care about the sg_table, but to make
+ * the DMA-API internal vmaping and freeing easier we stash away the page
+ * array as well (except for the fallback case).  This can go away any time,
+ * e.g. when a vmap-variant that takes a scatterlist comes along.
+ */
+struct dma_sgt_handle {
+	struct sg_table sgt;
+	struct page **pages;
+};
+#define sgt_handle(sgt) \
+	container_of((sgt), struct dma_sgt_handle, sgt)
+

 struct sg_table *iommu_dma_alloc_noncontiguous(struct device *dev, size_t size, enum dma_data_direction dir, gfp_t gfp, unsigned long attrs) {

drivers/iommu/dma-iommu.c +0 -0
@@ -1066,6 +1081,24 @@ void iommu_dma_free_noncontiguous(struct device *dev, size_t size,
  	kfree(sh);
  }

drivers/iommu/dma-iommu.c +18 -0
+void *iommu_dma_vmap_noncontiguous(struct device *dev, size_t size,
+		struct sg_table *sgt)
+{
+	unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
+
+	return vmap(sgt_handle(sgt)->pages, count, VM_MAP, PAGE_KERNEL);
+}
+
+int iommu_dma_mmap_noncontiguous(struct device *dev, struct vm_area_struct *vma,
+		size_t size, struct sg_table *sgt)
+{
+	unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
+
+	if (vma->vm_pgoff >= count || vma_pages(vma) > count - vma->vm_pgoff)
+		return -ENXIO;
+	return vm_map_pages(vma, sgt_handle(sgt)->pages, count);
+}
+

 void iommu_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, enum dma_data_direction dir)
 {

include/linux/dma-map-ops.h +0 -5
index 9668ddf3696e71..b7773201414c27 100644
@@ -24,11 +24,6 @@ struct dma_map_ops {
  			gfp_t gfp);
  	void (*free_pages)(struct device *dev, size_t size, struct page *vaddr,
  			dma_addr_t dma_handle, enum dma_data_direction dir);
-	struct sg_table *(*alloc_noncontiguous)(struct device *dev, size_t size,
-			enum dma_data_direction dir, gfp_t gfp,
-			unsigned long attrs);
-	void (*free_noncontiguous)(struct device *dev, size_t size,
-			struct sg_table *sgt, enum dma_data_direction dir);
  	int (*mmap)(struct device *, struct vm_area_struct *,
  			void *, dma_addr_t, size_t, unsigned long attrs);

include/linux/dma-map-ops.h +0 -0
@@ -206,20 +201,6 @@ static inline int dma_mmap_from_global_coherent(struct vm_area_struct *vma,
  }
  #endif /* CONFIG_DMA_GLOBAL_POOL */

include/linux/dma-map-ops.h +0 -14
-/*
- * This is the actual return value from the ->alloc_noncontiguous method.
- * The users of the DMA API should only care about the sg_table, but to make
- * the DMA-API internal vmaping and freeing easier we stash away the page
- * array as well (except for the fallback case).  This can go away any time,
- * e.g. when a vmap-variant that takes a scatterlist comes along.
- */
-struct dma_sgt_handle {
-	struct sg_table sgt;
-	struct page **pages;
-};
-#define sgt_handle(sgt) \
-	container_of((sgt), struct dma_sgt_handle, sgt)
-

 int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, void *cpu_addr, dma_addr_t dma_addr, size_t size, unsigned long attrs);

include/linux/iommu-dma.h +6 -0
index 1bb55ca1ab79d7..7bf145a52d6a1a 100644
@@ -44,6 +44,12 @@ struct sg_table *iommu_dma_alloc_noncontiguous(struct device *dev, size_t size,
  		enum dma_data_direction dir, gfp_t gfp, unsigned long attrs);
  void iommu_dma_free_noncontiguous(struct device *dev, size_t size,
  		struct sg_table *sgt, enum dma_data_direction dir);
+void *iommu_dma_vmap_noncontiguous(struct device *dev, size_t size,
+		struct sg_table *sgt);
+#define iommu_dma_vunmap_noncontiguous(dev, vaddr) \
+	vunmap(vaddr);
+int iommu_dma_mmap_noncontiguous(struct device *dev, struct vm_area_struct *vma,
+		size_t size, struct sg_table *sgt);
  void iommu_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
  		size_t size, enum dma_data_direction dir);
  void iommu_dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
kernel/dma/mapping.c +0 -1
index b839683da0baf0..7911c754d9f42a 100644
@@ -750,7 +750,6 @@ static struct sg_table *alloc_single_sgt(struct device *dev, size_t size,
  struct sg_table *dma_alloc_noncontiguous(struct device *dev, size_t size,
  		enum dma_data_direction dir, gfp_t gfp, unsigned long attrs)
  {
-	const struct dma_map_ops *ops = get_dma_ops(dev);
  	struct sg_table *sgt;


  if (WARN_ON_ONCE(attrs & ~DMA_ATTR_ALLOC_SINGLE_PAGES))

kernel/dma/mapping.c +0 -0
@@ -758,9 +757,7 @@ struct sg_table *dma_alloc_noncontiguous(struct device *dev, size_t size,
  	if (WARN_ON_ONCE(gfp & __GFP_COMP))
  		return NULL;

kernel/dma/mapping.c +1 -3
-	if (ops && ops->alloc_noncontiguous)
-		sgt = ops->alloc_noncontiguous(dev, size, dir, gfp, attrs);
-	else if (use_dma_iommu(dev))
+	if (use_dma_iommu(dev))

  sgt = iommu_dma_alloc_noncontiguous(dev, size, dir, gfp, attrs); else
  sgt = alloc_single_sgt(dev, size, dir, gfp);

kernel/dma/mapping.c +2 -5
@@ -786,13 +783,10 @@ static void free_single_sgt(struct device *dev, size_t size,
  void dma_free_noncontiguous(struct device *dev, size_t size,
  		struct sg_table *sgt, enum dma_data_direction dir)
  {
-	const struct dma_map_ops *ops = get_dma_ops(dev);
-
  	trace_dma_unmap_sg(dev, sgt->sgl, sgt->orig_nents, dir, 0);
  	debug_dma_unmap_sg(dev, sgt->sgl, sgt->orig_nents, dir);
-	if (ops && ops->free_noncontiguous)
-		ops->free_noncontiguous(dev, size, sgt, dir);
-	else if (use_dma_iommu(dev))
+
+	if (use_dma_iommu(dev))
  		iommu_dma_free_noncontiguous(dev, size, sgt, dir);

  else
  free_single_sgt(dev, size, sgt, dir);

kernel/dma/mapping.c +0 -2
@@ -802,37 +796,26 @@ EXPORT_SYMBOL_GPL(dma_free_noncontiguous);
  void *dma_vmap_noncontiguous(struct device *dev, size_t size,
  		struct sg_table *sgt)
  {
-	const struct dma_map_ops *ops = get_dma_ops(dev);
-	unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;

kernel/dma/mapping.c +3 -2
-	if (ops && ops->alloc_noncontiguous)
-		return vmap(sgt_handle(sgt)->pages, count, VM_MAP, PAGE_KERNEL);
+	if (use_dma_iommu(dev))
+		return iommu_dma_vmap_noncontiguous(dev, size, sgt);
+

  return page_address(sg_page(sgt->sgl));
 }
 EXPORT_SYMBOL_GPL(dma_vmap_noncontiguous);

 void dma_vunmap_noncontiguous(struct device *dev, void *vaddr) {

kernel/dma/mapping.c +2 -4
-	const struct dma_map_ops *ops = get_dma_ops(dev);
-
-	if (ops && ops->alloc_noncontiguous)
-		vunmap(vaddr);
+	if (use_dma_iommu(dev))
+		iommu_dma_vunmap_noncontiguous(dev, vaddr);

 }
 EXPORT_SYMBOL_GPL(dma_vunmap_noncontiguous);

 int dma_mmap_noncontiguous(struct device *dev, struct vm_area_struct *vma, size_t size, struct sg_table *sgt)
 {

kernel/dma/mapping.c +2 -10
-	const struct dma_map_ops *ops = get_dma_ops(dev);
-
-	if (ops && ops->alloc_noncontiguous) {
-		unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
-
-		if (vma->vm_pgoff >= count ||
-		    vma_pages(vma) > count - vma->vm_pgoff)
-			return -ENXIO;
-		return vm_map_pages(vma, sgt_handle(sgt)->pages, count);
-	}
+	if (use_dma_iommu(dev))
+		return iommu_dma_mmap_noncontiguous(dev, vma, size, sgt);

  return dma_mmap_pages(dev, vma, size, sg_page(sgt->sgl)); }
 EXPORT_SYMBOL_GPL(dma_mmap_noncontiguous);

Signature · 2 lines
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University