git: b94acafdbcc7 - stable/13 - PP mutexes: unlock: Reset inherited prio regardless of privileges

From: Olivier Certner <olce_at_FreeBSD.org>
Date: Thu, 09 May 2024 13:30:18 UTC
The branch stable/13 has been updated by olce:

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

commit b94acafdbcc7b34a57671b76910ec6e397a4e7db
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2024-02-20 13:52:40 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2024-05-09 13:29:11 +0000

    PP mutexes: unlock: Reset inherited prio regardless of privileges
    
    'uq_inherited_pri' contains the current priority inherited from Priority
    Protection mutexes.  If -1 is passed through 'm_ceilings[1]', meaning
    that there are no such mutexes held anymore, this must be reflected into
    it by setting it to PRI_MAX, regardless of whether the thread has
    privilege to set realtime priorities (PRI_MAX is also obviously not
    a realtime priority level).  By contrast, it shall not be updated and
    the computed 'new_inherited_pri' shall stay unused if the thread doesn't
    have the ability to set a realtime priority, possibly keeping an older
    such priority acquired previously.
    
    Reviewed by:            kib
    Approved by:            emaste (mentor)
    MFC after:              2 weeks
    Sponsored by:           The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D43984
    
    (cherry picked from commit 1df8700aa6cff7c759e90f7e507de4b8714435a4)
    
    Approved by:            emaste (mentor)
---
 sys/kern/kern_umtx.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c
index 94050beee7dd..5767a137b536 100644
--- a/sys/kern/kern_umtx.c
+++ b/sys/kern/kern_umtx.c
@@ -2685,7 +2685,8 @@ do_unlock_pp(struct thread *td, struct umutex *m, uint32_t flags, bool rb)
 	struct umtx_q *uq, *uq2;
 	struct umtx_pi *pi;
 	uint32_t id, owner, rceiling;
-	int error, pri, new_inherited_pri, su;
+	int error, pri, new_inherited_pri;
+	bool su;
 
 	id = td->td_tid;
 	uq = td->td_umtxq;
@@ -2740,7 +2741,7 @@ do_unlock_pp(struct thread *td, struct umutex *m, uint32_t flags, bool rb)
 		error = EFAULT;
 	else {
 		mtx_lock(&umtx_lock);
-		if (su != 0)
+		if (su || new_inherited_pri == PRI_MAX)
 			uq->uq_inherited_pri = new_inherited_pri;
 		pri = PRI_MAX;
 		TAILQ_FOREACH(pi, &uq->uq_pi_contested, pi_link) {