From patchwork Thu Nov 4 14:53:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 12603309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92E96C433EF for ; Thu, 4 Nov 2021 14:58:10 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 602B2611C4 for ; Thu, 4 Nov 2021 14:58:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 602B2611C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:54250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mieBt-0001v2-GK for qemu-devel@archiver.kernel.org; Thu, 04 Nov 2021 10:58:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mie7v-0002vN-QW for qemu-devel@nongnu.org; Thu, 04 Nov 2021 10:54:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:39877) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mie7s-0006qB-92 for qemu-devel@nongnu.org; Thu, 04 Nov 2021 10:54:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636037639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gd8Wr1cR/QTz+wM1DKAt/4rsQOgGuC3OU7Wu/CUP2i8=; b=K7jYLuG3DWmLP37og4mNquf7AchIbYIjeXbwWRaXYJmUn3vudm027MqtamwcF4fzgSzGxa MhHrYP0HziKcbO7i8TUo61u5EkvPWx+GauH88+rdjOmWrkvzvV6I0fxrLKxYeC8ieKf/g8 FEI4eupHLYNn7G+7TOuIPBH2wl0c5fw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-13-DnoooTQAMpOmiBi2ZAr3Xw-1; Thu, 04 Nov 2021 10:53:56 -0400 X-MC-Unique: DnoooTQAMpOmiBi2ZAr3Xw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9DC84CF984; Thu, 4 Nov 2021 14:53:50 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 486805F4ED; Thu, 4 Nov 2021 14:53:49 +0000 (UTC) From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [RFC PATCH v2 00/14] job: replace AioContext lock with job_mutex Date: Thu, 4 Nov 2021 10:53:20 -0400 Message-Id: <20211104145334.1346363-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.648, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , Wen Congyang , Xie Changlong , Emanuele Giuseppe Esposito , Markus Armbruster , qemu-devel@nongnu.org, Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" In this series, we want to remove the AioContext lock and instead use the already existent job_mutex to protect the job structures and list. This is part of the work to get rid of AioContext lock usage in favour of smaller granularity locks. In order to simplify reviewer's job, job lock/unlock functions and macros are added as empty prototypes (nop) in patch 1. They are converted to use the actual job mutex only in the last patch, 14. In this way we can freely create locking sections without worrying about deadlocks with the aiocontext lock. Patch 2 defines what fields in the job structure need protection, and patches 3-4 categorize respectively locked and unlocked functions in the job API. Patch 5-9 are in preparation to the job locks, they try to reduce the aiocontext critical sections and other minor fixes. Patch 10-13 introduces the (nop) job lock into the job API and its users, following the comments and categorizations done in patch 2-3-4. Patch 14 makes the prototypes in patch 1 use the job_mutex and removes all aiocontext lock at the same time. Tested this series by running unit tests, qemu-iotests and qtests (x86_64). This serie is based on my previous series "block layer: split block APIs in global state and I/O". Based-on: <20211025101735.2060852-1-eesposit@redhat.com> --- RFC v2: * use JOB_LOCK_GUARD and WITH_JOB_LOCK_GUARD * mu(u)ltiple typos in commit messages * job API split patches are sent separately in another series * use of empty job_{lock/unlock} and JOB_LOCK_GUARD/WITH_JOB_LOCK_GUARD to avoid deadlocks and simplify the reviewer job Emanuele Giuseppe Esposito (14): job.c: make job_lock/unlock public job.h: categorize fields in struct Job job.h: define locked functions job.h: define unlocked functions block/mirror.c: use of job helpers in drivers to avoid TOC/TOU job.c: make job_event_* functions static job.c: move inner aiocontext lock in callbacks aio-wait.h: introduce AIO_WAIT_WHILE_UNLOCKED jobs: remove aiocontext locks since the functions are under BQL jobs: protect jobs with job_lock/unlock block_job_query: remove atomic read jobs: use job locks and helpers also in the unit tests jobs: add job lock in find_* functions job.c: enable job lock/unlock and remove Aiocontext locks include/block/aio-wait.h | 15 +- include/qemu/job.h | 171 ++++++++++--- block.c | 6 + block/mirror.c | 8 +- block/replication.c | 6 + blockdev.c | 88 +++---- blockjob.c | 62 +++-- job-qmp.c | 54 ++-- job.c | 410 ++++++++++++++++++++++--------- monitor/qmp-cmds.c | 2 + qemu-img.c | 8 +- tests/unit/test-bdrv-drain.c | 44 ++-- tests/unit/test-block-iothread.c | 6 +- tests/unit/test-blockjob-txn.c | 10 + tests/unit/test-blockjob.c | 68 ++--- 15 files changed, 628 insertions(+), 330 deletions(-)