locking/rwsem: Fix lock optimistic spinning when owner is not running
locking/rwsem: Fix lock optimistic spinning when owner is not running

Ming reported soft lockups occurring when running xfstest due to
the following tip:locking/core commit:

  b3fd4f03ca0b ("locking/rwsem: Avoid deceiving lock spinners")

When doing optimistic spinning in rwsem, threads should stop
spinning when the lock owner is not running. While a thread is
spinning on owner, if the owner reschedules, owner->on_cpu
returns false and we stop spinning.

However, this commit essentially caused the check to get
ignored because when we break out of the spin loop due to
!on_cpu, we continue spinning if sem->owner != NULL.

This patch fixes this by making sure we stop spinning if the
owner is not running. Furthermore, just like with mutexes,
refactor the code such that we don't have separate checks for
owner_running(). This makes it more straightforward in terms of
why we exit the spin on owner loop and we would also avoid
needing to "guess" why we broke out of the loop to make this
more readable.

Reported-and-tested-by: Ming Lei <8d0fc11caeb4659419f0ba3104eb4a9d30848d42@canonical.com>
Signed-off-by: Jason Low <09ebf12aa4fd61769490ade56a7655bcf429b765@hp.com>
Acked-by: Davidlohr Bueso <bfcdf3e6ca6cef45543bfbb57509c92aec9a39fb@stgolabs.net>
Cc: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Cc: Dave Jones <d5ec0d24602845f6f4b6a35ef729998d1fba5507@codemonkey.org.uk>
Cc: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>
Cc: Michel Lespinasse <6a4cf9207bb95b1a4cf1be22c2e93f8b38036f65@google.com>
Cc: Oleg Nesterov <20b70f0af00562e63758b9ee42012ecc96c58590@redhat.com>
Cc: Paul E. McKenney <1e0ce936bb9b355d257bf5790d2513c3f28be22b@linux.vnet.ibm.com>
Cc: Peter Zijlstra <3fddac958924aef220f202ca567388ddab3f14a8@infradead.org>
Cc: Sasha Levin <e642b69ed2fc111e09ffdc37feb733a52253340d@oracle.com>
Cc: Thomas Gleixner <00e4cf8f46a57000a44449bf9dd8cbbcc209fd2a@linutronix.de>
Cc: Tim Chen <695db642e8bc2a781029b5690bc796db9446cc2f@linux.intel.com>
Link: d920f96ab4286f6cbed34c5a2a0e9a6c6c41d487@j-VirtualBox
Signed-off-by: Ingo Molnar <9dbbbf0688fedc85ad4da37637f1a64b8c718ee2@kernel.org>

KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs