🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
4 messages
4 total messages Started by Juanlu Herrero Tue, 10 Nov 2026 21:36
[PATCH 0/3] dma-debug: skip irrelevant buckets for partial syncs
#14210
Author: Juanlu Herrero
Date: Tue, 10 Nov 2026 21:36
36 lines
14184 bytes
Make the ZCRX area size configurable, skip DMA debug buckets that cannot
contain a partial sync, and add KUnit coverage for bucket bounds.

Earlier Fastio ZCRX registration means with DMA debug enabled:

  driver   pages    before     after      time saved
  mlx5      65536   4.720 s    0.942 s     3.778 s
  bnxt_en  131072  10.658 s    0.556 s    10.102 s

These runs used an earlier patch revision and workload. Later
SG-controlled CX7 runs showed no overall registration gain.

Validation: KUnit with KASAN/lockdep, W=1 build and checkpatch passed.

Codex assisted with implementation, review and validation.

Signed-off-by: Juanlu Herrero <juanlu@fastmail.com>
---
Juanlu Herrero (3):
      selftests: net: make iou-zcrx area size configurable
      dma-debug: skip irrelevant buckets for partial syncs
      dma-debug: add bucket bound lifetime coverage

 kernel/dma/Kconfig                                | 10 ++++
 kernel/dma/debug.c                                | 53 +++++++++++++++++----
 kernel/dma/tests/debug_kunit.c                    | 57 +++++++++++++++++++++++
 tools/testing/selftests/drivers/net/hw/iou-zcrx.c | 33 ++++++++++---
 4 files changed, 137 insertions(+), 16 deletions(-)
---
base-commit: 8ec20f45bd96cdc4c0faff4a6868aae52fab3827
change-id: 20261027-zcrx-dma-debug-registration-03221ef6a7d4

Best regards,
-- 
Juanlu Herrero
[PATCH 1/3] selftests: net: make iou-zcrx area size configurable
#14211
Author: Juanlu Herrero
Date: Tue, 10 Nov 2026 21:36
107 lines
16336 bytes
Add an -a option for selecting the area size in pages while keeping
8192 pages as the default. Combined with -d option, it allows
registration testing without running traffic.

Signed-off-by: Juanlu Herrero <juanlu@fastmail.com>
---
 tools/testing/selftests/drivers/net/hw/iou-zcrx.c | 33 ++++++++++++++++++-----
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c
index 91b025a8771e1..652b076d10fd5 100644
--- a/tools/testing/selftests/drivers/net/hw/iou-zcrx.c
+++ b/tools/testing/selftests/drivers/net/hw/iou-zcrx.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <assert.h>
+#include <ctype.h>
 #include <errno.h>
 #include <error.h>
 #include <fcntl.h>
@@ -59,7 +60,7 @@ struct t_io_uring_zcrx_ifq_reg {
 };
 
 static long page_size;
-#define AREA_SIZE (8192 * page_size)
+#define AREA_SIZE (cfg_area_pages * page_size)
 #define SEND_SIZE (512 * 4096)
 #define min(a, b) \
 	({ \
@@ -88,6 +89,7 @@ static int cfg_send_size = SEND_SIZE;
 static struct sockaddr_in6 cfg_addr;
 static unsigned int cfg_rx_buf_len;
 static bool cfg_dry_run;
+static size_t cfg_area_pages = 8192;
 static int cfg_num_threads = 1;
 
 static char *payload;
@@ -328,6 +330,7 @@ static void *server_worker(void *arg)
 	struct thread_ctx *ctx = arg;
 	uint64_t tstop;
 	int nr_conns;
+	int ret;
 	int i;
 
 	params.flags |= IORING_SETUP_COOP_TASKRUN;
@@ -336,9 +339,12 @@ static void *server_worker(void *arg)
 	params.flags |= IORING_SETUP_SUBMIT_ALL;
 	params.flags |= IORING_SETUP_CQE32;
 	params.flags |= IORING_SETUP_CQSIZE;
+	params.flags |= IORING_SETUP_CLAMP;
 	params.cq_entries = AREA_SIZE / page_size;
 
-	io_uring_queue_init_params(512, &ctx->ring, &params);
+	ret = io_uring_queue_init_params(512, &ctx->ring, &params);
+	if (ret)
+		error(1, -ret, "io_uring_queue_init_params()");
 	setup_zcrx(ctx);
 
 	if (cfg_dry_run)
@@ -574,9 +580,10 @@ static void run_client(void)
 
 static void usage(const char *filepath)
 {
-	error(1, 0, "Usage: %s (-4|-6) (-s|-c) -h<server_ip> -p<port> "
-		    "-l<payload_size> -i<ifname> -q<rxq_id> -t<num_threads>",
-		    filepath);
+	error(1, 0, "Usage: %s %s %s %s", filepath,
+	      "(-s|-c) -h<server_ip> -p<port>",
+	      "-l<payload_size> -i<ifname> -q<rxq_id>",
+	      "-t<num_threads> [-a<pages>] [-d]");
 }
 
 static void parse_opts(int argc, char **argv)
@@ -594,7 +601,7 @@ static void parse_opts(int argc, char **argv)
 		usage(argv[0]);
 	cfg_payload_len = max_payload_len;
 
-	while ((c = getopt(argc, argv, "sch:p:l:i:q:o:z:x:dt:")) != -1) {
+	while ((c = getopt(argc, argv, "sch:p:l:i:q:o:z:x:a:dt:")) != -1) {
 		switch (c) {
 		case 's':
 			if (cfg_client)
@@ -632,6 +639,20 @@ static void parse_opts(int argc, char **argv)
 		case 'x':
 			cfg_rx_buf_len = page_size * strtoul(optarg, NULL, 0);
 			break;
+		case 'a': {
+			char *end;
+			unsigned long long area_pages;
+
+			errno = 0;
+			area_pages = strtoull(optarg, &end, 0);
+			if (!isdigit((unsigned char)optarg[0]) || errno ||
+			    end == optarg || *end || !area_pages ||
+			    area_pages > UINT_MAX ||
+			    area_pages > SIZE_MAX / page_size)
+				error(1, 0, "invalid area page count: %s", optarg);
+			cfg_area_pages = area_pages;
+			break;
+		}
 		case 'd':
 			cfg_dry_run = true;
 			break;

-- 
2.53.0-Meta
[PATCH 2/3] dma-debug: skip irrelevant buckets for partial syncs
#14212
Author: Juanlu Herrero
Date: Tue, 10 Nov 2026 21:36
122 lines
16884 bytes
Partial syncs may start after a mapping's first hash bucket. Finding the
mapping then requires locking earlier buckets.

Keep a conservative size bound per bucket and skip those that cannot
span the sync range. Raise the bound on insertion and reset it when the
bucket empties. Stale larger bounds only add searches, so removal needs
no list rescan to update the bound.

This relies on ordered map publication before sync and unmapping after
sync. The bucket lock carries earlier bound updates through later
insertions even when the bound is unchanged.

Signed-off-by: Juanlu Herrero <juanlu@fastmail.com>
---
 kernel/dma/debug.c | 49 +++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 10 deletions(-)

diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
index 4cb5f86a7228a..8dad45d0a4360 100644
--- a/kernel/dma/debug.c
+++ b/kernel/dma/debug.c
@@ -90,6 +90,8 @@ typedef bool (*match_fn)(struct dma_debug_entry *, struct dma_debug_entry *);
 struct hash_bucket {
 	struct list_head list;
 	spinlock_t lock;
+	/* Upper bound on live mapping sizes; reset when the bucket empties. */
+	unsigned long max_entry_size;
 };
 
 /* Hash list to save the allocated dma addresses */
@@ -354,27 +356,49 @@ static struct dma_debug_entry *bucket_find_contain(struct hash_bucket **bucket,
 						   struct dma_debug_entry *ref,
 						   unsigned long *flags)
 {
-
 	struct dma_debug_entry *entry, index = *ref;
+	u64 min_offset = (index.dev_addr & ((1ULL << HASH_FN_SHIFT) - 1)) + 1;
 	int limit = min(HASH_SIZE, (index.dev_addr >> HASH_FN_SHIFT) + 1);
 
-	for (int i = 0; i < limit; i++) {
+	entry = __hash_bucket_find(*bucket, ref, containing_match);
+	if (entry)
+		return entry;
+	put_hash_bucket(*bucket, *flags);
+
+	for (int i = 1; i < limit; i++) {
+		unsigned long max_entry_size;
+
+		index.dev_addr -= (1 << HASH_FN_SHIFT);
+		*bucket = &dma_entry_hash[hash_fn(&index)];
+		/*
+		 * Writers serialize updates with the bucket lock. For any entry
+		 * that can validly match this sync, publishing the mapping is
+		 * ordered before the sync, including a cross-CPU handoff, and
+		 * unmapping is ordered after it. The bound only grows while the
+		 * bucket is nonempty, so it cannot become smaller than a live
+		 * entry. Removing an unrelated mapping may leave a larger bound,
+		 * which only causes an unnecessary search.
+		 */
+		max_entry_size = READ_ONCE((*bucket)->max_entry_size);
+		/* The mapping must span the distance back to this bucket. */
+		if (max_entry_size < ref->size ||
+		    max_entry_size - ref->size < min_offset)
+			goto next;
+
+		*bucket = get_hash_bucket(&index, flags);
 		entry = __hash_bucket_find(*bucket, ref, containing_match);
 
 		if (entry)
 			return entry;
 
-		/*
-		 * Nothing found, go back a hash bucket
-		 */
 		put_hash_bucket(*bucket, *flags);
-		index.dev_addr -= (1 << HASH_FN_SHIFT);
-		*bucket = get_hash_bucket(&index, flags);
+next:
+		min_offset += 1ULL << HASH_FN_SHIFT;
 	}
 
+	*bucket = get_hash_bucket(ref, flags);
 	return NULL;
 }
-
 /*
  * Add an entry to a hash bucket
  */
@@ -382,14 +406,19 @@ static void hash_bucket_add(struct hash_bucket *bucket,
 			    struct dma_debug_entry *entry)
 {
 	list_add_tail(&entry->list, &bucket->list);
+	if (entry->size > bucket->max_entry_size)
+		WRITE_ONCE(bucket->max_entry_size, entry->size);
 }
 
 /*
  * Remove entry from a hash bucket list
  */
-static void hash_bucket_del(struct dma_debug_entry *entry)
+static void hash_bucket_del(struct hash_bucket *bucket,
+			    struct dma_debug_entry *entry)
 {
 	list_del(&entry->list);
+	if (list_empty(&bucket->list))
+		WRITE_ONCE(bucket->max_entry_size, 0);
 }
 
 /*
@@ -1100,7 +1129,7 @@ static void check_unmap(struct dma_debug_entry *ref)
 	}
 #undef DMA_ATTR_UNMAP_VALID
 
-	hash_bucket_del(entry);
+	hash_bucket_del(bucket, entry);
 	put_hash_bucket(bucket, flags);
 
 	/*

-- 
2.53.0-Meta
[PATCH 3/3] dma-debug: add bucket bound lifetime coverage
#14213
Author: Juanlu Herrero
Date: Tue, 10 Nov 2026 21:36
111 lines
16655 bytes
Add a KUnit test on a local bucket for conservative bounds, equal-sized
mapping removal, empty-bucket reset and reuse. Exercise the existing
insertion and removal helpers without DMA hardware.

Signed-off-by: Juanlu Herrero <juanlu@fastmail.com>
---
 kernel/dma/Kconfig             | 10 ++++++++
 kernel/dma/debug.c             |  4 +++
 kernel/dma/tests/debug_kunit.c | 57 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+)

diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig
index 3830a63ae032d..3f295a1503597 100644
--- a/kernel/dma/Kconfig
+++ b/kernel/dma/Kconfig
@@ -291,6 +291,16 @@ config DMA_API_DEBUG
 
 	  If unsure, say N.
 
+config DMA_API_DEBUG_KUNIT_TEST
+	bool "Tests for DMA debug bucket bounds" if !KUNIT_ALL_TESTS
+	depends on KUNIT=y && DMA_API_DEBUG
+	default KUNIT_ALL_TESTS
+	help
+	  Enable KUnit (kernel unit test) coverage for DMA debug bucket bounds.
+	  Check that insertion and removal keep the bound conservative and
+	  reset it when a bucket becomes empty. Exercise reuse and equal-sized
+	  mappings on a local bucket. No physical DMA device is required.
+
 config DMA_MAP_BENCHMARK
 	bool "Enable benchmarking of streaming DMA mapping"
 	depends on DEBUG_FS
diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
index 8dad45d0a4360..1d0990e447516 100644
--- a/kernel/dma/debug.c
+++ b/kernel/dma/debug.c
@@ -1700,3 +1700,7 @@ static int __init dma_debug_driver_setup(char *str)
 	return 1;
 }
 __setup("dma_debug_driver=", dma_debug_driver_setup);
+
+#if IS_ENABLED(CONFIG_DMA_API_DEBUG_KUNIT_TEST)
+#include "tests/debug_kunit.c"
+#endif
diff --git a/kernel/dma/tests/debug_kunit.c b/kernel/dma/tests/debug_kunit.c
new file mode 100644
index 0000000000000..96cff02a6918d
--- /dev/null
+++ b/kernel/dma/tests/debug_kunit.c
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <kunit/test.h>
+#include <linux/sizes.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+
+static void dma_debug_bound_lifetime_test(struct kunit *test)
+{
+	struct dma_debug_entry *entries;
+	struct hash_bucket bucket = {};
+	unsigned long bounds[7];
+
+	entries = kunit_kcalloc(test, 3, sizeof(*entries), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, entries);
+	entries[0].size = SZ_4K;
+	entries[1].size = SZ_64K;
+	entries[2].size = SZ_64K;
+	INIT_LIST_HEAD(&bucket.list);
+	spin_lock_init(&bucket.lock);
+	spin_lock(&bucket.lock);
+	hash_bucket_add(&bucket, &entries[0]);
+	bounds[0] = bucket.max_entry_size;
+	hash_bucket_add(&bucket, &entries[1]);
+	hash_bucket_add(&bucket, &entries[2]);
+	bounds[1] = bucket.max_entry_size;
+	hash_bucket_del(&bucket, &entries[1]);
+	bounds[2] = bucket.max_entry_size;
+	hash_bucket_del(&bucket, &entries[2]);
+	bounds[3] = bucket.max_entry_size;
+	hash_bucket_del(&bucket, &entries[0]);
+	bounds[4] = bucket.max_entry_size;
+	hash_bucket_add(&bucket, &entries[0]);
+	bounds[5] = bucket.max_entry_size;
+	hash_bucket_del(&bucket, &entries[0]);
+	bounds[6] = bucket.max_entry_size;
+	spin_unlock(&bucket.lock);
+
+	KUNIT_EXPECT_GE(test, bounds[0], (unsigned long)SZ_4K);
+	KUNIT_EXPECT_GE(test, bounds[1], (unsigned long)SZ_64K);
+	KUNIT_EXPECT_GE(test, bounds[2], (unsigned long)SZ_64K);
+	KUNIT_EXPECT_GE(test, bounds[3], (unsigned long)SZ_4K);
+	KUNIT_EXPECT_EQ(test, bounds[4], 0UL);
+	KUNIT_EXPECT_GE(test, bounds[5], (unsigned long)SZ_4K);
+	KUNIT_EXPECT_EQ(test, bounds[6], 0UL);
+}
+
+static struct kunit_case dma_debug_bound_cases[] = {
+	KUNIT_CASE(dma_debug_bound_lifetime_test),
+	{}
+};
+
+static struct kunit_suite dma_debug_bound_suite = {
+	.name = "dma-debug-bound",
+	.test_cases = dma_debug_bound_cases,
+};
+
+kunit_test_suite(dma_debug_bound_suite);

-- 
2.53.0-Meta
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads