From nobody Sat Apr 12 09:15:42 2025 Delivered-To: importer@patchew.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=1589875784; cv=none; d=zohomail.com; s=zohoarc; b=Jm84dvZIqKAXgoXDRUaeJrwJUd4z7aZYnOjs+q7NmcKlObcva5EgGL+NFfCbQCarBv42LZKXb3JlinyLKNP9y6uBMXsGOvxnGtTtevL7VweNDQCd5gBbbScGRITCp5ch6yEhkzZCbYzkxAg4PNYLbASiP/2ZCKHrlpn5mF9uSjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589875784; 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=wZQYqyJDDytFdKeDX7BQ9v3ONr1NxDeFstGIXsm97BM=; b=jJhwPJUzaMa6ROdbyJfSNczCWtVvdxUUhOrI9XCEz7P8Ydk3ZOtu9mK6CB2+iC6f/0Ieq8TpYoCVF8KRcJBBaSihYRbREtaOaZwcviyIG3cmL7CLwewBZJQddEJlDa+oqEnHw3QIwW+t3pllRe/KdeB2i0/xTyDMrg0SJbgJDBg= 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 1589875784817172.60167698739235; Tue, 19 May 2020 01:09:44 -0700 (PDT) Received: from localhost ([::1]:40024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jaxJn-0006mU-F1 for importer@patchew.org; Tue, 19 May 2020 04:09:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jaxCO-0004tb-2k for qemu-devel@nongnu.org; Tue, 19 May 2020 04:02:04 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:57600 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jaxCN-0001dQ-AT for qemu-devel@nongnu.org; Tue, 19 May 2020 04:02:03 -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-322-fe2EQ68gMEqbGoCrk9eriw-1; Tue, 19 May 2020 04:01:58 -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 43502107ACCA; Tue, 19 May 2020 08:01:57 +0000 (UTC) Received: from localhost (ovpn-114-215.ams2.redhat.com [10.36.114.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18B7A79581; Tue, 19 May 2020 08:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589875322; 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=wZQYqyJDDytFdKeDX7BQ9v3ONr1NxDeFstGIXsm97BM=; b=i2MYAbuLrCCXzvTzQMpD1d0HYblXV67E0NVATMsKalmFaodg7RY8jO9Nf7L7TOPsSvle3c 2Cj0NCokiKt+p65ScwtFQpiRtWNWxL2lPs8/jj/PeL2HRpd/sXEw8Bd7CCrkeRgoLTAtj3 hlqo4w9As02XvVY0eXSdh6vtGwYZR5I= X-MC-Unique: fe2EQ68gMEqbGoCrk9eriw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PULL 7/8] aio-posix: don't duplicate fd handler deletion in fdmon_io_uring_destroy() Date: Tue, 19 May 2020 09:00:53 +0100 Message-Id: <20200519080054.146495-8-stefanha@redhat.com> In-Reply-To: <20200519080054.146495-1-stefanha@redhat.com> References: <20200519080054.146495-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 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=205.139.110.61; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/18 23:19:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: Laurent Vivier , Peter Maydell , Thomas Huth , qemu-block@nongnu.org, Oleksandr Natalenko , Stefan Weil , Max Reitz , Alexander Bulekov , Bandan Das , Stefan Hajnoczi , Paolo Bonzini , Fam Zheng , Kevin Wolf 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" The io_uring file descriptor monitoring implementation has an internal list of fd handlers that are pending submission to io_uring. fdmon_io_uring_destroy() deletes all fd handlers on the list. Don't delete fd handlers directly in fdmon_io_uring_destroy() for two reasons: 1. This duplicates the aio-posix.c AioHandler deletion code and could become outdated if the struct changes. 2. Only handlers with the FDMON_IO_URING_REMOVE flag set are safe to remove. If the flag is not set then something still has a pointer to the fd handler. Let aio-posix.c and its user worry about that. In practice this isn't an issue because fdmon_io_uring_destroy() is only called when shutting down so all users have removed their fd handlers, but the next patch will need this! Signed-off-by: Stefan Hajnoczi Tested-by: Oleksandr Natalenko Message-id: 20200511183630.279750-2-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- util/aio-posix.c | 1 + util/fdmon-io_uring.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/util/aio-posix.c b/util/aio-posix.c index c3613d299e..8af334ab19 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -679,6 +679,7 @@ void aio_context_destroy(AioContext *ctx) { fdmon_io_uring_destroy(ctx); fdmon_epoll_disable(ctx); + aio_free_deleted_handlers(ctx); } =20 void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, diff --git a/util/fdmon-io_uring.c b/util/fdmon-io_uring.c index d5a80ed6fb..1d14177df0 100644 --- a/util/fdmon-io_uring.c +++ b/util/fdmon-io_uring.c @@ -342,11 +342,18 @@ void fdmon_io_uring_destroy(AioContext *ctx) =20 io_uring_queue_exit(&ctx->fdmon_io_uring); =20 - /* No need to submit these anymore, just free them. */ + /* Move handlers due to be removed onto the deleted list */ while ((node =3D QSLIST_FIRST_RCU(&ctx->submit_list))) { + unsigned flags =3D atomic_fetch_and(&node->flags, + ~(FDMON_IO_URING_PENDING | + FDMON_IO_URING_ADD | + FDMON_IO_URING_REMOVE)); + + if (flags & FDMON_IO_URING_REMOVE) { + QLIST_INSERT_HEAD_RCU(&ctx->deleted_aio_handlers, node, no= de_deleted); + } + QSLIST_REMOVE_HEAD_RCU(&ctx->submit_list, node_submitted); - QLIST_REMOVE(node, node); - g_free(node); } =20 ctx->fdmon_ops =3D &fdmon_poll_ops; --=20 2.25.3