From nobody Fri Jun 24 16:10:33 2022 X-Original-To: dev-commits-src-main@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 E5DCF8654F5; Fri, 24 Jun 2022 16:10:33 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LV2CY2yfgz3JYx; Fri, 24 Jun 2022 16:10:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656087033; 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=O0sbh1ie+CfT0ZgJaOuinJEHBqQiYB64Qf8WiT+WQZw=; b=sa4h9T8pY2vKVO7Ij3pY81GMAzlhpKILD0QE4bA2SfyujYevU/rW4gNct5Fz5WSym2wz42 3LAAzjLWqycQtAC9hpOpjP9/d293P8+klBmjTh9/4kxO4trWiOVUockHrjj6Vfiw57b4KS 4r8ku/RUo9es2iXsJQ4jITDW6bcv1QBurDw14+NjtXrVTT+LCcNnmMcUPXtVESnqg61nYu yWwLwYaVonC8KaBVoGLHKP3Gz1nC5qUkkHpH3TJq+K9mQubIsgxWmO5UH4eQYTN854PoQc ZK+WOFzh1o9ytMEvvB2K3UOxFs/+Q8126rIIm30F4MrS69tgQxnTq4ClV/cT2g== 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 3D70213220; Fri, 24 Jun 2022 16:10:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25OGAXi9006168; Fri, 24 Jun 2022 16:10:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25OGAXXO006167; Fri, 24 Jun 2022 16:10:33 GMT (envelope-from git) Date: Fri, 24 Jun 2022 16:10:33 GMT Message-Id: <202206241610.25OGAXXO006167@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 5dc8dd5f3ac5 - main - unix/dgram: inline sbappendaddr_locked() into uipc_sosend_dgram() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5dc8dd5f3ac564518b391ecd3e8ad9f4f3c786df Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656087033; 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=O0sbh1ie+CfT0ZgJaOuinJEHBqQiYB64Qf8WiT+WQZw=; b=gqIX46/XfDQRb21w8uhxmDdhtvGF7mjkupSTAmPqtXoA86vxyqGfbPomekEkPgrVZBvahZ qzvC2Y1xFDciolS9Z0/nxH2ooIh/0SATsmJVedTjouC/c7ROxTgsie1kK4O4fGAq0tPxQZ FleKqqvhcmWwtWKRiNFSq5JaQM+MMNmmrpegiVkfS4DcxWkxfs1H4lYbIviAPeZmA0L8iR aVjwYbmVSWz/CG7td4lZdyA3X/TUGNbLHLmRNU6+h07k1Ja01cpab6S5ZCvKS5JVFAAfit hvrO3e53UHQ8lAul7IsjOzJEWp9KC6A+AmyQlBa37k3UT5CLri6DyLmf6DYLHA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656087033; a=rsa-sha256; cv=none; b=UmwZS4aF/3nXaWvb5TWSboOALw9CrIE+u0JWgbMQ7txtt1hiWvK8AtiQOSVHtwqpR+lX9a VkqXEQGKdZxHx2LFp6HOrUR7pkcakZMwNm2UaNTem/Qg37ezLUnvtA/Kf4oDRiZ4Y203eZ 29bN7KbiMmIA2IqEgbBzmQ3y6oFy+arbMslbA5Kc6BM1XS6+eqLe9zA0XHS/xB4LEE4vuQ yFK6yRxPP3JBkj6ThAHuSMt8J/xJwpjUexjnTcK5s8ux2lETf9TVAoYjqMRSXPKYfCDKbR r/atLLbhOxiKMmb4lr2nqIAVkKMTXUaEeS4eBmQEtGO2ExRuyMYcTGXbYf5sBw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=5dc8dd5f3ac564518b391ecd3e8ad9f4f3c786df commit 5dc8dd5f3ac564518b391ecd3e8ad9f4f3c786df Author: Gleb Smirnoff AuthorDate: 2022-06-24 16:09:10 +0000 Commit: Gleb Smirnoff CommitDate: 2022-06-24 16:09:10 +0000 unix/dgram: inline sbappendaddr_locked() into uipc_sosend_dgram() This allows to remove one M_NOWAIT allocation and also makes it more clear what's going on. Reviewed by: markj Differential revision: https://reviews.freebsd.org/D35297 --- sys/kern/uipc_usrreq.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 51f60d1299b9..2872e28aef3a 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1118,6 +1118,9 @@ release: /* * PF_UNIX/SOCK_DGRAM send + * + * Allocate a record consisting of 3 mbufs in the sequence of + * from -> control -> data and append it to the socket buffer. */ static int uipc_sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio, @@ -1126,11 +1129,14 @@ uipc_sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio, struct unpcb *unp, *unp2; const struct sockaddr *from; struct socket *so2; - int error; + struct sockbuf *sb; + struct mbuf *f, *clast; + int cc, error; MPASS((uio != NULL && m == NULL) || (m != NULL && uio == NULL)); error = 0; + f = NULL; if (__predict_false(flags & MSG_OOB)) { error = EOPNOTSUPP; @@ -1146,6 +1152,7 @@ uipc_sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio, error = EFAULT; goto out; } + f = m_get(M_WAITOK, MT_SONAME); if (c != NULL && (error = unp_internalize(&c, td))) goto out; } else { @@ -1159,6 +1166,10 @@ uipc_sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio, error = EMSGSIZE; goto out; } + if ((f = m_get(M_NOWAIT, MT_SONAME)) == NULL) { + error = ENOBUFS; + goto out; + } /* Condition the foreign mbuf to our standards. */ m_clrprotoflags(m); m_tag_delete_chain(m, NULL); @@ -1225,11 +1236,38 @@ uipc_sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio, from = (struct sockaddr *)unp->unp_addr; else from = &sun_noname; + f->m_len = from->sa_len; + MPASS(from->sa_len <= MLEN); + bcopy(from, mtod(f, void *), from->sa_len); + cc = f->m_len + m->m_pkthdr.len; + if (c != NULL) + cc += m_length(c, &clast); so2 = unp2->unp_socket; - SOCKBUF_LOCK(&so2->so_rcv); - if (sbappendaddr_locked(&so2->so_rcv, from, m, c)) { + sb = &so2->so_rcv; + SOCKBUF_LOCK(sb); + if (cc <= sbspace(sb)) { + /* Concatenate: from -> control -> data. */ + if (c != NULL) { + f->m_next = c; + clast->m_next = m; + } else + f->m_next = m; + m = f; + /* Reusing f as iterator. */ + for (f = m; f->m_next != NULL; f = f->m_next) + sballoc(sb, f); + sballoc(sb, f); + sb->sb_mbtail = f; + /* SBLINKRECORD */ + if (sb->sb_lastrecord != NULL) + sb->sb_lastrecord->m_nextpkt = m; + else + sb->sb_mb = m; + sb->sb_lastrecord = m; + SBLASTMBUFCHK(sb); + SBLASTRECORDCHK(sb); sorwakeup_locked(so2); - m = c = NULL; + f = m = c = NULL; } else { soroverflow_locked(so2); error = (so->so_state & SS_NBIO) ? EAGAIN : ENOBUFS; @@ -1248,6 +1286,8 @@ out2: if (c) unp_scan(c, unp_freerights); out: + if (f) + m_free(f); if (c) m_freem(c); if (m)