mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: madhuparnabhowmik04@gmail.com
To: paulmck@kernel.org, rostedt@goodmis.org, joel@joelfernandes.org
Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	Madhuparna Bhowmik <madhuparnabhowmik04@gmail.com>
Subject: [PATCH] rculist: Add macro list_prev_rcu
Date: Fri,  6 Dec 2019 20:35:54 +0530	[thread overview]
Message-ID: <20191206150554.10479-1-madhuparnabhowmik04@gmail.com> (raw)

From: Madhuparna Bhowmik <madhuparnabhowmik04@gmail.com>

There are instances in the linux kernel where the prev pointer
of a list is accessed.
Unlike list_next_rcu, a similar macro for accessing the prev
pointer was not present.
Therefore, directly accessing the prev pointer was causing
sparse errors.
One such example is the sparse error in fs/nfs/dir.c

error:
fs/nfs/dir.c:2353:14: error: incompatible types in comparison expression (different address spaces):
fs/nfs/dir.c:2353:14:    struct list_head [noderef] <asn:4> *
fs/nfs/dir.c:2353:14:    struct list_head *

The error is caused due to the following line:

lh = rcu_dereference(nfsi->access_cache_entry_lru.prev);

After adding the macro, this error can be fixed as follows:

lh = rcu_dereference(list_prev_rcu(&nfsi->access_cache_entry_lru));

Therefore, we think there is a need to add this macro to rculist.h.

Suggested-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik04@gmail.com>
---
 include/linux/rculist.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index 4b7ae1bf50b3..49eef8437753 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -40,6 +40,12 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
  */
 #define list_next_rcu(list)	(*((struct list_head __rcu **)(&(list)->next)))
 
+/*
+ * return the prev pointer of a list_head in an rcu safe
+ * way, we must not access it directly
+ */
+#define list_prev_rcu(list)	(*((struct list_head __rcu **)(&(list)->prev)))
+
 /*
  * Check during list traversal that we are within an RCU reader
  */
-- 
2.17.1


             reply	other threads:[~2019-12-06 15:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-06 15:05 madhuparnabhowmik04 [this message]
2019-12-06 15:32 ` Paul E. McKenney
2019-12-06 15:58   ` Joel Fernandes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191206150554.10479-1-madhuparnabhowmik04@gmail.com \
    --to=madhuparnabhowmik04@gmail.com \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®