From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:59918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qz8Fj-0002Mm-4i for qemu-devel@nongnu.org; Thu, 01 Sep 2011 10:28:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qz8Fi-0008I1-1L for qemu-devel@nongnu.org; Thu, 01 Sep 2011 10:28:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28204) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qz8Fh-0008Hc-MU for qemu-devel@nongnu.org; Thu, 01 Sep 2011 10:28:21 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p81ESLcI018465 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 1 Sep 2011 10:28:21 -0400 From: Kevin Wolf Date: Thu, 1 Sep 2011 16:31:11 +0200 Message-Id: <1314887471-18052-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1314887471-18052-1-git-send-email-kwolf@redhat.com> References: <1314887471-18052-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 3/3] async: Allow nested qemu_bh_poll calls List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, lcapitulino@redhat.com 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 --- 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