Patch "locking/locktorture: Fix num reader/writer corner cases" has been added to the 4.9-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
locking/locktorture: Fix num reader/writer corner cases
to the 4.9-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
locking-locktorture-fix-num-reader-writer-corner-cases.patch
and it can be found in the queue-4.9 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From foo@baz Sun Mar 18 16:55:33 CET 2018
From: Davidlohr Bueso <[email protected]>
Date: Mon, 15 May 2017 02:07:23 -0700
Subject: locking/locktorture: Fix num reader/writer corner cases
From: Davidlohr Bueso <[email protected]>
[ Upstream commit 2ce77d16db4240dd2e422fc0a5c26d3e2ec03446 ]
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.
--- kernel/locking/locktorture.c | 76 ++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 32 deletions(-)
kernel/locking/locktorture.c +44 -32
@@ -641,8 +641,7 @@ static void __torture_print_stats(char * {bool fail =0 ;int i, n_stress; -long max =0 ; -long min = statp[0 ].n_lock_acquired; +long max =0 , min = statp ? statp[0 ].n_lock_acquired :0 ;long long sum =0 ; n_stress = write ? cxt.nrealwriters_stress : cxt.nrealreaders_stress;
@@ -749,7 +748,7 @@ static void lock_torture_cleanup(void)* such, only perform the underlying torture-specific cleanups, * and avoid anything related to locktorture. */ -if (!cxt.lwsa) +if (!cxt.lwsa && !cxt.lrsa) goto end;if (writer_tasks) {
@@ -823,6 +822,13 @@ static int __init lock_torture_init(void firsterr = -EINVAL ; 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) cxt.cur_ops->init ();
@@ -846,17 +852,19 @@ static int __init lock_torture_init(void#endif /* Initialize the statistics so that each run gets its own numbers. */ +if (nwriters_stress) { + lock_is_write_held =0 ; + cxt.lwsa =kmalloc (sizeof (*cxt.lwsa) * cxt.nrealwriters_stress,GFP_KERNEL ); +if (cxt.lwsa ==NULL ) { +VERBOSE_TOROUT_STRING ("cxt.lwsa: Out of memory" ); + firsterr = -ENOMEM ; + goto unwind; + } - lock_is_write_held =0 ; - cxt.lwsa =kmalloc (sizeof (*cxt.lwsa) * cxt.nrealwriters_stress,GFP_KERNEL ); -if (cxt.lwsa ==NULL ) { -VERBOSE_TOROUT_STRING ("cxt.lwsa: Out of memory" ); - firsterr = -ENOMEM ; - goto unwind; - } -for (i =0 ; i < cxt.nrealwriters_stress; i++) { - cxt.lwsa[i].n_lock_fail =0 ; - cxt.lwsa[i].n_lock_acquired =0 ; +for (i =0 ; i < cxt.nrealwriters_stress; i++) { + cxt.lwsa[i].n_lock_fail =0 ; + cxt.lwsa[i].n_lock_acquired =0 ; + } }if (cxt.cur_ops->readlock) {
@@ -873,19 +881,21 @@ static int __init lock_torture_init(void cxt.nrealreaders_stress = cxt.nrealwriters_stress; } - lock_is_read_held =0 ; - cxt.lrsa =kmalloc (sizeof (*cxt.lrsa) * cxt.nrealreaders_stress,GFP_KERNEL ); -if (cxt.lrsa ==NULL ) { -VERBOSE_TOROUT_STRING ("cxt.lrsa: Out of memory" ); - firsterr = -ENOMEM ; -kfree (cxt.lwsa); - cxt.lwsa =NULL ; - goto unwind; - } - -for (i =0 ; i < cxt.nrealreaders_stress; i++) { - cxt.lrsa[i].n_lock_fail =0 ; - cxt.lrsa[i].n_lock_acquired =0 ; +if (nreaders_stress) { + lock_is_read_held =0 ; + cxt.lrsa =kmalloc (sizeof (*cxt.lrsa) * cxt.nrealreaders_stress,GFP_KERNEL ); +if (cxt.lrsa ==NULL ) { +VERBOSE_TOROUT_STRING ("cxt.lrsa: Out of memory" ); + firsterr = -ENOMEM ; +kfree (cxt.lwsa); + cxt.lwsa =NULL ; + goto unwind; + } + +for (i =0 ; i < cxt.nrealreaders_stress; i++) { + cxt.lrsa[i].n_lock_fail =0 ; + cxt.lrsa[i].n_lock_acquired =0 ; + } } }
@@ -915,12 +925,14 @@ static int __init lock_torture_init(void goto unwind; } - writer_tasks =kzalloc (cxt.nrealwriters_stress *sizeof (writer_tasks[0 ]), -GFP_KERNEL ); -if (writer_tasks ==NULL ) { -VERBOSE_TOROUT_ERRSTRING ("writer_tasks: Out of memory" ); - firsterr = -ENOMEM ; - goto unwind; +if (nwriters_stress) { + writer_tasks =kzalloc (cxt.nrealwriters_stress *sizeof (writer_tasks[0 ]), +GFP_KERNEL ); +if (writer_tasks ==NULL ) { +VERBOSE_TOROUT_ERRSTRING ("writer_tasks: Out of memory" ); + firsterr = -ENOMEM ; + goto unwind; + } }if (cxt.cur_ops->readlock) {
Patches currently in stable-queue which might be from [email protected] are
queue-4.9/locking-locktorture-fix-num-reader-writer-corner-cases.patch