From nobody Sat Feb 03 21:10:54 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 4TS50H2218z58RFn; Sat, 3 Feb 2024 21:10:55 +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 4TS50H1YmMz4CVm; Sat, 3 Feb 2024 21:10:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706994655; 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=MpYd9UuhU7WztUWTEJhi18grFmghzDwR+X8c5jowKQ0=; b=INsjdLGiYGKd1A7pWZFOb121b93q2MUAoF8ftMlAPYV6peZLq/89eh/xku1eHe6EjWbaoR U9kOiS6XmrHRs5ypKYkqfwqwYCgcC2NrLNEhnl3ln7XZCTOf+2gfMaGUdEw/DlZRFKjkxk MwSnNvXsalIMUYME02i+rB0QP/J/OZIA6fRlLkEM0hcuh4F9mWrL/lv0L8kuraGH56wnWF aUK7YGpCqT3g4aZ+MzlSe/o0H+X/MK4j1PS7oARYJNI55D/UxvsqTF89WL9lh6qcwLCuIV SyehrN2QlUqY1exDc5YOsLwwIxRc0S5JEvJc6Wt6ORr3m0ODuAuAkIG4yU0N8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706994655; 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=MpYd9UuhU7WztUWTEJhi18grFmghzDwR+X8c5jowKQ0=; b=oS8Kx/Z5hljO9yeKxVP9LYVwF+oxfIlbR/ZyVIGHRj5XQfmJP0QrWhPfSYYi65OVJEsOPm N3DNrUp/MFw7i6euQfCASAtQNwPb8uwWeaSsvJz0ShACpPmpYjAWJUT3xkRX+16+K587zn v1BhYjIa9SnNgtjEiI9q6zo0f43YtSjp2UYDezItqLOvNRqbXaiXPPBcvfMasY169JahLM 8cukcPJ4McDyAeizhWthsLgholBa2GeejBRlZocV9Xhr8kGdh2Ag0tkrXbTJqi1V85NH/F 1bSr2s7sG/OwAFPuMZFdF+u7Egryyegyt5pXurX4aCAI/B6Ii+w4eAJXPmV9NA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706994655; a=rsa-sha256; cv=none; b=bu+5lWMmFxe2H7J5yHy4H0214+uav86kRssTwuUL9vZ7XckcrCxIEr+EKuDavEx2tpN3IO 18HyHzcRzH0BOnXl52Iq35igVpSjDHMpjnLjTMXUfkMkANgwMhrxw6XeyLHecaOk0OWTN9 jOIbcq7JiKlGTA1RqRzHkCU5NUKpjU2I+hymLxtYkIDMp674LezXx83IPb5+iEQ0YMRRd+ 6QIQ4n1KVly49tKGEv8o6HByDT+Sy9cKIbvuKEDDhZAs3kheGp01T1HmHyK6npJ1aYzxjA 3FwrwZYkztL9RJD+ps+O6JzqsrCE3CKInsxWhadGenNL1KphAgDbrFWwpuIZqw== 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 4TS50H0XMRzSyv; Sat, 3 Feb 2024 21:10:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 413LAsr8093266; Sat, 3 Feb 2024 21:10:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 413LAsEU093263; Sat, 3 Feb 2024 21:10:54 GMT (envelope-from git) Date: Sat, 3 Feb 2024 21:10:54 GMT Message-Id: <202402032110.413LAsEU093263@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: ce69e37369aa - main - Revert "sockets: retire sorflush()" 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: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ce69e37369aa44a96113387253aadc5e49246928 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=ce69e37369aa44a96113387253aadc5e49246928 commit ce69e37369aa44a96113387253aadc5e49246928 Author: Gleb Smirnoff AuthorDate: 2024-02-03 21:08:41 +0000 Commit: Gleb Smirnoff CommitDate: 2024-02-03 21:08:41 +0000 Revert "sockets: retire sorflush()" Provide a comment in sorflush() why the socket I/O sx(9) lock is actually important. This reverts commit 507f87a799cf0811ce30f0ae7f10ba19b2fd3db3. --- sys/kern/uipc_socket.c | 42 +++++++++++++++++++++++++++++++++++++++--- sys/net/rtsock.c | 6 ++---- sys/netinet/raw_ip.c | 6 ++---- sys/netinet/sctp_usrreq.c | 6 +++++- sys/netinet/tcp_usrreq.c | 6 ++---- sys/netinet/udp_usrreq.c | 6 ++---- sys/netinet6/raw_ip6.c | 6 ++---- sys/sys/socketvar.h | 1 + 8 files changed, 55 insertions(+), 24 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 5e5e7d2cd058..b647766cf258 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -95,9 +95,9 @@ * * NOTE: With regard to VNETs the general rule is that callers do not set * curvnet. Exceptions to this rule include soabort(), sodisconnect(), - * sofree() (and with that sorele(), sotryfree()), as well as sonewconn(), - * which are usually called from a pre-set VNET context. sopoll() currently - * does not need a VNET context to be set. + * sofree(), sorele(), sonewconn() and sorflush(), which are usually called + * from a pre-set VNET context. sopoll() currently does not need a VNET + * context to be set. */ #include @@ -2964,6 +2964,42 @@ soshutdown(struct socket *so, enum shutdown_how how) return (error); } +/* + * Used by several pr_shutdown implementations that use generic socket buffers. + */ +void +sorflush(struct socket *so) +{ + int error; + + VNET_SO_ASSERT(so); + + /* + * Dislodge threads currently blocked in receive and wait to acquire + * a lock against other simultaneous readers before clearing the + * socket buffer. Don't let our acquire be interrupted by a signal + * despite any existing socket disposition on interruptable waiting. + * + * The SOCK_IO_RECV_LOCK() is important here as there some pr_soreceive + * methods that read the top of the socket buffer without acquisition + * of the socket buffer mutex, assuming that top of the buffer + * exclusively belongs to the read(2) syscall. This is handy when + * performing MSG_PEEK. + */ + socantrcvmore(so); + + error = SOCK_IO_RECV_LOCK(so, SBL_WAIT | SBL_NOINTR); + if (error != 0) { + KASSERT(SOLISTENING(so), + ("%s: soiolock(%p) failed", __func__, so)); + return; + } + + sbrelease(so, SO_RCV); + SOCK_IO_RECV_UNLOCK(so); + +} + /* * Wrapper for Socket established helper hook. * Parameters: socket, context of the hook point, hook id. diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index e4183232700e..e0411ed0c1d0 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -457,12 +457,10 @@ rts_shutdown(struct socket *so, enum shutdown_how how) */ switch (how) { case SHUT_RD: - socantrcvmore(so); - sbrelease(so, SO_RCV); + sorflush(so); break; case SHUT_RDWR: - socantrcvmore(so); - sbrelease(so, SO_RCV); + sorflush(so); /* FALLTHROUGH */ case SHUT_WR: socantsendmore(so); diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 004aaea01bfa..a6bef1c7e275 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -994,12 +994,10 @@ rip_shutdown(struct socket *so, enum shutdown_how how) switch (how) { case SHUT_RD: - socantrcvmore(so); - sbrelease(so, SO_RCV); + sorflush(so); break; case SHUT_RDWR: - socantrcvmore(so); - sbrelease(so, SO_RCV); + sorflush(so); /* FALLTHROUGH */ case SHUT_WR: socantsendmore(so); diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c index b847271a7bd3..70fe021be766 100644 --- a/sys/netinet/sctp_usrreq.c +++ b/sys/netinet/sctp_usrreq.c @@ -868,7 +868,11 @@ sctp_shutdown(struct socket *so, enum shutdown_how how) SCTP_TCB_UNLOCK(stcb); } SCTP_INP_WUNLOCK(inp); - socantrcvmore(so); + /* + * XXXGL: does SCTP need sorflush()? This is what old + * soshutdown() used to do for all kinds of sockets. + */ + sorflush(so); if (how == SHUT_RD) break; /* FALLTHROUGH */ diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 7c8e3d7e72db..ccd6a6149dae 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -824,12 +824,10 @@ tcp_usr_shutdown(struct socket *so, enum shutdown_how how) switch (how) { case SHUT_RD: - socantrcvmore(so); - sbrelease(so, SO_RCV); + sorflush(so); break; case SHUT_RDWR: - socantrcvmore(so); - sbrelease(so, SO_RCV); + sorflush(so); /* FALLTHROUGH */ case SHUT_WR: /* diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 24bc3403b0f7..9dad79e95b04 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1722,12 +1722,10 @@ udp_shutdown(struct socket *so, enum shutdown_how how) switch (how) { case SHUT_RD: - socantrcvmore(so); - sbrelease(so, SO_RCV); + sorflush(so); break; case SHUT_RDWR: - socantrcvmore(so); - sbrelease(so, SO_RCV); + sorflush(so); /* FALLTHROUGH */ case SHUT_WR: socantsendmore(so); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 5b31a84f31eb..3264de331817 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -839,12 +839,10 @@ rip6_shutdown(struct socket *so, enum shutdown_how how) switch (how) { case SHUT_RD: - socantrcvmore(so); - sbrelease(so, SO_RCV); + sorflush(so); break; case SHUT_RDWR: - socantrcvmore(so); - sbrelease(so, SO_RCV); + sorflush(so); /* FALLTHROUGH */ case SHUT_WR: socantsendmore(so); diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 030087cbc17c..cba7dd655aa0 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -501,6 +501,7 @@ int soreceive_generic(struct socket *so, struct sockaddr **paddr, void sorele_locked(struct socket *so); void sodealloc(struct socket *); int soreserve(struct socket *so, u_long sndcc, u_long rcvcc); +void sorflush(struct socket *so); int sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, struct mbuf *top, struct mbuf *control, int flags, struct thread *td);