From: sashiko-bot@kernel.org
To: "Lizhi Hou" <lizhi.hou@amd.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH V1 1/1] accel/amdxdna: Fix unsafe use of handle_mm_fault()
Date: Wed, 09 Sep 2026 16:49:11 +0000 [thread overview]
Message-ID: <20260909164911.91F811F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260909163211.950709-1-lizhi.hou@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Using remap_pfn_range() to map normal refcounted shmem folios creates special PTEs, violating MM invariants.
--
commit 2da717e72d7319305e74d66b3b963f132ff12737
Author: Lizhi Hou <lizhi.hou@amd.com>
accel/amdxdna: Fix unsafe use of handle_mm_fault()
This commit removes the unsafe use of handle_mm_fault() from the mmap
callback since the VMA is not yet linked. For shmem BOs, it replaces the
faulting loop with direct calls to remap_pfn_range(), and for imported BOs
it marks the mapping as invalid to be faulted in later.
> diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c
> index 3f05fa8811af1..7a5b0ad3235fd 100644
> --- a/drivers/accel/amdxdna/amdxdna_gem.c
> +++ b/drivers/accel/amdxdna/amdxdna_gem.c
[ ... ]
> @@ -490,16 +491,10 @@ static int amdxdna_insert_pages(struct amdxdna_gem_obj *abo,
[ ... ]
> + ret = drm_gem_shmem_mmap(&abo->base, vma);
> + if (ret) {
> + XDNA_ERR(xdna, "Failed shmem mmap %d", ret);
> + return ret;
> }
>
> - do {
> - vm_fault_t fault_ret;
> + for (i = 0; i < num_pages; i++) {
>
> - fault_ret = handle_mm_fault(vma, vma->vm_start + offset,
> - FAULT_FLAG_WRITE, NULL);
> - if (fault_ret & VM_FAULT_ERROR) {
> - XDNA_ERR(xdna, "Fault in page failed");
> - amdxdna_mark_mapp_invalid(abo, vma);
> - break;
> + ret = remap_pfn_range(vma, vma->vm_start + (i << PAGE_SHIFT),
> + page_to_pfn(abo->base.pages[vma->vm_pgoff + i]),
> + PAGE_SIZE, vma->vm_page_prot);
[Severity: High]
Does using remap_pfn_range() here to map normal refcounted shmem folios
create special PTEs?
Since remap_pfn_range() is designed for raw PFN mappings, it sets the
special bit on the resulting page table entries. If this is applied to
normal refcounted folios from the shmem BO, it violates the memory
management invariant that normal folios must not have special PTEs.
When the special bit is set, vm_normal_page() returns NULL, which hides
these pages from page table walkers, GUP (get_user_pages), and
mapcount-based refcount management. Can this break reverse mapping (rmap)
and lead to memory management corruption?
> + if (ret) {
> + if (i > 0)
> + zap_special_vma_range(vma, vma->vm_start, i << PAGE_SHIFT);
> + dma_resv_lock(to_gobj(abo)->resv, NULL);
> + drm_gem_shmem_put_pages_locked(&abo->base);
> + dma_resv_unlock(to_gobj(abo)->resv);
> + return ret;
> }
> -
> - offset += PAGE_SIZE;
> - } while (--num_pages);
> + }
>
> return 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260909163211.950709-1-lizhi.hou@amd.com?part=1
prev parent reply other threads:[~2026-09-09 16:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 16:32 [PATCH V1 1/1] accel/amdxdna: Fix unsafe use of handle_mm_fault() Lizhi Hou
2026-09-09 16:49 ` sashiko-bot [this message]
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=20260909164911.91F811F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=lizhi.hou@amd.com \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.