From 834bfca1374ae494bc3f7e6471ba1f8254109c8f Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 27 May 2025 09:33:59 +0000 Subject: [PATCH] Revert "xsk: Fix race condition in AF_XDP generic RX path" This reverts commit 65d3c570614b892257dc58a1b202908242ecf8fd which is commit a1356ac7749cafc4e27aa62c0c4604b5dca4983e upstream. It breaks the Android kernel abi and can be brought back in the future in an abi-safe way if it is really needed. Bug: 161946584 Change-Id: I15acb18ebd9dd5a0d2fb0bf4153c5ced269f978a Signed-off-by: Greg Kroah-Hartman --- include/net/xdp_sock.h | 3 +++ include/net/xsk_buff_pool.h | 2 -- net/xdp/xsk.c | 6 +++--- net/xdp/xsk_buff_pool.c | 1 - 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h index df3f5f07bc7c..bfe625b55d55 100644 --- a/include/net/xdp_sock.h +++ b/include/net/xdp_sock.h @@ -71,6 +71,9 @@ struct xdp_sock { */ u32 tx_budget_spent; + /* Protects generic receive. */ + spinlock_t rx_lock; + /* Statistics */ u64 rx_dropped; u64 rx_queue_full; diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h index 823fd5c7a3b1..bacb33f1e3e5 100644 --- a/include/net/xsk_buff_pool.h +++ b/include/net/xsk_buff_pool.h @@ -55,8 +55,6 @@ struct xsk_buff_pool { refcount_t users; struct xdp_umem *umem; struct work_struct work; - /* Protects generic receive in shared and non-shared umem mode. */ - spinlock_t rx_lock; struct list_head free_list; struct list_head xskb_list; u32 heads_cnt; diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index f031b07baa57..b57d5d2904eb 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -338,14 +338,13 @@ int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) u32 len = xdp_get_buff_len(xdp); int err; + spin_lock_bh(&xs->rx_lock); err = xsk_rcv_check(xs, xdp, len); if (!err) { - spin_lock_bh(&xs->pool->rx_lock); err = __xsk_rcv(xs, xdp, len); xsk_flush(xs); - spin_unlock_bh(&xs->pool->rx_lock); } - + spin_unlock_bh(&xs->rx_lock); return err; } @@ -1721,6 +1720,7 @@ static int xsk_create(struct net *net, struct socket *sock, int protocol, xs = xdp_sk(sk); xs->state = XSK_READY; mutex_init(&xs->mutex); + spin_lock_init(&xs->rx_lock); INIT_LIST_HEAD(&xs->map_list); spin_lock_init(&xs->map_list_lock); diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c index b69dbd8615fc..87e865b9b83a 100644 --- a/net/xdp/xsk_buff_pool.c +++ b/net/xdp/xsk_buff_pool.c @@ -87,7 +87,6 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs, pool->addrs = umem->addrs; pool->tx_metadata_len = umem->tx_metadata_len; pool->tx_sw_csum = umem->flags & XDP_UMEM_TX_SW_CSUM; - spin_lock_init(&pool->rx_lock); INIT_LIST_HEAD(&pool->free_list); INIT_LIST_HEAD(&pool->xskb_list); INIT_LIST_HEAD(&pool->xsk_tx_list);