[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/31] async: Allow nested qemu_bh_poll calls
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 04/31] async: Allow nested qemu_bh_poll calls |
Date: |
Tue, 6 Sep 2011 17:39:19 +0200 |
qemu may segfault when a BH handler first deletes a BH and then (possibly
indirectly) calls a nested qemu_bh_poll(). This is because the inner instance
frees the BH and deletes it from the list that the outer one processes.
This patch deletes BHs only in the outermost qemu_bh_poll instance.
Commit 7887f620 already tried to achieve the same, but it assumed that the BH
handler would only delete its own BH. With a nested qemu_bh_poll(), this isn't
guaranteed, so that commit wasn't enough. Hope this one fixes it for real.
Signed-off-by: Kevin Wolf <address@hidden>
---
async.c | 24 ++++++++++++++++--------
1 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/async.c b/async.c
index 9d4e960..ca13962 100644
--- a/async.c
+++ b/async.c
@@ -55,6 +55,9 @@ int qemu_bh_poll(void)
{
QEMUBH *bh, **bhp, *next;
int ret;
+ static int nesting = 0;
+
+ nesting++;
ret = 0;
for (bh = first_bh; bh; bh = next) {
@@ -68,15 +71,20 @@ int qemu_bh_poll(void)
}
}
+ nesting--;
+
/* remove deleted bhs */
- bhp = &first_bh;
- while (*bhp) {
- bh = *bhp;
- if (bh->deleted) {
- *bhp = bh->next;
- g_free(bh);
- } else
- bhp = &bh->next;
+ if (!nesting) {
+ bhp = &first_bh;
+ while (*bhp) {
+ bh = *bhp;
+ if (bh->deleted) {
+ *bhp = bh->next;
+ g_free(bh);
+ } else {
+ bhp = &bh->next;
+ }
+ }
}
return ret;
--
1.7.6
- [Qemu-devel] [PULL 00/31] Block patches, Kevin Wolf, 2011/09/06
- [Qemu-devel] [PATCH 02/31] qcow2: Properly initialise QcowL2Meta, Kevin Wolf, 2011/09/06
- [Qemu-devel] [PATCH 04/31] async: Allow nested qemu_bh_poll calls,
Kevin Wolf <=
- [Qemu-devel] [PATCH 01/31] linux aio: some comments, Kevin Wolf, 2011/09/06
- [Qemu-devel] [PATCH 03/31] qcow2: Fix error cases to run depedent requests, Kevin Wolf, 2011/09/06
- [Qemu-devel] [PATCH 05/31] block: Attach non-qdev devices as well, Kevin Wolf, 2011/09/06
- [Qemu-devel] [PATCH 06/31] block: Generalize change_cb() to BlockDevOps, Kevin Wolf, 2011/09/06
- [Qemu-devel] [PATCH 08/31] ide: Update command code definitions as per ACS-2 Table B.2, Kevin Wolf, 2011/09/06
- [Qemu-devel] [PATCH 07/31] block: Split change_cb() into change_media_cb(), resize_cb(), Kevin Wolf, 2011/09/06
- [Qemu-devel] [PATCH 09/31] ide: Clean up case label indentation in ide_exec_cmd(), Kevin Wolf, 2011/09/06
- [Qemu-devel] [PATCH 11/31] block/raw: Fix to forward method bdrv_media_changed(), Kevin Wolf, 2011/09/06