From: Aveline Noir <jm5905938@gmail.com>
To: Jason Gunthorpe <jgg@ziepe.ca>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Francois Dugast <francois.dugast@intel.com>,
Christoph Hellwig <hch@lst.de>, Leon Romanovsky <leon@kernel.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH] mm/hmm: honor write requests for owned device-private pages
Date: Sat, 31 Oct 2026 18:10:22 +1100 [thread overview]
Message-ID: <179343062238.2.2773026701442863377@gmail.com> (raw)
The owner-matching device-private PTE and PMD paths return read-only
pages even when HMM_PFN_REQ_WRITE is requested. For example, after fork,
a write request can succeed without resolving COW or returning
HMM_PFN_WRITE. The test_hmm consumer then returns -EFAULT.
Check read-only entries for write faults before returning their PFNs.
Keep the fast path for writable entries and skip the PMD request scan
when no write request is possible.
Fixes: 10b9feee2d0d ("mm/hmm: populate PFNs from PMD swap entry")
Signed-off-by: Aveline Noir <jm5905938@gmail.com>
---
Found during code review and synthetic HMM testing.
Tested PTE and PMD write requests, COW and read-only VMAs with QEMU
test_hmm on x86-64. A separate test probe covered request flags. All
executed tests passed. Testing on a real GPU would be appreciated.
---
mm/hmm.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/mm/hmm.c b/mm/hmm.c
index 2f1e98c6b644..92957541ba95 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -268,15 +268,22 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr,
const softleaf_t entry = softleaf_from_pte(pte);
/*
- * Don't fault in device private pages owned by the caller,
- * just report the PFN.
+ * Don't fault in device private pages owned by the caller unless
+ * a write fault is required.
*/
if (softleaf_is_device_private(entry) &&
page_pgmap(softleaf_to_page(entry))->owner ==
range->dev_private_owner) {
cpu_flags = HMM_PFN_VALID;
- if (softleaf_is_device_private_write(entry))
+ if (softleaf_is_device_private_write(entry)) {
cpu_flags |= HMM_PFN_WRITE;
+ } else {
+ required_fault =
+ hmm_pte_need_fault(hmm_vma_walk, pfn_req_flags,
+ cpu_flags);
+ if (required_fault)
+ goto fault;
+ }
new_pfn_flags = softleaf_to_pfn(entry) | cpu_flags;
goto out;
}
@@ -358,8 +365,15 @@ static int hmm_vma_handle_absent_pmd(struct mm_walk *walk, unsigned long start,
unsigned long pfn = softleaf_to_pfn(entry);
unsigned long i;
- if (softleaf_is_device_private_write(entry))
+ if (softleaf_is_device_private_write(entry)) {
cpu_flags |= HMM_PFN_WRITE;
+ } else if ((range->default_flags | range->pfn_flags_mask) &
+ HMM_PFN_REQ_WRITE) {
+ required_fault = hmm_range_need_fault(hmm_vma_walk,
+ hmm_pfns, npages, cpu_flags);
+ if (required_fault)
+ return hmm_record_fault(addr, end, required_fault, walk);
+ }
/*
* Fully populate the PFN list though subsequent PFNs could be
base-commit: d89e1d186ec9271bf78e62771779e9fc03bf0fc3
--
2.56.0
reply other threads:[~2026-10-31 7:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=179343062238.2.2773026701442863377@gmail.com \
--to=jm5905938@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=francois.dugast@intel.com \
--cc=hch@lst.de \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.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