mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V3] accel/amdxdna: Set HMM_PFN_REQ_WRITE for writable BO faults
@ 2026-09-17 17:19 Lizhi Hou
  2026-09-17 17:47 ` Max Zhen
  0 siblings, 1 reply; 2+ messages in thread
From: Lizhi Hou @ 2026-09-17 17:19 UTC (permalink / raw)
  To: ogabbay, quic_jhugo, mario.limonciello, karol.wachowski,
	dri-devel, max.zhen
  Cc: Lizhi Hou, linux-kernel, sonal.santan

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@amd.com>
---
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH V3] accel/amdxdna: Set HMM_PFN_REQ_WRITE for writable BO faults
  2026-09-17 17:19 [PATCH V3] accel/amdxdna: Set HMM_PFN_REQ_WRITE for writable BO faults Lizhi Hou
@ 2026-09-17 17:47 ` Max Zhen
  0 siblings, 0 replies; 2+ messages in thread
From: Max Zhen @ 2026-09-17 17:47 UTC (permalink / raw)
  To: Lizhi Hou, ogabbay, quic_jhugo, mario.limonciello,
	karol.wachowski, dri-devel
  Cc: linux-kernel, sonal.santan



On 9/17/2026 Thu 10:19, Lizhi Hou wrote:
> 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@amd.com>
Reviewed-by: Max Zhen <max.zhen@amd.com>
> ---
> 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);
>   


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-17 17:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 17:19 [PATCH V3] accel/amdxdna: Set HMM_PFN_REQ_WRITE for writable BO faults Lizhi Hou
2026-09-17 17:47 ` Max Zhen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®