Skip to content

Commit 6c206b2

Browse files
Paolo Abenidavem330
authored andcommitted
udp: fix rx queue len reported by diag and proc interface
After commit 6b229cf ("udp: add batching to udp_rmem_release()") the sk_rmem_alloc field does not measure exactly anymore the receive queue length, because we batch the rmem release. The issue is really apparent only after commit 0d4a660 ("udp: do rmem bulk free even if the rx sk queue is empty"): the user space can easily check for an empty socket with not-0 queue length reported by the 'ss' tool or the procfs interface. We need to use a custom UDP helper to report the correct queue length, taking into account the forward allocation deficit. Reported-by: [email protected] Fixes: 6b229cf ("UDP: add batching to udp_rmem_release()") Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 49c2c3f commit 6c206b2

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

include/net/transp_v6.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk, struct msghdr *msg,
4545
struct flowi6 *fl6, struct ipcm6_cookie *ipc6,
4646
struct sockcm_cookie *sockc);
4747

48-
void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
49-
__u16 srcp, __u16 destp, int bucket);
48+
void __ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
49+
__u16 srcp, __u16 destp, int rqueue, int bucket);
50+
static inline void
51+
ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp, __u16 srcp,
52+
__u16 destp, int bucket)
53+
{
54+
__ip6_dgram_sock_seq_show(seq, sp, srcp, destp, sk_rmem_alloc_get(sp),
55+
bucket);
56+
}
5057

5158
#define LOOPBACK4_IPV6 cpu_to_be32(0x7f000006)
5259

include/net/udp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ static inline __be16 udp_flow_src_port(struct net *net, struct sk_buff *skb,
247247
return htons((((u64) hash * (max - min)) >> 32) + min);
248248
}
249249

250+
static inline int udp_rqueue_get(struct sock *sk)
251+
{
252+
return sk_rmem_alloc_get(sk) - READ_ONCE(udp_sk(sk)->forward_deficit);
253+
}
254+
250255
/* net/ipv4/udp.c */
251256
void udp_destruct_sock(struct sock *sk);
252257
void skb_consume_udp(struct sock *sk, struct sk_buff *skb, int len);

net/ipv4/udp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2772,7 +2772,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
27722772
" %02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %d",
27732773
bucket, src, srcp, dest, destp, sp->sk_state,
27742774
sk_wmem_alloc_get(sp),
2775-
sk_rmem_alloc_get(sp),
2775+
udp_rqueue_get(sp),
27762776
0, 0L, 0,
27772777
from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
27782778
0, sock_i_ino(sp),

net/ipv4/udp_diag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static int udp_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh,
163163
static void udp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
164164
void *info)
165165
{
166-
r->idiag_rqueue = sk_rmem_alloc_get(sk);
166+
r->idiag_rqueue = udp_rqueue_get(sk);
167167
r->idiag_wqueue = sk_wmem_alloc_get(sk);
168168
}
169169

net/ipv6/datagram.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,8 +1019,8 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk,
10191019
}
10201020
EXPORT_SYMBOL_GPL(ip6_datagram_send_ctl);
10211021

1022-
void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
1023-
__u16 srcp, __u16 destp, int bucket)
1022+
void __ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
1023+
__u16 srcp, __u16 destp, int rqueue, int bucket)
10241024
{
10251025
const struct in6_addr *dest, *src;
10261026

@@ -1036,7 +1036,7 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
10361036
dest->s6_addr32[2], dest->s6_addr32[3], destp,
10371037
sp->sk_state,
10381038
sk_wmem_alloc_get(sp),
1039-
sk_rmem_alloc_get(sp),
1039+
rqueue,
10401040
0, 0L, 0,
10411041
from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
10421042
0,

net/ipv6/udp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,8 @@ int udp6_seq_show(struct seq_file *seq, void *v)
15231523
struct inet_sock *inet = inet_sk(v);
15241524
__u16 srcp = ntohs(inet->inet_sport);
15251525
__u16 destp = ntohs(inet->inet_dport);
1526-
ip6_dgram_sock_seq_show(seq, v, srcp, destp, bucket);
1526+
__ip6_dgram_sock_seq_show(seq, v, srcp, destp,
1527+
udp_rqueue_get(v), bucket);
15271528
}
15281529
return 0;
15291530
}

0 commit comments

Comments
 (0)