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_input: fix DMA alignment for evts

On non-cache-coherent platforms, when a structure contains a buffer
used for DMA alongside fields that the CPU writes to, cacheline sharing
can cause data corruption.

The evts array is used for DMA_FROM_DEVICE operations via
virtqueue_add_inbuf(). The adjacent lock and ready fields are written
by the CPU during normal operation. If these share cachelines with evts,
CPU writes can corrupt DMA data.

Add __dma_from_device_group_begin()/end() annotations to ensure evts is
isolated in its own cachelines.

Message-ID: <cd328233198a76618809bb5cd9a6ddcaa603a8a1.1767601130.git.mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

+3
+3
drivers/virtio/virtio_input.c
··· 4 4 #include <linux/virtio_config.h> 5 5 #include <linux/input.h> 6 6 #include <linux/slab.h> 7 + #include <linux/dma-mapping.h> 7 8 8 9 #include <uapi/linux/virtio_ids.h> 9 10 #include <uapi/linux/virtio_input.h> ··· 17 16 char serial[64]; 18 17 char phys[64]; 19 18 struct virtqueue *evt, *sts; 19 + __dma_from_device_group_begin(); 20 20 struct virtio_input_event evts[64]; 21 + __dma_from_device_group_end(); 21 22 spinlock_t lock; 22 23 bool ready; 23 24 };