From efa9f177f5a1afb7f7a9f1a5d77d6170dbf74006 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Sun, 31 Dec 2017 02:31:01 +0000 Subject: [PATCH] locks: adjust loop limit check when waiting for readers The check was for the exact value, but since the counter started being incremented by the number of readers it could have jumped over. --- sys/kern/kern_rwlock.c | 4 ++-- sys/kern/kern_sx.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index ea701330e442..025ced411fd0 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -516,7 +516,7 @@ __rw_rlock_hard(struct rwlock *rw, struct thread *td, uintptr_t v #endif KTR_STATE0(KTR_SCHED, "thread", sched_tdname(curthread), "running"); - if (i != rowner_loops) + if (i < rowner_loops) continue; } #endif @@ -995,7 +995,7 @@ __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v LOCK_FILE_LINE_ARG_DEF) #ifdef KDTRACE_HOOKS lda.spin_cnt += rowner_loops - i; #endif - if (i != rowner_loops) + if (i < rowner_loops) continue; sleep_reason = 2; } diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c index 13cc6deb77c1..d1440f8c7f5e 100644 --- a/sys/kern/kern_sx.c +++ b/sys/kern/kern_sx.c @@ -671,7 +671,7 @@ _sx_xlock_hard(struct sx *sx, uintptr_t x, int opts LOCK_FILE_LINE_ARG_DEF) #endif KTR_STATE0(KTR_SCHED, "thread", sched_tdname(curthread), "running"); - if (i != asx_loops) + if (i < asx_loops) continue; sleep_reason = 2; }