From: Luis Chamberlain <mcgrof@kernel.org>
To: vkoul@kernel.org, chenxiang66@hisilicon.com,
m.szyprowski@samsung.com, robin.murphy@arm.com, leon@kernel.org,
jgg@nvidia.com, alex.williamson@redhat.com,
joel.granados@kernel.org
Cc: iommu@lists.linux.dev, dmaengine@vger.kernel.org,
linux-block@vger.kernel.org, gost.dev@samsung.com,
mcgrof@kernel.org
Subject: [PATCH 5/6] dma-mapping: benchmark: move validation parameters into a helper
Date: Tue, 20 May 2025 15:39:12 -0700 [thread overview]
Message-ID: <20250520223913.3407136-6-mcgrof@kernel.org> (raw)
In-Reply-To: <20250520223913.3407136-1-mcgrof@kernel.org>
Before we run the benchmark we validate the input parameters. Move
this into a helper so we can also use this for other type of DMA
benchmark tests. This will be used in a subsequent patch for another
type of DMA benchmark.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
kernel/dma/map_benchmark.c | 99 +++++++++++++++++++++-----------------
1 file changed, 54 insertions(+), 45 deletions(-)
diff --git a/kernel/dma/map_benchmark.c b/kernel/dma/map_benchmark.c
index cc19a3efea89..b54345a757cb 100644
--- a/kernel/dma/map_benchmark.c
+++ b/kernel/dma/map_benchmark.c
@@ -196,6 +196,55 @@ static int do_map_benchmark(struct map_benchmark_data *map)
return ret;
}
+static int validate_benchmark_params(struct map_benchmark_data *map)
+{
+ if (map->bparam.threads == 0 ||
+ map->bparam.threads > DMA_MAP_MAX_THREADS) {
+ pr_err("invalid thread number\n");
+ return -EINVAL;
+ }
+
+ if (map->bparam.seconds == 0 ||
+ map->bparam.seconds > DMA_MAP_MAX_SECONDS) {
+ pr_err("invalid duration seconds\n");
+ return -EINVAL;
+ }
+
+ if (map->bparam.dma_trans_ns > DMA_MAP_MAX_TRANS_DELAY) {
+ pr_err("invalid transmission delay\n");
+ return -EINVAL;
+ }
+
+ if (map->bparam.node != NUMA_NO_NODE &&
+ (map->bparam.node < 0 || map->bparam.node >= MAX_NUMNODES ||
+ !node_possible(map->bparam.node))) {
+ pr_err("invalid numa node\n");
+ return -EINVAL;
+ }
+
+ if (map->bparam.granule < 1 || map->bparam.granule > 1024) {
+ pr_err("invalid granule size\n");
+ return -EINVAL;
+ }
+
+ switch (map->bparam.dma_dir) {
+ case DMA_MAP_BIDIRECTIONAL:
+ map->dir = DMA_BIDIRECTIONAL;
+ break;
+ case DMA_MAP_FROM_DEVICE:
+ map->dir = DMA_FROM_DEVICE;
+ break;
+ case DMA_MAP_TO_DEVICE:
+ map->dir = DMA_TO_DEVICE;
+ break;
+ default:
+ pr_err("invalid DMA direction\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static long map_benchmark_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
@@ -207,54 +256,13 @@ static long map_benchmark_ioctl(struct file *file, unsigned int cmd,
if (copy_from_user(&map->bparam, argp, sizeof(map->bparam)))
return -EFAULT;
+ ret = validate_benchmark_params(map);
+ if (ret)
+ return ret;
+
switch (cmd) {
case DMA_MAP_BENCHMARK:
- if (map->bparam.threads == 0 ||
- map->bparam.threads > DMA_MAP_MAX_THREADS) {
- pr_err("invalid thread number\n");
- return -EINVAL;
- }
-
- if (map->bparam.seconds == 0 ||
- map->bparam.seconds > DMA_MAP_MAX_SECONDS) {
- pr_err("invalid duration seconds\n");
- return -EINVAL;
- }
-
- if (map->bparam.dma_trans_ns > DMA_MAP_MAX_TRANS_DELAY) {
- pr_err("invalid transmission delay\n");
- return -EINVAL;
- }
-
- if (map->bparam.node != NUMA_NO_NODE &&
- (map->bparam.node < 0 || map->bparam.node >= MAX_NUMNODES ||
- !node_possible(map->bparam.node))) {
- pr_err("invalid numa node\n");
- return -EINVAL;
- }
-
- if (map->bparam.granule < 1 || map->bparam.granule > 1024) {
- pr_err("invalid granule size\n");
- return -EINVAL;
- }
-
- switch (map->bparam.dma_dir) {
- case DMA_MAP_BIDIRECTIONAL:
- map->dir = DMA_BIDIRECTIONAL;
- break;
- case DMA_MAP_FROM_DEVICE:
- map->dir = DMA_FROM_DEVICE;
- break;
- case DMA_MAP_TO_DEVICE:
- map->dir = DMA_TO_DEVICE;
- break;
- default:
- pr_err("invalid DMA direction\n");
- return -EINVAL;
- }
-
old_dma_mask = dma_get_mask(map->dev);
-
ret = dma_set_mask(map->dev,
DMA_BIT_MASK(map->bparam.dma_bits));
if (ret) {
@@ -263,6 +271,7 @@ static long map_benchmark_ioctl(struct file *file, unsigned int cmd,
return -EINVAL;
}
+ /* Run streaming DMA benchmark */
ret = do_map_benchmark(map);
/*
--
2.47.2
next prev parent reply other threads:[~2025-05-20 22:39 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-20 22:39 [PATCH 0/6] dma: fake-dma and IOVA tests Luis Chamberlain
2025-05-20 22:39 ` [PATCH 1/6] fake-dma: add fake dma engine driver Luis Chamberlain
2025-05-21 14:20 ` Robin Murphy
2025-05-21 17:07 ` Luis Chamberlain
2025-05-22 11:18 ` Marek Szyprowski
2025-05-22 16:59 ` Luis Chamberlain
2025-05-22 19:38 ` Luis Chamberlain
2025-05-21 23:40 ` kernel test robot
2025-05-20 22:39 ` [PATCH 2/6] dmatest: split dmatest_func() into helpers Luis Chamberlain
2025-05-20 22:39 ` [PATCH 3/6] dmatest: move printing to its own routine Luis Chamberlain
2025-05-21 14:41 ` Robin Murphy
2025-05-21 17:10 ` Luis Chamberlain
2025-05-21 22:26 ` kernel test robot
2025-05-20 22:39 ` [PATCH 4/6] dmatest: add IOVA tests Luis Chamberlain
2025-05-20 22:39 ` Luis Chamberlain [this message]
2025-05-20 22:39 ` [PATCH 6/6] dma-mapping: benchmark: add IOVA support Luis Chamberlain
2025-05-21 11:58 ` kernel test robot
2025-05-21 16:08 ` Robin Murphy
2025-05-21 17:17 ` Luis Chamberlain
2025-05-21 11:17 ` [PATCH 0/6] dma: fake-dma and IOVA tests Leon Romanovsky
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=20250520223913.3407136-6-mcgrof@kernel.org \
--to=mcgrof@kernel.org \
--cc=alex.williamson@redhat.com \
--cc=chenxiang66@hisilicon.com \
--cc=dmaengine@vger.kernel.org \
--cc=gost.dev@samsung.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joel.granados@kernel.org \
--cc=leon@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=robin.murphy@arm.com \
--cc=vkoul@kernel.org \
/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