[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <278f23d7-4c95-49df-b9c9-6ad19e6a08ca@samsung.com>
Date: Mon, 5 Jan 2026 19:28:49 +0100
From: Marek Szyprowski <m.szyprowski@...sung.com>
To: "Michael S. Tsirkin" <mst@...hat.com>, linux-kernel@...r.kernel.org
Cc: 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>, 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>, Petr Tesarik
<ptesarik@...e.com>, Leon Romanovsky <leon@...nel.org>, Jason Gunthorpe
<jgg@...pe.ca>, Bartosz Golaszewski <brgl@...nel.org>,
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 v2 02/15] docs: dma-api: document
__dma_from_device_group_begin()/end()
On 05.01.2026 09:22, Michael S. Tsirkin wrote:
> Document the __dma_from_device_group_begin()/end() annotations.
>
> Signed-off-by: Michael S. Tsirkin <mst@...hat.com>
> ---
> Documentation/core-api/dma-api-howto.rst | 52 ++++++++++++++++++++++++
> 1 file changed, 52 insertions(+)
Acked-by: Marek Szyprowski <m.szyprowski@...sung.com>
> diff --git a/Documentation/core-api/dma-api-howto.rst b/Documentation/core-api/dma-api-howto.rst
> index 96fce2a9aa90..e97743ab0f26 100644
> --- a/Documentation/core-api/dma-api-howto.rst
> +++ b/Documentation/core-api/dma-api-howto.rst
> @@ -146,6 +146,58 @@ What about block I/O and networking buffers? The block I/O and
> networking subsystems make sure that the buffers they use are valid
> for you to DMA from/to.
>
> +__dma_from_device_group_begin/end annotations
> +=============================================
> +
> +As explained previously, when a structure contains a DMA_FROM_DEVICE /
> +DMA_BIDIRECTIONAL buffer (device writes to memory) alongside fields that the
> +CPU writes to, cache line sharing between the DMA buffer and CPU-written fields
> +can cause data corruption on CPUs with DMA-incoherent caches.
> +
> +The ``__dma_from_device_group_begin(GROUP)/__dma_from_device_group_end(GROUP)``
> +macros ensure proper alignment to prevent this::
> +
> + struct my_device {
> + spinlock_t lock1;
> + __dma_from_device_group_begin();
> + char dma_buffer1[16];
> + char dma_buffer2[16];
> + __dma_from_device_group_end();
> + spinlock_t lock2;
> + };
> +
> +To isolate a DMA buffer from adjacent fields, use
> +``__dma_from_device_group_begin(GROUP)`` before the first DMA buffer
> +field and ``__dma_from_device_group_end(GROUP)`` after the last DMA
> +buffer field (with the same GROUP name). This protects both the head
> +and tail of the buffer from cache line sharing.
> +
> +The GROUP parameter is an optional identifier that names the DMA buffer group
> +(in case you have several in the same structure)::
> +
> + struct my_device {
> + spinlock_t lock1;
> + __dma_from_device_group_begin(buffer1);
> + char dma_buffer1[16];
> + __dma_from_device_group_end(buffer1);
> + spinlock_t lock2;
> + __dma_from_device_group_begin(buffer2);
> + char dma_buffer2[16];
> + __dma_from_device_group_end(buffer2);
> + };
> +
> +On cache-coherent platforms these macros expand to zero-length array markers.
> +On non-coherent platforms, they also ensure the minimal DMA alignment, which
> +can be as large as 128 bytes.
> +
> +.. note::
> +
> + It is allowed (though somewhat fragile) to include extra fields, not
> + intended for DMA from the device, within the group (in order to pack the
> + structure tightly) - but only as long as the CPU does not write these
> + fields while any fields in the group are mapped for DMA_FROM_DEVICE or
> + DMA_BIDIRECTIONAL.
> +
> DMA addressing capabilities
> ===========================
>
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
Powered by blists - more mailing lists