From d9794ef01e6e7a2baddc0466192f53c90d6fb0d3 Mon Sep 17 00:00:00 2001 From: Yandong Lin Date: Mon, 6 Nov 2023 16:03:36 +0800 Subject: [PATCH] video: rockchip: mpp: fix rkvenc2 run crash issue Calling an interface containing mutex lock after schedule_preempt_disabled caused the problem. Call trace: dump_backtrace+0xf4/0x118 show_stack+0x18/0x24 dump_stack_lvl+0x60/0x7c dump_stack+0x18/0x3c __schedule_bug+0x6c/0x8c __schedule+0x64c/0x9cc schedule+0x7c/0xe8 schedule_preempt_disabled+0x24/0x40 __mutex_lock+0x224/0xdac __mutex_lock_slowpath+0x14/0x24 mutex_lock+0x40/0xec clk_get_rate+0x50/0x134 rkvenc_run+0x4ec/0x728 [rk_vcodec] mpp_task_worker_default+0x2b4/0x494 [rk_vcodec] kthread_worker_fn+0x10c/0x244 kthread+0x104/0x1d4 ret_from_fork+0x10/0x20 Fixes: ca7fd6569330 ("video: rockchip: mpp: rkvenc2: optimize iommu fault handle") Signed-off-by: Yandong Lin Change-Id: I1bceea441495a1c6c94776a648601d670b7a29d2 --- drivers/video/rockchip/mpp/mpp_rkvenc2.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/video/rockchip/mpp/mpp_rkvenc2.c b/drivers/video/rockchip/mpp/mpp_rkvenc2.c index fc55395dafc0..ce60a15c838b 100644 --- a/drivers/video/rockchip/mpp/mpp_rkvenc2.c +++ b/drivers/video/rockchip/mpp/mpp_rkvenc2.c @@ -1246,11 +1246,6 @@ static int rkvenc_run(struct mpp_dev *mpp, struct mpp_task *mpp_task) /* init current task */ mpp->cur_task = mpp_task; - mpp_task_run_begin(mpp_task, timing_en, MPP_WORK_TIMEOUT_DELAY); - - /* Flush the register before the start the device */ - wmb(); - /* * reconfig timeout threshold. * bit0-bit23,x1024 core clk cycles @@ -1258,6 +1253,11 @@ static int rkvenc_run(struct mpp_dev *mpp, struct mpp_task *mpp_task) timeout_thd = mpp_read(mpp, RKVENC_WDG) & 0xff000000; timeout_thd |= TIMEOUT_MS * clk_get_rate(enc->core_clk_info.clk) / 1024000; mpp_write(mpp, RKVENC_WDG, timeout_thd); + + mpp_task_run_begin(mpp_task, timing_en, MPP_WORK_TIMEOUT_DELAY); + + /* Flush the register before the start the device */ + wmb(); mpp_write(mpp, enc->hw_info->enc_start_base, start_val); mpp_task_run_end(mpp_task, timing_en);