Hi Peter,

> It _should_ all work.. but scary, who knows where this early stuff ends
> up being used.

I have tested this patch, and the following patch, which moves the
jump label init early and it works as Thomas describes:
on_each_cpu() ends up calling only the current CPU.

Also, you mentioned:
> And I added a sync_core() in text_poke_early(), which I think we need
> for this.

text_poke_bp() ends up calling on_each_cpu(do_sync_core, NULL, 1);
which is called on boot CPU, and thus sync_core is called. If we keep
this patch we can remove sync_core() change from the next patch.

However, the other way to fix this bug is to change:
arch/x86/kernel/jump_label.c

-void arch_jump_label_transform(struct jump_entry *entry,
+void __ref arch_jump_label_transform(struct jump_entry *entry,
                               enum jump_label_type type)
 {
+       void *(*poker)(void *, const void *, size_t) = NULL;
+
+       if (unlikely(!after_bootmem))
+               poker = text_poke_early;
+
        mutex_lock(&text_mutex);
-       __jump_label_transform(entry, type, NULL, 0);
+       __jump_label_transform(entry, type, poker, 0);
        mutex_unlock(&text_mutex);
 }

Also, modify text_poke_early to call sync_core().

Of course, this way won't prevent us from having some other code
calling text_poke() in the future during boot where uninitialized
memory access is possible. If text_poke() is called sufficiently
early, it will fail because virt_to_page() will fail, but there is an
interval, where virt_to_page() succeeds (after paging_init()), but
pages are not yet initialized (before mem_init()). To safeguard us we
could add:

BUG_ON(!after_bootmem);

To text_poke()

Thank you,
Pavel

Reply via email to