All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] VIRTIO: Update the desc 'flag' fied last in packed ring.
@ 2026-06-02  4:31 yangjiale
  2026-06-02  6:04 ` Eugenio Perez Martin
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: yangjiale @ 2026-06-02  4:31 UTC (permalink / raw)
  To: Michael S . Tsirkin
  Cc: Jason Wang, Xuan Zhuo, Eugenio Pérez, virtualization,
	linux-kernel, yangjiale

When a descriptor list spans across cache lines,
updating the flag first can lead to a scenario where the device side
perceives the flag as valid, yet the corresponding address and length
fields remain unupdated—resulting in invalid values.
Therefore, the flag field must be updated last.

Signed-off-by: yangjiale <yangjiale133@163.com>
---
 drivers/virtio/virtio_ring.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index fbca7ce1c6bf..036b4f90d30f 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -1688,6 +1688,10 @@ static inline int virtqueue_add_packed(struct vring_virtqueue *vq,
 					     &addr, &len, premapped, attr))
 				goto unmap_release;
 
+			desc[i].addr = cpu_to_le64(addr);
+			desc[i].len = cpu_to_le32(len);
+			desc[i].id = cpu_to_le16(id);
+
 			flags = cpu_to_le16(vq->packed.avail_used_flags |
 				    (++c == total_sg ? 0 : VRING_DESC_F_NEXT) |
 				    (n < out_sgs ? 0 : VRING_DESC_F_WRITE));
@@ -1696,10 +1700,6 @@ static inline int virtqueue_add_packed(struct vring_virtqueue *vq,
 			else
 				desc[i].flags = flags;
 
-			desc[i].addr = cpu_to_le64(addr);
-			desc[i].len = cpu_to_le32(len);
-			desc[i].id = cpu_to_le16(id);
-
 			if (unlikely(vq->use_map_api)) {
 				vq->packed.desc_extra[curr].addr = premapped ?
 					DMA_MAPPING_ERROR : addr;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-06-06  0:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02  4:31 [PATCH] VIRTIO: Update the desc 'flag' fied last in packed ring yangjiale
2026-06-02  6:04 ` Eugenio Perez Martin
2026-06-02  6:59   ` Michael S. Tsirkin
2026-06-02  9:21     ` Dongli Zhang
2026-06-03  1:58   ` yangjiale133
2026-06-03  2:08     ` Xuan Zhuo
     [not found]   ` <5a3e06d5.103d.19e8b1863dd.Coremail.yangjiale133@163.com>
2026-06-03  5:10     ` Michael S. Tsirkin
2026-06-05 16:03   ` Si-Wei Liu
2026-06-05 17:43     ` Michael S. Tsirkin
2026-06-05 18:50       ` Si-Wei Liu
2026-06-06  0:11         ` Michael S. Tsirkin
2026-06-02  6:59 ` Michael S. Tsirkin
2026-06-03  1:09 ` Xuan Zhuo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.