locktorture: Prevent spinloop from escaping lock-held diagnostics

The lock_torture_writer() function uses lock_is_write_held to communicate
that the current task write-holds the lock.  Except that nothing currently
prevents the compiler from moving this wirte past the lock-hold delay,
which makes it less probable that other code will detect the fact
that the lock is in fact held.  This commit therefore adds barrier()
invocations to constrain the compiler.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index 665fe55..7e164c5 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -909,6 +909,8 @@ static int lock_torture_writer(void *arg)
 			if (WARN_ON_ONCE(READ_ONCE(lock_is_write_held)))
 				lwsp->n_lock_fail++;
 			WRITE_ONCE(lock_is_write_held, t);
+
+			barrier();
 			if (WARN_ON_ONCE(atomic_read(&lock_is_read_held)))
 				lwsp->n_lock_fail++; /* rare, but... */
 			if (acq_writer_lim > 0) {
@@ -920,6 +922,7 @@ static int lock_torture_writer(void *arg)
 			lwsp->n_lock_acquired++;
 
 			cxt.cur_ops->write_delay(&rand);
+			barrier();
 
 			WRITE_ONCE(lock_is_write_held, NULL);
 			WRITE_ONCE(last_lock_release, jiffies);