Commit 944d5fe5 authored by Linus Torvalds's avatar Linus Torvalds Committed by Linus Torvalds

sched/membarrier: reduce the ability to hammer on sys_membarrier

On some systems, sys_membarrier can be very expensive, causing overall
slowdowns for everything.  So put a lock on the path in order to
serialize the accesses to prevent the ability for this to be called at
too high of a frequency and saturate the machine.
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-and-tested-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Acked-by: default avatarBorislav Petkov <bp@alien8.de>
Fixes: 22e4ebb9 ("membarrier: Provide expedited private command")
Fixes: c5f58bd5 ("membarrier: Provide GLOBAL_EXPEDITED command")
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b401b621
...@@ -162,6 +162,9 @@ ...@@ -162,6 +162,9 @@
| MEMBARRIER_PRIVATE_EXPEDITED_RSEQ_BITMASK \ | MEMBARRIER_PRIVATE_EXPEDITED_RSEQ_BITMASK \
| MEMBARRIER_CMD_GET_REGISTRATIONS) | MEMBARRIER_CMD_GET_REGISTRATIONS)
static DEFINE_MUTEX(membarrier_ipi_mutex);
#define SERIALIZE_IPI() guard(mutex)(&membarrier_ipi_mutex)
static void ipi_mb(void *info) static void ipi_mb(void *info)
{ {
smp_mb(); /* IPIs should be serializing but paranoid. */ smp_mb(); /* IPIs should be serializing but paranoid. */
...@@ -259,6 +262,7 @@ static int membarrier_global_expedited(void) ...@@ -259,6 +262,7 @@ static int membarrier_global_expedited(void)
if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL)) if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL))
return -ENOMEM; return -ENOMEM;
SERIALIZE_IPI();
cpus_read_lock(); cpus_read_lock();
rcu_read_lock(); rcu_read_lock();
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
...@@ -347,6 +351,7 @@ static int membarrier_private_expedited(int flags, int cpu_id) ...@@ -347,6 +351,7 @@ static int membarrier_private_expedited(int flags, int cpu_id)
if (cpu_id < 0 && !zalloc_cpumask_var(&tmpmask, GFP_KERNEL)) if (cpu_id < 0 && !zalloc_cpumask_var(&tmpmask, GFP_KERNEL))
return -ENOMEM; return -ENOMEM;
SERIALIZE_IPI();
cpus_read_lock(); cpus_read_lock();
if (cpu_id >= 0) { if (cpu_id >= 0) {
...@@ -460,6 +465,7 @@ static int sync_runqueues_membarrier_state(struct mm_struct *mm) ...@@ -460,6 +465,7 @@ static int sync_runqueues_membarrier_state(struct mm_struct *mm)
* between threads which are users of @mm has its membarrier state * between threads which are users of @mm has its membarrier state
* updated. * updated.
*/ */
SERIALIZE_IPI();
cpus_read_lock(); cpus_read_lock();
rcu_read_lock(); rcu_read_lock();
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
......
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