[PATCH linux next v2] net: neigh: use kfree_skb_reason() in neigh_resolve_output() and neigh_connected_output()

jiang.kun2@zte.com.cn posted 1 patch 7 months ago
include/net/dropreason-core.h | 3 +++
net/core/neighbour.c          | 4 ++--
2 files changed, 5 insertions(+), 2 deletions(-)
[PATCH linux next v2] net: neigh: use kfree_skb_reason() in neigh_resolve_output() and neigh_connected_output()
Posted by jiang.kun2@zte.com.cn 7 months ago
From: Qiu Yutan <qiu.yutan@zte.com.cn>

Replace kfree_skb() used in neigh_resolve_output() and
neigh_connected_output() with kfree_skb_reason().

Following new skb drop reason is added:
/* failed to fill the device hard header */
SKB_DROP_REASON_NEIGH_HH_FILLFAIL

Signed-off-by: Qiu Yutan <qiu.yutan@zte.com.cn>
Signed-off-by: Jiang Kun <jiang.kun2@zte.com.cn>
---
v1->v2
https://lore.kernel.org/all/20250520180552.GP365796@horms.kernel.org/
1. use kfree_skb_reason() in neigh_connected_output()

 include/net/dropreason-core.h | 3 +++
 net/core/neighbour.c          | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h
index bea77934a235..bcf9d7467e1a 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -62,6 +62,7 @@
 	FN(NEIGH_FAILED)		\
 	FN(NEIGH_QUEUEFULL)		\
 	FN(NEIGH_DEAD)			\
+	FN(NEIGH_HH_FILLFAIL)		\
 	FN(TC_EGRESS)			\
 	FN(SECURITY_HOOK)		\
 	FN(QDISC_DROP)			\
@@ -348,6 +349,8 @@ enum skb_drop_reason {
 	SKB_DROP_REASON_NEIGH_QUEUEFULL,
 	/** @SKB_DROP_REASON_NEIGH_DEAD: neigh entry is dead */
 	SKB_DROP_REASON_NEIGH_DEAD,
+	/** @SKB_DROP_REASON_NEIGH_HH_FILLFAIL: failed to fill the device hard header */
+	SKB_DROP_REASON_NEIGH_HH_FILLFAIL,
 	/** @SKB_DROP_REASON_TC_EGRESS: dropped in TC egress HOOK */
 	SKB_DROP_REASON_TC_EGRESS,
 	/** @SKB_DROP_REASON_SECURITY_HOOK: dropped due to security HOOK */
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 254067b719da..a6e2c91ec3e7 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1517,7 +1517,7 @@ int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb)
 	return rc;
 out_kfree_skb:
 	rc = -EINVAL;
-	kfree_skb(skb);
+	kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_HH_FILLFAIL);
 	goto out;
 }
 EXPORT_SYMBOL(neigh_resolve_output);
@@ -1541,7 +1541,7 @@ int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb)
 		err = dev_queue_xmit(skb);
 	else {
 		err = -EINVAL;
-		kfree_skb(skb);
+		kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_HH_FILLFAIL);
 	}
 	return err;
 }
-- 
2.25.1
Re: [PATCH linux next v2] net: neigh: use kfree_skb_reason() in neigh_resolve_output() and neigh_connected_output()
Posted by Jakub Kicinski 6 months, 3 weeks ago
On Wed, 21 May 2025 10:14:08 +0800 (CST) jiang.kun2@zte.com.cn wrote:
> From: Qiu Yutan <qiu.yutan@zte.com.cn>
> 
> Replace kfree_skb() used in neigh_resolve_output() and
> neigh_connected_output() with kfree_skb_reason().
> 
> Following new skb drop reason is added:
> /* failed to fill the device hard header */
> SKB_DROP_REASON_NEIGH_HH_FILLFAIL

Looks like this got applied already but can you explain for which
protocol you see these drops? I checked random few and none of them
can fail in ->create().
Re: [PATCH linux next v2] net: neigh: use kfree_skb_reason() in neigh_resolve_output() and neigh_connected_output()
Posted by xu.xin16@zte.com.cn 7 months ago
> From: Qiu Yutan <qiu.yutan@zte.com.cn>
> 
> Replace kfree_skb() used in neigh_resolve_output() and
> neigh_connected_output() with kfree_skb_reason().
> 
> Following new skb drop reason is added:
> /* failed to fill the device hard header */
> SKB_DROP_REASON_NEIGH_HH_FILLFAIL
> 
> Signed-off-by: Qiu Yutan <qiu.yutan@zte.com.cn>
> Signed-off-by: Jiang Kun <jiang.kun2@zte.com.cn>

Looks good to me.
Reviewed-by: Xu Xin <xu.xin16@zte.com.cn>
Re: [PATCH linux next v2] net: neigh: use kfree_skb_reason() in neigh_resolve_output() and neigh_connected_output()
Posted by Kuniyuki Iwashima 7 months ago
From: <jiang.kun2@zte.com.cn>
Date: Wed, 21 May 2025 10:14:08 +0800 (CST)
> From: Qiu Yutan <qiu.yutan@zte.com.cn>
> 
> Replace kfree_skb() used in neigh_resolve_output() and
> neigh_connected_output() with kfree_skb_reason().
> 
> Following new skb drop reason is added:
> /* failed to fill the device hard header */
> SKB_DROP_REASON_NEIGH_HH_FILLFAIL
> 
> Signed-off-by: Qiu Yutan <qiu.yutan@zte.com.cn>
> Signed-off-by: Jiang Kun <jiang.kun2@zte.com.cn>

Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>