Re: [Linux kernel bug] WARNING in static_key_slow_inc_cpuslocked

From: Steven Rostedt
Date: Sun Jun 09 2024 - 10:25:24 EST


On Sun, 09 Jun 2024 16:06:05 +0200
Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:

> 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.

Ah, I missed the set_attr_rdpmc() as something not with a "?" in front :-p

>
> >> [ 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?
>

Hmm, but should jump labels fail when that happens? Or should it catch
it, and not cause a BUG?

-- Steve