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 1FE891F4CA0; Wed, 4 Jun 2025 01:01:10 +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=1748998871; cv=none; b=cGqA/YaHNoX7K7fVkna1roWp3ax831agZ1G21CL8oGlo/4yj1DLh/+Lf4B42FU4UBYsembh/CSIDviLO7Oq6NfVfahNDoBbZOB5accP7FTegy+K51Mt0H80iTEipd1WzqBIKdsQcVVPnQYLE74KjJeNjMM9cri+i2vbeBSB3geo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748998871; c=relaxed/simple; bh=8xE5uPIR737I6o6sFWV5AJsGv07/CXrfTK4q/qqtu2E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=qlMf8jDrwn01wVFr7XDtl14bIGCuOd0bW2yt3JVqyYP1/lcy5qWHjX5oM736hT7bBhoyvnf9iXG/8/ACZLbbLqv3ROvcDifxvXfjZmaaej3PZUXUrQW54T6RPDy0qT/ywZo7SVxj+1uLn2mz+38y+Zn7aweyM3N+Gbnc0KyytFM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KJ/3zmjv; 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="KJ/3zmjv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC09FC4CEED; Wed, 4 Jun 2025 01:01:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1748998870; bh=8xE5uPIR737I6o6sFWV5AJsGv07/CXrfTK4q/qqtu2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KJ/3zmjv4TICMt5zh8qxLa2m8f58IveW5zfX4WS1ziaqY26l9ADY6tMKfq+uJIK7y 0Vnpvs8JrjnwucbJkMyDrZIQYx78bkEZ6eSCJp42eiAb/RUodPU11KATQkM0WDWHrt w1XDVbjsXyOlbhMAiSZgwcLXYOWKdqiTFTtEKMe1NzHJbAog7hi/oSolyQPcqLYfYB Of/De6VNjUM21mRbY9oNncfJkyfZBdSSzGYUPIDisrs0oFUBC5HyiAyNWkSIfwqmhr kxUtShaKzcg/Hnu0mm0E9eKkd+sPG5Qt3IJwwPYaN89d4SGWEd1EAZRgu7zqHkYOq7 KiLgJJpHUaB6A== From: Sasha Levin To: patches@lists.linux.dev, stable@vger.kernel.org Cc: Joe Damato , Jakub Kicinski , Sasha Levin Subject: [PATCH AUTOSEL 6.12 62/93] netdevsim: Mark NAPI ID on skb in nsim_rcv Date: Tue, 3 Jun 2025 20:58:48 -0400 Message-Id: <20250604005919.4191884-62-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250604005919.4191884-1-sashal@kernel.org> References: <20250604005919.4191884-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.12.31 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Joe Damato [ Upstream commit f71c549b26a33fd62f1e9c7deeba738bfc73fbfc ] Previously, nsim_rcv was not marking the NAPI ID on the skb, leading to applications seeing a napi ID of 0 when using SO_INCOMING_NAPI_ID. To add to the userland confusion, netlink appears to correctly report the NAPI IDs for netdevsim queues but the resulting file descriptor from a call to accept() was reporting a NAPI ID of 0. Signed-off-by: Joe Damato Link: https://patch.msgid.link/20250424002746.16891-2-jdamato@fastly.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- Perfect! Now I fully understand the issue. The test at line 74-77 shows the exact problem: if `napi_id == 0`, it's considered a failure because SO_INCOMING_NAPI_ID should return a valid NAPI ID, not 0. Based on my comprehensive analysis, here's my assessment: **YES** ## Detailed Analysis This commit should be backported to stable kernel trees because it fixes a **critical functional bug** that affects userspace applications and testing infrastructure. ### **Root Cause Analysis** The commit addresses a missing `skb_mark_napi_id(skb, &rq->napi)` call in the `nsim_rcv()` function of the netdevsim driver. Here's what was happening: 1. **The Bug**: Before this fix, packets processed through `nsim_rcv()` did not have their NAPI ID properly marked on the skb structure 2. **The Impact**: When userspace applications called `getsockopt(SO_INCOMING_NAPI_ID)`, they received 0 instead of the actual NAPI ID 3. **The Flow**: ``` skb gets queued → nsim_rcv() processes it → skb->napi_id = 0 (not set) → netif_receive_skb() → protocol stack → sk_mark_napi_id(sk, skb) → sk->sk_napi_id = 0 → getsockopt(SO_INCOMING_NAPI_ID) returns 0 ``` ### **Why This Qualifies for Stable Backporting** #### **1. Functional Regression/Bug Fix** - **Clear Bug**: Missing `skb_mark_napi_id()` call causes SO_INCOMING_NAPI_ID to return invalid values - **Well-Defined Fix**: Single line addition that follows established patterns in other network drivers - **No Side Effects**: The change only adds the missing NAPI ID marking, with no architectural implications #### **2. Critical Infrastructure Impact** - **Testing Infrastructure**: netdevsim is the primary virtual driver for kernel networking tests - **CI/Testing Failure**: The included selftest `/linux/tools/testing/selftests/drivers/net/napi_id_helper.c` specifically fails when NAPI ID is 0 (lines 74-77) - **Broken SO_INCOMING_NAPI_ID**: This socket option is fundamental for busy polling and advanced networking applications #### **3. User-Visible Impact** - **Applications Broken**: Any userspace application using SO_INCOMING_NAPI_ID with netdevsim gets incorrect results - **Performance Tools**: Network performance testing and benchmarking tools that rely on NAPI ID information fail silently - **Silent Failure**: Applications don't crash but exhibit degraded performance or incorrect behavior #### **4. Meets Stable Criteria** - ✅ **Important bugfix**: Fixes broken SO_INCOMING_NAPI_ID functionality - ✅ **Small and contained**: Single line addition + header include - ✅ **No architectural changes**: Follows existing patterns in the codebase - ✅ **Minimal regression risk**: Only adds missing functionality, doesn't change existing behavior - ✅ **Clear impact**: Affects testing infrastructure and userspace applications #### **5. Code Pattern Consistency** Looking at the similar commit examples and other network drivers in the kernel tree, ALL proper NAPI implementations call `skb_mark_napi_id()` during packet reception. This fix brings netdevsim in line with established networking subsystem patterns. ### **Comparison with Similar Commits** This commit is most similar to **Similar Commit #4** which was marked for backporting because it fixed a functional bug in netdev-genl (missing RCU lock). Both: - Fix missing functionality in networking code - Have clear user-visible impact - Are small, contained changes - Address infrastructure/testing concerns ### **Conclusion** This is a clear **functional bug fix** that restores expected SO_INCOMING_NAPI_ID behavior in netdevsim. The fix is minimal, safe, and addresses a significant regression in testing infrastructure and userspace applications. It should definitely be backported to stable trees. drivers/net/netdevsim/netdev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 1b29d1d794a20..c2207887a70f5 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "netdevsim.h" @@ -341,6 +342,7 @@ static int nsim_rcv(struct nsim_rq *rq, int budget) break; skb = skb_dequeue(&rq->skb_queue); + skb_mark_napi_id(skb, &rq->napi); netif_receive_skb(skb); } -- 2.39.5