Commit 219e9b7b authored by William Cohen's avatar William Cohen Committed by Luis Henriques

Correct the race condition in aarch64_insn_patch_text_sync()

commit 899d5933 upstream.

When experimenting with patches to provide kprobes support for aarch64
smp machines would hang when inserting breakpoints into kernel code.
The hangs were caused by a race condition in the code called by
aarch64_insn_patch_text_sync().  The first processor in the
aarch64_insn_patch_text_cb() function would patch the code while other
processors were still entering the function and incrementing the
cpu_count field.  This resulted in some processors never observing the
exit condition and exiting the function.  Thus, processors in the
system hung.

The first processor to enter the patching function performs the
patching and signals that the patching is complete with an increment
of the cpu_count field. When all the processors have incremented the
cpu_count field the cpu_count will be num_cpus_online()+1 and they
will return to normal execution.

Fixes: ae164807 arm64: introduce interfaces to hotpatch kernel and module code
Signed-off-by: default avatarWilliam Cohen <wcohen@redhat.com>
Acked-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 73d908ca
...@@ -156,9 +156,10 @@ static int __kprobes aarch64_insn_patch_text_cb(void *arg) ...@@ -156,9 +156,10 @@ static int __kprobes aarch64_insn_patch_text_cb(void *arg)
* which ends with "dsb; isb" pair guaranteeing global * which ends with "dsb; isb" pair guaranteeing global
* visibility. * visibility.
*/ */
atomic_set(&pp->cpu_count, -1); /* Notify other processors with an additional increment. */
atomic_inc(&pp->cpu_count);
} else { } else {
while (atomic_read(&pp->cpu_count) != -1) while (atomic_read(&pp->cpu_count) <= num_online_cpus())
cpu_relax(); cpu_relax();
isb(); isb();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment