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

   ## Summary
   
     * Why: the virtio drivers pass `virtio_set_status()` only the status bit 
of the initialization step they are completing, and the virtio-mmio transport 
wrote that value to the status register as it was. The device status bits are 
cumulative and the specification forbids the driver from clearing them (VirtIO 
1.2, sections 2.1.1 and 3.1.1): writing `DRIVER` alone clears `ACKNOWLEDGE`, 
and `FEATURES_OK` alone clears both.
     * QEMU tolerates this, but a device that enforces the initialization 
sequence ignores `FEATURES_OK` and `DRIVER_OK` and never starts. This was found 
with a device built on the rust-vmm `virtio-device` crate.
     * What: `virtio_mmio_set_status()` in `drivers/virtio/virtio-mmio.c`.
     * How: the transport adds the new bit to the current value of the status 
register, unless the device is being reset.
   
   ## Impact
   
     * Is new feature added? Is existing feature changed? NO.
     * Impact on user (will user need to adapt to change)? NO.
     * Impact on build (will build process change)? NO.
     * Impact on hardware (will arch(s) / board(s) / driver(s) change)? YES. 
The virtio-mmio transport now writes the status sequence 1, 3, 11, 15 to a 
device instead of 1, 2, 8, 4. The virtio drivers themselves do not change.
     * Impact on documentation (is update required / provided)? NO.
     * Impact on security (any sort of implications)? NO.
     * Impact on compatibility (backward/forward/interoperability)? YES. 
Devices that enforce the initialization sequence of the specification now 
start. Devices that already worked keep working.
     * Anything else to consider or add? NO.
   
   ## Testing
   
     I confirm that changes are verified on local setup and works as intended:
     * Build Host(s): Ubuntu 22.04.5, x86_64, riscv64-unknown-elf-gcc 13.2.0, 
QEMU 10.0.2.
     * Target(s): RISC-V, `rv-virt:netnsh64`, unmodified, with virtio-serial, 
virtio-rng, virtio-net and virtio-blk on virtio-mmio.
     * Run with `-global virtio-mmio.force-legacy=false` and with legacy 
devices, with the same results in both.
     * QEMU traces the status writes of the guest (`-trace virtio_set_status`). 
The NSH commands exercise each driver.
   
     ```
     qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 1 \
       -global virtio-mmio.force-legacy=false \
       -device virtio-serial-device,bus=virtio-mmio-bus.0 \
       -chardev file,id=foo,path=virtcon.log -device virtconsole,chardev=foo \
       -device virtio-rng-device,bus=virtio-mmio-bus.1 \
       -netdev user,id=u1 -device 
virtio-net-device,netdev=u1,bus=virtio-mmio-bus.2 \
       -drive file=disk.img,if=none,format=raw,id=hd \
       -device virtio-blk-device,bus=virtio-mmio-bus.3,drive=hd \
       -trace virtio_set_status -D trace.log \
       -bios none -kernel nuttx -nographic
     ```
   
     Testing logs before change:
   
     Status writes of one device in `trace.log` (the other three are the same). 
The NSH session gives the same results as after the change, since QEMU accepts 
this sequence.
   
     ```
     virtio_set_status vdev 0x55ed0c334110 val 1
     virtio_set_status vdev 0x55ed0c334110 val 2
     virtio_set_status vdev 0x55ed0c334110 val 8
     virtio_set_status vdev 0x55ed0c334110 val 4
     ```
   
     Testing logs after change:
   
     ```
     virtio_set_status vdev 0x5590834ef110 val 1
     virtio_set_status vdev 0x5590834ef110 val 3
     virtio_set_status vdev 0x5590834ef110 val 11
     virtio_set_status vdev 0x5590834ef110 val 15
     ```
   
     ```
     nsh> uname -a
     NuttX  12.12.0 2bb99797 Nov 19 2026 16:09:07 risc-v rv-virt
     nsh> ls /dev
     /dev:
      console
      null
      ram0
      random
      telnet
      ttyS0
      ttyV0
      virtblk0
      virtio
      zero
     nsh> hexdump /dev/random count=16
     /dev/random at 00000000:
     0000: 7c d8 3f 74 23 5f 5f 19 23 18 75 3f 7b e7 f4 6f |.?t#__.#.u?{..o
     nsh> echo hello-from-nuttx > /dev/ttyV0
     nsh> mkfatfs /dev/virtblk0
     nsh> mount -t vfat /dev/virtblk0 /mnt
     nsh> echo virtio-blk-ok > /mnt/test.txt
     nsh> cat /mnt/test.txt
     virtio-blk-ok
     nsh> ping -c 3 10.0.2.2
     PING 10.0.2.2 56 bytes of data
     56 bytes from 10.0.2.2: icmp_seq=0 time=6.7 ms
     56 bytes from 10.0.2.2: icmp_seq=1 time=0.2 ms
     56 bytes from 10.0.2.2: icmp_seq=2 time=0.3 ms
     3 packets transmitted, 3 received, 0% packet loss, time 3030 ms
     rtt min/avg/max/mdev = 0.268/2.450/6.723/3.021 ms
     ```
   
     `virtcon.log` on the host contains `hello-from-nuttx`.
     
     
   ## PR verification Self-Check
   
     * [x] This PR introduces only one functional change.
     * [x] I have updated all required description fields above.
     * [x] My PR adheres to Contributing 
[Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md) and 
[Documentation](https://nuttx.apache.org/docs/latest/contributing/index.html) 
(git commit title and message, coding standard, etc).
     * [ ] My PR is still work in progress (not ready for review).
     * [x] My PR is ready for review and can be safely merged into a codebase.


-- 
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