Article View: linux.kernel.netdev
Article #9239Re: [PATCH net] soreuseport: annotate data-races around reuse->socks[] and num_socks
From: Jiayuan Chen
Date: Sun, 01 Nov 2026 06:44
Date: Sun, 01 Nov 2026 06:44
40 lines
10013 bytes
10013 bytes
On 10/30/26 8:09 PM, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> reuseport_select_sock() and reuseport_migrate_sock() read
> reuse->num_socks and reuse->socks[] locklessly under RCU, while
> writers holding reuseport_lock can change them.
>
> Readers snapshot num_socks once, then index socks[] with it.
> Meanwhile, writers can perform several operations, storing into
> slots below the reader's stale count:
>
> - __reuseport_detach_sock() moves the last socket into slot i.
> - __reuseport_add_sock() then writes the new socket at the
> (now smaller) num_socks index.
> - reuseport_stop_listen_sock() calls __reuseport_detach_sock()
> then __reuseport_add_closed_sock(), which writes slot
> max_socks - num_closed_socks - 1. This can be the slot a reader
> still considers part of the listener region when the array is full.
> - __reuseport_detach_closed_sock() can then rewrite that slot.
>
> All pointers stored in socks[] remain valid for the RCU grace period,
> but without annotations the compiler is allowed to tear or reload
> these accesses. For instance, reuseport_select_sock_by_hash() could
> reload reuse->socks[i] between the sk_state/sk_incoming_cpu checks
> and the return, returning a socket that did not pass them.
>
> Use WRITE_ONCE() for all socks[] stores done while the array is
> visible to readers, and for num_socks updates (readers already use
> READ_ONCE()). Use READ_ONCE() in the two lockless readers.
>
> Fixes: ef456144da8e ("soreuseport: define reuseport groups")
> Link: https://lore.kernel.org/netdev/20260902071900.395567-1-ruanjinjie@huawei.com/
> Cc: Kuniyuki Iwashima <kuniyu@google.com>
> Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Technical Details
Message-ID:
<39bb2026-f872-4cad-88e1-ebd07f59f2a7@linux.dev>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354194-linux-kernel-netdev=dewy.ruReferences:
<20261030120956.3026324-1-edumazet@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354194-linux-kernel-netdev=dewy.ru From: jiayuan.chen@linux.dev (Jiayuan Chen) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] soreuseport: annotate data-races around reuse->socks[] and num_socks Date: Sun, 1 Nov 2026 14:44:47 +0800 Organization: Usenet Network Message-ID: <39bb2026-f872-4cad-88e1-ebd07f59f2a7@linux.dev> References: <20261030120956.3026324-1-edumazet@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="2638979"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:vZASNoGqvz9BMh0MYyQG+f4mANM= sha256:96tOCQ+Fxqr+SjQoTl0ehkNPc4nZrJOwp0KM/2BVcpM= sha1:X8KoYoSAVxfTNGjf0LJHSJxeUYU= sha256:IfxGlJftkdE9JChvu+csnZk0sclqR71+B7eQLimhi8I= 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 252101122E9; Sun, 1 Nov 2026 09:45:22 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.051 X-Spam-Status: No, score=-2.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, HK_RANDOM_FROM=0.999, 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 (1024-bit key) header.d=linux.dev 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 F8_CEN1EWZWM; Sun, 1 Nov 2026 09:45:18 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-354194-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id F100B1122E6; Sun, 1 Nov 2026 09:45:09 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id BD3DD220AA; Sun, 1 Nov 2026 06:45:03 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793515501; b=c2cQjgE5XswBZI4U4QBMPAcLrY1LHCgpFke1pzmZWnQsazduFj62FDvm63uoAEXSmYaI fUNR7XUc1jqUQrVMxFInefQDnHTFwTL7U3Z5XypXfqvt+a9hrpQJnw3ReFmXQwq7isZgd bq5zTaAk5pHavS83x77jI8/FrvauHDR1dxLlOs/O8gqvGs9EKcG5DatuWrr6rVyNSSPpd wjbRvYHF1POShLb9bFfpfXS9JIIqv6/wkyI3mqLlghU7B3+9pJ/tzk840vr90FcEckKx3 WuTGVB17AZXIm7eLi+6vMWj/1Dx43xhEz2B/fXMQbiY3YjdxNecIdD+Qy7XvJ7ZQ7Nw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793515501; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=MjeLtY2DBxlNulj/2LaRSITduXdqvnbab4uZr8PMSus=; b=MdwVP2nOBsNvWEW8MnSYhXLxwi4fExZVnDt4+vfpEnUqcz0ZOw/H2/5a6z9zcOZbLViR ggsxlUqb/98Lae7lIYnJhqTLFynuAXXbrGsq3ByhLvEt2OUvcH0+piGTyjzkxruCjBPc4 zQc5q0OUM+OuPCOPBjUturuPPYtkJtuiVlkvbyhsqS6IloHIsjL1duI/6UAkMddqqTNYq WN6hHuUEjj74sAeGGIBEngtQzdfgRbDN2prlOczlK5zUfPIPlH33yZx4mMS3POZ7vxEQ2 8ts9iXPvvPW8M2YeMYT44PD1kTA0YiCOK7txUvoeZXmPlvFd6xgM7aq3VZAtElR2zHg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=su9O7hYL; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 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 8582F606A334; Sun, 1 Nov 2026 06:45:01 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=su9O7hYL X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.135 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793515500; b=MntbXz7ffUjRjAx1ELgLFducxxFruxlCSJ8LZa9GCRgBUw7OZReV7ikxpZrsqU16wXvR L610/wRAl8d5GIL4lqbyMH0/hw4TUpdAUwa5lZEyVd32FZyLv/EPKVDbqKs8RCwZW/1qP GxRO/SPDX0wtFZertqtWMGxDinAZf6v+ZYTIMzsPMapiRwakTGnY2pQAkdYPw2jalLexE yH1zDV8q8i+GmPaea/7xzQrKp+tqbb4bto8Z/GZ5/8I4uXDSdwWBwc9oqJQtt8bb7ycDs S5T2sg/5hDb0trNNWOc5MHoUwBQ5XGS9x2y42vKpTsF2hXdmimj2KGzF4CJnTjket/g== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793515500; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=MjeLtY2DBxlNulj/2LaRSITduXdqvnbab4uZr8PMSus=; b=Z4u8OJQAjjEe0WB+iujmH7G8+vbSE0XI/pq65MoKNU4a4NB9UwWkSctfSepzhTQuAort Rg2tjgwVzhB+k5F2KlQpHYPX5gCWCnLV4vx3pSOQnsNVZpAHV2eZ3ownCQ+neHZn4qoUW vQ/EAOG6yzeQleYFx8C9yc++sBBQSY6AuleY6axeFpq1c89cDVlZaYDHDESH7IWbYBn1q 4GABLyqcaSrZG+v5DIyqIwdRe77r03Ip+NlWrOczIKnqTvoP7okQ0yujr4LySB/jHMQV1 9h/q6kEFeuPCUQtIQWMZxjAIrVSa+LeNL2nPKQbvPWGqsQnUNfoe8nuTG2rWeFxMrNg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=su9O7hYL; arc=none smtp.remote-ip=91.218.175.135 X-Received: from mta0.migadu.com (out-135.mta0.migadu.com [91.218.175.135]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B04B4606A324 for <netdev@vger.kernel.org>; Sun, 1 Nov 2026 06:44:59 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B04B4606A324 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=60GCInmN/tX0eq+1oSQw8M2qeJADVFWe9YKgp/0g2oo=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793515497; v=1; x=1794120297; b=su9O7hYL0nHUAwcQo9+DskVC9BPjURwpfRoPx0e1HYsmnUCa5X13aYYerUrPtLafGHMjnmcq gktSyaZVA14RAe+STRO4IFY6GPHf3uMqoxCOxiyHxpul9m2kF1Vuh0bv/Ixg0rGW/Y1/zDy3BV0 svXw6D0bOtl97ievYBVjdFlw= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id 8c32165ce84ce8c6; Sun, 01 Nov 2026 06:44:57 +0000 X-Mizu-Trace-ID: 8c32165ce84ce8c6 X-Migadu-Flow: FLOW_OUT 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-User-Agent: Mozilla Thunderbird X-Cc: Kuniyuki Iwashima <kuniyu@google.com>, Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, Eric Dumazet <edumazet@google.com> X-In-Reply-To: <20261030120956.3026324-1-edumazet@kernel.org>