From: Faicker Mo <faic…@gmail.com>
tcf_police_act() reads the clock before taking tcfp_lock. Meanwhile
another CPU may update tcfp_t_c to a later time, making
now - tcfp_t_c negative.
With a byte rate, toks gets tcfp_toks added and is usually absorbed. A
pps-only policer has no byte rate, so the negative toks fails the
(toks | ptoks | ppstoks) >= 0 check and the packet is dropped even
if the pps bucket is full.
Clamp now to tcfp_t_c after taking the lock.
Fixes: 2ffe0395288a ("net/sched: act_police: add support for packet-per-second policing")
Signed-off-by: Faicker Mo <faic…@gmail.com>
---
net/sched/act_police.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 3f8147f37549..0b3163385a69 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -280,6 +280,7 @@ TC_INDIRECT_SCOPE int tcf_police_act(struct sk_buff *skb,
now = ktime_get_ns();
spin_lock_bh(&police->tcfp_lock);
+ now = max_t(s64, now, police->tcfp_t_c);
toks = min_t(s64, now - police->tcfp_t_c, p->tcfp_burst);
if (p->peak_present) {
ptoks = toks + police->tcfp_ptoks;
--
2.53.0