Index | Thread | Search

From:
Vitaliy Makkoveev <mvs@openbsd.org>
Subject:
unix(4): use atomic_load_int() to unlocked access to `unp*_*space'
To:
tech@openbsd.org, Alexander Bluhm <bluhm@openbsd.org>
Date:
Tue, 6 Aug 2024 18:35:53 +0300

Download raw body.

Thread
We decided to use atomic_load_*() to unlocked access to integers. So
adjust uipc_attach(). 

Index: sys/kern/uipc_usrreq.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v
diff -u -p -r1.208 uipc_usrreq.c
--- sys/kern/uipc_usrreq.c	28 Jun 2024 21:30:24 -0000	1.208
+++ sys/kern/uipc_usrreq.c	6 Aug 2024 15:32:30 -0000
@@ -235,12 +235,12 @@ uipc_setaddr(const struct unpcb *unp, st
  * be large enough for at least one max-size datagram plus address.
  */
 #define	PIPSIZ	8192
-u_int	unpst_sendspace = PIPSIZ;
-u_int	unpst_recvspace = PIPSIZ;
-u_int	unpsq_sendspace = PIPSIZ;
-u_int	unpsq_recvspace = PIPSIZ;
-u_int	unpdg_sendspace = 2*1024;	/* really max datagram size */
-u_int	unpdg_recvspace = 16*1024;
+u_int	unpst_sendspace = PIPSIZ;	/* [a] */
+u_int	unpst_recvspace = PIPSIZ;	/* [a] */
+u_int	unpsq_sendspace = PIPSIZ;	/* [a] */
+u_int	unpsq_recvspace = PIPSIZ;	/* [a] */
+u_int	unpdg_sendspace = 2*1024;	/* [a] really max datagram size */
+u_int	unpdg_recvspace = 16*1024;	/* [a] */
 
 const struct sysctl_bounded_args unpstctl_vars[] = {
 	{ UNPCTL_RECVSPACE, &unpst_recvspace, 0, SB_MAX },
@@ -267,15 +267,21 @@ uipc_attach(struct socket *so, int proto
 		switch (so->so_type) {
 
 		case SOCK_STREAM:
-			error = soreserve(so, unpst_sendspace, unpst_recvspace);
+			error = soreserve(so,
+			    atomic_load_int(&unpst_sendspace),
+			    atomic_load_int(&unpst_recvspace));
 			break;
 
 		case SOCK_SEQPACKET:
-			error = soreserve(so, unpsq_sendspace, unpsq_recvspace);
+			error = soreserve(so,
+			    atomic_load_int(&unpsq_sendspace),
+			    atomic_load_int(&unpsq_recvspace));
 			break;
 
 		case SOCK_DGRAM:
-			error = soreserve(so, unpdg_sendspace, unpdg_recvspace);
+			error = soreserve(so,
+			    atomic_load_int(&unpdg_sendspace),
+			    atomic_load_int(&unpdg_recvspace));
 			break;
 
 		default: