]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
vsock/virtio: fix DMA alignment for event_list
authorMichael S. Tsirkin <mst@redhat.com>
Mon, 29 Dec 2025 23:23:53 +0000 (18:23 -0500)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 8 Jan 2026 14:54:19 +0000 (09:54 -0500)
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>
net/vmw_vsock/virtio_transport.c

index 8c867023a2e523b4a788a311e1fd8b6b2e33588b..3de2b2d49b51e3a139d1ae58a882561ff2b2bd73 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/virtio_ids.h>
 #include <linux/virtio_config.h>
 #include <linux/virtio_vsock.h>
+#include <linux/dma-mapping.h>
 #include <net/sock.h>
 #include <linux/mutex.h>
 #include <net/af_vsock.h>
@@ -59,7 +60,9 @@ struct virtio_vsock {
         */
        struct mutex event_lock;
        bool event_run;
+       __dma_from_device_group_begin();
        struct virtio_vsock_event event_list[8];
+       __dma_from_device_group_end();
 
        u32 guest_cid;
        bool seqpacket_allow;