[PATCH V3] accel/amdxdna: Set HMM_PFN_REQ_WRITE for writable BO faults

From: Lizhi Hou

Date: Thu Sep 17 2026 - 14:16:04 EST


When aie2_populate_range() faults in pages, it only sets
HMM_PFN_REQ_FAULT. Without HMM_PFN_REQ_WRITE, handle_mm_fault() does not
request write permissions and may populate the CPU page tables with
read-only PTEs.

Check the VMA flags and set HMM_PFN_REQ_WRITE when the VMA has VM_WRITE.

Fixes: e486147c912f ("accel/amdxdna: Add BO import and export")
Signed-off-by: Lizhi Hou <lizhi.hou@xxxxxxx>
---
V3:
Revert the V2 change. Instead, add comment to describe why it is not
an issue.
V2:
Fix sashiko comment.

drivers/accel/amdxdna/amdxdna_gem.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c
index e861db6f9369..a5e30855c8a1 100644
--- a/drivers/accel/amdxdna/amdxdna_gem.c
+++ b/drivers/accel/amdxdna/amdxdna_gem.c
@@ -418,7 +418,15 @@ static int amdxdna_hmm_register(struct amdxdna_gem_obj *abo,
mapp->range.notifier = &mapp->notifier;
mapp->range.start = vma->vm_start;
mapp->range.end = vma->vm_end;
+ /*
+ * Access permissions are fixed at mmap() time. Changing them later
+ * with mprotect() is not supported: the range keeps requesting the
+ * original permissions, so the application may see a fault failure
+ * or an IOMMU fault.
+ */
mapp->range.default_flags = HMM_PFN_REQ_FAULT;
+ if (vma->vm_flags & VM_WRITE)
+ mapp->range.default_flags |= HMM_PFN_REQ_WRITE;
mapp->abo = abo;
kref_init(&mapp->refcnt);

--
2.34.1