xen/console: updates to rate-limiting
v5 cover xen/console: updates to rate-limiting
The series introduces compile-configuration for diagnostic messages rate-limiting.
Patch 1 is a fixup for the rate-limiter to adjust to new user-defined rate-limiting parameters.
Patch 2 introduces compile-time rate-limiting controls.
v4: https://lore.kernel.org/xen-devel/[email protected]/
CI: https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/2751536715
Denis Mukhin (2):
xen/console: re-calibrate rate-limiter based on user input xen/console: add build-time rate-limiting controls
xen/common/Kconfig | 30 ++++++++++++++++++++++++++++++ xen/drivers/char/console.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 9 deletions(-)
Signature · 1 line
2.54.0
PATCH v5 1/2 xen/console: re-calibrate rate-limiter based on user input
From: Denis Mukhin <[email protected]>
Current __printk_ratelimit() relies on hardcoded values 5000 and 10 respectively to program leaky-bucket message limiting.
Use 'ratelimit_ms' and 'ratelimit_burst' variables to re-calibrate limiter.
Ensure rate limiter is disabled if either 'ratelimit_ms' or 'ratelimit_burst' is 0.
---
Changes since v4:
- dropped 'initialized' flag
- updated commit message, including Fixes tag
--- xen/drivers/char/console.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
xen/drivers/char/console.c +21 -7
@@ -33,6 +33,7 @@#include <asm/setup.h> #include <xen/sections.h> #include <xen/consoled.h> +#include <xen/xvmalloc.h> #ifdef CONFIG_X86 #include <asm/guest.h>
@@ -1286,21 +1287,34 @@ bool __printk_ratelimit(unsigned int ratelimit_ms, unsigned int ratelimit_burst) {static DEFINE_SPINLOCK (ratelimit_lock); -static unsigned long toks =10 *5 *1000 ; +static unsigned long toks = ~0 ;static unsigned long last_msg;static unsigned int missed; +unsigned long limit; +unsigned long elapsed;unsigned long flags; -unsigned long long now =NOW ();/* ns */ unsigned long ms; +s_time_t now; -do_div (now,1000000 ); - ms = (unsigned long )now; +if ( !ratelimit_ms || !ratelimit_burst ) +return true; + + limit =DIM_MUL2 (ratelimit_burst, ratelimit_ms); + + now =NOW ();/* ns */ +do_div (now,MILLISECS (1 )); + ms = now;spin_lock_irqsave (&ratelimit_lock, flags); - toks += ms - last_msg; + + elapsed = ms - last_msg; +if ( toks >= limit || elapsed >= limit - toks ) + toks = limit; +else + toks += elapsed; + last_msg = ms; -if ( toks > (ratelimit_burst * ratelimit_ms)) - toks = ratelimit_burst * ratelimit_ms; +if ( toks >= ratelimit_ms ) {unsigned int lost = missed;
Signature · 1 line
2.54.0
Re: [PATCH v5 1/2] xen/console: re-calibrate rate-limiter based on user input
Quoted 1 line · On 12.08.2026 01:38, [email protected] wrote:
From: Denis Mukhin <[email protected]>
First: What user input is the subject talking about?
Quoted 2 lines
Current
__printk_ratelimit()relies on hardcoded values 5000 and 10 respectively to program leaky-bucket message limiting.
Which doesn't change, as ...
Quoted 2 lines
Use '
ratelimit_ms' and 'ratelimit_burst' variables to re-calibrate limiter.
... the values of the two static variables never change.
Quoted 4 lines
Ensure rate limiter is disabled if either '
ratelimit_ms' or 'ratelimit_burst' is 0.Fixes 26cf03554a75 ("[XEN] Implement rate-limited logging.")
I don't think anything is being fixed here.
xen/drivers/char/console.c line 36
Quoted 7 lines
xen/drivers/char/console.c +1
-0@@ -33,6 +33,7 @@#include <asm/setup.h> #include <xen/sections.h> #include <xen/consoled.h> +#include <xen/xvmalloc.h>
This shouldn't be needed, as ...
Quoted 11 lines
xen/drivers/char/console.c +3
-1@@ -1286,21 +1287,34 @@ bool __printk_ratelimit(unsigned int ratelimit_ms, unsigned int ratelimit_burst) {static DEFINE_SPINLOCK (ratelimit_lock); -static unsigned long toks =10 *5 *1000 ; +static unsigned long toks = ~0 ;static unsigned long last_msg;static unsigned int missed; +unsigned long limit; +unsigned long elapsed;unsigned long flags;
xen/drivers/char/console.c bool __printk_ratelimit(unsigned int ratelimit_ms, · line 1302
Quoted 10 lines
xen/drivers/char/console.c +5
-3-unsigned long long now =NOW ();/* ns */ unsigned long ms; +s_time_t now; -do_div (now,1000000 ); - ms = (unsigned long )now; +if ( !ratelimit_ms || !ratelimit_burst ) +return true; + + limit =DIM_MUL2 (ratelimit_burst, ratelimit_ms);
... this helper shouldn't be (ab)used here. I further wonder whether we really want differing behavior here for 32- and 64-bit hosts.
Jan
PATCH v5 2/2 xen/console: add build-time rate-limiting controls
In reply to [email protected]From: Denis Mukhin <[email protected]>
Introduce CONFIG_PRINTK_RATELIMIT_MS and CONFIG_PRINTK_RATELIMIT_BURST for configuring rate-limiting policy at the compile time.
Use symbols for global rate-limiting initialization in the console driver.
---
Changes since v4:
- dropped footnotes in Kconfig options
--- xen/common/Kconfig | 30 ++++++++++++++++++++++++++++++ xen/drivers/char/console.c | 6 ++++-- 2 files changed, 34 insertions(+), 2 deletions(-)
xen/common/Kconfig +30 -0
@@ -672,4 +672,34 @@ config PM_STATS Enable collection of performance management statistics to aid in analyzing and tuning power/performance characteristics of the system +menu "Console rate-limiting" + visible if EXPERT + +config PRINTK_RATELIMIT_MS + int "printk rate-limiting time window (milliseconds)" + default 5000 + help + Specifies the time window, in milliseconds, for rate-limited printk + messages. No more than `CONFIG_PRINTK_RATELIMIT_BURST` messages will be + printed within this window. + + Setting this value to 0 disables rate-limiting entirely. + + Configurations using a value other than the default of 5000 are not + security supported. + +config PRINTK_RATELIMIT_BURST + int "printk rate-limited message burst size" + default 10 + help + Defines the maximum number of rate-limited printk messages that may + be printed within each `CONFIG_PRINTK_RATELIMIT_MS` time window. + + Setting this value to 0 disables rate-limiting entirely. + + Configurations using a value other than the default of 10 are not + security supported. + +endmenu + endmenu
xen/drivers/char/console.c +4 -2
@@ -1344,10 +1344,12 @@ bool __printk_ratelimit(unsigned int ratelimit_ms, }/* Minimum time in ms between messages */ -static const unsigned int printk_ratelimit_ms =5 *1000 ; +static const unsigned int printk_ratelimit_ms = +CONFIG_PRINTK_RATELIMIT_MS ;/* Number of messages we send before ratelimiting */ -static const unsigned int printk_ratelimit_burst =10 ; +static const unsigned int printk_ratelimit_burst = +CONFIG_PRINTK_RATELIMIT_BURST ;bool printk_ratelimit (void ) {
Signature · 1 line
2.54.0
Re: [PATCH v5 2/2] xen/console: add build-time rate-limiting controls
Quoted 11 lines · On 12.08.2026 01:38, [email protected] wrote:
xen/common/Kconfig +5
-0@@ -672,4 +672,34 @@ config PM_STATS Enable collection of performance management statistics to aid in analyzing and tuning power/performance characteristics of the system +menu "Console rate-limiting" + visible if EXPERT + +config PRINTK_RATELIMIT_MS + int "printk rate-limiting time window (milliseconds)"
xen/common/Kconfig config PM_STATS · line 689
Quoted 10 lines
xen/common/Kconfig +10
-0+ default 5000 + help + Specifies the time window, in milliseconds, for rate-limited printk + messages. No more than `CONFIG_PRINTK_RATELIMIT_BURST` messages will be + printed within this window. + + Setting this value to 0 disables rate-limiting entirely. + + Configurations using a value other than the default of 5000 are not + security supported.
Do we need to be as strict? Specifying a larger value wouldn't increase the risk of log flooding.
xen/common/Kconfig config PM_STATS · line 701
Quoted 11 lines
xen/common/Kconfig +11
-0+config PRINTK_RATELIMIT_BURST + int "printk rate-limited message burst size" + default 10 + help + Defines the maximum number of rate-limited printk messages that may + be printed within each `CONFIG_PRINTK_RATELIMIT_MS` time window. + + Setting this value to 0 disables rate-limiting entirely. + + Configurations using a value other than the default of 10 are not + security supported.
Same here - lowering the number (to a non-zero value) wouldn't increase the risk of log flooding.
(Question to everyone, not just Denis.)
Jan