[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260102091459.6bec60c2@mordecai>
Date: Fri, 2 Jan 2026 09:14:59 +0100
From: Petr Tesarik <ptesarik@...e.com>
To: "Michael S. Tsirkin" <mst@...hat.com>
Cc: linux-kernel@...r.kernel.org, Cong Wang <xiyou.wangcong@...il.com>,
Jonathan Corbet <corbet@....net>, Olivia Mackall <olivia@...enic.com>,
Herbert Xu <herbert@...dor.apana.org.au>, Jason Wang <jasowang@...hat.com>,
Paolo Bonzini <pbonzini@...hat.com>, Stefan Hajnoczi <stefanha@...hat.com>,
Eugenio Pérez <eperezma@...hat.com>, "James E.J. Bottomley"
<James.Bottomley@...senpartnership.com>, "Martin K. Petersen"
<martin.petersen@...cle.com>, Gerd Hoffmann <kraxel@...hat.com>, Xuan Zhuo
<xuanzhuo@...ux.alibaba.com>, Marek Szyprowski <m.szyprowski@...sung.com>,
Robin Murphy <robin.murphy@....com>, Stefano Garzarella
<sgarzare@...hat.com>, "David S. Miller" <davem@...emloft.net>, Eric
Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, Paolo
Abeni <pabeni@...hat.com>, Simon Horman <horms@...nel.org>, Leon Romanovsky
<leon@...nel.org>, Jason Gunthorpe <jgg@...pe.ca>,
linux-doc@...r.kernel.org, linux-crypto@...r.kernel.org,
virtualization@...ts.linux.dev, linux-scsi@...r.kernel.org,
iommu@...ts.linux.dev, kvm@...r.kernel.org, netdev@...r.kernel.org
Subject: Re: [PATCH RFC 01/13] dma-mapping: add
__dma_from_device_align_begin/end
On Wed, 31 Dec 2025 15:48:26 -0500
"Michael S. Tsirkin" <mst@...hat.com> wrote:
> On Wed, Dec 31, 2025 at 03:01:59PM +0100, Petr Tesarik wrote:
> > On Tue, 30 Dec 2025 05:15:46 -0500
> > "Michael S. Tsirkin" <mst@...hat.com> wrote:
> >
> > > When a structure contains a buffer that DMA writes to alongside fields
> > > that the CPU writes to, cache line sharing between the DMA buffer and
> > > CPU-written fields can cause data corruption on non-cache-coherent
> > > platforms.
> > >
> > > Add __dma_from_device_aligned_begin/__dma_from_device_aligned_end
> > > annotations to ensure proper alignment to prevent this:
> > >
> > > struct my_device {
> > > spinlock_t lock1;
> > > __dma_from_device_aligned_begin char dma_buffer1[16];
> > > char dma_buffer2[16];
> > > __dma_from_device_aligned_end spinlock_t lock2;
> > > };
> > >
> > > When the DMA buffer is the last field in the structure, just
> > > __dma_from_device_aligned_begin is enough - the compiler's struct
> > > padding protects the tail:
> > >
> > > struct my_device {
> > > spinlock_t lock;
> > > struct mutex mlock;
> > > __dma_from_device_aligned_begin char dma_buffer1[16];
> > > char dma_buffer2[16];
> > > };
> >
> > This works, but it's a bit hard to read. Can we reuse the
> > __cacheline_group_{begin, end}() macros from <linux/cache.h>?
> > Something like this:
> >
> > #define __dma_from_device_group_begin(GROUP) \
> > __cacheline_group_begin(GROUP) \
> > ____dma_from_device_aligned
> > #define __dma_from_device_group_end(GROUP) \
> > __cacheline_group_end(GROUP) \
> > ____dma_from_device_aligned
> >
> > And used like this (the "rxbuf" group id was chosen arbitrarily):
> >
> > struct my_device {
> > spinlock_t lock1;
> > __dma_from_device_group_begin(rxbuf);
> > char dma_buffer1[16];
> > char dma_buffer2[16];
> > __dma_from_device_group_end(rxbuf);
> > spinlock_t lock2;
> > };
> >
> > Petr T
>
> Made this change, and pushed out to my tree.
>
> I'll post the new version in a couple of days, if no other issues
> surface.
FTR except my (non-critical) suggestions for PATCH 5/13, the updated
series looks good to me.
Thank you!
Petr T
Powered by blists - more mailing lists