From nobody Mon Feb 9 08:57:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666941488; cv=none; d=zohomail.com; s=zohoarc; b=DnvOlLDKwyMbpZ83poICDeumv4BSw6QVgCLWyIr2wqn1eaHU++bNwDB5G7bXm75OdsXnFx/xAR7s0MKYgjdPP8e5JRtKlmotUjzfHOFn16fxm2gNM7k4WlMKRK28d6w/c7C46dhkw0V0w/Nwf7tQwna9eyXE0J5pN1wPcZiCOEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666941488; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pe6EMnCgwBsJ+UXM6OUFwdRySDmt3ePeRadxDWE2nYs=; b=SaYlVcqOR1RfNl0PRcHvNOQQXE4qEtW+hNTROR8JIFJNcJavX3WBRaijRonOj+1cckVf4nyuGykFQ8pIfpBDcjM10rAn+X0gkRar9C5oubbqwWNRnks6ir1XdiT+vjpWPeqNM1lQkSz8LJt17dcz5S5UDWnwk5y62xDOC2uoCQ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666941488548521.2146412911486; Fri, 28 Oct 2022 00:18:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooJbv-0000KA-SB; Fri, 28 Oct 2022 03:16:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooJbo-0008Su-GH for qemu-devel@nongnu.org; Fri, 28 Oct 2022 03:16:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooJbm-0001kv-RB for qemu-devel@nongnu.org; Fri, 28 Oct 2022 03:16:52 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-98-9WmVUglCPZqlpNrykFer7A-1; Fri, 28 Oct 2022 03:16:39 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5340D38012C5; Fri, 28 Oct 2022 07:16:39 +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 04A48112131B; Fri, 28 Oct 2022 07:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666941410; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pe6EMnCgwBsJ+UXM6OUFwdRySDmt3ePeRadxDWE2nYs=; b=Cb3y+MOOaM0acT1FcoLRFLDt7Oa17Q8vpuNjcY5mfPb4PUuesc1dpMKEMXUttWFbrmqR+E 6/cbSvoPFzPhoEQtSsHFQHgBoNxeMIjAPjqu0z2ziaVPdLPJ8m+ioIUIj/SY3yAoze8s0t Keh8E3VAvLjvMuy6N/t+6ykyA8tpNlA= X-MC-Unique: 9WmVUglCPZqlpNrykFer7A-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Stefan Weil , Aarushi Mehta , Julia Suvorova , Stefan Hajnoczi , Stefano Garzarella , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v2 2/3] io_uring: use LuringState from the running thread Date: Fri, 28 Oct 2022 03:16:34 -0400 Message-Id: <20221028071635.3037348-3-eesposit@redhat.com> In-Reply-To: <20221028071635.3037348-1-eesposit@redhat.com> References: <20221028071635.3037348-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.515, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666941490835100007 Content-Type: text/plain; charset="utf-8" Remove usage of aio_context_acquire by always submitting asynchronous AIO to the current thread's LuringState. In order to prevent mistakes from the caller side, avoid passing LuringState in luring_io_{plug/unplug} and luring_co_submit. Signed-off-by: Emanuele Giuseppe Esposito --- block/file-posix.c | 12 ++++-------- block/io_uring.c | 26 +++++++++++++++----------- include/block/aio.h | 4 ---- include/block/raw-aio.h | 8 ++++---- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 23fe98eb3e..3800dbd222 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2093,9 +2093,8 @@ static int coroutine_fn raw_co_prw(BlockDriverState *= bs, uint64_t offset, type |=3D QEMU_AIO_MISALIGNED; #ifdef CONFIG_LINUX_IO_URING } else if (s->use_linux_io_uring) { - LuringState *aio =3D aio_get_linux_io_uring(bdrv_get_aio_context(b= s)); assert(qiov->size =3D=3D bytes); - return luring_co_submit(bs, aio, s->fd, offset, qiov, type); + return luring_co_submit(bs, s->fd, offset, qiov, type); #endif #ifdef CONFIG_LINUX_AIO } else if (s->use_linux_aio) { @@ -2145,8 +2144,7 @@ static void raw_aio_plug(BlockDriverState *bs) #endif #ifdef CONFIG_LINUX_IO_URING if (s->use_linux_io_uring) { - LuringState *aio =3D aio_get_linux_io_uring(bdrv_get_aio_context(b= s)); - luring_io_plug(bs, aio); + luring_io_plug(); } #endif } @@ -2161,8 +2159,7 @@ static void raw_aio_unplug(BlockDriverState *bs) #endif #ifdef CONFIG_LINUX_IO_URING if (s->use_linux_io_uring) { - LuringState *aio =3D aio_get_linux_io_uring(bdrv_get_aio_context(b= s)); - luring_io_unplug(bs, aio); + luring_io_unplug(); } #endif } @@ -2186,8 +2183,7 @@ static int coroutine_fn raw_co_flush_to_disk(BlockDri= verState *bs) =20 #ifdef CONFIG_LINUX_IO_URING if (s->use_linux_io_uring) { - LuringState *aio =3D aio_get_linux_io_uring(bdrv_get_aio_context(b= s)); - return luring_co_submit(bs, aio, s->fd, 0, NULL, QEMU_AIO_FLUSH); + return luring_co_submit(bs, s->fd, 0, NULL, QEMU_AIO_FLUSH); } #endif return raw_thread_pool_submit(bs, handle_aiocb_flush, &acb); diff --git a/block/io_uring.c b/block/io_uring.c index a1760152e0..8deaf8972b 100644 --- a/block/io_uring.c +++ b/block/io_uring.c @@ -19,6 +19,8 @@ #include "qapi/error.h" #include "trace.h" =20 +/* Only used for assertions. */ +#include "qemu/coroutine_int.h" =20 /* io_uring ring size */ #define MAX_ENTRIES 128 @@ -52,10 +54,9 @@ typedef struct LuringState { =20 struct io_uring ring; =20 - /* io queue for submit at batch. Protected by AioContext lock. */ + /* All data is only used in one I/O thread. */ LuringQueue io_q; =20 - /* I/O completion processing. Only runs in I/O thread. */ QEMUBH *completion_bh; } LuringState; =20 @@ -211,9 +212,8 @@ end: * eventually runs later. Coroutines cannot be entered recursively * so avoid doing that! */ - if (!qemu_coroutine_entered(luringcb->co)) { - aio_co_wake(luringcb->co); - } + assert(luringcb->co->ctx =3D=3D luringcb->aio_context); + qemu_coroutine_enter_if_inactive(luringcb->co); } qemu_bh_cancel(s->completion_bh); } @@ -264,13 +264,11 @@ static int ioq_submit(LuringState *s) =20 static void luring_process_completions_and_submit(LuringState *s) { - aio_context_acquire(s->aio_context); luring_process_completions(s); =20 if (!s->io_q.plugged && s->io_q.in_queue > 0) { ioq_submit(s); } - aio_context_release(s->aio_context); } =20 static void qemu_luring_completion_bh(void *opaque) @@ -308,14 +306,18 @@ static void ioq_init(LuringQueue *io_q) io_q->blocked =3D false; } =20 -void luring_io_plug(BlockDriverState *bs, LuringState *s) +void luring_io_plug(void) { + AioContext *ctx =3D qemu_get_current_aio_context(); + LuringState *s =3D aio_get_linux_io_uring(ctx); trace_luring_io_plug(s); s->io_q.plugged++; } =20 -void luring_io_unplug(BlockDriverState *bs, LuringState *s) +void luring_io_unplug(void) { + AioContext *ctx =3D qemu_get_current_aio_context(); + LuringState *s =3D aio_get_linux_io_uring(ctx); assert(s->io_q.plugged); trace_luring_io_unplug(s, s->io_q.blocked, s->io_q.plugged, s->io_q.in_queue, s->io_q.in_flight); @@ -375,10 +377,12 @@ static int luring_do_submit(int fd, LuringAIOCB *luri= ngcb, LuringState *s, return 0; } =20 -int coroutine_fn luring_co_submit(BlockDriverState *bs, LuringState *s, in= t fd, - uint64_t offset, QEMUIOVector *qiov, int= type) +int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t o= ffset, + QEMUIOVector *qiov, int type) { int ret; + AioContext *ctx =3D qemu_get_current_aio_context(); + LuringState *s =3D aio_get_linux_io_uring(ctx); LuringAIOCB luringcb =3D { .co =3D qemu_coroutine_self(), .ret =3D -EINPROGRESS, diff --git a/include/block/aio.h b/include/block/aio.h index 8bb5eea4a9..15375ff63a 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -203,10 +203,6 @@ struct AioContext { struct LinuxAioState *linux_aio; #endif #ifdef CONFIG_LINUX_IO_URING - /* - * State for Linux io_uring. Uses aio_context_acquire/release for - * locking. - */ struct LuringState *linux_io_uring; =20 /* State for file descriptor monitoring using Linux io_uring */ diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index f0f14f14f8..4d6b0ee125 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -62,12 +62,12 @@ void laio_io_unplug(uint64_t dev_max_batch); typedef struct LuringState LuringState; LuringState *luring_init(Error **errp); void luring_cleanup(LuringState *s); -int coroutine_fn luring_co_submit(BlockDriverState *bs, LuringState *s, in= t fd, - uint64_t offset, QEMUIOVector *qiov, int t= ype); +int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t o= ffset, + QEMUIOVector *qiov, int type); void luring_detach_aio_context(LuringState *s, AioContext *old_context); void luring_attach_aio_context(LuringState *s, AioContext *new_context); -void luring_io_plug(BlockDriverState *bs, LuringState *s); -void luring_io_unplug(BlockDriverState *bs, LuringState *s); +void luring_io_plug(void); +void luring_io_unplug(void); #endif =20 #ifdef _WIN32 --=20 2.31.1