From nobody Mon Feb 9 16:12:58 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1584001766; cv=none; d=zohomail.com; s=zohoarc; b=BO2r6SBF/gkvEnaethG6U+wSCwXIiBKybQCq7HACAQSBY4gQEE9XAJAGBJhwrQpWIJ/9/QbgXNQIbelCtPbT+QI/CzaTQyEo9+swbK2AVxM4DyvPlpHPuHDC7VyK/doOGjdW3QJ8GmCwZoI4iwSS+TKchWD6MNkrtBh1YKXtTZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584001766; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JeeA3HXLn+IiG0LS8xpqntr6BcKN2ZwBpoDiQH4Yyig=; b=EDwBI8DxTZXJc41LoikySY/pYHGBmN3M/D/Xu5ugFTovfAW9GZfpKS9eJxtRB1aChRmqSJvR6zlhKjyghTLVHZCL7rujDerw/NGUAkgXDyMU+bjFChctdLkeh3BTpXde7pbMbMwDGgmcZ2+ZtHt36WpZ7nbORgsJSNNDgYiRDrc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1584001766041205.2204092280342; Thu, 12 Mar 2020 01:29:26 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jCJCy-0004vU-R7; Thu, 12 Mar 2020 08:28:48 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jCJCx-0004v9-RK for xen-devel@lists.xenproject.org; Thu, 12 Mar 2020 08:28:47 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 76d89565-643b-11ea-b127-12813bfff9fa; Thu, 12 Mar 2020 08:28:36 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 019BBB23A; Thu, 12 Mar 2020 08:28:34 +0000 (UTC) X-Inumbo-ID: 76d89565-643b-11ea-b127-12813bfff9fa X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Thu, 12 Mar 2020 09:28:30 +0100 Message-Id: <20200312082831.22280-4-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200312082831.22280-1-jgross@suse.com> References: <20200312082831.22280-1-jgross@suse.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 3/4] xen/rcu: add assertions to debug build X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Ian Jackson , George Dunlap , Jan Beulich Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Xen's RCU implementation relies on no softirq handling taking place while being in a RCU critical section. Add ASSERT()s in debug builds in order to catch any violations. For that purpose modify rcu_read_[un]lock() to use a dedicated percpu counter instead of preempt_[en|dis]able() as this enables to test that condition in __do_softirq() (ASSERT_NOT_IN_ATOMIC() is not usable there due to __cpu_up() calling process_pending_softirqs() while holding the cpu hotplug lock). Dropping the now no longer needed #include of preempt.h in rcupdate.h requires adding it in some sources. While at it switch the rcu_read_[un]lock() implementation to static inline functions instead of macros. Signed-off-by: Juergen Gross --- V3: - add barriers to rcu_[en|dis]able() (Roger Pau Monn=C3=A9) - add rcu_quiesce_allowed() to ASSERT_NOT_IN_ATOMIC (Roger Pau Monn=C3=A9) - convert macros to static inline functions - add sanity check in rcu_read_unlock() V4: - use barrier() in rcu_[en|dis]able() (Julien Grall) V5: - use rcu counter even if not using a debug build --- xen/common/multicall.c | 1 + xen/common/preempt.c | 5 ++++- xen/common/rcupdate.c | 2 ++ xen/common/softirq.c | 4 +++- xen/common/wait.c | 1 + xen/include/xen/rcupdate.h | 35 +++++++++++++++++++++++++++++++---- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/xen/common/multicall.c b/xen/common/multicall.c index 5a199ebf8f..67f1a23485 100644 --- a/xen/common/multicall.c +++ b/xen/common/multicall.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/xen/common/preempt.c b/xen/common/preempt.c index 3b4178fd44..8a351e644b 100644 --- a/xen/common/preempt.c +++ b/xen/common/preempt.c @@ -21,13 +21,15 @@ =20 #include #include +#include #include =20 DEFINE_PER_CPU(unsigned int, __preempt_count); =20 bool_t in_atomic(void) { - return preempt_count() || in_irq() || !local_irq_is_enabled(); + return preempt_count() || in_irq() || !local_irq_is_enabled() || + !rcu_quiesce_allowed(); } =20 #ifndef NDEBUG @@ -36,5 +38,6 @@ void ASSERT_NOT_IN_ATOMIC(void) ASSERT(!preempt_count()); ASSERT(!in_irq()); ASSERT(local_irq_is_enabled()); + ASSERT(rcu_quiesce_allowed()); } #endif diff --git a/xen/common/rcupdate.c b/xen/common/rcupdate.c index c5ef6acb1e..d73735235d 100644 --- a/xen/common/rcupdate.c +++ b/xen/common/rcupdate.c @@ -46,6 +46,8 @@ #include #include =20 +DEFINE_PER_CPU(unsigned int, rcu_lock_cnt); + /* Global control variables for rcupdate callback mechanism. */ static struct rcu_ctrlblk { long cur; /* Current batch number. */ diff --git a/xen/common/softirq.c b/xen/common/softirq.c index 00d676b62c..eba65c5fc0 100644 --- a/xen/common/softirq.c +++ b/xen/common/softirq.c @@ -31,6 +31,8 @@ static void __do_softirq(unsigned long ignore_mask) unsigned long pending; bool rcu_allowed =3D !(ignore_mask & (1ul << RCU_SOFTIRQ)); =20 + ASSERT(!rcu_allowed || rcu_quiesce_allowed()); + for ( ; ; ) { /* @@ -58,7 +60,7 @@ void process_pending_softirqs(void) (1ul << SCHED_SLAVE_SOFTIRQ); =20 /* Block RCU processing in case of rcu_read_lock() held. */ - if ( preempt_count() ) + if ( !rcu_quiesce_allowed() ) ignore_mask |=3D 1ul << RCU_SOFTIRQ; =20 ASSERT(!in_irq() && local_irq_is_enabled()); diff --git a/xen/common/wait.c b/xen/common/wait.c index 24716e7676..9cdb174036 100644 --- a/xen/common/wait.c +++ b/xen/common/wait.c @@ -19,6 +19,7 @@ * along with this program; If not, see . */ =20 +#include #include #include #include diff --git a/xen/include/xen/rcupdate.h b/xen/include/xen/rcupdate.h index 31c8b86d13..be807694e7 100644 --- a/xen/include/xen/rcupdate.h +++ b/xen/include/xen/rcupdate.h @@ -32,12 +32,32 @@ #define __XEN_RCUPDATE_H =20 #include +#include #include #include -#include +#include =20 #define __rcu =20 +DECLARE_PER_CPU(unsigned int, rcu_lock_cnt); + +static inline void rcu_quiesce_disable(void) +{ + this_cpu(rcu_lock_cnt)++; + barrier(); +} + +static inline void rcu_quiesce_enable(void) +{ + barrier(); + this_cpu(rcu_lock_cnt)--; +} + +static inline bool rcu_quiesce_allowed(void) +{ + return !this_cpu(rcu_lock_cnt); +} + /** * struct rcu_head - callback structure for use with RCU * @next: next update requests in a list @@ -91,16 +111,23 @@ typedef struct _rcu_read_lock rcu_read_lock_t; * will be deferred until the outermost RCU read-side critical section * completes. * - * It is illegal to block while in an RCU read-side critical section. + * It is illegal to process softirqs while in an RCU read-side critical se= ction. */ -#define rcu_read_lock(x) ({ ((void)(x)); preempt_disable(); }) +static inline void rcu_read_lock(rcu_read_lock_t *lock) +{ + rcu_quiesce_disable(); +} =20 /** * rcu_read_unlock - marks the end of an RCU read-side critical section. * * See rcu_read_lock() for more information. */ -#define rcu_read_unlock(x) ({ ((void)(x)); preempt_enable(); }) +static inline void rcu_read_unlock(rcu_read_lock_t *lock) +{ + ASSERT(!rcu_quiesce_allowed()); + rcu_quiesce_enable(); +} =20 /* * So where is rcu_write_lock()? It does not exist, as there is no --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel