diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-06-16 00:47:39 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-06-16 00:47:39 -0400 |
commit | 5f2f89209500623ccb4713ec4af7de86fd30a9e4 (patch) | |
tree | 6a48b8183ac6d60d8ce6a9c907de1ea35c1ca918 /net/ipv4/inetpeer.c | |
parent | d5f31fbfd8fa3836a918592032853c41d1797c3d (diff) |
inetpeer: do not use zero refcnt for freed entries
Followup of commit aa1039e73cc2 (inetpeer: RCU conversion)
Unused inet_peer entries have a null refcnt.
Using atomic_inc_not_zero() in rcu lookups is not going to work for
them, and slow path is taken.
Fix this using -1 marker instead of 0 for deleted entries.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/inetpeer.c')
-rw-r--r-- | net/ipv4/inetpeer.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c index 58fbc7e2475e..349249fad2db 100644 --- a/net/ipv4/inetpeer.c +++ b/net/ipv4/inetpeer.c | |||
@@ -187,7 +187,12 @@ static struct inet_peer *lookup_rcu_bh(__be32 daddr) | |||
187 | 187 | ||
188 | while (u != peer_avl_empty) { | 188 | while (u != peer_avl_empty) { |
189 | if (daddr == u->v4daddr) { | 189 | if (daddr == u->v4daddr) { |
190 | if (unlikely(!atomic_inc_not_zero(&u->refcnt))) | 190 | /* Before taking a reference, check if this entry was |
191 | * deleted, unlink_from_pool() sets refcnt=-1 to make | ||
192 | * distinction between an unused entry (refcnt=0) and | ||
193 | * a freed one. | ||
194 | */ | ||
195 | if (unlikely(!atomic_add_unless(&u->refcnt, 1, -1))) | ||
191 | u = NULL; | 196 | u = NULL; |
192 | return u; | 197 | return u; |
193 | } | 198 | } |
@@ -322,8 +327,9 @@ static void unlink_from_pool(struct inet_peer *p) | |||
322 | * in cleanup() function to prevent sudden disappearing. If we can | 327 | * in cleanup() function to prevent sudden disappearing. If we can |
323 | * atomically (because of lockless readers) take this last reference, | 328 | * atomically (because of lockless readers) take this last reference, |
324 | * it's safe to remove the node and free it later. | 329 | * it's safe to remove the node and free it later. |
330 | * We use refcnt=-1 to alert lockless readers this entry is deleted. | ||
325 | */ | 331 | */ |
326 | if (atomic_cmpxchg(&p->refcnt, 1, 0) == 1) { | 332 | if (atomic_cmpxchg(&p->refcnt, 1, -1) == 1) { |
327 | struct inet_peer **stack[PEER_MAXDEPTH]; | 333 | struct inet_peer **stack[PEER_MAXDEPTH]; |
328 | struct inet_peer ***stackptr, ***delp; | 334 | struct inet_peer ***stackptr, ***delp; |
329 | if (lookup(p->v4daddr, stack) != p) | 335 | if (lookup(p->v4daddr, stack) != p) |