Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MU6Aa-0002Rf-7y for qemu-devel@nongnu.org; Thu, 23 Jul 2009 17:49:44 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MU6AU-0002Hh-P8 for qemu-devel@nongnu.org; Thu, 23 Jul 2009 17:49:43 -0400 Received: from [199.232.76.173] (port=41001 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MU6AU-0002Gy-HF for qemu-devel@nongnu.org; Thu, 23 Jul 2009 17:49:38 -0400 Received: from mx2.redhat.com ([66.187.237.31]:47087) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MU6AT-0000ts-Qu for qemu-devel@nongnu.org; Thu, 23 Jul 2009 17:49:38 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n6NLnaGV005112 for ; Thu, 23 Jul 2009 17:49:36 -0400 From: Markus Armbruster Date: Thu, 23 Jul 2009 23:49:33 +0200 Message-ID: <87zlavax3m.fsf@pike.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Qemu-devel] -drive werror=stop can cause state change handlers run out of order List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gleb Natapov Consider the following scenario[1]: 0. The virtual IDE drive goes south. All future writes return errors. 1. Something encounters a write error, and duly stops the VM with vm_stop(). 2. vm_stop() calls vm_state_notify(0). 3. vm_state_notify() runs the callbacks in list vm_change_state_head. It contains ide_dma_restart_cb() installed by bmdma_map()[2]. It also contains audio_vm_change_state_handler() installed by audio_init(). 4. audio_vm_change_state_handler() stops audio stuff. 5. User continues VM with monitor command "c". This runs vm_start(). 6. vm_start() calls vm_state_notify(1). 7. vm_state_notify() runs the callbacks in vm_change_state_head. 8. Say ide_dma_restart_cb() happens to come first. It does its work, runs into a write error, and duly stops the VM with vm_stop(). 9. vm_stop() runs vm_state_notify(0). 10. vm_state_notify() runs the callbacks in vm_change_state_head. 11. audio_vm_change_state_handler() stops audio stuff. Which isn't running. 12. vm_stop() finishes, ide_dma_restart_cb() finishes, step 7's vm_state_notify() resumes running handlers. 13. audio_vm_change_state_handler() starts audio stuff. Oopsie. What happens here is that when a VM state change handler changes VM state, other VM state change handlers can see the state transitions out of order. I showed this to Gleb, and he suggested to have ide_dma_restart_cb()[3] set up a bottom half to retry writes. I'm not familiar with the block code, so I figure I ask here before I try it: Is that the way to fix this? [1] Note: I didn't actually reproduce it in this form with upstream code. [2] Actually two of them, for the IDE device's bmdma[0] and bmdma[1], but that doesn't matter. [3] Same for SCSI and virtio-blk.