Re: [Linux kernel bug] WARNING in static_key_slow_inc_cpuslocked

From: Thomas Gleixner
Date: Sun Jun 09 2024 - 10:06:20 EST


On Sun, Jun 09 2024 at 09:04, Steven Rostedt wrote:
> On Sun, 9 Jun 2024 14:33:01 +0800
> Sam Sun <samsun1006219@xxxxxxxxx> wrote:
>> [ 82.310798][ T8020] ------------[ cut here ]------------
>> [ 82.311236][ T8020] kernel BUG at arch/x86/kernel/jump_label.c:73!
>
> This is not a bug with jump labels. It's a bug with whatever is using jump
> labels. Looks like something tried to modify a jump label that no longer
> exists.

The jump label exists.

>> [ 82.331873][ T8020] set_attr_rdpmc+0x193/0x270
>> [ 82.332179][ T8020] ? get_attr_rdpmc+0x30/0x30
>> [ 82.332511][ T8020] ? sysfs_kf_write+0x18d/0x2b0
>> [ 82.332832][ T8020] ? sysfs_kf_read+0x370/0x370
>> [ 82.333159][ T8020] kernfs_fop_write_iter+0x3ab/0x500
>
> So, something in kernfs modified a jump label location that was freed?

No. What happens is:

CPU 0 CPU 1

kernfs_fop_write_iter() kernfs_fop_write_iter()
set_attr_rdpmc() set_attr_rdpmc()
arch_jump_label_transform_queue() arch_jump_label_transform_queue()
mutex_lock(text_mutex) mutex_lock(text_mutex)
__jump_label_patch()
text_poke_queue()
mutex_unlokc(text_mutex)
__jump_label_patch()

CPU 1 sees the original text and not the expected because CPU 0 did not
yet invoke arch_jump_label_transform_apply().

So clearly set_attr_rdpmc() lacks serialization, no?

Thanks,

tglx