git: 3f10d87df48a - stable/13 - Handle cas failure when the compare succeeds

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Tue, 07 Jun 2022 14:23:29 UTC
The branch stable/13 has been updated by andrew:

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

commit 3f10d87df48a49136ea9ceefbe8171f24546f27c
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-05-09 14:28:56 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-06-07 14:20:18 +0000

    Handle cas failure when the compare succeeds
    
    When locking a priority inherit mutex we perform a compare and swap
    operation to try and acquire the mutex. This may fail even when the
    compare succeeds.
    
    Check and handle this case.
    
    PR:             263825
    Reviewed by:    kib, markj
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D35150
    
    (cherry picked from commit 11a6ecd4258b9108fb19420ec5db297f6d99a842)
---
 sys/kern/kern_umtx.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c
index b76d080b8e06..dd1622c476c5 100644
--- a/sys/kern/kern_umtx.c
+++ b/sys/kern/kern_umtx.c
@@ -2223,6 +2223,17 @@ do_lock_pi(struct thread *td, struct umutex *m, uint32_t flags,
 			break;
 		}
 
+		/*
+		 * Nobody owns it, but the acquire failed. This can happen
+		 * with ll/sc atomics.
+		 */
+		if (owner == UMUTEX_UNOWNED) {
+			error = thread_check_susp(td, true);
+			if (error != 0)
+				break;
+			continue;
+		}
+
 		/*
 		 * Avoid overwriting a possible error from sleep due
 		 * to the pending signal with suspension check result.