Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3cd13987 authored by Linus Torvalds's avatar Linus Torvalds Committed by Greg Kroah-Hartman
Browse files

sched/membarrier: reduce the ability to hammer on sys_membarrier



commit 944d5fe50f3f03daacfea16300e656a1691c4a23 upstream.

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.

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>
[ converted to explicit mutex_*() calls - cleanup.h is not in this stable
  branch - gregkh ]
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1e8c1c2a
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@
	| MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED			\
	| MEMBARRIER_PRIVATE_EXPEDITED_SYNC_CORE_BITMASK)

static DEFINE_MUTEX(membarrier_ipi_mutex);

static void ipi_mb(void *info)
{
	smp_mb();	/* IPIs should be serializing but paranoid. */
@@ -64,6 +66,7 @@ static int membarrier_global_expedited(void)
		fallback = true;
	}

	mutex_lock(&membarrier_ipi_mutex);
	cpus_read_lock();
	for_each_online_cpu(cpu) {
		struct task_struct *p;
@@ -104,6 +107,7 @@ static int membarrier_global_expedited(void)
	 * rq->curr modification in scheduler.
	 */
	smp_mb();	/* exit from system call is not a mb */
	mutex_unlock(&membarrier_ipi_mutex);
	return 0;
}

@@ -144,6 +148,7 @@ static int membarrier_private_expedited(int flags)
		fallback = true;
	}

	mutex_lock(&membarrier_ipi_mutex);
	cpus_read_lock();
	for_each_online_cpu(cpu) {
		struct task_struct *p;
@@ -182,6 +187,7 @@ static int membarrier_private_expedited(int flags)
	 * rq->curr modification in scheduler.
	 */
	smp_mb();	/* exit from system call is not a mb */
	mutex_unlock(&membarrier_ipi_mutex);

	return 0;
}