From: Michael S. Tsirkin Date: Mon, 29 Dec 2025 23:27:21 +0000 (-0500) Subject: virtio-rng: fix DMA alignment for data buffer X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd2b617c49820a38cefcf512c6d56d30deb59aa9;p=thirdparty%2Flinux.git virtio-rng: fix DMA alignment for data buffer The data buffer in struct virtrng_info is used for DMA_FROM_DEVICE via virtqueue_add_inbuf() and shares cachelines with the adjacent CPU-written fields (data_avail, data_idx). The device writing to the DMA buffer and the CPU writing to adjacent fields could corrupt each other's data on non-cache-coherent platforms. Add __dma_from_device_group_begin()/end() annotations to place these in distinct cache lines. Message-ID: <157a63b6324d1f1307ddd4faa3b62a8b90a79423.1767601130.git.mst@redhat.com> Signed-off-by: Michael S. Tsirkin --- diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index dd998f4fe4f23..eb80a031c7bec 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -28,11 +29,13 @@ struct virtrng_info { unsigned int data_avail; unsigned int data_idx; /* minimal size returned by rng_buffer_size() */ + __dma_from_device_group_begin(); #if SMP_CACHE_BYTES < 32 u8 data[32]; #else u8 data[SMP_CACHE_BYTES]; #endif + __dma_from_device_group_end(); }; static void random_recv_done(struct virtqueue *vq)