Skip to content

LoongArch: Fix calling smp_processor_id() in preemptible code#11259

Open
kernel-patches-daemon-bpf[bot] wants to merge 1 commit intobpf-next_basefrom
series/1060482=>bpf-next
Open

LoongArch: Fix calling smp_processor_id() in preemptible code#11259
kernel-patches-daemon-bpf[bot] wants to merge 1 commit intobpf-next_basefrom
series/1060482=>bpf-next

Conversation

@kernel-patches-daemon-bpf
Copy link

Pull request for series with
subject: LoongArch: Fix calling smp_processor_id() in preemptible code
version: 3
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060482

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 309d880
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060482
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 44dd647
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060482
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 05c9b2e
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060482
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 4faa189
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060482
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 748f9c6
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060482
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 6dd780f
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060482
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 099bded
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060482
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: bd2e02e
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060482
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: bd2e02e
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060482
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 0c55d48
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060482
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: e95e85b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060482
version: 3

Fix the warning:

    BUG: using smp_processor_id() in preemptible [00000000] code: sys
temd/1
    caller is larch_insn_text_copy+0x40/0xf0

Simply changing it to raw_smp_processor_id() is not enough: if preempt
and CPU hotplug happens after raw_smp_processor_id() but before
stop_machine(), the CPU where raw_smp_processor_id() has run may be
offline when stop_machine() and no CPU will run copy_to_kernel_nofault()
in text_copy_cb().  Thus guard the larch_insn_text_copy() calls with
cpus_read_lock() and change stop_machine() to stop_machine_cpuslocked()
to prevent this.

I've considered moving the locks inside larch_insn_text_copy() but
doing so seems not an easy hack.  In bpf_arch_text_poke() obviously the
memcpy() call must be guarded by text_mutex, so we have to leave the
acquire of text_mutex out of larch_insn_text_copy.  But in the entire
kernel the acquire of mutexes is always after cpus_read_lock(), so we
cannot put cpus_read_lock() into larch_insn_text_copy() while leaving
the text_mutex acquire out (or we risk a deadlock due to inconsistent
lock acquire order).  So let's fix the bug first and leave the
posssible refactor as future work.

Fixes: 9fbd18c ("LoongArch: BPF: Add dynamic code modification support")
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant