]> Git Repo - J-linux.git/commitdiff
fault-injection: make stacktrace filter works as expected
authorWei Yongjun <[email protected]>
Wed, 17 Aug 2022 08:03:32 +0000 (08:03 +0000)
committerAndrew Morton <[email protected]>
Fri, 16 Dec 2022 00:40:44 +0000 (16:40 -0800)
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.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Wei Yongjun <[email protected]>
Cc: Akinobu Mita <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Isabella Basso <[email protected]>
Cc: Josh Poimboeuf <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Miguel Ojeda <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Nick Desaulniers <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
lib/fault-inject.c

index d7819cacf8901bc6866f6b4d1a439c8d03dd5af1..6cff320c4eb4085b0dc93cb43909cb4fce8fac94 100644 (file)
@@ -102,10 +102,16 @@ static inline bool fail_stacktrace(struct fault_attr *attr)
 
 bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags)
 {
+       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)
@@ -125,6 +131,9 @@ bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags)
        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;
@@ -139,9 +148,6 @@ bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags)
        if (attr->probability <= get_random_u32_below(100))
                return false;
 
-       if (!fail_stacktrace(attr))
-               return false;
-
 fail:
        if (!(flags & FAULT_NOWARN))
                fail_dump(attr);
This page took 0.048518 seconds and 4 git commands to generate.