mit-pdos / xv6-riscv

Xv6 for RISC-V
Other
6.52k stars 2.37k forks source link

May there is a concurrency BUG with `virtio_disk_rw()` and `virtio_disk_intr()` #233

Closed crjg-k closed 3 months ago

crjg-k commented 3 months ago

First, I'm not sure whether my discovery is correct. Suppose such follow scene: We call sleep() at kernel/virtio_disk.c:285, and then the spinlock disk.vdisk_lock will be released at kernel/proc.c:548 but without modifying the state of p->chan and p->state correctly; Unfortunately another hart has received virto_disk's interrupt request and executes to kernel/virtio_disk.c:321 at the same time, then this interrupt processing couldn't find a process that meet the conditions if(p->state == SLEEPING && p->chan == chan) { at kernel/proc.c:574. The wakeup() function does nothing! And the worse is, when line 551 and 552 in kernel/proc.c done after wakeup()'s traversal, the state of own process who invoked virto_disk_rw() will be SLEEPING forever!