mm/error_inject: Fix allow_error_inject function signatures.
authorAlexei Starovoitov <ast@kernel.org>
Thu, 27 Aug 2020 22:01:10 +0000 (15:01 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 28 Aug 2020 19:20:32 +0000 (21:20 +0200)
'static' and 'static noinline' function attributes make no guarantees that
gcc/clang won't optimize them. The compiler may decide to inline 'static'
function and in such case ALLOW_ERROR_INJECT becomes meaningless. The compiler
could have inlined __add_to_page_cache_locked() in one callsite and didn't
inline in another. In such case injecting errors into it would cause
unpredictable behavior. It's worse with 'static noinline' which won't be
inlined, but it still can be optimized. Like the compiler may decide to remove
one argument or constant propagate the value depending on the callsite.

To avoid such issues make sure that these functions are global noinline.

Fixes: af3b854492f3 ("mm/page_alloc.c: allow error injection")
Fixes: cfcbfb1382db ("mm/filemap.c: enable error injection at add_to_page_cache()")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Link: https://lore.kernel.org/bpf/20200827220114.69225-2-alexei.starovoitov@gmail.com
mm/filemap.c
mm/page_alloc.c

index 1aaea26556cc7e4ab702af1e96262d67a0607cf0..054d93a86f8a02ac4c94da57325ef7bc6320e6f8 100644 (file)
@@ -827,10 +827,10 @@ int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask)
 }
 EXPORT_SYMBOL_GPL(replace_page_cache_page);
 
-static int __add_to_page_cache_locked(struct page *page,
-                                     struct address_space *mapping,
-                                     pgoff_t offset, gfp_t gfp_mask,
-                                     void **shadowp)
+noinline int __add_to_page_cache_locked(struct page *page,
+                                       struct address_space *mapping,
+                                       pgoff_t offset, gfp_t gfp_mask,
+                                       void **shadowp)
 {
        XA_STATE(xas, &mapping->i_pages, offset);
        int huge = PageHuge(page);
index 0e2bab486fea6f4d2a6f79c13255d33e097dcb9e..cd8d8f0326fc9a89e17ad17bea658d27d63f08ee 100644 (file)
@@ -3477,7 +3477,7 @@ static inline bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
 
 #endif /* CONFIG_FAIL_PAGE_ALLOC */
 
-static noinline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
+noinline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
 {
        return __should_fail_alloc_page(gfp_mask, order);
 }