diff mbox series

[v7,1/5] media: mediatek: vcodec: support manual request completion

Message ID 20241116031724.15694-2-yunfei.dong@mediatek.com
State New
Headers show
Series media: mediatek: vcodec: fix v4l2_ctrl_request_complete fail | expand

Commit Message

Yunfei Dong Nov. 16, 2024, 3:17 a.m. UTC
There is only a buffer object for some codecs, the request is marked
as completed if the buffer is set to done. Framework will add a new
control handler object to the request with latest control values, will
get below warning if the driver calling v4l2_ctrl_request_complete to
set media request complete again. Using manual request completion to
fix this issue.

Workqueue: core-decoder vdec_msg_queue_core_work [mtk_vcodec_dec]
pstate: 80c00089 (Nzcv daIf +PAN +UAO -TCO BTYPE=--)
pc : media_request_object_bind+0xa8/0x124
lr : media_request_object_bind+0x50/0x124
sp : ffffffc011393be0
x29: ffffffc011393be0 x28: 0000000000000000
x27: ffffff890c280248 x26: ffffffe21a71ab88
x25: 0000000000000000 x24: ffffff890c280280
x23: ffffff890c280280 x22: 00000000fffffff0
x21: 0000000000000000 x20: ffffff890260d280
x19: ffffff890260d2e8 x18: 0000000000001000
x17: 0000000000000400 x16: ffffffe21a4584a0
x15: 000000000053361d x14: 0000000000000018
x13: 0000000000000004 x12: ffffffa82427d000
x11: ffffffe21ac3fce0 x10: 0000000000000001
x9 : 0000000000000000 x8 : 0000000000000003
x7 : 0000000000000000 x6 : 000000000000003f
x5 : 0000000000000040 x4 : ffffff89052e7b98
x3 : 0000000000000000 x2 : 0000000000000001
x1 : 0000000000000000 x0 : 0000000000000000
Call trace:
 media_request_object_bind+0xa8/0x124
 v4l2_ctrl_request_bind+0xc4/0x168
 v4l2_ctrl_request_complete+0x198/0x1f4
 mtk_vdec_stateless_cap_to_disp+0x58/0x8c [mtk_vcodec_dec 245a7c1e48ff1b2451a50e1dfcb174262b6b462c]
 vdec_vp9_slice_core_decode+0x1c0/0x268 [mtk_vcodec_dec 245a7c1e48ff1b2451a50e1dfcb174262b6b462c]
 vdec_msg_queue_core_work+0x60/0x11c [mtk_vcodec_dec 245a7c1e48ff1b2451a50e1dfcb174262b6b462c]
 process_one_work+0x140/0x480
 worker_thread+0x12c/0x2f8
 kthread+0x13c/0x1d8
 ret_from_fork+0x10/0x30

Fixes: 7b182b8d9c852 ("media: mediatek: vcodec: Refactor get and put capture buffer flow")
Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
---
 .../mediatek/vcodec/decoder/mtk_vcodec_dec.c    |  8 +++++---
 .../vcodec/decoder/mtk_vcodec_dec_stateless.c   | 17 ++++++++++++++---
 2 files changed, 19 insertions(+), 6 deletions(-)

Comments

Sebastian Fricke Nov. 26, 2024, 8:04 a.m. UTC | #1
Hey Yunfei,

On 16.11.2024 11:17, Yunfei Dong wrote:
>There is only a buffer object for some codecs, the request is marked
>as completed if the buffer is set to done. Framework will add a new
>control handler object to the request with latest control values, will
>get below warning if the driver calling v4l2_ctrl_request_complete to
>set media request complete again. Using manual request completion to
>fix this issue.

Thank you for working on this.
I am currently working on this as well, so I would like to ask you for a
bit more patience, once I am finished with my testing and have a working
patch I'll send that patch and then we can discuss on the basis of that.

Regards,
Sebastian

>
>Workqueue: core-decoder vdec_msg_queue_core_work [mtk_vcodec_dec]
>pstate: 80c00089 (Nzcv daIf +PAN +UAO -TCO BTYPE=--)
>pc : media_request_object_bind+0xa8/0x124
>lr : media_request_object_bind+0x50/0x124
>sp : ffffffc011393be0
>x29: ffffffc011393be0 x28: 0000000000000000
>x27: ffffff890c280248 x26: ffffffe21a71ab88
>x25: 0000000000000000 x24: ffffff890c280280
>x23: ffffff890c280280 x22: 00000000fffffff0
>x21: 0000000000000000 x20: ffffff890260d280
>x19: ffffff890260d2e8 x18: 0000000000001000
>x17: 0000000000000400 x16: ffffffe21a4584a0
>x15: 000000000053361d x14: 0000000000000018
>x13: 0000000000000004 x12: ffffffa82427d000
>x11: ffffffe21ac3fce0 x10: 0000000000000001
>x9 : 0000000000000000 x8 : 0000000000000003
>x7 : 0000000000000000 x6 : 000000000000003f
>x5 : 0000000000000040 x4 : ffffff89052e7b98
>x3 : 0000000000000000 x2 : 0000000000000001
>x1 : 0000000000000000 x0 : 0000000000000000
>Call trace:
> media_request_object_bind+0xa8/0x124
> v4l2_ctrl_request_bind+0xc4/0x168
> v4l2_ctrl_request_complete+0x198/0x1f4
> mtk_vdec_stateless_cap_to_disp+0x58/0x8c [mtk_vcodec_dec 245a7c1e48ff1b2451a50e1dfcb174262b6b462c]
> vdec_vp9_slice_core_decode+0x1c0/0x268 [mtk_vcodec_dec 245a7c1e48ff1b2451a50e1dfcb174262b6b462c]
> vdec_msg_queue_core_work+0x60/0x11c [mtk_vcodec_dec 245a7c1e48ff1b2451a50e1dfcb174262b6b462c]
> process_one_work+0x140/0x480
> worker_thread+0x12c/0x2f8
> kthread+0x13c/0x1d8
> ret_from_fork+0x10/0x30
>
>Fixes: 7b182b8d9c852 ("media: mediatek: vcodec: Refactor get and put capture buffer flow")
>Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
>---
> .../mediatek/vcodec/decoder/mtk_vcodec_dec.c    |  8 +++++---
> .../vcodec/decoder/mtk_vcodec_dec_stateless.c   | 17 ++++++++++++++---
> 2 files changed, 19 insertions(+), 6 deletions(-)
>
>diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
>index 98838217b97d..d2146724f5de 100644
>--- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
>+++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
>@@ -887,10 +887,12 @@ void vb2ops_vdec_stop_streaming(struct vb2_queue *q)
> 			if (src_buf != &ctx->empty_flush_buf.vb) {
> 				struct media_request *req =
> 					src_buf->vb2_buf.req_obj.req;
>-				v4l2_m2m_buf_done(src_buf,
>-						VB2_BUF_STATE_ERROR);
>-				if (req)
>+
>+				v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR);
>+				if (req) {
> 					v4l2_ctrl_request_complete(req, &ctx->ctrl_hdl);
>+					media_request_manual_complete(req);
>+				}
> 			}
> 		}
> 		return;
>diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
>index afa224da0f41..1e11c08d708f 100644
>--- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
>+++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
>@@ -264,8 +264,10 @@ static void mtk_vdec_stateless_cap_to_disp(struct mtk_vcodec_dec_ctx *ctx, int e
> 		mtk_v4l2_vdec_err(ctx, "dst buffer is NULL");
> 	}
>
>-	if (src_buf_req)
>+	if (src_buf_req) {
> 		v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl);
>+		media_request_manual_complete(src_buf_req);
>+	}
> }
>
> static struct vdec_fb *vdec_get_cap_buffer(struct mtk_vcodec_dec_ctx *ctx)
>@@ -308,6 +310,7 @@ static void vb2ops_vdec_buf_request_complete(struct vb2_buffer *vb)
> 	struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
>
> 	v4l2_ctrl_request_complete(vb->req_obj.req, &ctx->ctrl_hdl);
>+	media_request_manual_complete(vb->req_obj.req);
> }
>
> static void mtk_vdec_worker(struct work_struct *work)
>@@ -375,8 +378,10 @@ static void mtk_vdec_worker(struct work_struct *work)
> 	if (!IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch) ||
> 	    ctx->current_codec == V4L2_PIX_FMT_VP8_FRAME) {
> 		v4l2_m2m_buf_done_and_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx, state);
>-		if (src_buf_req)
>+		if (src_buf_req) {
> 			v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl);
>+			media_request_manual_complete(src_buf_req);
>+		}
> 	} else {
> 		if (ret != -EAGAIN) {
> 			v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
>@@ -731,9 +736,15 @@ static int fops_media_request_validate(struct media_request *mreq)
> 	return vb2_request_validate(mreq);
> }
>
>+static void fops_media_request_queue(struct media_request *req)
>+{
>+	media_request_mark_manual_completion(req);
>+	v4l2_m2m_request_queue(req);
>+}
>+
> const struct media_device_ops mtk_vcodec_media_ops = {
> 	.req_validate	= fops_media_request_validate,
>-	.req_queue	= v4l2_m2m_request_queue,
>+	.req_queue	= fops_media_request_queue,
> };
>
> static void mtk_vcodec_add_formats(unsigned int fourcc,
>-- 
>2.46.0
>
>
diff mbox series

Patch

diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
index 98838217b97d..d2146724f5de 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
@@ -887,10 +887,12 @@  void vb2ops_vdec_stop_streaming(struct vb2_queue *q)
 			if (src_buf != &ctx->empty_flush_buf.vb) {
 				struct media_request *req =
 					src_buf->vb2_buf.req_obj.req;
-				v4l2_m2m_buf_done(src_buf,
-						VB2_BUF_STATE_ERROR);
-				if (req)
+
+				v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR);
+				if (req) {
 					v4l2_ctrl_request_complete(req, &ctx->ctrl_hdl);
+					media_request_manual_complete(req);
+				}
 			}
 		}
 		return;
diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
index afa224da0f41..1e11c08d708f 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
@@ -264,8 +264,10 @@  static void mtk_vdec_stateless_cap_to_disp(struct mtk_vcodec_dec_ctx *ctx, int e
 		mtk_v4l2_vdec_err(ctx, "dst buffer is NULL");
 	}
 
-	if (src_buf_req)
+	if (src_buf_req) {
 		v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl);
+		media_request_manual_complete(src_buf_req);
+	}
 }
 
 static struct vdec_fb *vdec_get_cap_buffer(struct mtk_vcodec_dec_ctx *ctx)
@@ -308,6 +310,7 @@  static void vb2ops_vdec_buf_request_complete(struct vb2_buffer *vb)
 	struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
 
 	v4l2_ctrl_request_complete(vb->req_obj.req, &ctx->ctrl_hdl);
+	media_request_manual_complete(vb->req_obj.req);
 }
 
 static void mtk_vdec_worker(struct work_struct *work)
@@ -375,8 +378,10 @@  static void mtk_vdec_worker(struct work_struct *work)
 	if (!IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch) ||
 	    ctx->current_codec == V4L2_PIX_FMT_VP8_FRAME) {
 		v4l2_m2m_buf_done_and_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx, state);
-		if (src_buf_req)
+		if (src_buf_req) {
 			v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl);
+			media_request_manual_complete(src_buf_req);
+		}
 	} else {
 		if (ret != -EAGAIN) {
 			v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
@@ -731,9 +736,15 @@  static int fops_media_request_validate(struct media_request *mreq)
 	return vb2_request_validate(mreq);
 }
 
+static void fops_media_request_queue(struct media_request *req)
+{
+	media_request_mark_manual_completion(req);
+	v4l2_m2m_request_queue(req);
+}
+
 const struct media_device_ops mtk_vcodec_media_ops = {
 	.req_validate	= fops_media_request_validate,
-	.req_queue	= v4l2_m2m_request_queue,
+	.req_queue	= fops_media_request_queue,
 };
 
 static void mtk_vcodec_add_formats(unsigned int fourcc,