git: c4d8b2462e77 - main - rangelocks: recheck that entry is not marked after sleepq is locked in rl_w_validate()

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 21 Aug 2024 15:21:45 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=c4d8b2462e771e409d29df5545cbfb8465673818

commit c4d8b2462e771e409d29df5545cbfb8465673818
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-08-20 12:59:35 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-08-21 15:19:57 +0000

    rangelocks: recheck that entry is not marked after sleepq is locked in rl_w_validate()
    
    otherwise we might loose the wakeup.
    
    Reported and tested by: markj
    Sponsored by:   The FreeBSD Foundation
---
 sys/kern/kern_rangelock.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sys/kern/kern_rangelock.c b/sys/kern/kern_rangelock.c
index d9042f364737..ef9d0104af72 100644
--- a/sys/kern/kern_rangelock.c
+++ b/sys/kern/kern_rangelock.c
@@ -609,6 +609,12 @@ again:
 			continue;
 		}
 		sleepq_lock(&lock->sleepers);
+		/* Reload after sleepq is locked */
+		next = rl_q_load(&cur->rl_q_next);
+		if (rl_e_is_marked(next)) {
+			sleepq_release(&lock->sleepers);
+			goto again;
+		}
 		rangelock_unlock_int(lock, e);
 		if (trylock) {
 			sleepq_release(&lock->sleepers);