dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "David Zhang" <yidong.zhang@amd.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH V4 15/19] accel/amdxdna: Make populate_range common for AIE2 and AIE4
Date: Fri, 09 Oct 2026 23:06:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-166173@kernel.org> (raw)
In-Reply-To: <20261009225343.3079074-16-yidong.zhang@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] drm/amdxdna: data race on hmm_range during concurrent faulting
- [High] mm: cross-process mmap_lock dependency blocks NPU job submission
--

commit c2a130c1477d63bd08139e79291eca214fcf225a
Author: David Zhang <yidong.zhang@amd.com>

accel/amdxdna: Make populate_range common for AIE2 and AIE4

This commit moves aie2_populate_range() from aie2_ctx.c into amdxdna_gem.c
as amdxdna_populate_range(), making it common for both AIE2 and AIE4
command submissions.

> diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c
> index e1b72cef51bdf..320604ec157f7 100644
> --- a/drivers/accel/amdxdna/amdxdna_gem.c
> +++ b/drivers/accel/amdxdna/amdxdna_gem.c

[ ... ]

> @@ -337,6 +337,79 @@ void amdxdna_umap_put(struct amdxdna_umap *mapp)
>  	kref_put(&mapp->refcnt, amdxdna_umap_release);
>  }
>  
> +int amdxdna_populate_range(struct amdxdna_gem_obj *abo)
> +{
> +	struct amdxdna_dev *xdna = to_xdna_dev(to_gobj(abo)->dev);
> +	struct amdxdna_umap *mapp;
> +	unsigned long timeout;
> +	struct mm_struct *mm;
> +	bool found;
> +	int ret;
> +
> +	timeout = msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT);
> +again:
> +	found = false;
> +	down_write(&xdna->notifier_lock);
> +	list_for_each_entry(mapp, &abo->mem.umap_list, node) {

[Severity: High]
Does this code iterate over all mappings across all processes without
filtering by the current process?

If an unprivileged process imports a shared dmabuf, maps it, and holds its
mmap_write_lock indefinitely (e.g., via userfaultfd or FUSE), it could cause
this function to block indefinitely when attempting to acquire the
mmap_read_lock for that other process's mm. 

Could this result in a denial of service by permanently blocking job
submission for the process that exported the dmabuf?

> +		/*
> +		 * Skip entries that have already been unmapped.
> +		 *
> +		 * If userspace unmaps the address and later submits I/O using
> +		 * it, the IOMMU will reject the access and report a fault.
> +		 * Ignore such entries here.
> +		 */
> +		if (mapp->unmapped)
> +			continue;
> +
> +		if (mapp->invalid && kref_get_unless_zero(&mapp->refcnt)) {
> +			found = true;
> +			break;
> +		}
> +	}
> +
> +	if (!found) {

[ ... ]

> +	if (!mmget_not_zero(mm)) {
> +		amdxdna_umap_put(mapp);
> +		return -EFAULT;
> +	}
> +
> +	ret = hmm_range_fault_unlocked_timeout(&mapp->range, timeout);

[Severity: High]
Can multiple concurrent job submissions on the same GEM object cause a data
race here?

When multiple hardware contexts submit jobs referencing the same GEM object
with invalidated memory mappings, aie2_cmd_submit() drops GEM reservations
and notifier_lock before calling amdxdna_populate_range(). Because
mapp->invalid remains true until the fault is completed, concurrent
submissions will find the exact same amdxdna_umap object and invoke
hmm_range_fault_unlocked_timeout() simultaneously on the identical
&mapp->range structure.

The HMM API requires struct hmm_range to be thread-local or synchronized by
the caller. The internal mmap_read_lock only protects the VMA, not the
hmm_range struct itself.

Could these unsynchronized writes to range->notifier_seq and the
range->hmm_pfns array break the mmu_interval_read_retry() logic, circumvent
MMU invalidations, or lead to memory corruption?

> +	if (ret)
> +		goto put_mm;
> +
> +	down_write(&xdna->notifier_lock);
> +	if (mmu_interval_read_retry(&mapp->notifier, mapp->range.notifier_seq)) {
> +		up_write(&xdna->notifier_lock);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261009225343.3079074-1-yidong.zhang@amd.com?part=15

  reply	other threads:[~2026-10-09 23:06 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09 22:53 [PATCH V4 00/19] accel/amdxdna: Kernel submission and PM for AIE4 David Zhang
2026-10-09 22:53 ` [PATCH V4 01/19] accel/amdxdna: Rename NPU3 firmware files David Zhang
2026-10-09 22:53 ` [PATCH V4 02/19] accel/amdxdna: Remove mmap for doorbell David Zhang
2026-10-12 20:37   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 03/19] accel/amdxdna: Add CERT firmware version support David Zhang
2026-10-12 20:39   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 04/19] accel/amdxdna: Support firmware 6.0 David Zhang
2026-10-09 23:08   ` sashiko-bot
2026-10-12 20:41   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 05/19] accel/amdxdna: Add NPU3 classic device support David Zhang
2026-10-09 23:08   ` sashiko-bot
2026-10-12 20:41   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 06/19] accel/amdxdna: Add AIE version query to aie4_get_info David Zhang
2026-10-12 20:55   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 07/19] accel/amdxdna: Add get and set power_mode for AIE4 David Zhang
2026-10-12 21:29   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 08/19] accel/amdxdna: Add clock, DPM frequency, and resource info queries " David Zhang
2026-10-09 23:12   ` sashiko-bot
2026-10-12 22:58   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 09/19] accel/amdxdna: Add context switch hysteresis with debugfs control David Zhang
2026-10-13 18:29   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 10/19] accel/amdxdna: Refactor AIE4 hardware initialization sequence David Zhang
2026-10-13 18:33   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 11/19] accel/amdxdna: Decouple AIE4 doorbell and MSI-X notify transport hooks David Zhang
2026-10-13 18:38   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 12/19] accel/amdxdna: Implement AIE4 kernel queue lifecycle and memory layout David Zhang
2026-10-13 18:41   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 13/19] accel/amdxdna: Prepare for AIE4 command submission David Zhang
2026-10-13 18:42   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 14/19] accel/amdxdna: Move HMM invalidate wait into common GEM code David Zhang
2026-10-13 18:45   ` Lizhi Hou
2026-10-09 22:53 ` [PATCH V4 15/19] accel/amdxdna: Make populate_range common for AIE2 and AIE4 David Zhang
2026-10-09 23:06   ` sashiko-bot [this message]
2026-10-09 22:53 ` [PATCH V4 16/19] accel/amdxdna: Implement AIE4 command packet building and submission David Zhang
2026-10-09 22:53 ` [PATCH V4 17/19] accel/amdxdna: Enable AIE4 firmware logging to DRAM David Zhang
2026-10-09 23:14   ` sashiko-bot
2026-10-09 22:53 ` [PATCH V4 18/19] accel/amdxdna: Implement AIE4 suspend and resume David Zhang
2026-10-09 22:53 ` [PATCH V4 19/19] accel/amdxdna: Implement runtime suspend and resume support David Zhang
2026-10-09 23:17   ` sashiko-bot

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=sashiko-outbox-166173@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yidong.zhang@amd.com \
    /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