From: Stanislav Fomichev <stfomichev@gmail.com>
To: "e.kubanski" <e.kubanski@partner.samsung.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
bjorn@kernel.org, magnus.karlsson@intel.com,
maciej.fijalkowski@intel.com, jonathan.lemon@gmail.com
Subject: Re: [PATCH bpf v2] xsk: Fix out of order segment free in __xsk_generic_xmit()
Date: Fri, 30 May 2025 09:07:56 -0700 [thread overview]
Message-ID: <aDnX3FVPZ3AIZDGg@mini-arch> (raw)
In-Reply-To: <20250530103456.53564-1-e.kubanski@partner.samsung.com>
On 05/30, e.kubanski wrote:
> Move xsk completion queue descriptor write-back to destructor.
>
> Fix xsk descriptor management in completion queue. Descriptor
> management mechanism didn't take care of situations where
> completion queue submission can happen out-of-order to
> descriptor write-back.
>
> __xsk_generic_xmit() was assigning descriptor to slot right
> after completion queue slot reservation. If multiple CPUs
> access the same completion queue after xmit, this can result
> in out-of-order submission of invalid descriptor batch.
> SKB destructor call can submit descriptor batch that is
> currently in use by other CPU, instead of correct transmitted
> ones. This could result in User-Space <-> Kernel-Space data race.
>
> Forbid possible out-of-order submissions:
> CPU A: Reservation + Descriptor Write
> CPU B: Reservation + Descriptor Write
> CPU B: Submit (submitted first batch reserved by CPU A)
> CPU A: Submit (submitted second batch reserved by CPU B)
>
> Move Descriptor Write to submission phase:
> CPU A: Reservation (only moves local writer)
> CPU B: Reservation (only moves local writer)
> CPU B: Descriptor Write + Submit
> CPU A: Descriptor Write + Submit
>
> This solves potential out-of-order free of xsk buffers.
I'm not sure I understand what's the issue here. If you're using the
same XSK from different CPUs, you should take care of the ordering
yourself on the userspace side?
> Signed-off-by: Eryk Kubanski <e.kubanski@partner.samsung.com>
> Fixes: e6c4047f5122 ("xsk: Use xsk_buff_pool directly for cq functions")
> ---
> include/linux/skbuff.h | 2 ++
> net/xdp/xsk.c | 17 +++++++++++------
> net/xdp/xsk_queue.h | 11 +++++++++++
> 3 files changed, 24 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 5520524c93bf..cc37b62638cd 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -624,6 +624,8 @@ struct skb_shared_info {
> void *destructor_arg;
> };
>
> + u64 xsk_descs[MAX_SKB_FRAGS];
This is definitely a no-go (sk_buff and skb_shared_info space is
precious).
next prev parent reply other threads:[~2025-05-30 16:07 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20250530103506eucas1p1e4091678f4157b928ddfa6f6534a0009@eucas1p1.samsung.com>
2025-05-30 10:34 ` [PATCH bpf v2] xsk: Fix out of order segment free in __xsk_generic_xmit() e.kubanski
[not found] ` <CGME20250530103506eucas1p1e4091678f4157b928ddfa6f6534a0009@eucms1p4>
2025-05-30 11:56 ` Eryk Kubanski
2025-05-30 16:07 ` Stanislav Fomichev [this message]
[not found] ` <CGME20250530103506eucas1p1e4091678f4157b928ddfa6f6534a0009@eucms1p1>
2025-06-02 9:27 ` Eryk Kubanski
2025-06-02 15:28 ` Stanislav Fomichev
2025-06-02 16:03 ` Maciej Fijalkowski
[not found] ` <CGME20250530103506eucas1p1e4091678f4157b928ddfa6f6534a0009@eucms1p2>
2025-06-02 16:18 ` Eryk Kubanski
2025-06-04 13:50 ` Maciej Fijalkowski
2025-06-04 14:15 ` Eryk Kubanski
2025-06-09 19:41 ` Maciej Fijalkowski
2025-06-10 9:35 ` Eryk Kubanski
[not found] ` <CGME20250530103506eucas1p1e4091678f4157b928ddfa6f6534a0009@eucms1p3>
2025-06-02 15:58 ` Eryk Kubanski
2025-06-10 9:11 ` Re: " Eryk Kubanski
2025-06-11 13:10 ` Maciej Fijalkowski
2025-07-03 23:37 ` Jason Xing
2025-07-04 12:34 ` Maciej Fijalkowski
2025-07-04 15:29 ` Jason Xing
2025-06-04 14:41 ` kernel test robot
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=aDnX3FVPZ3AIZDGg@mini-arch \
--to=stfomichev@gmail.com \
--cc=bjorn@kernel.org \
--cc=e.kubanski@partner.samsung.com \
--cc=jonathan.lemon@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).