From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGlJw-00061M-Tu for qemu-devel@nongnu.org; Fri, 21 Feb 2014 03:19:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGlJm-0001mM-SB for qemu-devel@nongnu.org; Fri, 21 Feb 2014 03:18:56 -0500 Received: from e35.co.us.ibm.com ([32.97.110.153]:41921) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGlJm-0001m7-L5 for qemu-devel@nongnu.org; Fri, 21 Feb 2014 03:18:46 -0500 Received: from /spool/local by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 21 Feb 2014 01:18:46 -0700 From: Michael Roth Date: Fri, 21 Feb 2014 02:17:10 -0600 Message-Id: <1392970647-21528-35-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1392970647-21528-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1392970647-21528-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 34/51] block/iscsi: use a bh to schedule co reentrance List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: lersek@redhat.com, qemu-stable@nongnu.org, Petar.Jovanovic@imgtec.com From: Peter Lieven this fixes a potential segfault and performance regression. If the coroutine is reentered directly in the iscsi_co_generic_cb iscsi_process_{read,write} are interrupted and reentered any time later. One the one hand this could happen after an iscsi_close where the iscsi context is already gone (segfault). On the other hand this limits the number of processed callbacks in each aio_dispatch to one (potential performance regression). Cc: qemu-stable@nongnu.org Signed-off-by: Peter Lieven Signed-off-by: Paolo Bonzini (cherry picked from commit 8b9dfe9098d91e06a3dd6376624307fe5fa13be8) Signed-off-by: Michael Roth --- block/iscsi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/block/iscsi.c b/block/iscsi.c index a2d578c..a410a28 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -65,6 +65,7 @@ typedef struct IscsiTask { int do_retry; struct scsi_task *task; Coroutine *co; + QEMUBH *bh; } IscsiTask; typedef struct IscsiAIOCB { @@ -121,6 +122,13 @@ iscsi_schedule_bh(IscsiAIOCB *acb) qemu_bh_schedule(acb->bh); } +static void iscsi_co_generic_bh_cb(void *opaque) +{ + struct IscsiTask *iTask = opaque; + qemu_bh_delete(iTask->bh); + qemu_coroutine_enter(iTask->co, NULL); +} + static void iscsi_co_generic_cb(struct iscsi_context *iscsi, int status, void *command_data, void *opaque) @@ -145,7 +153,8 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status, out: if (iTask->co) { - qemu_coroutine_enter(iTask->co, NULL); + iTask->bh = qemu_bh_new(iscsi_co_generic_bh_cb, iTask); + qemu_bh_schedule(iTask->bh); } } -- 1.7.9.5