From: Tushar Vyavahare <tushar.vyavahare@intel.com>
To: netdev@vger.kernel.org, magnus.karlsson@intel.com,
maciej.fijalkowski@intel.com, stfomichev@gmail.com,
kernelxing@tencent.com, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net,
tirthendu.sarkar@intel.com, tushar.vyavahare@intel.com
Cc: bpf@vger.kernel.org
Subject: [PATCH 5/5] selftests/xsk: Introduce mmap_size in umem struct
Date: Tue, 28 Apr 2026 13:33:16 +0530 [thread overview]
Message-ID: <20260428080317.702124-6-tushar.vyavahare@intel.com> (raw)
In-Reply-To: <20260428080317.702124-1-tushar.vyavahare@intel.com>
UMEM teardown currently recomputes the `munmap()` length
from frame geometry (`num_frames * frame_size`, shared-UMEM
multiplier, and hugepage rounding).
That duplicates setup logic in cleanup and makes teardown depend on
re-deriving values instead of using the exact mapping metadata.
Store the finalized mapping length in `xsk_umem_info` as `mmap_size` when
the UMEM mapping is created, and use that value during teardown.
This removes duplicated size arithmetic in cleanup and guarantees that
`munmap()` uses the same canonical size that was established at setup time.
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Tushar Vyavahare <tushar.vyavahare@intel.com>
---
tools/testing/selftests/bpf/prog_tests/test_xsk.c | 9 +++------
tools/testing/selftests/bpf/prog_tests/test_xsk.h | 1 +
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.c b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
index ba4768f83eb6..ba1bcfc6b74b 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_xsk.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
@@ -1594,6 +1594,8 @@ static int thread_common_ops(struct test_spec *test, struct ifobject *ifobject)
if (bufs == MAP_FAILED)
return -errno;
+ umem->mmap_size = ceil_u64(umem_sz, HUGEPAGE_SIZE) * HUGEPAGE_SIZE;
+
ret = xsk_configure_umem(ifobject, umem, bufs, umem_sz);
if (ret)
return ret;
@@ -1700,14 +1702,9 @@ void *worker_testapp_validate_rx(void *arg)
static void testapp_clean_xsk_umem(struct ifobject *ifobj)
{
struct xsk_umem_info *umem = ifobj->xsk->umem;
- u64 umem_sz = umem_size(umem);
-
- if (ifobj->shared_umem)
- umem_sz *= 2;
- umem_sz = ceil_u64(umem_sz, HUGEPAGE_SIZE) * HUGEPAGE_SIZE;
xsk_umem__delete(umem->umem);
- munmap(umem->buffer, umem_sz);
+ munmap(umem->buffer, umem->mmap_size);
}
static void handler(int signum)
diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.h b/tools/testing/selftests/bpf/prog_tests/test_xsk.h
index accda2456fe6..0355a9d06b4e 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_xsk.h
+++ b/tools/testing/selftests/bpf/prog_tests/test_xsk.h
@@ -85,6 +85,7 @@ struct xsk_umem_info {
struct xsk_ring_cons cq;
struct xsk_umem *umem;
u64 next_buffer;
+ u64 mmap_size;
u32 num_frames;
u32 frame_headroom;
void *buffer;
--
2.43.0
prev parent reply other threads:[~2026-04-28 8:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 8:03 [PATCH 0/5] selftests/xsk: foundational UMEM refactoring Tushar Vyavahare
2026-04-28 8:03 ` [PATCH 1/5] selftests/xsk: Introduce helpers for setting UMEM properties Tushar Vyavahare
2026-04-28 10:28 ` bot+bpf-ci
2026-04-28 12:39 ` Vyavahare, Tushar
2026-04-28 8:03 ` [PATCH 2/5] selftests/xsk: Eliminate umem reference from ifobject Tushar Vyavahare
2026-04-28 8:03 ` [PATCH 3/5] selftests/xsk: Remove umem from pkt_generate parameters Tushar Vyavahare
2026-04-28 8:03 ` [PATCH 4/5] selftests/xsk: Use umem_size() helper consistently Tushar Vyavahare
2026-04-28 8:03 ` Tushar Vyavahare [this message]
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=20260428080317.702124-6-tushar.vyavahare@intel.com \
--to=tushar.vyavahare@intel.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=kernelxing@tencent.com \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stfomichev@gmail.com \
--cc=tirthendu.sarkar@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox