Skip to content

Commit a916243

Browse files
committed
accel/amdxdna: Hold mm structure across iommu_sva_unbind_device()
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: be462c9 ("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
1 parent db7e7ea commit a916243

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/accel/amdxdna/amdxdna_pci_drv.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ static int amdxdna_drm_open(struct drm_device *ddev, struct drm_file *filp)
8282
ret = -ENODEV;
8383
goto unbind_sva;
8484
}
85+
client->mm = current->mm;
86+
mmgrab(client->mm);
8587
init_srcu_struct(&client->hwctx_srcu);
8688
xa_init_flags(&client->hwctx_xa, XA_FLAGS_ALLOC);
8789
mutex_init(&client->mm_lock);
@@ -116,6 +118,7 @@ static void amdxdna_client_cleanup(struct amdxdna_client *client)
116118
drm_gem_object_put(to_gobj(client->dev_heap));
117119

118120
iommu_sva_unbind_device(client->sva);
121+
mmdrop(client->mm);
119122

120123
kfree(client);
121124
}

drivers/accel/amdxdna/amdxdna_pci_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ struct amdxdna_client {
130130

131131
struct iommu_sva *sva;
132132
int pasid;
133+
struct mm_struct *mm;
133134
};
134135

135136
#define amdxdna_for_each_hwctx(client, hwctx_id, entry) \

0 commit comments

Comments
 (0)