* [PATCH net] net/sched: sch_netem: Fix arithmetic in netem_dump() for 32-bit platforms
@ 2022-06-16 23:43 Peilin Ye
2022-06-17 3:08 ` Stephen Hemminger
2022-06-18 3:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Peilin Ye @ 2022-06-16 23:43 UTC (permalink / raw)
To: Stephen Hemminger, Jamal Hadi Salim, Cong Wang, Jiri Pirko
Cc: Peilin Ye, Yuming Chen, Ted Lin, Dave Taht, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
Cong Wang, Peilin Ye
From: Peilin Ye <peilin.ye@bytedance.com>
As reported by Yuming, currently tc always show a latency of UINT_MAX
for netem Qdisc's on 32-bit platforms:
$ tc qdisc add dev dummy0 root netem latency 100ms
$ tc qdisc show dev dummy0
qdisc netem 8001: root refcnt 2 limit 1000 delay 275s 275s
^^^^^^^^^^^^^^^^
Let us take a closer look at netem_dump():
qopt.latency = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->latency,
UINT_MAX);
qopt.latency is __u32, psched_tdiff_t is signed long,
(psched_tdiff_t)(UINT_MAX) is negative for 32-bit platforms, so
qopt.latency is always UINT_MAX.
Fix it by using psched_time_t (u64) instead.
Note: confusingly, users have two ways to specify 'latency':
1. normally, via '__u32 latency' in struct tc_netem_qopt;
2. via the TCA_NETEM_LATENCY64 attribute, which is s64.
For the second case, theoretically 'latency' could be negative. This
patch ignores that corner case, since it is broken (i.e. assigning a
negative s64 to __u32) anyways, and should be handled separately.
Thanks Ted Lin for the analysis [1] .
[1] https://github.com/raspberrypi/linux/issues/3512
Reported-by: Yuming Chen <chenyuming.junnan@bytedance.com>
Fixes: 112f9cb65643 ("netem: convert to qdisc_watchdog_schedule_ns")
Reviewed-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
---
net/sched/sch_netem.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index ed4ccef5d6a8..5449ed114e40 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -1146,9 +1146,9 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
struct tc_netem_rate rate;
struct tc_netem_slot slot;
- qopt.latency = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->latency),
+ qopt.latency = min_t(psched_time_t, PSCHED_NS2TICKS(q->latency),
UINT_MAX);
- qopt.jitter = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->jitter),
+ qopt.jitter = min_t(psched_time_t, PSCHED_NS2TICKS(q->jitter),
UINT_MAX);
qopt.limit = q->limit;
qopt.loss = q->loss;
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] net/sched: sch_netem: Fix arithmetic in netem_dump() for 32-bit platforms
2022-06-16 23:43 [PATCH net] net/sched: sch_netem: Fix arithmetic in netem_dump() for 32-bit platforms Peilin Ye
@ 2022-06-17 3:08 ` Stephen Hemminger
2022-06-18 3:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2022-06-17 3:08 UTC (permalink / raw)
To: Peilin Ye
Cc: Jamal Hadi Salim, Cong Wang, Jiri Pirko, Peilin Ye, Yuming Chen,
Ted Lin, Dave Taht, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, Cong Wang
On Thu, 16 Jun 2022 16:43:36 -0700
Peilin Ye <yepeilin.cs@gmail.com> wrote:
> From: Peilin Ye <peilin.ye@bytedance.com>
>
> As reported by Yuming, currently tc always show a latency of UINT_MAX
> for netem Qdisc's on 32-bit platforms:
>
> $ tc qdisc add dev dummy0 root netem latency 100ms
> $ tc qdisc show dev dummy0
> qdisc netem 8001: root refcnt 2 limit 1000 delay 275s 275s
> ^^^^^^^^^^^^^^^^
>
> Let us take a closer look at netem_dump():
>
> qopt.latency = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->latency,
> UINT_MAX);
>
> qopt.latency is __u32, psched_tdiff_t is signed long,
> (psched_tdiff_t)(UINT_MAX) is negative for 32-bit platforms, so
> qopt.latency is always UINT_MAX.
>
> Fix it by using psched_time_t (u64) instead.
>
> Note: confusingly, users have two ways to specify 'latency':
>
> 1. normally, via '__u32 latency' in struct tc_netem_qopt;
> 2. via the TCA_NETEM_LATENCY64 attribute, which is s64.
>
> For the second case, theoretically 'latency' could be negative. This
> patch ignores that corner case, since it is broken (i.e. assigning a
> negative s64 to __u32) anyways, and should be handled separately.
>
> Thanks Ted Lin for the analysis [1] .
>
> [1] https://github.com/raspberrypi/linux/issues/3512
>
> Reported-by: Yuming Chen <chenyuming.junnan@bytedance.com>
> Fixes: 112f9cb65643 ("netem: convert to qdisc_watchdog_schedule_ns")
> Reviewed-by: Cong Wang <cong.wang@bytedance.com>
> Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
> ---
> net/sched/sch_netem.c | 4 ++--
Thanks for fixing.
Guess it is time to run netem on one of the Pi's.
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] net/sched: sch_netem: Fix arithmetic in netem_dump() for 32-bit platforms
2022-06-16 23:43 [PATCH net] net/sched: sch_netem: Fix arithmetic in netem_dump() for 32-bit platforms Peilin Ye
2022-06-17 3:08 ` Stephen Hemminger
@ 2022-06-18 3:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-06-18 3:40 UTC (permalink / raw)
To: Peilin Ye
Cc: stephen, jhs, xiyou.wangcong, jiri, peilin.ye, chenyuming.junnan,
ted, dave.taht, davem, edumazet, kuba, pabeni, netdev,
linux-kernel, cong.wang
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 16 Jun 2022 16:43:36 -0700 you wrote:
> From: Peilin Ye <peilin.ye@bytedance.com>
>
> As reported by Yuming, currently tc always show a latency of UINT_MAX
> for netem Qdisc's on 32-bit platforms:
>
> $ tc qdisc add dev dummy0 root netem latency 100ms
> $ tc qdisc show dev dummy0
> qdisc netem 8001: root refcnt 2 limit 1000 delay 275s 275s
> ^^^^^^^^^^^^^^^^
>
> [...]
Here is the summary with links:
- [net] net/sched: sch_netem: Fix arithmetic in netem_dump() for 32-bit platforms
https://git.kernel.org/netdev/net/c/a2b1a5d40bd1
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] 3+ messages in thread
end of thread, other threads:[~2022-06-18 3:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16 23:43 [PATCH net] net/sched: sch_netem: Fix arithmetic in netem_dump() for 32-bit platforms Peilin Ye
2022-06-17 3:08 ` Stephen Hemminger
2022-06-18 3: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).