Skip to contentSkip to conversation

RFC: switch to use the generic remapping dma-allocator

PATCH New Christoph Hellwig 2 participants 5 messages Nov 21, 2022

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

Hi all,

currently parisc has it's own implementation of the dma-coherent allocator that sets up PTEs with the uncached bit. I can't see any reason why using vmap to do the same kind of setup shouldn't work. This small series shows how that could work, but due to a lack of actual parisc hardware it is compile tested only and not only needs a careful review but also actual testing on hardware.

Diffstat:

 arch/parisc/Kconfig               |    4 
 arch/parisc/include/asm/pgtable.h |    1 
 arch/parisc/kernel/pci-dma.c      |  446 +-------------------------------------
 include/linux/dma-map-ops.h       |    1 
 kernel/dma/Kconfig                |    3 
 kernel/dma/direct.c               |    4 
 6 files changed, 24 insertions(+), 435 deletions(-)
#1 lore raw

PATCH 1/2 dma-mapping: add a arch_can_dma_alloc_coherent hook

This hook allows an architecture to reject coherent DMA allocations entirely if they can't be supported. This will be useful to convert parisc and m68knommu to the generic dma-direct code.

---
 include/linux/dma-map-ops.h | 1 +
 kernel/dma/Kconfig          | 3 +++
 kernel/dma/direct.c         | 4 ++++
 3 files changed, 8 insertions(+)
include/linux/dma-map-ops.h +1 -0
index d678afeb8a13a..10272f95cdb64 100644
@@ -344,6 +344,7 @@ static inline void arch_dma_mark_clean(phys_addr_t paddr, size_t size)
 }
 #endif /* ARCH_HAS_DMA_MARK_CLEAN */
 
+bool arch_can_dma_alloc_coherent(void);
 void *arch_dma_set_uncached(void *addr, size_t size);
 void arch_dma_clear_uncached(void *addr, size_t size);
 
kernel/dma/Kconfig +3 -0
index 56866aaa2ae1a..6fd4efe71d136 100644
@@ -20,6 +20,9 @@ config DMA_OPS
 config DMA_OPS_BYPASS
 	bool
 
+config ARCH_HAS_CAN_DMA_ALLOC_COHERENT
+	bool
+
 # Lets platform IOMMU driver choose between bypass and IOMMU
 config ARCH_HAS_DMA_MAP_DIRECT
 	bool
kernel/dma/direct.c +4 -0
index 63859a101ed83..03929482e92f7 100644
@@ -232,6 +232,10 @@ void *dma_direct_alloc(struct device *dev, size_t size,
 			return arch_dma_alloc(dev, size, dma_handle, gfp,
 					      attrs);
 
+		if (IS_ENABLED(CONFIG_ARCH_HAS_CAN_DMA_ALLOC_COHERENT) &&
+		    !arch_can_dma_alloc_coherent())
+			return NULL;
+
 		/*
 		 * If there is a global pool, always allocate from it for
 		 * non-coherent devices.
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/2 parisc: use the generic remapping dma allocator

In reply to Christoph Hellwig

Use the dma-direct code that uses vmap to create an uncacheable mapping for coherent allocations instead of the hand-crafted bitmap.

---
 arch/parisc/Kconfig               |   4 +
 arch/parisc/include/asm/pgtable.h |   1 -
 arch/parisc/kernel/pci-dma.c      | 446 +-----------------------------
 3 files changed, 16 insertions(+), 435 deletions(-)
arch/parisc/Kconfig +4 -0
index a98940e642432..c1c8bec74aa7c 100644
@@ -8,6 +8,8 @@ config PARISC
 	select HAVE_FUNCTION_GRAPH_TRACER
 	select HAVE_SYSCALL_TRACEPOINTS
 	select ARCH_WANT_FRAME_POINTERS
+	select ARCH_HAS_CAN_DMA_ALLOC_COHERENT
+	select ARCH_HAS_DMA_PREP_COHERENT
 	select ARCH_HAS_ELF_RANDOMIZE
 	select ARCH_HAS_STRICT_KERNEL_RWX
 	select ARCH_HAS_STRICT_MODULE_RWX
@@ -19,6 +21,8 @@ config PARISC
 	select ARCH_STACKWALK
 	select ARCH_HAS_DEBUG_VM_PGTABLE
 	select HAVE_RELIABLE_STACKTRACE
+	select DMA_COHERENT_POOL
+	select DMA_DIRECT_REMAP
 	select DMA_OPS
 	select RTC_CLASS
 	select RTC_DRV_GENERIC
arch/parisc/include/asm/pgtable.h +0 -1
index ecd0288544698..d76013716f694 100644
@@ -263,7 +263,6 @@ extern void __update_cache(pte_t pte);
 #define PAGE_KERNEL_EXEC	__pgprot(_PAGE_KERNEL_EXEC)
 #define PAGE_KERNEL_RWX	__pgprot(_PAGE_KERNEL_RWX)
 #define PAGE_KERNEL_RO	__pgprot(_PAGE_KERNEL_RO)
-#define PAGE_KERNEL_UNC	__pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
 #define PAGE_GATEWAY    __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_GATEWAY| _PAGE_READ)
 
 
arch/parisc/kernel/pci-dma.c +12 -434

458 lines not on this page · raw message

Signature · 1 line
2.30.2
maintainer
#3 lore raw
In reply to Christoph Hellwig

Hi Christoph,

Quoted 6 lines · Christoph Hellwig

currently parisc has it's own implementation of the dma-coherent allocator that sets up PTEs with the uncached bit. I can't see any reason why using vmap to do the same kind of setup shouldn't work. This small series shows how that could work, but due to a lack of actual parisc hardware it is compile tested only and not only needs a careful review but also actual testing on hardware.

Very interesting!
I'll give it a spin on real hardware and will come back with the results...

Thanks!
Helge

Quoted 8 lines

Diffstat:

  arch/parisc/Kconfig               |    4
  arch/parisc/include/asm/pgtable.h |    1
  arch/parisc/kernel/pci-dma.c      |  446 +-------------------------------------
  include/linux/dma-map-ops.h       |    1
  kernel/dma/Kconfig                |    3
  kernel/dma/direct.c               |    4
  6 files changed, 24 insertions(+), 435 deletions(-)
maintainer
#4 lore raw
Quoted 10 lines · Helge Deller
Quoted 6 lines · Christoph Hellwig

currently parisc has it's own implementation of the dma-coherent allocator that sets up PTEs with the uncached bit.  I can't see any reason why using vmap to do the same kind of setup shouldn't work. This small series shows how that could work, but due to a lack of actual parisc hardware it is compile tested only and not only needs a careful review but also actual testing on hardware.

Very interesting!
I'll give it a spin on real hardware and will come back with the results...

kernel builds & boots with those patches.
SCSI drives are detected, but SCSI communication fails afterwards:

[   13.509173] zalon_probe: Zalon version 1, IRQ 68
[   13.564410] ncr53c720-0: rev 0xf irq 68
[   13.614207] ncr53c720-0: ID 7, Fast-10, Parity Checking, Differential
[   13.696785] scsi host0: ncr53c8xx-3.4.3g
[   17.575885] scsi 0:0:6:0: Direct-Access     SEAGATE  ST32171W         HP03 PQ: 0 ANSI: 2
[   17.673111] scsi target0:0:6: Beginning Domain Validation
[   17.742479] scsi target0:0:6: asynchronous
[   17.806301] scsi target0:0:6: wide asynchronous
[   17.871736] scsi target0:0:6: FAST-10 WIDE SCSI 20.0 MB/s ST (100 ns, offset 8)
[   17.965723] scsi target0:0:6: Domain Validation skipping write tests
[   18.041560] scsi target0:0:6: Ending Domain Validation
[   20.448322] 53c700: Version 2.8 By [email protected]
[   20.528403] scsi1: 53c710 rev 2
[   21.567995] scsi host1: LASI SCSI 53c700
[   21.936685] scsi 1:0:1:0: CD-ROM            PHILIPS  PCA80SC          V3-0 PQ: 0 ANSI: 2
[   22.033927] scsi target1:0:1: Beginning Domain Validation
[   22.100102] scsi target1:0:1: asynchronous
[   22.161326] scsi target1:0:1: FAST-10 SCSI 10.0 MB/s ST (100 ns, offset 8)
[   22.250962] scsi target1:0:1: Domain Validation skipping write tests
[   22.326829] scsi target1:0:1: Ending Domain Validation
[   23.972351] st: Version 20160209, fixed bufsize 32768, s/g segs 256
[   24.052265] sd 0:0:6:0: Power-on or device reset occurred
[   24.117020] sr 1:0:1:0: Power-on or device reset occurred
[   24.185309] sd 0:0:6:0: [sda] 4194685 512-byte logical blocks: (2.15 GB/2.00 GiB)
[   24.279279] sd 0:0:6:0: [sda] Write Protect is off
[   24.336921] sr 1:0:1:0: [sr0] scsi-1 drive
[   24.386003] cdrom: Uniform CD-ROM driver Revision: 3.20
[   24.451015] sd 0:0:6:0: [sda] Write cache: disabled, read cache: enabled, supports DPO and FUA
[   24.569057] sd 0:0:6:0: Attached scsi generic sg0 type 0
[   24.634080] sr 1:0:1:0: Attached scsi generic sg1 type 5
...
[   28.246342] EXT4-fs (sda5): mounting ext3 file system using the ext4 subsystem
[   28.338790] ncr53c720-0:6: ERROR (81:0) (0-0-0) (8/1b) @ (mem 43c:00000000).
[   28.343500] ncr53c720-0: regdump:
[   28.343500]  da
[   28.343500]  10
[   28.343500]  c0
[   28.343500]  1b
[   28.343500]  47
[   28.343500]  08
[   28.343500]  06
[   28.343500]  07
[   28.343500]  45
[   28.343500]  08
[   28.343500]  86
[   28.343500]  af
[   28.343500]  80
[   28.343500]  00
[   28.343500]  07
[   28.343500]  0b
[   28.343500] .

Helge