From nobody Fri Oct 29 23:58:07 2021 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 7B778181CD6C; Fri, 29 Oct 2021 23:58:09 +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 4Hgzrw1mJDz4VM4; Fri, 29 Oct 2021 23:58:07 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B8B052006D; Fri, 29 Oct 2021 23:58:07 +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 19TNw7Al003336; Fri, 29 Oct 2021 23:58:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19TNw7jr003335; Fri, 29 Oct 2021 23:58:07 GMT (envelope-from git) Date: Fri, 29 Oct 2021 23:58:07 GMT Message-Id: <202110292358.19TNw7jr003335@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 19224c9f8477 - stable/13 - cxgbei: Rework the pdu_append_data hook to support M_WAITOK. 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 19224c9f8477c73776664ee9fca7e119db364e00 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=19224c9f8477c73776664ee9fca7e119db364e00 commit 19224c9f8477c73776664ee9fca7e119db364e00 Author: John Baldwin AuthorDate: 2021-05-14 19:17:14 +0000 Commit: John Baldwin CommitDate: 2021-10-29 22:54:22 +0000 cxgbei: Rework the pdu_append_data hook to support M_WAITOK. - Only allocate 16K jumbo mbufs if the region of data to be appended is sufficiently large, and use a loop. - Use m_getm2() to allocate a chain for data less than 16K, or if m_getjcl() fails. - Use ENOMEM as the return value instead of '1' if the hook fails due to a memory allocation error. Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D29909 (cherry picked from commit 31df8ff73e3aa809146fae9baa6a96e1adf8526b) --- sys/dev/cxgbe/cxgbei/icl_cxgbei.c | 65 ++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/sys/dev/cxgbe/cxgbei/icl_cxgbei.c b/sys/dev/cxgbe/cxgbei/icl_cxgbei.c index 5770599eeeef..f91b9ee38616 100644 --- a/sys/dev/cxgbe/cxgbei/icl_cxgbei.c +++ b/sys/dev/cxgbe/cxgbei/icl_cxgbei.c @@ -324,35 +324,70 @@ int icl_cxgbei_conn_pdu_append_data(struct icl_conn *ic, struct icl_pdu *ip, const void *addr, size_t len, int flags) { - struct mbuf *m; #ifdef INVARIANTS struct icl_cxgbei_pdu *icp = ip_to_icp(ip); #endif + struct mbuf *m, *m_tail; + const char *src; MPASS(icp->icp_signature == CXGBEI_PDU_SIGNATURE); MPASS(ic == ip->ip_conn); KASSERT(len > 0, ("%s: len is %jd", __func__, (intmax_t)len)); - m = ip->ip_data_mbuf; - if (m == NULL) { + m_tail = ip->ip_data_mbuf; + if (m_tail != NULL) + for (; m_tail->m_next != NULL; m_tail = m_tail->m_next) + ; + + src = (const char *)addr; + + /* Allocate as jumbo mbufs of size MJUM16BYTES. */ + while (len >= MJUM16BYTES) { m = m_getjcl(M_NOWAIT, MT_DATA, 0, MJUM16BYTES); - if (__predict_false(m == NULL)) + if (__predict_false(m == NULL)) { + if ((flags & M_WAITOK) != 0) { + /* Fall back to non-jumbo mbufs. */ + break; + } return (ENOMEM); - - ip->ip_data_mbuf = m; + } + memcpy(mtod(m, void *), src, MJUM16BYTES); + m->m_len = MJUM16BYTES; + if (ip->ip_data_mbuf == NULL) { + ip->ip_data_mbuf = m_tail = m; + ip->ip_data_len = MJUM16BYTES; + } else { + m_tail->m_next = m; + m_tail = m_tail->m_next; + ip->ip_data_len += MJUM16BYTES; + } + src += MJUM16BYTES; + len -= MJUM16BYTES; } - if (__predict_true(m_append(m, len, addr) != 0)) { - ip->ip_data_len += len; - MPASS(ip->ip_data_len <= ic->ic_max_data_segment_length); - return (0); - } else { - if (flags & M_WAITOK) { - CXGBE_UNIMPLEMENTED("fail safe append"); + /* Allocate mbuf chain for the remaining data. */ + if (len != 0) { + m = m_getm2(NULL, len, flags, MT_DATA, 0); + if (__predict_false(m == NULL)) + return (ENOMEM); + if (ip->ip_data_mbuf == NULL) { + ip->ip_data_mbuf = m; + ip->ip_data_len = len; + } else { + m_tail->m_next = m; + ip->ip_data_len += len; } - ip->ip_data_len = m_length(m, NULL); - return (1); + for (; m != NULL; m = m->m_next) { + m->m_len = min(len, M_SIZE(m)); + memcpy(mtod(m, void *), src, m->m_len); + src += m->m_len; + len -= m->m_len; + } + MPASS(len == 0); } + MPASS(ip->ip_data_len <= ic->ic_max_data_segment_length); + + return (0); } void