From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757656AbcHCPKR (ORCPT ); Wed, 3 Aug 2016 11:10:17 -0400 Received: from userp1050.oracle.com ([156.151.31.82]:51453 "EHLO userp1050.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755690AbcHCPKI (ORCPT ); Wed, 3 Aug 2016 11:10:08 -0400 From: Vegard Nossum To: Akinobu Mita , Peter Zijlstra , Ingo Molnar Cc: linux-kernel@vger.kernel.org, Vegard Nossum Subject: [PATCH 05/10] fault injection: mutex_trylock() fault injection Date: Wed, 3 Aug 2016 17:05:50 +0200 Message-Id: <1470236755-29844-5-git-send-email-vegard.nossum@oracle.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470236755-29844-1-git-send-email-vegard.nossum@oracle.com> References: <1470236755-29844-1-git-send-email-vegard.nossum@oracle.com> X-Source-IP: userp1040.oracle.com [156.151.31.81] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cc: Peter Zijlstra Cc: Ingo Molnar Signed-off-by: Vegard Nossum --- kernel/locking/mutex.c | 32 ++++++++++++++++++++++++++++++++ lib/Kconfig.debug | 6 ++++++ 2 files changed, 38 insertions(+) diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index a70b90d..0651ca6 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -17,6 +17,7 @@ * * Also see Documentation/locking/mutex-design.txt. */ +#include #include #include #include @@ -887,6 +888,34 @@ static inline int __mutex_trylock_slowpath(atomic_t *lock_count) return prev == 1; } +#ifdef CONFIG_FAIL_MUTEX +DECLARE_FAULT_ATTR(fail_mutex); + +static int __init setup_fail_mutex(char *str) +{ + return setup_fault_attr(&fail_mutex, str); +} +__setup("fail_mutex=", setup_fail_mutex); + +static int __init fail_mutex_debugfs(void) +{ + struct dentry *dir = fault_create_debugfs_attr("fail_mutex", + NULL, &fail_mutex); + return PTR_ERR_OR_ZERO(dir); +} +late_initcall(fail_mutex_debugfs); + +static inline bool should_fail_mutex(struct mutex *lock) +{ + return should_fail(&fail_mutex, 1); +} +#else +static inline bool should_fail_mutex(struct mutex *lock) +{ + return false; +} +#endif + /** * mutex_trylock - try to acquire the mutex, without waiting * @lock: the mutex to be acquired @@ -905,6 +934,9 @@ int __sched mutex_trylock(struct mutex *lock) { int ret; + if (should_fail_mutex(lock)) + return 0; + ret = __mutex_fastpath_trylock(&lock->count, __mutex_trylock_slowpath); if (ret) mutex_set_owner(lock); diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 5896b6f..0043e66 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1657,6 +1657,12 @@ config FAIL_FUTEX help Provide fault-injection capability for futexes. +config FAIL_MUTEX + bool "Fault-injection capability for mutexes" + depends on FAULT_INJECTION + help + Provide fault-injection capability for mutex_trylock(). + config FAULT_INJECTION_DEBUG_FS bool "Debugfs entries for fault-injection capabilities" depends on FAULT_INJECTION && SYSFS && DEBUG_FS -- 1.9.1