* [PATCH bpf] xsk: inherit need_wakeup flag for shared sockets
@ 2022-09-19 19:24 Jalal Mostafa
2022-09-20 6:27 ` Magnus Karlsson
0 siblings, 1 reply; 2+ messages in thread
From: Jalal Mostafa @ 2022-09-19 19:24 UTC (permalink / raw)
To: netdev, bpf
Cc: bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon,
davem, edumazet, kuba, pabeni, ast, daniel, hawk, john.fastabend,
linux-kernel, jalal.a.mostapha, jalal.mostafa
The flag for need_wakeup is not set for xsks with `XDP_SHARED_UMEM`
flag and of different queue ids and/or devices. They should inherit
the flag from the first socket buffer pool since no flags can be
specified once `XDP_SHARED_UMEM` is specified. The issue is fixed
by creating a new function `xp_create_and_assign_umem_shared` to
create xsk_buff_pool for xsks with the shared umem flag set.
Signed-off-by: Jalal Mostafa <jalal.a.mostapha@gmail.com>
---
include/net/xsk_buff_pool.h | 2 ++
net/xdp/xsk.c | 3 +--
net/xdp/xsk_buff_pool.c | 15 +++++++++++++++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h
index 647722e847b4..917cfef9d355 100644
--- a/include/net/xsk_buff_pool.h
+++ b/include/net/xsk_buff_pool.h
@@ -93,6 +93,8 @@ struct xsk_buff_pool {
/* AF_XDP core. */
struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
struct xdp_umem *umem);
+struct xsk_buff_pool *xp_create_and_assign_umem_shared(struct xdp_sock *xs,
+ struct xdp_sock *umem_xs);
int xp_assign_dev(struct xsk_buff_pool *pool, struct net_device *dev,
u16 queue_id, u16 flags);
int xp_assign_dev_shared(struct xsk_buff_pool *pool, struct xdp_umem *umem,
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 5b4ce6ba1bc7..a415db88e8e5 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -946,8 +946,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
/* Share the umem with another socket on another qid
* and/or device.
*/
- xs->pool = xp_create_and_assign_umem(xs,
- umem_xs->umem);
+ xs->pool = xp_create_and_assign_umem_shared(xs, umem_xs);
if (!xs->pool) {
err = -ENOMEM;
sockfd_put(sock);
diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
index a71a8c6edf55..7d5b0bd8d953 100644
--- a/net/xdp/xsk_buff_pool.c
+++ b/net/xdp/xsk_buff_pool.c
@@ -112,6 +112,21 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
return NULL;
}
+struct xsk_buff_pool *xp_create_and_assign_umem_shared(struct xdp_sock *xs,
+ struct xdp_sock *umem_xs)
+{
+ struct xdp_umem *umem = umem_xs->umem;
+ struct xsk_buff_pool *pool = xp_create_and_assign_umem(xs, umem);
+
+ if (!pool)
+ goto out;
+
+ pool->uses_need_wakeup = umem_xs->pool->uses_need_wakeup;
+
+out:
+ return pool;
+}
+
void xp_set_rxq_info(struct xsk_buff_pool *pool, struct xdp_rxq_info *rxq)
{
u32 i;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf] xsk: inherit need_wakeup flag for shared sockets
2022-09-19 19:24 [PATCH bpf] xsk: inherit need_wakeup flag for shared sockets Jalal Mostafa
@ 2022-09-20 6:27 ` Magnus Karlsson
0 siblings, 0 replies; 2+ messages in thread
From: Magnus Karlsson @ 2022-09-20 6:27 UTC (permalink / raw)
To: Jalal Mostafa
Cc: netdev, bpf, bjorn, magnus.karlsson, maciej.fijalkowski,
jonathan.lemon, davem, edumazet, kuba, pabeni, ast, daniel, hawk,
john.fastabend, linux-kernel, jalal.mostafa
On Mon, Sep 19, 2022 at 9:27 PM Jalal Mostafa
<jalal.a.mostapha@gmail.com> wrote:
>
> The flag for need_wakeup is not set for xsks with `XDP_SHARED_UMEM`
> flag and of different queue ids and/or devices. They should inherit
> the flag from the first socket buffer pool since no flags can be
> specified once `XDP_SHARED_UMEM` is specified. The issue is fixed
> by creating a new function `xp_create_and_assign_umem_shared` to
> create xsk_buff_pool for xsks with the shared umem flag set.
Thanks for spotting this Jalal. Though I think we should aim for a
simpler fix. The uses_need_wakeup flag is set by xp_assign_dev(). The
problem here is the function xp_assign_dev_shared() that prepares the
flag parameter for xp_assign_dev().
if (pool->uses_need_wakeup)
flags |= XDP_USE_NEED_WAKEUP;
Should really be:
if (umem_xs->pool->uses_need_wakeup)
flags |= XDP_USE_NEED_WAKEUP;
So change the function parameter *umem to *umem_xs, use that in the
function call and do:
flags = umem_xs->umem->zc ? XDP_ZEROCOPY : XDP_COPY;
if (umem_xs->pool->uses_need_wakeup)
flags |= XDP_USE_NEED_WAKEUP;
What do you think?
> Signed-off-by: Jalal Mostafa <jalal.a.mostapha@gmail.com>
> ---
> include/net/xsk_buff_pool.h | 2 ++
> net/xdp/xsk.c | 3 +--
> net/xdp/xsk_buff_pool.c | 15 +++++++++++++++
> 3 files changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h
> index 647722e847b4..917cfef9d355 100644
> --- a/include/net/xsk_buff_pool.h
> +++ b/include/net/xsk_buff_pool.h
> @@ -93,6 +93,8 @@ struct xsk_buff_pool {
> /* AF_XDP core. */
> struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
> struct xdp_umem *umem);
> +struct xsk_buff_pool *xp_create_and_assign_umem_shared(struct xdp_sock *xs,
> + struct xdp_sock *umem_xs);
> int xp_assign_dev(struct xsk_buff_pool *pool, struct net_device *dev,
> u16 queue_id, u16 flags);
> int xp_assign_dev_shared(struct xsk_buff_pool *pool, struct xdp_umem *umem,
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 5b4ce6ba1bc7..a415db88e8e5 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -946,8 +946,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
> /* Share the umem with another socket on another qid
> * and/or device.
> */
> - xs->pool = xp_create_and_assign_umem(xs,
> - umem_xs->umem);
> + xs->pool = xp_create_and_assign_umem_shared(xs, umem_xs);
> if (!xs->pool) {
> err = -ENOMEM;
> sockfd_put(sock);
> diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
> index a71a8c6edf55..7d5b0bd8d953 100644
> --- a/net/xdp/xsk_buff_pool.c
> +++ b/net/xdp/xsk_buff_pool.c
> @@ -112,6 +112,21 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
> return NULL;
> }
>
> +struct xsk_buff_pool *xp_create_and_assign_umem_shared(struct xdp_sock *xs,
> + struct xdp_sock *umem_xs)
> +{
> + struct xdp_umem *umem = umem_xs->umem;
> + struct xsk_buff_pool *pool = xp_create_and_assign_umem(xs, umem);
> +
> + if (!pool)
> + goto out;
> +
> + pool->uses_need_wakeup = umem_xs->pool->uses_need_wakeup;
> +
> +out:
> + return pool;
> +}
> +
> void xp_set_rxq_info(struct xsk_buff_pool *pool, struct xdp_rxq_info *rxq)
> {
> u32 i;
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-20 6:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-19 19:24 [PATCH bpf] xsk: inherit need_wakeup flag for shared sockets Jalal Mostafa
2022-09-20 6:27 ` Magnus Karlsson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.