From nobody Mon Nov 25 04:09:33 2024 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=1598886197; cv=none; d=zohomail.com; s=zohoarc; b=EjQCSrnwMCScz9Le3SrwJa4Tdb7NXRKL1b5w3qxx7qsP8FsHOLsfinN+93/Tik+EDMzqtailN1PEHg/lxfGBzEUYMtotIogibHovZemgawetxmBBLSzNX61oJFxQ3buzj4A9AVzv7NlqVBKh8bMrZtjGo5lDal3Fk7NrvM1Tesg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598886197; 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=qFxxKXv45+YeuWDgfHdSeowkU7NVsNR1P4xUgcB+O18=; b=e8eKuIybueYXbHawgqHycJdWjNn+JIprMWSq4RLwLt0by4aYFOJU5HyRWxAJEDF606MVvBojDxfl2oE1jXPWSELD1yNoI9iJgvXy5EqvJbXcXlhQSyRXqWXIkYBFrc24pLH/91M5seKGZeMEyIdxrij3EQ8DL6gLGICnllvYiTo= 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 1598886197239608.2411561980524; Mon, 31 Aug 2020 08:03:17 -0700 (PDT) Received: from localhost ([::1]:34966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kClL1-0007hu-Qn for importer@patchew.org; Mon, 31 Aug 2020 11:03:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kClJZ-0006Bf-JK for qemu-devel@nongnu.org; Mon, 31 Aug 2020 11:01:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25507) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kClJX-0004VH-As for qemu-devel@nongnu.org; Mon, 31 Aug 2020 11:01:45 -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-395-CeA76xckOCqariznq96bNQ-1; Mon, 31 Aug 2020 11:01:40 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 30C71801AC5; Mon, 31 Aug 2020 15:01:39 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id A069019C4F; Mon, 31 Aug 2020 15:01:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598886102; 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=qFxxKXv45+YeuWDgfHdSeowkU7NVsNR1P4xUgcB+O18=; b=P5XVRr+3Q3/iXeLA2SJwb4bmrSG6tmcyVc1YQ0eW6GnRFh+JU4kt+f+jOWTJBWxZGEONvZ wmaYZFhrg4nATGgrkAjJN3Byb/kL/fYzq+or1O+GEfoAizWM0EDt4IwtBmpecPLjBij4gz sCyhzPRdzvFTSNpPj91LRmGaqHGMcWA= X-MC-Unique: CeA76xckOCqariznq96bNQ-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v4 2/9] rcu: Implement drain_call_rcu Date: Mon, 31 Aug 2020 18:01:17 +0300 Message-Id: <20200831150124.206267-3-mlevitsk@redhat.com> In-Reply-To: <20200831150124.206267-1-mlevitsk@redhat.com> References: <20200831150124.206267-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mlevitsk@redhat.com X-Mimecast-Spam-Score: 0.002 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=216.205.24.124; envelope-from=mlevitsk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 03:43:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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, DKIMWL_WL_HIGH=-0.001, 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_H5=0.001, RCVD_IN_MSPIKE_WL=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: Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Stefan Hajnoczi , Maxim Levitsky , Stefan Hajnoczi , Paolo Bonzini 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" This will allow is to preserve the semantics of hmp_device_del, that the device is deleted immediatly which was changed by previos patch that delayed this to RCU callback Signed-off-by: Maxim Levitsky Suggested-by: Stefan Hajnoczi Reviewed-by: Stefan Hajnoczi --- include/qemu/rcu.h | 1 + util/rcu.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h index 570aa603eb..0e375ebe13 100644 --- a/include/qemu/rcu.h +++ b/include/qemu/rcu.h @@ -133,6 +133,7 @@ struct rcu_head { }; =20 extern void call_rcu1(struct rcu_head *head, RCUCBFunc *func); +extern void drain_call_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/util/rcu.c b/util/rcu.c index 60a37f72c3..c4fefa9333 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -293,6 +293,61 @@ void call_rcu1(struct rcu_head *node, void (*func)(str= uct rcu_head *node)) qemu_event_set(&rcu_call_ready_event); } =20 + +struct rcu_drain { + struct rcu_head rcu; + QemuEvent drain_complete_event; +}; + +static void drain_rcu_callback(struct rcu_head *node) +{ + struct rcu_drain *event =3D (struct rcu_drain *)node; + qemu_event_set(&event->drain_complete_event); +} + +/* + * This function ensures that all pending RCU callbacks + * on the current thread are done executing + + * drops big qemu lock during the wait to allow RCU thread + * to process the callbacks + * + */ + +void drain_call_rcu(void) +{ + struct rcu_drain rcu_drain; + bool locked =3D qemu_mutex_iothread_locked(); + + memset(&rcu_drain, 0, sizeof(struct rcu_drain)); + qemu_event_init(&rcu_drain.drain_complete_event, false); + + if (locked) { + qemu_mutex_unlock_iothread(); + } + + + /* + * RCU callbacks are invoked in the same order as in which they + * are registered, thus we can be sure that when 'drain_rcu_callback' + * is called, all RCU callbacks that were registered on this thread + * prior to calling this function are completed. + * + * Note that since we have only one global queue of the RCU callbacks, + * we also end up waiting for most of RCU callbacks that were register= ed + * on the other threads, but this is a side effect that shoudn't be + * assumed. + */ + + call_rcu1(&rcu_drain.rcu, drain_rcu_callback); + qemu_event_wait(&rcu_drain.drain_complete_event); + + if (locked) { + qemu_mutex_lock_iothread(); + } + +} + void rcu_register_thread(void) { assert(rcu_reader.ctr =3D=3D 0); --=20 2.26.2