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/20220817080332.1052710-5-weiyongjun1@huawei.com Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com> Cc: Akinobu Mita <akinobu.mita@gmail.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Isabella Basso <isabbasso@riseup.net> Cc: Josh Poimboeuf <jpoimboe@kernel.org> Cc: Kees Cook <keescook@chromium.org> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 0199907 commit f9eeef5

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

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)