]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xsk: add indirect call for xsk_destruct_skb
authorJason Xing <kernelxing@tencent.com>
Fri, 31 Oct 2025 10:33:28 +0000 (18:33 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 11 Nov 2025 09:21:08 +0000 (10:21 +0100)
Since Eric proposed an idea about adding indirect call wrappers for
UDP and managed to see a huge improvement[1], the same situation can
also be applied in xsk scenario.

This patch adds an indirect call for xsk and helps current copy mode
improve the performance by around 1% stably which was observed with
IXGBE at 10Gb/sec loaded. If the throughput grows, the positive effect
will be magnified. I applied this patch on top of batch xmit series[2],
and was able to see <5% improvement from our internal application
which is a little bit unstable though.

Use INDIRECT wrappers to keep xsk_destruct_skb static as it used to
be when the mitigation config is off.

Be aware of the freeing path that can be very hot since the frequency
can reach around 2,000,000 times per second with the xdpsock test.

[1]: https://lore.kernel.org/netdev/20251006193103.2684156-2-edumazet@google.com/
[2]: https://lore.kernel.org/all/20251021131209.41491-1-kerneljasonxing@gmail.com/

Suggested-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: Jason Xing <kernelxing@tencent.com>
Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Link: https://patch.msgid.link/20251031103328.95468-1-kerneljasonxing@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
include/net/xdp_sock.h
net/core/skbuff.c
net/xdp/xsk.c

index ce587a2256618d5cd0e2cb69bca46e67a3ca6e0d..23e8861e8b25e673c2fb0f6b6629d2bff7fd2bcb 100644 (file)
@@ -125,6 +125,7 @@ struct xsk_tx_metadata_ops {
 int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
 int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp);
 void __xsk_map_flush(struct list_head *flush_list);
+INDIRECT_CALLABLE_DECLARE(void xsk_destruct_skb(struct sk_buff *));
 
 /**
  *  xsk_tx_metadata_to_compl - Save enough relevant metadata information
@@ -218,6 +219,12 @@ static inline void __xsk_map_flush(struct list_head *flush_list)
 {
 }
 
+#ifdef CONFIG_MITIGATION_RETPOLINE
+static inline void xsk_destruct_skb(struct sk_buff *skb)
+{
+}
+#endif
+
 static inline void xsk_tx_metadata_to_compl(struct xsk_tx_metadata *meta,
                                            struct xsk_tx_metadata_compl *compl)
 {
index d95658b738d1935963286a9b01d7602212b7d8b0..4f4d7ab7057f16bcf88f29827a45a9f4a8f43d5c 100644 (file)
@@ -81,6 +81,7 @@
 #include <net/page_pool/helpers.h>
 #include <net/psp/types.h>
 #include <net/dropreason.h>
+#include <net/xdp_sock.h>
 
 #include <linux/uaccess.h>
 #include <trace/events/skb.h>
@@ -1140,12 +1141,13 @@ void skb_release_head_state(struct sk_buff *skb)
        if (skb->destructor) {
                DEBUG_NET_WARN_ON_ONCE(in_hardirq());
 #ifdef CONFIG_INET
-               INDIRECT_CALL_3(skb->destructor,
+               INDIRECT_CALL_4(skb->destructor,
                                tcp_wfree, __sock_wfree, sock_wfree,
+                               xsk_destruct_skb,
                                skb);
 #else
-               INDIRECT_CALL_1(skb->destructor,
-                               sock_wfree,
+               INDIRECT_CALL_2(skb->destructor,
+                               sock_wfree, xsk_destruct_skb,
                                skb);
 
 #endif
index ed8b612ec29d0c0dfb0d4de0d4d68aae401497c6..bcfd400e9cf8bb07452f6b02017ef4c6d2eeb541 100644 (file)
@@ -602,7 +602,8 @@ static u32 xsk_get_num_desc(struct sk_buff *skb)
        return XSKCB(skb)->num_descs;
 }
 
-static void xsk_destruct_skb(struct sk_buff *skb)
+INDIRECT_CALLABLE_SCOPE
+void xsk_destruct_skb(struct sk_buff *skb)
 {
        struct xsk_tx_metadata_compl *compl = &skb_shinfo(skb)->xsk_meta;