Skip to content

Commit 4ab5f8e

Browse files
ctmarinasakpm00
authored andcommitted
mm/slab: decouple ARCH_KMALLOC_MINALIGN from ARCH_DMA_MINALIGN
Patch series "mm, dma, arm64: Reduce ARCH_KMALLOC_MINALIGN to 8", v7. A series reducing the kmalloc() minimum alignment on arm64 to 8 (from 128). This patch (of 17): In preparation for supporting a kmalloc() minimum alignment smaller than the arch DMA alignment, decouple the two definitions. This requires that either the kmalloc() caches are aligned to a (run-time) cache-line size or the DMA API bounces unaligned kmalloc() allocations. Subsequent patches will implement both options. After this patch, ARCH_DMA_MINALIGN is expected to be used in static alignment annotations and defined by an architecture to be the maximum alignment for all supported configurations/SoCs in a single Image. Architectures opting in to a smaller ARCH_KMALLOC_MINALIGN will need to define its value in the arch headers. Since ARCH_DMA_MINALIGN is now always defined, adjust the #ifdef in dma_get_cache_alignment() so that there is no change for architectures not requiring a minimum DMA alignment. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]> Tested-by: Isaac J. Manjarres <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Robin Murphy <[email protected]> Cc: Alasdair Kergon <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Daniel Vetter <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Herbert Xu <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Mark Brown <[email protected]> Cc: Mike Snitzer <[email protected]> Cc: Rafael J. Wysocki <[email protected]> Cc: Saravana Kannan <[email protected]> Cc: Will Deacon <[email protected]> Cc: Jerry Snitselaar <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Lars-Peter Clausen <[email protected]> Cc: Logan Gunthorpe <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 349d167 commit 4ab5f8e

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

include/linux/cache.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,10 @@ struct cacheline_padding {
9898
#define CACHELINE_PADDING(name)
9999
#endif
100100

101+
#ifdef ARCH_DMA_MINALIGN
102+
#define ARCH_HAS_DMA_MINALIGN
103+
#else
104+
#define ARCH_DMA_MINALIGN __alignof__(unsigned long long)
105+
#endif
106+
101107
#endif /* __LINUX_CACHE_H */

include/linux/dma-mapping.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef _LINUX_DMA_MAPPING_H
33
#define _LINUX_DMA_MAPPING_H
44

5+
#include <linux/cache.h>
56
#include <linux/sizes.h>
67
#include <linux/string.h>
78
#include <linux/device.h>
@@ -545,7 +546,7 @@ static inline int dma_set_min_align_mask(struct device *dev,
545546

546547
static inline int dma_get_cache_alignment(void)
547548
{
548-
#ifdef ARCH_DMA_MINALIGN
549+
#ifdef ARCH_HAS_DMA_MINALIGN
549550
return ARCH_DMA_MINALIGN;
550551
#endif
551552
return 1;

include/linux/slab.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#ifndef _LINUX_SLAB_H
1313
#define _LINUX_SLAB_H
1414

15+
#include <linux/cache.h>
1516
#include <linux/gfp.h>
1617
#include <linux/overflow.h>
1718
#include <linux/types.h>
@@ -235,12 +236,17 @@ void kmem_dump_obj(void *object);
235236
* alignment larger than the alignment of a 64-bit integer.
236237
* Setting ARCH_DMA_MINALIGN in arch headers allows that.
237238
*/
238-
#if defined(ARCH_DMA_MINALIGN) && ARCH_DMA_MINALIGN > 8
239+
#ifdef ARCH_HAS_DMA_MINALIGN
240+
#if ARCH_DMA_MINALIGN > 8 && !defined(ARCH_KMALLOC_MINALIGN)
239241
#define ARCH_KMALLOC_MINALIGN ARCH_DMA_MINALIGN
240-
#define KMALLOC_MIN_SIZE ARCH_DMA_MINALIGN
241-
#define KMALLOC_SHIFT_LOW ilog2(ARCH_DMA_MINALIGN)
242-
#else
242+
#endif
243+
#endif
244+
245+
#ifndef ARCH_KMALLOC_MINALIGN
243246
#define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long)
247+
#elif ARCH_KMALLOC_MINALIGN > 8
248+
#define KMALLOC_MIN_SIZE ARCH_KMALLOC_MINALIGN
249+
#define KMALLOC_SHIFT_LOW ilog2(KMALLOC_MIN_SIZE)
244250
#endif
245251

246252
/*

0 commit comments

Comments
 (0)