Skip to content

Commit e91d7ff

Browse files
Alexei Starovoitovgregkh
authored andcommitted
mm/error_inject: Fix allow_error_inject function signatures.
[ Upstream commit 76cd617 ] '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: af3b854 ("mm/page_alloc.c: allow error injection") Fixes: cfcbfb1 ("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 Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 0fabd29 commit e91d7ff

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

mm/filemap.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,10 +827,10 @@ int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask)
827827
}
828828
EXPORT_SYMBOL_GPL(replace_page_cache_page);
829829

830-
static int __add_to_page_cache_locked(struct page *page,
831-
struct address_space *mapping,
832-
pgoff_t offset, gfp_t gfp_mask,
833-
void **shadowp)
830+
noinline int __add_to_page_cache_locked(struct page *page,
831+
struct address_space *mapping,
832+
pgoff_t offset, gfp_t gfp_mask,
833+
void **shadowp)
834834
{
835835
XA_STATE(xas, &mapping->i_pages, offset);
836836
int huge = PageHuge(page);

mm/page_alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3496,7 +3496,7 @@ static inline bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
34963496

34973497
#endif /* CONFIG_FAIL_PAGE_ALLOC */
34983498

3499-
static noinline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
3499+
noinline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
35003500
{
35013501
return __should_fail_alloc_page(gfp_mask, order);
35023502
}

0 commit comments

Comments
 (0)