All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v7 5/6] udmabuf: Pin the pages using memfd_pin_folios() API (v5)
  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   ` Vivek Kasireddy
  0 siblings, 0 replies; 5+ messages in thread
From: Vivek Kasireddy @ 2023-12-12  7:38 UTC (permalink / raw)
  To: dri-devel, linux-mm
  Cc: Dongwon Kim, David Hildenbrand, Daniel Vetter, Hugh Dickins,
	Vivek Kasireddy, Peter Xu, Gerd Hoffmann, Jason Gunthorpe,
	Junxiao Chang, Mike Kravetz

Using memfd_pin_folios() will ensure that the pages are pinned
correctly using FOLL_PIN. And, this also ensures that we don't
accidentally break features such as memory hotunplug as it would
not allow pinning pages in the movable zone.

Using this new API also simplifies the code as we no longer have
to deal with extracting individual pages from their mappings or
handle shmem and hugetlb cases separately.

v2:
- Adjust to the change in signature of pin_user_pages_fd() by
  passing in file * instead of fd.

v3:
- Limit the changes in this patch only to those that are required
  for using pin_user_pages_fd()
- Slightly improve the commit message

v4:
- Adjust to the change in name of the API (memfd_pin_user_pages)

v5:
- Adjust to the changes in memfd_pin_folios which now populates
  a list of folios and offsets

Cc: David Hildenbrand <david@redhat.com>
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>
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
---
 drivers/dma-buf/udmabuf.c | 85 ++++++---------------------------------
 1 file changed, 12 insertions(+), 73 deletions(-)

diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index e1b8da3c9b2a..a614e720837d 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -42,7 +42,7 @@ static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
 	if (pgoff >= ubuf->pagecount)
 		return VM_FAULT_SIGBUS;
 
-	pfn = page_to_pfn(&ubuf->folios[pgoff]->page);
+	pfn = page_to_pfn(folio_page(ubuf->folios[pgoff], 0));
 	pfn += ubuf->offsets[pgoff] >> PAGE_SHIFT;
 
 	return vmf_insert_pfn(vma, vmf->address, pfn);
@@ -79,7 +79,7 @@ static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map)
 		return -ENOMEM;
 
 	for (pg = 0; pg < ubuf->pagecount; pg++)
-		pages[pg] = &ubuf->folios[pg]->page;
+		pages[pg] = folio_page(ubuf->folios[pg], 0);
 
 	vaddr = vm_map_ram(pages, ubuf->pagecount, -1);
 	kfree(pages);
@@ -163,7 +163,8 @@ static void release_udmabuf(struct dma_buf *buf)
 		put_sg_table(dev, ubuf->sg, DMA_BIDIRECTIONAL);
 
 	for (pg = 0; pg < ubuf->pagecount; pg++)
-		folio_put(ubuf->folios[pg]);
+		unpin_user_page(folio_page(ubuf->folios[pg], 0));
+
 	kfree(ubuf->offsets);
 	kfree(ubuf->folios);
 	kfree(ubuf);
@@ -218,65 +219,6 @@ static const struct dma_buf_ops udmabuf_ops = {
 #define SEALS_WANTED (F_SEAL_SHRINK)
 #define SEALS_DENIED (F_SEAL_WRITE)
 
-static int handle_hugetlb_pages(struct udmabuf *ubuf, struct file *memfd,
-				pgoff_t offset, pgoff_t pgcnt,
-				pgoff_t *pgbuf)
-{
-	struct hstate *hpstate = hstate_file(memfd);
-	pgoff_t mapidx = offset >> huge_page_shift(hpstate);
-	pgoff_t subpgoff = (offset & ~huge_page_mask(hpstate)) >> PAGE_SHIFT;
-	pgoff_t maxsubpgs = huge_page_size(hpstate) >> PAGE_SHIFT;
-	struct folio *folio = NULL;
-	pgoff_t pgidx;
-
-	mapidx <<= huge_page_order(hpstate);
-	for (pgidx = 0; pgidx < pgcnt; pgidx++) {
-		if (!folio) {
-			folio = __filemap_get_folio(memfd->f_mapping,
-						    mapidx,
-						    FGP_ACCESSED, 0);
-			if (IS_ERR(folio))
-				return PTR_ERR(folio);
-		}
-
-		folio_get(folio);
-		ubuf->folios[*pgbuf] = folio;
-		ubuf->offsets[*pgbuf] = subpgoff << PAGE_SHIFT;
-		(*pgbuf)++;
-		if (++subpgoff == maxsubpgs) {
-			folio_put(folio);
-			folio = NULL;
-			subpgoff = 0;
-			mapidx += pages_per_huge_page(hpstate);
-		}
-	}
-
-	if (folio)
-		folio_put(folio);
-
-	return 0;
-}
-
-static int handle_shmem_pages(struct udmabuf *ubuf, struct file *memfd,
-			      pgoff_t offset, pgoff_t pgcnt,
-			      pgoff_t *pgbuf)
-{
-	pgoff_t pgidx, pgoff = offset >> PAGE_SHIFT;
-	struct folio *folio = NULL;
-
-	for (pgidx = 0; pgidx < pgcnt; pgidx++) {
-		folio = shmem_read_folio(memfd->f_mapping,
-					 pgoff + pgidx);
-		if (IS_ERR(folio))
-			return PTR_ERR(folio);
-
-		ubuf->folios[*pgbuf] = folio;
-		(*pgbuf)++;
-	}
-
-	return 0;
-}
-
 static int check_memfd_seals(struct file *memfd)
 {
 	int seals;
@@ -325,7 +267,7 @@ static long udmabuf_create(struct miscdevice *device,
 	pgoff_t pgcnt, pgbuf = 0, pglimit;
 	struct file *memfd = NULL;
 	struct udmabuf *ubuf;
-	int ret = -EINVAL;
+	long ret = -EINVAL;
 	u32 i, flags;
 
 	ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL);
@@ -366,17 +308,13 @@ static long udmabuf_create(struct miscdevice *device,
 			goto err;
 
 		pgcnt = list[i].size >> PAGE_SHIFT;
-		if (is_file_hugepages(memfd))
-			ret = handle_hugetlb_pages(ubuf, memfd,
-						   list[i].offset,
-						   pgcnt, &pgbuf);
-		else
-			ret = handle_shmem_pages(ubuf, memfd,
-						 list[i].offset,
-						 pgcnt, &pgbuf);
+		ret = memfd_pin_folios(memfd, list[i].offset, pgcnt,
+				       ubuf->folios + pgbuf,
+				       ubuf->offsets + pgbuf);
 		if (ret < 0)
 			goto err;
 
+		pgbuf += pgcnt;
 		fput(memfd);
 		memfd = NULL;
 	}
@@ -389,8 +327,9 @@ static long udmabuf_create(struct miscdevice *device,
 	return ret;
 
 err:
-	while (pgbuf > 0)
-		folio_put(ubuf->folios[--pgbuf]);
+	while (pgbuf-- > 0)
+		if (ubuf->folios[pgbuf])
+			unpin_user_page(folio_page(ubuf->folios[pgbuf], 0));
 	if (memfd)
 		fput(memfd);
 	kfree(ubuf->offsets);
-- 
2.39.2


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

* [PATCH v7 5/6] udmabuf: Pin the pages using memfd_pin_folios() API (v5)
@ 2023-12-12  7:38   ` Vivek Kasireddy
  0 siblings, 0 replies; 5+ messages in thread
From: Vivek Kasireddy @ 2023-12-12  7:38 UTC (permalink / raw)
  To: dri-devel, linux-mm
  Cc: Vivek Kasireddy, David Hildenbrand, Daniel Vetter, Mike Kravetz,
	Hugh Dickins, Peter Xu, Jason Gunthorpe, Gerd Hoffmann,
	Dongwon Kim, Junxiao Chang

Using memfd_pin_folios() will ensure that the pages are pinned
correctly using FOLL_PIN. And, this also ensures that we don't
accidentally break features such as memory hotunplug as it would
not allow pinning pages in the movable zone.

Using this new API also simplifies the code as we no longer have
to deal with extracting individual pages from their mappings or
handle shmem and hugetlb cases separately.

v2:
- Adjust to the change in signature of pin_user_pages_fd() by
  passing in file * instead of fd.

v3:
- Limit the changes in this patch only to those that are required
  for using pin_user_pages_fd()
- Slightly improve the commit message

v4:
- Adjust to the change in name of the API (memfd_pin_user_pages)

v5:
- Adjust to the changes in memfd_pin_folios which now populates
  a list of folios and offsets

Cc: David Hildenbrand <david@redhat.com>
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>
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
---
 drivers/dma-buf/udmabuf.c | 85 ++++++---------------------------------
 1 file changed, 12 insertions(+), 73 deletions(-)

diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index e1b8da3c9b2a..a614e720837d 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -42,7 +42,7 @@ static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
 	if (pgoff >= ubuf->pagecount)
 		return VM_FAULT_SIGBUS;
 
-	pfn = page_to_pfn(&ubuf->folios[pgoff]->page);
+	pfn = page_to_pfn(folio_page(ubuf->folios[pgoff], 0));
 	pfn += ubuf->offsets[pgoff] >> PAGE_SHIFT;
 
 	return vmf_insert_pfn(vma, vmf->address, pfn);
@@ -79,7 +79,7 @@ static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map)
 		return -ENOMEM;
 
 	for (pg = 0; pg < ubuf->pagecount; pg++)
-		pages[pg] = &ubuf->folios[pg]->page;
+		pages[pg] = folio_page(ubuf->folios[pg], 0);
 
 	vaddr = vm_map_ram(pages, ubuf->pagecount, -1);
 	kfree(pages);
@@ -163,7 +163,8 @@ static void release_udmabuf(struct dma_buf *buf)
 		put_sg_table(dev, ubuf->sg, DMA_BIDIRECTIONAL);
 
 	for (pg = 0; pg < ubuf->pagecount; pg++)
-		folio_put(ubuf->folios[pg]);
+		unpin_user_page(folio_page(ubuf->folios[pg], 0));
+
 	kfree(ubuf->offsets);
 	kfree(ubuf->folios);
 	kfree(ubuf);
@@ -218,65 +219,6 @@ static const struct dma_buf_ops udmabuf_ops = {
 #define SEALS_WANTED (F_SEAL_SHRINK)
 #define SEALS_DENIED (F_SEAL_WRITE)
 
-static int handle_hugetlb_pages(struct udmabuf *ubuf, struct file *memfd,
-				pgoff_t offset, pgoff_t pgcnt,
-				pgoff_t *pgbuf)
-{
-	struct hstate *hpstate = hstate_file(memfd);
-	pgoff_t mapidx = offset >> huge_page_shift(hpstate);
-	pgoff_t subpgoff = (offset & ~huge_page_mask(hpstate)) >> PAGE_SHIFT;
-	pgoff_t maxsubpgs = huge_page_size(hpstate) >> PAGE_SHIFT;
-	struct folio *folio = NULL;
-	pgoff_t pgidx;
-
-	mapidx <<= huge_page_order(hpstate);
-	for (pgidx = 0; pgidx < pgcnt; pgidx++) {
-		if (!folio) {
-			folio = __filemap_get_folio(memfd->f_mapping,
-						    mapidx,
-						    FGP_ACCESSED, 0);
-			if (IS_ERR(folio))
-				return PTR_ERR(folio);
-		}
-
-		folio_get(folio);
-		ubuf->folios[*pgbuf] = folio;
-		ubuf->offsets[*pgbuf] = subpgoff << PAGE_SHIFT;
-		(*pgbuf)++;
-		if (++subpgoff == maxsubpgs) {
-			folio_put(folio);
-			folio = NULL;
-			subpgoff = 0;
-			mapidx += pages_per_huge_page(hpstate);
-		}
-	}
-
-	if (folio)
-		folio_put(folio);
-
-	return 0;
-}
-
-static int handle_shmem_pages(struct udmabuf *ubuf, struct file *memfd,
-			      pgoff_t offset, pgoff_t pgcnt,
-			      pgoff_t *pgbuf)
-{
-	pgoff_t pgidx, pgoff = offset >> PAGE_SHIFT;
-	struct folio *folio = NULL;
-
-	for (pgidx = 0; pgidx < pgcnt; pgidx++) {
-		folio = shmem_read_folio(memfd->f_mapping,
-					 pgoff + pgidx);
-		if (IS_ERR(folio))
-			return PTR_ERR(folio);
-
-		ubuf->folios[*pgbuf] = folio;
-		(*pgbuf)++;
-	}
-
-	return 0;
-}
-
 static int check_memfd_seals(struct file *memfd)
 {
 	int seals;
@@ -325,7 +267,7 @@ static long udmabuf_create(struct miscdevice *device,
 	pgoff_t pgcnt, pgbuf = 0, pglimit;
 	struct file *memfd = NULL;
 	struct udmabuf *ubuf;
-	int ret = -EINVAL;
+	long ret = -EINVAL;
 	u32 i, flags;
 
 	ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL);
@@ -366,17 +308,13 @@ static long udmabuf_create(struct miscdevice *device,
 			goto err;
 
 		pgcnt = list[i].size >> PAGE_SHIFT;
-		if (is_file_hugepages(memfd))
-			ret = handle_hugetlb_pages(ubuf, memfd,
-						   list[i].offset,
-						   pgcnt, &pgbuf);
-		else
-			ret = handle_shmem_pages(ubuf, memfd,
-						 list[i].offset,
-						 pgcnt, &pgbuf);
+		ret = memfd_pin_folios(memfd, list[i].offset, pgcnt,
+				       ubuf->folios + pgbuf,
+				       ubuf->offsets + pgbuf);
 		if (ret < 0)
 			goto err;
 
+		pgbuf += pgcnt;
 		fput(memfd);
 		memfd = NULL;
 	}
@@ -389,8 +327,9 @@ static long udmabuf_create(struct miscdevice *device,
 	return ret;
 
 err:
-	while (pgbuf > 0)
-		folio_put(ubuf->folios[--pgbuf]);
+	while (pgbuf-- > 0)
+		if (ubuf->folios[pgbuf])
+			unpin_user_page(folio_page(ubuf->folios[pgbuf], 0));
 	if (memfd)
 		fput(memfd);
 	kfree(ubuf->offsets);
-- 
2.39.2



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

* 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

* Re: [PATCH v7 5/6] udmabuf: Pin the pages using memfd_pin_folios() API (v5)
  2023-12-12  7:38   ` Vivek Kasireddy
@ 2023-12-13 18:03     ` Matthew Wilcox
  -1 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox @ 2023-12-13 18:03 UTC (permalink / raw)
  To: Vivek Kasireddy
  Cc: Gerd Hoffmann, Dongwon Kim, David Hildenbrand, Daniel Vetter,
	Hugh Dickins, dri-devel, linux-mm, Peter Xu, Jason Gunthorpe,
	Junxiao Chang, Mike Kravetz

On Mon, Dec 11, 2023 at 11:38:02PM -0800, Vivek Kasireddy wrote:
> +++ b/drivers/dma-buf/udmabuf.c
> @@ -42,7 +42,7 @@ static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
>  	if (pgoff >= ubuf->pagecount)
>  		return VM_FAULT_SIGBUS;
>  
> -	pfn = page_to_pfn(&ubuf->folios[pgoff]->page);
> +	pfn = page_to_pfn(folio_page(ubuf->folios[pgoff], 0));

Why are you changing from &folio->page to folio_page(folio, 0) in
this patch?  Either that should have been done the other way in the
earlier patch, or it shouldn't be done at all.

My vote is that it shuoldn't be done at all.  These all seem like "I
have to convert back from folio to page because the APIs I want aren't
available", not "I want the first page from this folio".


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

* Re: [PATCH v7 5/6] udmabuf: Pin the pages using memfd_pin_folios() API (v5)
@ 2023-12-13 18:03     ` Matthew Wilcox
  0 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox @ 2023-12-13 18:03 UTC (permalink / raw)
  To: Vivek Kasireddy
  Cc: dri-devel, linux-mm, David Hildenbrand, Daniel Vetter,
	Mike Kravetz, Hugh Dickins, Peter Xu, Jason Gunthorpe,
	Gerd Hoffmann, Dongwon Kim, Junxiao Chang

On Mon, Dec 11, 2023 at 11:38:02PM -0800, Vivek Kasireddy wrote:
> +++ b/drivers/dma-buf/udmabuf.c
> @@ -42,7 +42,7 @@ static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
>  	if (pgoff >= ubuf->pagecount)
>  		return VM_FAULT_SIGBUS;
>  
> -	pfn = page_to_pfn(&ubuf->folios[pgoff]->page);
> +	pfn = page_to_pfn(folio_page(ubuf->folios[pgoff], 0));

Why are you changing from &folio->page to folio_page(folio, 0) in
this patch?  Either that should have been done the other way in the
earlier patch, or it shouldn't be done at all.

My vote is that it shuoldn't be done at all.  These all seem like "I
have to convert back from folio to page because the APIs I want aren't
available", not "I want the first page from this folio".



^ 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.