Changes in 4.9.327 parisc: Fix exception handler for fldw and fstw instructions xfrm: fix refcount leak in __xfrm_policy_check() af_key: Do not call xfrm_probe_algs in parallel rose: check NULL rose_loopback_neigh->loopback bonding: 802.3ad: fix no transmission of LACPDUs netfilter: nft_payload: report ERANGE for too long offset and length ratelimit: Fix data-races in ___ratelimit(). net: Fix a data-race around sysctl_tstamp_allow_data. net: Fix a data-race around sysctl_net_busy_poll. net: Fix a data-race around sysctl_net_busy_read. net: Fix a data-race around sysctl_somaxconn. ixgbe: stop resetting SYSTIME in ixgbe_ptp_start_cyclecounter btrfs: check if root is readonly while setting security xattr loop: Check for overflow while configuring loop asm-generic: sections: refactor memory_intersects mm/hugetlb: fix hugetlb not supporting softdirty tracking mm: Force TLB flush for PFNMAP mappings before unlink_file_vma() s390/mm: do not trigger write fault when vma does not allow VM_WRITE x86/cpu: Add Tiger Lake to Intel family x86/bugs: Add "unknown" reporting for MMIO Stale Data kbuild: Fix include path in scripts/Makefile.modpost Bluetooth: L2CAP: Fix build errors in some archs media: pvrusb2: fix memory leak in pvr_probe HID: hidraw: fix memory leak in hidraw_release() fbdev: fb_pm2fb: Avoid potential divide by zero error ftrace: Fix NULL pointer dereference in is_ftrace_trampoline when ftrace is dead arm64: map FDT as RW for early_init_dt_scan() s390/hypfs: avoid error message under KVM netfilter: conntrack: NF_CONNTRACK_PROCFS should no longer default to y mm/rmap: Fix anon_vma->degree ambiguity leading to double-reuse kprobes: don't call disarm_kprobe() for disabled kprobes Linux 4.9.327 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I6944c82cad25fbe5a35384f4ef0b7fb485203a05
78 lines
1.8 KiB
C
78 lines
1.8 KiB
C
/*
|
|
* ratelimit.c - Do something with rate limit.
|
|
*
|
|
* Isolated from kernel/printk.c by Dave Young <hidave.darkstar@gmail.com>
|
|
*
|
|
* 2008-05-01 rewrite the function and use a ratelimit_state data struct as
|
|
* parameter. Now every user can use their own standalone ratelimit_state.
|
|
*
|
|
* This file is released under the GPLv2.
|
|
*/
|
|
|
|
#include <linux/ratelimit.h>
|
|
#include <linux/jiffies.h>
|
|
#include <linux/export.h>
|
|
|
|
/*
|
|
* __ratelimit - rate limiting
|
|
* @rs: ratelimit_state data
|
|
* @func: name of calling function
|
|
*
|
|
* This enforces a rate limit: not more than @rs->burst callbacks
|
|
* in every @rs->interval
|
|
*
|
|
* RETURNS:
|
|
* 0 means callbacks will be suppressed.
|
|
* 1 means go ahead and do it.
|
|
*/
|
|
int ___ratelimit(struct ratelimit_state *rs, const char *func)
|
|
{
|
|
/* Paired with WRITE_ONCE() in .proc_handler().
|
|
* Changing two values seperately could be inconsistent
|
|
* and some message could be lost. (See: net_ratelimit_state).
|
|
*/
|
|
int interval = READ_ONCE(rs->interval);
|
|
int burst = READ_ONCE(rs->burst);
|
|
unsigned long flags;
|
|
int ret;
|
|
|
|
if (!interval)
|
|
return 1;
|
|
|
|
/*
|
|
* If we contend on this state's lock then almost
|
|
* by definition we are too busy to print a message,
|
|
* in addition to the one that will be printed by
|
|
* the entity that is holding the lock already:
|
|
*/
|
|
if (!raw_spin_trylock_irqsave(&rs->lock, flags))
|
|
return 0;
|
|
|
|
if (!rs->begin)
|
|
rs->begin = jiffies;
|
|
|
|
if (time_is_before_jiffies(rs->begin + interval)) {
|
|
if (rs->missed) {
|
|
if (!(rs->flags & RATELIMIT_MSG_ON_RELEASE)) {
|
|
printk_deferred(KERN_WARNING
|
|
"%s: %d callbacks suppressed\n",
|
|
func, rs->missed);
|
|
rs->missed = 0;
|
|
}
|
|
}
|
|
rs->begin = jiffies;
|
|
rs->printed = 0;
|
|
}
|
|
if (burst && burst > rs->printed) {
|
|
rs->printed++;
|
|
ret = 1;
|
|
} else {
|
|
rs->missed++;
|
|
ret = 0;
|
|
}
|
|
raw_spin_unlock_irqrestore(&rs->lock, flags);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(___ratelimit);
|