Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1455852 > unrolled thread

[PATCH 08/10] fault injection: down_{read,write}_trylock() fault injection

Started byVegard Nossum <vegard.nossum@oracle.com>
First post2016-08-03 17:20 +0200
Last post2016-08-03 17:20 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 08/10] fault injection: down_{read,write}_trylock() fault injection Vegard Nossum <vegard.nossum@oracle.com> - 2016-08-03 17:20 +0200

#1455852 — [PATCH 08/10] fault injection: down_{read,write}_trylock() fault injection

FromVegard Nossum <vegard.nossum@oracle.com>
Date2016-08-03 17:20 +0200
Subject[PATCH 08/10] fault injection: down_{read,write}_trylock() fault injection
Message-ID<s267E-4aR-21@gated-at.bofh.it>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
---
 kernel/locking/rwsem.c | 35 +++++++++++++++++++++++++++++++++--
 lib/Kconfig.debug      |  6 ++++++
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index 45ba475..e52ffd3 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -4,6 +4,7 @@
  * Derived from asm-i386/semaphore.h
  */
 
+#include <linux/fault-inject.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
@@ -13,6 +14,28 @@
 
 #include "rwsem.h"
 
+#ifdef CONFIG_FAIL_RW_SEMAPHORE
+DECLARE_FAULT_ATTR(fail_rwsem);
+
+static int __init fail_rwsem_debugfs(void)
+{
+	struct dentry *dir = fault_create_debugfs_attr("fail_rwsem",
+		NULL, &fail_rwsem);
+	return PTR_ERR_OR_ZERO(dir);
+}
+late_initcall(fail_rwsem_debugfs);
+
+static inline bool should_fail_rwsem(struct rw_semaphore *sem)
+{
+	return should_fail(&fail_rwsem, 1);
+}
+#else
+static inline bool should_fail_rwsem(struct rw_semaphore *sem)
+{
+	return false;
+}
+#endif
+
 /*
  * lock for reading
  */
@@ -32,8 +55,12 @@ EXPORT_SYMBOL(down_read);
  */
 int down_read_trylock(struct rw_semaphore *sem)
 {
-	int ret = __down_read_trylock(sem);
+	int ret;
+
+	if (should_fail_rwsem(sem))
+		return 0;
 
+	ret = __down_read_trylock(sem);
 	if (ret == 1) {
 		rwsem_acquire_read(&sem->dep_map, 0, 1, _RET_IP_);
 		rwsem_set_reader_owned(sem);
@@ -81,8 +108,12 @@ EXPORT_SYMBOL(down_write_killable);
  */
 int down_write_trylock(struct rw_semaphore *sem)
 {
-	int ret = __down_write_trylock(sem);
+	int ret;
+
+	if (should_fail_rwsem(sem))
+		return 0;
 
+	ret = __down_write_trylock(sem);
 	if (ret == 1) {
 		rwsem_acquire(&sem->dep_map, 0, 1, _RET_IP_);
 		rwsem_set_owner(sem);
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 5473759..a69289a 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1675,6 +1675,12 @@ config FAIL_SEMAPHORE
 	help
 	  Provide fault-injection capability for down_trylock().
 
+config FAIL_RW_SEMAPHORE
+	bool "Fault-injection capability for RW semaphores"
+	depends on FAULT_INJECTION
+	help
+	  Provide fault-injection capability for down_{read,write}_trylock().
+
 config FAULT_INJECTION_DEBUG_FS
 	bool "Debugfs entries for fault-injection capabilities"
 	depends on FAULT_INJECTION && SYSFS && DEBUG_FS
-- 
1.9.1

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web