linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* mm/shmem.c:2223 shmem_split_large_entry() error: uninitialized symbol 'entry_order'.
@ 2025-06-18 17:42 Dan Carpenter
  2025-06-18 17:47 ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2025-06-18 17:42 UTC (permalink / raw)
  To: oe-kbuild, Zi Yan
  Cc: lkp, oe-kbuild-all, linux-kernel, Andrew Morton,
	Linux Memory Management List, Baolin Wang

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   4774cfe3543abb8ee98089f535e28ebfd45b975a
commit: d53c78fffe7ad364397c693522ceb4d152c2aacd mm/shmem: use xas_try_split() in shmem_split_large_entry()
config: x86_64-randconfig-161-20250614 (https://download.01.org/0day-ci/archive/20250614/202506141535.tjdnCMqW-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0

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/202506141535.tjdnCMqW-lkp@intel.com/

smatch warnings:
mm/shmem.c:2223 shmem_split_large_entry() error: uninitialized symbol 'entry_order'.

vim +/entry_order +2223 mm/shmem.c

12885cbe88ddf6 Baolin Wang 2024-08-12  2151  static int shmem_split_large_entry(struct inode *inode, pgoff_t index,
12885cbe88ddf6 Baolin Wang 2024-08-12  2152  				   swp_entry_t swap, gfp_t gfp)
12885cbe88ddf6 Baolin Wang 2024-08-12  2153  {
12885cbe88ddf6 Baolin Wang 2024-08-12  2154  	struct address_space *mapping = inode->i_mapping;
12885cbe88ddf6 Baolin Wang 2024-08-12  2155  	XA_STATE_ORDER(xas, &mapping->i_pages, index, 0);
d53c78fffe7ad3 Zi Yan      2025-03-14  2156  	int split_order = 0, entry_order;
d53c78fffe7ad3 Zi Yan      2025-03-14  2157  	int i;
12885cbe88ddf6 Baolin Wang 2024-08-12  2158  
12885cbe88ddf6 Baolin Wang 2024-08-12  2159  	/* Convert user data gfp flags to xarray node gfp flags */
12885cbe88ddf6 Baolin Wang 2024-08-12  2160  	gfp &= GFP_RECLAIM_MASK;
12885cbe88ddf6 Baolin Wang 2024-08-12  2161  
12885cbe88ddf6 Baolin Wang 2024-08-12  2162  	for (;;) {
12885cbe88ddf6 Baolin Wang 2024-08-12  2163  		void *old = NULL;
d53c78fffe7ad3 Zi Yan      2025-03-14  2164  		int cur_order;
d53c78fffe7ad3 Zi Yan      2025-03-14  2165  		pgoff_t swap_index;
12885cbe88ddf6 Baolin Wang 2024-08-12  2166  
12885cbe88ddf6 Baolin Wang 2024-08-12  2167  		xas_lock_irq(&xas);
12885cbe88ddf6 Baolin Wang 2024-08-12  2168  		old = xas_load(&xas);
12885cbe88ddf6 Baolin Wang 2024-08-12  2169  		if (!xa_is_value(old) || swp_to_radix_entry(swap) != old) {
12885cbe88ddf6 Baolin Wang 2024-08-12  2170  			xas_set_err(&xas, -EEXIST);
12885cbe88ddf6 Baolin Wang 2024-08-12  2171  			goto unlock;

Imagine we hit this goto on the first iteration

12885cbe88ddf6 Baolin Wang 2024-08-12  2172  		}
12885cbe88ddf6 Baolin Wang 2024-08-12  2173  
d53c78fffe7ad3 Zi Yan      2025-03-14  2174  		entry_order = xas_get_order(&xas);
12885cbe88ddf6 Baolin Wang 2024-08-12  2175  
d53c78fffe7ad3 Zi Yan      2025-03-14  2176  		if (!entry_order)
d53c78fffe7ad3 Zi Yan      2025-03-14  2177  			goto unlock;
12885cbe88ddf6 Baolin Wang 2024-08-12  2178  
12885cbe88ddf6 Baolin Wang 2024-08-12  2179  		/* Try to split large swap entry in pagecache */
d53c78fffe7ad3 Zi Yan      2025-03-14  2180  		cur_order = entry_order;
d53c78fffe7ad3 Zi Yan      2025-03-14  2181  		swap_index = round_down(index, 1 << entry_order);
d53c78fffe7ad3 Zi Yan      2025-03-14  2182  
d53c78fffe7ad3 Zi Yan      2025-03-14  2183  		split_order = xas_try_split_min_order(cur_order);
d53c78fffe7ad3 Zi Yan      2025-03-14  2184  
d53c78fffe7ad3 Zi Yan      2025-03-14  2185  		while (cur_order > 0) {
d53c78fffe7ad3 Zi Yan      2025-03-14  2186  			pgoff_t aligned_index =
d53c78fffe7ad3 Zi Yan      2025-03-14  2187  				round_down(index, 1 << cur_order);
d53c78fffe7ad3 Zi Yan      2025-03-14  2188  			pgoff_t swap_offset = aligned_index - swap_index;
d53c78fffe7ad3 Zi Yan      2025-03-14  2189  
d53c78fffe7ad3 Zi Yan      2025-03-14  2190  			xas_set_order(&xas, index, split_order);
d53c78fffe7ad3 Zi Yan      2025-03-14  2191  			xas_try_split(&xas, old, cur_order);
d53c78fffe7ad3 Zi Yan      2025-03-14  2192  			if (xas_error(&xas))
12885cbe88ddf6 Baolin Wang 2024-08-12  2193  				goto unlock;
12885cbe88ddf6 Baolin Wang 2024-08-12  2194  
12885cbe88ddf6 Baolin Wang 2024-08-12  2195  			/*
12885cbe88ddf6 Baolin Wang 2024-08-12  2196  			 * Re-set the swap entry after splitting, and the swap
12885cbe88ddf6 Baolin Wang 2024-08-12  2197  			 * offset of the original large entry must be continuous.
12885cbe88ddf6 Baolin Wang 2024-08-12  2198  			 */
d53c78fffe7ad3 Zi Yan      2025-03-14  2199  			for (i = 0; i < 1 << cur_order;
d53c78fffe7ad3 Zi Yan      2025-03-14  2200  			     i += (1 << split_order)) {
12885cbe88ddf6 Baolin Wang 2024-08-12  2201  				swp_entry_t tmp;
12885cbe88ddf6 Baolin Wang 2024-08-12  2202  
d53c78fffe7ad3 Zi Yan      2025-03-14  2203  				tmp = swp_entry(swp_type(swap),
d53c78fffe7ad3 Zi Yan      2025-03-14  2204  						swp_offset(swap) + swap_offset +
d53c78fffe7ad3 Zi Yan      2025-03-14  2205  							i);
12885cbe88ddf6 Baolin Wang 2024-08-12  2206  				__xa_store(&mapping->i_pages, aligned_index + i,
12885cbe88ddf6 Baolin Wang 2024-08-12  2207  					   swp_to_radix_entry(tmp), 0);
12885cbe88ddf6 Baolin Wang 2024-08-12  2208  			}
d53c78fffe7ad3 Zi Yan      2025-03-14  2209  			cur_order = split_order;
d53c78fffe7ad3 Zi Yan      2025-03-14  2210  			split_order = xas_try_split_min_order(split_order);
12885cbe88ddf6 Baolin Wang 2024-08-12  2211  		}
12885cbe88ddf6 Baolin Wang 2024-08-12  2212  
12885cbe88ddf6 Baolin Wang 2024-08-12  2213  unlock:
12885cbe88ddf6 Baolin Wang 2024-08-12  2214  		xas_unlock_irq(&xas);
12885cbe88ddf6 Baolin Wang 2024-08-12  2215  
12885cbe88ddf6 Baolin Wang 2024-08-12  2216  		if (!xas_nomem(&xas, gfp))
12885cbe88ddf6 Baolin Wang 2024-08-12  2217  			break;

And we hit this break.

12885cbe88ddf6 Baolin Wang 2024-08-12  2218  	}
12885cbe88ddf6 Baolin Wang 2024-08-12  2219  
12885cbe88ddf6 Baolin Wang 2024-08-12  2220  	if (xas_error(&xas))
12885cbe88ddf6 Baolin Wang 2024-08-12  2221  		return xas_error(&xas);
12885cbe88ddf6 Baolin Wang 2024-08-12  2222  
d53c78fffe7ad3 Zi Yan      2025-03-14 @2223  	return entry_order;
6cec2b95dadf77 Miaohe Lin  2022-05-19  2224  }

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



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

* Re: mm/shmem.c:2223 shmem_split_large_entry() error: uninitialized symbol 'entry_order'.
  2025-06-18 17:42 mm/shmem.c:2223 shmem_split_large_entry() error: uninitialized symbol 'entry_order' Dan Carpenter
@ 2025-06-18 17:47 ` Matthew Wilcox
  2025-06-18 17:53   ` Zi Yan
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2025-06-18 17:47 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: oe-kbuild, Zi Yan, lkp, oe-kbuild-all, linux-kernel,
	Andrew Morton, Linux Memory Management List, Baolin Wang

On Wed, Jun 18, 2025 at 08:42:17PM +0300, Dan Carpenter wrote:
> smatch warnings:
> mm/shmem.c:2223 shmem_split_large_entry() error: uninitialized symbol 'entry_order'.

...

> 12885cbe88ddf6 Baolin Wang 2024-08-12  2169  		if (!xa_is_value(old) || swp_to_radix_entry(swap) != old) {
> 12885cbe88ddf6 Baolin Wang 2024-08-12  2170  			xas_set_err(&xas, -EEXIST);
> 12885cbe88ddf6 Baolin Wang 2024-08-12  2171  			goto unlock;
> 
> Imagine we hit this goto on the first iteration

That can happen (but if it does, we set -EEXIST in the xa_state).

> 12885cbe88ddf6 Baolin Wang 2024-08-12  2213  unlock:
> 12885cbe88ddf6 Baolin Wang 2024-08-12  2214  		xas_unlock_irq(&xas);
> 12885cbe88ddf6 Baolin Wang 2024-08-12  2215  
> 12885cbe88ddf6 Baolin Wang 2024-08-12  2216  		if (!xas_nomem(&xas, gfp))
> 12885cbe88ddf6 Baolin Wang 2024-08-12  2217  			break;
> 
> And we hit this break.

That's guaranteed.  If there's an errno in the xa_state that isn't
-ENOMEM, xas_nomem() will fail.

> 12885cbe88ddf6 Baolin Wang 2024-08-12  2218  	}
> 12885cbe88ddf6 Baolin Wang 2024-08-12  2219  
> 12885cbe88ddf6 Baolin Wang 2024-08-12  2220  	if (xas_error(&xas))
> 12885cbe88ddf6 Baolin Wang 2024-08-12  2221  		return xas_error(&xas);
> 12885cbe88ddf6 Baolin Wang 2024-08-12  2222  
> d53c78fffe7ad3 Zi Yan      2025-03-14 @2223  	return entry_order;

but if this does happen, then xas_error() will be true and we'll return
-EEXIST here instead of returning entry_order.


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

* Re: mm/shmem.c:2223 shmem_split_large_entry() error: uninitialized symbol 'entry_order'.
  2025-06-18 17:47 ` Matthew Wilcox
@ 2025-06-18 17:53   ` Zi Yan
  0 siblings, 0 replies; 3+ messages in thread
From: Zi Yan @ 2025-06-18 17:53 UTC (permalink / raw)
  To: Matthew Wilcox, Dan Carpenter
  Cc: oe-kbuild, lkp, oe-kbuild-all, linux-kernel, Andrew Morton,
	Linux Memory Management List, Baolin Wang

On 18 Jun 2025, at 13:47, Matthew Wilcox wrote:

> On Wed, Jun 18, 2025 at 08:42:17PM +0300, Dan Carpenter wrote:
>> smatch warnings:
>> mm/shmem.c:2223 shmem_split_large_entry() error: uninitialized symbol 'entry_order'.
>
> ...
>
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2169  		if (!xa_is_value(old) || swp_to_radix_entry(swap) != old) {
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2170  			xas_set_err(&xas, -EEXIST);
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2171  			goto unlock;
>>
>> Imagine we hit this goto on the first iteration
>
> That can happen (but if it does, we set -EEXIST in the xa_state).
>
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2213  unlock:
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2214  		xas_unlock_irq(&xas);
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2215
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2216  		if (!xas_nomem(&xas, gfp))
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2217  			break;
>>
>> And we hit this break.
>
> That's guaranteed.  If there's an errno in the xa_state that isn't
> -ENOMEM, xas_nomem() will fail.
>
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2218  	}
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2219
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2220  	if (xas_error(&xas))
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2221  		return xas_error(&xas);
>> 12885cbe88ddf6 Baolin Wang 2024-08-12  2222
>> d53c78fffe7ad3 Zi Yan      2025-03-14 @2223  	return entry_order;
>
> but if this does happen, then xas_error() will be true and we'll return
> -EEXIST here instead of returning entry_order.
Hi Matthew,

Thank you for the explanation.

Hi Dan,

I got a similar report 3 months ago and explained it already.
See https://lore.kernel.org/linux-mm/B024C29C-96D4-4F92-B2EF-F01CB06B27DF@nvidia.com/

Best Regards,
Yan, Zi


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

end of thread, other threads:[~2025-06-18 17:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-18 17:42 mm/shmem.c:2223 shmem_split_large_entry() error: uninitialized symbol 'entry_order' Dan Carpenter
2025-06-18 17:47 ` Matthew Wilcox
2025-06-18 17:53   ` Zi Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).