Skip to content

Commit 17b1bbe

Browse files
edumazetmehmetb0
authored andcommitted
inetpeer: update inetpeer timestamp in inet_getpeer()
BugLink: https://bugs.launchpad.net/bugs/2111953 [ Upstream commit 50b362f ] inet_putpeer() will be removed in the following patch, because we will no longer use refcounts. Update inetpeer timestamp (p->dtime) at lookup time. Signed-off-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20241215175629.1248773-4-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Stable-dep-of: a853c60 ("inetpeer: do not get a refcount in inet_getpeer()") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Mehmet Basaran <mehmet.basaran@canonical.com>
1 parent d2dc8ea commit 17b1bbe

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

net/ipv4/inetpeer.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static struct inet_peer *lookup(const struct inetpeer_addr *daddr,
9898
{
9999
struct rb_node **pp, *parent, *next;
100100
struct inet_peer *p;
101+
u32 now;
101102

102103
pp = &base->rb_root.rb_node;
103104
parent = NULL;
@@ -113,6 +114,9 @@ static struct inet_peer *lookup(const struct inetpeer_addr *daddr,
113114
if (cmp == 0) {
114115
if (!refcount_inc_not_zero(&p->refcnt))
115116
break;
117+
now = jiffies;
118+
if (READ_ONCE(p->dtime) != now)
119+
WRITE_ONCE(p->dtime, now);
116120
return p;
117121
}
118122
if (gc_stack) {
@@ -158,9 +162,6 @@ static void inet_peer_gc(struct inet_peer_base *base,
158162
for (i = 0; i < gc_cnt; i++) {
159163
p = gc_stack[i];
160164

161-
/* The READ_ONCE() pairs with the WRITE_ONCE()
162-
* in inet_putpeer()
163-
*/
164165
delta = (__u32)jiffies - READ_ONCE(p->dtime);
165166

166167
if (delta < ttl || !refcount_dec_if_one(&p->refcnt))
@@ -232,11 +233,6 @@ EXPORT_SYMBOL_GPL(inet_getpeer);
232233

233234
void inet_putpeer(struct inet_peer *p)
234235
{
235-
/* The WRITE_ONCE() pairs with itself (we run lockless)
236-
* and the READ_ONCE() in inet_peer_gc()
237-
*/
238-
WRITE_ONCE(p->dtime, (__u32)jiffies);
239-
240236
if (refcount_dec_and_test(&p->refcnt))
241237
call_rcu(&p->rcu, inetpeer_free_rcu);
242238
}

0 commit comments

Comments
 (0)