Date: Thu, 14 May 2020 20:17:09 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361056 - head/sys/kern Message-ID: <202005142017.04EKH9pQ071966@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005142017.04EKH9pQ071966>