linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* mm/filemap.c:3307 do_sync_mmap_readahead() warn: assigning (-12) to unsigned variable 'ra->order'
@ 2026-01-13 11:12 Dan Carpenter
  2026-01-13 12:24 ` Jan Kara
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2026-01-13 11:12 UTC (permalink / raw)
  To: oe-kbuild, Roman Gushchin
  Cc: lkp, oe-kbuild-all, linux-kernel, Andrew Morton,
	Linux Memory Management List, Dev Jain, Jan Kara

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   b71e635feefc852405b14620a7fc58c4c80c0f73
commit: 9f1edf1aedac1b287355f63f768ba4275de72dca mm: readahead: make thp readahead conditional to mmap_miss logic
config: x86_64-randconfig-161-20260113 (https://download.01.org/0day-ci/archive/20260113/202601131311.g3lyUAks-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
smatch version: v0.5.0-8985-g2614ff1a

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202601131311.g3lyUAks-lkp@intel.com/

smatch warnings:
mm/filemap.c:3307 do_sync_mmap_readahead() warn: assigning (-12) to unsigned variable 'ra->order'

vim +3307 mm/filemap.c

6b4c9f4469819a0 Josef Bacik             2019-03-13  3248  static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)
ef00e08e26dd5d8 Linus Torvalds          2009-06-16  3249  {
2a1180f1bd389e9 Josef Bacik             2019-03-13  3250  	struct file *file = vmf->vma->vm_file;
2a1180f1bd389e9 Josef Bacik             2019-03-13  3251  	struct file_ra_state *ra = &file->f_ra;
ef00e08e26dd5d8 Linus Torvalds          2009-06-16  3252  	struct address_space *mapping = file->f_mapping;
fcd9ae4f7f3b5fb Matthew Wilcox (Oracle  2021-04-07  3253) 	DEFINE_READAHEAD(ractl, file, ra, mapping, vmf->pgoff);
6b4c9f4469819a0 Josef Bacik             2019-03-13  3254  	struct file *fpin = NULL;
bfbe71109fa40e8 Lorenzo Stoakes         2025-06-18  3255  	vm_flags_t vm_flags = vmf->vma->vm_flags;
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3256  	bool force_thp_readahead = false;
f5e8b140cd1324c Ryan Roberts            2025-06-09  3257  	unsigned short mmap_miss;
ef00e08e26dd5d8 Linus Torvalds          2009-06-16  3258  
4687fdbb805a92c Matthew Wilcox (Oracle  2021-07-24  3259) 	/* Use the readahead code, even if readahead is disabled */
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3260  	if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) &&
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3261  	    (vm_flags & VM_HUGEPAGE) && HPAGE_PMD_ORDER <= MAX_PAGECACHE_ORDER)
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3262  		force_thp_readahead = true;
4687fdbb805a92c Matthew Wilcox (Oracle  2021-07-24  3263) 
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3264  	if (!force_thp_readahead) {
38b0ece6d76374b Ryan Roberts            2025-06-09  3265  		/*
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3266  		 * If we don't want any read-ahead, don't bother.
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3267  		 * VM_EXEC case below is already intended for random access.
38b0ece6d76374b Ryan Roberts            2025-06-09  3268  		 */
38b0ece6d76374b Ryan Roberts            2025-06-09  3269  		if ((vm_flags & (VM_RAND_READ | VM_EXEC)) == VM_RAND_READ)
6b4c9f4469819a0 Josef Bacik             2019-03-13  3270  			return fpin;
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3271  
275b12bf5486f6f Wu Fengguang            2011-05-24  3272  		if (!ra->ra_pages)
6b4c9f4469819a0 Josef Bacik             2019-03-13  3273  			return fpin;
ef00e08e26dd5d8 Linus Torvalds          2009-06-16  3274  
dcfa24ba68991ab Matthew Wilcox (Oracle  2022-05-25  3275) 		if (vm_flags & VM_SEQ_READ) {
6b4c9f4469819a0 Josef Bacik             2019-03-13  3276  			fpin = maybe_unlock_mmap_for_io(vmf, fpin);
fcd9ae4f7f3b5fb Matthew Wilcox (Oracle  2021-04-07  3277) 			page_cache_sync_ra(&ractl, ra->ra_pages);
6b4c9f4469819a0 Josef Bacik             2019-03-13  3278  			return fpin;
ef00e08e26dd5d8 Linus Torvalds          2009-06-16  3279  		}
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3280  	}
ef00e08e26dd5d8 Linus Torvalds          2009-06-16  3281  
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3282  	if (!(vm_flags & VM_SEQ_READ)) {
207d04baa3591a3 Andi Kleen              2011-05-24  3283  		/* Avoid banging the cache line if not needed */
e630bfac79456d3 Kirill A. Shutemov      2020-08-14  3284  		mmap_miss = READ_ONCE(ra->mmap_miss);
e630bfac79456d3 Kirill A. Shutemov      2020-08-14  3285  		if (mmap_miss < MMAP_LOTSAMISS * 10)
e630bfac79456d3 Kirill A. Shutemov      2020-08-14  3286  			WRITE_ONCE(ra->mmap_miss, ++mmap_miss);
ef00e08e26dd5d8 Linus Torvalds          2009-06-16  3287  
ef00e08e26dd5d8 Linus Torvalds          2009-06-16  3288  		/*
ef00e08e26dd5d8 Linus Torvalds          2009-06-16  3289  		 * Do we miss much more than hit in this file? If so,
ef00e08e26dd5d8 Linus Torvalds          2009-06-16  3290  		 * stop bothering with read-ahead. It will only hurt.
ef00e08e26dd5d8 Linus Torvalds          2009-06-16  3291  		 */
e630bfac79456d3 Kirill A. Shutemov      2020-08-14  3292  		if (mmap_miss > MMAP_LOTSAMISS)
6b4c9f4469819a0 Josef Bacik             2019-03-13  3293  			return fpin;
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3294  	}
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3295  
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3296  	if (force_thp_readahead) {
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3297  		fpin = maybe_unlock_mmap_for_io(vmf, fpin);
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3298  		ractl._index &= ~((unsigned long)HPAGE_PMD_NR - 1);
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3299  		ra->size = HPAGE_PMD_NR;
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3300  		/*
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3301  		 * Fetch two PMD folios, so we get the chance to actually
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3302  		 * readahead, unless we've been told not to.
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3303  		 */
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3304  		if (!(vm_flags & VM_RAND_READ))
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3305  			ra->size *= 2;
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3306  		ra->async_size = HPAGE_PMD_NR;
9f1edf1aedac1b2 Roman Gushchin          2025-10-06 @3307  		ra->order = HPAGE_PMD_ORDER;

HPAGE_PMD_SHIFT is zero in this config?
ra->order is a u16.

9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3308  		page_cache_ra_order(&ractl, ra);
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3309  		return fpin;
9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3310  	}
ef00e08e26dd5d8 Linus Torvalds          2009-06-16  3311  
38b0ece6d76374b Ryan Roberts            2025-06-09  3312  	if (vm_flags & VM_EXEC) {
38b0ece6d76374b Ryan Roberts            2025-06-09  3313  		/*
38b0ece6d76374b Ryan Roberts            2025-06-09  3314  		 * Allow arch to request a preferred minimum folio order for
38b0ece6d76374b Ryan Roberts            2025-06-09  3315  		 * executable memory. This can often be beneficial to

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: mm/filemap.c:3307 do_sync_mmap_readahead() warn: assigning (-12) to unsigned variable 'ra->order'
  2026-01-13 11:12 mm/filemap.c:3307 do_sync_mmap_readahead() warn: assigning (-12) to unsigned variable 'ra->order' Dan Carpenter
@ 2026-01-13 12:24 ` Jan Kara
  2026-01-13 12:56   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kara @ 2026-01-13 12:24 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: oe-kbuild, Roman Gushchin, lkp, oe-kbuild-all, linux-kernel,
	Andrew Morton, Linux Memory Management List, Dev Jain, Jan Kara

On Tue 13-01-26 14:12:28, Dan Carpenter wrote:
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head:   b71e635feefc852405b14620a7fc58c4c80c0f73
> commit: 9f1edf1aedac1b287355f63f768ba4275de72dca mm: readahead: make thp readahead conditional to mmap_miss logic
> config: x86_64-randconfig-161-20260113 (https://download.01.org/0day-ci/archive/20260113/202601131311.g3lyUAks-lkp@intel.com/config)
> compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
> smatch version: v0.5.0-8985-g2614ff1a
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> | Closes: https://lore.kernel.org/r/202601131311.g3lyUAks-lkp@intel.com/
> 
> smatch warnings:
> mm/filemap.c:3307 do_sync_mmap_readahead() warn: assigning (-12) to unsigned variable 'ra->order'
...
> 9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3306  		ra->async_size = HPAGE_PMD_NR;
> 9f1edf1aedac1b2 Roman Gushchin          2025-10-06 @3307  		ra->order = HPAGE_PMD_ORDER;
> 
> HPAGE_PMD_SHIFT is zero in this config?
> ra->order is a u16.

What's the config exactly? I suppose CONFIG_TRANSPARENT_HUGEPAGE is
disabled in this case, isn't it? In that case force_thp_readahead will
never be true and thus the branch with the assignment can never be reached
AFAICT...

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: mm/filemap.c:3307 do_sync_mmap_readahead() warn: assigning (-12) to unsigned variable 'ra->order'
  2026-01-13 12:24 ` Jan Kara
@ 2026-01-13 12:56   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2026-01-13 12:56 UTC (permalink / raw)
  To: Jan Kara
  Cc: oe-kbuild, Roman Gushchin, lkp, oe-kbuild-all, linux-kernel,
	Andrew Morton, Linux Memory Management List, Dev Jain

On Tue, Jan 13, 2026 at 01:24:20PM +0100, Jan Kara wrote:
> On Tue 13-01-26 14:12:28, Dan Carpenter wrote:
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > head:   b71e635feefc852405b14620a7fc58c4c80c0f73
> > commit: 9f1edf1aedac1b287355f63f768ba4275de72dca mm: readahead: make thp readahead conditional to mmap_miss logic
> > config: x86_64-randconfig-161-20260113 (https://download.01.org/0day-ci/archive/20260113/202601131311.g3lyUAks-lkp@intel.com/config)
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> > compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
> > smatch version: v0.5.0-8985-g2614ff1a
> > 
> > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > the same patch/commit), kindly add following tags
> > | Reported-by: kernel test robot <lkp@intel.com>
> > | Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> > | Closes: https://lore.kernel.org/r/202601131311.g3lyUAks-lkp@intel.com/
> > 
> > smatch warnings:
> > mm/filemap.c:3307 do_sync_mmap_readahead() warn: assigning (-12) to unsigned variable 'ra->order'
> ...
> > 9f1edf1aedac1b2 Roman Gushchin          2025-10-06  3306  		ra->async_size = HPAGE_PMD_NR;
> > 9f1edf1aedac1b2 Roman Gushchin          2025-10-06 @3307  		ra->order = HPAGE_PMD_ORDER;
> > 
> > HPAGE_PMD_SHIFT is zero in this config?
> > ra->order is a u16.
> 
> What's the config exactly? I suppose CONFIG_TRANSPARENT_HUGEPAGE is
> disabled in this case, isn't it? In that case force_thp_readahead will
> never be true and thus the branch with the assignment can never be reached
> AFAICT...
> 

Ah, yes.  You are right.  force_thp_readahead is false in this
config.

The truth is, I could easily disable these kinds of warnings in smatch
because this is marked as an impossible path.  if (is_impossible_path())
return...  I've done that on a case by case basis in the past but maybe I
should just do it globally.

regards,
dan carpenter



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-13 12:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-13 11:12 mm/filemap.c:3307 do_sync_mmap_readahead() warn: assigning (-12) to unsigned variable 'ra->order' Dan Carpenter
2026-01-13 12:24 ` Jan Kara
2026-01-13 12:56   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox