]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
accel/amdxdna: Hold mm structure across iommu_sva_unbind_device()
authorLizhi Hou <lizhi.hou@amd.com>
Wed, 28 Jan 2026 00:23:56 +0000 (16:23 -0800)
committerLizhi Hou <lizhi.hou@amd.com>
Fri, 30 Jan 2026 19:52:45 +0000 (11:52 -0800)
Some tests trigger a crash in iommu_sva_unbind_device() due to
accessing iommu_mm after the associated mm structure has been
freed.

Fix this by taking an explicit reference to the mm structure
after successfully binding the device, and releasing it only
after the device is unbound. This ensures the mm remains valid
for the entire SVA bind/unbind lifetime.

Fixes: be462c97b7df ("accel/amdxdna: Add hardware context")
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Link: https://patch.msgid.link/20260128002356.1858122-1-lizhi.hou@amd.com
drivers/accel/amdxdna/amdxdna_pci_drv.c
drivers/accel/amdxdna/amdxdna_pci_drv.h

index 45f5c12fc67fbf96667e5fbf37321c631c56dd5a..fdefd9ec206688e47ed65b090dc8654790093bae 100644 (file)
@@ -82,6 +82,8 @@ static int amdxdna_drm_open(struct drm_device *ddev, struct drm_file *filp)
                ret = -ENODEV;
                goto unbind_sva;
        }
+       client->mm = current->mm;
+       mmgrab(client->mm);
        init_srcu_struct(&client->hwctx_srcu);
        xa_init_flags(&client->hwctx_xa, XA_FLAGS_ALLOC);
        mutex_init(&client->mm_lock);
@@ -116,6 +118,7 @@ static void amdxdna_client_cleanup(struct amdxdna_client *client)
                drm_gem_object_put(to_gobj(client->dev_heap));
 
        iommu_sva_unbind_device(client->sva);
+       mmdrop(client->mm);
 
        kfree(client);
 }
index 6580cb5ec7e2f6c0105789efb47f13bca0ca2fa0..f08406b8fdf93965b6c7f8d69205e77277b03f62 100644 (file)
@@ -130,6 +130,7 @@ struct amdxdna_client {
 
        struct iommu_sva                *sva;
        int                             pasid;
+       struct mm_struct                *mm;
 };
 
 #define amdxdna_for_each_hwctx(client, hwctx_id, entry)                \