Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: faicker.mo@gmail.com
To: faicker.mo@gmail.com
Cc: stable@vger.kernel.org, Jamal Hadi Salim <jhs@mojatatu.com>,
	Jiri Pirko <jiri@resnulli.us>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>,
	Louis Peens <louis.peens@netronome.com>,
	Baowen Zheng <baowen.zheng@corigine.com>,
	netdev@vger.kernel.org
Subject: [PATCH] net/sched: act_police: fix false drops of pps-only policers
Date: Tue,  1 Dec 2026 14:12:23 +0800	[thread overview]
Message-ID: <20261201061300.3321513-1-faicker.mo@gmail.com> (raw)

From: Faicker Mo <faicker.mo@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 <faicker.mo@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


             reply	other threads:[~2026-12-01  6:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  6:12 faicker.mo [this message]
2026-12-01  6:18 ` [PATCH] net/sched: act_police: fix false drops of pps-only policers netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201061300.3321513-1-faicker.mo@gmail.com \
    --to=faicker.mo@gmail.com \
    --cc=baowen.zheng@corigine.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=louis.peens@netronome.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox