From nobody Tue Jan 16 18:31:36 2024 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 4TDyJm6qYPz57mYp; Tue, 16 Jan 2024 18:31:36 +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 4TDyJm4Hw2z4wB3; Tue, 16 Jan 2024 18:31:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705429896; 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=OV0N1O9KYaxsRaYWjIakF8UuZSiu3IeDoCnYJV8afq4=; b=VWKPhBjr3atOH4JlBIwUtDtTaG8hh8SDCLHlLEwzFEn4ZPiTZZLmKbgI74xd+tIJ9Hrkap aLRDyispoVnKeqCZD0XggLuj43Elqko5cODZETxVvN/LqSSvZFYnCt4Qv9aTdc9+s9UuN4 arxC1dQgySq7DPVRT5HJqnaXgHd0N+FXb69Yz2JHnwzwbRhR4IB42URnLM7kMldyVq3Pbb 7GuzrUVfewVS+F3KUPpILBE173v3/WcqppnFCQqUTTQd9kJzYETbL5yQgNgWO/8aw+/GnT Lwy4RK8339lmrgOH5l7NQA2Q1EcHOGfrRjoMqHNYqSiPzMSTZ0IMYYDdFRT1Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705429896; 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=OV0N1O9KYaxsRaYWjIakF8UuZSiu3IeDoCnYJV8afq4=; b=FT/Ox8NTTDg6hMWaKwCvKYxMwLqWtsxsm+395q85ShcRykX9rub/Ptjh4zCJI71uYnqRtr +lVSYnRG6Wa4YO0+E6/iznuRQ3J+K8D5lfZOKBeiOdyd/bHE56YRY/MEDXPfH7efMjN+O9 lxEG+G2ptQv7IjW0HmmsMwPMH3FlkPJ6hPxfPlqmpJ3ymrRrRbae2H3SCs51qAvNZVUsaC WzBCYfqZcBeD6ZauWkBcg6mG5GdD+u4cdORRAZYQWb/hDJYspjWzUweIaX7QgH8qAuPWIU crTM3kQ3CG1ln/VAUTsowATfik61NMREwH6up+4R7BeMiw0xi1p72UZSZx37EQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705429896; a=rsa-sha256; cv=none; b=bDwppZohXUOY3GvereC2pdtuM7XerZlJHLpQdxXgBSQA6aK7ivhca1zhaTboKaQXk9IAd1 lwXNRxbvxhaCcNIXZS0kXdrqW4BK0HQMMbWk79IQBwOAt1L7qJI1XnlbdVCkorWRvje0/d qPPhJ17X/zFaTQr2RrG7M3Yzts0rW88E1lsTuiXJZqW6T5H6lfIXS9IKRURrqvGczTIi2n VWBHPaKinBd3JfE0tu1/3OLega39HlMiP4/Tz2u7SVT261bJzSceSVF0dCw0wQMBqT06lf 4uBe0eCIzBuDvWEXHjN+JSe9+6HQf8ny/MvystzGnD9KqfizNo1gkLRgg+1/Dg== 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 4TDyJm3MJzzrFd; Tue, 16 Jan 2024 18:31:36 +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 40GIVaal056002; Tue, 16 Jan 2024 18:31:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40GIVaUO055999; Tue, 16 Jan 2024 18:31:36 GMT (envelope-from git) Date: Tue, 16 Jan 2024 18:31:36 GMT Message-Id: <202401161831.40GIVaUO055999@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: 507f87a799cf - main - sockets: retire sorflush() 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: 507f87a799cf0811ce30f0ae7f10ba19b2fd3db3 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=507f87a799cf0811ce30f0ae7f10ba19b2fd3db3 commit 507f87a799cf0811ce30f0ae7f10ba19b2fd3db3 Author: Gleb Smirnoff AuthorDate: 2024-01-16 18:26:10 +0000 Commit: Gleb Smirnoff CommitDate: 2024-01-16 18:30:49 +0000 sockets: retire sorflush() With removal of dom_dispose method the function boils down to two meaningful function calls: socantrcvmore() and sbrelease(). The latter is only relevant for protocols that use generic socket buffers. The socket I/O sx(9) lock acquisition in sorflush() is not relevant for shutdown(2) operation as it doesn't do any I/O that may interleave with read(2) or write(2). The socket buffer mutex acquisition inside sbrelease() is what guarantees thread safety. This sx(9) acquisition in soshutdown() can be tracked down to 4.4BSD times, where it used to be sblock(), and it was carried over through the years evolving together with sockets with no reconsideration of why do we carry it over. I can't tell if that sblock() made sense back then, but it doesn't make any today. Reviewed by: tuexen Differential Revision: https://reviews.freebsd.org/D43415 --- sys/kern/uipc_socket.c | 36 +++--------------------------------- 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, 24 insertions(+), 49 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 1626c6a7442d..65230e39e4ae 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() - * and sorflush(), which are usually called from a pre-set VNET context. - * sopoll() currently does not need a VNET context to be set. + * 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. */ #include @@ -2971,36 +2971,6 @@ 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. - */ - 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 94d5e9e4bccc..cb149f176b6d 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -457,10 +457,12 @@ rts_shutdown(struct socket *so, enum shutdown_how how) */ switch (how) { case SHUT_RD: - sorflush(so); + socantrcvmore(so); + sbrelease(so, SO_RCV); break; case SHUT_RDWR: - sorflush(so); + socantrcvmore(so); + sbrelease(so, SO_RCV); /* FALLTHROUGH */ case SHUT_WR: socantsendmore(so); diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index a6bef1c7e275..004aaea01bfa 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -994,10 +994,12 @@ rip_shutdown(struct socket *so, enum shutdown_how how) switch (how) { case SHUT_RD: - sorflush(so); + socantrcvmore(so); + sbrelease(so, SO_RCV); break; case SHUT_RDWR: - sorflush(so); + socantrcvmore(so); + sbrelease(so, SO_RCV); /* FALLTHROUGH */ case SHUT_WR: socantsendmore(so); diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c index ec9f211b519b..51c056e052a5 100644 --- a/sys/netinet/sctp_usrreq.c +++ b/sys/netinet/sctp_usrreq.c @@ -868,11 +868,7 @@ sctp_shutdown(struct socket *so, enum shutdown_how how) SCTP_TCB_UNLOCK(stcb); } SCTP_INP_WUNLOCK(inp); - /* - * XXXGL: does SCTP need sorflush()? This is what old - * soshutdown() used to do for all kinds of sockets. - */ - sorflush(so); + socantrcvmore(so); if (how == SHUT_RD) break; /* FALLTHROUGH */ diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index ccd6a6149dae..7c8e3d7e72db 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -824,10 +824,12 @@ tcp_usr_shutdown(struct socket *so, enum shutdown_how how) switch (how) { case SHUT_RD: - sorflush(so); + socantrcvmore(so); + sbrelease(so, SO_RCV); break; case SHUT_RDWR: - sorflush(so); + socantrcvmore(so); + sbrelease(so, SO_RCV); /* FALLTHROUGH */ case SHUT_WR: /* diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index f91a96edeb68..b68ec95a923a 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1696,10 +1696,12 @@ udp_shutdown(struct socket *so, enum shutdown_how how) switch (how) { case SHUT_RD: - sorflush(so); + socantrcvmore(so); + sbrelease(so, SO_RCV); break; case SHUT_RDWR: - sorflush(so); + socantrcvmore(so); + sbrelease(so, SO_RCV); /* FALLTHROUGH */ case SHUT_WR: socantsendmore(so); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 3264de331817..5b31a84f31eb 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -839,10 +839,12 @@ rip6_shutdown(struct socket *so, enum shutdown_how how) switch (how) { case SHUT_RD: - sorflush(so); + socantrcvmore(so); + sbrelease(so, SO_RCV); break; case SHUT_RDWR: - sorflush(so); + socantrcvmore(so); + sbrelease(so, SO_RCV); /* FALLTHROUGH */ case SHUT_WR: socantsendmore(so); diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 19ca52177d17..5d651b36b1e7 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -501,7 +501,6 @@ 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);