From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9025239E19A for ; Thu, 26 Mar 2026 18:17:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774549039; cv=none; b=YBdMw/41M4qSQ7avajZhKHfEi70Gi0naPMp7r0pLh3cynxkquhXNOqVKLN5++ilW1qnH7APrWjUiW4XuKY3oRKRIZCDaBzXEMvi/rbKKRy/zH9ZdUTlaTBjTk2gQdbvou2F6Beos+dxUNL/hJuWjLgveAcL5RREYv38sntMOvQ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774549039; c=relaxed/simple; bh=/s7mUG5Fv9kdG+vGSLKGdiphjJXIw7IkX1WF0aGUmUY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LT0x0ye6UckYgw+K7ULNeOMMfy4fzPn0IkHJw0TCT6rm+swBJ+8UrhyBdcerE+5Zwz1RCw/rfEFtDYnCA8rrej7yADxp52ttZ/9iHjEyM/ZbZAhgUgxvUio3zNIFT2Q+d9IIVw+x4DHm8tpt56LbssMlOJnxQDXb1za+D5xabo4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org; spf=pass smtp.mailfrom=networkplumber.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20230601.gappssmtp.com header.i=@networkplumber-org.20230601.gappssmtp.com header.b=hxeD51F+; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=networkplumber.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20230601.gappssmtp.com header.i=@networkplumber-org.20230601.gappssmtp.com header.b="hxeD51F+" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2adff872068so5487905ad.1 for ; Thu, 26 Mar 2026 11:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1774549035; x=1775153835; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AE8phg7go9B6C5XM74Kv5AapiNe7XDiY/VQZh3AQgvY=; b=hxeD51F+wfrdXVVfiTTIW38uGUn4VWizY3MoXuiZcIY8U/7HbXukA030/DUNI5aY/c Mli9SrbBOpIBDdrR4qTQeDu8yVaxlf7c5NBXEpbHHTFVPGTXDxFVOpPr6D/ayODhEEYo BWV/HozGdfdXfavqjfBD5my+xI3td4zEe+8Cn4/3Ixc93g5si4Nv+NwvQVXk51qb0jYs 8c+sRxBYTtv2rdaaKdz7CBsZhIlTGOH0J8PsO3noE+vc0XLBUK/oGKbUH8sJus9HeX4T zW8ux4chS4VOphADnpdbtaLhgTAdXbWEm52wv8/7ElGH6glHAqeo0BAZMgNyeLPcaCk7 zr9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774549035; x=1775153835; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=AE8phg7go9B6C5XM74Kv5AapiNe7XDiY/VQZh3AQgvY=; b=sss5uCxVGqDRXtU2eG1MgkGPggqIV4mzcKBrTF1dkJSJfI30nM8musaHiyt2HW1SdE p8yOptYmH5O6jfcaYQGu/e3MmKMnDmIAK1z67TEkRKCovW2kaf0qU6drkdE8agL9u1Cb EFNPPg3SC+saLVtF9WmB1CU+P2cK5uO6cWyXjvbLnvspQxPcg8/W+R8FeyFA8vxtJcXU F0dO5ZK1P0Y62fHzT4LEUXvrFORi+TJBZhz2wcE7h3SjuzfYHhGuXVO/m00m7o6242u7 HQeyN4G+lDDFnz5G9/+X6NIWB8rkVQgNwti7KC3WUHvuKT97v3u2kIwbZxWqxyy/ZFov 8zgA== X-Forwarded-Encrypted: i=1; AJvYcCXvw+CkND3qJFK0GRasxrTh3PoXkeaReDpBeMOc/vOtutCky4EBz2DWhTfoZntSPFxsufJXwyt9xVk+ZqA=@vger.kernel.org X-Gm-Message-State: AOJu0YyHBhyObi+suzoyrqjV7seQPykMkiHXUVvH29IQsSle79VSbswR 5Riu9i6NpCJHOsw2ZVhMIFIPpcjpI/zObPt2SdbuS2ARbCtjmpZbxFvhuUYp5QqokVQ= X-Gm-Gg: ATEYQzwPcONbAMlsn+gI7vOnqaiImSQI804UWdnPIHcdBcIX8M41dag5uI6T/UxWzmw XmAUN8nK1SmJ/UW7hGshGnQ9iLaV48Rcee1vsge5+rLpeO/EBXNX/aDYGuP25Py5EjkcN5W3DB+ LNJvk0H0sWaLPka0WJ5s5QsHPZkPfC7a2LZjDldwSyA6NjHMt1MPHVkmZYSYEL0C0rry/bQEzEb PR+aCuZzWQeJFj9sHxIUjlDP0DoafbjKy4Fl4tfvuGiXQQ13nM8enskkbMYXa9oaplBSNY7gulx /EB9cySc+Al+jcwilwb7WKYi2edOdjRO6QzshvpM/XJBoNvT1iXFoixBXVWHj+xSWGTlaJ8fXWR aD0XlL/5NeKypycQZN4zty21Wq7jUfGV38h440Ln5Jdx7OQ8ve1Nc+dl5NhvwkJwh+SWQf9aGmf fvx9Pnes0HrMI+H+j5tDYoWuWAFMJBaUZc X-Received: by 2002:a17:903:2bce:b0:2ae:63a4:3baf with SMTP id d9443c01a7336-2b0b0b0f401mr99782905ad.46.1774549035400; Thu, 26 Mar 2026 11:17:15 -0700 (PDT) Received: from phoenix.lan ([104.202.29.139]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b0bc8c4bd3sm38590245ad.63.2026.03.26.11.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 11:17:14 -0700 (PDT) From: Stephen Hemminger To: netdev@vger.kernel.org Cc: Jamal Hadi Salim , Stephen Hemminger , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 1/7] net: Introduce skb tc depth field to track packet loops Date: Thu, 26 Mar 2026 11:01:00 -0700 Message-ID: <20260326181701.308275-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260326181701.308275-1-stephen@networkplumber.org> References: <20260326181701.308275-1-stephen@networkplumber.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jamal Hadi Salim Add a 2-bit per-skb tc depth field to track packet loops across the stack. The previous per-CPU loop counters like MIRRED_NEST_LIMIT assume a single call stack and lose state in two cases: 1) When a packet is queued and reprocessed later (e.g., egress->ingress via backlog), the per-cpu state is gone by the time it is dequeued. 2) With XPS/RPS a packet may arrive on one CPU and be processed on another. A per-skb field solves both by travelling with the packet itself. The field fits in existing padding, using 2 bits that were previously a hole: pahole before(-) and after (+) diff looks like: __u8 slow_gro:1; /* 132: 3 1 */ __u8 csum_not_inet:1; /* 132: 4 1 */ __u8 unreadable:1; /* 132: 5 1 */ + __u8 tc_depth:2; /* 132: 6 1 */ - /* XXX 2 bits hole, try to pack */ /* XXX 1 byte hole, try to pack */ __u16 tc_index; /* 134 2 */ There used to be a ttl field which was removed as part of tc_verd in commit aec745e2c520 ("net-tc: remove unused tc_verd fields"). It was already unused by that time, due to remove earlier in commit c19ae86a510c ("tc: remove unused redirect ttl"). The first user of this field is netem, which increments tc_depth on duplicated packets before re-enqueueing them at the root qdisc. On re-entry, netem skips duplication for any skb with tc_depth already set, bounding recursion to a single level regardless of tree topology. The other user is mirred which increments it on each pass and limits to depth to MIRRED_DEFER_LIMIT (3). The new field was called ttl in earlier versions of this patch but renamed to tc_depth to avoid confusion with IP ttl. Signed-off-by: Jamal Hadi Salim Reviewed-by: Stephen Hemminger --- include/linux/skbuff.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index daa4e4944ce3..aba4c88a1b3f 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -821,6 +821,7 @@ enum skb_tstamp_type { * @_sk_redir: socket redirection information for skmsg * @_nfct: Associated connection, if any (with nfctinfo bits) * @skb_iif: ifindex of device we arrived on + * @tc_depth: counter for packet duplication * @tc_index: Traffic control index * @hash: the packet hash * @queue_mapping: Queue mapping for multiqueue devices @@ -1030,6 +1031,7 @@ struct sk_buff { __u8 csum_not_inet:1; #endif __u8 unreadable:1; + __u8 tc_depth:2; #if defined(CONFIG_NET_SCHED) || defined(CONFIG_NET_XGRESS) __u16 tc_index; /* traffic control index */ #endif -- 2.53.0