Skip to content

Commit 75af0a5

Browse files
Pranjal Ramajor Asha Kanojiyaquic-jhugo
authored andcommitted
accel/qaic: Grab ch_lock during QAIC_ATTACH_SLICE_BO
During QAIC_ATTACH_SLICE_BO, we associate a BO to its DBC. We need to grab the dbc->ch_lock to make sure that DBC does not goes away while QAIC_ATTACH_SLICE_BO is still running. Fixes: ff13be8 ("accel/qaic: Add datapath") Signed-off-by: Pranjal Ramajor Asha Kanojiya <[email protected]> Reviewed-by: Carl Vanderlip <[email protected]> Reviewed-by: Jeffrey Hugo <[email protected]> Signed-off-by: Jeffrey Hugo <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent faa7c4e commit 75af0a5

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/accel/qaic/qaic_data.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -924,8 +924,8 @@ int qaic_attach_slice_bo_ioctl(struct drm_device *dev, void *data, struct drm_fi
924924
{
925925
struct qaic_attach_slice_entry *slice_ent;
926926
struct qaic_attach_slice *args = data;
927+
int rcu_id, usr_rcu_id, qdev_rcu_id;
927928
struct dma_bridge_chan *dbc;
928-
int usr_rcu_id, qdev_rcu_id;
929929
struct drm_gem_object *obj;
930930
struct qaic_device *qdev;
931931
unsigned long arg_size;
@@ -969,12 +969,6 @@ int qaic_attach_slice_bo_ioctl(struct drm_device *dev, void *data, struct drm_fi
969969
goto unlock_dev_srcu;
970970
}
971971

972-
dbc = &qdev->dbc[args->hdr.dbc_id];
973-
if (dbc->usr != usr) {
974-
ret = -EINVAL;
975-
goto unlock_dev_srcu;
976-
}
977-
978972
user_data = u64_to_user_ptr(args->data);
979973

980974
slice_ent = kzalloc(arg_size, GFP_KERNEL);
@@ -1006,9 +1000,16 @@ int qaic_attach_slice_bo_ioctl(struct drm_device *dev, void *data, struct drm_fi
10061000
goto put_bo;
10071001
}
10081002

1003+
dbc = &qdev->dbc[args->hdr.dbc_id];
1004+
rcu_id = srcu_read_lock(&dbc->ch_lock);
1005+
if (dbc->usr != usr) {
1006+
ret = -EINVAL;
1007+
goto unlock_ch_srcu;
1008+
}
1009+
10091010
ret = qaic_prepare_bo(qdev, bo, &args->hdr);
10101011
if (ret)
1011-
goto put_bo;
1012+
goto unlock_ch_srcu;
10121013

10131014
ret = qaic_attach_slicing_bo(qdev, bo, &args->hdr, slice_ent);
10141015
if (ret)
@@ -1018,6 +1019,7 @@ int qaic_attach_slice_bo_ioctl(struct drm_device *dev, void *data, struct drm_fi
10181019
dma_sync_sgtable_for_cpu(&qdev->pdev->dev, bo->sgt, args->hdr.dir);
10191020

10201021
bo->dbc = dbc;
1022+
srcu_read_unlock(&dbc->ch_lock, rcu_id);
10211023
drm_gem_object_put(obj);
10221024
srcu_read_unlock(&qdev->dev_lock, qdev_rcu_id);
10231025
srcu_read_unlock(&usr->qddev_lock, usr_rcu_id);
@@ -1026,6 +1028,8 @@ int qaic_attach_slice_bo_ioctl(struct drm_device *dev, void *data, struct drm_fi
10261028

10271029
unprepare_bo:
10281030
qaic_unprepare_bo(qdev, bo);
1031+
unlock_ch_srcu:
1032+
srcu_read_unlock(&dbc->ch_lock, rcu_id);
10291033
put_bo:
10301034
drm_gem_object_put(obj);
10311035
free_slice_ent:

0 commit comments

Comments
 (0)