Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1576037ybt; Thu, 9 Jul 2020 10:09:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTVjYNAb17rp8eajQuGUdU3+WwqWroqjdilmBlJ2uwzPwbetbPQH2NOjvGBiqjwYbugoLb X-Received: by 2002:a05:6402:1d3a:: with SMTP id dh26mr54797555edb.349.1594314572280; Thu, 09 Jul 2020 10:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594314572; cv=none; d=google.com; s=arc-20160816; b=bRd2N6XmCC7gdwA9Ng7q4acbCh9TlHbZwuDKep/gLtV7glW7vAU+/K5Cs5GUUh789s TdHbDvQIJqGi4eVCAJBTVIzAnhuNa0idw1PskPrTrrVCwhmcMikD81QVh0rAEjjIv+K8 xFDppg1S4ogHatojl5x1ZBna2ugsvRBcYsUQ3fLIWd2wZPwDj53qofXwyZ3RdCflkKIj H2gvdWMg5zQWNMuBgWV/f3fABu49N+d5XNBJP38GtK1HB5vJk5bMQ4E1X3TSxG11GxiI lL6PGQ5b7M5lg/8EoV9FWIpbrpl/U6CnYpf96KJh9yWBXiZ2hfuej5OcxfrNEKk/n5Pm QgGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=dHcclfYYBKIHnSq5Q0GT/hqn8J1lxzpRSKLQ942O9vk=; b=snZeaJe/QrZCYkDJiPCZEFO58c82kmFvmidKxsw1hXHBu8le1qeXAFlMunrMHFfDh+ 81X3emyi7Rf5jH9kVcMsF58sHuUhPM6NPTZjedoB1llhdru+hn/z9fyAR9xsMCzU8c8k 59PTl9BGnOI7+/INyD2rhaPo2ret+/Th4AYNF0mqzsPhPwEnup3IyCwufySoX9sbfqOr Ess8bLaUyBSpC6j8tlvp3ySKVO0TpiDEqAvpipy+ZOUYFxx/JJCQtUW053D443o9xYmH lf/WFp77DAilVKf/wUWaceZRb4a7Tm0Lj2zU2Y1KYQUZNuevzisXDdsXstr3DqMtqC3c XJyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AToluhOG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z65si2265089ede.610.2020.07.09.10.09.07; Thu, 09 Jul 2020 10:09:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AToluhOG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727074AbgGIRG0 (ORCPT + 99 others); Thu, 9 Jul 2020 13:06:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726615AbgGIRG0 (ORCPT ); Thu, 9 Jul 2020 13:06:26 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7ABDC08C5CE; Thu, 9 Jul 2020 10:06:25 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id e8so1240232pgc.5; Thu, 09 Jul 2020 10:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=dHcclfYYBKIHnSq5Q0GT/hqn8J1lxzpRSKLQ942O9vk=; b=AToluhOGiT9776vm4oXRGg9NB5hy0sUFBt2Ho/l3PSRaKfHAcwd1/lTaKYNUn1x4nv LRe5AomMs20Vjo7IMeYcsmK4kZMbmqB6PRxBHfJa/nNE/JcixTLSc2S5FQRJQbi4CxVN bZ8a64mRM+VxdezDuASQX1rFQa2ReYdWF6XJXqkMTGS64cD9TuU3OStcl9p0aMIikHSz /N1RyLDHIwPGj4Mq+vxD+XZVSgU+ZpWCFXKVtgxcz6vCwN2yTgb84x9ytJLliZk8qnEA pzvHwwDTKRh7PRaAS6CiCMj4sczp4smqCs6b50IiG/FRhrCjHzYvEczZiuDQxR8DxGEI 9OOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=dHcclfYYBKIHnSq5Q0GT/hqn8J1lxzpRSKLQ942O9vk=; b=rjbCntYVSMMA6y2NWMpdCkce3XdhjkZMGgSDBD0cQkdJcYGNY2rT2QVtPVF2FAUSSp sK36YzDxAz0IutZlWNCApdugBmT7sQmSEFCIexOX56TQojgetISO46ECx7Bb132ZSyco N2CgfRN8gJCN5JCBby8xfJVNgnj/ZotcqlrYkQ16kpv57BA28sMfma8on+1bc/Ws36T5 nU2ABQYkjaOLrZqiQvgSzYk48BIBZil6bTaNAzdyHAeLs5xSjbFJsfpebJxexf1l5XbO bNSPglsuHRhfxSUtRXMdTpPVecogBlNfhebqS4jbo8xJ6kWnSy9GEUjnSyChlf6napkA 2AqQ== X-Gm-Message-State: AOAM532Ik+CtWBCUBcd1t5gE5UJifAoE8bsyV+B4HOTFHZ4kBjDPnQGx d6SIprP29nX9A90PpnGVgQ== X-Received: by 2002:a63:5b63:: with SMTP id l35mr53811605pgm.34.1594314385452; Thu, 09 Jul 2020 10:06:25 -0700 (PDT) Received: from madhuparna-HP-Notebook ([2402:3a80:cfe:de9d:4919:edd3:5dbd:ffec]) by smtp.gmail.com with ESMTPSA id i13sm3229973pjd.33.2020.07.09.10.06.21 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Jul 2020 10:06:24 -0700 (PDT) From: Madhuparna Bhowmik X-Google-Original-From: Madhuparna Bhowmik Date: Thu, 9 Jul 2020 22:36:18 +0530 To: joel@joelfernandes.org Cc: madhuparnabhowmik10@gmail.com, paulmck@kernel.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, frextrite@gmail.com Subject: Re: [PATCH] rculist : Introduce list/hlist_for_each_entry_srcu() macros Message-ID: <20200709170617.GA19062@madhuparna-HP-Notebook> References: <20200703140828.7016-1-madhuparnabhowmik10@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 08, 2020 at 08:33:49AM -0400, joel@joelfernandes.org wrote: > > > On July 3, 2020 10:08:28 AM EDT, madhuparnabhowmik10@gmail.com wrote: > >From: Madhuparna Bhowmik > > > >list/hlist_for_each_entry_rcu() provides an optional cond argument > >to specify the lock held in the updater side. > >However for SRCU read side, not providing the cond argument results > >into false positive as whether srcu_read_lock is held or not is not > >checked implicitly. Therefore, on read side the lockdep expression > >srcu_read_lock_held(srcu struct) can solve this issue. > > > >However, the function still fails to check the cases where srcu > >protected list is traversed with rcu_read_lock() instead of > >srcu_read_lock(). Therefore, to remove the false negative, > >this patch introduces two new list traversal primitives : > >list_for_each_entry_srcu() and hlist_for_each_entry_srcu(). > > > >Both of the functions have non-optional cond argument > >as it is required for both read and update side, and simply checks > >if the cond is true. > > Looks ok to me. Could you update the comment below to also clarify that in regular read side usage, the traversal can be done by also passing the expression srcu_read_lock_held which is also a lockdep expression. > > Could you post the user-patches along with it? That gives more context to reviewers. > Thank you for reviewing the patch, I will make the changes suggested and send the patch along with the user patches. Regards, Madhuparna > Thanks! > > - Joel > > > > > >Suggested-by: Paolo Bonzini > >Signed-off-by: Madhuparna Bhowmik > >--- > > include/linux/rculist.h | 44 +++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 44 insertions(+) > > > >diff --git a/include/linux/rculist.h b/include/linux/rculist.h > >index df587d181844..04a7e5791c39 100644 > >--- a/include/linux/rculist.h > >+++ b/include/linux/rculist.h > >@@ -63,9 +63,17 @@ static inline void INIT_LIST_HEAD_RCU(struct > >list_head *list) > > RCU_LOCKDEP_WARN(!(cond) && !rcu_read_lock_any_held(), \ > > "RCU-list traversed in non-reader section!"); \ > > }) > >+ > >+#define __list_check_srcu(cond) \ > >+ ({ \ > >+ RCU_LOCKDEP_WARN(!(cond), \ > >+ "RCU-list traversed without holding the required lock!");\ > >+ }) > > #else > > #define __list_check_rcu(dummy, cond, extra...) \ > > ({ check_arg_count_one(extra); }) > >+ > >+#define __list_check_srcu(cond) > > #endif > > > > /* > >@@ -383,6 +391,23 @@ static inline void > >list_splice_tail_init_rcu(struct list_head *list, > > &pos->member != (head); \ > > pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) > > > >+/** > >+ * list_for_each_entry_srcu - iterate over rcu list of given type > >+ * @pos: the type * to use as a loop cursor. > >+ * @head: the head for your list. > >+ * @member: the name of the list_head within the struct. > >+ * @cond: lockdep expression for the lock required to traverse the > >list. > >+ * > >+ * This list-traversal primitive may safely run concurrently with > >+ * the _rcu list-mutation primitives such as list_add_rcu() > >+ * as long as the traversal is guarded by srcu_read_lock(). > >+ */ > >+#define list_for_each_entry_srcu(pos, head, member, cond) \ > >+ for (__list_check_srcu(cond), \ > >+ pos = list_entry_rcu((head)->next, typeof(*pos), member); \ > >+ &pos->member != (head); \ > >+ pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) > >+ > > /** > > * list_entry_lockless - get the struct for this entry > > * @ptr: the &struct list_head pointer. > >@@ -681,6 +706,25 @@ static inline void hlist_add_behind_rcu(struct > >hlist_node *n, > > pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(\ > > &(pos)->member)), typeof(*(pos)), member)) > > > >+/** > >+ * hlist_for_each_entry_srcu - iterate over rcu list of given type > >+ * @pos: the type * to use as a loop cursor. > >+ * @head: the head for your list. > >+ * @member: the name of the hlist_node within the struct. > >+ * @cond: lockdep expression for the lock required to traverse the > >list. > >+ * > >+ * This list-traversal primitive may safely run concurrently with > >+ * the _rcu list-mutation primitives such as hlist_add_head_rcu() > >+ * as long as the traversal is guarded by srcu_read_lock(). > >+ */ > >+#define hlist_for_each_entry_srcu(pos, head, member, cond) \ > >+ for (__list_check_srcu(cond), \ > >+ pos = > >hlist_entry_safe(rcu_dereference_raw(hlist_first_rcu(head)),\ > >+ typeof(*(pos)), member); \ > >+ pos; \ > >+ pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(\ > >+ &(pos)->member)), typeof(*(pos)), member)) > >+ > > /** > >* hlist_for_each_entry_rcu_notrace - iterate over rcu list of given > >type (for tracing) > > * @pos: the type * to use as a loop cursor. > > -- > Sent from my Android device with K-9 Mail. Please excuse my brevity.