Skip to content

Commit f9eeef5

Browse files
Wei Yongjunakpm00
authored andcommitted
fault-injection: make stacktrace filter works as expected
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]>
1 parent 0199907 commit f9eeef5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/fault-inject.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,16 @@ static inline bool fail_stacktrace(struct fault_attr *attr)
102102

103103
bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags)
104104
{
105+
bool stack_checked = false;
106+
105107
if (in_task()) {
106108
unsigned int fail_nth = READ_ONCE(current->fail_nth);
107109

108110
if (fail_nth) {
111+
if (!fail_stacktrace(attr))
112+
return false;
113+
114+
stack_checked = true;
109115
fail_nth--;
110116
WRITE_ONCE(current->fail_nth, fail_nth);
111117
if (!fail_nth)
@@ -125,6 +131,9 @@ bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags)
125131
if (atomic_read(&attr->times) == 0)
126132
return false;
127133

134+
if (!stack_checked && !fail_stacktrace(attr))
135+
return false;
136+
128137
if (atomic_read(&attr->space) > size) {
129138
atomic_sub(size, &attr->space);
130139
return false;
@@ -139,9 +148,6 @@ bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags)
139148
if (attr->probability <= get_random_u32_below(100))
140149
return false;
141150

142-
if (!fail_stacktrace(attr))
143-
return false;
144-
145151
fail:
146152
if (!(flags & FAULT_NOWARN))
147153
fail_dump(attr);

0 commit comments

Comments
 (0)