Commit ad11afd5 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Greg Kroah-Hartman

locking/locktorture: Fix num reader/writer corner cases


[ Upstream commit 2ce77d16 ]

Things can explode for locktorture if the user does combinations
of nwriters_stress=0 nreaders_stress=0. Fix this by not assuming
we always want to torture writer threads.
Reported-by: default avatarJeremy Linton <jeremy.linton@arm.com>
Signed-off-by: default avatarDavidlohr Bueso <dbueso@suse.de>
Signed-off-by: default avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Reviewed-by: default avatarJeremy Linton <jeremy.linton@arm.com>
Tested-by: default avatarJeremy Linton <jeremy.linton@arm.com>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 992cfe95
...@@ -641,8 +641,7 @@ static void __torture_print_stats(char *page, ...@@ -641,8 +641,7 @@ static void __torture_print_stats(char *page,
{ {
bool fail = 0; bool fail = 0;
int i, n_stress; int i, n_stress;
long max = 0; long max = 0, min = statp ? statp[0].n_lock_acquired : 0;
long min = statp[0].n_lock_acquired;
long long sum = 0; long long sum = 0;
n_stress = write ? cxt.nrealwriters_stress : cxt.nrealreaders_stress; n_stress = write ? cxt.nrealwriters_stress : cxt.nrealreaders_stress;
...@@ -749,7 +748,7 @@ static void lock_torture_cleanup(void) ...@@ -749,7 +748,7 @@ static void lock_torture_cleanup(void)
* such, only perform the underlying torture-specific cleanups, * such, only perform the underlying torture-specific cleanups,
* and avoid anything related to locktorture. * and avoid anything related to locktorture.
*/ */
if (!cxt.lwsa) if (!cxt.lwsa && !cxt.lrsa)
goto end; goto end;
if (writer_tasks) { if (writer_tasks) {
...@@ -823,6 +822,13 @@ static int __init lock_torture_init(void) ...@@ -823,6 +822,13 @@ static int __init lock_torture_init(void)
firsterr = -EINVAL; firsterr = -EINVAL;
goto unwind; goto unwind;
} }
if (nwriters_stress == 0 && nreaders_stress == 0) {
pr_alert("lock-torture: must run at least one locking thread\n");
firsterr = -EINVAL;
goto unwind;
}
if (cxt.cur_ops->init) if (cxt.cur_ops->init)
cxt.cur_ops->init(); cxt.cur_ops->init();
...@@ -846,7 +852,7 @@ static int __init lock_torture_init(void) ...@@ -846,7 +852,7 @@ static int __init lock_torture_init(void)
#endif #endif
/* Initialize the statistics so that each run gets its own numbers. */ /* Initialize the statistics so that each run gets its own numbers. */
if (nwriters_stress) {
lock_is_write_held = 0; lock_is_write_held = 0;
cxt.lwsa = kmalloc(sizeof(*cxt.lwsa) * cxt.nrealwriters_stress, GFP_KERNEL); cxt.lwsa = kmalloc(sizeof(*cxt.lwsa) * cxt.nrealwriters_stress, GFP_KERNEL);
if (cxt.lwsa == NULL) { if (cxt.lwsa == NULL) {
...@@ -854,10 +860,12 @@ static int __init lock_torture_init(void) ...@@ -854,10 +860,12 @@ static int __init lock_torture_init(void)
firsterr = -ENOMEM; firsterr = -ENOMEM;
goto unwind; goto unwind;
} }
for (i = 0; i < cxt.nrealwriters_stress; i++) { for (i = 0; i < cxt.nrealwriters_stress; i++) {
cxt.lwsa[i].n_lock_fail = 0; cxt.lwsa[i].n_lock_fail = 0;
cxt.lwsa[i].n_lock_acquired = 0; cxt.lwsa[i].n_lock_acquired = 0;
} }
}
if (cxt.cur_ops->readlock) { if (cxt.cur_ops->readlock) {
if (nreaders_stress >= 0) if (nreaders_stress >= 0)
...@@ -873,6 +881,7 @@ static int __init lock_torture_init(void) ...@@ -873,6 +881,7 @@ static int __init lock_torture_init(void)
cxt.nrealreaders_stress = cxt.nrealwriters_stress; cxt.nrealreaders_stress = cxt.nrealwriters_stress;
} }
if (nreaders_stress) {
lock_is_read_held = 0; lock_is_read_held = 0;
cxt.lrsa = kmalloc(sizeof(*cxt.lrsa) * cxt.nrealreaders_stress, GFP_KERNEL); cxt.lrsa = kmalloc(sizeof(*cxt.lrsa) * cxt.nrealreaders_stress, GFP_KERNEL);
if (cxt.lrsa == NULL) { if (cxt.lrsa == NULL) {
...@@ -888,6 +897,7 @@ static int __init lock_torture_init(void) ...@@ -888,6 +897,7 @@ static int __init lock_torture_init(void)
cxt.lrsa[i].n_lock_acquired = 0; cxt.lrsa[i].n_lock_acquired = 0;
} }
} }
}
lock_torture_print_module_parms(cxt.cur_ops, "Start of test"); lock_torture_print_module_parms(cxt.cur_ops, "Start of test");
...@@ -915,6 +925,7 @@ static int __init lock_torture_init(void) ...@@ -915,6 +925,7 @@ static int __init lock_torture_init(void)
goto unwind; goto unwind;
} }
if (nwriters_stress) {
writer_tasks = kzalloc(cxt.nrealwriters_stress * sizeof(writer_tasks[0]), writer_tasks = kzalloc(cxt.nrealwriters_stress * sizeof(writer_tasks[0]),
GFP_KERNEL); GFP_KERNEL);
if (writer_tasks == NULL) { if (writer_tasks == NULL) {
...@@ -922,6 +933,7 @@ static int __init lock_torture_init(void) ...@@ -922,6 +933,7 @@ static int __init lock_torture_init(void)
firsterr = -ENOMEM; firsterr = -ENOMEM;
goto unwind; goto unwind;
} }
}
if (cxt.cur_ops->readlock) { if (cxt.cur_ops->readlock) {
reader_tasks = kzalloc(cxt.nrealreaders_stress * sizeof(reader_tasks[0]), reader_tasks = kzalloc(cxt.nrealreaders_stress * sizeof(reader_tasks[0]),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment