selftests/xsk: Avoid bpf_link probe for existing xsk
authorMaciej Fijalkowski <maciej.fijalkowski@intel.com>
Wed, 29 Jun 2022 14:34:55 +0000 (16:34 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 30 Jun 2022 20:48:57 +0000 (22:48 +0200)
Currently bpf_link probe is done for each call of xsk_socket__create().
For cases where xsk context was previously created and current socket
creation uses it, has_bpf_link will be overwritten, where it has already
been initialized.

Optimize this by moving the query to the xsk_create_ctx() so that when
xsk_get_ctx() finds a ctx then no further bpf_link probes are needed.

Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/bpf/20220629143458.934337-2-maciej.fijalkowski@intel.com
tools/testing/selftests/bpf/xsk.c

index eb50c3f..fa13d2c 100644 (file)
@@ -958,6 +958,7 @@ static struct xsk_ctx *xsk_create_ctx(struct xsk_socket *xsk,
        ctx->fill = fill;
        ctx->comp = comp;
        list_add(&ctx->list, &umem->ctx_list);
+       ctx->has_bpf_link = xsk_probe_bpf_link();
        return ctx;
 }
 
@@ -1059,7 +1060,6 @@ int xsk_socket__create_shared(struct xsk_socket **xsk_ptr,
                }
        }
        xsk->ctx = ctx;
-       xsk->ctx->has_bpf_link = xsk_probe_bpf_link();
 
        if (rx && !rx_setup_done) {
                err = setsockopt(xsk->fd, SOL_XDP, XDP_RX_RING,