From: SeongJae Park <sj@kernel.org>
To: Vivek Kasireddy <vivek.kasireddy@intel.com>
Cc: SeongJae Park <sj@kernel.org>,
dri-devel@lists.freedesktop.org, linux-mm@kvack.org,
David Hildenbrand <david@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
Christoph Hellwig <hch@infradead.org>,
Daniel Vetter <daniel.vetter@ffwll.ch>,
Hugh Dickins <hughd@google.com>, Peter Xu <peterx@redhat.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Dongwon Kim <dongwon.kim@intel.com>,
Junxiao Chang <junxiao.chang@intel.com>,
Jason Gunthorpe <jgg@nvidia.com>, Christoph Hellwig <hch@lst.de>,
Dave Airlie <airlied@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v16 3/9] mm/gup: Introduce memfd_pin_folios() for pinning memfd folios
Date: Fri, 5 Jul 2024 13:48:25 -0700 [thread overview]
Message-ID: <20240705204825.109189-1-sj@kernel.org> (raw)
In-Reply-To: <20240624063952.1572359-4-vivek.kasireddy@intel.com>
Hello Vivek and Andrew,
On Sun, 23 Jun 2024 23:36:11 -0700 Vivek Kasireddy <vivek.kasireddy@intel.com> wrote:
> For drivers that would like to longterm-pin the folios associated
> with a memfd, the memfd_pin_folios() API provides an option to
> not only pin the folios via FOLL_PIN but also to check and migrate
> them if they reside in movable zone or CMA block. This API
> currently works with memfds but it should work with any files
> that belong to either shmemfs or hugetlbfs. Files belonging to
> other filesystems are rejected for now.
>
> The folios need to be located first before pinning them via FOLL_PIN.
> If they are found in the page cache, they can be immediately pinned.
> Otherwise, they need to be allocated using the filesystem specific
> APIs and then pinned.
>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Christoph Hellwig <hch@infradead.org>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Peter Xu <peterx@redhat.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Dongwon Kim <dongwon.kim@intel.com>
> Cc: Junxiao Chang <junxiao.chang@intel.com>
> Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> (v2)
> Reviewed-by: David Hildenbrand <david@redhat.com> (v3)
> Reviewed-by: Christoph Hellwig <hch@lst.de> (v6)
> Acked-by: Dave Airlie <airlied@redhat.com>
> Acked-by: Gerd Hoffmann <kraxel@redhat.com>
> Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
> ---
> include/linux/memfd.h | 5 ++
> include/linux/mm.h | 3 +
> mm/gup.c | 137 ++++++++++++++++++++++++++++++++++++++++++
> mm/memfd.c | 45 ++++++++++++++
> 4 files changed, 190 insertions(+)
>
[...]
> diff --git a/mm/gup.c b/mm/gup.c
> index a88e19c78730..94160abbf499 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
[...]
> @@ -3747,3 +3749,138 @@ long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
> &locked, gup_flags);
> }
> EXPORT_SYMBOL(pin_user_pages_unlocked);
> +
> +/**
> + * memfd_pin_folios() - pin folios associated with a memfd
[...]
> + for (i = 0; i < nr_found; i++) {
> + /*
> + * As there can be multiple entries for a
> + * given folio in the batch returned by
> + * filemap_get_folios_contig(), the below
> + * check is to ensure that we pin and return a
> + * unique set of folios between start and end.
> + */
> + if (next_idx &&
> + next_idx != folio_index(fbatch.folios[i]))
> + continue;
> +
> + folio = try_grab_folio(&fbatch.folios[i]->page,
> + 1, FOLL_PIN);
> + if (!folio) {
> + folio_batch_release(&fbatch);
> + ret = -EINVAL;
> + goto err;
> + }
I found this patch is applied on mm-unstable as commit 7618d1ff59ef ("mm/gup:
introduce memfd_pin_folios() for pinning memfd folios"). Somehow, however, the
commit has changd the above try_grab_folio() call to try_grab_folio_fast()
call.
As a result, building kernel without CONFIG_MMU fais as below:
CC mm/gup.o
mm/gup.c: In function 'memfd_pin_folios':
mm/gup.c:3862:41: error: implicit declaration of function 'try_grab_folio_fast'; did you mean 'try_grab_folio'? [-Werror=implicit-function-declaration]
3862 | folio = try_grab_folio_fast(&fbatch.folios[i]->page,
| ^~~~~~~~~~~~~~~~~~~
| try_grab_folio
mm/gup.c:3862:39: warning: assignment to 'struct folio *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
3862 | folio = try_grab_folio_fast(&fbatch.folios[i]->page,
| ^
But simply changing the call back to try_grab_folio() causes another failure:
CC mm/gup.o
mm/gup.c: In function 'memfd_pin_folios':
mm/gup.c:3862:56: error: passing argument 1 of 'try_grab_folio' from incompatible pointer type [-Werror=incompatible-pointer-types]
3862 | folio = try_grab_folio(&fbatch.folios[i]->page,
| ^~~~~~~~~~~~~~~~~~~~~~~
| |
| struct page *
mm/gup.c:141:47: note: expected 'struct folio *' but argument is of type 'struct page *'
141 | int __must_check try_grab_folio(struct folio *folio, int refs,
| ~~~~~~~~~~~~~~^~~~~
mm/gup.c:3862:39: warning: assignment to 'struct folio *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
3862 | folio = try_grab_folio(&fbatch.folios[i]->page,
| ^
Maybe the change has made to fix conflict with another mm-unstable commit
02a2d55767d1 ("mm: gup: stop abusing try_grab_folio"), but forgot the
CONFIG_MMU unset case?
I confirmed the failure disappears after further cleanup like below:
diff --git a/mm/gup.c b/mm/gup.c
index 46a266ed84f7..9f4902425070 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -3859,9 +3859,9 @@ long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end,
next_idx != folio_index(fbatch.folios[i]))
continue;
- folio = try_grab_folio_fast(&fbatch.folios[i]->page,
- 1, FOLL_PIN);
- if (!folio) {
+ folio = page_folio(&fbatch.folios[i]->page);
+
+ if (try_grab_folio(folio, 1, FOLL_PIN)) {
folio_batch_release(&fbatch);
ret = -EINVAL;
goto err;
I didn't look deep into the patch, so unsure if that's a valid fix, though.
May I ask your thoughts?
Thanks,
SJ
[...]
next prev parent reply other threads:[~2024-07-05 20:48 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-24 6:36 [PATCH v16 0/9] " Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 1/9] mm/gup: Introduce unpin_folio/unpin_folios helpers Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 2/9] mm/gup: Introduce check_and_migrate_movable_folios() Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 3/9] mm/gup: Introduce memfd_pin_folios() for pinning memfd folios Vivek Kasireddy
2024-07-05 20:48 ` SeongJae Park [this message]
2024-07-05 21:23 ` Andrew Morton
2024-07-05 22:11 ` Kasireddy, Vivek
2024-07-05 22:55 ` Andrew Morton
2024-07-12 22:32 ` Andrew Morton
2024-07-14 2:30 ` Kasireddy, Vivek
2024-06-24 6:36 ` [PATCH v16 4/9] udmabuf: add CONFIG_MMU dependency Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 5/9] udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 6/9] udmabuf: Add back support for mapping hugetlb pages Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 7/9] udmabuf: Convert udmabuf driver to use folios Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 8/9] udmabuf: Pin the pages using memfd_pin_folios() API Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 9/9] selftests/udmabuf: Add tests to verify data after page migration Vivek Kasireddy
2024-06-26 19:13 ` [PATCH v16 0/9] mm/gup: Introduce memfd_pin_folios() for pinning memfd folios Kasireddy, Vivek
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=20240705204825.109189-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=airlied@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=daniel.vetter@ffwll.ch \
--cc=david@redhat.com \
--cc=dongwon.kim@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hch@infradead.org \
--cc=hch@lst.de \
--cc=hughd@google.com \
--cc=jgg@nvidia.com \
--cc=junxiao.chang@intel.com \
--cc=kraxel@redhat.com \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=vivek.kasireddy@intel.com \
--cc=willy@infradead.org \
/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