linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: Gautam Menghani <gautammenghani201@gmail.com>
Cc: llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
	Linux Memory Management List <linux-mm@kvack.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [linux-next:master 3067/3190] mm/khugepaged.c:1729:7: warning: variable 'index' is used uninitialized whenever 'if' condition is true
Date: Tue, 25 Oct 2022 19:01:57 +0800	[thread overview]
Message-ID: <202210251946.eT92YAhG-lkp@intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 36750 bytes --]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   89bf6e28373beef9577fa71f996a5f73a569617c
commit: eae5270d3322f7838ced159e7e59be606f5db8e9 [3067/3190] mm/khugepaged: add tracepoint to collapse_file()
config: s390-randconfig-r004-20221024 (attached as .config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install s390 cross compiling tool for clang build
        # apt-get install binutils-s390x-linux-gnu
        # https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=eae5270d3322f7838ced159e7e59be606f5db8e9
        git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
        git fetch --no-tags linux-next master
        git checkout eae5270d3322f7838ced159e7e59be606f5db8e9
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> mm/khugepaged.c:1729:7: warning: variable 'index' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
                   if (!xas_nomem(&xas, GFP_KERNEL)) {
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   mm/khugepaged.c:2063:47: note: uninitialized use occurs here
           trace_mm_khugepaged_collapse_file(mm, hpage, index, is_shmem,
                                                        ^~~~~
   mm/khugepaged.c:1729:3: note: remove the 'if' if its condition is always false
                   if (!xas_nomem(&xas, GFP_KERNEL)) {
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   mm/khugepaged.c:1716:6: warning: variable 'index' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (result != SCAN_SUCCEED)
               ^~~~~~~~~~~~~~~~~~~~~~
   mm/khugepaged.c:2063:47: note: uninitialized use occurs here
           trace_mm_khugepaged_collapse_file(mm, hpage, index, is_shmem,
                                                        ^~~~~
   mm/khugepaged.c:1716:2: note: remove the 'if' if its condition is always false
           if (result != SCAN_SUCCEED)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   mm/khugepaged.c:1705:15: note: initialize the variable 'index' to silence this warning
           pgoff_t index, end = start + HPAGE_PMD_NR;
                        ^
                         = 0
>> mm/khugepaged.c:1729:7: warning: variable 'nr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
                   if (!xas_nomem(&xas, GFP_KERNEL)) {
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   mm/khugepaged.c:2064:15: note: uninitialized use occurs here
                   addr, file, nr, result);
                               ^~
   mm/khugepaged.c:1729:3: note: remove the 'if' if its condition is always false
                   if (!xas_nomem(&xas, GFP_KERNEL)) {
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   mm/khugepaged.c:1716:6: warning: variable 'nr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (result != SCAN_SUCCEED)
               ^~~~~~~~~~~~~~~~~~~~~~
   mm/khugepaged.c:2064:15: note: uninitialized use occurs here
                   addr, file, nr, result);
                               ^~
   mm/khugepaged.c:1716:2: note: remove the 'if' if its condition is always false
           if (result != SCAN_SUCCEED)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   mm/khugepaged.c:1710:8: note: initialize the variable 'nr' to silence this warning
           int nr;
                 ^
                  = 0
   4 warnings generated.


vim +1729 mm/khugepaged.c

f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1674  
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1675  /**
99cb0dbd47a15d Song Liu                2019-09-23  1676   * collapse_file - collapse filemap/tmpfs/shmem pages into huge one.
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1677   *
336e6b53d99ae3 Alex Shi                2020-12-14  1678   * @mm: process address space where collapse happens
34488399fa08fa Zach O'Keefe            2022-09-22  1679   * @addr: virtual collapse start address
336e6b53d99ae3 Alex Shi                2020-12-14  1680   * @file: file that collapse on
336e6b53d99ae3 Alex Shi                2020-12-14  1681   * @start: collapse start address
9710a78ab2aed0 Zach O'Keefe            2022-07-06  1682   * @cc: collapse context and scratchpad
336e6b53d99ae3 Alex Shi                2020-12-14  1683   *
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1684   * Basic scheme is simple, details are more complex:
87c460a0bded56 Hugh Dickins            2018-11-30  1685   *  - allocate and lock a new huge page;
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1686   *  - scan page cache replacing old pages with the new one
99cb0dbd47a15d Song Liu                2019-09-23  1687   *    + swap/gup in pages if necessary;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1688   *    + fill in gaps;
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1689   *    + keep old pages around in case rollback is required;
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1690   *  - if replacing succeeds:
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1691   *    + copy data over;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1692   *    + free old pages;
87c460a0bded56 Hugh Dickins            2018-11-30  1693   *    + unlock huge page;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1694   *  - if replacing failed;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1695   *    + put all pages back and unfreeze them;
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1696   *    + restore gaps in the page cache;
87c460a0bded56 Hugh Dickins            2018-11-30  1697   *    + unlock and free huge page;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1698   */
34488399fa08fa Zach O'Keefe            2022-09-22  1699  static int collapse_file(struct mm_struct *mm, unsigned long addr,
579c571e2efdb8 Song Liu                2019-09-23  1700  			 struct file *file, pgoff_t start,
34488399fa08fa Zach O'Keefe            2022-09-22  1701  			 struct collapse_control *cc)
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1702  {
579c571e2efdb8 Song Liu                2019-09-23  1703  	struct address_space *mapping = file->f_mapping;
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1704  	struct page *hpage;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1705  	pgoff_t index, end = start + HPAGE_PMD_NR;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1706  	LIST_HEAD(pagelist);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1707  	XA_STATE_ORDER(xas, &mapping->i_pages, start, HPAGE_PMD_ORDER);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1708  	int nr_none = 0, result = SCAN_SUCCEED;
99cb0dbd47a15d Song Liu                2019-09-23  1709  	bool is_shmem = shmem_file(file);
bf9ecead53c89d Muchun Song             2021-02-24  1710  	int nr;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1711  
99cb0dbd47a15d Song Liu                2019-09-23  1712  	VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1713  	VM_BUG_ON(start & (HPAGE_PMD_NR - 1));
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1714  
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1715  	result = alloc_charge_hpage(&hpage, mm, cc);
9710a78ab2aed0 Zach O'Keefe            2022-07-06  1716  	if (result != SCAN_SUCCEED)
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1717  		goto out;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1718  
6b24ca4a1a8d4e Matthew Wilcox (Oracle  2020-06-27  1719) 	/*
6b24ca4a1a8d4e Matthew Wilcox (Oracle  2020-06-27  1720) 	 * Ensure we have slots for all the pages in the range.  This is
6b24ca4a1a8d4e Matthew Wilcox (Oracle  2020-06-27  1721) 	 * almost certainly a no-op because most of the pages must be present
6b24ca4a1a8d4e Matthew Wilcox (Oracle  2020-06-27  1722) 	 */
95feeabb77149f Hugh Dickins            2018-11-30  1723  	do {
95feeabb77149f Hugh Dickins            2018-11-30  1724  		xas_lock_irq(&xas);
95feeabb77149f Hugh Dickins            2018-11-30  1725  		xas_create_range(&xas);
95feeabb77149f Hugh Dickins            2018-11-30  1726  		if (!xas_error(&xas))
95feeabb77149f Hugh Dickins            2018-11-30  1727  			break;
95feeabb77149f Hugh Dickins            2018-11-30  1728  		xas_unlock_irq(&xas);
95feeabb77149f Hugh Dickins            2018-11-30 @1729  		if (!xas_nomem(&xas, GFP_KERNEL)) {
95feeabb77149f Hugh Dickins            2018-11-30  1730  			result = SCAN_FAIL;
95feeabb77149f Hugh Dickins            2018-11-30  1731  			goto out;
95feeabb77149f Hugh Dickins            2018-11-30  1732  		}
95feeabb77149f Hugh Dickins            2018-11-30  1733  	} while (1);
95feeabb77149f Hugh Dickins            2018-11-30  1734  
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1735  	__SetPageLocked(hpage);
99cb0dbd47a15d Song Liu                2019-09-23  1736  	if (is_shmem)
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1737  		__SetPageSwapBacked(hpage);
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1738  	hpage->index = start;
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1739  	hpage->mapping = mapping;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1740  
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1741  	/*
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1742  	 * At this point the hpage is locked and not up-to-date.
87c460a0bded56 Hugh Dickins            2018-11-30  1743  	 * It's safe to insert it into the page cache, because nobody would
87c460a0bded56 Hugh Dickins            2018-11-30  1744  	 * be able to map it or use it in another way until we unlock it.
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1745  	 */
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1746  
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1747  	xas_set(&xas, start);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1748  	for (index = start; index < end; index++) {
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1749  		struct page *page = xas_next(&xas);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1750  
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1751  		VM_BUG_ON(index != xas.xa_index);
99cb0dbd47a15d Song Liu                2019-09-23  1752  		if (is_shmem) {
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1753  			if (!page) {
701270fa193aad Hugh Dickins            2018-11-30  1754  				/*
99cb0dbd47a15d Song Liu                2019-09-23  1755  				 * Stop if extent has been truncated or
99cb0dbd47a15d Song Liu                2019-09-23  1756  				 * hole-punched, and is now completely
99cb0dbd47a15d Song Liu                2019-09-23  1757  				 * empty.
701270fa193aad Hugh Dickins            2018-11-30  1758  				 */
701270fa193aad Hugh Dickins            2018-11-30  1759  				if (index == start) {
701270fa193aad Hugh Dickins            2018-11-30  1760  					if (!xas_next_entry(&xas, end - 1)) {
701270fa193aad Hugh Dickins            2018-11-30  1761  						result = SCAN_TRUNCATED;
042a30824871fa Hugh Dickins            2018-11-30  1762  						goto xa_locked;
701270fa193aad Hugh Dickins            2018-11-30  1763  					}
701270fa193aad Hugh Dickins            2018-11-30  1764  					xas_set(&xas, index);
701270fa193aad Hugh Dickins            2018-11-30  1765  				}
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1766  				if (!shmem_charge(mapping->host, 1)) {
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1767  					result = SCAN_FAIL;
042a30824871fa Hugh Dickins            2018-11-30  1768  					goto xa_locked;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1769  				}
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1770  				xas_store(&xas, hpage);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1771  				nr_none++;
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1772  				continue;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1773  			}
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1774  
3159f943aafdba Matthew Wilcox          2017-11-03  1775  			if (xa_is_value(page) || !PageUptodate(page)) {
7459c149ae9ca7 Matthew Wilcox (Oracle  2022-09-02  1776) 				struct folio *folio;
7459c149ae9ca7 Matthew Wilcox (Oracle  2022-09-02  1777) 
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1778  				xas_unlock_irq(&xas);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1779  				/* swap in or instantiate fallocated page */
7459c149ae9ca7 Matthew Wilcox (Oracle  2022-09-02  1780) 				if (shmem_get_folio(mapping->host, index,
7459c149ae9ca7 Matthew Wilcox (Oracle  2022-09-02  1781) 						&folio, SGP_NOALLOC)) {
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1782  					result = SCAN_FAIL;
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1783  					goto xa_unlocked;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1784  				}
7459c149ae9ca7 Matthew Wilcox (Oracle  2022-09-02  1785) 				page = folio_file_page(folio, index);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1786  			} else if (trylock_page(page)) {
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1787  				get_page(page);
042a30824871fa Hugh Dickins            2018-11-30  1788  				xas_unlock_irq(&xas);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1789  			} else {
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1790  				result = SCAN_PAGE_LOCK;
042a30824871fa Hugh Dickins            2018-11-30  1791  				goto xa_locked;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1792  			}
99cb0dbd47a15d Song Liu                2019-09-23  1793  		} else {	/* !is_shmem */
99cb0dbd47a15d Song Liu                2019-09-23  1794  			if (!page || xa_is_value(page)) {
99cb0dbd47a15d Song Liu                2019-09-23  1795  				xas_unlock_irq(&xas);
99cb0dbd47a15d Song Liu                2019-09-23  1796  				page_cache_sync_readahead(mapping, &file->f_ra,
99cb0dbd47a15d Song Liu                2019-09-23  1797  							  file, index,
e5a59d308f52bb David Howells           2020-09-04  1798  							  end - index);
99cb0dbd47a15d Song Liu                2019-09-23  1799  				/* drain pagevecs to help isolate_lru_page() */
99cb0dbd47a15d Song Liu                2019-09-23  1800  				lru_add_drain();
99cb0dbd47a15d Song Liu                2019-09-23  1801  				page = find_lock_page(mapping, index);
99cb0dbd47a15d Song Liu                2019-09-23  1802  				if (unlikely(page == NULL)) {
99cb0dbd47a15d Song Liu                2019-09-23  1803  					result = SCAN_FAIL;
99cb0dbd47a15d Song Liu                2019-09-23  1804  					goto xa_unlocked;
99cb0dbd47a15d Song Liu                2019-09-23  1805  				}
75f360696ce9d8 Song Liu                2019-11-30  1806  			} else if (PageDirty(page)) {
75f360696ce9d8 Song Liu                2019-11-30  1807  				/*
75f360696ce9d8 Song Liu                2019-11-30  1808  				 * khugepaged only works on read-only fd,
75f360696ce9d8 Song Liu                2019-11-30  1809  				 * so this page is dirty because it hasn't
75f360696ce9d8 Song Liu                2019-11-30  1810  				 * been flushed since first write. There
75f360696ce9d8 Song Liu                2019-11-30  1811  				 * won't be new dirty pages.
75f360696ce9d8 Song Liu                2019-11-30  1812  				 *
75f360696ce9d8 Song Liu                2019-11-30  1813  				 * Trigger async flush here and hope the
75f360696ce9d8 Song Liu                2019-11-30  1814  				 * writeback is done when khugepaged
75f360696ce9d8 Song Liu                2019-11-30  1815  				 * revisits this page.
75f360696ce9d8 Song Liu                2019-11-30  1816  				 *
75f360696ce9d8 Song Liu                2019-11-30  1817  				 * This is a one-off situation. We are not
75f360696ce9d8 Song Liu                2019-11-30  1818  				 * forcing writeback in loop.
75f360696ce9d8 Song Liu                2019-11-30  1819  				 */
75f360696ce9d8 Song Liu                2019-11-30  1820  				xas_unlock_irq(&xas);
75f360696ce9d8 Song Liu                2019-11-30  1821  				filemap_flush(mapping);
75f360696ce9d8 Song Liu                2019-11-30  1822  				result = SCAN_FAIL;
75f360696ce9d8 Song Liu                2019-11-30  1823  				goto xa_unlocked;
74c42e1baacf20 Rongwei Wang            2021-10-28  1824  			} else if (PageWriteback(page)) {
74c42e1baacf20 Rongwei Wang            2021-10-28  1825  				xas_unlock_irq(&xas);
74c42e1baacf20 Rongwei Wang            2021-10-28  1826  				result = SCAN_FAIL;
74c42e1baacf20 Rongwei Wang            2021-10-28  1827  				goto xa_unlocked;
99cb0dbd47a15d Song Liu                2019-09-23  1828  			} else if (trylock_page(page)) {
99cb0dbd47a15d Song Liu                2019-09-23  1829  				get_page(page);
99cb0dbd47a15d Song Liu                2019-09-23  1830  				xas_unlock_irq(&xas);
99cb0dbd47a15d Song Liu                2019-09-23  1831  			} else {
99cb0dbd47a15d Song Liu                2019-09-23  1832  				result = SCAN_PAGE_LOCK;
99cb0dbd47a15d Song Liu                2019-09-23  1833  				goto xa_locked;
99cb0dbd47a15d Song Liu                2019-09-23  1834  			}
99cb0dbd47a15d Song Liu                2019-09-23  1835  		}
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1836  
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1837  		/*
b93b016313b3ba Matthew Wilcox          2018-04-10  1838  		 * The page must be locked, so we can drop the i_pages lock
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1839  		 * without racing with truncate.
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1840  		 */
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1841  		VM_BUG_ON_PAGE(!PageLocked(page), page);
4655e5e5f38726 Song Liu                2019-11-15  1842  
4655e5e5f38726 Song Liu                2019-11-15  1843  		/* make sure the page is up to date */
4655e5e5f38726 Song Liu                2019-11-15  1844  		if (unlikely(!PageUptodate(page))) {
4655e5e5f38726 Song Liu                2019-11-15  1845  			result = SCAN_FAIL;
4655e5e5f38726 Song Liu                2019-11-15  1846  			goto out_unlock;
4655e5e5f38726 Song Liu                2019-11-15  1847  		}
06a5e1268a5fb9 Hugh Dickins            2018-11-30  1848  
06a5e1268a5fb9 Hugh Dickins            2018-11-30  1849  		/*
06a5e1268a5fb9 Hugh Dickins            2018-11-30  1850  		 * If file was truncated then extended, or hole-punched, before
06a5e1268a5fb9 Hugh Dickins            2018-11-30  1851  		 * we locked the first page, then a THP might be there already.
58ac9a8993a13e Zach O'Keefe            2022-09-22  1852  		 * This will be discovered on the first iteration.
06a5e1268a5fb9 Hugh Dickins            2018-11-30  1853  		 */
06a5e1268a5fb9 Hugh Dickins            2018-11-30  1854  		if (PageTransCompound(page)) {
58ac9a8993a13e Zach O'Keefe            2022-09-22  1855  			struct page *head = compound_head(page);
58ac9a8993a13e Zach O'Keefe            2022-09-22  1856  
58ac9a8993a13e Zach O'Keefe            2022-09-22  1857  			result = compound_order(head) == HPAGE_PMD_ORDER &&
58ac9a8993a13e Zach O'Keefe            2022-09-22  1858  					head->index == start
58ac9a8993a13e Zach O'Keefe            2022-09-22  1859  					/* Maybe PMD-mapped */
58ac9a8993a13e Zach O'Keefe            2022-09-22  1860  					? SCAN_PTE_MAPPED_HUGEPAGE
58ac9a8993a13e Zach O'Keefe            2022-09-22  1861  					: SCAN_PAGE_COMPOUND;
06a5e1268a5fb9 Hugh Dickins            2018-11-30  1862  			goto out_unlock;
06a5e1268a5fb9 Hugh Dickins            2018-11-30  1863  		}
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1864  
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1865  		if (page_mapping(page) != mapping) {
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1866  			result = SCAN_TRUNCATED;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1867  			goto out_unlock;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1868  		}
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1869  
74c42e1baacf20 Rongwei Wang            2021-10-28  1870  		if (!is_shmem && (PageDirty(page) ||
74c42e1baacf20 Rongwei Wang            2021-10-28  1871  				  PageWriteback(page))) {
4655e5e5f38726 Song Liu                2019-11-15  1872  			/*
4655e5e5f38726 Song Liu                2019-11-15  1873  			 * khugepaged only works on read-only fd, so this
4655e5e5f38726 Song Liu                2019-11-15  1874  			 * page is dirty because it hasn't been flushed
4655e5e5f38726 Song Liu                2019-11-15  1875  			 * since first write.
4655e5e5f38726 Song Liu                2019-11-15  1876  			 */
4655e5e5f38726 Song Liu                2019-11-15  1877  			result = SCAN_FAIL;
4655e5e5f38726 Song Liu                2019-11-15  1878  			goto out_unlock;
4655e5e5f38726 Song Liu                2019-11-15  1879  		}
4655e5e5f38726 Song Liu                2019-11-15  1880  
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1881  		if (isolate_lru_page(page)) {
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1882  			result = SCAN_DEL_PAGE_LRU;
042a30824871fa Hugh Dickins            2018-11-30  1883  			goto out_unlock;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1884  		}
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1885  
99cb0dbd47a15d Song Liu                2019-09-23  1886  		if (page_has_private(page) &&
99cb0dbd47a15d Song Liu                2019-09-23  1887  		    !try_to_release_page(page, GFP_KERNEL)) {
99cb0dbd47a15d Song Liu                2019-09-23  1888  			result = SCAN_PAGE_HAS_PRIVATE;
2f33a706027c94 Hugh Dickins            2020-05-27  1889  			putback_lru_page(page);
99cb0dbd47a15d Song Liu                2019-09-23  1890  			goto out_unlock;
99cb0dbd47a15d Song Liu                2019-09-23  1891  		}
99cb0dbd47a15d Song Liu                2019-09-23  1892  
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1893  		if (page_mapped(page))
869f7ee6f64773 Matthew Wilcox (Oracle  2022-02-15  1894) 			try_to_unmap(page_folio(page),
869f7ee6f64773 Matthew Wilcox (Oracle  2022-02-15  1895) 					TTU_IGNORE_MLOCK | TTU_BATCH_FLUSH);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1896  
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1897  		xas_lock_irq(&xas);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1898  		xas_set(&xas, index);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1899  
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1900  		VM_BUG_ON_PAGE(page != xas_load(&xas), page);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1901  
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1902  		/*
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1903  		 * The page is expected to have page_count() == 3:
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1904  		 *  - we hold a pin on it;
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1905  		 *  - one reference from page cache;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1906  		 *  - one from isolate_lru_page;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1907  		 */
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1908  		if (!page_ref_freeze(page, 3)) {
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1909  			result = SCAN_PAGE_COUNT;
042a30824871fa Hugh Dickins            2018-11-30  1910  			xas_unlock_irq(&xas);
042a30824871fa Hugh Dickins            2018-11-30  1911  			putback_lru_page(page);
042a30824871fa Hugh Dickins            2018-11-30  1912  			goto out_unlock;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1913  		}
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1914  
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1915  		/*
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1916  		 * Add the page to the list to be able to undo the collapse if
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1917  		 * something go wrong.
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1918  		 */
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1919  		list_add_tail(&page->lru, &pagelist);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1920  
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1921  		/* Finally, replace with the new page. */
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1922  		xas_store(&xas, hpage);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1923  		continue;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1924  out_unlock:
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1925  		unlock_page(page);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1926  		put_page(page);
042a30824871fa Hugh Dickins            2018-11-30  1927  		goto xa_unlocked;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1928  	}
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1929  	nr = thp_nr_pages(hpage);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1930  
99cb0dbd47a15d Song Liu                2019-09-23  1931  	if (is_shmem)
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1932  		__mod_lruvec_page_state(hpage, NR_SHMEM_THPS, nr);
09d91cda0e8207 Song Liu                2019-09-23  1933  	else {
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1934  		__mod_lruvec_page_state(hpage, NR_FILE_THPS, nr);
09d91cda0e8207 Song Liu                2019-09-23  1935  		filemap_nr_thps_inc(mapping);
eb6ecbed0aa273 Collin Fijalkovich      2021-06-30  1936  		/*
eb6ecbed0aa273 Collin Fijalkovich      2021-06-30  1937  		 * Paired with smp_mb() in do_dentry_open() to ensure
eb6ecbed0aa273 Collin Fijalkovich      2021-06-30  1938  		 * i_writecount is up to date and the update to nr_thps is
eb6ecbed0aa273 Collin Fijalkovich      2021-06-30  1939  		 * visible. Ensures the page cache will be truncated if the
eb6ecbed0aa273 Collin Fijalkovich      2021-06-30  1940  		 * file is opened writable.
eb6ecbed0aa273 Collin Fijalkovich      2021-06-30  1941  		 */
eb6ecbed0aa273 Collin Fijalkovich      2021-06-30  1942  		smp_mb();
eb6ecbed0aa273 Collin Fijalkovich      2021-06-30  1943  		if (inode_is_open_for_write(mapping->host)) {
eb6ecbed0aa273 Collin Fijalkovich      2021-06-30  1944  			result = SCAN_FAIL;
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1945  			__mod_lruvec_page_state(hpage, NR_FILE_THPS, -nr);
eb6ecbed0aa273 Collin Fijalkovich      2021-06-30  1946  			filemap_nr_thps_dec(mapping);
eb6ecbed0aa273 Collin Fijalkovich      2021-06-30  1947  			goto xa_locked;
eb6ecbed0aa273 Collin Fijalkovich      2021-06-30  1948  		}
09d91cda0e8207 Song Liu                2019-09-23  1949  	}
99cb0dbd47a15d Song Liu                2019-09-23  1950  
042a30824871fa Hugh Dickins            2018-11-30  1951  	if (nr_none) {
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1952  		__mod_lruvec_page_state(hpage, NR_FILE_PAGES, nr_none);
2f55f070e5b80f Miaohe Lin              2022-06-25  1953  		/* nr_none is always 0 for non-shmem. */
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1954  		__mod_lruvec_page_state(hpage, NR_SHMEM, nr_none);
042a30824871fa Hugh Dickins            2018-11-30  1955  	}
042a30824871fa Hugh Dickins            2018-11-30  1956  
6b24ca4a1a8d4e Matthew Wilcox (Oracle  2020-06-27  1957) 	/* Join all the small entries into a single multi-index entry */
6b24ca4a1a8d4e Matthew Wilcox (Oracle  2020-06-27  1958) 	xas_set_order(&xas, start, HPAGE_PMD_ORDER);
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1959  	xas_store(&xas, hpage);
042a30824871fa Hugh Dickins            2018-11-30  1960  xa_locked:
042a30824871fa Hugh Dickins            2018-11-30  1961  	xas_unlock_irq(&xas);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1962  xa_unlocked:
042a30824871fa Hugh Dickins            2018-11-30  1963  
6d9df8a5889c56 Hugh Dickins            2022-02-14  1964  	/*
6d9df8a5889c56 Hugh Dickins            2022-02-14  1965  	 * If collapse is successful, flush must be done now before copying.
6d9df8a5889c56 Hugh Dickins            2022-02-14  1966  	 * If collapse is unsuccessful, does flush actually need to be done?
6d9df8a5889c56 Hugh Dickins            2022-02-14  1967  	 * Do it anyway, to clear the state.
6d9df8a5889c56 Hugh Dickins            2022-02-14  1968  	 */
6d9df8a5889c56 Hugh Dickins            2022-02-14  1969  	try_to_unmap_flush();
6d9df8a5889c56 Hugh Dickins            2022-02-14  1970  
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1971  	if (result == SCAN_SUCCEED) {
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1972  		struct page *page, *tmp;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1973  
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1974  		/*
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1975  		 * Replacing old pages with new one has succeeded, now we
77da9389b9d5f0 Matthew Wilcox          2017-12-04  1976  		 * need to copy the content and free the old pages.
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1977  		 */
2af8ff291848cc Hugh Dickins            2018-11-30  1978  		index = start;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1979  		list_for_each_entry_safe(page, tmp, &pagelist, lru) {
2af8ff291848cc Hugh Dickins            2018-11-30  1980  			while (index < page->index) {
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1981  				clear_highpage(hpage + (index % HPAGE_PMD_NR));
2af8ff291848cc Hugh Dickins            2018-11-30  1982  				index++;
2af8ff291848cc Hugh Dickins            2018-11-30  1983  			}
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1984  			copy_highpage(hpage + (page->index % HPAGE_PMD_NR),
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1985  				      page);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1986  			list_del(&page->lru);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1987  			page->mapping = NULL;
042a30824871fa Hugh Dickins            2018-11-30  1988  			page_ref_unfreeze(page, 1);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1989  			ClearPageActive(page);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1990  			ClearPageUnevictable(page);
042a30824871fa Hugh Dickins            2018-11-30  1991  			unlock_page(page);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1992  			put_page(page);
2af8ff291848cc Hugh Dickins            2018-11-30  1993  			index++;
2af8ff291848cc Hugh Dickins            2018-11-30  1994  		}
2af8ff291848cc Hugh Dickins            2018-11-30  1995  		while (index < end) {
50ad2f24b3b48c Zach O'Keefe            2022-07-06  1996  			clear_highpage(hpage + (index % HPAGE_PMD_NR));
2af8ff291848cc Hugh Dickins            2018-11-30  1997  			index++;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1998  		}
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  1999  
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2000  		SetPageUptodate(hpage);
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2001  		page_ref_add(hpage, HPAGE_PMD_NR - 1);
6058eaec816f29 Johannes Weiner         2020-06-03  2002  		if (is_shmem)
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2003  			set_page_dirty(hpage);
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2004  		lru_cache_add(hpage);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2005  
042a30824871fa Hugh Dickins            2018-11-30  2006  		/*
042a30824871fa Hugh Dickins            2018-11-30  2007  		 * Remove pte page tables, so we can re-fault the page as huge.
042a30824871fa Hugh Dickins            2018-11-30  2008  		 */
34488399fa08fa Zach O'Keefe            2022-09-22  2009  		result = retract_page_tables(mapping, start, mm, addr, hpage,
34488399fa08fa Zach O'Keefe            2022-09-22  2010  					     cc);
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2011  		unlock_page(hpage);
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2012  		hpage = NULL;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2013  	} else {
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2014  		struct page *page;
aaa52e340073b7 Hugh Dickins            2018-11-30  2015  
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2016  		/* Something went wrong: roll back page cache changes */
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2017  		xas_lock_irq(&xas);
2f55f070e5b80f Miaohe Lin              2022-06-25  2018  		if (nr_none) {
aaa52e340073b7 Hugh Dickins            2018-11-30  2019  			mapping->nrpages -= nr_none;
aaa52e340073b7 Hugh Dickins            2018-11-30  2020  			shmem_uncharge(mapping->host, nr_none);
2f55f070e5b80f Miaohe Lin              2022-06-25  2021  		}
aaa52e340073b7 Hugh Dickins            2018-11-30  2022  
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2023  		xas_set(&xas, start);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2024  		xas_for_each(&xas, page, end - 1) {
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2025  			page = list_first_entry_or_null(&pagelist,
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2026  					struct page, lru);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2027  			if (!page || xas.xa_index < page->index) {
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2028  				if (!nr_none)
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2029  					break;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2030  				nr_none--;
59749e6ce53735 Johannes Weiner         2016-12-12  2031  				/* Put holes back where they were */
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2032  				xas_store(&xas, NULL);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2033  				continue;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2034  			}
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2035  
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2036  			VM_BUG_ON_PAGE(page->index != xas.xa_index, page);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2037  
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2038  			/* Unfreeze the page. */
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2039  			list_del(&page->lru);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2040  			page_ref_unfreeze(page, 2);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2041  			xas_store(&xas, page);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2042  			xas_pause(&xas);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2043  			xas_unlock_irq(&xas);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2044  			unlock_page(page);
042a30824871fa Hugh Dickins            2018-11-30  2045  			putback_lru_page(page);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2046  			xas_lock_irq(&xas);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2047  		}
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2048  		VM_BUG_ON(nr_none);
77da9389b9d5f0 Matthew Wilcox          2017-12-04  2049  		xas_unlock_irq(&xas);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2050  
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2051  		hpage->mapping = NULL;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2052  	}
042a30824871fa Hugh Dickins            2018-11-30  2053  
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2054  	if (hpage)
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2055  		unlock_page(hpage);
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2056  out:
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2057  	VM_BUG_ON(!list_empty(&pagelist));
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2058  	if (hpage) {
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2059  		mem_cgroup_uncharge(page_folio(hpage));
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2060  		put_page(hpage);
c6a7f445a2727a Yang Shi                2022-07-06  2061  	}
eae5270d3322f7 Gautam Menghani         2022-10-24  2062  
eae5270d3322f7 Gautam Menghani         2022-10-24  2063  	trace_mm_khugepaged_collapse_file(mm, hpage, index, is_shmem,
eae5270d3322f7 Gautam Menghani         2022-10-24  2064  		addr, file, nr, result);
50ad2f24b3b48c Zach O'Keefe            2022-07-06  2065  	return result;
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2066  }
f3f0e1d2150b2b Kirill A. Shutemov      2016-07-26  2067  

:::::: The code at line 1729 was first introduced by commit
:::::: 95feeabb77149f7d48f05bde61d75621c57db67e mm/khugepaged: fix the xas_create_range() error path

:::::: TO: Hugh Dickins <hughd@google.com>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 15424 bytes --]

             reply	other threads:[~2022-10-25 11:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 11:01 kernel test robot [this message]
2022-10-26  1:44 ` [linux-next:master 3067/3190] mm/khugepaged.c:1729:7: warning: variable 'index' is used uninitialized whenever 'if' condition is true Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202210251946.eT92YAhG-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=gautammenghani201@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=llvm@lists.linux.dev \
    --cc=oe-kbuild-all@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).