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>zero-colors
parent
1758fd4688
commit
d24406c85d
|
@ -1977,9 +1977,10 @@ static void udp_sk_rx_dst_set(struct sock *sk, struct dst_entry *dst)
|
||||||
{
|
{
|
||||||
struct dst_entry *old;
|
struct dst_entry *old;
|
||||||
|
|
||||||
dst_hold(dst);
|
if (dst_hold_safe(dst)) {
|
||||||
old = xchg(&sk->sk_rx_dst, dst);
|
old = xchg(&sk->sk_rx_dst, dst);
|
||||||
dst_release(old);
|
dst_release(old);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2303,13 +2304,11 @@ void udp_v4_early_demux(struct sk_buff *skb)
|
||||||
if (dst)
|
if (dst)
|
||||||
dst = dst_check(dst, 0);
|
dst = dst_check(dst, 0);
|
||||||
if (dst) {
|
if (dst) {
|
||||||
/* DST_NOCACHE can not be used without taking a reference */
|
/* set noref for now.
|
||||||
if (dst->flags & DST_NOCACHE) {
|
* any place which wants to hold dst has to call
|
||||||
if (likely(atomic_inc_not_zero(&dst->__refcnt)))
|
* dst_hold_safe()
|
||||||
skb_dst_set(skb, dst);
|
*/
|
||||||
} else {
|
skb_dst_set_noref(skb, dst);
|
||||||
skb_dst_set_noref(skb, dst);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -920,12 +920,11 @@ static void udp_v6_early_demux(struct sk_buff *skb)
|
||||||
if (dst)
|
if (dst)
|
||||||
dst = dst_check(dst, inet6_sk(sk)->rx_dst_cookie);
|
dst = dst_check(dst, inet6_sk(sk)->rx_dst_cookie);
|
||||||
if (dst) {
|
if (dst) {
|
||||||
if (dst->flags & DST_NOCACHE) {
|
/* set noref for now.
|
||||||
if (likely(atomic_inc_not_zero(&dst->__refcnt)))
|
* any place which wants to hold dst has to call
|
||||||
skb_dst_set(skb, dst);
|
* dst_hold_safe()
|
||||||
} else {
|
*/
|
||||||
skb_dst_set_noref(skb, dst);
|
skb_dst_set_noref(skb, dst);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue