OpenCloudOS-Kernel/arch/arm64
Will Deacon dd0aaa9ac4 arm64: jump_label: Ensure patched jump_labels are visible to all CPUs
[ Upstream commit cfb00a35786414e7c0e6226b277d9f09657eae74 ]

Although the Arm architecture permits concurrent modification and
execution of NOP and branch instructions, it still requires some
synchronisation to ensure that other CPUs consistently execute the newly
written instruction:

 >  When the modified instructions are observable, each PE that is
 >  executing the modified instructions must execute an ISB or perform a
 >  context synchronizing event to ensure execution of the modified
 >  instructions

Prior to commit f6cc0c5016 ("arm64: Avoid calling stop_machine() when
patching jump labels"), the arm64 jump_label patching machinery
performed synchronisation using stop_machine() after each modification,
however this was problematic when flipping static keys from atomic
contexts (namely, the arm_arch_timer CPU hotplug startup notifier) and
so we switched to the _nosync() patching routines to avoid "scheduling
while atomic" BUG()s during boot.

In hindsight, the analysis of the issue in f6cc0c5016 isn't quite
right: it cites the use of IPIs in the default patching routines as the
cause of the lockup, whereas stop_machine() does not rely on IPIs and
the I-cache invalidation is performed using __flush_icache_range(),
which elides the call to kick_all_cpus_sync(). In fact, the blocking
wait for other CPUs is what triggers the BUG() and the problem remains
even after f6cc0c5016, for example because we could block on the
jump_label_mutex. Eventually, the arm_arch_timer driver was fixed to
avoid the static key entirely in commit a862fc2254
("clocksource/arm_arch_timer: Remove use of workaround static key").

This all leaves the jump_label patching code in a funny situation on
arm64 as we do not synchronise with other CPUs to reduce the likelihood
of a bug which no longer exists. Consequently, toggling a static key on
one CPU cannot be assumed to take effect on other CPUs, leading to
potential issues, for example with missing preempt notifiers.

Rather than revert f6cc0c5016 and go back to stop_machine() for each
patch site, implement arch_jump_label_transform_apply() and kick all
the other CPUs with an IPI at the end of patching.

Cc: Alexander Potapenko <glider@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Fixes: f6cc0c5016 ("arm64: Avoid calling stop_machine() when patching jump labels")
Signed-off-by: Will Deacon <will@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20240731133601.3073-1-will@kernel.org
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-08-11 12:47:24 +02:00
..
boot arm64: dts: qcom: sdm845: Disable SS instance in Parkmode for USB 2024-08-11 12:47:12 +02:00
configs arm64: defconfig: enable the vf610 gpio driver 2024-06-27 13:49:10 +02:00
crypto crypto: arm64/neonbs - fix out-of-bounds access on short input 2024-03-06 14:48:40 +00:00
hyperv
include arm64: jump_label: Ensure patched jump_labels are visible to all CPUs 2024-08-11 12:47:24 +02:00
kernel arm64: jump_label: Ensure patched jump_labels are visible to all CPUs 2024-08-11 12:47:24 +02:00
kvm KVM: arm64: Disassociate vcpus from redistributor region on teardown 2024-06-27 13:49:11 +02:00
lib arm64 fixes for -rc1 2023-09-08 12:48:37 -07:00
mm arm64: hibernate: Fix level3 translation fault in swsusp_save() 2024-04-27 17:11:41 +02:00
net bpf, arm64: Fix incorrect runtime stats 2024-05-17 12:02:01 +02:00
tools arm64: Rename ARM64_WORKAROUND_2966298 2024-01-31 16:18:55 -08:00
xen
Kbuild
Kconfig arm64: ftrace: Don't forbid CALL_OPS+CC_OPTIMIZE_FOR_SIZE with Clang 2024-03-26 18:19:53 -04:00
Kconfig.debug
Kconfig.platforms
Makefile kbuild: unify vdso_install rules 2024-06-12 11:12:32 +02:00