Re: [willy-pagecache:for-next 52/85] mm/page_vma_mapped.c:246 page_vma_mapped_walk() warn: always true condition '(pvmw->nr_pages >= (1 << ( - 12))) => (0-u32max >= 0)'

From: Matthew Wilcox
Date: Mon Feb 14 2022 - 10:20:44 EST


Hey Dan, is this an smatch bug?

On Mon, Feb 14, 2022 at 07:53:39PM +0800, kernel test robot wrote:
> tree: git://git.infradead.org/users/willy/pagecache for-next
> head: c267b33d0001488f1d9dad12d6a87655e174d914
> commit: 9733dd1f11d6b6f8a38fa82f0cc014f7840cbd67 [52/85] mm: Convert page_vma_mapped_walk to work on PFNs
> config: xtensa-randconfig-m031-20220213 (https://download.01.org/0day-ci/archive/20220214/202202141933.YLNzdo4f-lkp@xxxxxxxxx/config)
> compiler: xtensa-linux-gcc (GCC) 11.2.0
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
>
> smatch warnings:
> mm/page_vma_mapped.c:246 page_vma_mapped_walk() warn: always true condition '(pvmw->nr_pages >= (1 << ( - 12))) => (0-u32max >= 0)'

[...]

> 244 if ((pvmw->flags & PVMW_SYNC) &&
> 245 transparent_hugepage_active(vma) &&
> > 246 (pvmw->nr_pages >= HPAGE_PMD_NR)) {
> 247 spinlock_t *ptl = pmd_lock(mm, pvmw->pmd);

The config in question doesn't enable CONFIG_TRANSPARENT_HUGEPAGE,
so this condition should turn into
if ((pvmw->flags & PVMW_SYNC) && false && true)
and I don't think smatch should warn on the third clause of the if
being always-true when the second one is false. Of course, it's not a
literal "false", it's:

static inline bool transparent_hugepage_active(struct vm_area_struct *vma)
{
return false;
}

unless my debugging / understanding of this issue has gone astray.