netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 1/2] net/sched: ets: Remove drr class from the active list if it changes to strict
@ 2025-12-08 19:01 Victor Nogueira
  2025-12-08 19:01 ` [PATCH net 2/2] selftests/tc-testing: Create tests to exercise ets classes active list misplacements Victor Nogueira
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Victor Nogueira @ 2025-12-08 19:01 UTC (permalink / raw)
  To: davem, kuba, pabeni, edumazet, jhs, jiri, xiyou.wangcong
  Cc: horms, dcaratti, petrm, netdev

Whenever a user issues an ets qdisc change command, transforming a
drr class into a strict one, the ets code isn't checking whether that
class was in the active list and removing it. This means that, if a
user changes a strict class (which was in the active list) back to a drr
one, that class will be added twice to the active list [1].

Doing so with the following commands:

tc qdisc add dev lo root handle 1: ets bands 2 strict 1
tc qdisc add dev lo parent 1:2 handle 20: \
    tbf rate 8bit burst 100b latency 1s
tc filter add dev lo parent 1: basic classid 1:2
ping -c1 -W0.01 -s 56 127.0.0.1
tc qdisc change dev lo root handle 1: ets bands 2 strict 2
tc qdisc change dev lo root handle 1: ets bands 2 strict 1
ping -c1 -W0.01 -s 56 127.0.0.1

Will trigger the following splat with list debug turned on:

[   59.279014][  T365] ------------[ cut here ]------------
[   59.279452][  T365] list_add double add: new=ffff88801d60e350, prev=ffff88801d60e350, next=ffff88801d60e2c0.
[   59.280153][  T365] WARNING: CPU: 3 PID: 365 at lib/list_debug.c:35 __list_add_valid_or_report+0x17f/0x220
[   59.280860][  T365] Modules linked in:
[   59.281165][  T365] CPU: 3 UID: 0 PID: 365 Comm: tc Not tainted 6.18.0-rc7-00105-g7e9f13163c13-dirty #239 PREEMPT(voluntary)
[   59.281977][  T365] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
[   59.282391][  T365] RIP: 0010:__list_add_valid_or_report+0x17f/0x220
[   59.282842][  T365] Code: 89 c6 e8 d4 b7 0d ff 90 0f 0b 90 90 31 c0 e9 31 ff ff ff 90 48 c7 c7 e0 a0 22 9f 48 89 f2 48 89 c1 4c 89 c6 e8 b2 b7 0d ff 90 <0f> 0b 90 90 31 c0 e9 0f ff ff ff 48 89 f7 48 89 44 24 10 4c 89 44
...
[   59.288812][  T365] Call Trace:
[   59.289056][  T365]  <TASK>
[   59.289224][  T365]  ? srso_alias_return_thunk+0x5/0xfbef5
[   59.289546][  T365]  ets_qdisc_change+0xd2b/0x1e80
[   59.289891][  T365]  ? __lock_acquire+0x7e7/0x1be0
[   59.290223][  T365]  ? __pfx_ets_qdisc_change+0x10/0x10
[   59.290546][  T365]  ? srso_alias_return_thunk+0x5/0xfbef5
[   59.290898][  T365]  ? __mutex_trylock_common+0xda/0x240
[   59.291228][  T365]  ? __pfx___mutex_trylock_common+0x10/0x10
[   59.291655][  T365]  ? srso_alias_return_thunk+0x5/0xfbef5
[   59.291993][  T365]  ? srso_alias_return_thunk+0x5/0xfbef5
[   59.292313][  T365]  ? trace_contention_end+0xc8/0x110
[   59.292656][  T365]  ? srso_alias_return_thunk+0x5/0xfbef5
[   59.293022][  T365]  ? srso_alias_return_thunk+0x5/0xfbef5
[   59.293351][  T365]  tc_modify_qdisc+0x63a/0x1cf0

Fix this by always checking and removing an ets class from the active list
when changing it to strict.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/tree/net/sched/sch_ets.c?id=ce052b9402e461a9aded599f5b47e76bc727f7de#n663

Fixes: cd9b50adc6bb9 ("net/sched: ets: fix crash when flipping from 'strict' to 'quantum'")
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
---
 net/sched/sch_ets.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/sched/sch_ets.c b/net/sched/sch_ets.c
index ae46643e596d..306e046276d4 100644
--- a/net/sched/sch_ets.c
+++ b/net/sched/sch_ets.c
@@ -664,6 +664,10 @@ static int ets_qdisc_change(struct Qdisc *sch, struct nlattr *opt,
 			q->classes[i].deficit = quanta[i];
 		}
 	}
+	for (i = q->nstrict; i < nstrict; i++) {
+		if (cl_is_active(&q->classes[i]))
+			list_del_init(&q->classes[i].alist);
+	}
 	WRITE_ONCE(q->nstrict, nstrict);
 	memcpy(q->prio2band, priomap, sizeof(priomap));
 
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 2/2] selftests/tc-testing: Create tests to exercise ets classes active list misplacements
  2025-12-08 19:01 [PATCH net 1/2] net/sched: ets: Remove drr class from the active list if it changes to strict Victor Nogueira
@ 2025-12-08 19:01 ` Victor Nogueira
  2025-12-09 14:00   ` Petr Machata
  2025-12-09 13:42 ` [PATCH net 1/2] net/sched: ets: Remove drr class from the active list if it changes to strict Petr Machata
  2025-12-11  9:40 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: Victor Nogueira @ 2025-12-08 19:01 UTC (permalink / raw)
  To: davem, kuba, pabeni, edumazet, jhs, jiri, xiyou.wangcong
  Cc: horms, dcaratti, petrm, netdev

Add a test case for a bug fixed by Jamal [1] and for scenario where an
ets drr class is inserted into the active list twice.

- Try to delete ets drr class' qdisc while still keeping it in the
  active list
- Try to add ets class to the active list twice

[1] https://lore.kernel.org/netdev/20251128151919.576920-1-jhs@mojatatu.com/

Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
---
 .../tc-testing/tc-tests/infra/qdiscs.json     | 78 +++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/tools/testing/selftests/tc-testing/tc-tests/infra/qdiscs.json b/tools/testing/selftests/tc-testing/tc-tests/infra/qdiscs.json
index 47de27fd4f90..6a39640aa2a8 100644
--- a/tools/testing/selftests/tc-testing/tc-tests/infra/qdiscs.json
+++ b/tools/testing/selftests/tc-testing/tc-tests/infra/qdiscs.json
@@ -1033,5 +1033,83 @@
         "teardown": [
             "$TC qdisc del dev $DUMMY handle 1: root"
         ]
+    },
+    {
+        "id": "6e4f",
+        "name": "Try to delete ets drr class' qdisc while still keeping it in the active list",
+        "category": [
+            "qdisc",
+            "ets",
+            "tbf"
+        ],
+        "plugins": {
+            "requires": [
+                "nsPlugin",
+                "scapyPlugin"
+            ]
+        },
+        "setup": [
+            "$IP link set dev $DUMMY up || true",
+            "$IP addr add 10.10.11.10/24 dev $DUMMY || true",
+            "$TC qdisc add dev $DUMMY root handle 1: ets bands 2 strict 1",
+            "$TC qdisc add dev $DUMMY parent 1:2 handle 20: tbf rate 8bit burst 100b latency 1s",
+            "$TC filter add dev $DUMMY parent 1: basic classid 1:2",
+            "ping -c2 -W0.01 -s 56 -I $DUMMY 10.10.11.11 || true",
+            "$TC qdisc change dev $DUMMY root handle 1: ets bands 2 strict 2",
+            "$TC qdisc change dev $DUMMY root handle 1: ets bands 1 strict 1"
+        ],
+        "cmdUnderTest": "ping -c1 -W0.01 -s 56 -I $DUMMY 10.10.11.11",
+        "expExitCode": "1",
+        "verifyCmd": "$TC -s -j qdisc ls dev $DUMMY root",
+        "matchJSON": [
+            {
+                "kind": "ets",
+                "handle": "1:",
+                "bytes": 196,
+                "packets": 2
+            }
+        ],
+        "teardown": [
+            "$TC qdisc del dev $DUMMY root handle 1:"
+        ]
+    },
+    {
+        "id": "0b8f",
+        "name": "Try to add ets class to the active list twice",
+        "category": [
+            "qdisc",
+            "ets",
+            "tbf"
+        ],
+        "plugins": {
+            "requires": [
+                "nsPlugin",
+                "scapyPlugin"
+            ]
+        },
+        "setup": [
+            "$IP link set dev $DUMMY up || true",
+            "$IP addr add 10.10.11.10/24 dev $DUMMY || true",
+            "$TC qdisc add dev $DUMMY root handle 1: ets bands 2 strict 1",
+            "$TC qdisc add dev $DUMMY parent 1:2 handle 20: tbf rate 8bit burst 100b latency 1s",
+            "$TC filter add dev $DUMMY parent 1: basic classid 1:2",
+            "ping -c2 -W0.01 -s 56 -I $DUMMY 10.10.11.11 || true",
+            "$TC qdisc change dev $DUMMY root handle 1: ets bands 2 strict 2",
+            "$TC qdisc change dev $DUMMY root handle 1: ets bands 2 strict 1"
+        ],
+        "cmdUnderTest": "ping -c1 -W0.01 -s 56 -I $DUMMY 10.10.11.11",
+        "expExitCode": "1",
+        "verifyCmd": "$TC -s -j qdisc ls dev $DUMMY root",
+        "matchJSON": [
+            {
+                "kind": "ets",
+                "handle": "1:",
+                "bytes": 98,
+                "packets": 1
+            }
+        ],
+        "teardown": [
+            "$TC qdisc del dev $DUMMY root handle 1:"
+        ]
     }
 ]
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net 1/2] net/sched: ets: Remove drr class from the active list if it changes to strict
  2025-12-08 19:01 [PATCH net 1/2] net/sched: ets: Remove drr class from the active list if it changes to strict Victor Nogueira
  2025-12-08 19:01 ` [PATCH net 2/2] selftests/tc-testing: Create tests to exercise ets classes active list misplacements Victor Nogueira
@ 2025-12-09 13:42 ` Petr Machata
  2025-12-11  9:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Petr Machata @ 2025-12-09 13:42 UTC (permalink / raw)
  To: Victor Nogueira
  Cc: davem, kuba, pabeni, edumazet, jhs, jiri, xiyou.wangcong, horms,
	dcaratti, petrm, netdev


Victor Nogueira <victor@mojatatu.com> writes:

> Whenever a user issues an ets qdisc change command, transforming a
> drr class into a strict one, the ets code isn't checking whether that
> class was in the active list and removing it. This means that, if a
> user changes a strict class (which was in the active list) back to a drr
> one, that class will be added twice to the active list [1].
>
> Doing so with the following commands:
>
> tc qdisc add dev lo root handle 1: ets bands 2 strict 1
> tc qdisc add dev lo parent 1:2 handle 20: \
>     tbf rate 8bit burst 100b latency 1s
> tc filter add dev lo parent 1: basic classid 1:2
> ping -c1 -W0.01 -s 56 127.0.0.1
> tc qdisc change dev lo root handle 1: ets bands 2 strict 2
> tc qdisc change dev lo root handle 1: ets bands 2 strict 1
> ping -c1 -W0.01 -s 56 127.0.0.1
>
> Will trigger the following splat with list debug turned on:
>
> [   59.279014][  T365] ------------[ cut here ]------------
> [   59.279452][  T365] list_add double add: new=ffff88801d60e350, prev=ffff88801d60e350, next=ffff88801d60e2c0.
> [   59.280153][  T365] WARNING: CPU: 3 PID: 365 at lib/list_debug.c:35 __list_add_valid_or_report+0x17f/0x220
> [   59.280860][  T365] Modules linked in:
> [   59.281165][  T365] CPU: 3 UID: 0 PID: 365 Comm: tc Not tainted 6.18.0-rc7-00105-g7e9f13163c13-dirty #239 PREEMPT(voluntary)
> [   59.281977][  T365] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
> [   59.282391][  T365] RIP: 0010:__list_add_valid_or_report+0x17f/0x220
> [   59.282842][  T365] Code: 89 c6 e8 d4 b7 0d ff 90 0f 0b 90 90 31 c0 e9 31 ff ff ff 90 48 c7 c7 e0 a0 22 9f 48 89 f2 48 89 c1 4c 89 c6 e8 b2 b7 0d ff 90 <0f> 0b 90 90 31 c0 e9 0f ff ff ff 48 89 f7 48 89 44 24 10 4c 89 44
> ...
> [   59.288812][  T365] Call Trace:
> [   59.289056][  T365]  <TASK>
> [   59.289224][  T365]  ? srso_alias_return_thunk+0x5/0xfbef5
> [   59.289546][  T365]  ets_qdisc_change+0xd2b/0x1e80
> [   59.289891][  T365]  ? __lock_acquire+0x7e7/0x1be0
> [   59.290223][  T365]  ? __pfx_ets_qdisc_change+0x10/0x10
> [   59.290546][  T365]  ? srso_alias_return_thunk+0x5/0xfbef5
> [   59.290898][  T365]  ? __mutex_trylock_common+0xda/0x240
> [   59.291228][  T365]  ? __pfx___mutex_trylock_common+0x10/0x10
> [   59.291655][  T365]  ? srso_alias_return_thunk+0x5/0xfbef5
> [   59.291993][  T365]  ? srso_alias_return_thunk+0x5/0xfbef5
> [   59.292313][  T365]  ? trace_contention_end+0xc8/0x110
> [   59.292656][  T365]  ? srso_alias_return_thunk+0x5/0xfbef5
> [   59.293022][  T365]  ? srso_alias_return_thunk+0x5/0xfbef5
> [   59.293351][  T365]  tc_modify_qdisc+0x63a/0x1cf0
>
> Fix this by always checking and removing an ets class from the active list
> when changing it to strict.
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/tree/net/sched/sch_ets.c?id=ce052b9402e461a9aded599f5b47e76bc727f7de#n663
>
> Fixes: cd9b50adc6bb9 ("net/sched: ets: fix crash when flipping from 'strict' to 'quantum'")
> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
> Signed-off-by: Victor Nogueira <victor@mojatatu.com>

Reviewed-by: Petr Machata <petrm@nvidia.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net 2/2] selftests/tc-testing: Create tests to exercise ets classes active list misplacements
  2025-12-08 19:01 ` [PATCH net 2/2] selftests/tc-testing: Create tests to exercise ets classes active list misplacements Victor Nogueira
@ 2025-12-09 14:00   ` Petr Machata
  0 siblings, 0 replies; 5+ messages in thread
From: Petr Machata @ 2025-12-09 14:00 UTC (permalink / raw)
  To: Victor Nogueira
  Cc: davem, kuba, pabeni, edumazet, jhs, jiri, xiyou.wangcong, horms,
	dcaratti, petrm, netdev


Victor Nogueira <victor@mojatatu.com> writes:

> Add a test case for a bug fixed by Jamal [1] and for scenario where an
> ets drr class is inserted into the active list twice.
>
> - Try to delete ets drr class' qdisc while still keeping it in the
>   active list
> - Try to add ets class to the active list twice
>
> [1] https://lore.kernel.org/netdev/20251128151919.576920-1-jhs@mojatatu.com/
>
> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
> Signed-off-by: Victor Nogueira <victor@mojatatu.com>

Reviewed-by: Petr Machata <petrm@nvidia.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net 1/2] net/sched: ets: Remove drr class from the active list if it changes to strict
  2025-12-08 19:01 [PATCH net 1/2] net/sched: ets: Remove drr class from the active list if it changes to strict Victor Nogueira
  2025-12-08 19:01 ` [PATCH net 2/2] selftests/tc-testing: Create tests to exercise ets classes active list misplacements Victor Nogueira
  2025-12-09 13:42 ` [PATCH net 1/2] net/sched: ets: Remove drr class from the active list if it changes to strict Petr Machata
@ 2025-12-11  9:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-12-11  9:40 UTC (permalink / raw)
  To: Victor Nogueira
  Cc: davem, kuba, pabeni, edumazet, jhs, jiri, xiyou.wangcong, horms,
	dcaratti, petrm, netdev

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  8 Dec 2025 16:01:24 -0300 you wrote:
> Whenever a user issues an ets qdisc change command, transforming a
> drr class into a strict one, the ets code isn't checking whether that
> class was in the active list and removing it. This means that, if a
> user changes a strict class (which was in the active list) back to a drr
> one, that class will be added twice to the active list [1].
> 
> Doing so with the following commands:
> 
> [...]

Here is the summary with links:
  - [net,1/2] net/sched: ets: Remove drr class from the active list if it changes to strict
    https://git.kernel.org/netdev/net/c/b1e125ae425a
  - [net,2/2] selftests/tc-testing: Create tests to exercise ets classes active list misplacements
    https://git.kernel.org/netdev/net/c/5914428e0e44

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-12-11  9:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-08 19:01 [PATCH net 1/2] net/sched: ets: Remove drr class from the active list if it changes to strict Victor Nogueira
2025-12-08 19:01 ` [PATCH net 2/2] selftests/tc-testing: Create tests to exercise ets classes active list misplacements Victor Nogueira
2025-12-09 14:00   ` Petr Machata
2025-12-09 13:42 ` [PATCH net 1/2] net/sched: ets: Remove drr class from the active list if it changes to strict Petr Machata
2025-12-11  9:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).