casaroli opened a new pull request, #21912:
URL: https://github.com/apache/nuttx/pull/21912

   ## Summary
   
   `virtqueue_add_buffer()` of OpenAMP checks the number of free descriptors 
only with `VQUEUE_DEBUG` (`CONFIG_OPENAMP_DEBUG`). Without it, a request that 
needs more descriptors than the queue has free walks past the end of the free 
list: it overwrites descriptors that other requests still use, and the free 
count wraps. QEMU then stops the device ("Desc next is 32768"), and with it the 
block device. A virtio-blk read or write uses 3 descriptors and a flush 2, and 
nothing limits the requests in flight: each open of `/dev/virtblkN` has its own 
block-to-character driver (and its own lock), and file systems on the device 
send their own requests. With a queue of 16 descriptors, 6 concurrent requests 
fill it. This PR makes a request wait until the queue has enough free 
descriptors; `virtio_blk_done()` wakes the waiting requests after the replies 
give descriptors back. Only a cancellation ends the wait early. In an interrupt 
handler or after a panic, where a request already polls for its re
 ply, the request polls for finished requests instead of a wait. This is the 
same fix as #21911 for the 9P transport.
   
   ## Impact
   
   `drivers/virtio/virtio-blk.c` only. A request that finds the queue full now 
waits for the replies of other requests instead of corrupting the queue. 
Nothing changes while the queue has room. No API change. No Documentation 
change. The same code in flat, protected and kernel builds.
   
   ## Testing
   
   - Test program `blkring.c`: 8 threads each open `/dev/virtblk0` (so each has 
its own block-to-character driver) and read random runs of 1 to 64 sectors for 
10 s; the disk image has a known pattern and every byte is checked. 
qemu-armv8a:nsh_smp (flat build, 2 CPUs, arm64, QEMU with HVF) with 
`CONFIG_DRIVERS_VIRTIO_BLK`, `CONFIG_BCH` and 
`CONFIG_DRIVERS_VIRTIO_MMIO_QUEUE_LEN=16`, a 4 MiB raw image on 
`virtio-blk-device`. master: QEMU stops the device at once ("Desc next is 
32768"), the threads never return, FAIL. This PR: PASS, 263098 reads, no bad 
data, no error.
   - ostest: qemu-armv8a:knsh (kernel build) exit 0, qemu-armv8a:nsh (flat 
build) exit 0, with `CONFIG_DRIVERS_VIRTIO_BLK` and `CONFIG_BCH`, arm64, QEMU 
with HVF.
   - Not run: the interrupt and panic path (polling) with a full queue.
   - rv-virt:nsh64 (flat build, riscv64) with the driver: `virtio-blk.c` 
compiles without warnings; the link fails in libmetal (a flat risc-v build has 
no `up_addrenv_va_to_pa` or `up_addrenv_pa_to_va`, on master too), not changed 
here.
   - checkpatch: `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to