netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: dhowells@redhat.com, davem@davemloft.net, netdev@vger.kernel.org,
	linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 19/19] rxrpc: Use RCU to access a peer's service connection tree
Date: Thu, 30 Jun 2016 17:36:51 +0100	[thread overview]
Message-ID: <587.1467304611@warthog.procyon.org.uk> (raw)
In-Reply-To: <19436.1467303739@warthog.procyon.org.uk>

David Howells <dhowells@redhat.com> wrote:

> > You want rb_link_node_rcu() here.
> 
> Should there be an rb_replace_node_rcu() also?

Or I could make rb_replace_node() RCU friendly.  What do you think of the
attached changes (split into appropriate patches)?  It's a case of changing
the order in which pointers are set in the rbtree code and inserting a
barrier.

I also wonder if rb_insert_color() needs some attention - though possibly
that's okay as it doesn't start with unset pointers (since you call
rb_link_node_rcu() first).

David
---
diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
index 14d7b831b63a..d076183e49be 100644
--- a/include/linux/rbtree_augmented.h
+++ b/include/linux/rbtree_augmented.h
@@ -130,6 +130,19 @@ __rb_change_child(struct rb_node *old, struct rb_node *new,
 		WRITE_ONCE(root->rb_node, new);
 }
 
+static inline void
+__rb_change_child_rcu(struct rb_node *old, struct rb_node *new,
+		      struct rb_node *parent, struct rb_root *root)
+{
+	if (parent) {
+		if (parent->rb_left == old)
+			rcu_assign_pointer(parent->rb_left, new);
+		else
+			rcu_assign_pointer(parent->rb_right, new);
+	} else
+		rcu_assign_pointer(root->rb_node, new);
+}
+
 extern void __rb_erase_color(struct rb_node *parent, struct rb_root *root,
 	void (*augment_rotate)(struct rb_node *old, struct rb_node *new));
 
diff --git a/lib/rbtree.c b/lib/rbtree.c
index 1356454e36de..2b1a190c737c 100644
--- a/lib/rbtree.c
+++ b/lib/rbtree.c
@@ -539,15 +539,17 @@ void rb_replace_node(struct rb_node *victim, struct rb_node *new,
 {
 	struct rb_node *parent = rb_parent(victim);
 
+	/* Copy the pointers/colour from the victim to the replacement */
+	*new = *victim;
+
 	/* Set the surrounding nodes to point to the replacement */
-	__rb_change_child(victim, new, parent, root);
 	if (victim->rb_left)
 		rb_set_parent(victim->rb_left, new);
 	if (victim->rb_right)
 		rb_set_parent(victim->rb_right, new);
 
-	/* Copy the pointers/colour from the victim to the replacement */
-	*new = *victim;
+	/* Set the onward pointer last with an RCU barrier */
+	__rb_change_child_rcu(victim, new, parent, root);
 }
 EXPORT_SYMBOL(rb_replace_node);
 
diff --git a/net/rxrpc/conn_service.c b/net/rxrpc/conn_service.c
index dc64211c5ee8..298ec300cfcc 100644
--- a/net/rxrpc/conn_service.c
+++ b/net/rxrpc/conn_service.c
@@ -41,14 +41,14 @@ struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *peer,
 		 */
 		read_seqbegin_or_lock(&peer->service_conn_lock, &seq);
 
-		p = peer->service_conns.rb_node;
+		p = rcu_dereference(peer->service_conns.rb_node);
 		while (p) {
 			conn = rb_entry(p, struct rxrpc_connection, service_node);
 
 			if (conn->proto.index_key < k.index_key)
-				p = p->rb_left;
+				p = rcu_dereference(p->rb_left);
 			else if (conn->proto.index_key > k.index_key)
-				p = p->rb_right;
+				p = rcu_dereference(p->rb_right);
 			else
 				goto done;
 			conn = NULL;
@@ -90,7 +90,7 @@ rxrpc_publish_service_conn(struct rxrpc_peer *peer,
 			goto found_extant_conn;
 	}
 
-	rb_link_node(&conn->service_node, parent, pp);
+	rb_link_node_rcu(&conn->service_node, parent, pp);
 	rb_insert_color(&conn->service_node, &peer->service_conns);
 conn_published:
 	set_bit(RXRPC_CONN_IN_SERVICE_CONNS, &conn->flags);

  parent reply	other threads:[~2016-06-30 16:46 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-30 14:10 [PATCH net-next 00/19] rxrpc: Improve conn/call lookup and fix call number generation David Howells
2016-06-30 14:10 ` [PATCH net-next 01/19] rxrpc: Check the source of a packet to a client conn David Howells
2016-06-30 14:10 ` [PATCH net-next 02/19] rxrpc: Avoid using stack memory in SG lists in rxkad David Howells
2016-06-30 14:11 ` [PATCH net-next 03/19] rxrpc: Provide more refcount helper functions David Howells
2016-06-30 14:11 ` [PATCH net-next 04/19] rxrpc: Dup the main conn list for the proc interface David Howells
2016-06-30 14:11 ` [PATCH net-next 05/19] rxrpc: Turn connection #defines into enums and put outside struct def David Howells
2016-06-30 14:11 ` [PATCH net-next 06/19] rxrpc: Check that the client conns cache is empty before module removal David Howells
2016-06-30 14:11 ` [PATCH net-next 07/19] rxrpc: Move usage count getting into rxrpc_queue_conn() David Howells
2016-06-30 14:11 ` [PATCH net-next 08/19] rxrpc: Fix handling of connection failure in client call creation David Howells
2016-06-30 14:11 ` [PATCH net-next 09/19] rxrpc: Release a call's connection ref on call disconnection David Howells
2016-06-30 14:11 ` [PATCH net-next 10/19] rxrpc: Add RCU destruction for connections and calls David Howells
2016-06-30 14:12 ` [PATCH net-next 11/19] rxrpc: Access socket accept queue under right lock David Howells
2016-06-30 14:12 ` [PATCH net-next 12/19] rxrpc: Call channels should have separate call number spaces David Howells
2016-06-30 14:12 ` [PATCH net-next 13/19] rxrpc: Split client connection code out into its own file David Howells
2016-06-30 14:12 ` [PATCH net-next 14/19] rxrpc: Split service " David Howells
2016-06-30 14:12 ` [PATCH net-next 15/19] rxrpc: Move peer lookup from call-accept to new-incoming-conn David Howells
2016-06-30 14:12 ` [PATCH net-next 16/19] rxrpc: Maintain an extra ref on a conn for the cache list David Howells
2016-06-30 14:12 ` [PATCH net-next 17/19] rxrpc: Prune the contents of the rxrpc_conn_proto struct David Howells
2016-06-30 14:12 ` [PATCH net-next 18/19] rxrpc: Move data_ready peer lookup into rxrpc_find_connection() David Howells
2016-06-30 14:12 ` [PATCH net-next 19/19] rxrpc: Use RCU to access a peer's service connection tree David Howells
2016-06-30 15:30   ` Peter Zijlstra
2016-06-30 16:22   ` David Howells
2016-06-30 16:36   ` David Howells [this message]
2016-06-30 20:19     ` Peter Zijlstra
2016-06-30 14:22 ` [PATCH net-next 00/19] rxrpc: Improve conn/call lookup and fix call number generation David Howells

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=587.1467304611@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=davem@davemloft.net \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).