Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1455847
| Path | csiph.com!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Vegard Nossum <vegard.nossum@oracle.com> |
| Newsgroups | linux.kernel |
| Subject | [PATCH 07/10] fault injection: down_trylock() fault injection |
| Date | Wed, 03 Aug 2016 17:20:01 +0200 |
| Message-ID | <s267D-4aR-1@gated-at.bofh.it> (permalink) |
| References | <s267D-4aR-3@gated-at.bofh.it> |
| X-Mailer | git-send-email 1.9.1 |
| X-Source-IP | aserp1040.oracle.com [141.146.126.69] |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 78 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | linux-kernel@vger.kernel.org, Vegard Nossum <vegard.nossum@oracle.com> |
| X-Original-Date | Wed, 3 Aug 2016 17:05:52 +0200 |
| X-Original-Message-ID | <1470236755-29844-7-git-send-email-vegard.nossum@oracle.com> |
| X-Original-References | <1470236755-29844-1-git-send-email-vegard.nossum@oracle.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1455847 |
Show key headers only | View raw
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
---
kernel/locking/semaphore.c | 26 ++++++++++++++++++++++++++
lib/Kconfig.debug | 6 ++++++
2 files changed, 32 insertions(+)
diff --git a/kernel/locking/semaphore.c b/kernel/locking/semaphore.c
index b8120ab..367bae3 100644
--- a/kernel/locking/semaphore.c
+++ b/kernel/locking/semaphore.c
@@ -25,6 +25,7 @@
* semaphore. If it's zero, there may be tasks waiting on the wait_list.
*/
+#include <linux/fault-inject.h>
#include <linux/compiler.h>
#include <linux/kernel.h>
#include <linux/export.h>
@@ -114,6 +115,28 @@ int down_killable(struct semaphore *sem)
}
EXPORT_SYMBOL(down_killable);
+#ifdef CONFIG_FAIL_SEMAPHORE
+DECLARE_FAULT_ATTR(fail_semaphore);
+
+static int __init fail_semaphore_debugfs(void)
+{
+ struct dentry *dir = fault_create_debugfs_attr("fail_semaphore",
+ NULL, &fail_semaphore);
+ return PTR_ERR_OR_ZERO(dir);
+}
+late_initcall(fail_semaphore_debugfs);
+
+static inline bool should_fail_semaphore(struct semaphore *sem)
+{
+ return should_fail(&fail_semaphore, 1);
+}
+#else
+static inline bool should_fail_semaphore(struct semaphore *sem)
+{
+ return false;
+}
+#endif
+
/**
* down_trylock - try to acquire the semaphore, without waiting
* @sem: the semaphore to be acquired
@@ -132,6 +155,9 @@ int down_trylock(struct semaphore *sem)
unsigned long flags;
int count;
+ if (should_fail_semaphore(sem))
+ return 1;
+
raw_spin_lock_irqsave(&sem->lock, flags);
count = sem->count - 1;
if (likely(count >= 0))
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 4d7110c..5473759 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1669,6 +1669,12 @@ config FAIL_RT_MUTEX
help
Provide fault-injection capability for rt_mutex_trylock().
+config FAIL_SEMAPHORE
+ bool "Fault-injection capability for semaphores"
+ depends on FAULT_INJECTION
+ help
+ Provide fault-injection capability for down_trylock().
+
config FAULT_INJECTION_DEBUG_FS
bool "Debugfs entries for fault-injection capabilities"
depends on FAULT_INJECTION && SYSFS && DEBUG_FS
--
1.9.1
Back to linux.kernel | Previous | Next | Find similar | Unroll thread
[PATCH 07/10] fault injection: down_trylock() fault injection Vegard Nossum <vegard.nossum@oracle.com> - 2016-08-03 17:20 +0200
csiph-web