From nobody Tue Sep 03 14:55:04 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WypZJ43qqz5TMrL; Tue, 03 Sep 2024 14:55:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WypZJ1gsyz4xF0; Tue, 3 Sep 2024 14:55:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725375304; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=r9n3FCvIITpjyewOuO3p9IVQqiNcMAV6J8vUdHmAQtg=; b=rCoPTxfBXwAThx5D0qorIVMr32ht1SYD0B6eH+AwbBaj/iL+YyTtE1te7HSB1IYdLVAG3A tEZkVMsBviuMHOT9Kd/J+GIVRro/C3xY/YrVLgMobiZ3QhyNktuE5YzyVnfkRV+VKYD2CK Te6nqQZFnMVk/QnQvAnBiPQ2ARAzhqIZ8BrSfesjTZ42RH/TQ76uWmgplinX8xAE+YNv/L wDeH9ipHt3GgF4FlZEEnAq5YYH9Ju/oqFiCO49UKf2RELCbMkMs4jbWRGnoPHHV0XHOLl4 rJTkSher8t9xkiYQEt4f7w37z7A6bx3HsxfyilLEtujctn8FHIaEcNC0hQTd8g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725375304; a=rsa-sha256; cv=none; b=iSmgnGDlKKVB7irzDo5yEWwdbCmcydcia14LmRxZ6Fhfz3NkUc+DmfzcQU3/Hcog99klBF IWewLS9G1xBxSiLozn1MBUSRPktmXxxcy8Qb58C1ynD1z7GF6fJ6fIH85P53lR+hP2rXbB rpZeSQ4IiV/PuMeGAy7yQDYXqo7OplqA60mMvdfnMnWy4D1Z0BBw7rdx3s4w0LU73oZhSr MmHtxKnvtmF0OcHT3cYQ2eXHkHvaP8+esCR5mN4YovfUVVNDStLNd0juhZd9OF2cz8jXF0 ZXKNzytWHaIePYut/Lhfvumw0QEvHmV6P3ND2/C7zbRrqyX8UGbWcpCEYLl4SQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725375304; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=r9n3FCvIITpjyewOuO3p9IVQqiNcMAV6J8vUdHmAQtg=; b=nmFE4sErdaDRbnImyWZOjtpqNJ4/tLqmXvfaqqVOgetkAZJTlldlhZeY8tG4PrLszMM70V 0FHf+SzUrklWdoaPfkq5VGeTb71DevZGNrxYCWtOtiV1r/TEUIhs8VKK7x2/Rwi3vRA4oi 03me8eY0evkC5m3rVoUPR9TuPxzL8sf5F+HQ/6arRzEawyujm0oXGpjcNVLAbBcTy24KLB sUwIBJQuSWjaomwYGxx3GJNfkLdNZynZkdQmO8sUKbxjM4vENGNmTkChzmO2+NGamqGn0m a8pWvEWBBZFxTKSDOl+D3WbElIjszbCOyeb+kijbt6y/5j8WLLm6BTW/+LKmOg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WypZJ1JDzzlSf; Tue, 3 Sep 2024 14:55:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 483Et4Ik070726; Tue, 3 Sep 2024 14:55:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 483Et4Ac070723; Tue, 3 Sep 2024 14:55:04 GMT (envelope-from git) Date: Tue, 3 Sep 2024 14:55:04 GMT Message-Id: <202409031455.483Et4Ac070723@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 20bef7f7c2e2 - stable/14 - socket: Split up soreceive_stream() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 20bef7f7c2e249a073a22677785b1c51a5ce36c2 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=20bef7f7c2e249a073a22677785b1c51a5ce36c2 commit 20bef7f7c2e249a073a22677785b1c51a5ce36c2 Author: Mark Johnston AuthorDate: 2024-08-19 14:20:03 +0000 Commit: Mark Johnston CommitDate: 2024-09-03 14:54:43 +0000 socket: Split up soreceive_stream() Factor out the bits that run with the sock I/O lock held into a separate function. No functional change intended. Reviewed by: gallatin, glebius MFC after: 2 weeks Sponsored by: Klara, Inc. Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D46303 (cherry picked from commit aa141adc039a5418d7b7800094115d861baf91a0) --- sys/kern/uipc_socket.c | 109 ++++++++++++++++++++++++++++--------------------- sys/sys/socketvar.h | 4 ++ 2 files changed, 66 insertions(+), 47 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 7801054315ef..8a688e41ee88 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -2517,56 +2517,15 @@ release: /* * Optimized version of soreceive() for stream (TCP) sockets. */ -int -soreceive_stream(struct socket *so, struct sockaddr **psa, struct uio *uio, - struct mbuf **mp0, struct mbuf **controlp, int *flagsp) +static int +soreceive_stream_locked(struct socket *so, struct sockbuf *sb, + struct sockaddr **psa, struct uio *uio, struct mbuf **mp0, + struct mbuf **controlp, int flags) { - int len = 0, error = 0, flags, oresid; - struct sockbuf *sb; + int len = 0, error = 0, oresid; struct mbuf *m, *n = NULL; - /* We only do stream sockets. */ - if (so->so_type != SOCK_STREAM) - return (EINVAL); - if (psa != NULL) - *psa = NULL; - if (flagsp != NULL) - flags = *flagsp &~ MSG_EOR; - else - flags = 0; - if (controlp != NULL) - *controlp = NULL; - if (flags & MSG_OOB) - return (soreceive_rcvoob(so, uio, flags)); - if (mp0 != NULL) - *mp0 = NULL; - - sb = &so->so_rcv; - -#ifdef KERN_TLS - /* - * KTLS store TLS records as records with a control message to - * describe the framing. - * - * We check once here before acquiring locks to optimize the - * common case. - */ - if (sb->sb_tls_info != NULL) - return (soreceive_generic(so, psa, uio, mp0, controlp, - flagsp)); -#endif - - /* Prevent other readers from entering the socket. */ - error = SOCK_IO_RECV_LOCK(so, SBLOCKWAIT(flags)); - if (error) - return (error); -#ifdef KERN_TLS - if (__predict_false(sb->sb_tls_info != NULL)) { - SOCK_IO_RECV_UNLOCK(so); - return (soreceive_generic(so, psa, uio, mp0, controlp, - flagsp)); - } -#endif + SOCK_IO_RECV_ASSERT_LOCKED(so); SOCKBUF_LOCK(sb); /* Easy one, no space to copyout anything. */ @@ -2729,6 +2688,62 @@ out: SBLASTRECORDCHK(sb); SBLASTMBUFCHK(sb); SOCKBUF_UNLOCK(sb); + return (error); +} + +int +soreceive_stream(struct socket *so, struct sockaddr **psa, struct uio *uio, + struct mbuf **mp0, struct mbuf **controlp, int *flagsp) +{ + struct sockbuf *sb; + int error, flags; + + sb = &so->so_rcv; + + /* We only do stream sockets. */ + if (so->so_type != SOCK_STREAM) + return (EINVAL); + if (psa != NULL) + *psa = NULL; + if (flagsp != NULL) + flags = *flagsp & ~MSG_EOR; + else + flags = 0; + if (controlp != NULL) + *controlp = NULL; + if (flags & MSG_OOB) + return (soreceive_rcvoob(so, uio, flags)); + if (mp0 != NULL) + *mp0 = NULL; + +#ifdef KERN_TLS + /* + * KTLS store TLS records as records with a control message to + * describe the framing. + * + * We check once here before acquiring locks to optimize the + * common case. + */ + if (sb->sb_tls_info != NULL) + return (soreceive_generic(so, psa, uio, mp0, controlp, + flagsp)); +#endif + + /* + * Prevent other threads from reading from the socket. This lock may be + * dropped in order to sleep waiting for data to arrive. + */ + error = SOCK_IO_RECV_LOCK(so, SBLOCKWAIT(flags)); + if (error) + return (error); +#ifdef KERN_TLS + if (__predict_false(sb->sb_tls_info != NULL)) { + SOCK_IO_RECV_UNLOCK(so); + return (soreceive_generic(so, psa, uio, mp0, controlp, + flagsp)); + } +#endif + error = soreceive_stream_locked(so, sb, psa, uio, mp0, controlp, flags); SOCK_IO_RECV_UNLOCK(so); return (error); } diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 485494b605ec..7d194462acba 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -313,11 +313,15 @@ soeventmtx(struct socket *so, const sb_which which) #define SOCK_IO_SEND_UNLOCK(so) \ soiounlock(&(so)->so_snd_sx) #define SOCK_IO_SEND_OWNED(so) sx_xlocked(&(so)->so_snd_sx) +#define SOCK_IO_SEND_ASSERT_LOCKED(so) \ + sx_assert(&(so)->so_snd_sx, SA_XLOCKED) #define SOCK_IO_RECV_LOCK(so, flags) \ soiolock((so), &(so)->so_rcv_sx, (flags)) #define SOCK_IO_RECV_UNLOCK(so) \ soiounlock(&(so)->so_rcv_sx) #define SOCK_IO_RECV_OWNED(so) sx_xlocked(&(so)->so_rcv_sx) +#define SOCK_IO_RECV_ASSERT_LOCKED(so) \ + sx_assert(&(so)->so_rcv_sx, SA_XLOCKED) /* do we have to send all at once on a socket? */ #define sosendallatonce(so) \