mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vegard Nossum <vegard.nossum@oracle.com>
To: Akinobu Mita <akinobu.mita@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Vegard Nossum <vegard.nossum@oracle.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>
Subject: [PATCH 07/10] fault injection: down_trylock() fault injection
Date: Sun, 16 Oct 2016 17:56:09 +0200	[thread overview]
Message-ID: <20161016155612.4784-7-vegard.nossum@oracle.com> (raw)
In-Reply-To: <20161016155612.4784-1-vegard.nossum@oracle.com>

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 12ad8eb..1e134de 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
-- 
2.10.0.479.g221bd91

  parent reply	other threads:[~2016-10-16 15:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-16 15:56 [PATCH 01/10] fault injection: fix a few documentation errors Vegard Nossum
2016-10-16 15:56 ` [PATCH 02/10] fault injection: fix Kconfig menu Vegard Nossum
2016-10-18  9:32   ` Ulf Hansson
2016-10-16 15:56 ` [PATCH 03/10] fault injection: allow FAULT_INJECTION_STACKTRACE_FILTER on X86_64 Vegard Nossum
2016-10-16 15:56 ` [PATCH 04/10] fault injection: prevent recursive fault injection Vegard Nossum
2016-10-17  3:58   ` Hillf Danton
2016-10-16 15:56 ` [PATCH 05/10] fault injection: mutex_trylock() " Vegard Nossum
2016-10-16 16:27   ` Peter Zijlstra
2016-10-16 15:56 ` [PATCH 06/10] fault injection: rt_mutex_trylock() " Vegard Nossum
2016-10-16 16:27   ` Peter Zijlstra
2016-10-16 15:56 ` Vegard Nossum [this message]
2016-10-16 16:27   ` [PATCH 07/10] fault injection: down_trylock() " Peter Zijlstra
2016-10-16 15:56 ` [PATCH 08/10] fault injection: down_{read,write}_trylock() " Vegard Nossum
2016-10-16 16:27   ` Peter Zijlstra
2016-10-16 15:56 ` [PATCH 09/10] fault injection: spin_trylock() " Vegard Nossum
2016-10-16 16:28   ` Peter Zijlstra
2016-10-16 15:56 ` [PATCH 10/10] fault injection: inject faults in new/rare callchains Vegard Nossum
2016-10-21  0:32   ` Akinobu Mita
  -- strict thread matches above, loose matches on Subject: below --
2016-08-03 15:05 [PATCH 01/10] fault injection: fix a few documentation errors Vegard Nossum
2016-08-03 15:05 ` [PATCH 07/10] fault injection: down_trylock() fault injection Vegard Nossum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161016155612.4784-7-vegard.nossum@oracle.com \
    --to=vegard.nossum@oracle.com \
    --cc=akinobu.mita@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®