When we specify __GFP_NOWARN, we only expect that no warnings will be issued for current caller. But in the __should_failslab() and __should_fail_alloc_page(), the local GFP flags alter the global {failslab|fail_page_alloc}.attr, which is persistent and shared by all tasks. This is not what we expected, let's fix it. [akpm@linux-foundation.org: unexport should_fail_ex()] Link: https://lkml.kernel.org/r/20221118100011.2634-1-zhengqi.arch@bytedance.com Fixes: 3f913fc5f974 ("mm: fix missing handler for __GFP_NOWARN") Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com> Reported-by: Dmitry Vyukov <dvyukov@google.com> Reviewed-by: Akinobu Mita <akinobu.mita@gmail.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Cc: Akinobu Mita <akinobu.mita@gmail.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Showing the changes to lib (1 of 4 files). Show all
Unified · Split
| @@ -41,9 +41,6 @@ EXPORT_SYMBOL_GPL(setup_fault_attr); · 40 unmodified lines | |||
| 41 | 41 | ||
| 42 | static void fail_dump(struct fault_attr *attr) | 42 | static void fail_dump(struct fault_attr *attr) |
| 43 | { | 43 | { |
| 44 | if (attr->no_warn) | ||
| 45 | return; | ||
| 46 | |||
| 47 | if (attr->verbose > 0 && __ratelimit(&attr->ratelimit_state)) { | 44 | if (attr->verbose > 0 && __ratelimit(&attr->ratelimit_state)) { |
| 48 | printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure.\n" | 45 | printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure.\n" |
| 49 | "name %pd, interval %lu, probability %lu, " | 46 | "name %pd, interval %lu, probability %lu, " |
| @@ -103,7 +100,7 @@ static inline bool fail_stacktrace(struct fault_attr *attr) · 53 unmodified lines | |||
| 103 | * http://www.nongnu.org/failmalloc/ | 100 | * http://www.nongnu.org/failmalloc/ |
| 104 | */ | 101 | */ |
| 105 | 102 | ||
| 106 | bool should_fail(struct fault_attr *attr, ssize_t size) | 103 | bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags) |
| 107 | { | 104 | { |
| 108 | if (in_task()) { | 105 | if (in_task()) { |
| 109 | unsigned int fail_nth = READ_ONCE(current->fail_nth); | 106 | unsigned int fail_nth = READ_ONCE(current->fail_nth); |
| @@ -146,13 +143,19 @@ bool should_fail(struct fault_attr *attr, ssize_t size) · 36 unmodified lines | |||
| 146 | return false; | 143 | return false; |
| 147 | 144 | ||
| 148 | fail: | 145 | fail: |
| 149 | fail_dump(attr); | 146 | if (!(flags & FAULT_NOWARN)) |
| 147 | fail_dump(attr); | ||
| 150 | 148 | ||
| 151 | if (atomic_read(&attr->times) != -1) | 149 | if (atomic_read(&attr->times) != -1) |
| 152 | atomic_dec_not_zero(&attr->times); | 150 | atomic_dec_not_zero(&attr->times); |
| 153 | 151 | ||
| 154 | return true; | 152 | return true; |
| 155 | } | 153 | } |
| 154 | |||
| 155 | bool should_fail(struct fault_attr *attr, ssize_t size) | ||
| 156 | { | ||
| 157 | return should_fail_ex(attr, size, 0); | ||
| 158 | } | ||
| 156 | EXPORT_SYMBOL_GPL(should_fail); | 159 | EXPORT_SYMBOL_GPL(should_fail); |
| 157 | 160 | ||
| 158 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS | 161 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS |