From patchwork Tue Oct 5 18:58:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12537571 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 0A023C433F5 for ; Tue, 5 Oct 2021 19:05:22 +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 A770C6124D for ; Tue, 5 Oct 2021 19:05:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A770C6124D 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]:33170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXpke-0004Nb-L8 for qemu-devel@archiver.kernel.org; Tue, 05 Oct 2021 15:05:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXpdr-0003vA-AD for qemu-devel@nongnu.org; Tue, 05 Oct 2021 14:58:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55494) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXpdo-0004Z3-Cu for qemu-devel@nongnu.org; Tue, 05 Oct 2021 14:58:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633460295; 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: in-reply-to:in-reply-to:references:references; bh=+W7Y6rnsDDZf/ETt0uqjFCnv3qWeNLJXTQ9FgIMtpVs=; b=LuWTkjx8hm+188Y2/v/zZjjdsO1fkVRxbcfXzCsOx/pO87Q/WgnV0loOdyUs6FfCt8DGLt U5X2aV6hWBBPv/V+xsdpGAkjgXS4N1W/ZJImtYS6WYz276j+ORlOygWKDRbAVSV+uhkR2u +/oeBRgtY6YvK5Q04gUQ0R5iwbwGRY4= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-204-aD_lphQpNiCGc2pVOkIvNQ-1; Tue, 05 Oct 2021 14:58:14 -0400 X-MC-Unique: aD_lphQpNiCGc2pVOkIvNQ-1 Received: by mail-wr1-f70.google.com with SMTP id x14-20020a5d60ce000000b00160b27b5fd1so77041wrt.5 for ; Tue, 05 Oct 2021 11:58:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+W7Y6rnsDDZf/ETt0uqjFCnv3qWeNLJXTQ9FgIMtpVs=; b=K/KHpOaHpVjZRfI9/uvqSprF1Yq63FsegxRzcQH/C6PDaodQB/ho8n+jERYyuEcljJ ZAq8O+mpMvODSddjKMr5eKi4f6wqHRb0GZNOSxCKBgxBTL6SfF9mJAKLd67Ar/2Pmj8j pLNeIHRpD+FaAsN3iIv+voFG+1zQu4XYAMOs+9j2I8sAK8FvAAwugEnMY2QoeKbVkd1O HK+1nEBUrkSagsB70UZpLeA5OOc1Z8A6+FaWelAdzSeCSzbILOmXXjbEMLM/dy5/gjZH 5ZcX7X4bJBFB4WtQ8wTGeCSOKS2kArHCHuDM5Z+3IiX6kPKE/9p6b8pe6JJkupnaIE2q HrwQ== X-Gm-Message-State: AOAM530wl0L5JdKSlzbZgxwgmDIrIrqJvDDxzqWHfOtv0OPZN+B1LsbF b4yg355X9zFMjRxa6q3qFjDbAQ11rBdZv5/hOUpse12JPE55PFPbXXge24FU7wpBe6i7Lm1WtFV Wa6+cOiUFvqeStvEimFKc3w79xRWVNG3MDt/m8bCWu25us2DVyHLozT/hxIsLn9y6 X-Received: by 2002:a7b:c954:: with SMTP id i20mr5325384wml.126.1633460293311; Tue, 05 Oct 2021 11:58:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwidVFBmid0TDIDnJBkgBPtHJbHDrccdTXyE39Dq8J28z1hKYZoZJx3yeUgSE41KAWAMMDktg== X-Received: by 2002:a7b:c954:: with SMTP id i20mr5325359wml.126.1633460293104; Tue, 05 Oct 2021 11:58:13 -0700 (PDT) Received: from x1w.redhat.com (118.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.118]) by smtp.gmail.com with ESMTPSA id e14sm8762358wrw.33.2021.10.05.11.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 11:58:12 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 1/4] block/aio: Add automatically released aio_context variants Date: Tue, 5 Oct 2021 20:58:04 +0200 Message-Id: <20211005185807.4134557-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211005185807.4134557-1-philmd@redhat.com> References: <20211005185807.4134557-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) DKIMWL_WL_HIGH=-0.066, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, "Michael S. Tsirkin" , "Dr . David Alan Gilbert" , Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Similarly to commit 5626f8c6d46 ("rcu: Add automatically released rcu_read_lock variants"): AIO_CONTEXT_ACQUIRE_GUARD() acquires the aio context and then uses glib's g_auto infrastructure (and thus whatever the compiler's hooks are) to release it on all exits of the block. WITH_AIO_CONTEXT_ACQUIRE_GUARD() is similar but is used as a wrapper for the lock, i.e.: WITH_AIO_CONTEXT_ACQUIRE_GUARD() { stuff with context acquired } Inspired-by: Dr. David Alan Gilbert Signed-off-by: Philippe Mathieu-Daudé --- include/block/aio.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/block/aio.h b/include/block/aio.h index 47fbe9d81f2..4fa5a5c2720 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -294,6 +294,30 @@ void aio_context_acquire(AioContext *ctx); /* Relinquish ownership of the AioContext. */ void aio_context_release(AioContext *ctx); +static inline AioContext *aio_context_auto_acquire(AioContext *ctx) +{ + aio_context_acquire(ctx); + return ctx; +} + +static inline void aio_context_auto_release(AioContext *ctx) +{ + aio_context_release(ctx); +} + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(AioContext, aio_context_auto_release) + +#define WITH_AIO_CONTEXT_ACQUIRE_GUARD(ctx) \ + WITH_AIO_CONTEXT_ACQUIRE_GUARD_(glue(_aio_context_auto, __COUNTER__), ctx) + +#define WITH_AIO_CONTEXT_ACQUIRE_GUARD_(var, ctx) \ + for (g_autoptr(AioContext) var = aio_context_auto_acquire(ctx); \ + (var); aio_context_auto_release(var), (var) = NULL) + +#define AIO_CONTEXT_ACQUIRE_GUARD(ctx) \ + g_autoptr(AioContext) _aio_context_auto __attribute__((unused)) \ + = aio_context_auto_acquire(ctx) + /** * aio_bh_schedule_oneshot_full: Allocate a new bottom half structure that will * run only once and as soon as possible. From patchwork Tue Oct 5 18:58:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12537573 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 8AE33C433EF for ; Tue, 5 Oct 2021 19:05:24 +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 3F2026124D for ; Tue, 5 Oct 2021 19:05:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3F2026124D 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]:33210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXpkh-0004PS-Ad for qemu-devel@archiver.kernel.org; Tue, 05 Oct 2021 15:05:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXpdv-000476-RK for qemu-devel@nongnu.org; Tue, 05 Oct 2021 14:58:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37707) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXpds-0004eE-II for qemu-devel@nongnu.org; Tue, 05 Oct 2021 14:58:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633460299; 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: in-reply-to:in-reply-to:references:references; bh=/l+iPsFyRbttZ9o4aXnxrKdZE8dURbTJQ5ld8MPAwxM=; b=Ks6t+r+0xhweM0DhqwcrEw5e0d9UnAg7QP44SrlDTyNyizkokTXeDm6zdVf7TQhFNXClvg UtdWDiyWsNWEUHQBoDaT5zW2rw/4ix4oRwGXSh8Q1yAdUvFi15JUZu62KVKutE3RtQWXA3 ZwWNhzfl1pu+aThwwaUFicvor/2OUPk= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-523-Z1cQ_Z5VOdKFQbX4s1COLA-1; Tue, 05 Oct 2021 14:58:19 -0400 X-MC-Unique: Z1cQ_Z5VOdKFQbX4s1COLA-1 Received: by mail-wr1-f69.google.com with SMTP id v15-20020adfa1cf000000b00160940b17a2so69774wrv.19 for ; Tue, 05 Oct 2021 11:58:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/l+iPsFyRbttZ9o4aXnxrKdZE8dURbTJQ5ld8MPAwxM=; b=R7A1xRkvzo0Rk2+k6pBD3g+0yF2m2WD4O2+Frem87ivpnuUBTSVvlw5vRfQXRsYSzt GLKip3QGRuniZhUbWmXdPnwUwkWH/A4+pvym4BxZF9o7ehHkKJ1JJ8bEnpZA5sCrtUDU 715wOPiUXUfUwb4TSIVLnf1AdueSQ1oVe7j+ejwzneLZbZ7yzs8X/EkUje3oxByAglNb pla07aeaTt0hijH+og/pwq1Gnv6zXID+a6DQMQQvZWxMXSskZfC+EcAG2C8dS8Byg2dE YTrVjK5mCLaiuwJgxBql7TTMF6qN4y2ljqS+zA5FVnS82h/V7VtYN9J2KmSoC8QShut4 qXMw== X-Gm-Message-State: AOAM533gaIG4N3rWRtueZBiHiu210Wj8PE/1NZc+DF/ovzBD6AdoORAL sv/f7WldRfeNFe20hxEZ9Rt+98mAppMRhfp+9/QC1k3MKXqk82C735ohQLOqNYsJY1UZSmZ7dR6 OMOiiYKkbpXmw6OCSm5y9un/dahvW3MWyPMaXHfcNg/UX3gy77An6H3ZXhIB7m1TK X-Received: by 2002:a7b:cb49:: with SMTP id v9mr5161655wmj.76.1633460297604; Tue, 05 Oct 2021 11:58:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/WOij0B7vKYjkaYr9RjdMJscd/g/HhX+NhQVooN2vCuHpKCTMULPRmmyt2cuPyL5QOyySyg== X-Received: by 2002:a7b:cb49:: with SMTP id v9mr5161627wmj.76.1633460297427; Tue, 05 Oct 2021 11:58:17 -0700 (PDT) Received: from x1w.redhat.com (118.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.118]) by smtp.gmail.com with ESMTPSA id k128sm3020741wme.41.2021.10.05.11.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 11:58:17 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 2/4] hw/scsi/scsi-disk: Use automatic AIO context lock Date: Tue, 5 Oct 2021 20:58:05 +0200 Message-Id: <20211005185807.4134557-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211005185807.4134557-1-philmd@redhat.com> References: <20211005185807.4134557-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.066, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, "Michael S. Tsirkin" , "Dr . David Alan Gilbert" , Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use the automatic AIO context acquire/release in scsi_block_realize(). Signed-off-by: Philippe Mathieu-Daudé --- hw/scsi/scsi-disk.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index e8a547dbb7d..fa2d8543718 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2605,7 +2605,6 @@ static int get_device_type(SCSIDiskState *s) static void scsi_block_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); - AioContext *ctx; int sg_version; int rc; @@ -2620,8 +2619,7 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp) "be removed in a future version"); } - ctx = blk_get_aio_context(s->qdev.conf.blk); - aio_context_acquire(ctx); + AIO_CONTEXT_ACQUIRE_GUARD(blk_get_aio_context(dev->conf.blk)); /* check we are using a driver managing SG_IO (version 3 and after) */ rc = blk_ioctl(s->qdev.conf.blk, SG_GET_VERSION_NUM, &sg_version); @@ -2630,18 +2628,18 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp) if (rc != -EPERM) { error_append_hint(errp, "Is this a SCSI device?\n"); } - goto out; + return; } if (sg_version < 30000) { error_setg(errp, "scsi generic interface too old"); - goto out; + return; } /* get device type from INQUIRY data */ rc = get_device_type(s); if (rc < 0) { error_setg(errp, "INQUIRY failed"); - goto out; + return; } /* Make a guess for the block size, we'll fix it when the guest sends. @@ -2661,9 +2659,6 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp) scsi_realize(&s->qdev, errp); scsi_generic_read_device_inquiry(&s->qdev); - -out: - aio_context_release(ctx); } typedef struct SCSIBlockReq { From patchwork Tue Oct 5 18:58:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12537575 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 9B242C433EF for ; Tue, 5 Oct 2021 19:07:16 +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 50BFD60F43 for ; Tue, 5 Oct 2021 19:07:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 50BFD60F43 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]:37676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXpmV-0007Sz-Do for qemu-devel@archiver.kernel.org; Tue, 05 Oct 2021 15:07:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXpe1-0004O6-Bk for qemu-devel@nongnu.org; Tue, 05 Oct 2021 14:58:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54314) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXpdx-0004lJ-4j for qemu-devel@nongnu.org; Tue, 05 Oct 2021 14:58:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633460304; 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: in-reply-to:in-reply-to:references:references; bh=WZHNlTuTnklt4Xwql7kVo/EoV/I/Z/JZGj7l0lQfqyg=; b=bttIkjEFVpM0FVBIqJTggQLAJ1huAGG8duMhBxPYZ/IK1Hcct7Y9CzBOB/MYLWCJlAGhTg jRrlgQRhApujJ8A3T8NsrnxIfQVdupPx1ia0847aly2W7Rp8EJu0xsPhGIvKAeXTmkF0Vk gy0X19nWpLyba3/tnP/lN0G29ibhOuw= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-452-un53WkgdO96NsOyDSk7QJA-1; Tue, 05 Oct 2021 14:58:23 -0400 X-MC-Unique: un53WkgdO96NsOyDSk7QJA-1 Received: by mail-wr1-f69.google.com with SMTP id a10-20020a5d508a000000b00160723ce588so68922wrt.23 for ; Tue, 05 Oct 2021 11:58:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WZHNlTuTnklt4Xwql7kVo/EoV/I/Z/JZGj7l0lQfqyg=; b=KOWkAoE8FH5VYRP6VT6dbAGW00M8KiT7337IIIMkJgue06WYgoyKJEMwQniuSvqrMw tp4FQMY70EWztT+gVpBKLdXNCmTYWUSNtZvwVeRKlKHyEAehsLhtsSek9o84jR57s23t LFwJs9ATU1HHglbLPNv2u9gIZpuVHHSz4HIu8ZUecwJ4P+4hpVEdaDdUIlGMj1M6b80R rGqctXizhUPW5NOx7JYkqQOEv5w8CU2D2CNNlifziycwN076/WXy4lJGQbkaYkCrmzn5 UgrB1JXV1TAc1rcQ/F61plGq13DaBd35i5PirWHUeynE4PVO1pvt34YZjLixrXMLhG5i dOhA== X-Gm-Message-State: AOAM531KVVwpaW2k+zFQsMWY4vlu23iN4Ag1XLjTYqBa/5wskcGk9/zw xDoL41C/nR945TC8nhVZHTU+QlIx+ry4dM2TVqUTonnzOlrbTEpib5wizxnj1apPTe09tRcFANl ZUgaD8oF3GdvpvwdkXGyPECBiZvzt4XVd1X6NKgQscBKZ1G5yv7d5xV034pOgk0e3 X-Received: by 2002:a1c:3b06:: with SMTP id i6mr5330300wma.172.1633460302070; Tue, 05 Oct 2021 11:58:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyV8xwrb2B23Lu4C67s97BE/vo8DdZ5JC2Yvzb8kRL4v6ceSDU53m5SUnUzUxbiru8jpeaWw== X-Received: by 2002:a1c:3b06:: with SMTP id i6mr5330274wma.172.1633460301883; Tue, 05 Oct 2021 11:58:21 -0700 (PDT) Received: from x1w.redhat.com (118.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.118]) by smtp.gmail.com with ESMTPSA id h17sm3382759wrx.55.2021.10.05.11.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 11:58:21 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 3/4] hw/scsi/scsi-generic: Use automatic AIO context lock Date: Tue, 5 Oct 2021 20:58:06 +0200 Message-Id: <20211005185807.4134557-4-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211005185807.4134557-1-philmd@redhat.com> References: <20211005185807.4134557-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.066, 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_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, "Michael S. Tsirkin" , "Dr . David Alan Gilbert" , Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use the automatic AIO context acquire/release in scsi_command_complete(). Signed-off-by: Philippe Mathieu-Daudé --- hw/scsi/scsi-generic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 665baf900e4..08ef623c030 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -114,9 +114,9 @@ static void scsi_command_complete(void *opaque, int ret) assert(r->req.aiocb != NULL); r->req.aiocb = NULL; - aio_context_acquire(blk_get_aio_context(s->conf.blk)); - scsi_command_complete_noio(r, ret); - aio_context_release(blk_get_aio_context(s->conf.blk)); + WITH_AIO_CONTEXT_ACQUIRE_GUARD(blk_get_aio_context(s->conf.blk)) { + scsi_command_complete_noio(r, ret); + } } static int execute_command(BlockBackend *blk, From patchwork Tue Oct 5 18:58:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12537567 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 88983C433EF for ; Tue, 5 Oct 2021 19:02:32 +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 2C8D66103E for ; Tue, 5 Oct 2021 19:02:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2C8D66103E 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]:53528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXphv-0007Xu-99 for qemu-devel@archiver.kernel.org; Tue, 05 Oct 2021 15:02:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60090) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXpe3-0004UT-CI for qemu-devel@nongnu.org; Tue, 05 Oct 2021 14:58:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60438) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXpe1-0004oz-Jt for qemu-devel@nongnu.org; Tue, 05 Oct 2021 14:58:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633460308; 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: in-reply-to:in-reply-to:references:references; bh=f8Ls47LDQwx5EUQb8VoETc5nYTSCXK17qEkxYGf41pg=; b=XoTuGRPT5Rv52ifVAFdsac09hFRR+Y9INDCw8m7SU9T4QqTKl2QdyumfjVh/56qTFbJ8A6 RJLFvisxBdk2hZBXGAp5sp7XSoLJ7oqgzKgAnj2kEVjW+qZhjG24DGJMG2e7Zbl2cVbNJe TJQz8NDH1CW4EYR+L5GdfEt3WQIEBYs= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-139-D46nVmCiPASQG7FRI7NgQg-1; Tue, 05 Oct 2021 14:58:28 -0400 X-MC-Unique: D46nVmCiPASQG7FRI7NgQg-1 Received: by mail-wr1-f70.google.com with SMTP id k2-20020adff5c2000000b00160b12639a5so79021wrp.3 for ; Tue, 05 Oct 2021 11:58:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f8Ls47LDQwx5EUQb8VoETc5nYTSCXK17qEkxYGf41pg=; b=rPbUfiJOXFnbP8ZV1K9yUgzc7pQ8Z+1az1XRK7CZhOQnxlRidPR1QinHs5Fc6iSmhE 0Eyy9Nn2XsAgZNKCWe3QaECG9ZAx6lcqosMfEZetKTdBK51C0+6VQMzXo/MAQelIAfXs ORVBTqW6gTsx5O125mHCtLLKA+sfX0VTxPEmdXnr01oX1yKGSsLdHnMwEUxPG0S3jCPt bJ0opeS6Vsf+Ibp3VcXocAqLcsWJSvz/weLZKi1X7xcJJ0aSZZ5Sc3Si5F/OFkp9GvQy fN0Y3lvahhvhwg2Cs7ycANlAeRiJakWhWp5cSA13B0I6eOeMVNHz5oLVVWlBMSr76czy oSlw== X-Gm-Message-State: AOAM533eHiH8WzQlyYQ0ebOnE6vt/p+nPQ4whUyljJmSFg2Q+Xm2yXAJ qVS4qUiSrwYTxxhG+PzuAOMrFcPAQBICDXo50t1b36U12tGkazJpGDswKMQb3I5ficMrxVyjLTd 2zhX4IItjj+xaZN//6xVkV3/cDfjtCRZcknCQaZFUrKE1bZrpfSdUxauKR8IMvycs X-Received: by 2002:a05:600c:1d18:: with SMTP id l24mr5322791wms.98.1633460306550; Tue, 05 Oct 2021 11:58:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpsLJqgIzOS/1WvaTqnMG9oMbi3+E5hwQvvcTn6XEkKxOy/03Y3mE4/cRQ/NQW8J6HO7v/5w== X-Received: by 2002:a05:600c:1d18:: with SMTP id l24mr5322754wms.98.1633460306278; Tue, 05 Oct 2021 11:58:26 -0700 (PDT) Received: from x1w.redhat.com (118.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.118]) by smtp.gmail.com with ESMTPSA id u17sm4364007wrw.85.2021.10.05.11.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 11:58:25 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 4/4] hw/block/virtio-blk: Use automatic AIO context lock Date: Tue, 5 Oct 2021 20:58:07 +0200 Message-Id: <20211005185807.4134557-5-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211005185807.4134557-1-philmd@redhat.com> References: <20211005185807.4134557-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.066, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, "Michael S. Tsirkin" , "Dr . David Alan Gilbert" , Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use the automatic AIO context acquire/release in virtio_blk_reset(). Signed-off-by: Philippe Mathieu-Daudé --- hw/block/virtio-blk.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index f139cd7cc9c..2dd6428e7b3 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -896,24 +896,22 @@ static void virtio_blk_dma_restart_cb(void *opaque, bool running, static void virtio_blk_reset(VirtIODevice *vdev) { VirtIOBlock *s = VIRTIO_BLK(vdev); - AioContext *ctx; VirtIOBlockReq *req; - ctx = blk_get_aio_context(s->blk); - aio_context_acquire(ctx); - blk_drain(s->blk); - - /* We drop queued requests after blk_drain() because blk_drain() itself can - * produce them. */ - while (s->rq) { - req = s->rq; - s->rq = req->next; - virtqueue_detach_element(req->vq, &req->elem, 0); - virtio_blk_free_request(req); + WITH_AIO_CONTEXT_ACQUIRE_GUARD(blk_get_aio_context(s->blk)) { + blk_drain(s->blk); + /* + * We drop queued requests after blk_drain() because + * blk_drain() itself can produce them. + */ + while (s->rq) { + req = s->rq; + s->rq = req->next; + virtqueue_detach_element(req->vq, &req->elem, 0); + virtio_blk_free_request(req); + } } - aio_context_release(ctx); - assert(!s->dataplane_started); blk_set_enable_write_cache(s->blk, s->original_wce); }