All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4 -next] fault-injection: make stacktrace filter works with others
@ 2022-08-17  8:03 Wei Yongjun
  2022-08-17  8:03 ` [PATCH 1/4 -next] fault-injection: allow stacktrace filter for x86-64 Wei Yongjun
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Wei Yongjun @ 2022-08-17  8:03 UTC (permalink / raw)
  To: Akinobu Mita, Andrew Morton, Nathan Chancellor, Peter Zijlstra,
	Kees Cook, Nick Desaulniers, Josh Poimboeuf, Dan Williams,
	Miguel Ojeda, Isabella Basso, Vlastimil Babka, Rasmus Villemoes
  Cc: Wei Yongjun, linux-kernel

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(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4 -next] fault-injection: allow stacktrace filter for x86-64
  2022-08-17  8:03 [PATCH 0/4 -next] fault-injection: make stacktrace filter works with others Wei Yongjun
@ 2022-08-17  8:03 ` Wei Yongjun
  2022-08-17  8:03 ` [PATCH 2/4 -next] fault-injection: skip stacktrace filtering by default Wei Yongjun
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Wei Yongjun @ 2022-08-17  8:03 UTC (permalink / raw)
  To: Akinobu Mita, Andrew Morton, Nathan Chancellor, Peter Zijlstra,
	Kees Cook, Nick Desaulniers, Josh Poimboeuf, Dan Williams,
	Miguel Ojeda, Isabella Basso, Vlastimil Babka, Rasmus Villemoes
  Cc: Wei Yongjun, linux-kernel

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

    commit 6d690dcac92a84f98fd774862628ff871b713660
    Author: Akinobu Mita <akinobu.mita@gmail.com>
    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.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 lib/Kconfig.debug | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 38d259b1d262..c6795f4656d7 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -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
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4 -next] fault-injection: skip stacktrace filtering by default
  2022-08-17  8:03 [PATCH 0/4 -next] fault-injection: make stacktrace filter works with others Wei Yongjun
  2022-08-17  8:03 ` [PATCH 1/4 -next] fault-injection: allow stacktrace filter for x86-64 Wei Yongjun
@ 2022-08-17  8:03 ` Wei Yongjun
  2022-08-17  8:03 ` [PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable Wei Yongjun
  2022-08-17  8:03 ` [PATCH 4/4 -next] fault-injection: make stacktrace filter works as expected Wei Yongjun
  3 siblings, 0 replies; 7+ messages in thread
From: Wei Yongjun @ 2022-08-17  8:03 UTC (permalink / raw)
  To: Akinobu Mita, Andrew Morton, Nathan Chancellor, Peter Zijlstra,
	Kees Cook, Nick Desaulniers, Josh Poimboeuf, Dan Williams,
	Miguel Ojeda, Isabella Basso, Vlastimil Babka, Rasmus Villemoes
  Cc: Wei Yongjun, linux-kernel

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.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 lib/fault-inject.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index 423784d9c058..515fc5aaf032 100644
--- a/lib/fault-inject.c
+++ b/lib/fault-inject.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable
  2022-08-17  8:03 [PATCH 0/4 -next] fault-injection: make stacktrace filter works with others Wei Yongjun
  2022-08-17  8:03 ` [PATCH 1/4 -next] fault-injection: allow stacktrace filter for x86-64 Wei Yongjun
  2022-08-17  8:03 ` [PATCH 2/4 -next] fault-injection: skip stacktrace filtering by default Wei Yongjun
@ 2022-08-17  8:03 ` Wei Yongjun
  2022-08-19 13:24   ` Akinobu Mita
  2022-08-17  8:03 ` [PATCH 4/4 -next] fault-injection: make stacktrace filter works as expected Wei Yongjun
  3 siblings, 1 reply; 7+ messages in thread
From: Wei Yongjun @ 2022-08-17  8:03 UTC (permalink / raw)
  To: Akinobu Mita, Andrew Morton, Nathan Chancellor, Peter Zijlstra,
	Kees Cook, Nick Desaulniers, Josh Poimboeuf, Dan Williams,
	Miguel Ojeda, Isabella Basso, Vlastimil Babka, Rasmus Villemoes
  Cc: Wei Yongjun, linux-kernel

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

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 lib/fault-inject.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index 515fc5aaf032..deca05e7c9b3 100644
--- a/lib/fault-inject.c
+++ b/lib/fault-inject.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4 -next] fault-injection: make stacktrace filter works as expected
  2022-08-17  8:03 [PATCH 0/4 -next] fault-injection: make stacktrace filter works with others Wei Yongjun
                   ` (2 preceding siblings ...)
  2022-08-17  8:03 ` [PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable Wei Yongjun
@ 2022-08-17  8:03 ` Wei Yongjun
  3 siblings, 0 replies; 7+ messages in thread
From: Wei Yongjun @ 2022-08-17  8:03 UTC (permalink / raw)
  To: Akinobu Mita, Andrew Morton, Nathan Chancellor, Peter Zijlstra,
	Kees Cook, Nick Desaulniers, Josh Poimboeuf, Dan Williams,
	Miguel Ojeda, Isabella Basso, Vlastimil Babka, Rasmus Villemoes
  Cc: Wei Yongjun, linux-kernel

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.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 lib/fault-inject.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index deca05e7c9b3..9dd1dd1d2610 100644
--- a/lib/fault-inject.c
+++ b/lib/fault-inject.c
@@ -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);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable
  2022-08-17  8:03 ` [PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable Wei Yongjun
@ 2022-08-19 13:24   ` Akinobu Mita
  2022-10-03 21:17     ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Akinobu Mita @ 2022-08-19 13:24 UTC (permalink / raw)
  To: Wei Yongjun
  Cc: Andrew Morton, Nathan Chancellor, Peter Zijlstra, Kees Cook,
	Nick Desaulniers, Josh Poimboeuf, Dan Williams, Miguel Ojeda,
	Isabella Basso, Vlastimil Babka, Rasmus Villemoes, LKML

2022年8月17日(水) 16:45 Wei Yongjun <weiyongjun1@huawei.com>:
>
> 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
>
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
>  lib/fault-inject.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/lib/fault-inject.c b/lib/fault-inject.c
> index 515fc5aaf032..deca05e7c9b3 100644
> --- a/lib/fault-inject.c
> +++ b/lib/fault-inject.c
> @@ -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?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable
  2022-08-19 13:24   ` Akinobu Mita
@ 2022-10-03 21:17     ` Andrew Morton
  0 siblings, 0 replies; 7+ messages in thread
From: Andrew Morton @ 2022-10-03 21:17 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: Wei Yongjun, Nathan Chancellor, Peter Zijlstra, Kees Cook,
	Nick Desaulniers, Josh Poimboeuf, Dan Williams, Miguel Ojeda,
	Isabella Basso, Vlastimil Babka, Rasmus Villemoes, LKML

On Fri, 19 Aug 2022 22:24:10 +0900 Akinobu Mita <akinobu.mita@gmail.com> wrote:

> 2022年8月17日(水) 16:45 Wei Yongjun <weiyongjun1@huawei.com>:
> >
> > 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
> >
> > Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> > ---
> >  lib/fault-inject.c | 16 ++++++++++++----
> >  1 file changed, 12 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/fault-inject.c b/lib/fault-inject.c
> > index 515fc5aaf032..deca05e7c9b3 100644
> > --- a/lib/fault-inject.c
> > +++ b/lib/fault-inject.c
> > @@ -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?

Could we please have a response to this?



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-10-03 21:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-17  8:03 [PATCH 0/4 -next] fault-injection: make stacktrace filter works with others Wei Yongjun
2022-08-17  8:03 ` [PATCH 1/4 -next] fault-injection: allow stacktrace filter for x86-64 Wei Yongjun
2022-08-17  8:03 ` [PATCH 2/4 -next] fault-injection: skip stacktrace filtering by default Wei Yongjun
2022-08-17  8:03 ` [PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable Wei Yongjun
2022-08-19 13:24   ` Akinobu Mita
2022-10-03 21:17     ` Andrew Morton
2022-08-17  8:03 ` [PATCH 4/4 -next] fault-injection: make stacktrace filter works as expected Wei Yongjun

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.