From nobody Thu Dec 18 17:53:19 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586454208; cv=none; d=zohomail.com; s=zohoarc; b=PXo3LgYx084Hut0fh/3JntrIxnh8dwqmrPebBdgLDtMGtq9MG/VLvwUddMQeeyYuwNG+XpQ0llZaZee09sl6Ee2u2RNfFK8VanLHkDmJp5Dg+bFBhIN5zOPAAZrFlhpSZmEdV812KsS/cnmBtCEiDEOOHXAEGSHrMshNQj1Kxlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586454208; h=Content-Type: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=0zq38BUlrj/isy7pME+Q9jm+00Jwv5PAkZjHQUQ5kxo=; b=SSSIA5AVurwJ3DPySOdsn1Y+8Y+hzwYb6aD8ACKckCltDUK/z1fZoZkfp+g1eR8RzKw2h2uAZ7lSh92KxO2iIbABQJgRya0MMvVvwUwvuvKKxFkYOLgHCGW3Sz1xuEDyEY8CA7ufS39pQefRtW8fF4xKvUw5uixjHOYrpp18CA0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586454208683200.25243036725885; Thu, 9 Apr 2020 10:43:28 -0700 (PDT) Received: from localhost ([::1]:53398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMbD5-000745-Bv for importer@patchew.org; Thu, 09 Apr 2020 13:43:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39483) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMbC9-0005TD-JI for qemu-devel@nongnu.org; Thu, 09 Apr 2020 13:42:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jMbC7-0006pm-8W for qemu-devel@nongnu.org; Thu, 09 Apr 2020 13:42:29 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:51682 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jMbC7-0006pU-4t for qemu-devel@nongnu.org; Thu, 09 Apr 2020 13:42:27 -0400 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-197-NgQl9B4HPLSsDAxMoL9b9g-1; Thu, 09 Apr 2020 13:42:24 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6EEEA1922963; Thu, 9 Apr 2020 17:42:23 +0000 (UTC) Received: from localhost (ovpn-114-141.ams2.redhat.com [10.36.114.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0819C1195A6; Thu, 9 Apr 2020 17:42:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586454146; 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=0zq38BUlrj/isy7pME+Q9jm+00Jwv5PAkZjHQUQ5kxo=; b=Wv7xAHPjNkDHAUEll4tqvlPFYtZEqIq+JvwhWmhHcbF/a3meLT0Mt/yeFoIKsUIPHZlHzy n2JO3HO0RWm5CULC0v6SGjUusvmQQE7ena2EecYpSxBTtj3oIYGxctZTnCG53zs00kea6L LP4pECKbaFnDjiEtNNeKIZPyAa9qJVM= X-MC-Unique: NgQl9B4HPLSsDAxMoL9b9g-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PULL for-5.0 2/3] aio-wait: delegate polling of main AioContext if BQL not held Date: Thu, 9 Apr 2020 18:42:08 +0100 Message-Id: <20200409174209.321725-3-stefanha@redhat.com> In-Reply-To: <20200409174209.321725-1-stefanha@redhat.com> References: <20200409174209.321725-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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 , Peter Maydell , qemu-block@nongnu.org, Stefan Weil , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Any thread that is not a iothread returns NULL for qemu_get_current_aio_con= text(). As a result, it would also return true for in_aio_context_home_thread(qemu_get_aio_context()), causing AIO_WAIT_WHILE to invoke aio_poll() directly. This is incorrect if the BQL is not held, because aio_poll() does not expect to run concurrently from multiple threads, and it can actually happen when savevm writes to the vmstate file from the migration thread. Therefore, restrict in_aio_context_home_thread to return true for the main AioContext only if the BQL is held. The function is moved to aio-wait.h because it is mostly used there and to avoid a circular reference between main-loop.h and block/aio.h. Signed-off-by: Paolo Bonzini Message-Id: <20200407140746.8041-5-pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi --- include/block/aio-wait.h | 22 ++++++++++++++++++++++ include/block/aio.h | 29 ++++++++++------------------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h index afeeb18f95..716d2639df 100644 --- a/include/block/aio-wait.h +++ b/include/block/aio-wait.h @@ -26,6 +26,7 @@ #define QEMU_AIO_WAIT_H =20 #include "block/aio.h" +#include "qemu/main-loop.h" =20 /** * AioWait: @@ -124,4 +125,25 @@ void aio_wait_kick(void); */ void aio_wait_bh_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque); =20 +/** + * in_aio_context_home_thread: + * @ctx: the aio context + * + * Return whether we are running in the thread that normally runs @ctx. N= ote + * that acquiring/releasing ctx does not affect the outcome, each AioConte= xt + * still only has one home thread that is responsible for running it. + */ +static inline bool in_aio_context_home_thread(AioContext *ctx) +{ + if (ctx =3D=3D qemu_get_current_aio_context()) { + return true; + } + + if (ctx =3D=3D qemu_get_aio_context()) { + return qemu_mutex_iothread_locked(); + } else { + return false; + } +} + #endif /* QEMU_AIO_WAIT_H */ diff --git a/include/block/aio.h b/include/block/aio.h index cb1989105a..62ed954344 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -133,12 +133,16 @@ struct AioContext { AioHandlerList deleted_aio_handlers; =20 /* Used to avoid unnecessary event_notifier_set calls in aio_notify; - * accessed with atomic primitives. If this field is 0, everything - * (file descriptors, bottom halves, timers) will be re-evaluated - * before the next blocking poll(), thus the event_notifier_set call - * can be skipped. If it is non-zero, you may need to wake up a - * concurrent aio_poll or the glib main event loop, making - * event_notifier_set necessary. + * only written from the AioContext home thread, or under the BQL in + * the case of the main AioContext. However, it is read from any + * thread so it is still accessed with atomic primitives. + * + * If this field is 0, everything (file descriptors, bottom halves, + * timers) will be re-evaluated before the next blocking poll() or + * io_uring wait; therefore, the event_notifier_set call can be + * skipped. If it is non-zero, you may need to wake up a concurrent + * aio_poll or the glib main event loop, making event_notifier_set + * necessary. * * Bit 0 is reserved for GSource usage of the AioContext, and is 1 * between a call to aio_ctx_prepare and the next call to aio_ctx_chec= k. @@ -681,19 +685,6 @@ void aio_co_enter(AioContext *ctx, struct Coroutine *c= o); */ AioContext *qemu_get_current_aio_context(void); =20 -/** - * in_aio_context_home_thread: - * @ctx: the aio context - * - * Return whether we are running in the thread that normally runs @ctx. N= ote - * that acquiring/releasing ctx does not affect the outcome, each AioConte= xt - * still only has one home thread that is responsible for running it. - */ -static inline bool in_aio_context_home_thread(AioContext *ctx) -{ - return ctx =3D=3D qemu_get_current_aio_context(); -} - /** * aio_context_setup: * @ctx: the aio context --=20 2.25.1