From: sashiko-bot@kernel.org
To: "Tushar Vyavahare" <tushar.vyavahare@intel.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next 1/5] selftests/xsk: add UMEM users refcount and centralize socket teardown
Date: Sat, 08 Aug 2026 13:44:28 +0000 [thread overview]
Message-ID: <20260808134429.D6C421F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260807134209.3794735-2-tushar.vyavahare@intel.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Premature UMEM destruction during batch teardown of partially configured socket arrays causes `xsk_umem` file descriptor and memory leaks.
--
--- Patch [1]: [PATCH net-next 1/5] selftests/xsk: add UMEM users refcount and centralize socket teardown ---
commit 99dd730a09377ba26c180094a39cc7721ae72648
Author: Tushar Vyavahare <tushar.vyavahare@intel.com>
selftests/xsk: add UMEM users refcount and centralize socket teardown
This commit introduces a reference count for shared UMEM users in the XSK
selftests and centralizes socket teardown in xsk_delete_socket(). It
replaces manual UMEM teardown functions with a unified batch deletion
approach to avoid leaks or double-releases during error handling.
> diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.c b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
> index 6eb9096d084c0..43ab61faad024 100644
> --- a/tools/testing/selftests/bpf/prog_tests/test_xsk.c
> +++ b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
[ ... ]
> @@ -1702,12 +1718,71 @@ void *worker_testapp_validate_rx(void *arg)
> pthread_exit(NULL);
> }
>
> -static void testapp_clean_xsk_umem(struct ifobject *ifobj)
> +void xsk_delete_socket(struct xsk_socket_info *xsk)
> {
> - struct xsk_umem_info *umem = ifobj->xsk->umem;
> + struct xsk_umem_info *umem;
[ ... ]
> + /* Always decrement refcount for this socket's UMEM reference */
> + if (refcount_dec_and_test(&umem->users)) {
> + if (umem->umem) {
> + int err = xsk_umem__delete(umem->umem);
> +
> + if (err)
> + ksft_print_msg("xsk_umem__delete failed: %d (umem still busy?)\n",
> + err);
> + }
> + if (umem->buffer && umem->mmap_size)
> + munmap(umem->buffer, umem->mmap_size);
> + umem->umem = NULL;
> + umem->buffer = NULL;
> + umem->mmap_size = 0;
> + }
> +}
> +
> +static void xsk_delete_socket_batch(struct ifobject *ifobject, u32 count)
> +{
> + u32 i;
> +
> + if (!ifobject)
> + return;
> +
> + for (i = count; i > 0; i--)
> + xsk_delete_socket(&ifobject->xsk_arr[i - 1]);
> +}
[Severity: Medium]
Could this result in a premature UMEM destruction and a subsequent file
descriptor leak during partial setup failures?
Since xsk->umem is pre-initialized for all array slots in
__test_spec_init(), uninitialized slots will still have a non-NULL
umem pointer.
If setup fails halfway through (e.g., enable_busy_poll() fails for i = 0 in
xsk_configure()), the batch teardown iterates backwards from test->nb_sockets.
When it reaches an uninitialized slot (like i = 1), it will see the
pre-initialized umem pointer and decrement the refcount.
If this brings the refcount to 0, it prematurely attempts teardown. Since the
valid socket at i = 0 is still active, xsk_umem__delete() returns -EBUSY.
However, the code still proceeds to munmap the buffer and set umem->umem = NULL.
When the loop finally processes i = 0, the refcount is already 0, so it skips
calling xsk_umem__delete() entirely, permanently leaking the UMEM and its
file descriptor.
Is there a way to distinguish between a pre-initialized slot that never took a
reference and a successfully configured slot?
> +
> +static void xsk_delete_all_ifobj_sockets(struct test_spec *test, struct ifobject *ifobj)
> +{
> + if (!ifobj)
> + return;
> +
> + xsk_delete_socket_batch(ifobj, test->nb_sockets);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260807134209.3794735-1-tushar.vyavahare@intel.com?part=1
next prev parent reply other threads:[~2026-08-08 13:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 13:42 [PATCH net-next 0/5] selftests/xsk: improve shared-UMEM coverage and infrastructure Tushar Vyavahare
2026-08-07 13:42 ` [PATCH net-next 1/5] selftests/xsk: add UMEM users refcount and centralize socket teardown Tushar Vyavahare
2026-08-08 13:44 ` sashiko-bot [this message]
2026-08-12 2:42 ` bot+bpf-ci
2026-08-07 13:42 ` [PATCH net-next 2/5] selftests/xsk: roll back partial socket setup on configure failures Tushar Vyavahare
2026-08-08 13:44 ` sashiko-bot
2026-08-12 2:42 ` bot+bpf-ci
2026-08-07 13:42 ` [PATCH net-next 3/5] selftests/xsk: expand XSKMAP capacity and add length-based XDP program Tushar Vyavahare
2026-08-12 2:42 ` bot+bpf-ci
2026-08-07 13:42 ` [PATCH net-next 4/5] selftests/xsk: add shared-UMEM callback framework and initial test cases Tushar Vyavahare
2026-08-07 13:42 ` [PATCH net-next 5/5] selftests/xsk: make pkt_stream_even_odd_sequence rollback-safe Tushar Vyavahare
2026-08-12 2:28 ` bot+bpf-ci
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=20260808134429.D6C421F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tushar.vyavahare@intel.com \
/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 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.