Skip to contentSkip to conversation

Allow nested qemu_bh_poll() after BH deletion

PATCH In review Kevin Wolf 2 participants 2 messages Jun 15, 2011

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 Allow nested qemu_bh_poll() after BH deletion

Without this, qemu segfaults when a BH handler first deletes its BH and then calls another function which involves a nested qemu_bh_poll() call.

This can be reproduced by generating an I/O error (e.g. with blkdebug) on an IDE device and using rerror/werror=stop to stop the VM. When continuing the VM, qemu segfaults.

---
 async.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
async.c +3 -2
index 57ac3a8..fd313df 100644
@@ -137,11 +137,12 @@ QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
 
 int qemu_bh_poll(void)
 {
-    QEMUBH *bh, **bhp;
+    QEMUBH *bh, **bhp, *next;
     int ret;
 
     ret = 0;
-    for (bh = async_context->first_bh; bh; bh = bh->next) {
+    for (bh = async_context->first_bh; bh; bh = next) {
+        next = bh->next;
         if (!bh->deleted && bh->scheduled) {
             bh->scheduled = 0;
             if (!bh->idle)
Signature · 1 line
1.7.5.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Kevin Wolf

Without this, qemu segfaults when a BH handler first deletes its BH and then calls another function which involves a nested qemu_bh_poll() call.

This can be reproduced by generating an I/O error (e.g. with blkdebug) on an IDE device and using rerror/werror=stop to stop the VM. When continuing the VM, qemu segfaults.

---
 async.c |    5 +++--

 1 files changed, 3 insertions(+), 2 deletions(-)

Almost worth switching to qemu-queue.h and FOREACH_SAFE().