All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v2 3/3] userfaultfd: convert __mcopy_atomic() to use a folio
@ 2023-03-15 10:50 kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2023-03-15 10:50 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20230314131350.924377-4-zhangpeng362@huawei.com>
References: <20230314131350.924377-4-zhangpeng362@huawei.com>
TO: Peng Zhang <zhangpeng362@huawei.com>
TO: linux-mm@kvack.org
TO: linux-kernel@vger.kernel.org
TO: willy@infradead.org
CC: akpm@linux-foundation.org
CC: mike.kravetz@oracle.com
CC: vishal.moola@gmail.com
CC: sidhartha.kumar@oracle.com
CC: wangkefeng.wang@huawei.com
CC: sunnanyong@huawei.com
CC: ZhangPeng <zhangpeng362@huawei.com>

Hi Peng,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.3-rc2 next-20230315]
[cannot apply to akpm-mm/mm-everything]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Peng-Zhang/userfaultfd-convert-mcopy_atomic_pte-to-use-a-folio/20230314-211824
patch link:    https://lore.kernel.org/r/20230314131350.924377-4-zhangpeng362%40huawei.com
patch subject: [PATCH v2 3/3] userfaultfd: convert __mcopy_atomic() to use a folio
:::::: branch date: 21 hours ago
:::::: commit date: 21 hours ago
config: microblaze-randconfig-m041-20230312 (https://download.01.org/0day-ci/archive/20230315/202303151800.E99FNcRY-lkp@intel.com/config)
compiler: microblaze-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Link: https://lore.kernel.org/r/202303151800.E99FNcRY-lkp@intel.com/

New smatch warnings:
mm/shmem.c:2492 shmem_mfill_atomic_pte() error: uninitialized symbol 'folio'.
mm/userfaultfd.c:181 mcopy_atomic_pte() error: uninitialized symbol 'folio'.

Old smatch warnings:
arch/microblaze/include/asm/thread_info.h:85 current_thread_info() error: uninitialized symbol 'sp'.
include/linux/userfaultfd_k.h:149 vma_can_userfault() warn: bitwise AND condition is false here

vim +/folio +2492 mm/shmem.c

^1da177e4c3f41 Linus Torvalds          2005-04-16  2416  
3460f6e5c1ed94 Axel Rasmussen          2021-06-30  2417  #ifdef CONFIG_USERFAULTFD
3460f6e5c1ed94 Axel Rasmussen          2021-06-30  2418  int shmem_mfill_atomic_pte(struct mm_struct *dst_mm,
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2419  			   pmd_t *dst_pmd,
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2420  			   struct vm_area_struct *dst_vma,
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2421  			   unsigned long dst_addr,
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2422  			   unsigned long src_addr,
8ee79edff6d3b4 Peter Xu                2022-05-12  2423  			   bool zeropage, bool wp_copy,
732542eb883709 ZhangPeng               2023-03-14  2424  			   struct folio **foliop)
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2425  {
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2426  	struct inode *inode = file_inode(dst_vma->vm_file);
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2427  	struct shmem_inode_info *info = SHMEM_I(inode);
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2428  	struct address_space *mapping = inode->i_mapping;
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2429  	gfp_t gfp = mapping_gfp_mask(mapping);
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2430  	pgoff_t pgoff = linear_page_index(dst_vma, dst_addr);
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2431  	void *page_kaddr;
b7dd44a12cf266 Matthew Wilcox (Oracle  2022-05-12  2432) 	struct folio *folio;
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2433  	int ret;
3460f6e5c1ed94 Axel Rasmussen          2021-06-30  2434  	pgoff_t max_off;
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2435  
7ed9d238c7dbb1 Axel Rasmussen          2021-05-14  2436  	if (!shmem_inode_acct_block(inode, 1)) {
7ed9d238c7dbb1 Axel Rasmussen          2021-05-14  2437  		/*
7ed9d238c7dbb1 Axel Rasmussen          2021-05-14  2438  		 * We may have got a page, returned -ENOENT triggering a retry,
7ed9d238c7dbb1 Axel Rasmussen          2021-05-14  2439  		 * and now we find ourselves with -ENOMEM. Release the page, to
7ed9d238c7dbb1 Axel Rasmussen          2021-05-14  2440  		 * avoid a BUG_ON in our caller.
7ed9d238c7dbb1 Axel Rasmussen          2021-05-14  2441  		 */
732542eb883709 ZhangPeng               2023-03-14  2442  		if (unlikely(*foliop)) {
732542eb883709 ZhangPeng               2023-03-14  2443  			folio_put(*foliop);
732542eb883709 ZhangPeng               2023-03-14  2444  			*foliop = NULL;
7ed9d238c7dbb1 Axel Rasmussen          2021-05-14  2445  		}
7d64ae3ab648a9 Axel Rasmussen          2021-06-30  2446  		return -ENOMEM;
7ed9d238c7dbb1 Axel Rasmussen          2021-05-14  2447  	}
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2448  
732542eb883709 ZhangPeng               2023-03-14  2449  	if (!*foliop) {
7d64ae3ab648a9 Axel Rasmussen          2021-06-30  2450  		ret = -ENOMEM;
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2451) 		folio = shmem_alloc_folio(gfp, info, pgoff);
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2452) 		if (!folio)
0f0796945614b7 Mike Rapoport           2017-09-06  2453  			goto out_unacct_blocks;
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2454  
3460f6e5c1ed94 Axel Rasmussen          2021-06-30  2455  		if (!zeropage) {	/* COPY */
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2456) 			page_kaddr = kmap_local_folio(folio, 0);
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2457  			/*
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2458  			 * The read mmap_lock is held here.  Despite the
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2459  			 * mmap_lock being read recursive a deadlock is still
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2460  			 * possible if a writer has taken a lock.  For example:
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2461  			 *
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2462  			 * process A thread 1 takes read lock on own mmap_lock
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2463  			 * process A thread 2 calls mmap, blocks taking write lock
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2464  			 * process B thread 1 takes page fault, read lock on own mmap lock
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2465  			 * process B thread 2 calls mmap, blocks taking write lock
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2466  			 * process A thread 1 blocks taking read lock on process B
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2467  			 * process B thread 1 blocks taking read lock on process A
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2468  			 *
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2469  			 * Disable page faults to prevent potential deadlock
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2470  			 * and retry the copy outside the mmap_lock.
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2471  			 */
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2472  			pagefault_disable();
8d10396342063c Mike Rapoport           2017-09-06  2473  			ret = copy_from_user(page_kaddr,
8d10396342063c Mike Rapoport           2017-09-06  2474  					     (const void __user *)src_addr,
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2475  					     PAGE_SIZE);
5dc21f0c0b1c02 Ira Weiny               2022-10-25  2476  			pagefault_enable();
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2477) 			kunmap_local(page_kaddr);
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2478  
c1e8d7c6a7a682 Michel Lespinasse       2020-06-08  2479  			/* fallback to copy_from_user outside mmap_lock */
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2480  			if (unlikely(ret)) {
732542eb883709 ZhangPeng               2023-03-14  2481  				*foliop = folio;
7d64ae3ab648a9 Axel Rasmussen          2021-06-30  2482  				ret = -ENOENT;
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2483  				/* don't free the page */
7d64ae3ab648a9 Axel Rasmussen          2021-06-30  2484  				goto out_unacct_blocks;
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2485  			}
19b482c29b6f38 Muchun Song             2022-03-22  2486  
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2487) 			flush_dcache_folio(folio);
3460f6e5c1ed94 Axel Rasmussen          2021-06-30  2488  		} else {		/* ZEROPAGE */
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2489) 			clear_user_highpage(&folio->page, dst_addr);
8d10396342063c Mike Rapoport           2017-09-06  2490  		}
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2491  	} else {
732542eb883709 ZhangPeng               2023-03-14 @2492  		VM_BUG_ON_FOLIO(folio_test_large(*foliop), folio);
732542eb883709 ZhangPeng               2023-03-14  2493  		*foliop = NULL;
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2494  	}
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2495  
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2496) 	VM_BUG_ON(folio_test_locked(folio));
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2497) 	VM_BUG_ON(folio_test_swapbacked(folio));
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2498) 	__folio_set_locked(folio);
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2499) 	__folio_set_swapbacked(folio);
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2500) 	__folio_mark_uptodate(folio);
9cc90c664a65f9 Andrea Arcangeli        2017-02-22  2501  
e2a50c1f64145a Andrea Arcangeli        2018-11-30  2502  	ret = -EFAULT;
e2a50c1f64145a Andrea Arcangeli        2018-11-30  2503  	max_off = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
3460f6e5c1ed94 Axel Rasmussen          2021-06-30  2504  	if (unlikely(pgoff >= max_off))
e2a50c1f64145a Andrea Arcangeli        2018-11-30  2505  		goto out_release;
e2a50c1f64145a Andrea Arcangeli        2018-11-30  2506  
b7dd44a12cf266 Matthew Wilcox (Oracle  2022-05-12  2507) 	ret = shmem_add_to_page_cache(folio, mapping, pgoff, NULL,
3fea5a499d57de Johannes Weiner         2020-06-03  2508  				      gfp & GFP_RECLAIM_MASK, dst_mm);
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2509  	if (ret)
3fea5a499d57de Johannes Weiner         2020-06-03  2510  		goto out_release;
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2511  
7d64ae3ab648a9 Axel Rasmussen          2021-06-30  2512  	ret = mfill_atomic_install_pte(dst_mm, dst_pmd, dst_vma, dst_addr,
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2513) 				       &folio->page, true, wp_copy);
7d64ae3ab648a9 Axel Rasmussen          2021-06-30  2514  	if (ret)
7d64ae3ab648a9 Axel Rasmussen          2021-06-30  2515  		goto out_delete_from_cache;
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2516  
94b7cc01da5a3c Yang Shi                2020-04-20  2517  	spin_lock_irq(&info->lock);
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2518  	info->alloced++;
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2519  	inode->i_blocks += BLOCKS_PER_PAGE;
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2520  	shmem_recalc_inode(inode);
94b7cc01da5a3c Yang Shi                2020-04-20  2521  	spin_unlock_irq(&info->lock);
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2522  
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2523) 	folio_unlock(folio);
7d64ae3ab648a9 Axel Rasmussen          2021-06-30  2524  	return 0;
7d64ae3ab648a9 Axel Rasmussen          2021-06-30  2525  out_delete_from_cache:
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2526) 	filemap_remove_folio(folio);
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2527  out_release:
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2528) 	folio_unlock(folio);
7a7256d5f512b6 Matthew Wilcox (Oracle  2022-09-02  2529) 	folio_put(folio);
4c27fe4c4c84f3 Mike Rapoport           2017-02-22  2530  out_unacct_blocks:
0f0796945614b7 Mike Rapoport           2017-09-06  2531  	shmem_inode_unacct_blocks(inode, 1);
7d64ae3ab648a9 Axel Rasmussen          2021-06-30  2532  	return ret;
8d10396342063c Mike Rapoport           2017-09-06  2533  }
3460f6e5c1ed94 Axel Rasmussen          2021-06-30  2534  #endif /* CONFIG_USERFAULTFD */
8d10396342063c Mike Rapoport           2017-09-06  2535  

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

^ permalink raw reply	[flat|nested] 2+ messages in thread
* [PATCH v2 0/3] userfaultfd: convert userfaultfd functions to use folios
@ 2023-03-14 13:13 Peng Zhang
  2023-03-14 13:13 ` [PATCH v2 3/3] userfaultfd: convert __mcopy_atomic() to use a folio Peng Zhang
  0 siblings, 1 reply; 2+ messages in thread
From: Peng Zhang @ 2023-03-14 13:13 UTC (permalink / raw)
  To: linux-mm, linux-kernel, willy
  Cc: akpm, mike.kravetz, vishal.moola, sidhartha.kumar,
	wangkefeng.wang, sunnanyong, ZhangPeng

From: ZhangPeng <zhangpeng362@huawei.com>

This patch series converts several userfaultfd functions to use folios.
And this series pass the userfaultfd selftests and the LTP userfaultfd
test cases.

Change log:

v1->v2:
In patch 2:
- Rename copy_large_folio_from_user() to copy_folio_from_user().
- Delete the inner_folio.
- kmap() and kmap_atomic() are converted to kmap_local_page(). Use
  pagefault_disable() to ensure that a deadlock will not occur.
- flush_dcache_folio() is placed outside the loop.

ZhangPeng (3):
  userfaultfd: convert mcopy_atomic_pte() to use a folio
  userfaultfd: convert __mcopy_atomic_hugetlb() to use a folio
  userfaultfd: convert __mcopy_atomic() to use a folio

 include/linux/hugetlb.h  |  4 +--
 include/linux/mm.h       |  3 +-
 include/linux/shmem_fs.h |  2 +-
 mm/hugetlb.c             | 25 +++++++-------
 mm/memory.c              | 27 +++++++--------
 mm/shmem.c               | 17 +++++----
 mm/userfaultfd.c         | 74 +++++++++++++++++++---------------------
 7 files changed, 72 insertions(+), 80 deletions(-)

-- 
2.25.1



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

end of thread, other threads:[~2023-03-15 10:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-15 10:50 [PATCH v2 3/3] userfaultfd: convert __mcopy_atomic() to use a folio kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2023-03-14 13:13 [PATCH v2 0/3] userfaultfd: convert userfaultfd functions to use folios Peng Zhang
2023-03-14 13:13 ` [PATCH v2 3/3] userfaultfd: convert __mcopy_atomic() to use a folio Peng Zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.