From nobody Fri Oct 29 23:58:25 2021 X-Original-To: dev-commits-src-branches@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 B9A70181D6A8; Fri, 29 Oct 2021 23:58:29 +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 4HgzsJ0svtz4VNM; Fri, 29 Oct 2021 23:58:28 +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 C098C201F2; Fri, 29 Oct 2021 23:58:25 +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 19TNwPAj003750; Fri, 29 Oct 2021 23:58:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19TNwPAt003749; Fri, 29 Oct 2021 23:58:25 GMT (envelope-from git) Date: Fri, 29 Oct 2021 23:58:25 GMT Message-Id: <202110292358.19TNwPAt003749@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: a2bd630ca784 - stable/13 - cxgbei: Wait for socket to close in icl_cxgbei_conn_close. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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: a2bd630ca7845120c45f2196bad870588beef16d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=a2bd630ca7845120c45f2196bad870588beef16d commit a2bd630ca7845120c45f2196bad870588beef16d Author: John Baldwin AuthorDate: 2021-07-29 23:34:46 +0000 Commit: John Baldwin CommitDate: 2021-10-29 23:14:16 +0000 cxgbei: Wait for socket to close in icl_cxgbei_conn_close. This ensures the TOE has finished processing any in-flight received data before returning to the caller. The caller assumes it is safe to free any open tasks or transfers (and associated buffers) after this function returns. Previously, data placed directly via DDP could be written to buffers after the caller had freed the buffers. Reported by: Jithesh Arakkan @ Chelsio Sponsored by: Chelsio Communications (cherry picked from commit 67495c13d0bc25c57ebf0103e9d2af7c4a3088c9) --- sys/dev/cxgbe/cxgbei/icl_cxgbei.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sys/dev/cxgbe/cxgbei/icl_cxgbei.c b/sys/dev/cxgbe/cxgbei/icl_cxgbei.c index e974ad73a935..4a6cf0a19d44 100644 --- a/sys/dev/cxgbe/cxgbei/icl_cxgbei.c +++ b/sys/dev/cxgbe/cxgbei/icl_cxgbei.c @@ -881,7 +881,14 @@ icl_cxgbei_conn_close(struct icl_conn *ic) INP_WLOCK(inp); if (toep != NULL) { /* NULL if connection was never offloaded. */ toep->ulpcb = NULL; + + /* Discard PDUs queued for TX. */ mbufq_drain(&toep->ulp_pduq); + + /* + * Wait for the cwt threads to stop processing this + * connection. + */ SOCKBUF_LOCK(sb); if (icc->rx_flags & RXF_ACTIVE) { volatile u_int *p = &icc->rx_flags; @@ -896,6 +903,10 @@ icl_cxgbei_conn_close(struct icl_conn *ic) SOCKBUF_LOCK(sb); } + /* + * Discard received PDUs not passed to the iSCSI + * layer. + */ while (!STAILQ_EMPTY(&icc->rcvd_pdus)) { ip = STAILQ_FIRST(&icc->rcvd_pdus); STAILQ_REMOVE_HEAD(&icc->rcvd_pdus, ip_next); @@ -914,7 +925,22 @@ icl_cxgbei_conn_close(struct icl_conn *ic) * queues were purged instead of delivered reliably but soabort isn't * really general purpose and wouldn't do the right thing here. */ + soref(so); soclose(so); + + /* + * Wait for the socket to fully close. This ensures any + * pending received data has been received (and in particular, + * any data that would be received by DDP has been handled). + * Callers assume that it is safe to free buffers for tasks + * and transfers after this function returns. + */ + SOCK_LOCK(so); + while ((so->so_state & SS_ISDISCONNECTED) == 0) + mtx_sleep(&so->so_timeo, SOCK_MTX(so), PSOCK, "conclo2", 0); + CURVNET_SET(so->so_vnet); + sorele(so); + CURVNET_RESTORE(); } static void