From: David Zhang <yidong.zhang@amd.com>
To: <quic_jhugo@quicinc.com>, <karol.wachowski@linux.intel.com>,
<max.zhen@amd.com>, <lizhi.hou@amd.com>, <ogabbay@kernel.org>,
<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>
Cc: David Zhang <yidong.zhang@amd.com>, <sonal.santan@amd.com>,
<mario.limonciello@amd.com>
Subject: [PATCH V3 15/19] accel/amdxdna: Make populate_range common for AIE2 and AIE4
Date: Wed, 7 Oct 2026 20:23:44 -0700 [thread overview]
Message-ID: <20261008032348.2044667-16-yidong.zhang@amd.com> (raw)
In-Reply-To: <20261008032348.2044667-1-yidong.zhang@amd.com>
When a user mapping of a BO is invalidated, the MMU notifier sets
map_invalid and command submission must fault the range back in
before attaching the job fence. AIE2 does this in
aie2_populate_range(), which AIE4 command submission also needs.
Move aie2_populate_range() from aie2_ctx.c into amdxdna_gem.c as
amdxdna_populate_range(), next to the MMU notifier code, and declare
it in amdxdna_gem.h. No functional change for AIE2.
Signed-off-by: David Zhang <yidong.zhang@amd.com>
---
drivers/accel/amdxdna/aie2_ctx.c | 75 +----------------------------
drivers/accel/amdxdna/amdxdna_gem.c | 73 ++++++++++++++++++++++++++++
drivers/accel/amdxdna/amdxdna_gem.h | 1 +
3 files changed, 75 insertions(+), 74 deletions(-)
diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c
index 8c1b29964f8f..05ed71e641c3 100644
--- a/drivers/accel/amdxdna/aie2_ctx.c
+++ b/drivers/accel/amdxdna/aie2_ctx.c
@@ -1105,79 +1105,6 @@ int aie2_hwctx_sync_debug_bo(struct amdxdna_hwctx *hwctx, u32 debug_bo_hdl)
return ret;
}
-static int aie2_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) {
- /*
- * 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) {
- /*
- * This also covers the case where all mappings have been
- * removed. There are no invalid mappings left to process.
- * Any subsequent I/O using the unmapped address will be
- * rejected by the IOMMU.
- */
- abo->mem.map_invalid = false;
- up_write(&xdna->notifier_lock);
- return 0;
- }
-
- up_write(&xdna->notifier_lock);
-
- mm = mapp->notifier.mm;
- if (!mmget_not_zero(mm)) {
- amdxdna_umap_put(mapp);
- return -EFAULT;
- }
-
- ret = hmm_range_fault_unlocked_timeout(&mapp->range, timeout);
- 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);
- amdxdna_umap_put(mapp);
- mmput(mm);
- goto again;
- }
- mapp->invalid = false;
- up_write(&xdna->notifier_lock);
- amdxdna_umap_put(mapp);
- mmput(mm);
- goto again;
-
-put_mm:
- amdxdna_umap_put(mapp);
- mmput(mm);
- return ret == -EBUSY ? -ETIME : ret;
-}
-
int aie2_cmd_submit(struct amdxdna_hwctx *hwctx, struct amdxdna_sched_job *job, u64 *seq)
{
struct amdxdna_dev *xdna = hwctx->client->xdna;
@@ -1237,7 +1164,7 @@ int aie2_cmd_submit(struct amdxdna_hwctx *hwctx, struct amdxdna_sched_job *job,
goto cleanup_job;
}
- ret = aie2_populate_range(abo);
+ ret = amdxdna_populate_range(abo);
if (ret)
goto cleanup_job;
goto retry;
diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c
index eebd93b6f2c3..98b4768718a8 100644
--- a/drivers/accel/amdxdna/amdxdna_gem.c
+++ b/drivers/accel/amdxdna/amdxdna_gem.c
@@ -333,6 +333,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) {
+ /*
+ * 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) {
+ /*
+ * This also covers the case where all mappings have been
+ * removed. There are no invalid mappings left to process.
+ * Any subsequent I/O using the unmapped address will be
+ * rejected by the IOMMU.
+ */
+ abo->mem.map_invalid = false;
+ up_write(&xdna->notifier_lock);
+ return 0;
+ }
+
+ up_write(&xdna->notifier_lock);
+
+ mm = mapp->notifier.mm;
+ if (!mmget_not_zero(mm)) {
+ amdxdna_umap_put(mapp);
+ return -EFAULT;
+ }
+
+ ret = hmm_range_fault_unlocked_timeout(&mapp->range, timeout);
+ 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);
+ amdxdna_umap_put(mapp);
+ mmput(mm);
+ goto again;
+ }
+ mapp->invalid = false;
+ up_write(&xdna->notifier_lock);
+ amdxdna_umap_put(mapp);
+ mmput(mm);
+ goto again;
+
+put_mm:
+ amdxdna_umap_put(mapp);
+ mmput(mm);
+ return ret == -EBUSY ? -ETIME : ret;
+}
+
static void amdxdna_hmm_unreg_work(struct work_struct *work)
{
struct amdxdna_gem_obj *abo = container_of(work, struct amdxdna_gem_obj,
diff --git a/drivers/accel/amdxdna/amdxdna_gem.h b/drivers/accel/amdxdna/amdxdna_gem.h
index 9b4aa21a37c9..977548e19ae4 100644
--- a/drivers/accel/amdxdna/amdxdna_gem.h
+++ b/drivers/accel/amdxdna/amdxdna_gem.h
@@ -103,6 +103,7 @@ static inline u64 amdxdna_obj_dma_addr(struct amdxdna_gem_obj *abo)
}
void amdxdna_umap_put(struct amdxdna_umap *mapp);
+int amdxdna_populate_range(struct amdxdna_gem_obj *abo);
void amdxdna_gem_heap_free(struct amdxdna_client *client, struct amdxdna_gem_obj *abo);
struct drm_gem_object *
--
2.34.1
next prev parent reply other threads:[~2026-10-08 3:24 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 3:23 [PATCH V3 00/19] accel/amdxdna: Kernel submission and PM for AIE4 David Zhang
2026-10-08 3:23 ` [PATCH V3 01/19] accel/amdxdna: Rename NPU3 firmware files David Zhang
2026-10-08 16:23 ` Lizhi Hou
2026-10-08 3:23 ` [PATCH V3 02/19] accel/amdxdna: Remove mmap for doorbell David Zhang
2026-10-08 3:23 ` [PATCH V3 03/19] accel/amdxdna: Add CERT firmware version support David Zhang
2026-10-08 17:12 ` Lizhi Hou
2026-10-08 17:26 ` Zhang, Yidong (David)
2026-10-08 3:23 ` [PATCH V3 04/19] accel/amdxdna: Upgrade firmware version to 6.0 David Zhang
2026-10-08 17:15 ` Lizhi Hou
2026-10-08 3:23 ` [PATCH V3 05/19] accel/amdxdna: Add NPU3 classic device support David Zhang
2026-10-08 3:23 ` [PATCH V3 06/19] accel/amdxdna: Add AIE version query to aie4_get_info David Zhang
2026-10-08 3:23 ` [PATCH V3 07/19] accel/amdxdna: Add get and set power_mode for AIE4 David Zhang
2026-10-08 3:23 ` [PATCH V3 08/19] accel/amdxdna: Add clock, DPM frequency, and resource info queries " David Zhang
2026-10-08 3:23 ` [PATCH V3 09/19] accel/amdxdna: Add context switch hysteresis with debugfs control David Zhang
2026-10-08 3:23 ` [PATCH V3 10/19] accel/amdxdna: Refactor AIE4 hardware initialization sequence David Zhang
2026-10-08 3:23 ` [PATCH V3 11/19] accel/amdxdna: Decouple AIE4 doorbell and MSI-X notify transport hooks David Zhang
2026-10-08 3:23 ` [PATCH V3 12/19] accel/amdxdna: Implement AIE4 kernel queue lifecycle and memory layout David Zhang
2026-10-08 3:23 ` [PATCH V3 13/19] accel/amdxdna: Prepare for AIE4 command submission David Zhang
2026-10-08 3:23 ` [PATCH V3 14/19] accel/amdxdna: Move HMM invalidate wait into common GEM code David Zhang
2026-10-08 3:23 ` David Zhang [this message]
2026-10-08 3:23 ` [PATCH V3 16/19] accel/amdxdna: Implement AIE4 command packet building and submission David Zhang
2026-10-08 3:23 ` [PATCH V3 17/19] accel/amdxdna: Enable AIE4 firmware logging to DRAM David Zhang
2026-10-08 3:23 ` [PATCH V3 18/19] accel/amdxdna: Implement AIE4 suspend and resume David Zhang
2026-10-08 3:23 ` [PATCH V3 19/19] accel/amdxdna: Implement runtime suspend and resume support David Zhang
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=20261008032348.2044667-16-yidong.zhang@amd.com \
--to=yidong.zhang@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=karol.wachowski@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizhi.hou@amd.com \
--cc=mario.limonciello@amd.com \
--cc=max.zhen@amd.com \
--cc=ogabbay@kernel.org \
--cc=quic_jhugo@quicinc.com \
--cc=sonal.santan@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
all inboxes | Powered by JetHome®