mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "e.kubanski" <e.kubanski@partner.samsung.com>
To: magnus.karlsson@intel.com
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	bjorn@kernel.org, maciej.fijalkowski@intel.com,
	jonathan.lemon@gmail.com
Subject: Re: Re: [PATCH] xsk: Fix race condition in AF_XDP generic RX path
Date: Wed,  9 Apr 2025 16:20:11 +0200	[thread overview]
Message-ID: <20250409142011.82687-1-e.kubanski@partner.samsung.com> (raw)
In-Reply-To: <CGME20250409125216eucas1p150b189cd13807197a233718302103a02@eucas1p1.samsung.com>

> I do not fully understand what you are doing in user space. Could you
> please provide a user-space code example that will trigger this
> problem?

We want to scale single hardware queue AF_XDP setup to
receive packets on multiple threads through RPS mechanisms.
The problem arises when RPS is enabled in the kernel.
In this situation single hardware queue flow can scale across
multiple CPU cores. Then we perform XDP/eBPF load-balancing
to multiple sockets, by using CPU_ID of issued XDP call.

Every socket is binded to queue number 0, device has single queue.

User-space socket setup looks more-or-less like that (with libxdp):
```
xsk_ring_prod fq{};
xsk_ring_cons cq{};

xsk_umem_config umem_cfg{ ... };
xsk_umem* umem;
auto result = xsk_umem__create(&umem, umem_memory, pool_size_bytes, &fq, &cq, &umem_cfg);

...

xsk_socket_config xsk_cfg{
    ...
    .xdp_flags = XDP_FLAGS_SKB_MODE,
    ...
};

xsk_socket* sock1{nullptr};
xsk_ring_cons rq1{};
xsk_ring_prod tq1{};
auto result = xsk_socket__create_shared(
    &sock1,
    device_name,
    0,
    &rq1,
    &tq1,
    &fq,
    &cq,
    &cfg
);

xsk_socket* sock2{nullptr};
xsk_ring_cons rq2{};
xsk_ring_prod tq2{};
auto result = xsk_socket__create_shared(
    &sock2,
    device_name,
    0,
    &rq2,
    &tq2,
    &fq,
    &cq,
    &cfg
);

...
```

We're working on cloud native deploymetns, where
it's not possible to scale RX through RSS mechanism only.

That's why we wanted to use RPS to scale not only
user-space processing but also XDP processing.

This patch effectively allows us to use RPS to scale XDP
in Generic mode.

The same goes for RPS disabled, where we use MACVLAN

child device attached to parent device with multiple queues.
In this situation MACVLAN allows for multi-core kernel-side
processing, but xsk_buff_pool isn't protected.

We can't do any passthrough in this situation, we must rely
on MACVLAN with single RX/TX queue pair.

Of course this is not a problem in situation where every device
packet is processed on single core.

> Please note that if you share an Rx ring or the fill ring between
> processes/threads, then you have to take care about mutual exclusion
> in user space.

Of course, RX/TX/FILL/COMP are SPSC queues, we included mutual
exclusion for FILL/COMP because RX/TX are accessed by single thread.
Im doing single process deployment with multiple threads, where every
thread has it's own AF_XDP socket and pool is shared across threads.

> If you really want to do this, it is usually a better
> idea to use the other shared umem mode in which each process gets its
> own rx and fill ring, removing the need for mutual exclusion.

If I understand AF_XDP architecture correctly it's not possible for single
queue deployment, or maybe Im missing something? We need to maintain
single FILL/COMP pair per device queue.


  parent reply	other threads:[~2025-04-09 14:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20250409125216eucas1p150b189cd13807197a233718302103a02@eucas1p1.samsung.com>
2025-04-09 12:49 ` e.kubanski
2025-04-09 13:21   ` Magnus Karlsson
2025-04-09 14:20 ` e.kubanski [this message]
2025-04-10  7:52   ` Magnus Karlsson

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=20250409142011.82687-1-e.kubanski@partner.samsung.com \
    --to=e.kubanski@partner.samsung.com \
    --cc=bjorn@kernel.org \
    --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

all inboxes | Powered by JetHome®