From: Stephen Hemminger <shemminger@vyatta•com>
To: Alexander Viro <viro@zeniv•linux.org.uk>,
Andrew Morton <akpm@linux-foundation•org>,
Rusty Russell <rusty@rustcorp•com.au>,
Peter Oberparleiter <oberpar@linux•vnet.ibm.com>,
Miklos S
Cc: netdev@vger•kernel.org
Subject: [PATCH 1/3] seq_file: add RCU versions of new hlist/list iterators (v3)
Date: Fri, 19 Feb 2010 13:59:14 -0800 [thread overview]
Message-ID: <20100219220111.692855800@vyatta.com> (raw)
In-Reply-To: 20100219215913.819285957@vyatta.com
[-- Attachment #1: seq_hlist_rcu.patch --]
[-- Type: text/plain, Size: 3528 bytes --]
Many usages of seq_file use RCU protected lists, so non RCU
iterators will not work safely.
Signed-off-by: Stephen Hemminger <shemminger@vyatta•com>
---
This version drops the list_rcu variants because not needed yet
fs/seq_file.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++
include/linux/rculist.h | 5 ++++
include/linux/seq_file.h | 12 +++++++---
3 files changed, 70 insertions(+), 3 deletions(-)
--- a/fs/seq_file.c 2010-02-18 21:46:46.978333060 -0800
+++ b/fs/seq_file.c 2010-02-19 11:22:30.540260974 -0800
@@ -750,3 +750,59 @@ struct hlist_node *seq_hlist_next(void *
return node->next;
}
EXPORT_SYMBOL(seq_hlist_next);
+
+/**
+ * seq_hlist_start_rcu - start an iteration of a hlist protected by RCU
+ * @head: the head of the hlist
+ * @pos: the start position of the sequence
+ *
+ * Called at seq_file->op->start().
+ */
+struct hlist_node *seq_hlist_start_rcu(struct hlist_head *head, loff_t pos)
+{
+ struct hlist_node *node;
+
+ __hlist_for_each_rcu(node, head)
+ if (pos-- == 0)
+ return node;
+ return NULL;
+}
+EXPORT_SYMBOL(seq_hlist_start_rcu);
+
+/**
+ * seq_hlist_start_head_rcu - start an iteration of a hlist protected by RCU
+ * @head: the head of the hlist
+ * @pos: the start position of the sequence
+ *
+ * Called at seq_file->op->start(). Call this function if you want to
+ * print a header at the top of the output.
+ */
+struct hlist_node *seq_hlist_start_head_rcu(struct hlist_head *head, loff_t pos)
+{
+ if (!pos)
+ return SEQ_START_TOKEN;
+
+ return seq_hlist_start_rcu(head, pos - 1);
+}
+EXPORT_SYMBOL(seq_hlist_start_head_rcu);
+
+/**
+ * seq_hlist_next_rcu - move to the next position of the hlist protected by RCU
+ * @v: the current iterator
+ * @head: the head of the hlist
+ * @pos: the current posision
+ *
+ * Called at seq_file->op->next().
+ */
+struct hlist_node *seq_hlist_next_rcu(void *v, struct hlist_head *head,
+ loff_t *ppos)
+{
+ struct hlist_node *node = v;
+
+ ++*ppos;
+ if (v == SEQ_START_TOKEN)
+ return rcu_dereference(head->first);
+ else
+ return rcu_dereference(node->next);
+}
+EXPORT_SYMBOL(seq_hlist_next_rcu);
--- a/include/linux/seq_file.h 2010-02-18 21:46:47.014333155 -0800
+++ b/include/linux/seq_file.h 2010-02-19 11:24:42.356546569 -0800
@@ -140,10 +140,16 @@ extern struct list_head *seq_list_next(v
*/
extern struct hlist_node *seq_hlist_start(struct hlist_head *head,
- loff_t pos);
+ loff_t pos);
extern struct hlist_node *seq_hlist_start_head(struct hlist_head *head,
- loff_t pos);
+ loff_t pos);
extern struct hlist_node *seq_hlist_next(void *v, struct hlist_head *head,
- loff_t *ppos);
+ loff_t *ppos);
+extern struct hlist_node *seq_hlist_start_rcu(struct hlist_head *head,
+ loff_t pos);
+extern struct hlist_node *seq_hlist_start_head_rcu(struct hlist_head *head,
+ loff_t pos);
+extern struct hlist_node *seq_hlist_next_rcu(void *v, struct hlist_head *head,
+ loff_t *ppos);
#endif
--- a/include/linux/rculist.h 2010-02-18 21:46:46.998211692 -0800
+++ b/include/linux/rculist.h 2010-02-19 11:21:32.880295586 -0800
@@ -406,6 +406,11 @@ static inline void hlist_add_after_rcu(s
n->next->pprev = &n->next;
}
+#define __hlist_for_each_rcu(pos, head) \
+ for (pos = rcu_dereference((head)->first); \
+ pos && ({ prefetch(pos->next); 1; }); \
+ pos = rcu_dereference(pos->next))
+
/**
* hlist_for_each_entry_rcu - iterate over rcu list of given type
* @tpos: the type * to use as a loop cursor.
--
next prev parent reply other threads:[~2010-02-19 22:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-19 21:59 [PATCH 0/3] Convert packet and key sockets to RCU Stephen Hemminger
2010-02-19 21:59 ` Stephen Hemminger [this message]
2010-02-19 22:22 ` [PATCH 1/3] seq_file: add RCU versions of new hlist/list iterators (v3) Al Viro
2010-02-19 21:59 ` [PATCH 2/3] packet: convert socket list to RCU (v2) Stephen Hemminger
2010-02-19 22:23 ` [PATCH] packet: convert socket list to RCU (v3) Stephen Hemminger
2010-02-20 3:39 ` Eric Dumazet
2010-02-19 21:59 ` [PATCH 3/3] af_key: locking change Stephen Hemminger
2010-02-20 4:07 ` Eric Dumazet
2010-02-20 5:53 ` Stephen Hemminger
2010-02-20 20:51 ` David Miller
[not found] <20100222175716.900955428@vyatta.com>
2010-02-22 17:57 ` [PATCH 1/3] seq_file: add RCU versions of new hlist/list iterators (v3) Stephen Hemminger
2010-02-22 23:46 ` David Miller
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=20100219220111.692855800@vyatta.com \
--to=shemminger@vyatta$(echo .)com \
--cc=akpm@linux-foundation$(echo .)org \
--cc=netdev@vger$(echo .)kernel.org \
--cc=oberpar@linux$(echo .)vnet.ibm.com \
--cc=rusty@rustcorp$(echo .)com.au \
--cc=viro@zeniv$(echo .)linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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