All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v7 5/6] udmabuf: Pin the pages using memfd_pin_folios() API (v5)
@ 2023-12-12 23:00 kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2023-12-12 23:00 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20231212073803.3233055-6-vivek.kasireddy@intel.com>
References: <20231212073803.3233055-6-vivek.kasireddy@intel.com>
TO: Vivek Kasireddy <vivek.kasireddy@intel.com>
TO: dri-devel@lists.freedesktop.org
TO: linux-mm@kvack.org
CC: Dongwon Kim <dongwon.kim@intel.com>
CC: David Hildenbrand <david@redhat.com>
CC: Daniel Vetter <daniel.vetter@ffwll.ch>
CC: Hugh Dickins <hughd@google.com>
CC: Vivek Kasireddy <vivek.kasireddy@intel.com>
CC: Peter Xu <peterx@redhat.com>
CC: Gerd Hoffmann <kraxel@redhat.com>
CC: Jason Gunthorpe <jgg@nvidia.com>
CC: Junxiao Chang <junxiao.chang@intel.com>
CC: Mike Kravetz <mike.kravetz@oracle.com>

Hi Vivek,

kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]

url:    https://github.com/intel-lab-lkp/linux/commits/Vivek-Kasireddy/udmabuf-Use-vmf_insert_pfn-and-VM_PFNMAP-for-handling-mmap/20231212-160312
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20231212073803.3233055-6-vivek.kasireddy%40intel.com
patch subject: [PATCH v7 5/6] udmabuf: Pin the pages using memfd_pin_folios() API (v5)
:::::: branch date: 15 hours ago
:::::: commit date: 15 hours ago
config: x86_64-randconfig-161-20231213 (https://download.01.org/0day-ci/archive/20231213/202312130653.GAeUPHvx-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce: (https://download.01.org/0day-ci/archive/20231213/202312130653.GAeUPHvx-lkp@intel.com/reproduce)

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 <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202312130653.GAeUPHvx-lkp@intel.com/

smatch warnings:
drivers/dma-buf/udmabuf.c:331 udmabuf_create() error: we previously assumed 'ubuf->folios' could be null (see line 293)

vim +331 drivers/dma-buf/udmabuf.c

5b8ec1d16b07c1e Vivek Kasireddy     2023-12-11  262  
c1bbed668997268 Gurchetan Singh     2019-12-02  263  static long udmabuf_create(struct miscdevice *device,
c1bbed668997268 Gurchetan Singh     2019-12-02  264  			   struct udmabuf_create_list *head,
c1bbed668997268 Gurchetan Singh     2019-12-02  265  			   struct udmabuf_create_item *list)
fbb0de795078190 Gerd Hoffmann       2018-08-27  266  {
5b8ec1d16b07c1e Vivek Kasireddy     2023-12-11  267  	pgoff_t pgcnt, pgbuf = 0, pglimit;
fbb0de795078190 Gerd Hoffmann       2018-08-27  268  	struct file *memfd = NULL;
fbb0de795078190 Gerd Hoffmann       2018-08-27  269  	struct udmabuf *ubuf;
57a12569fe6e85c Vivek Kasireddy     2023-12-11  270  	long ret = -EINVAL;
fbb0de795078190 Gerd Hoffmann       2018-08-27  271  	u32 i, flags;
fbb0de795078190 Gerd Hoffmann       2018-08-27  272  
33f35429fc49c09 Gerd Hoffmann       2018-09-11  273  	ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL);
fbb0de795078190 Gerd Hoffmann       2018-08-27  274  	if (!ubuf)
fbb0de795078190 Gerd Hoffmann       2018-08-27  275  		return -ENOMEM;
fbb0de795078190 Gerd Hoffmann       2018-08-27  276  
dc4716d75154b36 Gerd Hoffmann       2018-09-11  277  	pglimit = (size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
fbb0de795078190 Gerd Hoffmann       2018-08-27  278  	for (i = 0; i < head->count; i++) {
fbb0de795078190 Gerd Hoffmann       2018-08-27  279  		if (!IS_ALIGNED(list[i].offset, PAGE_SIZE))
0d17455ca85ecbc Gerd Hoffmann       2018-09-11  280  			goto err;
fbb0de795078190 Gerd Hoffmann       2018-08-27  281  		if (!IS_ALIGNED(list[i].size, PAGE_SIZE))
0d17455ca85ecbc Gerd Hoffmann       2018-09-11  282  			goto err;
fbb0de795078190 Gerd Hoffmann       2018-08-27  283  		ubuf->pagecount += list[i].size >> PAGE_SHIFT;
dc4716d75154b36 Gerd Hoffmann       2018-09-11  284  		if (ubuf->pagecount > pglimit)
0d17455ca85ecbc Gerd Hoffmann       2018-09-11  285  			goto err;
fbb0de795078190 Gerd Hoffmann       2018-08-27  286  	}
2b6dd600dd72573 Pavel Skripkin      2021-12-30  287  
2b6dd600dd72573 Pavel Skripkin      2021-12-30  288  	if (!ubuf->pagecount)
2b6dd600dd72573 Pavel Skripkin      2021-12-30  289  		goto err;
2b6dd600dd72573 Pavel Skripkin      2021-12-30  290  
5b8ec1d16b07c1e Vivek Kasireddy     2023-12-11  291  	ubuf->folios = kmalloc_array(ubuf->pagecount, sizeof(*ubuf->folios),
fbb0de795078190 Gerd Hoffmann       2018-08-27  292  				    GFP_KERNEL);
5b8ec1d16b07c1e Vivek Kasireddy     2023-12-11 @293  	if (!ubuf->folios) {
fbb0de795078190 Gerd Hoffmann       2018-08-27  294  		ret = -ENOMEM;
0d17455ca85ecbc Gerd Hoffmann       2018-09-11  295  		goto err;
fbb0de795078190 Gerd Hoffmann       2018-08-27  296  	}
cb2b9e0d8e97af6 Vivek Kasireddy     2023-12-11  297  	ubuf->offsets = kcalloc(ubuf->pagecount, sizeof(*ubuf->offsets),
cb2b9e0d8e97af6 Vivek Kasireddy     2023-12-11  298  				GFP_KERNEL);
cb2b9e0d8e97af6 Vivek Kasireddy     2023-12-11  299  	if (!ubuf->offsets) {
cb2b9e0d8e97af6 Vivek Kasireddy     2023-12-11  300  		ret = -ENOMEM;
cb2b9e0d8e97af6 Vivek Kasireddy     2023-12-11  301  		goto err;
cb2b9e0d8e97af6 Vivek Kasireddy     2023-12-11  302  	}
fbb0de795078190 Gerd Hoffmann       2018-08-27  303  
fbb0de795078190 Gerd Hoffmann       2018-08-27  304  	pgbuf = 0;
fbb0de795078190 Gerd Hoffmann       2018-08-27  305  	for (i = 0; i < head->count; i++) {
fbb0de795078190 Gerd Hoffmann       2018-08-27  306  		memfd = fget(list[i].memfd);
5b8ec1d16b07c1e Vivek Kasireddy     2023-12-11  307  		if (check_memfd_seals(memfd) < 0)
0d17455ca85ecbc Gerd Hoffmann       2018-09-11  308  			goto err;
cb2b9e0d8e97af6 Vivek Kasireddy     2023-12-11  309  
fbb0de795078190 Gerd Hoffmann       2018-08-27  310  		pgcnt = list[i].size >> PAGE_SHIFT;
57a12569fe6e85c Vivek Kasireddy     2023-12-11  311  		ret = memfd_pin_folios(memfd, list[i].offset, pgcnt,
57a12569fe6e85c Vivek Kasireddy     2023-12-11  312  				       ubuf->folios + pgbuf,
57a12569fe6e85c Vivek Kasireddy     2023-12-11  313  				       ubuf->offsets + pgbuf);
cb2b9e0d8e97af6 Vivek Kasireddy     2023-12-11  314  		if (ret < 0)
0d17455ca85ecbc Gerd Hoffmann       2018-09-11  315  			goto err;
cb2b9e0d8e97af6 Vivek Kasireddy     2023-12-11  316  
57a12569fe6e85c Vivek Kasireddy     2023-12-11  317  		pgbuf += pgcnt;
fbb0de795078190 Gerd Hoffmann       2018-08-27  318  		fput(memfd);
fbb0de795078190 Gerd Hoffmann       2018-08-27  319  		memfd = NULL;
0d17455ca85ecbc Gerd Hoffmann       2018-09-11  320  	}
fbb0de795078190 Gerd Hoffmann       2018-08-27  321  
5b8ec1d16b07c1e Vivek Kasireddy     2023-12-11  322  	flags = head->flags & UDMABUF_FLAGS_CLOEXEC ? O_CLOEXEC : 0;
5b8ec1d16b07c1e Vivek Kasireddy     2023-12-11  323  	ret = export_udmabuf(ubuf, device, flags);
5b8ec1d16b07c1e Vivek Kasireddy     2023-12-11  324  	if (ret < 0)
0d17455ca85ecbc Gerd Hoffmann       2018-09-11  325  		goto err;
fbb0de795078190 Gerd Hoffmann       2018-08-27  326  
5b8ec1d16b07c1e Vivek Kasireddy     2023-12-11  327  	return ret;
fbb0de795078190 Gerd Hoffmann       2018-08-27  328  
0d17455ca85ecbc Gerd Hoffmann       2018-09-11  329  err:
57a12569fe6e85c Vivek Kasireddy     2023-12-11  330  	while (pgbuf-- > 0)
57a12569fe6e85c Vivek Kasireddy     2023-12-11 @331  		if (ubuf->folios[pgbuf])
57a12569fe6e85c Vivek Kasireddy     2023-12-11  332  			unpin_user_page(folio_page(ubuf->folios[pgbuf], 0));
683a0e630cb463d Gustavo A. R. Silva 2018-09-04  333  	if (memfd)
fbb0de795078190 Gerd Hoffmann       2018-08-27  334  		fput(memfd);
cb2b9e0d8e97af6 Vivek Kasireddy     2023-12-11  335  	kfree(ubuf->offsets);
5b8ec1d16b07c1e Vivek Kasireddy     2023-12-11  336  	kfree(ubuf->folios);
fbb0de795078190 Gerd Hoffmann       2018-08-27  337  	kfree(ubuf);
fbb0de795078190 Gerd Hoffmann       2018-08-27  338  	return ret;
fbb0de795078190 Gerd Hoffmann       2018-08-27  339  }
fbb0de795078190 Gerd Hoffmann       2018-08-27  340  

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

^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH v7 0/6] mm/gup: Introduce memfd_pin_folios() for pinning memfd folios (v7)
@ 2023-12-12  7:37 Vivek Kasireddy
  2023-12-12  7:38   ` Vivek Kasireddy
  0 siblings, 1 reply; 5+ messages in thread
From: Vivek Kasireddy @ 2023-12-12  7:37 UTC (permalink / raw)
  To: dri-devel, linux-mm
  Cc: Dongwon Kim, David Hildenbrand, Daniel Vetter, Hugh Dickins,
	Vivek Kasireddy, Peter Xu, Christoph Hellwig, Gerd Hoffmann,
	Jason Gunthorpe, Junxiao Chang, Mike Kravetz

The first two patches were previously reviewed but not yet merged.
These ones need to be merged first as the fourth patch depends on
the changes introduced in them and they also fix bugs seen in
very specific scenarios (running Qemu with hugetlb=on, blob=true
and rebooting guest VM).

The third patch introduces memfd_pin_folios() API and the fourth
patch converts udmabuf driver to use folios. The fifth patch shows
how the udmabuf driver can make use of the new API to longterm-pin
the folios. The last patch adds two new udmabuf selftests to verify
data coherency after potential page migration.

v2:
- Updated the first patch to include review feedback from David and
  Jason. The main change in this series is the allocation of page
  in the case of hugetlbfs if it is not found in the page cache.

v3:
- Made changes to include review feedback from David to improve the
  comments and readability of code
- Enclosed the hugepage alloc code with #ifdef CONFIG_HUGETLB_PAGE

v4:
- Augmented the commit message of the udmabuf patch that uses
  pin_user_pages_fd()
- Added previously reviewed but unmerged udmabuf patches to this
  series

v5:
- Updated the patch that adds pin_user_pages_fd() to include feedback
  from David to handle simultaneous users trying to add a huge page
  to the mapping
- Replaced find_get_page_flags() with __filemap_get_folio() in the
  second and third patches to ensure that we only obtain head pages
  from the mapping

v6: (Christoph)
- Renamed the new API to memfd_pin_user_pages()
- Improved the page cache lookup efficiency by using
  filemap_get_folios_contig() which uses batches

v7:
- Rename the new API to memfd_pin_folios() and make it return folios
  and offsets (David)
- Added a new preparatory patch to this series to convert udmabuf
  driver to use folios

This series is tested using following methods:
- Run the subtests added in the fifth patch
- Run Qemu (master) with the following options and a few additional
  patches to Spice:
  qemu-system-x86_64 -m 4096m....
  -device virtio-gpu-pci,max_outputs=1,blob=true,xres=1920,yres=1080
  -spice port=3001,gl=on,disable-ticketing=on,preferred-codec=gstreamer:h264
  -object memory-backend-memfd,hugetlb=on,id=mem1,size=4096M
  -machine memory-backend=mem1

Cc: David Hildenbrand <david@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Dongwon Kim <dongwon.kim@intel.com>
Cc: Junxiao Chang <junxiao.chang@intel.com>

Vivek Kasireddy (6):
  udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap
  udmabuf: Add back support for mapping hugetlb pages (v6)
  mm/gup: Introduce memfd_pin_folios() for pinning memfd folios (v7)
  udmabuf: Convert udmabuf driver to use folios
  udmabuf: Pin the pages using memfd_pin_folios() API (v5)
  selftests/dma-buf/udmabuf: Add tests to verify data after page
    migration

 drivers/dma-buf/udmabuf.c                     | 166 +++++++++++-------
 include/linux/memfd.h                         |   5 +
 include/linux/mm.h                            |   3 +
 mm/gup.c                                      | 155 ++++++++++++++++
 mm/memfd.c                                    |  34 ++++
 .../selftests/drivers/dma-buf/udmabuf.c       | 151 +++++++++++++++-
 6 files changed, 451 insertions(+), 63 deletions(-)

-- 
2.39.2


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

end of thread, other threads:[~2023-12-13 18:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-12 23:00 [PATCH v7 5/6] udmabuf: Pin the pages using memfd_pin_folios() API (v5) kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2023-12-12  7:37 [PATCH v7 0/6] mm/gup: Introduce memfd_pin_folios() for pinning memfd folios (v7) Vivek Kasireddy
2023-12-12  7:38 ` [PATCH v7 5/6] udmabuf: Pin the pages using memfd_pin_folios() API (v5) Vivek Kasireddy
2023-12-12  7:38   ` Vivek Kasireddy
2023-12-13 18:03   ` Matthew Wilcox
2023-12-13 18:03     ` Matthew Wilcox

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.