[PATCH net-next 16/19] net: dev: use kfree_skb_reason() for enqueue_to_backlog()

From: menglong8 . dong
Date: Tue Feb 15 2022 - 06:33:19 EST


From: Menglong Dong <imagedong@xxxxxxxxxxx>

Replace kfree_skb() used in enqueue_to_backlog() with
kfree_skb_reason(). The skb drop reason SKB_DROP_REASON_CPU_BACKLOG is
introduced for the case of failing to enqueue the skb to the per CPU
backlog queue. The further reason can be backlog queue full or RPS
flow limition, and I think we needn't to make further distinctions.

Signed-off-by: Menglong Dong <imagedong@xxxxxxxxxxx>
---
include/linux/skbuff.h | 6 ++++++
include/trace/events/skb.h | 1 +
net/core/dev.c | 6 +++++-
3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 0f7e5177dbaf..d59fdcd98278 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -404,6 +404,12 @@ enum skb_drop_reason {
* outputting (failed to enqueue to
* current qdisc)
*/
+ SKB_DROP_REASON_CPU_BACKLOG, /* failed to enqueue the skb to
+ * the per CPU backlog queue. This
+ * can be caused by backlog queue
+ * full (see netdev_max_backlog in
+ * net.rst) or RPS flow limit
+ */
SKB_DROP_REASON_MAX,
};

diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h
index 356bea7567b5..a1c235daf23b 100644
--- a/include/trace/events/skb.h
+++ b/include/trace/events/skb.h
@@ -45,6 +45,7 @@
EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL) \
EM(SKB_DROP_REASON_QDISC_EGRESS, QDISC_EGRESS) \
EM(SKB_DROP_REASON_QDISC_DROP, QDISC_DROP) \
+ EM(SKB_DROP_REASON_CPU_BACKLOG, CPU_BACKLOG) \
EMe(SKB_DROP_REASON_MAX, MAX)

#undef EM
diff --git a/net/core/dev.c b/net/core/dev.c
index 55e890964fe2..8fee7adfca88 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4520,10 +4520,12 @@ static bool skb_flow_limit(struct sk_buff *skb, unsigned int qlen)
static int enqueue_to_backlog(struct sk_buff *skb, int cpu,
unsigned int *qtail)
{
+ enum skb_drop_reason reason;
struct softnet_data *sd;
unsigned long flags;
unsigned int qlen;

+ reason = SKB_DROP_REASON_NOT_SPECIFIED;
sd = &per_cpu(softnet_data, cpu);

local_irq_save(flags);
@@ -4550,6 +4552,8 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu,
____napi_schedule(sd, &sd->backlog);
}
goto enqueue;
+ } else {
+ reason = SKB_DROP_REASON_CPU_BACKLOG;
}

drop:
@@ -4559,7 +4563,7 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu,
local_irq_restore(flags);

atomic_long_inc(&skb->dev->rx_dropped);
- kfree_skb(skb);
+ kfree_skb_reason(skb, reason);
return NET_RX_DROP;
}

--
2.34.1