From patchwork Tue Mar 10 07:28:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11428597 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D13CC14E3 for ; Tue, 10 Mar 2020 07:30:07 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B72F024655 for ; Tue, 10 Mar 2020 07:30:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B72F024655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jBZKD-0001bd-8B; Tue, 10 Mar 2020 07:29:13 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jBZKA-0001ay-Vs for xen-devel@lists.xenproject.org; Tue, 10 Mar 2020 07:29:11 +0000 X-Inumbo-ID: cfbffa36-62a0-11ea-bdac-bc764e2007e4 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cfbffa36-62a0-11ea-bdac-bc764e2007e4; Tue, 10 Mar 2020 07:29:01 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 7629CAE38; Tue, 10 Mar 2020 07:28:59 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Tue, 10 Mar 2020 08:28:53 +0100 Message-Id: <20200310072853.27567-7-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200310072853.27567-1-jgross@suse.com> References: <20200310072853.27567-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v4 6/6] xen/rcu: add per-lock counter in debug builds 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Add a lock specific counter to rcu read locks in debug builds. This allows to test for matching lock/unlock calls. Signed-off-by: Juergen Gross --- xen/include/xen/rcupdate.h | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/xen/include/xen/rcupdate.h b/xen/include/xen/rcupdate.h index 0f32b3c7d8..602b819d75 100644 --- a/xen/include/xen/rcupdate.h +++ b/xen/include/xen/rcupdate.h @@ -36,21 +36,33 @@ #include #include #include +#include #define __rcu #ifndef NDEBUG +/* * Lock type for passing to rcu_read_{lock,unlock}. */ +struct _rcu_read_lock { + atomic_t cnt; +}; +typedef struct _rcu_read_lock rcu_read_lock_t; +#define DEFINE_RCU_READ_LOCK(x) rcu_read_lock_t x = { .cnt = ATOMIC_INIT(0) } +#define RCU_READ_LOCK_INIT(x) atomic_set(&(x)->cnt, 0) + DECLARE_PER_CPU(unsigned int, rcu_lock_cnt); -static inline void rcu_quiesce_disable(void) +static inline void rcu_quiesce_disable(rcu_read_lock_t *lock) { this_cpu(rcu_lock_cnt)++; + atomic_inc(&lock->cnt); barrier(); } -static inline void rcu_quiesce_enable(void) +static inline void rcu_quiesce_enable(rcu_read_lock_t *lock) { barrier(); + ASSERT(atomic_read(&lock->cnt)); + atomic_dec(&lock->cnt); this_cpu(rcu_lock_cnt)--; } @@ -60,8 +72,17 @@ static inline bool rcu_quiesce_allowed(void) } #else -static inline void rcu_quiesce_disable(void) { } -static inline void rcu_quiesce_enable(void) { } +/* + * Dummy lock type for passing to rcu_read_{lock,unlock}. Currently exists + * only to document the reason for rcu_read_lock() critical sections. + */ +struct _rcu_read_lock {}; +typedef struct _rcu_read_lock rcu_read_lock_t; +#define DEFINE_RCU_READ_LOCK(x) rcu_read_lock_t x +#define RCU_READ_LOCK_INIT(x) + +static inline void rcu_quiesce_disable(rcu_read_lock_t *lock) { } +static inline void rcu_quiesce_enable(rcu_read_lock_t *lock) { } static inline bool rcu_quiesce_allowed(void) { return true; @@ -88,15 +109,6 @@ struct rcu_head { int rcu_pending(int cpu); int rcu_needs_cpu(int cpu); -/* - * Dummy lock type for passing to rcu_read_{lock,unlock}. Currently exists - * only to document the reason for rcu_read_lock() critical sections. - */ -struct _rcu_read_lock {}; -typedef struct _rcu_read_lock rcu_read_lock_t; -#define DEFINE_RCU_READ_LOCK(x) rcu_read_lock_t x -#define RCU_READ_LOCK_INIT(x) - /** * rcu_read_lock - mark the beginning of an RCU read-side critical section. * @@ -125,7 +137,7 @@ typedef struct _rcu_read_lock rcu_read_lock_t; */ static inline void rcu_read_lock(rcu_read_lock_t *lock) { - rcu_quiesce_disable(); + rcu_quiesce_disable(lock); } /** @@ -136,7 +148,7 @@ static inline void rcu_read_lock(rcu_read_lock_t *lock) static inline void rcu_read_unlock(rcu_read_lock_t *lock) { ASSERT(!rcu_quiesce_allowed()); - rcu_quiesce_enable(); + rcu_quiesce_enable(lock); } /*