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

Configure Feed

Select the types of activity you want to include in your feed.

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 <mst@redhat.com>

+3
+3
drivers/char/hw_random/virtio-rng.c
··· 11 11 #include <linux/spinlock.h> 12 12 #include <linux/virtio.h> 13 13 #include <linux/virtio_rng.h> 14 + #include <linux/dma-mapping.h> 14 15 #include <linux/module.h> 15 16 #include <linux/slab.h> 16 17 ··· 29 28 unsigned int data_avail; 30 29 unsigned int data_idx; 31 30 /* minimal size returned by rng_buffer_size() */ 31 + __dma_from_device_group_begin(); 32 32 #if SMP_CACHE_BYTES < 32 33 33 u8 data[32]; 34 34 #else 35 35 u8 data[SMP_CACHE_BYTES]; 36 36 #endif 37 + __dma_from_device_group_end(); 37 38 }; 38 39 39 40 static void random_recv_done(struct virtqueue *vq)