Skip to content

Commit 22911fc

Browse files
Eric Dumazetdavem330
Eric Dumazet
authored andcommitted
net: skb_free_datagram_locked() doesnt drop all packets
dropwatch wrongly diagnose all received UDP packets as drops. This patch removes trace_kfree_skb() done in skb_free_datagram_locked(). Locations calling skb_free_datagram_locked() should do it on their own. As a result, drops are accounted on the right function. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4c3af03 commit 22911fc

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

net/core/datagram.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ void skb_free_datagram_locked(struct sock *sk, struct sk_buff *skb)
248248
unlock_sock_fast(sk, slow);
249249

250250
/* skb is now orphaned, can be freed outside of locked section */
251-
trace_kfree_skb(skb, skb_free_datagram_locked);
252251
__kfree_skb(skb);
253252
}
254253
EXPORT_SYMBOL(skb_free_datagram_locked);

net/ipv4/udp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
#include <net/xfrm.h>
109109
#include <trace/events/udp.h>
110110
#include <linux/static_key.h>
111+
#include <trace/events/skb.h>
111112
#include "udp_impl.h"
112113

113114
struct udp_table udp_table __read_mostly;
@@ -1220,8 +1221,10 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
12201221
goto csum_copy_err;
12211222
}
12221223

1223-
if (err)
1224+
if (unlikely(err)) {
1225+
trace_kfree_skb(skb, udp_recvmsg);
12241226
goto out_free;
1227+
}
12251228

12261229
if (!peeked)
12271230
UDP_INC_STATS_USER(sock_net(sk),

net/ipv6/udp.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
#include <linux/proc_fs.h>
5050
#include <linux/seq_file.h>
51+
#include <trace/events/skb.h>
5152
#include "udp_impl.h"
5253

5354
int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
@@ -385,15 +386,16 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
385386

386387
if (skb_csum_unnecessary(skb))
387388
err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr),
388-
msg->msg_iov, copied );
389+
msg->msg_iov, copied);
389390
else {
390391
err = skb_copy_and_csum_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov);
391392
if (err == -EINVAL)
392393
goto csum_copy_err;
393394
}
394-
if (err)
395+
if (unlikely(err)) {
396+
trace_kfree_skb(skb, udpv6_recvmsg);
395397
goto out_free;
396-
398+
}
397399
if (!peeked) {
398400
if (is_udp4)
399401
UDP_INC_STATS_USER(sock_net(sk),

net/sunrpc/svcsock.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <net/tcp_states.h>
4444
#include <asm/uaccess.h>
4545
#include <asm/ioctls.h>
46+
#include <trace/events/skb.h>
4647

4748
#include <linux/sunrpc/types.h>
4849
#include <linux/sunrpc/clnt.h>
@@ -619,6 +620,8 @@ static int svc_udp_recvfrom(struct svc_rqst *rqstp)
619620
if (!svc_udp_get_dest_address(rqstp, cmh)) {
620621
net_warn_ratelimited("svc: received unknown control message %d/%d; dropping RPC reply datagram\n",
621622
cmh->cmsg_level, cmh->cmsg_type);
623+
out_free:
624+
trace_kfree_skb(skb, svc_udp_recvfrom);
622625
skb_free_datagram_locked(svsk->sk_sk, skb);
623626
return 0;
624627
}
@@ -630,8 +633,7 @@ static int svc_udp_recvfrom(struct svc_rqst *rqstp)
630633
if (csum_partial_copy_to_xdr(&rqstp->rq_arg, skb)) {
631634
local_bh_enable();
632635
/* checksum error */
633-
skb_free_datagram_locked(svsk->sk_sk, skb);
634-
return 0;
636+
goto out_free;
635637
}
636638
local_bh_enable();
637639
skb_free_datagram_locked(svsk->sk_sk, skb);
@@ -640,10 +642,8 @@ static int svc_udp_recvfrom(struct svc_rqst *rqstp)
640642
rqstp->rq_arg.head[0].iov_base = skb->data +
641643
sizeof(struct udphdr);
642644
rqstp->rq_arg.head[0].iov_len = len;
643-
if (skb_checksum_complete(skb)) {
644-
skb_free_datagram_locked(svsk->sk_sk, skb);
645-
return 0;
646-
}
645+
if (skb_checksum_complete(skb))
646+
goto out_free;
647647
rqstp->rq_xprt_ctxt = skb;
648648
}
649649

0 commit comments

Comments
 (0)