From: Balbir Singh <balbirs@nvidia.com>
To: linux-mm@kvack.org
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
Balbir Singh <balbirs@nvidia.com>
Subject: [v1 09/12] lib/test_hmm: add test case for split pages
Date: Fri, 4 Jul 2025 08:27:56 +1000 [thread overview]
Message-ID: <20250703222759.1943776-10-balbirs@nvidia.com> (raw)
In-Reply-To: <20250703222759.1943776-1-balbirs@nvidia.com>
Add a new flag HMM_DMIRROR_FLAG_FAIL_ALLOC to emulate
failure of allocating a large page. This tests the code paths
involving split migration.
Signed-off-by: Balbir Singh <balbirs@nvidia.com>
---
lib/test_hmm.c | 61 ++++++++++++++++++++++++++++++---------------
lib/test_hmm_uapi.h | 3 +++
2 files changed, 44 insertions(+), 20 deletions(-)
diff --git a/lib/test_hmm.c b/lib/test_hmm.c
index e20021fb7c69..c322be89d54c 100644
--- a/lib/test_hmm.c
+++ b/lib/test_hmm.c
@@ -92,6 +92,7 @@ struct dmirror {
struct xarray pt;
struct mmu_interval_notifier notifier;
struct mutex mutex;
+ __u64 flags;
};
/*
@@ -699,7 +700,12 @@ static void dmirror_migrate_alloc_and_copy(struct migrate_vma *args,
page_to_pfn(spage)))
goto next;
- dpage = dmirror_devmem_alloc_page(dmirror, is_large);
+ if (dmirror->flags & HMM_DMIRROR_FLAG_FAIL_ALLOC) {
+ dmirror->flags &= ~HMM_DMIRROR_FLAG_FAIL_ALLOC;
+ dpage = NULL;
+ } else
+ dpage = dmirror_devmem_alloc_page(dmirror, is_large);
+
if (!dpage) {
struct folio *folio;
unsigned long i;
@@ -954,44 +960,55 @@ static vm_fault_t dmirror_devmem_fault_alloc_and_copy(struct migrate_vma *args,
goto next;
spage = BACKING_PAGE(spage);
order = folio_order(page_folio(spage));
-
if (order)
+ *dst = MIGRATE_PFN_COMPOUND;
+ if (*src & MIGRATE_PFN_WRITE)
+ *dst |= MIGRATE_PFN_WRITE;
+
+ if (dmirror->flags & HMM_DMIRROR_FLAG_FAIL_ALLOC) {
+ dmirror->flags &= ~HMM_DMIRROR_FLAG_FAIL_ALLOC;
+ *dst &= ~MIGRATE_PFN_COMPOUND;
+ dpage = NULL;
+ } else if (order) {
dpage = folio_page(vma_alloc_folio(GFP_HIGHUSER_MOVABLE,
order, args->vma, addr), 0);
- else
- dpage = alloc_page_vma(GFP_HIGHUSER_MOVABLE, args->vma, addr);
-
- /* Try with smaller pages if large allocation fails */
- if (!dpage && order) {
+ } else {
dpage = alloc_page_vma(GFP_HIGHUSER_MOVABLE, args->vma, addr);
- if (!dpage)
- return VM_FAULT_OOM;
- order = 0;
}
+ if (!dpage && !order)
+ return VM_FAULT_OOM;
+
pr_debug("migrating from sys to dev pfn src: 0x%lx pfn dst: 0x%lx\n",
page_to_pfn(spage), page_to_pfn(dpage));
- lock_page(dpage);
- xa_erase(&dmirror->pt, addr >> PAGE_SHIFT);
- copy_highpage(dpage, spage);
- *dst = migrate_pfn(page_to_pfn(dpage));
- if (*src & MIGRATE_PFN_WRITE)
- *dst |= MIGRATE_PFN_WRITE;
- if (order)
- *dst |= MIGRATE_PFN_COMPOUND;
+
+ if (dpage) {
+ lock_page(dpage);
+ *dst |= migrate_pfn(page_to_pfn(dpage));
+ }
for (i = 0; i < (1 << order); i++) {
struct page *src_page;
struct page *dst_page;
+ /* Try with smaller pages if large allocation fails */
+ if (!dpage && order) {
+ dpage = alloc_page_vma(GFP_HIGHUSER_MOVABLE, args->vma, addr);
+ lock_page(dpage);
+ dst[i] = migrate_pfn(page_to_pfn(dpage));
+ dst_page = pfn_to_page(page_to_pfn(dpage));
+ dpage = NULL; /* For the next iteration */
+ } else {
+ dst_page = pfn_to_page(page_to_pfn(dpage) + i);
+ }
+
src_page = pfn_to_page(page_to_pfn(spage) + i);
- dst_page = pfn_to_page(page_to_pfn(dpage) + i);
xa_erase(&dmirror->pt, addr >> PAGE_SHIFT);
+ addr += PAGE_SIZE;
copy_highpage(dst_page, src_page);
}
next:
- addr += PAGE_SIZE << order;
src += 1 << order;
dst += 1 << order;
}
@@ -1509,6 +1526,10 @@ static long dmirror_fops_unlocked_ioctl(struct file *filp,
dmirror_device_remove_chunks(dmirror->mdevice);
ret = 0;
break;
+ case HMM_DMIRROR_FLAGS:
+ dmirror->flags = cmd.npages;
+ ret = 0;
+ break;
default:
return -EINVAL;
diff --git a/lib/test_hmm_uapi.h b/lib/test_hmm_uapi.h
index 8c818a2cf4f6..f94c6d457338 100644
--- a/lib/test_hmm_uapi.h
+++ b/lib/test_hmm_uapi.h
@@ -37,6 +37,9 @@ struct hmm_dmirror_cmd {
#define HMM_DMIRROR_EXCLUSIVE _IOWR('H', 0x05, struct hmm_dmirror_cmd)
#define HMM_DMIRROR_CHECK_EXCLUSIVE _IOWR('H', 0x06, struct hmm_dmirror_cmd)
#define HMM_DMIRROR_RELEASE _IOWR('H', 0x07, struct hmm_dmirror_cmd)
+#define HMM_DMIRROR_FLAGS _IOWR('H', 0x08, struct hmm_dmirror_cmd)
+
+#define HMM_DMIRROR_FLAG_FAIL_ALLOC (1ULL << 0)
/*
* Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT.
--
2.49.0
next prev parent reply other threads:[~2025-07-03 22:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-03 22:27 [v1 00/12] THP support for zone device page migration Balbir Singh
2025-07-03 22:27 ` [v1 01/12] mm/zone_device: support large zone device private folios Balbir Singh
2025-07-03 22:27 ` [v1 02/12] mm/migrate_device: flags for selecting device private THP pages Balbir Singh
2025-07-03 22:27 ` [v1 03/12] mm/thp: zone_device awareness in THP handling code Balbir Singh
2025-07-03 22:27 ` [v1 04/12] mm/migrate_device: THP migration of zone device pages Balbir Singh
2025-07-03 22:27 ` [v1 05/12] mm/memory/fault: add support for zone device THP fault handling Balbir Singh
2025-07-03 22:27 ` [v1 06/12] lib/test_hmm: test cases and support for zone device private THP Balbir Singh
2025-07-03 22:27 ` [v1 07/12] mm/memremap: add folio_split support Balbir Singh
2025-07-03 22:27 ` [v1 08/12] mm/thp: add split during migration support Balbir Singh
2025-07-03 22:27 ` Balbir Singh [this message]
2025-07-03 22:27 ` [v1 10/12] selftests/mm/hmm-tests: new tests for zone device THP migration Balbir Singh
2025-07-03 22:27 ` [v1 11/12] gpu/drm/nouveau: add THP migration support Balbir Singh
2025-07-03 22:27 ` [v1 12/12] selftests/mm/hmm-tests: new throughput tests including THP Balbir Singh
2025-07-03 23:00 ` [v1 00/12] THP support for zone device page migration Zi Yan
2025-07-03 23:06 ` Balbir Singh
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=20250703222759.1943776-10-balbirs@nvidia.com \
--to=balbirs@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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