diff mbox series

[v4,02/15] dma: Allow dma_get_cache_alignment() to return the smaller cache_line_size()

Message ID 20230518173403.1150549-3-catalin.marinas@arm.com (mailing list archive)
State New
Headers show
Series mm, dma, arm64: Reduce ARCH_KMALLOC_MINALIGN to 8 | expand

Commit Message

Catalin Marinas May 18, 2023, 5:33 p.m. UTC
On architectures like arm64, ARCH_DMA_MINALIGN is larger than most cache
line size configurations deployed. However, the single kernel binary
requirement doesn't allow the smaller ARCH_DMA_MINALIGN. Permit an
architecture to opt in to dma_get_cache_alignment() returning
cache_line_size() which can be probed at run-time.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 include/linux/dma-mapping.h | 2 ++
 kernel/dma/Kconfig          | 7 +++++++
 2 files changed, 9 insertions(+)

Comments

Christoph Hellwig May 20, 2023, 5:42 a.m. UTC | #1
On Thu, May 18, 2023 at 06:33:50PM +0100, Catalin Marinas wrote:
> On architectures like arm64, ARCH_DMA_MINALIGN is larger than most cache
> line size configurations deployed. However, the single kernel binary
> requirement doesn't allow the smaller ARCH_DMA_MINALIGN. Permit an
> architecture to opt in to dma_get_cache_alignment() returning
> cache_line_size() which can be probed at run-time.
> 
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Will Deacon <will@kernel.org>
> ---
>  include/linux/dma-mapping.h | 2 ++
>  kernel/dma/Kconfig          | 7 +++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
> index 3288a1339271..b29124341317 100644
> --- a/include/linux/dma-mapping.h
> +++ b/include/linux/dma-mapping.h
> @@ -545,6 +545,8 @@ static inline int dma_set_min_align_mask(struct device *dev,
>  
>  static inline int dma_get_cache_alignment(void)
>  {
> +	if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_CACHE_LINE_SIZE))
> +		return cache_line_size();
>  #ifdef ARCH_HAS_DMA_MINALIGN
>  	return ARCH_DMA_MINALIGN;
>  #endif

Maybe allowing architectures to simply override
dma_get_cache_alignment would be a little cleaner rather than adding
yet another abstraction?  That might also be able to repace
ARCH_DMA_MINALIGN in follow on cleanup.
Christoph Hellwig May 20, 2023, 6:14 a.m. UTC | #2
On Sat, May 20, 2023 at 07:42:09AM +0200, Christoph Hellwig wrote:
> yet another abstraction?  That might also be able to repace
> ARCH_DMA_MINALIGN in follow on cleanup.

Looking at the rest of the series, this part is obviously not going to
work..
Catalin Marinas May 20, 2023, 10:34 a.m. UTC | #3
On Sat, May 20, 2023 at 08:14:41AM +0200, Christoph Hellwig wrote:
> On Sat, May 20, 2023 at 07:42:09AM +0200, Christoph Hellwig wrote:
> > yet another abstraction?  That might also be able to repace
> > ARCH_DMA_MINALIGN in follow on cleanup.
> 
> Looking at the rest of the series, this part is obviously not going to
> work..

ARCH_DMA_MINALIGN needs to remain a constant (taking over from the
original ARCH_KMALLOC_MINALIGN). But the dma_get_cache_alignment() can
indeed be overridden by the arch code, it's a good idea.
diff mbox series

Patch

diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 3288a1339271..b29124341317 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -545,6 +545,8 @@  static inline int dma_set_min_align_mask(struct device *dev,
 
 static inline int dma_get_cache_alignment(void)
 {
+	if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_CACHE_LINE_SIZE))
+		return cache_line_size();
 #ifdef ARCH_HAS_DMA_MINALIGN
 	return ARCH_DMA_MINALIGN;
 #endif
diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig
index 6677d0e64d27..cc750062c412 100644
--- a/kernel/dma/Kconfig
+++ b/kernel/dma/Kconfig
@@ -76,6 +76,13 @@  config ARCH_HAS_DMA_PREP_COHERENT
 config ARCH_HAS_FORCE_DMA_UNENCRYPTED
 	bool
 
+config ARCH_HAS_DMA_CACHE_LINE_SIZE
+	bool
+	help
+	  Select if the architecture has non-coherent DMA and
+	  defines ARCH_DMA_MINALIGN larger than a run-time
+	  cache_line_size().
+
 #
 # Select this option if the architecture assumes DMA devices are coherent
 # by default.