From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF04E26AA94; Wed, 4 Jun 2025 01:04:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748999062; cv=none; b=dwGrMzGkhZ/pQ8KWPRO8YNq5RmmwTrkAIug1+5oif5G00AKP2HmFrZjRGm+FLr3jvi3/QrNyWNEZKPEbgWDpEOtJD5Ehh2gdWuWgvHSlRfwnbVXjdLq9y4JVP9KPgnQcAHF6gsD319klEdcoJb+nwc7R4YqFRJidydTidhb8Wnw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748999062; c=relaxed/simple; bh=ZeGSuN4SU3Dwm2OGeK26dtZpnE9Mwo/a8b6u3iPrr5s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=WFE6udNWk8zEIJYJyKVO7HxduC8mjIJamqom5QiTu+dGzJXaky5KyLX812hxBUWARn5OnIYC+iQ95cyaLGz7k0qnJpekCoBXaBGIWBfnj9c1wSg7/S18SNmrMR6IDWqejeo5uKxs19g37eIDc2UBgFt9LybK9iVIFhDEbJdMZxk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pUgerX1S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pUgerX1S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FFCEC4CEF1; Wed, 4 Jun 2025 01:04:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1748999062; bh=ZeGSuN4SU3Dwm2OGeK26dtZpnE9Mwo/a8b6u3iPrr5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pUgerX1SRK3jO2UEja6xepr+wopqJexOUZgNk1QBPT35PjcBfu2nqMwVKyuA1qkeg 2O0GScSTiGCu3bFwVPPEtV41hE7Pqyr8Dn+nbDVCnB6MZXQKdj/Dw0/ZPiFB3+7bB+ E41mFHN2g7heZdvVAjHYIfAd95yqyOI+PBxOlKypEYQTTePbfw+d3xIJb1aEgRK2fg VH8ltyKnQLFWtB3iZh27Y+7s/DFZ65FW+PMe/xURtZP+ru0TosM27Uwx7O/rIW3BzP u2oTl4rozsgviFNODEv66jH/vcwPLkmiSjf5erNSyd4P7hZeQhT0AeRKLlSRy7Fuk6 x6D5sk9RywdbQ== From: Sasha Levin To: patches@lists.linux.dev, stable@vger.kernel.org Cc: Petr Malat , Xin Long , Jakub Kicinski , Sasha Levin , marcelo.leitner@gmail.com, linux-sctp@vger.kernel.org Subject: [PATCH AUTOSEL 6.1 09/46] sctp: Do not wake readers in __sctp_write_space() Date: Tue, 3 Jun 2025 21:03:27 -0400 Message-Id: <20250604010404.5109-9-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250604010404.5109-1-sashal@kernel.org> References: <20250604010404.5109-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-sctp@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.140 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Petr Malat [ Upstream commit af295892a7abbf05a3c2ba7abc4d81bb448623d6 ] Function __sctp_write_space() doesn't set poll key, which leads to ep_poll_callback() waking up all waiters, not only these waiting for the socket being writable. Set the key properly using wake_up_interruptible_poll(), which is preferred over the sync variant, as writers are not woken up before at least half of the queue is available. Also, TCP does the same. Signed-off-by: Petr Malat Acked-by: Xin Long Link: https://patch.msgid.link/20250516081727.1361451-1-oss@malat.biz Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- Based on my analysis of the commit and comparison with similar historical commits, here is my assessment: **YES** This commit should be backported to stable kernel trees. ## Detailed Analysis: ### 1. **Core Issue Being Fixed** The commit addresses a specific bug in SCTP's `__sctp_write_space()` function where `wake_up_interruptible()` is called without setting a poll key. This causes `ep_poll_callback()` to wake up **all** waiters on the socket, not just those waiting for writability (EPOLLOUT events). This is inefficient and can cause spurious wake-ups for readers waiting on the same socket. ### 2. **Code Changes Analysis** The fix is minimal and surgical: ```c // Before: wake_up_interruptible(&wq->wait); // After: wake_up_interruptible_poll(&wq->wait, EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND); ``` ### 3. **Consistency with Existing Patterns** Looking at `/home/sasha/linux/net/core/stream.c:41-42`, I can see that the fix aligns with established patterns in the kernel networking stack: ```c wake_up_interruptible_poll(&wq->wait, EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND); ``` This is exactly what TCP and other protocols use in their write space callbacks, making SCTP consistent with the rest of the networking subsystem. ### 4. **Comparison with Historical Similar Commits** **Positive Indicators (matching YES backports):** - **Similar Commit #1**: Also SCTP-related, fixes socket behavior issue affecting users - **Similar Commit #4**: TCP polling fix with similar wake-up improvements - **Similar Commit #5**: SCTP wake-up related fix that was backported **Risk Assessment:** - The change is contained to a single function (`__sctp_write_space`) - No architectural changes - Follows existing kernel patterns exactly - Low regression risk - improves efficiency without changing core behavior ### 5. **Impact and Benefits** - **Performance improvement**: Eliminates spurious wake-ups for readers when only write space becomes available - **Correctness**: Ensures only appropriate waiters are woken (those waiting for EPOLLOUT) - **Consistency**: Aligns SCTP behavior with TCP and other protocols ### 6. **Stable Tree Criteria Compliance** ✅ **Important bugfix**: Fixes incorrect polling behavior affecting performance ✅ **Minimal risk**: Single-line change following established patterns ✅ **Small and contained**: Only affects one function in SCTP ✅ **No new features**: Pure bugfix ✅ **No architectural changes**: Maintains existing interfaces ### 7. **Clear Author Intent** The commit message explicitly states this change makes SCTP behave "as TCP does," indicating this is a correctness fix to align with established networking patterns rather than a new feature. This commit exhibits all the characteristics of a good stable backport candidate: it's a small, contained bugfix that improves correctness and performance without introducing new functionality or significant risk. net/sctp/socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 65162d67c3a3c..8a8a5cf8d8e65 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -9089,7 +9089,8 @@ static void __sctp_write_space(struct sctp_association *asoc) wq = rcu_dereference(sk->sk_wq); if (wq) { if (waitqueue_active(&wq->wait)) - wake_up_interruptible(&wq->wait); + wake_up_interruptible_poll(&wq->wait, EPOLLOUT | + EPOLLWRNORM | EPOLLWRBAND); /* Note that we try to include the Async I/O support * here by modeling from the current TCP/UDP code. -- 2.39.5