svn commit: r361056 - head/sys/kern

Konstantin Belousov kib at FreeBSD.org
Thu May 14 20:17:10 UTC 2020


Author: kib
Date: Thu May 14 20:17:09 2020
New Revision: 361056
URL: https://svnweb.freebsd.org/changeset/base/361056

Log:
  Fix r361037.
  
  Reorder flag manipulations and use barrier to ensure that the program
  order is followed by compiler and CPU, for unlocked reader of so_state.
  
  In collaboration with:	markj
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week
  Differential revision:	https://reviews.freebsd.org/D24842

Modified:
  head/sys/kern/uipc_socket.c

Modified: head/sys/kern/uipc_socket.c
==============================================================================
--- head/sys/kern/uipc_socket.c	Thu May 14 20:07:02 2020	(r361055)
+++ head/sys/kern/uipc_socket.c	Thu May 14 20:17:09 2020	(r361056)
@@ -4016,8 +4016,17 @@ soisdisconnected(struct socket *so)
 {
 
 	SOCK_LOCK(so);
-	so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING);
+
+	/*
+	 * There is at least one reader of so_state that does not
+	 * acquire socket lock, namely soreceive_generic().  Ensure
+	 * that it never sees all flags that track connection status
+	 * cleared, by ordering the update with a barrier semantic of
+	 * our release thread fence.
+	 */
 	so->so_state |= SS_ISDISCONNECTED;
+	atomic_thread_fence_rel();
+	so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING);
 
 	if (!SOLISTENING(so)) {
 		SOCK_UNLOCK(so);


More information about the svn-src-head mailing list