Commit 84fe7399 authored by David S. Miller's avatar David S. Miller

Merge branch 'do_once_lite'

Tanner Love says:

====================
net: update netdev_rx_csum_fault() print dump only once

First patch implements DO_ONCE_LITE to abstract uses of the ".data.once"
trick. It is defined in its own, new header file  -- rather than
alongside the existing DO_ONCE in include/linux/once.h -- because
include/linux/once.h includes include/linux/jump_label.h, and this
causes the build to break for some architectures if
include/linux/once.h is included in include/linux/printk.h or
include/asm-generic/bug.h.

Second patch uses DO_ONCE_LITE in netdev_rx_csum_fault to print dump
only once.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents b74ef9f9 127d7355
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#ifndef __XFS_MESSAGE_H #ifndef __XFS_MESSAGE_H
#define __XFS_MESSAGE_H 1 #define __XFS_MESSAGE_H 1
#include <linux/once_lite.h>
struct xfs_mount; struct xfs_mount;
extern __printf(2, 3) extern __printf(2, 3)
...@@ -41,16 +43,7 @@ do { \ ...@@ -41,16 +43,7 @@ do { \
} while (0) } while (0)
#define xfs_printk_once(func, dev, fmt, ...) \ #define xfs_printk_once(func, dev, fmt, ...) \
({ \ DO_ONCE_LITE(func, dev, fmt, ##__VA_ARGS__)
static bool __section(".data.once") __print_once; \
bool __ret_print_once = !__print_once; \
\
if (!__print_once) { \
__print_once = true; \
func(dev, fmt, ##__VA_ARGS__); \
} \
unlikely(__ret_print_once); \
})
#define xfs_emerg_ratelimited(dev, fmt, ...) \ #define xfs_emerg_ratelimited(dev, fmt, ...) \
xfs_printk_ratelimited(xfs_emerg, dev, fmt, ##__VA_ARGS__) xfs_printk_ratelimited(xfs_emerg, dev, fmt, ##__VA_ARGS__)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/instrumentation.h> #include <linux/instrumentation.h>
#include <linux/once_lite.h>
#define CUT_HERE "------------[ cut here ]------------\n" #define CUT_HERE "------------[ cut here ]------------\n"
...@@ -140,39 +141,15 @@ void __warn(const char *file, int line, void *caller, unsigned taint, ...@@ -140,39 +141,15 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
}) })
#ifndef WARN_ON_ONCE #ifndef WARN_ON_ONCE
#define WARN_ON_ONCE(condition) ({ \ #define WARN_ON_ONCE(condition) \
static bool __section(".data.once") __warned; \ DO_ONCE_LITE_IF(condition, WARN_ON, 1)
int __ret_warn_once = !!(condition); \
\
if (unlikely(__ret_warn_once && !__warned)) { \
__warned = true; \
WARN_ON(1); \
} \
unlikely(__ret_warn_once); \
})
#endif #endif
#define WARN_ONCE(condition, format...) ({ \ #define WARN_ONCE(condition, format...) \
static bool __section(".data.once") __warned; \ DO_ONCE_LITE_IF(condition, WARN, 1, format)
int __ret_warn_once = !!(condition); \
\
if (unlikely(__ret_warn_once && !__warned)) { \
__warned = true; \
WARN(1, format); \
} \
unlikely(__ret_warn_once); \
})
#define WARN_TAINT_ONCE(condition, taint, format...) ({ \ #define WARN_TAINT_ONCE(condition, taint, format...) \
static bool __section(".data.once") __warned; \ DO_ONCE_LITE_IF(condition, WARN_TAINT, 1, taint, format)
int __ret_warn_once = !!(condition); \
\
if (unlikely(__ret_warn_once && !__warned)) { \
__warned = true; \
WARN_TAINT(1, taint, format); \
} \
unlikely(__ret_warn_once); \
})
#else /* !CONFIG_BUG */ #else /* !CONFIG_BUG */
#ifndef HAVE_ARCH_BUG #ifndef HAVE_ARCH_BUG
......
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_ONCE_LITE_H
#define _LINUX_ONCE_LITE_H
#include <linux/types.h>
/* Call a function once. Similar to DO_ONCE(), but does not use jump label
* patching via static keys.
*/
#define DO_ONCE_LITE(func, ...) \
DO_ONCE_LITE_IF(true, func, ##__VA_ARGS__)
#define DO_ONCE_LITE_IF(condition, func, ...) \
({ \
static bool __section(".data.once") __already_done; \
bool __ret_do_once = !!(condition); \
\
if (unlikely(__ret_do_once && !__already_done)) { \
__already_done = true; \
func(__VA_ARGS__); \
} \
unlikely(__ret_do_once); \
})
#endif /* _LINUX_ONCE_LITE_H */
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <linux/linkage.h> #include <linux/linkage.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/ratelimit_types.h> #include <linux/ratelimit_types.h>
#include <linux/once_lite.h>
extern const char linux_banner[]; extern const char linux_banner[];
extern const char linux_proc_banner[]; extern const char linux_proc_banner[];
...@@ -436,27 +437,9 @@ extern int kptr_restrict; ...@@ -436,27 +437,9 @@ extern int kptr_restrict;
#ifdef CONFIG_PRINTK #ifdef CONFIG_PRINTK
#define printk_once(fmt, ...) \ #define printk_once(fmt, ...) \
({ \ DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__)
static bool __section(".data.once") __print_once; \
bool __ret_print_once = !__print_once; \
\
if (!__print_once) { \
__print_once = true; \
printk(fmt, ##__VA_ARGS__); \
} \
unlikely(__ret_print_once); \
})
#define printk_deferred_once(fmt, ...) \ #define printk_deferred_once(fmt, ...) \
({ \ DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__)
static bool __section(".data.once") __print_once; \
bool __ret_print_once = !__print_once; \
\
if (!__print_once) { \
__print_once = true; \
printk_deferred(fmt, ##__VA_ARGS__); \
} \
unlikely(__ret_print_once); \
})
#else #else
#define printk_once(fmt, ...) \ #define printk_once(fmt, ...) \
no_printk(fmt, ##__VA_ARGS__) no_printk(fmt, ##__VA_ARGS__)
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/irq_work.h> #include <linux/irq_work.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/once_lite.h>
#ifdef CONFIG_FTRACE_SYSCALLS #ifdef CONFIG_FTRACE_SYSCALLS
#include <asm/unistd.h> /* For NR_SYSCALLS */ #include <asm/unistd.h> /* For NR_SYSCALLS */
...@@ -99,16 +100,8 @@ enum trace_type { ...@@ -99,16 +100,8 @@ enum trace_type {
#include "trace_entries.h" #include "trace_entries.h"
/* Use this for memory failure errors */ /* Use this for memory failure errors */
#define MEM_FAIL(condition, fmt, ...) ({ \ #define MEM_FAIL(condition, fmt, ...) \
static bool __section(".data.once") __warned; \ DO_ONCE_LITE_IF(condition, pr_err, "ERROR: " fmt, ##__VA_ARGS__)
int __ret_warn_once = !!(condition); \
\
if (unlikely(__ret_warn_once && !__warned)) { \
__warned = true; \
pr_err("ERROR: " fmt, ##__VA_ARGS__); \
} \
unlikely(__ret_warn_once); \
})
/* /*
* syscalls are special, and need special handling, this is why * syscalls are special, and need special handling, this is why
......
...@@ -148,6 +148,7 @@ ...@@ -148,6 +148,7 @@
#include <net/devlink.h> #include <net/devlink.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/prandom.h> #include <linux/prandom.h>
#include <linux/once_lite.h>
#include "net-sysfs.h" #include "net-sysfs.h"
...@@ -3487,13 +3488,16 @@ EXPORT_SYMBOL(__skb_gso_segment); ...@@ -3487,13 +3488,16 @@ EXPORT_SYMBOL(__skb_gso_segment);
/* Take action when hardware reception checksum errors are detected. */ /* Take action when hardware reception checksum errors are detected. */
#ifdef CONFIG_BUG #ifdef CONFIG_BUG
static void do_netdev_rx_csum_fault(struct net_device *dev, struct sk_buff *skb)
{
pr_err("%s: hw csum failure\n", dev ? dev->name : "<unknown>");
skb_dump(KERN_ERR, skb, true);
dump_stack();
}
void netdev_rx_csum_fault(struct net_device *dev, struct sk_buff *skb) void netdev_rx_csum_fault(struct net_device *dev, struct sk_buff *skb)
{ {
if (net_ratelimit()) { DO_ONCE_LITE(do_netdev_rx_csum_fault, dev, skb);
pr_err("%s: hw csum failure\n", dev ? dev->name : "<unknown>");
skb_dump(KERN_ERR, skb, true);
dump_stack();
}
} }
EXPORT_SYMBOL(netdev_rx_csum_fault); EXPORT_SYMBOL(netdev_rx_csum_fault);
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment