]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
accel/amdxdna: Skip unmapped range in aie2_populate_range()
authorLizhi Hou <lizhi.hou@amd.com>
Wed, 12 Aug 2026 20:56:28 +0000 (13:56 -0700)
committerLizhi Hou <lizhi.hou@amd.com>
Thu, 13 Aug 2026 06:12:20 +0000 (23:12 -0700)
aie2_populate_range() incorrectly failed jobs for BOs with multiple
mmaps: if the unmapped entry appeared first in umap_list, the loop would
pick it up, call hmm_range_fault() on a gone VMA, and return -EFAULT
without ever trying the remaining valid mapps.

Fix it by skipping unmapped entries. After the loop, if the map list is
empty or all maps are valid, map_invalid can be cleared normally.

Fixes: e486147c912f ("accel/amdxdna: Add BO import and export")
Reviewed-by: Max Zhen <max.zhen@amd.com>
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Link: https://patch.msgid.link/20260812205628.810816-1-lizhi.hou@amd.com
drivers/accel/amdxdna/aie2_ctx.c

index 2b97d9707129da9f3732c5b5ea27922acf5d4203..b713a57b3a3b01b692d8f3e9f4ca992e975aec57 100644 (file)
@@ -1053,6 +1053,16 @@ 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;
@@ -1060,6 +1070,12 @@ again:
        }
 
        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;