BPF List
 help / color / mirror / Atom feed
From: Fernando Fernandez Mancera <fmancera@suse.de>
To: Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org, csmate@nop.hu, kerneljasonxing@gmail.com,
	maciej.fijalkowski@intel.com, bjorn@kernel.org, sdf@fomichev.me,
	jonathan.lemon@gmail.com, bpf@vger.kernel.org
Subject: Re: [PATCH net] xsk: avoid data corruption on cq descriptor number
Date: Tue, 21 Oct 2025 20:25:00 +0200	[thread overview]
Message-ID: <32086239-2fd5-42bd-a554-d0e3c263bb0c@suse.de> (raw)
In-Reply-To: <aPez6DYh13kmY9NF@horms.kernel.org>



On 10/21/25 6:25 PM, Simon Horman wrote:
> On Tue, Oct 21, 2025 at 05:06:56PM +0200, Fernando Fernandez Mancera wrote:
> 
> ...
> 
>> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> 
> ...
> 
>> @@ -774,6 +777,7 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,
>>   {
>>   	struct net_device *dev = xs->dev;
>>   	struct sk_buff *skb = xs->skb;
>> +	struct page *page;
>>   	int err;
>>   
>>   	if (dev->priv_flags & IFF_TX_SKB_NO_LINEAR) {
>> @@ -791,6 +795,8 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,
>>   		len = desc->len;
>>   
>>   		if (!skb) {
>> +			struct xsk_addr_node *head_addr;
>> +
>>   			hr = max(NET_SKB_PAD, L1_CACHE_ALIGN(dev->needed_headroom));
>>   			tr = dev->needed_tailroom;
>>   			skb = sock_alloc_send_skb(&xs->sk, hr + len + tr, 1, &err);
>> @@ -804,7 +810,13 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,
>>   			if (unlikely(err))
>>   				goto free_err;
>>   
>> -			xsk_skb_init_misc(skb, xs, desc->addr);
>> +			head_addr = kmem_cache_zalloc(xsk_tx_generic_cache, GFP_KERNEL);
>> +			if (!head_addr) {
>> +				__free_page(page);
> 
> Hi Fernando,
> 
> Perhaps the page changes to xsk_build_skb() aren't needed
> because page seems to be uninitialised here.
> 
> Flagged by W=1 builds with Clang 21.1.1, and Smatch.
> 

Ah, I don't know know what I was thinking about.. but yes, that page 
handling isn't needed of course as it isn't initialized. (I even needed 
the page struct because it wasn't available in that context).

I will send a V2 patch if the proposed solution is accepted. In additon, 
the performance impact isn't as bad as I thought.. just 4 bytes pero 
skb.. as the cache must be initialized anyway.

>> +				err = -ENOMEM;
>> +				goto free_err;
>> +			}
>> +			xsk_skb_init_misc(skb, xs, head_addr, desc->addr);
>>   			if (desc->options & XDP_TX_METADATA) {
>>   				err = xsk_skb_metadata(skb, buffer, desc,
>>   						       xs->pool, hr);
>> @@ -814,7 +826,6 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,
>>   		} else {
>>   			int nr_frags = skb_shinfo(skb)->nr_frags;
>>   			struct xsk_addr_node *xsk_addr;
>> -			struct page *page;
>>   			u8 *vaddr;
>>   
>>   			if (unlikely(nr_frags == (MAX_SKB_FRAGS - 1) && xp_mb_desc(desc))) {
>> @@ -843,7 +854,7 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,
>>   			refcount_add(PAGE_SIZE, &xs->sk.sk_wmem_alloc);
>>   
>>   			xsk_addr->addr = desc->addr;
>> -			list_add_tail(&xsk_addr->addr_node, &XSKCB(skb)->addrs_list);
>> +			list_add_tail(&xsk_addr->addr_node, &XSK_TX_HEAD(skb)->addr_node);
>>   		}
>>   	}
>>   
>> -- 
>> 2.51.0
>>
>>


  reply	other threads:[~2025-10-21 18:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-21 15:06 [PATCH net] xsk: avoid data corruption on cq descriptor number Fernando Fernandez Mancera
2025-10-21 16:25 ` Simon Horman
2025-10-21 18:25   ` Fernando Fernandez Mancera [this message]
2025-10-22  5:23 ` kernel test robot
2025-10-22 18:24 ` Fernando Fernandez Mancera

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=32086239-2fd5-42bd-a554-d0e3c263bb0c@suse.de \
    --to=fmancera@suse.de \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=csmate@nop.hu \
    --cc=horms@kernel.org \
    --cc=jonathan.lemon@gmail.com \
    --cc=kerneljasonxing@gmail.com \
    --cc=maciej.fijalkowski@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@fomichev.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox