Skip to content

Commit d24406c

Browse files
tracywwnjdavem330
authored andcommitted
udp: call dst_hold_safe() in udp_sk_rx_set_dst()
In udp_v4/6_early_demux() code, we try to hold dst->__refcnt for dst with DST_NOCACHE flag. This is because later in udp_sk_rx_dst_set() function, we will try to cache this dst in sk for connected case. However, a better way to achieve this is to not try to hold dst in early_demux(), but in udp_sk_rx_dst_set(), call dst_hold_safe(). This approach is also more consistant with how tcp is handling it. And it will make later changes simpler. Signed-off-by: Wei Wang <weiwan@google.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1758fd4 commit d24406c

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

net/ipv4/udp.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,9 +1977,10 @@ static void udp_sk_rx_dst_set(struct sock *sk, struct dst_entry *dst)
19771977
{
19781978
struct dst_entry *old;
19791979

1980-
dst_hold(dst);
1981-
old = xchg(&sk->sk_rx_dst, dst);
1982-
dst_release(old);
1980+
if (dst_hold_safe(dst)) {
1981+
old = xchg(&sk->sk_rx_dst, dst);
1982+
dst_release(old);
1983+
}
19831984
}
19841985

19851986
/*
@@ -2303,13 +2304,11 @@ void udp_v4_early_demux(struct sk_buff *skb)
23032304
if (dst)
23042305
dst = dst_check(dst, 0);
23052306
if (dst) {
2306-
/* DST_NOCACHE can not be used without taking a reference */
2307-
if (dst->flags & DST_NOCACHE) {
2308-
if (likely(atomic_inc_not_zero(&dst->__refcnt)))
2309-
skb_dst_set(skb, dst);
2310-
} else {
2311-
skb_dst_set_noref(skb, dst);
2312-
}
2307+
/* set noref for now.
2308+
* any place which wants to hold dst has to call
2309+
* dst_hold_safe()
2310+
*/
2311+
skb_dst_set_noref(skb, dst);
23132312
}
23142313
}
23152314

net/ipv6/udp.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -920,12 +920,11 @@ static void udp_v6_early_demux(struct sk_buff *skb)
920920
if (dst)
921921
dst = dst_check(dst, inet6_sk(sk)->rx_dst_cookie);
922922
if (dst) {
923-
if (dst->flags & DST_NOCACHE) {
924-
if (likely(atomic_inc_not_zero(&dst->__refcnt)))
925-
skb_dst_set(skb, dst);
926-
} else {
927-
skb_dst_set_noref(skb, dst);
928-
}
923+
/* set noref for now.
924+
* any place which wants to hold dst has to call
925+
* dst_hold_safe()
926+
*/
927+
skb_dst_set_noref(skb, dst);
929928
}
930929
}
931930

0 commit comments

Comments
 (0)