Skip to contentSkip to conversation

inetpeer: Don't disable BH for initial fast RCU lookup.

PATCH In review David Miller 2 participants 5 messages Mar 8, 2011 – Mar 14, 2011

Subsystems (3)
lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

PATCH 1/1 inetpeer: Don't disable BH for initial fast RCU lookup.

If modifications on other cpus are ok, then modifications to the tree during lookup done by the local cpu are ok too.

---
 net/ipv4/inetpeer.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
net/ipv4/inetpeer.c +9 -9
index f604ffd..6442c35 100644
@@ -206,16 +206,16 @@ static int addr_compare(const struct inetpeer_addr *a,
 })
 
 /*
- * Called with rcu_read_lock_bh()
+ * Called with rcu_read_lock()
  * Because we hold no lock against a writer, its quite possible we fall
  * in an endless loop.
  * But every pointer we follow is guaranteed to be valid thanks to RCU.
  * We exit from this function if number of links exceeds PEER_MAXDEPTH
  */
-static struct inet_peer *lookup_rcu_bh(const struct inetpeer_addr *daddr,
-				       struct inet_peer_base *base)
+static struct inet_peer *lookup_rcu(const struct inetpeer_addr *daddr,
+				    struct inet_peer_base *base)
 {
-	struct inet_peer *u = rcu_dereference_bh(base->root);
+	struct inet_peer *u = rcu_dereference(base->root);
 	int count = 0;
 
 	while (u != peer_avl_empty) {
@@ -231,9 +231,9 @@ static struct inet_peer *lookup_rcu_bh(const struct inetpeer_addr *daddr,
 			return u;
 		}
 		if (cmp == -1)
-			u = rcu_dereference_bh(u->avl_left);
+			u = rcu_dereference(u->avl_left);
 		else
-			u = rcu_dereference_bh(u->avl_right);
+			u = rcu_dereference(u->avl_right);
 		if (unlikely(++count == PEER_MAXDEPTH))
 			break;
 	}
@@ -470,11 +470,11 @@ struct inet_peer *inet_getpeer(struct inetpeer_addr *daddr, int create)
 	/* Look up for the address quickly, lockless.
 	 * Because of a concurrent writer, we might not find an existing entry.
 	 */
-	rcu_read_lock_bh();
+	rcu_read_lock();
 	sequence = read_seqbegin(&base->lock);
-	p = lookup_rcu_bh(daddr, base);
+	p = lookup_rcu(daddr, base);
 	invalidated = read_seqretry(&base->lock, sequence);
-	rcu_read_unlock_bh();
+	rcu_read_unlock();
 
 	if (p) {
 		/* The existing node has been found.
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 50 lines · David Miller

If modifications on other cpus are ok, then modifications to the tree during lookup done by the local cpu are ok too.

---
 net/ipv4/inetpeer.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
net/ipv4/inetpeer.c +6 -7
index f604ffd..6442c35 100644
@@ -206,16 +206,16 @@ static int addr_compare(const struct inetpeer_addr *a,
 })
 
 /*
- * Called with rcu_read_lock_bh()
+ * Called with rcu_read_lock()
  * Because we hold no lock against a writer, its quite possible we fall
  * in an endless loop.
  * But every pointer we follow is guaranteed to be valid thanks to RCU.
  * We exit from this function if number of links exceeds PEER_MAXDEPTH
  */
-static struct inet_peer *lookup_rcu_bh(const struct inetpeer_addr *daddr,
-				       struct inet_peer_base *base)
+static struct inet_peer *lookup_rcu(const struct inetpeer_addr *daddr,
+				    struct inet_peer_base *base)
 {
-	struct inet_peer *u = rcu_dereference_bh(base->root);
+	struct inet_peer *u = rcu_dereference(base->root);
 	int count = 0;
 
 	while (u != peer_avl_empty) {
@@ -231,9 +231,9 @@ static struct inet_peer *lookup_rcu_bh(const struct inetpeer_addr *daddr,
 			return u;
 		}
 		if (cmp == -1)
-			u = rcu_dereference_bh(u->avl_left);
+			u = rcu_dereference(u->avl_left);
 		else
-			u = rcu_dereference_bh(u->avl_right);
+			u = rcu_dereference(u->avl_right);
 		if (unlikely(++count == PEER_MAXDEPTH))
 			break;
 	}
@@ -470,11 +470,11 @@ struct inet_peer *inet_getpeer(struct inetpeer_addr *daddr, int create)
 	/* Look up for the address quickly, lockless.
 	 * Because of a concurrent writer, we might not find an existing entry.
 	 */
-	rcu_read_lock_bh();

net/ipv4/inetpeer.c struct inet_peer *inet_getpeer(struct inetpeer_addr *daddr, int create) · line 480

Quoted 10 lines
net/ipv4/inetpeer.c +3 -2
+	rcu_read_lock();
 	sequence = read_seqbegin(&base->lock);
-	p = lookup_rcu_bh(daddr, base);
+	p = lookup_rcu(daddr, base);
 	invalidated = read_seqretry(&base->lock, sequence);
-	rcu_read_unlock_bh();
+	rcu_read_unlock();
 
 	if (p) {
 		/* The existing node has been found.

David, I am not sure this is safe, since we use call_rcu_bh() when freeing one item. One cpu could decide to kfree() one item while another cpu could still use it.

rcu_read_lock_bh() was signalling to others cpu we were in a softirq section, so we were delaying a possible kfree().

author maintainer
#2 lore raw

From: Eric Dumazet <[email protected]>
Date: Sun, 13 Mar 2011 11:04:09 +0100

Quoted 6 lines

David, I am not sure this is safe, since we use call_rcu_bh() when freeing one item. One cpu could decide to kfree() one item while another cpu could still use it.

rcu_read_lock_bh() was signalling to others cpu we were in a softirq section, so we were delaying a possible kfree().

Ok, could we use normal call_rcu() to solve this then?

#3 lore raw

PATCH 1/1 inetpeer: should use call_rcu() variant

Quoted 11 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Sun, 13 Mar 2011 11:04:09 +0100

Quoted 6 lines

David, I am not sure this is safe, since we use call_rcu_bh() when freeing one item. One cpu could decide to kfree() one item while another cpu could still use it.

rcu_read_lock_bh() was signalling to others cpu we were in a softirq section, so we were delaying a possible kfree().

Ok, could we use normal call_rcu() to solve this then?

Yes, this should be good.

Thanks

[PATCH net-next-2.6] inetpeer: should use call_rcu() variant

After commit 7b46ac4e77f3224a (inetpeer: Don't disable BH for initial fast RCU lookup.), we should use call_rcu() to wait proper RCU grace period.

---
 net/ipv4/inetpeer.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/inetpeer.c +1 -1
index 86b1d08..dd1b20e 100644
@@ -399,7 +399,7 @@ static void unlink_from_pool(struct inet_peer *p, struct inet_peer_base *base)
 	write_sequnlock_bh(&base->lock);
 
 	if (do_free)
-		call_rcu_bh(&p->rcu, inetpeer_free_rcu);
+		call_rcu(&p->rcu, inetpeer_free_rcu);
 	else
 		/* The node is used again.  Decrease the reference counter
 		 * back.  The loop "cleanup -> unlink_from_unused
author maintainer Applied
#4 lore raw

Re: [PATCH net-next-2.6] inetpeer: should use call_rcu() variant

From: Eric Dumazet <[email protected]>
Date: Mon, 14 Mar 2011 05:15:31 +0100

Quoted 7 lines

[PATCH net-next-2.6] inetpeer: should use call_rcu() variant

After commit 7b46ac4e77f3224a (inetpeer: Don't disable BH for initial fast RCU lookup.), we should use call_rcu() to wait proper RCU grace period.

Applied, thanks a lot Eric.