From nobody Tue Sep 03 14:55:06 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 4WypZL5BXWz5TN97; Tue, 03 Sep 2024 14:55:06 +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 4WypZL3dDvz4x1f; Tue, 3 Sep 2024 14:55:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725375306; 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=XsNPNR7hoMW+aE2RFJIjLELnZi1McUygIuBQS9AfsAQ=; b=hGE0D4V/LqPdL5tsUkCpSTn/C2j50PDK8s3/f2tkVtmpt0C5pKUr5nooWr2W2AB9HLg9Ad QdognFSXSesZhYO97oTjrJTLnBGBN0YsRRXZyG75xpAGfdmI16WWrDfrALilk4KSBV2v/A t+t/ZayqBnnlCISXzDOxYRTAZHNjh30K4DqTmr8eJe2R54mTjz703OFziavysJBXnzS7cQ npzlQyka6HIDnZLb46G83GTqIFa4SIe9yw9Xik7StznrQ+dysEL6xzfunGWyLSLVNNWtbj GE6PmIYBiWG4rtUOdXOPD02GNLw9srFqzWNHO24ZWRrtkPbb4j198ikn2iHw8A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725375306; a=rsa-sha256; cv=none; b=qzr+gW+i/IsT58CMYgiah2z7dcyTcEL7l/ElRUJjkejIUBc/yD2vyaHze8UqrIHxK1Mt7d fYmO+7gmmGJQGqjcI2OiKIyS0f0dzqwqDJCNRjjt9quGUavlRIhbuKTxYSFmJHLhkVplLT 2kwGJa3swkasZRJcB8+7dU0yrznDrR+vx8wqzRrAQv8ccGa711PKMtOfvX3v2Hvvu+raLf YQy2PbgTL2PFq8r9y3Ln6TxnRFKNKY4wV2n+3QEHS6rDH8JFGpjzUNdDt0I1g9E1gyR2AH qPtw826oJs5MAlQ4a2Ne95DAqxiqJDvAWedu/n74Pu+XxHQmMDnLcaxK6fb1Og== 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=1725375306; 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=XsNPNR7hoMW+aE2RFJIjLELnZi1McUygIuBQS9AfsAQ=; b=ld6/tuN8cDalUL41qf3f/lAmoFh1wlHmuHehfCoS/RZYafb5TX6y/Q1Y6DQRdnn9vemOG+ QbrHzsUb/GImNEVHG4IZ0k/9dgHt4zS8FqoJnyiT+TMz7dwE/wyxaI19FJcLWBYsoaV3kc qUhfp5yq+E+OZ4q3J3JkpY1ipJnGBuZDo2SyydRr8zAOXAks0vOj+PeyNYe8c0xA/ZO31N YNj1S7mshwGEAJQ/rYmR/W0P8Db+Qi5hDryRKLuLeNUhH6xq2nr8ycgU+5AGA2x/6/87AQ ZDiAs8ydrhwIWpiKkNYS1Z9JhXOTHoJ2UJrBGqIm7iGFf2y8KRmz3neRWmKmjQ== 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 4WypZL3DYjzllh; Tue, 3 Sep 2024 14:55:06 +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 483Et6av070814; Tue, 3 Sep 2024 14:55:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 483Et6xp070811; Tue, 3 Sep 2024 14:55:06 GMT (envelope-from git) Date: Tue, 3 Sep 2024 14:55:06 GMT Message-Id: <202409031455.483Et6xp070811@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: 2537245ecd01 - stable/14 - socket: Split up sosend_generic() 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: 2537245ecd0188c0db1fd36565e1175a177637c3 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=2537245ecd0188c0db1fd36565e1175a177637c3 commit 2537245ecd0188c0db1fd36565e1175a177637c3 Author: Mark Johnston AuthorDate: 2024-08-19 14:20:43 +0000 Commit: Mark Johnston CommitDate: 2024-09-03 14:54:43 +0000 socket: Split up sosend_generic() Factor out the bits that run with the sock I/O lock held into a separate function. In this implementation, we are doing a bit more work under the I/O lock than before. However, lock contention is only a problem when multiple threads are transmitting on the same socket, which is an unusual case that is not expected to perform well in any case. 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/D46305 (cherry picked from commit fb901935f257ddcc492fe9efb605797f181c6597) --- sys/kern/uipc_socket.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 99073121d7de..dfe75978ac39 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1601,8 +1601,8 @@ out: * counts if EINTR/ERESTART are returned. Data and control buffers are freed * on return. */ -int -sosend_generic(struct socket *so, struct sockaddr *addr, struct uio *uio, +static int +sosend_generic_locked(struct socket *so, struct sockaddr *addr, struct uio *uio, struct mbuf *top, struct mbuf *control, int flags, struct thread *td) { long space; @@ -1618,6 +1618,9 @@ sosend_generic(struct socket *so, struct sockaddr *addr, struct uio *uio, tls = NULL; tls_rtype = TLS_RLTYPE_APP; #endif + + SOCK_IO_SEND_ASSERT_LOCKED(so); + if (uio != NULL) resid = uio->uio_resid; else if ((top->m_flags & M_PKTHDR) != 0) @@ -1647,10 +1650,6 @@ sosend_generic(struct socket *so, struct sockaddr *addr, struct uio *uio, if (control != NULL) clen = control->m_len; - error = SOCK_IO_SEND_LOCK(so, SBLOCKWAIT(flags)); - if (error) - goto out; - #ifdef KERN_TLS tls_send_flag = 0; tls = ktls_hold(so->so_snd.sb_tls_info); @@ -1673,7 +1672,7 @@ sosend_generic(struct socket *so, struct sockaddr *addr, struct uio *uio, if (resid == 0 && !ktls_permit_empty_frames(tls)) { error = EINVAL; - goto release; + goto out; } } #endif @@ -1684,13 +1683,13 @@ restart: if (so->so_snd.sb_state & SBS_CANTSENDMORE) { SOCKBUF_UNLOCK(&so->so_snd); error = EPIPE; - goto release; + goto out; } if (so->so_error) { error = so->so_error; so->so_error = 0; SOCKBUF_UNLOCK(&so->so_snd); - goto release; + goto out; } if ((so->so_state & SS_ISCONNECTED) == 0) { /* @@ -1705,7 +1704,7 @@ restart: !(resid == 0 && clen != 0)) { SOCKBUF_UNLOCK(&so->so_snd); error = ENOTCONN; - goto release; + goto out; } } else if (addr == NULL) { SOCKBUF_UNLOCK(&so->so_snd); @@ -1713,7 +1712,7 @@ restart: error = ENOTCONN; else error = EDESTADDRREQ; - goto release; + goto out; } } space = sbspace(&so->so_snd); @@ -1723,7 +1722,7 @@ restart: clen > so->so_snd.sb_hiwat) { SOCKBUF_UNLOCK(&so->so_snd); error = EMSGSIZE; - goto release; + goto out; } if (space < resid + clen && (atomic || space < so->so_snd.sb_lowat || space < clen)) { @@ -1731,12 +1730,12 @@ restart: (flags & (MSG_NBIO | MSG_DONTWAIT)) != 0) { SOCKBUF_UNLOCK(&so->so_snd); error = EWOULDBLOCK; - goto release; + goto out; } error = sbwait(so, SO_SND); SOCKBUF_UNLOCK(&so->so_snd); if (error) - goto release; + goto out; goto restart; } SOCKBUF_UNLOCK(&so->so_snd); @@ -1781,7 +1780,7 @@ restart: ((flags & MSG_EOR) ? M_EOR : 0)); if (top == NULL) { error = EFAULT; /* only possible error */ - goto release; + goto out; } space -= resid - uio->uio_resid; resid = uio->uio_resid; @@ -1845,12 +1844,10 @@ restart: control = NULL; top = NULL; if (error) - goto release; + goto out; } while (resid && space > 0); } while (resid); -release: - SOCK_IO_SEND_UNLOCK(so); out: #ifdef KERN_TLS if (tls != NULL) @@ -1863,6 +1860,20 @@ out: return (error); } +int +sosend_generic(struct socket *so, struct sockaddr *addr, struct uio *uio, + struct mbuf *top, struct mbuf *control, int flags, struct thread *td) +{ + int error; + + error = SOCK_IO_SEND_LOCK(so, 0); + if (error) + return (error); + error = sosend_generic_locked(so, addr, uio, top, control, flags, td); + SOCK_IO_SEND_UNLOCK(so); + return (error); +} + /* * Send to a socket from a kernel thread. *