linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vivek Kasireddy <vivek.kasireddy@intel.com>
To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org
Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Steve Sistare <steven.sistare@oracle.com>,
	Muchun Song <muchun.song@linux.dev>,
	David Hildenbrand <david@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH v4 0/3] mm/memfd: Reserve hugetlb folios before allocation
Date: Tue, 17 Jun 2025 22:30:52 -0700	[thread overview]
Message-ID: <20250618053415.1036185-1-vivek.kasireddy@intel.com> (raw)

There are cases when we try to pin a folio but discover that it has
not been faulted-in. So, we try to allocate it in memfd_alloc_folio()
but the allocation request may not succeed if there are no active
reservations in the system at that instant.

Therefore, making a reservation (by calling hugetlb_reserve_pages())
associated with the allocation will ensure that our request would
not fail due to lack of reservations. This will also ensure that
proper region/subpool accounting is done with our allocation.

-----------------------------

Patchset overview:

Patch 1: Return nr of updated entries from hugetlb_reserve_pages()
Patch 2: Make reservation (hugetlb_reserve_pages) in memfd_alloc_folio()
Patch 3: New udmabuf selftest to invoke memfd_alloc_folio()

This series is tested by running the new udmabuf selftest introduced
in patch #3 along with the other selftests.

Changelog:
v3 -> v4:
- Create a standalone patch to fix the BUG reported by syzbot that
  can be backported to stable kernels (Andrew)
- Split the changes in memfd_alloc_folio() that add a call to
  hugetlb_reserve_pages() into a separate patch

v2 -> v3:
- Call hugetlb_unreserve_pages() only if the reservation was actively
  (and successfully) made from memfd_alloc_folio() (David)

v1 -> v2:
- Replace VM_BUG_ON() with WARN_ON_ONCE() in the function
  alloc_hugetlb_folio_reserve() (David)
- Move the inline function subpool_inode() from hugetlb.c into the
  relevant header (hugetlb.h)
- Call hugetlb_unreserve_pages() if the folio cannot be added to
  the page cache as well
- Added a new udmabuf selftest to exercise the same path as that
  of syzbot

Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Steve Sistare <steven.sistare@oracle.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: David Hildenbrand <david@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>

Vivek Kasireddy (3):
  mm/hugetlb: Make hugetlb_reserve_pages() return nr of entries updated
  mm/memfd: Reserve hugetlb folios before allocation
  selftests/udmabuf: Add a test to pin first before writing to memfd

 fs/hugetlbfs/inode.c                          |  8 +++----
 include/linux/hugetlb.h                       |  7 +++++-
 mm/hugetlb.c                                  | 24 ++++++++++---------
 mm/memfd.c                                    | 17 ++++++++++---
 .../selftests/drivers/dma-buf/udmabuf.c       | 20 +++++++++++++++-
 5 files changed, 56 insertions(+), 20 deletions(-)

-- 
2.49.0



             reply	other threads:[~2025-06-18  5:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18  5:30 Vivek Kasireddy [this message]
2025-06-18  5:30 ` [PATCH v4 1/3] mm/hugetlb: Make hugetlb_reserve_pages() return nr of entries updated Vivek Kasireddy
2025-06-18  5:30 ` [PATCH v4 2/3] mm/memfd: Reserve hugetlb folios before allocation Vivek Kasireddy
2025-06-18  7:46   ` Oscar Salvador
2025-06-19  5:34     ` Kasireddy, Vivek
2025-06-18  5:30 ` [PATCH v4 3/3] selftests/udmabuf: Add a test to pin first before writing to memfd Vivek Kasireddy

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=20250618053415.1036185-1-vivek.kasireddy@intel.com \
    --to=vivek.kasireddy@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kraxel@redhat.com \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=steven.sistare@oracle.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).