svn commit: r305063 - in stable: 10/sys/kern 11/sys/kern

Eric Badger badger at FreeBSD.org
Tue Aug 30 13:39:43 UTC 2016


Author: badger
Date: Tue Aug 30 13:39:42 2016
New Revision: 305063
URL: https://svnweb.freebsd.org/changeset/base/305063

Log:
  MFC r304184:
  
  sem_post(): wake up the sleeper only after adjusting has_waiters
  
  If the caller of sem_post() wakes up a thread sleeping via sem_wait()
  before it clears the has_waiters flag, the caller of sem_wait() has no way of
  knowing when it is safe to destroy the semaphore and reuse the memory. This is
  because the caller of sem_post() may be interrupted between the wake step and
  the clearing of has_waiters. It will then write into the has_waiters flag in
  userspace after being preempted for some unknown amount of time.
  
  Approved by:	vangyzen (mentor)
  Sponsored by:	Dell Inc.

Modified:
  stable/10/sys/kern/kern_umtx.c
Directory Properties:
  stable/10/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/sys/kern/kern_umtx.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/10/sys/kern/kern_umtx.c
==============================================================================
--- stable/10/sys/kern/kern_umtx.c	Tue Aug 30 13:26:00 2016	(r305062)
+++ stable/10/sys/kern/kern_umtx.c	Tue Aug 30 13:39:42 2016	(r305063)
@@ -3344,7 +3344,6 @@ do_sem_wake(struct thread *td, struct _u
 	umtxq_busy(&key);
 	cnt = umtxq_count(&key);
 	if (cnt > 0) {
-		umtxq_signal(&key, 1);
 		/*
 		 * Check if count is greater than 0, this means the memory is
 		 * still being referenced by user code, so we can safely
@@ -3357,6 +3356,7 @@ do_sem_wake(struct thread *td, struct _u
 			if (error == -1)
 				error = EFAULT;
 		}
+		umtxq_signal(&key, 1);
 	}
 	umtxq_unbusy(&key);
 	umtxq_unlock(&key);


More information about the svn-src-stable-10 mailing list