From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,will@kernel.org,vivek.kasireddy@intel.com,
skhawaja@google.com,robin.murphy@arm.com,peterx@redhat.com,
kevin.tian@intel.com,joro@8bytes.org,jhubbard@nvidia.com,jgg@ziepe.ca,
david@kernel.org,xujiahao@cmss.chinamobile.com,akpm@linux-foundation.org
Subject: + mm-gup-add-file_is_memfd_compatible-helper.patch added to mm-new branch
Date: Mon, 23 Nov 2026 17:38:55 -0800 [thread overview]
Message-ID: <20261124013855.98B111F000C4@smtp.kernel.org> (raw)
In-Reply-To: <20261119163531.788514-1-xujiahao@cmss.chinamobile.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 5116 bytes --]
The patch titled
Subject: mm/gup: add file_is_memfd_compatible() helper
has been added to the -mm mm-new branch. Its filename is
mm-gup-add-file_is_memfd_compatible-helper.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-gup-add-file_is_memfd_compatible-helper.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Jiahao Xu <xujiahao@cmss.chinamobile.com>
Subject: mm/gup: add file_is_memfd_compatible() helper
Date: Thu, 19 Nov 2026 16:35:31 +0800
memfd_pin_folios() accepts only shmem and file-hugetlb files and enforces
that inline with shmem_file() and is_file_hugepages(). A caller that has
to know up front whether a file may be handed to memfd_pin_folios() cannot
use those predicates: since d3710111839d ("mm/shmem: make shmem_file()
check the file's inode") shmem_file() is an out-of-line function in
mm/shmem.c which is not exported, so modules cannot call it, and
is_file_hugepages() on its own is not the same question.
Provide the check as an exported helper next to memfd_pin_folios() and use
it inside memfd_pin_folios() itself, so that a single place decides which
files may be pinned.
Link: https://patch.msgid.link/20261119163531.788514-1-xujiahao@cmss.chinamobile.com
Signed-off-by: Jiahao Xu <xujiahao@cmss.chinamobile.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Samiullah Khawaja <skhawaja@google.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>
Cc: Kevin Tian <kevin.tian@intel.com>
Cc: Jörg Rödel <joro@8bytes.org>
Cc: Will Deacon <will@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
include/linux/mm.h | 1 +
mm/gup.c | 23 ++++++++++++++++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)
--- a/include/linux/mm.h~mm-gup-add-file_is_memfd_compatible-helper
+++ a/include/linux/mm.h
@@ -3604,6 +3604,7 @@ long pin_user_pages_unlocked(unsigned lo
long memfd_pin_folios(struct file *memfd, loff_t start, loff_t end,
struct folio **folios, unsigned int max_folios,
pgoff_t *offset);
+bool file_is_memfd_compatible(struct file *file);
int folio_add_pins(struct folio *folio, unsigned int pins);
int get_user_pages_fast(unsigned long start, int nr_pages,
--- a/mm/gup.c~mm-gup-add-file_is_memfd_compatible-helper
+++ a/mm/gup.c
@@ -3450,6 +3450,27 @@ long pin_user_pages_unlocked(unsigned lo
EXPORT_SYMBOL(pin_user_pages_unlocked);
/**
+ * file_is_memfd_compatible() - check if a file may be used with
+ * memfd_pin_folios()
+ * @file: the file to check
+ *
+ * memfd_pin_folios() only accepts files backed by shmem or by hugetlb.
+ * This is wider than "is a memfd": every shmem file matches, not only the
+ * unlinked ones memfd_create() produces, and file-hugetlb files are not
+ * memfds at all.
+ *
+ * Callers that have to validate a file before pinning it, or before taking
+ * a reference to it, can use this helper instead of duplicating the check.
+ *
+ * Return: true if @file may be passed to memfd_pin_folios().
+ */
+bool file_is_memfd_compatible(struct file *file)
+{
+ return shmem_file(file) || is_file_hugepages(file);
+}
+EXPORT_SYMBOL_GPL(file_is_memfd_compatible);
+
+/**
* memfd_pin_folios() - pin folios associated with a memfd
* @memfd: the memfd whose folios are to be pinned
* @start: the first memfd offset
@@ -3493,7 +3514,7 @@ long memfd_pin_folios(struct file *memfd
if (!memfd)
return -EINVAL;
- if (!shmem_file(memfd) && !is_file_hugepages(memfd))
+ if (!file_is_memfd_compatible(memfd))
return -EINVAL;
if (end >= i_size_read(file_inode(memfd)))
_
Patches currently in -mm which might be from xujiahao@cmss.chinamobile.com are
mm-gup-add-file_is_memfd_compatible-helper.patch
iommufd-only-hold-references-to-files-memfd_pin_folios-can-pin.patch
next prev parent reply other threads:[~2026-11-24 1:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 8:35 [PATCH v2 1/2] mm/gup: add file_is_memfd_compatible() helper Jiahao Xu
2026-11-19 8:35 ` [PATCH v2 2/2] iommufd: only hold references to files memfd_pin_folios() can pin Jiahao Xu
2026-11-20 20:04 ` Samiullah Khawaja
2026-11-24 1:38 ` + iommufd-only-hold-references-to-files-memfd_pin_folios-can-pin.patch added to mm-new branch Andrew Morton
2026-11-24 4:46 ` [merged] iommufd-only-hold-references-to-files-memfd_pin_folios-can-pin.patch removed from -mm tree Andrew Morton
2026-11-20 9:31 ` [PATCH v2 1/2] mm/gup: add file_is_memfd_compatible() helper David Hildenbrand (Arm)
2026-11-20 20:03 ` Samiullah Khawaja
2026-11-20 20:49 ` Jason Gunthorpe
2026-11-24 1:38 ` Andrew Morton [this message]
2026-11-24 2:34 ` + mm-gup-add-file_is_memfd_compatible-helper.patch added to mm-new branch Jiahao Xu
2026-11-24 4:47 ` Andrew Morton
2026-11-24 4:46 ` [merged] mm-gup-add-file_is_memfd_compatible-helper.patch removed from -mm tree 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=20261124013855.98B111F000C4@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=mm-commits@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=robin.murphy@arm.com \
--cc=skhawaja@google.com \
--cc=vivek.kasireddy@intel.com \
--cc=will@kernel.org \
--cc=xujiahao@cmss.chinamobile.com \
/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 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.