🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25641

[PATCH RFC net-next 1/2] af_unix: Add SO_MAX_DGRAM_QLEN for per-socket datagram queue length

#25641
From: Ishu Brar via B4 Relay
Date: Wed, 02 Dec 2026 07:09
167 lines
14188 bytes
From: Ishu Brar <patches@brar.si>

Datagram queue length of AF_UNIX socket is sk_max_ack_backlog, copied
from net.unix.max_dgram_qlen at creation, can't be changed after,
listen() is refused on datagram sockets.

This hurts long-lived sockets created early in boot, like journald's
/dev/log. PID 1 creates it before sysctl.d is applied, keeps it across
journald restarts, so admin's value never reaches it. All syslog(3)
callers share that queue, when it's full, blocking senders stall,
non-blocking ones drop messages. Only way today is changing sysctl
globally before socket is created, which hits every other socket created
meanwhile too.

SO_RCVBUF doesn't help, AF_UNIX datagram sockets never check receiver's
sk_rcvbuf, so queue length is only limit receiver has.

Add SO_MAX_DGRAM_QLEN to set it per socket:

 - SOCK_DGRAM only, -ENOPROTOOPT otherwise.
 - negative value gives -EINVAL, same as sysctl.
 - going above sysctl needs CAP_NET_ADMIN in user ns owning socket's
   netns, sysctl itself can be set there.
 - same meaning as sysctl, queue is full when it holds more than that
   many datagrams.
 - lowering keeps what's already queued.
 - raising wakes all senders blocked in sendmsg() or waiting in poll(),
   no recvmsg() will do it for them.

sk_max_ack_backlog is now written while senders read it without lock in
unix_recvq_full_lockless(), so annotate both sides.

Idea is KF.71 on UAPI group kernel wishlist.

Link: https://github.com/uapi-group/kernel-features
Link: https://github.com/systemd/systemd/issues/45144
Signed-off-by: Ishu Brar <patches@brar.si>
---
 arch/alpha/include/uapi/asm/socket.h  |  2 ++
 arch/mips/include/uapi/asm/socket.h   |  2 ++
 arch/parisc/include/uapi/asm/socket.h |  2 ++
 arch/sparc/include/uapi/asm/socket.h  |  2 ++
 include/uapi/asm-generic/socket.h     |  2 ++
 net/unix/af_unix.c                    | 27 ++++++++++++++++++++++++++-
 6 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/arch/alpha/include/uapi/asm/socket.h b/arch/alpha/include/uapi/asm/socket.h
index 430ef65e51ea..189acf751a66 100644
--- a/arch/alpha/include/uapi/asm/socket.h
+++ b/arch/alpha/include/uapi/asm/socket.h
@@ -163,6 +163,8 @@
 
 #define SO_PASSCRED_THREAD     88
 
+#define SO_MAX_DGRAM_QLEN     89
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/mips/include/uapi/asm/socket.h b/arch/mips/include/uapi/asm/socket.h
index 7e49b24170d2..93e5a056e6d1 100644
--- a/arch/mips/include/uapi/asm/socket.h
+++ b/arch/mips/include/uapi/asm/socket.h
@@ -174,6 +174,8 @@
 
 #define SO_PASSCRED_THREAD     88
 
+#define SO_MAX_DGRAM_QLEN     89
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/parisc/include/uapi/asm/socket.h b/arch/parisc/include/uapi/asm/socket.h
index e414c2397224..f79087bfbf4f 100644
--- a/arch/parisc/include/uapi/asm/socket.h
+++ b/arch/parisc/include/uapi/asm/socket.h
@@ -155,6 +155,8 @@
 
 #define SO_PASSCRED_THREAD	0x4056
 
+#define SO_MAX_DGRAM_QLEN	0x4057
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/sparc/include/uapi/asm/socket.h b/arch/sparc/include/uapi/asm/socket.h
index 9ca7ec9ba450..fee3b12313b7 100644
--- a/arch/sparc/include/uapi/asm/socket.h
+++ b/arch/sparc/include/uapi/asm/socket.h
@@ -156,6 +156,8 @@
 
 #define SO_PASSCRED_THREAD       0x0061
 
+#define SO_MAX_DGRAM_QLEN       0x0062
+
 #if !defined(__KERNEL__)
 
 
diff --git a/include/uapi/asm-generic/socket.h b/include/uapi/asm-generic/socket.h
index 2e5d9db1c9fa..0b392c252307 100644
--- a/include/uapi/asm-generic/socket.h
+++ b/include/uapi/asm-generic/socket.h
@@ -158,6 +158,8 @@
 
 #define SO_PASSCRED_THREAD	88
 
+#define SO_MAX_DGRAM_QLEN	89
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 53a5553bfb66..2afa958c8e2b 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -287,7 +287,8 @@ static inline int unix_may_send(struct sock *sk, struct sock *osk)
 
 static inline int unix_recvq_full_lockless(const struct sock *sk)
 {
-	return skb_queue_len_lockless(&sk->sk_receive_queue) > sk->sk_max_ack_backlog;
+	return skb_queue_len_lockless(&sk->sk_receive_queue) >
+	       READ_ONCE(sk->sk_max_ack_backlog);
 }
 
 struct sock *unix_peer_get(struct sock *s)
@@ -945,6 +946,7 @@ static bool unix_custom_sockopt(int optname)
 	switch (optname) {
 	case SO_INQ:
 	case SO_RIGHTS_NOTRUNC:
+	case SO_MAX_DGRAM_QLEN:
 		return true;
 	default:
 		return false;
@@ -988,6 +990,29 @@ static int unix_setsockopt(struct socket *sock, int level, int optname,
 		WRITE_ONCE(u->scm_rights_notrunc, val);
 		break;
 
+	case SO_MAX_DGRAM_QLEN: {
+		struct net *net = sock_net(sk);
+		u32 old;
+
+		if (sk->sk_type != SOCK_DGRAM)
+			return -ENOPROTOOPT;
+
+		if (val < 0)
+			return -EINVAL;
+
+		if (val > READ_ONCE(net->unx.sysctl_max_dgram_qlen) &&
+		    !sockopt_ns_capable(net->user_ns, CAP_NET_ADMIN))
+			return -EPERM;
+
+		old = READ_ONCE(sk->sk_max_ack_backlog);
+		WRITE_ONCE(sk->sk_max_ack_backlog, val);
+
+		/* Raising frees slots without a read: wake all senders. */
+		if (val > old)
+			wake_up_interruptible_all(&u->peer_wait);
+		break;
+	}
+
 	default:
 		return -ENOPROTOOPT;
 	}

-- 
2.56.1
Technical Details
Message-ID: <20261202-af-unix-dgram-qlen-v1-1-043723f83d6d@brar.si>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375599-linux-kernel-netdev=dewy.ru
References: <20261202-af-unix-dgram-qlen-v1-0-043723f83d6d@brar.si>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375599-linux-kernel-netdev=dewy.ru
From: devnull+patches.brar.si@kernel.org (Ishu Brar via B4 Relay)
Newsgroups: linux.kernel.netdev
Subject: [PATCH RFC net-next 1/2] af_unix: Add SO_MAX_DGRAM_QLEN for
 per-socket datagram queue length
Date: Wed, 02 Dec 2026 12:39:17 +0530
Organization: Usenet Network
Message-ID: <20261202-af-unix-dgram-qlen-v1-1-043723f83d6d@brar.si>
References: <20261202-af-unix-dgram-qlen-v1-0-043723f83d6d@brar.si>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="1912218"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:xqq0F79lFZScPwJiK06HL1aQD2k= sha256:Gpq8koqrdi2UdBkK+6YVEBUGD+QoZQlhS4rV+1hv8jc=
	sha1:Az72jSPbmd6xrOsOYJa6uBQ5cO8= sha256:9C/q66G9NHgtSqx/t9GELXgGZlMUp2w6w9Inmez4z2Y=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 57A591171EB; Wed,  2 Dec 2026 10:09:42 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.401
X-Spam-Status: No, score=-2.401 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id kHsd-CLZokSC;
	Wed,  2 Dec 2026 10:09:38 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-375599-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 78125117581; Wed,  2 Dec 2026 10:09:29 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 1783A60190E; Wed,  2 Dec 2026 07:09:28 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 15F9E606A68F;
	Wed,  2 Dec 2026 07:09:26 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KLtDvOVQ
X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail;
	t=1796195365;
	b=kioqoMuQAm1cxRTYqA5wkdmE1cQF2oh1qazcjkRxduGO4W9pk349t7Xy7KDR7Go1+bL2
	 PHZ3MdRg89YmAUf2z+9OhPbSqFCY+mTRwC6djTyrwNQGMkzQBOUATAKHuY+86ZN0zkIb4
	 dMQCZpfAc8ztrytASxa1fRM4/uuD7QRTggHpEtKCh1E4g9ROY+5hB3P8IIDawgs7xcqJh
	 GSnwkHi4L3c5S4X/Glvbo+tOzv7E2rMlYCE0ywVKsTPOCmE6jLH7iAySp+d15VTgZ0bm2
	 94kIp7sytWgSbTyRvgZIVcnRmD23eh9K0dfp8TD4JaGnLsCB7YcFnQWNLT/5ruv7ipg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796195365;
	h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version:
	 Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer:
	 X-Developer-Signature:X-Developer-Key:X-Endpoint-Received:
	 X-Original-From:Reply-To:Content-Transfer-Encoding;
	bh=ufJQugrx74CK5g0zW0ajaUXJFiStUiiBfpls/tHrnLw=;
	b=wulMemYWSfy6YYO17lLHgmT2y+FdDbM1ffXFww+Lzcs1mR8Ln3DJK53YaZhtv7PGp5cg
	 f/0oLZBZggHlvHw9FKmkaEs8qNLwYESKBuWD7pTYTGbaE528hifz28B6d4Tj3lf+R3fVQ
	 0CsoYK8b1svRyqokX2REOadPt4Wysie1yJaja4Jf8Rk2JyKLowqnU5OflNn/p2j7kNntB
	 98CPT7pQO3ifSi1sBXF46q5L9gsjdIhcl2cENYNQc1lmj6qLMopCTy53esSq20aLkqjnU
	 w7afRAW8gZxwxyFzppkpWUioW/SiztxGqN/noapriGpa46KmzCn6pKLgFMeHxY6JP8g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KLtDvOVQ;
	arc=fail smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30DA7606A322;
	Wed,  2 Dec 2026 07:09:25 +0000 (UTC)
X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77
X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none;
	t=1796195364;
	b=FsAsACiiReFIUTsQ5vqPhgRjNrkYFXR7CTUvCiK6XFFm6c2NluRLKoE6iQdUUGCSDM6m
	 Grg3CiD8YjUU4vOYenqbg6mgdo4ePEAOn1tPkRu3r9fNfxqmdn+AKADaZmcx76WPJvvSn
	 P/BR02vyP6YTS5e+UzaZGU5fmowP1Lx32T5TURT2pPUMSZFHuWltYwxW8BHnjMIqgKabm
	 aaKV5mvm2CS8C69R8HT15IyY18YbTGtnsfC00eR5563vUa2cz1uVnn5WppUhCSXfaLiB3
	 u7gBK348KtTFTVopI+Onf9pE62CcOwlctIaqujswGhlpu3LqtNgKI0IAOT+b7Q6+Fdw==
X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256;
	c=relaxed/relaxed; t=1796195364;
	h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type:
	 Message-Id:References:In-Reply-To:To:Cc:X-Mailer:
	 X-Developer-Signature:X-Developer-Key:X-Endpoint-Received:
	 X-Original-From:Reply-To:Content-Transfer-Encoding;
	bh=ufJQugrx74CK5g0zW0ajaUXJFiStUiiBfpls/tHrnLw=;
	b=tEovtVGCu1W0LJC2e1PPbXq9ZKxpzaXLhnSfvrH6sZwYCX711vtpyKL0+jSMDTBlZKFH
	 E4Lr6FA8+/E0QyIC6l8FRmOQbfKtsQ5UV/98+4I9rDmgfCe2y77ibyD4wL8PoGWGQgK3e
	 HGNJZsppPko00yRCPgo6PnaTdYxAjT7Ja+r88X3oHQJUjlPEjLFiXv4LECDlaq/ccu3FF
	 uqPIgAt/AzPOLjX4RTHkCuHPvvEJ+D+w8Mf14qT+P2zrHWNUyB341whf+bpbsEJomK0KO
	 kxwxf6LY/BTqL2D9A1fT4VEO6bFymeGTITyJ68UXlzrQgf1jSnSAqBPbuNUK465RqbA==
X-ARC-Authentication-Results: i=1; smtp.kernel.org; 
	arc=none smtp.remote-ip=100.80.115.77
X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.kernel.org (Postfix) with ESMTPS id 1A6CD1F00896;
	Wed,  2 Dec 2026 07:09:24 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796195364;
	bh=ufJQugrx74CK5g0zW0ajaUXJFiStUiiBfpls/tHrnLw=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To;
	b=KLtDvOVQfIWsZidPQ5vuStQAXPvOAxGhQWMEkCOJWHFgO+7+C3DE1wIbbN6SdwjpC
	 oY0ki2AmQFLVfbLoHu6vscd8vGz6XRb27/CwZXvsTCq/ICBDVDLfJTqPYA6isVw/te
	 GCPbZbqfuwKQFNILSCJzrc/m8liEX0SaePGJHxTjaMfgSiiz4dMuIQIBk6jsAhTVUn
	 7SmoCmi/W3g1Jfdm7h35+pcAQ/Di8o7HYCFIGTGpLEI0Fp8OVu+sbyFYa5fkQ2oYxq
	 9TDBa7f0yR844NlTmJ954tQVErSBAhDPQE3hdzPFBYGyABfyYzzaJmBCA4JAqnr3VE
	 I27gTS+pKq9UA==
X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1])
	by lkml.kernel.org (Postfix) with ESMTP id 9A4C04F2C2;
	Wed,  2 Dec 2026 07:09:23 +0000 (UTC)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261202-af-unix-dgram-qlen-v1-0-043723f83d6d@brar.si>
X-Cc: linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, 
 linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, 
 linux-arch@vger.kernel.org, netdev@vger.kernel.org, 
 linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, 
 Christian Brauner <brauner@kernel.org>, Ishu Brar <patches@brar.si>
X-Mailer: b4 0.15.2
X-Developer-Signature: v=1; a=ed25519-sha256; t=1796195361; l=5384;
 i=patches@brar.si; h=from:subject:message-id;
 bh=EvaeW8mhO0UXmqLNUjFMlUKMNHCi76d7pLL7r3xBah0=;
 b=4Lfu5owOphW6GYSqmHp7n/K3nlCwzQB9rvV1UXprmN3kC3UwMuVolAEGRzHc5yK8rPCiYk5EI
 OfESwQ0Jn2HD25/xrEeqaul04po1931e6Mnl5K7gzNHTmC6AvEzF0Rt
X-Developer-Key: i=patches@brar.si; a=ed25519;
 pk=Ds+E23E3ntzjPzuBDyVRkOouclcNI5k75R+N42yJtCk=
X-Endpoint-Received: by B4 Relay for patches@brar.si/default with
 auth_id=1189
X-Original-From: Ishu Brar <patches@brar.si>
X-Reply-To: patches@brar.si