Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm: fix printk() rate limiting code

Using the same rate limiting state for different kinds of messages
is wrong because this can cause a high frequency message to suppress
a report of a low frequency message. Hence use a unique rate limiting
state per message type.

Fixes: 71a16736a15e ("dm: use local printk ratelimit")
Cc: stable@vger.kernel.org
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>

authored by

Bart Van Assche and committed by
Mike Snitzer
60440789 68515cc7

+12 -39
-10
drivers/md/dm.c
··· 27 27 28 28 #define DM_MSG_PREFIX "core" 29 29 30 - #ifdef CONFIG_PRINTK 31 - /* 32 - * ratelimit state to be used in DMXXX_LIMIT(). 33 - */ 34 - DEFINE_RATELIMIT_STATE(dm_ratelimit_state, 35 - DEFAULT_RATELIMIT_INTERVAL, 36 - DEFAULT_RATELIMIT_BURST); 37 - EXPORT_SYMBOL(dm_ratelimit_state); 38 - #endif 39 - 40 30 /* 41 31 * Cookies are numeric values sent with CHANGE and REMOVE 42 32 * uevents while resuming, removing or renaming the device.
+12 -29
include/linux/device-mapper.h
··· 549 549 *---------------------------------------------------------------*/ 550 550 #define DM_NAME "device-mapper" 551 551 552 - #ifdef CONFIG_PRINTK 553 - extern struct ratelimit_state dm_ratelimit_state; 554 - 555 - #define dm_ratelimit() __ratelimit(&dm_ratelimit_state) 556 - #else 557 - #define dm_ratelimit() 0 558 - #endif 552 + #define DM_RATELIMIT(pr_func, fmt, ...) \ 553 + do { \ 554 + static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL, \ 555 + DEFAULT_RATELIMIT_BURST); \ 556 + \ 557 + if (__ratelimit(&rs)) \ 558 + pr_func(DM_FMT(fmt), ##__VA_ARGS__); \ 559 + } while (0) 559 560 560 561 #define DM_FMT(fmt) DM_NAME ": " DM_MSG_PREFIX ": " fmt "\n" 561 562 562 563 #define DMCRIT(fmt, ...) pr_crit(DM_FMT(fmt), ##__VA_ARGS__) 563 564 564 565 #define DMERR(fmt, ...) pr_err(DM_FMT(fmt), ##__VA_ARGS__) 565 - #define DMERR_LIMIT(fmt, ...) \ 566 - do { \ 567 - if (dm_ratelimit()) \ 568 - DMERR(fmt, ##__VA_ARGS__); \ 569 - } while (0) 570 - 566 + #define DMERR_LIMIT(fmt, ...) DM_RATELIMIT(pr_err, fmt, ##__VA_ARGS__) 571 567 #define DMWARN(fmt, ...) pr_warn(DM_FMT(fmt), ##__VA_ARGS__) 572 - #define DMWARN_LIMIT(fmt, ...) \ 573 - do { \ 574 - if (dm_ratelimit()) \ 575 - DMWARN(fmt, ##__VA_ARGS__); \ 576 - } while (0) 577 - 568 + #define DMWARN_LIMIT(fmt, ...) DM_RATELIMIT(pr_warn, fmt, ##__VA_ARGS__) 578 569 #define DMINFO(fmt, ...) pr_info(DM_FMT(fmt), ##__VA_ARGS__) 579 - #define DMINFO_LIMIT(fmt, ...) \ 580 - do { \ 581 - if (dm_ratelimit()) \ 582 - DMINFO(fmt, ##__VA_ARGS__); \ 583 - } while (0) 570 + #define DMINFO_LIMIT(fmt, ...) DM_RATELIMIT(pr_info, fmt, ##__VA_ARGS__) 584 571 585 572 #ifdef CONFIG_DM_DEBUG 586 573 #define DMDEBUG(fmt, ...) printk(KERN_DEBUG DM_FMT(fmt), ##__VA_ARGS__) 587 - #define DMDEBUG_LIMIT(fmt, ...) \ 588 - do { \ 589 - if (dm_ratelimit()) \ 590 - DMDEBUG(fmt, ##__VA_ARGS__); \ 591 - } while (0) 574 + #define DMDEBUG_LIMIT(fmt, ...) DM_RATELIMIT(pr_debug, fmt, ##__VA_ARGS__) 592 575 #else 593 576 #define DMDEBUG(fmt, ...) no_printk(fmt, ##__VA_ARGS__) 594 577 #define DMDEBUG_LIMIT(fmt, ...) no_printk(fmt, ##__VA_ARGS__)