Skip to contentSkip to conversation

dmaengine: dmatest: Fix iteration non-stop logic

PATCH Applied Andy Shevchenko 3 participants 13 messages Apr 24, 2020 – Apr 27, 2020 dmaengine

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 dmaengine: dmatest: Fix iteration non-stop logic

Under some circumstances, i.e. when test is still running and about to time out and user runs, for example,

grep -H . /sys/module/dmatest/parameters/*

the iterations parameter is not respected and test is going on and on until user gives

echo 0 > /sys/module/dmatest/parameters/run

This is not what expected.

The history of this bug is interesting. I though that the commit
2d88ce76eb98 ("dmatest: add a 'wait' parameter")
is a culprit, but looking closer to the code I think it simple revealed the broken logic from the day one, i.e. in the commit
0a2ff57d6fba ("dmaengine: dmatest: add a maximum number of test iterations")
which adds iterations parameter.

So, to the point, the conditional of checking the thread to be stopped being first part of conjunction logic prevents to check iterations. Thus, we have to always check both conditions to be able to stop after given iterations.

Since it wasn't visible before second commit appeared, I add a respective Fixes tag.

Fixes 2d88ce76eb98 ("dmatest: add a 'wait' parameter")
Cc Dan Williams <[email protected]>
Cc Nicolas Ferre <[email protected]>
---
 drivers/dma/dmatest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/dmatest.c +2 -2
index a2cadfa2e6d78..4993e3e5c5b01 100644
@@ -662,8 +662,8 @@ static int dmatest_func(void *data)
 		flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
 
 	ktime = ktime_get();
-	while (!kthread_should_stop()
-	       && !(params->iterations && total_tests >= params->iterations)) {
+	while (!(kthread_should_stop() ||
+	       (params->iterations && total_tests >= params->iterations))) {
 		struct dma_async_tx_descriptor *tx = NULL;
 		struct dmaengine_unmap_data *um;
 		dma_addr_t *dsts;
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/6 dmaengine: dmatest: Fix process hang when reading 'wait' parameter

If we do

% echo 1 > /sys/module/dmatest/parameters/run

  [  115.851124] dmatest: Could not start test, no channels configured

% echo dma8chan7 > /sys/module/dmatest/parameters/channel

  [  127.563872] dmatest: Added 1 threads using dma8chan7

% cat /sys/module/dmatest/parameters/wait
... !!! HANG !!! ...

The culprit is the commit 6138f967bccc

("dmaengine: dmatest: Use fixed point div to calculate iops")

which makes threads not to run, but pending and being kicked off by writing to the 'run' node. However, it forgot to consider 'wait' routine to avoid above mentioned case.

In order to fix this, check for really running threads, i.e. with pending and done flags unset.

It's pity the culprit commit hadn't updated documentation and tested all possible scenarios.

Fixes 6138f967bccc ("dmaengine: dmatest: Use fixed point div to calculate iops")
Cc Seraj Alijan <[email protected]>
---
 drivers/dma/dmatest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/dmatest.c +2 -2
index 4993e3e5c5b01..307622e765996 100644
@@ -240,7 +240,7 @@ static bool is_threaded_test_run(struct dmatest_info *info)
 		struct dmatest_thread *thread;
 
 		list_for_each_entry(thread, &dtc->threads, node) {
-			if (!thread->done)
+			if (!thread->done && !thread->pending)
 				return true;
 		}
 	}
@@ -1192,7 +1192,7 @@ static int dmatest_chan_set(const char *val, const struct kernel_param *kp)
 		mutex_unlock(&info->lock);
 		return ret;
 	}
-	/*Clear any previously run threads */
+	/* Clear any previously run threads */
 	if (!is_threaded_test_run(info) && !is_threaded_test_pending(info))
 		stop_threaded_test(info);
 	/* Reject channels that are already registered */
Signature · 1 line
2.26.2
#9 lore raw

PATCH 6/6 dmaengine: dmatest: Describe members of struct dmatest_info

In reply to Andy Shevchenko

Kernel documentation validator complains that not all members of struct dmatest_info are being described. Describe them all.

---
 drivers/dma/dmatest.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/dma/dmatest.c +3 -0
index 946b03859cdec..31ba5d7b6ae8c 100644
@@ -125,7 +125,10 @@ struct dmatest_params {
 /**
  * struct dmatest_info - test information.
  * @params:		test parameters
+ * @channels:		channels under test
+ * @nr_channels:	number of channels under test
  * @lock:		access protection to the fields of this structure
+ * @did_init:		module has been initialized completely
  */
 static struct dmatest_info {
 	/* Test parameters */
Signature · 1 line
2.26.2
#5 lore raw

PATCH 4/6 dmaengine: dmatest: Allow negative timeout value to specify infinite wait

In reply to Andy Shevchenko

The dmatest module parameter 'timeout' is documented as accepting a -1 to mean "infinite timeout". However, an infinite timeout is not advised, nor possible since the module parameter is an unsigned int, which won't accept a negative value. Change the parameter type to be signed integer.

---
 drivers/dma/dmatest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dmatest.c +1 -1
index a521067751651..123b4bd41a085 100644
@@ -60,7 +60,7 @@ MODULE_PARM_DESC(pq_sources,
 		"Number of p+q source buffers (default: 3)");
 
 static int timeout = 3000;
-module_param(timeout, uint, S_IRUGO | S_IWUSR);
+module_param(timeout, int, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(timeout, "Transfer Timeout in msec (default: 3000), "
 		 "Pass -1 for infinite timeout");
 
Signature · 1 line
2.26.2
#7 lore raw

PATCH 5/6 dmaengine: dmatest: Describe members of struct dmatest_params

In reply to Andy Shevchenko

Kernel documentation validator complains that not all members of struct dmatest_params are being described. Describe them all.

---
 drivers/dma/dmatest.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/dma/dmatest.c +9 -4
index 123b4bd41a085..946b03859cdec 100644
@@ -72,10 +72,6 @@ static bool norandom;
 module_param(norandom, bool, 0644);
 MODULE_PARM_DESC(norandom, "Disable random offset setup (default: random)");
 
-static bool polled;
-module_param(polled, bool, S_IRUGO | S_IWUSR);
-MODULE_PARM_DESC(polled, "Use polling for completion instead of interrupts");
-
 static bool verbose;
 module_param(verbose, bool, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(verbose, "Enable \"success\" result messages (default: off)");
@@ -88,6 +84,10 @@ static unsigned int transfer_size;
 module_param(transfer_size, uint, 0644);
 MODULE_PARM_DESC(transfer_size, "Optional custom transfer size in bytes (default: not used (0))");
 
+static bool polled;
+module_param(polled, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(polled, "Use polling for completion instead of interrupts");
+
 /**
  * struct dmatest_params - test parameters.
  * @buf_size:		size of the memcpy test buffer
@@ -99,6 +99,11 @@ MODULE_PARM_DESC(transfer_size, "Optional custom transfer size in bytes (default
  * @xor_sources:	number of xor source buffers
  * @pq_sources:		number of p+q source buffers
  * @timeout:		transfer timeout in msec, -1 for infinite timeout
+ * @noverify:		disable data verification
+ * @norandom:		disable random offset setup
+ * @alignment:		custom data address alignment taken as 2^alignment
+ * @transfer_size:	custom transfer size in bytes
+ * @polled:		use polling for completion instead of interrupts
  */
 struct dmatest_params {
 	unsigned int	buf_size;
Signature · 1 line
2.26.2
#3 lore raw

PATCH 3/6 Revert "dmaengine: dmatest: timeout value of -1 should specify infinite wait"

In reply to Andy Shevchenko

This reverts commit ed04b7c57c3383ed4573f1d1d1dbdc1108ba0bed.

While it gives a good description what happens, the approach seems too confusing. Let's fix it in the following patch.

---
 drivers/dma/dmatest.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/dma/dmatest.c +3 -3
index 307622e765996..a521067751651 100644
@@ -62,7 +62,7 @@ MODULE_PARM_DESC(pq_sources,
 static int timeout = 3000;
 module_param(timeout, uint, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(timeout, "Transfer Timeout in msec (default: 3000), "
-		 "Pass 0xFFFFFFFF (4294967295) for maximum timeout");
+		 "Pass -1 for infinite timeout");
 
 static bool noverify;
 module_param(noverify, bool, S_IRUGO | S_IWUSR);
@@ -98,7 +98,7 @@ MODULE_PARM_DESC(transfer_size, "Optional custom transfer size in bytes (default
  * @iterations:		iterations before stopping test
  * @xor_sources:	number of xor source buffers
  * @pq_sources:		number of p+q source buffers
- * @timeout:		transfer timeout in msec, 0 - 0xFFFFFFFF (4294967295)
+ * @timeout:		transfer timeout in msec, -1 for infinite timeout
  */
 struct dmatest_params {
 	unsigned int	buf_size;
@@ -109,7 +109,7 @@ struct dmatest_params {
 	unsigned int	iterations;
 	unsigned int	xor_sources;
 	unsigned int	pq_sources;
-	unsigned int	timeout;
+	int		timeout;
 	bool		noverify;
 	bool		norandom;
 	int		alignment;
Signature · 1 line
2.26.2
Acked-by on v1 1/6
#11 lore raw
In reply to Andy Shevchenko

Andy,

Quoted 23 lines · Andy Shevchenko

Under some circumstances, i.e. when test is still running and about to time out and user runs, for example,

grep -H . /sys/module/dmatest/parameters/*

the iterations parameter is not respected and test is going on and on until user gives

echo 0 > /sys/module/dmatest/parameters/run

This is not what expected.

The history of this bug is interesting. I though that the commit
2d88ce76eb98 ("dmatest: add a 'wait' parameter")
is a culprit, but looking closer to the code I think it simple revealed the broken logic from the day one, i.e. in the commit
0a2ff57d6fba ("dmaengine: dmatest: add a maximum number of test iterations")
which adds iterations parameter.

So, to the point, the conditional of checking the thread to be stopped being first part of conjunction logic prevents to check iterations. Thus, we have to always check both conditions to be able to stop after given iterations.

Quoted 6 lines

Since it wasn't visible before second commit appeared, I add a respective Fixes tag.

Fixes 2d88ce76eb98 ("dmatest: add a 'wait' parameter")
Cc Dan Williams <[email protected]>
Cc Nicolas Ferre <[email protected]>

Yes, makes sense indeed:

Quoted 23 lines
---
  drivers/dma/dmatest.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/dmatest.c +2 -3
index a2cadfa2e6d78..4993e3e5c5b01 100644
@@ -662,8 +662,8 @@ static int dmatest_func(void *data)
                 flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
 
         ktime = ktime_get();
-       while (!kthread_should_stop()
-              && !(params->iterations && total_tests >= params->iterations)) {
+       while (!(kthread_should_stop() ||
+              (params->iterations && total_tests >= params->iterations))) {
                 struct dma_async_tx_descriptor *tx = NULL;
                 struct dmaengine_unmap_data *um;
                 dma_addr_t *dsts;
--

2.26.2

Signature · 1 line
Nicolas Ferre
maintainer Applied
#12 lore raw
In reply to Andy Shevchenko
Quoted 19 lines · Andy Shevchenko

Under some circumstances, i.e. when test is still running and about to time out and user runs, for example,

grep -H . /sys/module/dmatest/parameters/*

the iterations parameter is not respected and test is going on and on until user gives

echo 0 > /sys/module/dmatest/parameters/run

This is not what expected.

The history of this bug is interesting. I though that the commit
2d88ce76eb98 ("dmatest: add a 'wait' parameter")
is a culprit, but looking closer to the code I think it simple revealed the broken logic from the day one, i.e. in the commit
0a2ff57d6fba ("dmaengine: dmatest: add a maximum number of test iterations")
which adds iterations parameter.

Quoted 6 lines

So, to the point, the conditional of checking the thread to be stopped being first part of conjunction logic prevents to check iterations. Thus, we have to always check both conditions to be able to stop after given iterations.

Since it wasn't visible before second commit appeared, I add a respective Fixes tag.

Applied, thanks

Signature · 1 line
~Vinod
maintainer
#2 lore raw

Re: [PATCH v1 2/6] dmaengine: dmatest: Fix process hang when reading 'wait' parameter

In reply to Andy Shevchenko
Quoted 46 lines · Andy Shevchenko

If we do

% echo 1 > /sys/module/dmatest/parameters/run

  [  115.851124] dmatest: Could not start test, no channels configured

% echo dma8chan7 > /sys/module/dmatest/parameters/channel

  [  127.563872] dmatest: Added 1 threads using dma8chan7

% cat /sys/module/dmatest/parameters/wait
... !!! HANG !!! ...

The culprit is the commit 6138f967bccc

("dmaengine: dmatest: Use fixed point div to calculate iops")

which makes threads not to run, but pending and being kicked off by writing to the 'run' node. However, it forgot to consider 'wait' routine to avoid above mentioned case.

In order to fix this, check for really running threads, i.e. with pending and done flags unset.

It's pity the culprit commit hadn't updated documentation and tested all possible scenarios.

Fixes 6138f967bccc ("dmaengine: dmatest: Use fixed point div to calculate iops")
Cc Seraj Alijan <[email protected]>
---
 drivers/dma/dmatest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/dmatest.c +1 -1
index 4993e3e5c5b01..307622e765996 100644
@@ -240,7 +240,7 @@ static bool is_threaded_test_run(struct dmatest_info *info)
 		struct dmatest_thread *thread;
 
 		list_for_each_entry(thread, &dtc->threads, node) {
-			if (!thread->done)
+			if (!thread->done && !thread->pending)
 				return true;
 		}
 	}

drivers/dma/dmatest.c static int dmatest_chan_set(const char *val, const struct kernel_param *kp) · line 1195

Quoted 5 lines
drivers/dma/dmatest.c +1 -1
@@ -1192,7 +1192,7 @@ static int dmatest_chan_set(const char *val, const struct kernel_param *kp)
 		mutex_unlock(&info->lock);
 		return ret;
 	}
-	/*Clear any previously run threads */
+	/* Clear any previously run threads */

This does not belong to this patch, can you please split it out...

Signature · 1 line
~Vinod
maintainer Applied
#4 lore raw

Re: [PATCH v1 3/6] Revert "dmaengine: dmatest: timeout value of -1 should specify infinite wait"

In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

This reverts commit ed04b7c57c3383ed4573f1d1d1dbdc1108ba0bed.

While it gives a good description what happens, the approach seems too confusing. Let's fix it in the following patch.

Applied, thanks

Signature · 1 line
~Vinod
maintainer Applied
#6 lore raw

Re: [PATCH v1 4/6] dmaengine: dmatest: Allow negative timeout value to specify infinite wait

In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

The dmatest module parameter 'timeout' is documented as accepting a -1 to mean "infinite timeout". However, an infinite timeout is not advised, nor possible since the module parameter is an unsigned int, which won't accept a negative value. Change the parameter type to be signed integer.

Applied, thanks

Signature · 1 line
~Vinod
maintainer Applied
#8 lore raw

Re: [PATCH v1 5/6] dmaengine: dmatest: Describe members of struct dmatest_params

In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

Kernel documentation validator complains that not all members of struct dmatest_params are being described. Describe them all.

Applied, thanks

Signature · 1 line
~Vinod
maintainer Applied
#10 lore raw

Re: [PATCH v1 6/6] dmaengine: dmatest: Describe members of struct dmatest_info

In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

Kernel documentation validator complains that not all members of struct dmatest_info are being described. Describe them all.

Applied, thanks

Signature · 1 line
~Vinod