android_kernel_motorola_sm6375/drivers/virtio
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Yuan Yao ec6ad9d99e virtio_ring: fix avail_wrap_counter in virtqueue_add_packed
[ Upstream commit 1acfe2c1225899eab5ab724c91b7e1eb2881b9ab ]

In current packed virtqueue implementation, the avail_wrap_counter won't
flip, in the case when the driver supplies a descriptor chain with a
length equals to the queue size; total_sg == vq->packed.vring.num.

Let’s assume the following situation:
vq->packed.vring.num=4
vq->packed.next_avail_idx: 1
vq->packed.avail_wrap_counter: 0

Then the driver adds a descriptor chain containing 4 descriptors.

We expect the following result with avail_wrap_counter flipped:
vq->packed.next_avail_idx: 1
vq->packed.avail_wrap_counter: 1

But, the current implementation gives the following result:
vq->packed.next_avail_idx: 1
vq->packed.avail_wrap_counter: 0

To reproduce the bug, you can set a packed queue size as small as
possible, so that the driver is more likely to provide a descriptor
chain with a length equal to the packed queue size. For example, in
qemu run following commands:
sudo qemu-system-x86_64 \
-enable-kvm \
-nographic \
-kernel "path/to/kernel_image" \
-m 1G \
-drive file="path/to/rootfs",if=none,id=disk \
-device virtio-blk,drive=disk \
-drive file="path/to/disk_image",if=none,id=rwdisk \
-device virtio-blk,drive=rwdisk,packed=on,queue-size=4,\
indirect_desc=off \
-append "console=ttyS0 root=/dev/vda rw init=/bin/bash"

Inside the VM, create a directory and mount the rwdisk device on it. The
rwdisk will hang and mount operation will not complete.

This commit fixes the wrap counter error by flipping the
packed.avail_wrap_counter, when start of descriptor chain equals to the
end of descriptor chain (head == i).

Fixes: 1ce9e6055f ("virtio_ring: introduce packed ring support")
Signed-off-by: Yuan Yao <[email protected]>
Message-Id: <[email protected]>
Acked-by: Jason Wang <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
2023-09-23 10:59:53 +02:00
..
Kconfig
Makefile
virtio.c virtio: acknowledge all features before access 2022-03-16 13:21:48 +01:00
virtio_balloon.c
virtio_input.c
virtio_mmio.c virtio-mmio: don't break lifecycle of vm_dev 2023-08-30 16:27:15 +02:00
virtio_pci_common.c virtio-pci: Remove wrong address verification in vp_del_vqs() 2022-06-22 14:11:24 +02:00
virtio_pci_common.h
virtio_pci_legacy.c
virtio_pci_modern.c
virtio_ring.c virtio_ring: fix avail_wrap_counter in virtqueue_add_packed 2023-09-23 10:59:53 +02:00