@@ -112,8 +112,8 @@ static inline int __apic_test_and_clear_vector(int vec, void *bitmap)
return __test_and_clear_bit(VEC_POS(vec), (bitmap) + REG_POS(vec));
}
-struct static_key_deferred apic_hw_disabled __read_mostly;
-struct static_key_deferred apic_sw_disabled __read_mostly;
+static_key_deferred(apic_hw_disabled);
+static_key_deferred(apic_sw_disabled);
static inline void apic_set_spiv(struct kvm_lapic *apic, u32 val)
{
@@ -108,7 +108,7 @@ static inline bool kvm_vcpu_has_lapic(struct kvm_vcpu *vcpu)
return true;
}
-extern struct static_key_deferred apic_hw_disabled;
+extern static_key_deferred(apic_hw_disabled);
static inline int kvm_apic_hw_enabled(struct kvm_lapic *apic)
{
@@ -117,7 +117,7 @@ static inline int kvm_apic_hw_enabled(struct kvm_lapic *apic)
return MSR_IA32_APICBASE_ENABLE;
}
-extern struct static_key_deferred apic_sw_disabled;
+extern static_key_deferred(apic_sw_disabled);
static inline int kvm_apic_sw_enabled(struct kvm_lapic *apic)
{
@@ -214,6 +214,7 @@
#define READ_MOSTLY_DATA(align) \
. = ALIGN(align); \
*(.data..read_mostly) \
+ *(__deferred_keys) \
. = ALIGN(align);
#define CACHELINE_ALIGNED_DATA(align) \
@@ -3,6 +3,10 @@
#include <linux/jump_label.h>
#include <linux/workqueue.h>
+#include <linux/compiler.h>
+
+#define static_key_deferred(name) \
+ struct static_key_deferred name __section(__deferred_keys)
#if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL)
struct static_key_deferred {
@@ -347,6 +347,9 @@ struct module
#ifdef HAVE_JUMP_LABEL
struct jump_entry *jump_entries;
unsigned int num_jump_entries;
+
+ struct static_key_deferred *deferred_keys;
+ unsigned int num_deferred_keys;
#endif
#ifdef CONFIG_TRACING
unsigned int num_trace_bprintk_fmt;
@@ -672,7 +672,7 @@ perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr)
}
}
-extern struct static_key_deferred perf_sched_events;
+extern static_key_deferred(perf_sched_events);
static inline void perf_event_task_sched_in(struct task_struct *prev,
struct task_struct *task)
@@ -138,7 +138,7 @@ enum event_type_t {
* perf_sched_events : >0 events exist
* perf_cgroup_events: >0 per-cpu cgroup events exist on this cpu
*/
-struct static_key_deferred perf_sched_events __read_mostly;
+static_key_deferred(perf_sched_events);
static DEFINE_PER_CPU(atomic_t, perf_cgroup_events);
static DEFINE_PER_CPU(atomic_t, perf_branch_stack_events);
@@ -2751,6 +2751,10 @@ static int find_module_sections(struct module *mod, struct load_info *info)
mod->jump_entries = section_objs(info, "__jump_table",
sizeof(*mod->jump_entries),
&mod->num_jump_entries);
+ mod->deferred_keys = section_objs(info, "__deferred_keys",
+ sizeof(*mod->deferred_keys),
+ &mod->num_deferred_keys);
+
#endif
#ifdef CONFIG_EVENT_TRACING
mod->trace_events = section_objs(info, "_ftrace_events",
We need to know about all deferred keys if we want to correctly - initialize timers on kernel init/module load - destroy pending timers when unloading a module We depend on section attribute, so direct definitions of struct static_key_deferred should be avoided, which is suboptimal. Signed-off-by: Radim Kr?má? <rkrcmar@redhat.com> --- More general solution would use compile-time magic to generate an array of pointers to deferred structures, but I am not sure if it is acceptable and possible. Worse approach added an unload_callback_list to the struct module. Callbacks of type void (*)(void *) were registered on static_key_rate_limit(), to cancel the deferred key work from module_unload_free(). (I have patches for this) Jump labels are already notified for module changes, so we could keep track of deferred keys in modules there, using a static global tree. (in the worst case) arch/x86/kvm/lapic.c | 4 ++-- arch/x86/kvm/lapic.h | 4 ++-- include/asm-generic/vmlinux.lds.h | 1 + include/linux/jump_label_ratelimit.h | 4 ++++ include/linux/module.h | 3 +++ include/linux/perf_event.h | 2 +- kernel/events/core.c | 2 +- kernel/module.c | 4 ++++ 8 files changed, 18 insertions(+), 6 deletions(-)