blob: 8c3ee291b2d81e28ed2653a2a718983e684dc151 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Andrew Jones851cf6e2013-08-09 19:51:57 +05302#ifndef _LINUX_JUMP_LABEL_RATELIMIT_H
3#define _LINUX_JUMP_LABEL_RATELIMIT_H
4
5#include <linux/jump_label.h>
6#include <linux/workqueue.h>
7
Masahiro Yamadae9666d12018-12-31 00:14:15 +09008#if defined(CONFIG_JUMP_LABEL)
Andrew Jones851cf6e2013-08-09 19:51:57 +05309struct static_key_deferred {
10 struct static_key key;
11 unsigned long timeout;
12 struct delayed_work work;
13};
Andrew Jones851cf6e2013-08-09 19:51:57 +053014
Jakub Kicinskiad282a82019-03-29 17:08:52 -070015struct static_key_true_deferred {
16 struct static_key_true key;
17 unsigned long timeout;
18 struct delayed_work work;
19};
20
21struct static_key_false_deferred {
22 struct static_key_false key;
23 unsigned long timeout;
24 struct delayed_work work;
25};
26
27#define static_key_slow_dec_deferred(x) \
28 __static_key_slow_dec_deferred(&(x)->key, &(x)->work, (x)->timeout)
29#define static_branch_slow_dec_deferred(x) \
30 __static_key_slow_dec_deferred(&(x)->key.key, &(x)->work, (x)->timeout)
31
32#define static_key_deferred_flush(x) \
33 __static_key_deferred_flush((x), &(x)->work)
34
35extern void
36__static_key_slow_dec_deferred(struct static_key *key,
37 struct delayed_work *work,
38 unsigned long timeout);
39extern void __static_key_deferred_flush(void *key, struct delayed_work *work);
Andrew Jones851cf6e2013-08-09 19:51:57 +053040extern void
41jump_label_rate_limit(struct static_key_deferred *key, unsigned long rl);
42
Jakub Kicinskiad282a82019-03-29 17:08:52 -070043extern void jump_label_update_timeout(struct work_struct *work);
44
45#define DEFINE_STATIC_KEY_DEFERRED_TRUE(name, rl) \
46 struct static_key_true_deferred name = { \
47 .key = { STATIC_KEY_INIT_TRUE }, \
48 .timeout = (rl), \
49 .work = __DELAYED_WORK_INITIALIZER((name).work, \
50 jump_label_update_timeout, \
51 0), \
52 }
53
54#define DEFINE_STATIC_KEY_DEFERRED_FALSE(name, rl) \
55 struct static_key_false_deferred name = { \
56 .key = { STATIC_KEY_INIT_FALSE }, \
57 .timeout = (rl), \
58 .work = __DELAYED_WORK_INITIALIZER((name).work, \
59 jump_label_update_timeout, \
60 0), \
61 }
62
Masahiro Yamadae9666d12018-12-31 00:14:15 +090063#else /* !CONFIG_JUMP_LABEL */
Andrew Jones851cf6e2013-08-09 19:51:57 +053064struct static_key_deferred {
65 struct static_key key;
66};
Jakub Kicinskiad282a82019-03-29 17:08:52 -070067struct static_key_true_deferred {
68 struct static_key_true key;
69};
70struct static_key_false_deferred {
71 struct static_key_false key;
72};
73#define DEFINE_STATIC_KEY_DEFERRED_TRUE(name, rl) \
74 struct static_key_true_deferred name = { STATIC_KEY_TRUE_INIT }
75#define DEFINE_STATIC_KEY_DEFERRED_FALSE(name, rl) \
76 struct static_key_false_deferred name = { STATIC_KEY_FALSE_INIT }
77
78#define static_branch_slow_dec_deferred(x) static_branch_dec(&(x)->key)
79
Andrew Jones851cf6e2013-08-09 19:51:57 +053080static inline void static_key_slow_dec_deferred(struct static_key_deferred *key)
81{
Borislav Petkov5cdda512017-10-18 17:24:28 +020082 STATIC_KEY_CHECK_USE(key);
Andrew Jones851cf6e2013-08-09 19:51:57 +053083 static_key_slow_dec(&key->key);
84}
Jakub Kicinskiad282a82019-03-29 17:08:52 -070085static inline void static_key_deferred_flush(void *key)
David Matlackb6416e62016-12-16 14:30:35 -080086{
Borislav Petkov5cdda512017-10-18 17:24:28 +020087 STATIC_KEY_CHECK_USE(key);
David Matlackb6416e62016-12-16 14:30:35 -080088}
Andrew Jones851cf6e2013-08-09 19:51:57 +053089static inline void
90jump_label_rate_limit(struct static_key_deferred *key,
91 unsigned long rl)
92{
Borislav Petkov5cdda512017-10-18 17:24:28 +020093 STATIC_KEY_CHECK_USE(key);
Andrew Jones851cf6e2013-08-09 19:51:57 +053094}
Masahiro Yamadae9666d12018-12-31 00:14:15 +090095#endif /* CONFIG_JUMP_LABEL */
Willem de Bruijnf01c3732019-06-13 11:08:15 -040096
97#define static_branch_deferred_inc(x) static_branch_inc(&(x)->key)
98
Andrew Jones851cf6e2013-08-09 19:51:57 +053099#endif /* _LINUX_JUMP_LABEL_RATELIMIT_H */