Skip to content

Commit

Permalink
rangelocks: re-check that the lock is still in the cheating mode afte…
Browse files Browse the repository at this point in the history
…r setting of DRAINING failed

Noted by:	markj
Tested by:	dougm, pho (previous version)
Reviewed by:	markj (previous version), dougm
Fixes:	9ef425e
Sponsored by:	The FreeBSD Foundation
  • Loading branch information
kostikbel committed Aug 8, 2024
1 parent c89d94a commit 57cc80e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions sys/kern/kern_rangelock.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ rangelock_cheat_lock(struct rangelock *lock, int locktype, bool trylock,
goto drain1;
sleepq_release(&lock->head);
/* Possibly forgive passed conflict */
continue;
} else {
x = (v & ~RL_CHEAT_MASK) + RL_CHEAT_READER;
x |= RL_CHEAT_CHEATING;
if (atomic_fcmpset_acq_ptr(&lock->head, &v,
x) != 0)
break;
}
x = (v & ~RL_CHEAT_MASK) + RL_CHEAT_READER;
x |= RL_CHEAT_CHEATING;
if (atomic_fcmpset_acq_ptr(&lock->head, &v, x) != 0)
break;
if ((v & RL_CHEAT_CHEATING) == 0)
return (false);
if ((v & RL_CHEAT_DRAINING) != 0)
Expand All @@ -156,11 +157,12 @@ rangelock_cheat_lock(struct rangelock *lock, int locktype, bool trylock,
goto drain1;
sleepq_release(&lock->head);
/* Possibly forgive passed conflict */
continue;
} else {
x = RL_CHEAT_WLOCKED | RL_CHEAT_CHEATING;
if (atomic_fcmpset_acq_ptr(&lock->head, &v,
x) != 0)
break;
}
x = RL_CHEAT_WLOCKED | RL_CHEAT_CHEATING;
if (atomic_fcmpset_acq_ptr(&lock->head, &v, x) != 0)
break;
if ((v & RL_CHEAT_CHEATING) == 0)
return (false);
if ((v & RL_CHEAT_DRAINING) != 0)
Expand Down

0 comments on commit 57cc80e

Please sign in to comment.