From nobody Mon Feb 9 01:01:32 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1635861227; cv=none; d=zohomail.com; s=zohoarc; b=cwI2zZ8D+naheqhcAJFGcWEcCSikpIn0okWineV6s1pYOqzrwj6Mf2msj2bDJOZTa35GLMiNkspLjT33EqcFPIL6eYhW1Rv0zLngCls8RRuDs9EHqVQfOWxh2JFEodD6CjX37QNKI99USHB7b1Y+CDFFFFk0yG12WDHuHIiTbeE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635861227; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=dS5M3tFrBHWIS8Shku3dELlUlfbO/3KbYO55up63qnQ=; b=P/c8IKxrJprh+ENLhkit5vGYUMKASmIzbiIbFvn7GbjCyzSGf71uBlCfEP/gBi2ZVwlex/L1MfbymihqKvGxrhe2iDAbzD/y++ihBId4JlZMtBpPzKeHo8/RN5dOtzwTutv8fO5c2GaBO2InPgFXxpXYessbmpohNSNjw/yrQuA= 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 1635861227523353.62471745526693; Tue, 2 Nov 2021 06:53:47 -0700 (PDT) Received: from localhost ([::1]:59692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mhuEU-0002O2-BA for importer@patchew.org; Tue, 02 Nov 2021 09:53:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mhu0a-0000Zw-59 for qemu-devel@nongnu.org; Tue, 02 Nov 2021 09:39:25 -0400 Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]:33500) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mhu0U-0005GA-WC for qemu-devel@nongnu.org; Tue, 02 Nov 2021 09:39:22 -0400 Received: from iva8-d2cd82b7433e.qloud-c.yandex.net (iva8-d2cd82b7433e.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:a88e:0:640:d2cd:82b7]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 7B58B2E12B9; Tue, 2 Nov 2021 16:39:10 +0300 (MSK) Received: from myt5-70c90f7d6d7d.qloud-c.yandex.net (myt5-70c90f7d6d7d.qloud-c.yandex.net [2a02:6b8:c12:3e2c:0:640:70c9:f7d]) by iva8-d2cd82b7433e.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id Lr6hckm6Cz-dAsOd4FY; Tue, 02 Nov 2021 16:39:10 +0300 Received: from den-plotnikov-w.yandex-team.ru (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b081:8010::1:3a]) by myt5-70c90f7d6d7d.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPS id RyP6wzUDBk-d9xCDFKK; Tue, 02 Nov 2021 16:39:10 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1635860350; bh=dS5M3tFrBHWIS8Shku3dELlUlfbO/3KbYO55up63qnQ=; h=Message-Id:Date:Subject:To:From:Cc; b=adi/Uz1Jyyu7wjgkYxCtaVgELXHCR/jOGE+hTjZlyZ8f/l5E05AS89igReMqjkfu1 2dVZrJUT86rQbK5rS/o0nT/kXjd3sMUrjoSOor6X+NRZsUfoiG3qgsIm6C+JGqB0HP ZsW7y7CRn2QoRpxsp2JHF26POfqS4rLTJpTJOAuQ= Authentication-Results: iva8-d2cd82b7433e.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru X-Yandex-Fwd: 2 From: Denis Plotnikov To: qemu-devel@nongnu.org Subject: [PATCH v0] vl: flush all task from rcu queue before exiting Date: Tue, 2 Nov 2021 16:39:01 +0300 Message-Id: <20211102133901.286027-1-den-plotnikov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 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=77.88.29.217; envelope-from=den-plotnikov@yandex-team.ru; helo=forwardcorp1p.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, yc-core@yandex-team.ru, mlevitsk@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1635861230891100001 Content-Type: text/plain; charset="utf-8" The device destruction may superimpose over qemu shutdown. In this case some management layer, requested a device unplug and waiting for DEVICE_DELETED event, may never get this event. This happens because device_finalize() may never be called on qemu shutdown for some devices using address_space_destroy(). The later is called from the rcu thread. On qemu shutdown, not all rcu callbacks may be called because the rcu thread may not have enough time to converge before qemu main thread exit. To resolve this issue this patch makes rcu thread to finish all its callbac= ks explicitly by calling a new rcu intreface function right before qemu main thread exit. Signed-off-by: Denis Plotnikov --- include/qemu/rcu.h | 1 + softmmu/runstate.c | 3 +++ util/rcu.c | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h index 515d327cf11c..f7fbdc3781e5 100644 --- a/include/qemu/rcu.h +++ b/include/qemu/rcu.h @@ -134,6 +134,7 @@ struct rcu_head { =20 extern void call_rcu1(struct rcu_head *head, RCUCBFunc *func); extern void drain_call_rcu(void); +extern void flush_rcu(void); =20 /* The operands of the minus operator must have the same type, * which must be the one that we specify in the cast. diff --git a/softmmu/runstate.c b/softmmu/runstate.c index 10d9b7365aa7..28f319a97a2b 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -822,5 +822,8 @@ void qemu_cleanup(void) monitor_cleanup(); qemu_chr_cleanup(); user_creatable_cleanup(); + + /* finish all the tasks from rcu queue before exiting */ + flush_rcu(); /* TODO: unref root container, check all devices are ok */ } diff --git a/util/rcu.c b/util/rcu.c index 13ac0f75cb2a..f047f8ee8d16 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -348,6 +348,18 @@ void drain_call_rcu(void) =20 } =20 +/* + * This function drains rcu queue until there are no tasks to do left + * and aims to the cases when one needs to ensure that no work hang + * in rcu thread before proceeding, e.g. on qemu shutdown. + */ +void flush_rcu(void) +{ + while (qatomic_read(&rcu_call_count) > 0) { + drain_call_rcu(); + } +} + void rcu_register_thread(void) { assert(rcu_reader.ctr =3D=3D 0); --=20 2.25.1