Commit c2c6a374 authored by Ken MacKay's avatar Ken MacKay Committed by Commit Bot

Add GN arg to enable mutex priority inheritance

Mutex priority inheritance is useful to avoid cases where a
high-priority thread is waiting for a mutex that is held by a low
priority thread that may not get to run for a while. This is
particularly useful for realtime applications. For more discussion, see
https://www.kernel.org/doc/Documentation/pi-futex.txt

Some platforms (eg Chromecast) are known to fulfill the requirements for
safe use of mutex priority inheritance; add a GN arg and buildflag so
that priority inheritance can be enabled for those platforms.

Chromecast uses Linux 4.1 or greater, and glibc 2.23-r10, so the bugs
mentioned in LockImpl::PriorityInheritanceAvailable() are not present.

Bug: 
Change-Id: I21cecd2144d82f038e35aa30a2a51c35d541c644
Reviewed-on: https://chromium-review.googlesource.com/847642
Commit-Queue: Kenneth MacKay <kmackay@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#526884}
parent 1060ac80
......@@ -50,6 +50,11 @@ declare_args() {
# Set to true to disable COM init check hooks.
com_init_check_hook_disabled = false
# Set to true to enable mutex priority inheritance. See the comments in
# LockImpl::PriorityInheritanceAvailable() in lock_impl_posix.cc for the
# platform requirements to safely enable priority inheritance.
enable_mutex_priority_inheritance = false
}
if (is_android) {
......@@ -1146,6 +1151,7 @@ jumbo_component("base") {
":cfi_flags",
":debugging_flags",
":protected_memory_flags",
":synchronization_flags",
"//base/numerics:base_numerics",
]
......@@ -1758,6 +1764,14 @@ buildflag_header("protected_memory_flags") {
flags = [ "USE_LLD=$use_lld" ]
}
buildflag_header("synchronization_flags") {
header = "synchronization_flags.h"
header_dir = "base/synchronization"
flags =
[ "ENABLE_MUTEX_PRIORITY_INHERITANCE=$enable_mutex_priority_inheritance" ]
}
# This is the subset of files from base that should not be used with a dynamic
# library. Note that this library cannot depend on base because base depends on
# base_static.
......
......@@ -8,6 +8,8 @@
#include "base/debug/activity_tracker.h"
#include "base/synchronization/lock.h"
#include "base/synchronization/synchronization_flags.h"
#include "build/build_config.h"
namespace base {
namespace internal {
......@@ -76,11 +78,13 @@ void LockImpl::Lock() {
// static
bool LockImpl::PriorityInheritanceAvailable() {
#if PRIORITY_INHERITANCE_LOCKS_POSSIBLE() && defined(OS_MACOSX)
#if BUILDFLAG(ENABLE_MUTEX_PRIORITY_INHERITANCE)
return true;
#elif PRIORITY_INHERITANCE_LOCKS_POSSIBLE() && defined(OS_MACOSX)
return true;
#else
// Security concerns prevent the use of priority inheritance mutexes on Linux.
// * CVE-2010-0622 - wake_futex_pi unlocks incorrect, possible DoS.
// * CVE-2010-0622 - Linux < 2.6.33-rc7, wake_futex_pi possible DoS.
// https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-0622
// * CVE-2012-6647 - Linux < 3.5.1, futex_wait_requeue_pi possible DoS.
// https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-6647
......@@ -92,7 +96,7 @@ bool LockImpl::PriorityInheritanceAvailable() {
// * glibc Bug 14652: https://sourceware.org/bugzilla/show_bug.cgi?id=14652
// Fixed in glibc 2.17.
// Priority inheritance mutexes may deadlock with condition variables
// during recacquisition of the mutex after the condition variable is
// during reacquisition of the mutex after the condition variable is
// signalled.
return false;
#endif
......
......@@ -246,10 +246,12 @@ TEST_P(TaskSchedulerSingleThreadTaskRunnerManagerCommonTest,
waitable_event_background.Wait();
waitable_event_normal.Wait();
if (Lock::HandlesMultipleThreadPriorities())
if (Lock::HandlesMultipleThreadPriorities() &&
PlatformThread::CanIncreaseCurrentThreadPriority()) {
EXPECT_EQ(ThreadPriority::BACKGROUND, thread_priority_background);
else
} else {
EXPECT_EQ(ThreadPriority::NORMAL, thread_priority_background);
}
EXPECT_EQ(ThreadPriority::NORMAL, thread_priority_normal);
}
......
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