Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: core: Fix IIO_ALIGN and rename as it was not sufficiently large

Discussion of the series:
https://lore.kernel.org/all/20220405135758.774016-1-catalin.marinas@arm.com/
mm, arm64: Reduce ARCH_KMALLOC_MINALIGN brought to my attention that
our current IIO usage of L1CACHE_ALIGN is insufficient as their are Arm
platforms out their with non coherent DMA and larger cache lines at
at higher levels of their cache hierarchy.

Rename the define to make it's purpose more explicit. It will be used
much more widely going forwards (to replace incorrect ____cacheline_aligned
markings.

Note this patch will greatly reduce the padding on some architectures
that have smaller requirements for DMA safe buffers.

The history of changing values of ARCH_KMALLOC_MINALIGN via
ARCH_DMA_MINALIGN on arm64 is rather complex. I'm not tagging this
as fixing a particular patch from that route as it's not clear what to tag.

Most recently a change to bring them back inline was reverted because
of some Qualcomm Kryo cores with an L2 cache with 128-byte lines
sitting above the point of coherency.

c1132702c71f Revert "arm64: cache: Lower ARCH_DMA_MINALIGN to 64 (L1_CACHE_BYTES)"
That reverts:
65688d2a05de arm64: cache: Lower ARCH_DMA_MINALIGN to 64 (L1_CACHE_BYTES) which
refers to the change originally being motivated by Thunder x1 performance
rather than correctness.

Fixes: 6f7c8ee585e9d ("staging:iio: Add ability to allocate private data space to iio_allocate_device")
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20220508175712.647246-2-jic23@kernel.org

+15 -8
+1 -1
drivers/iio/accel/bma400_core.c
··· 93 93 __le16 buff[3]; 94 94 u8 temperature; 95 95 s64 ts __aligned(8); 96 - } buffer __aligned(IIO_ALIGN); 96 + } buffer __aligned(IIO_DMA_MINALIGN); 97 97 __le16 status; 98 98 __be16 duration; 99 99 };
+4 -3
drivers/iio/adc/adi-axi-adc.c
··· 84 84 { 85 85 struct adi_axi_adc_client *cl = conv_to_client(conv); 86 86 87 - return (char *)cl + ALIGN(sizeof(struct adi_axi_adc_client), IIO_ALIGN); 87 + return (char *)cl + ALIGN(sizeof(struct adi_axi_adc_client), 88 + IIO_DMA_MINALIGN); 88 89 } 89 90 EXPORT_SYMBOL_NS_GPL(adi_axi_adc_conv_priv, IIO_ADI_AXI); 90 91 ··· 170 169 struct adi_axi_adc_client *cl; 171 170 size_t alloc_size; 172 171 173 - alloc_size = ALIGN(sizeof(struct adi_axi_adc_client), IIO_ALIGN); 172 + alloc_size = ALIGN(sizeof(struct adi_axi_adc_client), IIO_DMA_MINALIGN); 174 173 if (sizeof_priv) 175 - alloc_size += ALIGN(sizeof_priv, IIO_ALIGN); 174 + alloc_size += ALIGN(sizeof_priv, IIO_DMA_MINALIGN); 176 175 177 176 cl = kzalloc(alloc_size, GFP_KERNEL); 178 177 if (!cl)
+2 -2
drivers/iio/industrialio-core.c
··· 1630 1630 1631 1631 alloc_size = sizeof(struct iio_dev_opaque); 1632 1632 if (sizeof_priv) { 1633 - alloc_size = ALIGN(alloc_size, IIO_ALIGN); 1633 + alloc_size = ALIGN(alloc_size, IIO_DMA_MINALIGN); 1634 1634 alloc_size += sizeof_priv; 1635 1635 } 1636 1636 ··· 1640 1640 1641 1641 indio_dev = &iio_dev_opaque->indio_dev; 1642 1642 indio_dev->priv = (char *)iio_dev_opaque + 1643 - ALIGN(sizeof(struct iio_dev_opaque), IIO_ALIGN); 1643 + ALIGN(sizeof(struct iio_dev_opaque), IIO_DMA_MINALIGN); 1644 1644 1645 1645 indio_dev->dev.parent = parent; 1646 1646 indio_dev->dev.type = &iio_device_type;
+8 -2
include/linux/iio/iio.h
··· 9 9 10 10 #include <linux/device.h> 11 11 #include <linux/cdev.h> 12 + #include <linux/slab.h> 12 13 #include <linux/iio/types.h> 13 14 #include <linux/of.h> 14 15 /* IIO TODO LIST */ ··· 709 708 return dev_get_drvdata(&indio_dev->dev); 710 709 } 711 710 712 - /* Can we make this smaller? */ 713 - #define IIO_ALIGN L1_CACHE_BYTES 711 + /* 712 + * Used to ensure the iio_priv() structure is aligned to allow that structure 713 + * to in turn include IIO_DMA_MINALIGN'd elements such as buffers which 714 + * must not share cachelines with the rest of the structure, thus making 715 + * them safe for use with non-coherent DMA. 716 + */ 717 + #define IIO_DMA_MINALIGN ARCH_KMALLOC_MINALIGN 714 718 struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv); 715 719 716 720 /* The information at the returned address is guaranteed to be cacheline aligned */