From nobody Wed May 1 22:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490118610951971.8613225835362; Tue, 21 Mar 2017 10:50:10 -0700 (PDT) Received: from localhost ([::1]:41706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqNv7-0007IW-4t for importer@patchew.org; Tue, 21 Mar 2017 13:50:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqNtL-000648-F6 for qemu-devel@nongnu.org; Tue, 21 Mar 2017 13:48:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqNtI-000246-7K for qemu-devel@nongnu.org; Tue, 21 Mar 2017 13:48:19 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:34997) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cqNtI-00023g-1X; Tue, 21 Mar 2017 13:48:16 -0400 Received: by mail-wr0-x242.google.com with SMTP id u108so23565559wrb.2; Tue, 21 Mar 2017 10:48:15 -0700 (PDT) Received: from 640k.lan (94-39-135-166.adsl-ull.clienti.tiscali.it. [94.39.135.166]) by smtp.gmail.com with ESMTPSA id j34sm25628788wre.7.2017.03.21.10.48.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Mar 2017 10:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=dWMuqCghXA7n7fpkXVqyoIkXJ9JUdvSIF948PUgTReg=; b=IuwWdvyN8FBDafTvobmOmlstwtYe20hp4byb2fcDqqyvwaVoPhx8d4YlnyVcSK9PWd Gqx1O6nVqC8ytEjv0GUWx8sN7ektD/fhgSuBAlf4/F9M5/XYqI97Z1MqpPiFTdqu25VL V90flIHGXLqaACeEOt3OMCKIf0Pc6TFyL5awDzU57rwU9LgZ9X104za1s1mnwAA9RZfp /4NUwJonyglUcU/6VwF9wmwjdtfm6E6zgPlCkJXohqz26mntlMiy7gCOlaxqrT/1a1D/ PjAJ0EoyYObgPAmwHUp+ZsPX/9wO1xXzV9QuIA0HroYntjiCzWyjtNYlGAE7jkoNUfpa i2iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=dWMuqCghXA7n7fpkXVqyoIkXJ9JUdvSIF948PUgTReg=; b=qgj3ruplBBXQ7xp89NYhl2NRA32cReGLqjd8yAqPvj+XgQ9MRbw15YSIApwoe45jW2 teZhUNMQGpA7nLDUVSl2Rl2SbkUICxyLATduFR6pvZwFj6OkRRxR3U6AAwhqbqgZcpPO jhQEJIiJRtVbUnVAAPH5xtRYS/u5Ymw1tTCSc6kUS5D89nSFRT0O3zzuGR7Aomh1UWgb ufLZtQsoC/dQ37qn+wvv1qt1u/WOzuWLei+9/grAq7tXXPmkNM0T3xnR6MS3uMa6D5Qs PtWw2beXoed9sW34hh0AqnglqHDAsELxik7dqNyQxLkKkltXvus6dc9q3MR/+uaQQ4xZ ORwg== X-Gm-Message-State: AFeK/H3OipsBH/kOzu1TuS1kFPpm+XhiNTciIU5gQ0IBrF7RAstk56yS6n7aISZxg6Ecww== X-Received: by 10.223.157.38 with SMTP id k38mr29981256wre.156.1490118494624; Tue, 21 Mar 2017 10:48:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 21 Mar 2017 18:48:10 +0100 Message-Id: <1490118490-5597-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PATCH for-2.9] 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: jsnow@redhat.com, famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: John Snow --- 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 *opa= que) =20 /* Fetch BDS AioContext again, in case it has changed */ aio_context =3D blk_get_aio_context(data->job->blk); - aio_context_acquire(aio_context); + if (aio_context !=3D data->aio_context) { + aio_context_acquire(aio_context); + } =20 data->job->deferred_to_main_loop =3D false; data->fn(data->job, data->opaque); =20 - aio_context_release(aio_context); + if (aio_context !=3D data->aio_context) { + aio_context_release(aio_context); + } =20 aio_context_release(data->aio_context); =20 --=20 1.8.3.1