Bug 996613

Summary: printk_ratelimited function doesn't work always
Product: [Community] Bugzilla Reporter: caiqiuming <cailvse>
Component: Bugzilla GeneralAssignee: PnT DevOps Devs <hss-ied-bugs>
Status: CLOSED NOTABUG QA Contact: tools-bugs <tools-bugs>
Severity: urgent Docs Contact:
Priority: unspecified    
Version: 4.4CC: jmcdonal, rjoost
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-08-21 04:25:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description caiqiuming 2013-08-13 14:23:31 UTC
Description of problem:
The purpose of "ratelimit for printk" doesn't work always in rhel6.2 or above release.








Version-Release number of selected component (if applicable):
[root@r64-115 linux]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[root@r64-115 linux]# uname -a
Linux r64-115 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

The problem existed in rhel6.2, rhel6.2... also.








How reproducible:
sure occur!





Steps to Reproduce:
1. don't need to change the following parameters, left them as default value.
/proc/sys/kernel/printk_ratelimit
/proc/sys/kernel/printk_ratelimit_burst

2.write an ordinary kernel module, using "printk_ratelimited" function to printk some messages in loop about 1000 or more times.
 
Actual results:
You can see it will print All the times your loop, the purpose of "ratelimit for printk" out of work. In my system it may lead to panic coz print too much in console.

Expected results:
The print items should be limited.



Additional info:
See the code file: linux-2.6.32-358.el6.x86_64/include/linux/kernel.h
in "Red Hat Enterprise Linux Server release 6.4" kernel source:
************************************************
 626 #define printk_ratelimited(fmt, ...)  ({                \
 627         static struct ratelimit_state _rs = {           \
 628                 .interval = DEFAULT_RATELIMIT_INTERVAL, \
 629                 .burst = DEFAULT_RATELIMIT_BURST,       \
 630         };                                              \
 631                                                         \
 632         if (!__ratelimit(&_rs))                         \
 633                 printk(fmt, ##__VA_ARGS__);             \
 634 })
************************************************

In line 632 the condition is negatived, which make the problem wrong.
Because the fact is printk will work when __ratelimit is true.
See the Suse kernel source correspondingly, which work perfect:
--------------------------------------------
#ifdef CONFIG_PRINTK
#define printk_ratelimited(fmt, ...)  ({                \
    static DEFINE_RATELIMIT_STATE(_rs,                \
                      DEFAULT_RATELIMIT_INTERVAL,    \
                      DEFAULT_RATELIMIT_BURST);        \
                                    \
    if (__ratelimit(&_rs))                        \
        printk(fmt, ##__VA_ARGS__);                \
})
-------------------------------------------------

Comment 1 Jason McDonald 2013-08-21 04:25:52 UTC
This is not a bug in the Red Hat Bugzilla product. Please file the bug under the correct product and component.