On 5/25/2023 6:23 AM, Sergey Senozhatsky wrote: > On (23/05/24 22:06), Vikash Garodia wrote: >>> Instead the struct v4l2_m2m_ctx q_lock pointer, if set, will use that >>> mutex for all vb2 operations. >>> >>> I think you can set it to the 'lock' mutex in struct venus_inst. >> >> IIUC, the suggestion is to use the 'lock' in struct venus_inst while >> initializing the queue. This might lead to deadlock as the same lock is used >> during vb2 operations in driver. Might be introducing a new lock for this >> purpose in struct venus_inst would do, unless we are trying to serialize at >> video device (or core) context. > > Something like this? > > Video device has to provide a lock so that __video_do_ioctl() > can serialize IOCTL calls. Introduce a dedicated venus_inst > mutex (which is set a ctx ->q_lock) for the purpose of vb2 > operations synchronization. > > Signed-off-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx> > --- > drivers/media/platform/qcom/venus/core.h | 2 ++ > drivers/media/platform/qcom/venus/vdec.c | 4 ++++ > drivers/media/platform/qcom/venus/venc.c | 3 +++ > 3 files changed, 9 insertions(+) > > diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h > index 4f81669986ba..6ac5236d6888 100644 > --- a/drivers/media/platform/qcom/venus/core.h > +++ b/drivers/media/platform/qcom/venus/core.h > @@ -389,6 +389,7 @@ enum venus_inst_modes { > * @sequence_out: a sequence counter for output queue > * @m2m_dev: a reference to m2m device structure > * @m2m_ctx: a reference to m2m context structure > + * @ctx_queue_lock: a lock to serialize video device ioctl calls suggestion: we can keep this as ctx_q_lock. > * @state: current state of the instance > * @done: a completion for sync HFI operation > * @error: an error returned during last HFI sync operation > @@ -460,6 +461,7 @@ struct venus_inst { > u32 sequence_out; > struct v4l2_m2m_dev *m2m_dev; > struct v4l2_m2m_ctx *m2m_ctx; > + struct mutex ctx_queue_lock; > unsigned int state; > struct completion done; > unsigned int error; > diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c > index 51a53bf82bd3..2caeba5b6378 100644 > --- a/drivers/media/platform/qcom/venus/vdec.c > +++ b/drivers/media/platform/qcom/venus/vdec.c > @@ -1641,6 +1641,7 @@ static int vdec_open(struct file *file) > INIT_LIST_HEAD(&inst->internalbufs); > INIT_LIST_HEAD(&inst->list); > mutex_init(&inst->lock); > + mutex_init(&inst->ctx_queue_lock); > > inst->core = core; > inst->session_type = VIDC_SESSION_TYPE_DEC; > @@ -1684,8 +1685,10 @@ static int vdec_open(struct file *file) > goto err_m2m_release; > } > > + > v4l2_fh_init(&inst->fh, core->vdev_dec); > > + inst->m2m_ctx->q_lock = &inst->ctx_queue_lock; Better to do this in queue_init callback i.e "m2m_queue_init" in vdec.c. src_vq->lock = &inst->ctx_q_lock; ... dst_vq->lock = src_vq->lock; > inst->fh.ctrl_handler = &inst->ctrl_handler; > v4l2_fh_add(&inst->fh); > inst->fh.m2m_ctx = inst->m2m_ctx; > @@ -1716,6 +1719,7 @@ static int vdec_close(struct file *file) > ida_destroy(&inst->dpb_ids); > hfi_session_destroy(inst); > mutex_destroy(&inst->lock); > + mutex_destroy(&inst->ctx_queue_lock); > v4l2_fh_del(&inst->fh); > v4l2_fh_exit(&inst->fh); > > diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c > index 4666f42feea3..4292b299f014 100644 > --- a/drivers/media/platform/qcom/venus/venc.c > +++ b/drivers/media/platform/qcom/venus/venc.c > @@ -1443,6 +1443,7 @@ static int venc_open(struct file *file) > INIT_LIST_HEAD(&inst->internalbufs); > INIT_LIST_HEAD(&inst->list); > mutex_init(&inst->lock); > + mutex_init(&inst->ctx_queue_lock); > > inst->core = core; > inst->session_type = VIDC_SESSION_TYPE_ENC; > @@ -1483,6 +1484,7 @@ static int venc_open(struct file *file) > > v4l2_fh_init(&inst->fh, core->vdev_enc); > > + inst->m2m_ctx->q_lock = &inst->ctx_queue_lock; Same comment applies here. This can be moved to "m2m_queue_init" in venc.c. > inst->fh.ctrl_handler = &inst->ctrl_handler; > v4l2_fh_add(&inst->fh); > inst->fh.m2m_ctx = inst->m2m_ctx; > @@ -1512,6 +1514,7 @@ static int venc_close(struct file *file) > venc_ctrl_deinit(inst); > hfi_session_destroy(inst); > mutex_destroy(&inst->lock); > + mutex_destroy(&inst->ctx_queue_lock); > v4l2_fh_del(&inst->fh); > v4l2_fh_exit(&inst->fh); >