Skip to contentSkip to conversation

fault-injection: make stacktrace filter works with others

PATCH Applied Wei Yongjun 3 participants 7 messages Aug 17, 2022 – Oct 3, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover fault-injection: make stacktrace filter works with others

This patchset allow fault injection run on x86_64, and make stacktrace filter works as expected. With this, we can test device driver module by fault injecting more easy.

*** BLURB HERE ***

Wei Yongjun (4):
fault-injection: allow stacktrace filter for x86-64
fault-injection: skip stacktrace filtering by default
fault-injection: make some stack filter attrs more readable
fault-injection: make stacktrace filter works as expected

 lib/Kconfig.debug  |  1 -
 lib/fault-inject.c | 30 ++++++++++++++++++++++--------
 2 files changed, 22 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 fault-injection: allow stacktrace filter for x86-64

FAULT_INJECTION_STACKTRACE_FILTER option was apparently disallowed on x86_64 because of problems with the stack unwinder:

commit 6d690dcac92a84f98fd774862628ff871b713660
Author: Akinobu Mita <[email protected]>
Date: Sat May 12 10:36:53 2007 -0700

fault injection: disable stacktrace filter for x86-64

However, there is no problems whatsoever with this today. Let's allow it again.

---
 lib/Kconfig.debug | 1 -
 1 file changed, 1 deletion(-)
lib/Kconfig.debug +0 -1
index 38d259b1d262..c6795f4656d7 100644
@@ -1944,7 +1944,6 @@ config FAIL_SUNRPC
 config FAULT_INJECTION_STACKTRACE_FILTER
 	bool "stacktrace filter for fault-injection capabilities"
 	depends on FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT
-	depends on !X86_64
 	select STACKTRACE
 	depends on FRAME_POINTER || MIPS || PPC || S390 || MICROBLAZE || ARM || ARC || X86
 	help
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/4 fault-injection: skip stacktrace filtering by default

In reply to Wei Yongjun

If FAULT_INJECTION_STACKTRACE_FILTER is enabled, the depth is default to 32. This means fail_stacktrace() will iter each entry's stacktrace, even if filter is not configured.

This patch change to quick return from fail_stacktrace() if stacktrace filter is not set.

---
 lib/fault-inject.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fault-inject.c +1 -1
index 423784d9c058..515fc5aaf032 100644
@@ -74,7 +74,7 @@ static bool fail_stacktrace(struct fault_attr *attr)
 	int n, nr_entries;
 	bool found = (attr->require_start == 0 && attr->require_end == ULONG_MAX);
 
-	if (depth == 0)
+	if (depth == 0 || (found && !attr->reject_start && !attr->reject_end))
 		return found;
 
 	nr_entries = stack_trace_save(entries, depth, 1);
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/4 fault-injection: make some stack filter attrs more readable

In reply to Wei Yongjun

Attributes of stack filter are show as unsigned decimal, such as 'require-start', 'require-end'. This patch change to show them as unsigned hexadecimal for more readable.

Before:

  $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start
  $ cat /sys/kernel/debug/failslab/require-start
  18446744072638263296

After:

  $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start
  $ cat /sys/kernel/debug/failslab/require-start
  0xffffffffc0257000
---
 lib/fault-inject.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
lib/fault-inject.c +12 -4
index 515fc5aaf032..deca05e7c9b3 100644
@@ -179,6 +179,14 @@ static void debugfs_create_ul(const char *name, umode_t mode,
 
 #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
 
+DEFINE_SIMPLE_ATTRIBUTE(fops_xl, debugfs_ul_get, debugfs_ul_set, "0x%llx\n");
+
+static void debugfs_create_xl(const char *name, umode_t mode,
+			      struct dentry *parent, unsigned long *value)
+{
+	debugfs_create_file(name, mode, parent, value, &fops_xl);
+}
+
 static int debugfs_stacktrace_depth_set(void *data, u64 val)
 {
 	*(unsigned long *)data =
@@ -223,10 +231,10 @@ struct dentry *fault_create_debugfs_attr(const char *name,
 #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
 	debugfs_create_stacktrace_depth("stacktrace-depth", mode, dir,
 					&attr->stacktrace_depth);
-	debugfs_create_ul("require-start", mode, dir, &attr->require_start);
-	debugfs_create_ul("require-end", mode, dir, &attr->require_end);
-	debugfs_create_ul("reject-start", mode, dir, &attr->reject_start);
-	debugfs_create_ul("reject-end", mode, dir, &attr->reject_end);
+	debugfs_create_xl("require-start", mode, dir, &attr->require_start);
+	debugfs_create_xl("require-end", mode, dir, &attr->require_end);
+	debugfs_create_xl("reject-start", mode, dir, &attr->reject_start);
+	debugfs_create_xl("reject-end", mode, dir, &attr->reject_end);
 #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
 
 	attr->dname = dget(dir);
Signature · 1 line
2.34.1
maintainer
#4 lore raw

Re: [PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable

2022年8月17日(水) 16:45 Wei Yongjun <[email protected]>:

Quoted 25 lines

Attributes of stack filter are show as unsigned decimal, such as 'require-start', 'require-end'. This patch change to show them as unsigned hexadecimal for more readable.

Before:

  $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start
  $ cat /sys/kernel/debug/failslab/require-start
  18446744072638263296

After:

  $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start
  $ cat /sys/kernel/debug/failslab/require-start
  0xffffffffc0257000
---
 lib/fault-inject.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
lib/fault-inject.c +0 -0
index 515fc5aaf032..deca05e7c9b3 100644

lib/fault-inject.c static void debugfs_create_ul(const char *name, umode_t mode, · line 188

Quoted 10 lines
lib/fault-inject.c +7 -0
@@ -179,6 +179,14 @@ static void debugfs_create_ul(const char *name, umode_t mode,
 
 #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
 
+DEFINE_SIMPLE_ATTRIBUTE(fops_xl, debugfs_ul_get, debugfs_ul_set, "0x%llx\n");
+
+static void debugfs_create_xl(const char *name, umode_t mode,
+                             struct dentry *parent, unsigned long *value)
+{
+       debugfs_create_file(name, mode, parent, value, &fops_xl);
+}

How about using an existing debugfs_create_xul() instead of defining a local helper function?

maintainer
#5 lore raw

Re: [PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable

Quoted 29 lines · On Fri, 19 Aug 2022 22:24:10 +0900 Akinobu Mita <[email protected]> wrote:

2022年8月17日(水) 16:45 Wei Yongjun <[email protected]>:

Quoted 28 lines

Attributes of stack filter are show as unsigned decimal, such as 'require-start', 'require-end'. This patch change to show them as unsigned hexadecimal for more readable.

Before:

  $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start
  $ cat /sys/kernel/debug/failslab/require-start
  18446744072638263296

After:

  $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start
  $ cat /sys/kernel/debug/failslab/require-start
  0xffffffffc0257000
---
 lib/fault-inject.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
lib/fault-inject.c +0 -0
index 515fc5aaf032..deca05e7c9b3 100644
@@ -179,6 +179,14 @@ static void debugfs_create_ul(const char *name, umode_t mode,
 
 #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
 
Quoted 10 lines

lib/fault-inject.c static void debugfs_create_ul(const char *name, umode_t mode, · line 188

Quoted 7 lines
lib/fault-inject.c +7 -0
+DEFINE_SIMPLE_ATTRIBUTE(fops_xl, debugfs_ul_get, debugfs_ul_set, "0x%llx\n");
+
+static void debugfs_create_xl(const char *name, umode_t mode,
+                             struct dentry *parent, unsigned long *value)
+{
+       debugfs_create_file(name, mode, parent, value, &fops_xl);
+}

How about using an existing debugfs_create_xul() instead of defining a local helper function?

Could we please have a response to this?

#6 lore raw

PATCH 4/4 fault-injection: make stacktrace filter works as expected

In reply to Wei Yongjun

stacktrace filter is checked after others, such as fail-nth, interval and probability. This make it doesn't work well as expected.

Fix to running stacktrace filter before other filters. It will speed up fault inject testing for driver modules.

---
 lib/fault-inject.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
lib/fault-inject.c +9 -3
index deca05e7c9b3..9dd1dd1d2610 100644
@@ -105,10 +105,16 @@ static inline bool fail_stacktrace(struct fault_attr *attr)
 
 bool should_fail(struct fault_attr *attr, ssize_t size)
 {
+	bool stack_checked = false;
+
 	if (in_task()) {
 		unsigned int fail_nth = READ_ONCE(current->fail_nth);
 
 		if (fail_nth) {
+			if (!fail_stacktrace(attr))
+				return false;
+
+			stack_checked = true;
 			fail_nth--;
 			WRITE_ONCE(current->fail_nth, fail_nth);
 			if (!fail_nth)
@@ -128,6 +134,9 @@ bool should_fail(struct fault_attr *attr, ssize_t size)
 	if (atomic_read(&attr->times) == 0)
 		return false;
 
+	if (!stack_checked && !fail_stacktrace(attr))
+		return false;
+
 	if (atomic_read(&attr->space) > size) {
 		atomic_sub(size, &attr->space);
 		return false;
@@ -142,9 +151,6 @@ bool should_fail(struct fault_attr *attr, ssize_t size)
 	if (attr->probability <= prandom_u32() % 100)
 		return false;
 
-	if (!fail_stacktrace(attr))
-		return false;
-
 fail:
 	fail_dump(attr);
 
Signature · 1 line
2.34.1