Re: [PATCH 4/8] mm: thp: only regular file could be THP eligible

From: Miaohe Lin
Date: Thu Mar 03 2022 - 06:48:50 EST


On 2022/3/3 19:43, Dan Carpenter wrote:
> Hi Yang,
>
> url: https://github.com/0day-ci/linux/commits/Yang-Shi/Make-khugepaged-collapse-readonly-FS-THP-more-consistent/20220301-075903
> base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
> config: arm64-randconfig-m031-20220227 (https://download.01.org/0day-ci/archive/20220302/202203020034.2Ii9kTrs-lkp@xxxxxxxxx/config)
> compiler: aarch64-linux-gcc (GCC) 11.2.0
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
> Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
>
> smatch warnings:
> include/linux/huge_mm.h:179 file_thp_enabled() warn: variable dereferenced before check 'vma->vm_file' (see line 177)
> mm/khugepaged.c:468 hugepage_vma_check() error: we previously assumed 'vma->vm_file' could be null (see line 455)
> include/linux/huge_mm.h:179 file_thp_enabled() warn: variable dereferenced before check 'vma->vm_file' (see line 177)
>
> vim +179 include/linux/huge_mm.h
>
> 2224ed1155c07b Yang Shi 2022-02-28 175 static inline bool file_thp_enabled(struct vm_area_struct *vma)
> 2224ed1155c07b Yang Shi 2022-02-28 176 {
> 2224ed1155c07b Yang Shi 2022-02-28 @177 struct inode *inode = vma->vm_file->f_inode;
> ^^^^^^^^^^^^^^
> Dereference.
>
> 2224ed1155c07b Yang Shi 2022-02-28 178
> 2224ed1155c07b Yang Shi 2022-02-28 @179 return (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) && vma->vm_file &&
> ^^^^^^^^^^^^
> Checked too late.

Yep. We should check vma->vm_file first before we access vma->vm_file->f_inode.

Thanks.

>
> 2224ed1155c07b Yang Shi 2022-02-28 180 (vma->vm_flags & VM_EXEC) &&
> 2224ed1155c07b Yang Shi 2022-02-28 181 !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode);
> 2224ed1155c07b Yang Shi 2022-02-28 182 }
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx
>
> .
>