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

   ## Summary
   
   `virtqueue_add_buffer()` of OpenAMP checks the number of free descriptors 
only with `VQUEUE_DEBUG` (`CONFIG_OPENAMP_DEBUG`). Without it, a 9P 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 entries 
past the end of the table, and the free count wraps. QEMU then stops the 9P 
device ("Desc next is 32768" or "Guest says index 32768 is available"), and 
with it the file system. With `CONFIG_ARCH_ADDRENV` a user buffer needs one 
descriptor per run of physical pages, so a 64 KiB read or write can need 17 
descriptors, and 7 such requests at the same time fill the 128 descriptors of 
QEMU's 9P device over virtio-pci. Threads that read large files at the same 
time do this. This PR makes `virtio_9p_request()` wait until the queue has 
enough free descriptors; `virtio_9p_done()` wakes the waiting requests after 
the replies give descriptors back. Only a cancellation ends the wait early (th
 e device has nothing of the request yet). A request larger than the whole 
queue gets `-E2BIG`.
   
   ## Impact
   
   `fs/v9fs/virtio_9p.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. The other virtio drivers that call 
`virtqueue_add_buffer()` without this check are not changed here. No API 
change. No Documentation change. The same code in flat, protected and kernel 
builds (without `CONFIG_ARCH_ADDRENV` a request uses one descriptor per iovec, 
so the queue fills later, with more requests).
   
   ## Testing
   
   - Test program `v9fsring.c`: 16 threads read a file with a known pattern 
into user pages, write such pages to their own file and read them back (the 
data is checked), and read directories, for 30 s, on the 9P file system 
`/system`. qemu-armv8a:knsh (kernel build, arm64, QEMU with HVF, virtio-mmio). 
To fill the queue with a few threads, the test ran with 
`CONFIG_DRIVERS_VIRTIO_MMIO_QUEUE_LEN=16` and the mount option `msize=16384` 
(every single request still fits in the queue). master: QEMU stops the 9P 
device at once ("Guest says index 32768 is available"), the guest stops, FAIL. 
This PR: PASS, 174517 operations, no bad data, no device error.
   - ostest: qemu-armv8a:knsh (kernel build) exit 0, qemu-armv8a:nsh (flat 
build) exit 0, with the same queue length, arm64, QEMU with HVF.
   - rv-virt:knsh64 (kernel build, riscv64) with virtio-mmio 9p: `virtio_9p.c` 
compiles without warnings; the link fails in libmetal (`up_addrenv_pa_to_va` is 
not defined for risc-v on master either), not changed here. Not run on x86_64 
(virtio-pci).
   - 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