Skip to content

Commit aa2cc35

Browse files
committed
ratelimit: Force re-initialization when rate-limiting re-enabled
Currently, if rate limiting is disabled, ___ratelimit() does an immediate early return with no state changes. This can result in false-positive drops when re-enabling rate limiting. Therefore, mark the ratelimit_state structure "uninitialized" when rate limiting is disabled. [ paulmck: Apply Petr Mladek feedback. ] Link: https://lore.kernel.org/all/fbe93a52-365e-47fe-93a4-44a44547d601@paulmck-laptop/ Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Paul E. McKenney <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Kuniyuki Iwashima <[email protected]> Cc: Mateusz Guzik <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: John Ogness <[email protected]> Cc: Sergey Senozhatsky <[email protected]>
1 parent 084a990 commit aa2cc35

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/ratelimit.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,24 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
3535
unsigned long flags;
3636
int ret;
3737

38+
/*
39+
* Zero interval says never limit, otherwise, non-positive burst
40+
* says always limit.
41+
*/
3842
if (interval <= 0 || burst <= 0) {
3943
ret = interval == 0 || burst > 0;
44+
if (!(READ_ONCE(rs->flags) & RATELIMIT_INITIALIZED) || (!interval && !burst) ||
45+
!raw_spin_trylock_irqsave(&rs->lock, flags)) {
46+
if (!ret)
47+
ratelimit_state_inc_miss(rs);
48+
return ret;
49+
}
50+
51+
/* Force re-initialization once re-enabled. */
52+
rs->flags &= ~RATELIMIT_INITIALIZED;
4053
if (!ret)
4154
ratelimit_state_inc_miss(rs);
42-
return ret;
55+
goto unlock_ret;
4356
}
4457

4558
/*

0 commit comments

Comments
 (0)