From nobody Mon Aug 19 14:37:41 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 4WnZv96dMlz5T8M2; Mon, 19 Aug 2024 14:37:41 +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 4WnZv93q5Bz4tvD; Mon, 19 Aug 2024 14:37:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724078261; 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=6dapba6pF3Z5OT+DYg50kymfDYrtEgxsB5y9w3DGA7o=; b=YUmPO6QV+KJpn+LCs/3fhXrP7IcDOiuiBny7Woh+7tSDl1ZwGZt4zVTRhF5foL4kiM5HeN XxOkRmTsOLJ4DIPJsl7dlB1jN5SqbExkpcNTal4kcVC4raAgx147yFEgclsPh+br4OG5E+ tsTupSXDFgcSha1RREmcbcwxwQ/lXsWbyZIoL+tVCPufo5PrJGyRL79Cg9Oe1glgYxjRLC EAYzCNBjdEZWpKznnMPt26OuaO4fuO86oFXOO+ABRoz6evA39QC9ojVNLoWY6FXU4Ga6hH MOqp2I8eW0oQzrklLobrl/qhZ5PDTii75gmrG35lSQPNAjR+HAlTu0OD6RRg0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724078261; a=rsa-sha256; cv=none; b=XtRwcoFSqv6B8dPZ4Ms6jB+SjVWydLoDp8gwJOQwP1Xu25TWGLlkTWfzCV6aT38EBboVaV K30DLCB1+Cgaw5J4HqD3jtSd9PkLKadC+5TlheWU2F5w3c3vAGpSceyJpW85lxQG6F+WYF /PlMdcTn1AOe8H41+o/K0u77jjCQaKBkKN+c8glm28h1yu2ac1ciYBltdNx8Rq3/ycYtuN uhTCf5+3KXozQ5emxVvZZxyruz+9Rhk7QV2TJVgPUzc2TT8NiAscof6zdzBp0NSbqbz6yd RZOb8FSe4pGLrC030xSK3QjfGEAd+OlA4TkmySDRtqjeA6d/xwBpoOuAeO0FFA== 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=1724078261; 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=6dapba6pF3Z5OT+DYg50kymfDYrtEgxsB5y9w3DGA7o=; b=BFWhr6EvTrdDfFkcvVRAw+fvjwPBJcGCwI46RVpbn1ZTNdsWixNaJCnHtroOe/jyVE831p sGSedF3KYJs7PWaHcgyBuRjuxfVCjf4Xsp2d8RuGBVuWQrYmA6XnUz4+CtJ56kTHOiMDNa jC78Jz++udEjIumbWka5CtJ2exyqsxVlyMpeo9vYNJx/YesHejV+dU+BpvIEnfdMgfuumw yBPk84rQ52c4MVbtH5PrwUh6L9RwfS0Dgo30E0yM8DJhD8Hk98AdOzPQUbXS8amf8rou3r R0kTW+vdzYYV01Bmtb1uvYC9054+Y0irG1JN/iAw6mb2pcOAvJ8w8AgidJLwYg== 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 4WnZv92KTWzKqs; Mon, 19 Aug 2024 14:37:41 +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 47JEbfCD094180; Mon, 19 Aug 2024 14:37:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47JEbf28094177; Mon, 19 Aug 2024 14:37:41 GMT (envelope-from git) Date: Mon, 19 Aug 2024 14:37:41 GMT Message-Id: <202408191437.47JEbf28094177@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: aa141adc039a - main - 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/main X-Git-Reftype: branch X-Git-Commit: aa141adc039a5418d7b7800094115d861baf91a0 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=aa141adc039a5418d7b7800094115d861baf91a0 commit aa141adc039a5418d7b7800094115d861baf91a0 Author: Mark Johnston AuthorDate: 2024-08-19 14:20:03 +0000 Commit: Mark Johnston CommitDate: 2024-08-19 14:37:27 +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 --- sys/kern/uipc_socket.c | 109 ++++++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 47 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 9a44c1d557f0..5886c7ac84f4 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -2566,56 +2566,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. */ @@ -2778,6 +2737,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); }