]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xsk: advance cq/fq check when shared umem is used
authorJason Xing <kernelxing@tencent.com>
Sun, 4 Jan 2026 01:21:24 +0000 (09:21 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 15 Jan 2026 09:07:44 +0000 (10:07 +0100)
In the shared umem mode with different queues or devices, either
uninitialized cq or fq is not allowed which was previously done in
xp_assign_dev_shared(). The patch advances the check at the beginning
so that 1) we can avoid a few memory allocation and stuff if cq or fq
is NULL, 2) it can be regarded as preparation for the next patch in
the series.

Signed-off-by: Jason Xing <kernelxing@tencent.com>
Link: https://patch.msgid.link/20260104012125.44003-2-kerneljasonxing@gmail.com
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/xdp/xsk.c
net/xdp/xsk_buff_pool.c

index f093c3453f64ce4071f4698da6adc7a05870e711..3c52fafae47c65e6dd3e72df585017fa584a88aa 100644 (file)
@@ -1349,6 +1349,13 @@ static int xsk_bind(struct socket *sock, struct sockaddr_unsized *addr, int addr
                }
 
                if (umem_xs->queue_id != qid || umem_xs->dev != dev) {
+                       /* One fill and completion ring required for each queue id. */
+                       if (!xsk_validate_queues(xs)) {
+                               err = -EINVAL;
+                               sockfd_put(sock);
+                               goto out_unlock;
+                       }
+
                        /* Share the umem with another socket on another qid
                         * and/or device.
                         */
index 51526034c42acb9a45b69133da430c0f72227831..6bf84316e2adbb39bae51a15dee8d879fa473ba8 100644 (file)
@@ -247,10 +247,6 @@ int xp_assign_dev_shared(struct xsk_buff_pool *pool, struct xdp_sock *umem_xs,
        u16 flags;
        struct xdp_umem *umem = umem_xs->umem;
 
-       /* One fill and completion ring required for each queue id. */
-       if (!pool->fq || !pool->cq)
-               return -EINVAL;
-
        flags = umem->zc ? XDP_ZEROCOPY : XDP_COPY;
        if (umem_xs->pool->uses_need_wakeup)
                flags |= XDP_USE_NEED_WAKEUP;