All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeremy Linton <jeremy.linton@arm.com>
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, mingo@redhat.com,
	Jeremy Linton <jeremy.linton@arm.com>
Subject: [PATCH] locktorture: Fix Oops when reader/writer count is 0
Date: Tue, 10 Oct 2017 10:52:48 -0500	[thread overview]
Message-ID: <20171010155248.11602-1-jeremy.linton@arm.com> (raw)

If nwriters_stress=0 is passed to the lock torture test
it will panic in:

Internal error: Oops: 96000005 [#1] SMP
...
[<ffff000000b7022c>] __torture_print_stats+0x2c/0x1c8 [locktorture]
[<ffff000000b7070c>] lock_torture_stats_print+0x74/0x120 [locktorture]
[<ffff000000b707f8>] lock_torture_stats+0x40/0xa8 [locktorture]
[<ffff0000080f3570>] kthread+0x108/0x138
[<ffff000008084b90>] ret_from_fork+0x10/0x18

This is caused by the deference to a null statp. Fix that by
checking the n_stress for non zero count before referencing statp.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
 kernel/locking/locktorture.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index f24582d4dad3..8229ba7147e5 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -716,10 +716,14 @@ static void __torture_print_stats(char *page,
 	bool fail = 0;
 	int i, n_stress;
 	long max = 0;
-	long min = statp[0].n_lock_acquired;
+	long min = 0;
 	long long sum = 0;
 
 	n_stress = write ? cxt.nrealwriters_stress : cxt.nrealreaders_stress;
+
+	if (n_stress)
+		min = statp[0].n_lock_acquired;
+
 	for (i = 0; i < n_stress; i++) {
 		if (statp[i].n_lock_fail)
 			fail = true;
-- 
2.13.5

             reply	other threads:[~2017-10-10 15:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-10 15:52 Jeremy Linton [this message]
2017-11-07 20:01 ` [PATCH] locktorture: Fix Oops when reader/writer count is 0 Jeremy Linton
2017-11-07 21:07   ` Peter Zijlstra
2017-11-07 22:15     ` Paul E. McKenney
2017-11-08  8:27       ` Peter Zijlstra
2017-11-08 14:17         ` Paul E. McKenney
2017-11-08 14:45       ` Davidlohr Bueso
2017-11-08 16:48         ` Paul E. McKenney
2017-11-08 16:57           ` Jeremy Linton
2017-11-08 17:44             ` Paul E. McKenney
2017-11-09 16:15               ` Jeremy Linton
2017-11-09 16:19           ` Davidlohr Bueso
2017-11-09 16:45             ` Paul E. McKenney

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=20171010155248.11602-1-jeremy.linton@arm.com \
    --to=jeremy.linton@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.