Skip to content

Commit 63dfad0

Browse files
committed
vsock/virtio: fix DMA alignment for event_list
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 event_list array is used for DMA_FROM_DEVICE operations via virtqueue_add_inbuf(). The adjacent event_run and guest_cid fields are written by the CPU while the buffer is available, so mapped for the device. If these share cachelines with event_list, CPU writes can corrupt DMA data. Add __dma_from_device_group_begin()/end() annotations to ensure event_list is isolated in its own cachelines. Message-ID: <f19ebd74f70c91cab4b0178df78cf6a6e107a96b.1767601130.git.mst@redhat.com> Acked-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 5fc6dd1 commit 63dfad0

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

net/vmw_vsock/virtio_transport.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/virtio_ids.h>
1818
#include <linux/virtio_config.h>
1919
#include <linux/virtio_vsock.h>
20+
#include <linux/dma-mapping.h>
2021
#include <net/sock.h>
2122
#include <linux/mutex.h>
2223
#include <net/af_vsock.h>
@@ -59,7 +60,9 @@ struct virtio_vsock {
5960
*/
6061
struct mutex event_lock;
6162
bool event_run;
63+
__dma_from_device_group_begin();
6264
struct virtio_vsock_event event_list[8];
65+
__dma_from_device_group_end();
6366

6467
u32 guest_cid;
6568
bool seqpacket_allow;

0 commit comments

Comments
 (0)