[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAL+tcoDnAv7+kG4WdAh1ELP0=bj_1og+DdD-JS4YuWzZC+9OhA@mail.gmail.com>
Date: Sat, 25 Oct 2025 17:08:39 +0800
From: Jason Xing <kerneljasonxing@...il.com>
To: Simon Horman <horms@...nel.org>
Cc: davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
pabeni@...hat.com, bjorn@...nel.org, magnus.karlsson@...el.com,
maciej.fijalkowski@...el.com, jonathan.lemon@...il.com, sdf@...ichev.me,
ast@...nel.org, daniel@...earbox.net, hawk@...nel.org,
john.fastabend@...il.com, joe@...a.to, willemdebruijn.kernel@...il.com,
bpf@...r.kernel.org, netdev@...r.kernel.org,
Jason Xing <kernelxing@...cent.com>
Subject: Re: [PATCH net-next v3 1/9] xsk: introduce XDP_GENERIC_XMIT_BATCH setsockopt
Hi Simon,
On Fri, Oct 24, 2025 at 9:30 PM Simon Horman <horms@...nel.org> wrote:
>
> On Tue, Oct 21, 2025 at 09:12:01PM +0800, Jason Xing wrote:
>
> ...
>
> > index 7b0c68a70888..ace91800c447 100644
>
> ...
>
> > @@ -1544,6 +1546,55 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname,
> > WRITE_ONCE(xs->max_tx_budget, budget);
> > return 0;
> > }
> > + case XDP_GENERIC_XMIT_BATCH:
> > + {
> > + struct xsk_buff_pool *pool = xs->pool;
> > + struct xsk_batch *batch = &xs->batch;
> > + struct xdp_desc *descs;
> > + struct sk_buff **skbs;
> > + unsigned int size;
> > + int ret = 0;
> > +
> > + if (optlen != sizeof(size))
> > + return -EINVAL;
> > + if (copy_from_sockptr(&size, optval, sizeof(size)))
> > + return -EFAULT;
> > + if (size == batch->generic_xmit_batch)
> > + return 0;
> > + if (size > xs->max_tx_budget || !pool)
> > + return -EACCES;
> > +
> > + mutex_lock(&xs->mutex);
> > + if (!size) {
> > + kfree(batch->skb_cache);
> > + kvfree(batch->desc_cache);
> > + batch->generic_xmit_batch = 0;
> > + goto out;
> > + }
> > +
> > + skbs = kmalloc(size * sizeof(struct sk_buff *), GFP_KERNEL);
> > + if (!skbs) {
> > + ret = -ENOMEM;
> > + goto out;
> > + }
> > + descs = kvcalloc(size, sizeof(struct xdp_desc), GFP_KERNEL);
> > + if (!descs) {
> > + kfree(skbs);
> > + ret = -ENOMEM;
> > + goto out;
> > + }
> > + if (batch->skb_cache)
> > + kfree(batch->skb_cache);
> > + if (batch->desc_cache)
> > + kvfree(batch->desc_cache);
>
> Hi Jason,
>
> nit: kfree and kvfree are no-ops when passed NULL,
> so the conditions above seem unnecessary.
Yep, but the checkpatch complains. I thought it might be good to keep
it because normally we need to check the validation of the pointer
first and then free it. WDYT?
Thanks,
Jason
Powered by blists - more mailing lists