From patchwork Wed Mar 22 17:30:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 742223 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vpGvm4ff3z9s3s for ; Thu, 23 Mar 2017 04:32:04 +1100 (AEDT) Received: from localhost ([::1]:52484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqk78-0005yz-49 for incoming@patchwork.ozlabs.org; Wed, 22 Mar 2017 13:32:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46982) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqk6J-0005rQ-9r for qemu-devel@nongnu.org; Wed, 22 Mar 2017 13:31:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqk6I-0003aI-I9 for qemu-devel@nongnu.org; Wed, 22 Mar 2017 13:31:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60380) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cqk6E-0003Y1-4A; Wed, 22 Mar 2017 13:31:06 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E4C964D8C; Wed, 22 Mar 2017 17:31:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2E4C964D8C Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2E4C964D8C Received: from localhost (ovpn-117-90.phx2.redhat.com [10.3.117.90]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C40097F38B; Wed, 22 Mar 2017 17:31:05 +0000 (UTC) From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 22 Mar 2017 13:30:59 -0400 Message-Id: <20170322173102.18180-2-jcody@redhat.com> In-Reply-To: <20170322173102.18180-1-jcody@redhat.com> References: <20170322173102.18180-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 22 Mar 2017 17:31:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL for-2.9 1/4] blockjob: avoid recursive AioContext locking X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Paolo Bonzini Streaming or any other block job hangs when performed on a block device that has a non-default iothread. This happens because the AioContext is acquired twice by block_job_defer_to_main_loop_bh and then released only once by BDRV_POLL_WHILE. (Insert rants on recursive mutexes, which unfortunately are a temporary but necessary evil for iothreads at the moment). Luckily, the reason for the double acquisition is simple; the function acquires the AioContext for both the job iothread and the BDS iothread, in case the BDS iothread was changed while the job was running. It is therefore enough to skip the second acquisition when the two AioContexts are one and the same. Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Jeff Cody Message-id: 1490118490-5597-1-git-send-email-pbonzini@redhat.com Signed-off-by: Jeff Cody --- blockjob.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/blockjob.c b/blockjob.c index 69126af..2159df7 100644 --- a/blockjob.c +++ b/blockjob.c @@ -755,12 +755,16 @@ static void block_job_defer_to_main_loop_bh(void *opaque) /* Fetch BDS AioContext again, in case it has changed */ aio_context = blk_get_aio_context(data->job->blk); - aio_context_acquire(aio_context); + if (aio_context != data->aio_context) { + aio_context_acquire(aio_context); + } data->job->deferred_to_main_loop = false; data->fn(data->job, data->opaque); - aio_context_release(aio_context); + if (aio_context != data->aio_context) { + aio_context_release(aio_context); + } aio_context_release(data->aio_context);