aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/locking
diff options
context:
space:
mode:
authorDavidlohr Bueso <dave@stgolabs.net>2017-05-15 05:07:23 -0400
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2017-12-11 12:18:28 -0500
commit2ce77d16db4240dd2e422fc0a5c26d3e2ec03446 (patch)
treefbce40ef15840b4aecb33f0c5744aa2a0fe1c2fb /kernel/locking
parentf2f762608f45353b0b8c37507824f95bb716c3d5 (diff)
locking/locktorture: Fix num reader/writer corner cases
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: Jeremy Linton <jeremy.linton@arm.com> Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Reviewed-by: Jeremy Linton <jeremy.linton@arm.com> Tested-by: Jeremy Linton <jeremy.linton@arm.com>
Diffstat (limited to 'kernel/locking')
-rw-r--r--kernel/locking/locktorture.c76
1 files changed, 44 insertions, 32 deletions
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index a307a79e6b0b..2a1fc2a58910 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -703,8 +703,7 @@ static void __torture_print_stats(char *page,
703{ 703{
704 bool fail = 0; 704 bool fail = 0;
705 int i, n_stress; 705 int i, n_stress;
706 long max = 0; 706 long max = 0, min = statp ? statp[0].n_lock_acquired : 0;
707 long min = statp[0].n_lock_acquired;
708 long long sum = 0; 707 long long sum = 0;
709 708
710 n_stress = write ? cxt.nrealwriters_stress : cxt.nrealreaders_stress; 709 n_stress = write ? cxt.nrealwriters_stress : cxt.nrealreaders_stress;
@@ -811,7 +810,7 @@ static void lock_torture_cleanup(void)
811 * such, only perform the underlying torture-specific cleanups, 810 * such, only perform the underlying torture-specific cleanups,
812 * and avoid anything related to locktorture. 811 * and avoid anything related to locktorture.
813 */ 812 */
814 if (!cxt.lwsa) 813 if (!cxt.lwsa && !cxt.lrsa)
815 goto end; 814 goto end;
816 815
817 if (writer_tasks) { 816 if (writer_tasks) {
@@ -886,6 +885,13 @@ static int __init lock_torture_init(void)
886 firsterr = -EINVAL; 885 firsterr = -EINVAL;
887 goto unwind; 886 goto unwind;
888 } 887 }
888
889 if (nwriters_stress == 0 && nreaders_stress == 0) {
890 pr_alert("lock-torture: must run at least one locking thread\n");
891 firsterr = -EINVAL;
892 goto unwind;
893 }
894
889 if (cxt.cur_ops->init) 895 if (cxt.cur_ops->init)
890 cxt.cur_ops->init(); 896 cxt.cur_ops->init();
891 897
@@ -909,17 +915,19 @@ static int __init lock_torture_init(void)
909#endif 915#endif
910 916
911 /* Initialize the statistics so that each run gets its own numbers. */ 917 /* Initialize the statistics so that each run gets its own numbers. */
918 if (nwriters_stress) {
919 lock_is_write_held = 0;
920 cxt.lwsa = kmalloc(sizeof(*cxt.lwsa) * cxt.nrealwriters_stress, GFP_KERNEL);
921 if (cxt.lwsa == NULL) {
922 VERBOSE_TOROUT_STRING("cxt.lwsa: Out of memory");
923 firsterr = -ENOMEM;
924 goto unwind;
925 }
912 926
913 lock_is_write_held = 0; 927 for (i = 0; i < cxt.nrealwriters_stress; i++) {
914 cxt.lwsa = kmalloc(sizeof(*cxt.lwsa) * cxt.nrealwriters_stress, GFP_KERNEL); 928 cxt.lwsa[i].n_lock_fail = 0;
915 if (cxt.lwsa == NULL) { 929 cxt.lwsa[i].n_lock_acquired = 0;
916 VERBOSE_TOROUT_STRING("cxt.lwsa: Out of memory"); 930 }
917 firsterr = -ENOMEM;
918 goto unwind;
919 }
920 for (i = 0; i < cxt.nrealwriters_stress; i++) {
921 cxt.lwsa[i].n_lock_fail = 0;
922 cxt.lwsa[i].n_lock_acquired = 0;
923 } 931 }
924 932
925 if (cxt.cur_ops->readlock) { 933 if (cxt.cur_ops->readlock) {
@@ -936,19 +944,21 @@ static int __init lock_torture_init(void)
936 cxt.nrealreaders_stress = cxt.nrealwriters_stress; 944 cxt.nrealreaders_stress = cxt.nrealwriters_stress;
937 } 945 }
938 946
939 lock_is_read_held = 0; 947 if (nreaders_stress) {
940 cxt.lrsa = kmalloc(sizeof(*cxt.lrsa) * cxt.nrealreaders_stress, GFP_KERNEL); 948 lock_is_read_held = 0;
941 if (cxt.lrsa == NULL) { 949 cxt.lrsa = kmalloc(sizeof(*cxt.lrsa) * cxt.nrealreaders_stress, GFP_KERNEL);
942 VERBOSE_TOROUT_STRING("cxt.lrsa: Out of memory"); 950 if (cxt.lrsa == NULL) {
943 firsterr = -ENOMEM; 951 VERBOSE_TOROUT_STRING("cxt.lrsa: Out of memory");
944 kfree(cxt.lwsa); 952 firsterr = -ENOMEM;
945 cxt.lwsa = NULL; 953 kfree(cxt.lwsa);
946 goto unwind; 954 cxt.lwsa = NULL;
947 } 955 goto unwind;
948 956 }
949 for (i = 0; i < cxt.nrealreaders_stress; i++) { 957
950 cxt.lrsa[i].n_lock_fail = 0; 958 for (i = 0; i < cxt.nrealreaders_stress; i++) {
951 cxt.lrsa[i].n_lock_acquired = 0; 959 cxt.lrsa[i].n_lock_fail = 0;
960 cxt.lrsa[i].n_lock_acquired = 0;
961 }
952 } 962 }
953 } 963 }
954 964
@@ -978,12 +988,14 @@ static int __init lock_torture_init(void)
978 goto unwind; 988 goto unwind;
979 } 989 }
980 990
981 writer_tasks = kzalloc(cxt.nrealwriters_stress * sizeof(writer_tasks[0]), 991 if (nwriters_stress) {
982 GFP_KERNEL); 992 writer_tasks = kzalloc(cxt.nrealwriters_stress * sizeof(writer_tasks[0]),
983 if (writer_tasks == NULL) { 993 GFP_KERNEL);
984 VERBOSE_TOROUT_ERRSTRING("writer_tasks: Out of memory"); 994 if (writer_tasks == NULL) {
985 firsterr = -ENOMEM; 995 VERBOSE_TOROUT_ERRSTRING("writer_tasks: Out of memory");
986 goto unwind; 996 firsterr = -ENOMEM;
997 goto unwind;
998 }
987 } 999 }
988 1000
989 if (cxt.cur_ops->readlock) { 1001 if (cxt.cur_ops->readlock) {