From e4247367325a5aa175be7f762dc0a5303e0c620b Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Mon, 26 Feb 2024 14:50:40 +0800 Subject: [PATCH] video: rockchip: mpp: rkvenc2: Fix rw_sem error Use the pointer copy to replace rwsem entry copy. https://redmine.rock-chips.com/issues/461476 DEBUG_RWSEMS_WARN_ON(sem->magic != sem): count = 0x100, magic = 0xffffff81036e2a80, owner = 0xffffff81037f8001, curr 0xffffff81037f8000, list not empty WARNING: CPU: 0 PID: 171 at kernel/locking/rwsem.c:1468 __up_read+0x1dc/0x264 Modules linked in: bcmdhd(O) dhd_static_buf CPU: 0 PID: 171 Comm: irq/47-fdbe0000 Tainted: G O 5.10.160 #13 Hardware name: Rockchip RK3588S TABLET V11 Board (DT) pstate: 60c00009 (nZCv daif +PAN +UAO TCO BTYPE=-) pc : __up_read+0x1dc/0x264 lr : __up_read+0x1dc/0x264 sp : ffffffc00ca83bb0 x29: ffffffc00ca83bb0 x28: 0000000000000000 x27: ffffffc0080e1000 x26: ffffffc0080e16e0 x25: ffffffc0080e17c0 x24: ffffff8103504080 x23: ffffff8299eeec00 x22: ffffff817ecf8038 x21: ffffff817ecf8088 x20: ffffffc00a725000 x19: ffffff81036e3280 x18: 0000000000000030 x17: 0000000000004d49 x16: 0000000000021f36 x15: ffffffc00a746570 x14: 0000000000000086 x13: ffffffc00964a930 x12: 0000000000000003 x11: fffffffffffe5a28 x10: fffffffffffe5a08 x9 : ffffffc0081b3290 x8 : ffffffc00a748b78 x7 : ffffffc00a7f8b78 x6 : 0000000000000001 x5 : 0000000000000000 x4 : ffffff84fd5b5df8 x3 : ffffff84fd5c6730 x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffffff81037f8000 Call trace: __up_read+0x1dc/0x264 up_read+0x44/0x70 mpp_task_finalize+0x6c/0xb4 rkvenc_free_task+0x20/0x7c mpp_free_task+0x50/0x114 mpp_taskqueue_pop_running.isra.0+0x80/0xbc mpp_task_finish+0xb8/0x180 rkvenc_isr+0xd0/0x2ec mpp_dev_isr_sched+0x70/0xd0 irq_thread_fn+0x30/0xa0 irq_thread+0x1d4/0x2d0 kthread+0x150/0x154 ret_from_fork+0x10/0x1c Fixes: 99582ba73a65 ("video: rockchip: mpp: rkvenc2: Fix dual core issue") Signed-off-by: Herman Chen Change-Id: Id3ecd4b03a9676183a80774fd571f86918281cb9 --- drivers/video/rockchip/mpp/mpp_iommu.c | 3 ++- drivers/video/rockchip/mpp/mpp_iommu.h | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/video/rockchip/mpp/mpp_iommu.c b/drivers/video/rockchip/mpp/mpp_iommu.c index 1abbfb74f4e2..b19da6e67c0a 100644 --- a/drivers/video/rockchip/mpp/mpp_iommu.c +++ b/drivers/video/rockchip/mpp/mpp_iommu.c @@ -529,7 +529,8 @@ mpp_iommu_probe(struct device *dev) goto err_put_group; } - init_rwsem(&info->rw_sem); + init_rwsem(&info->rw_sem_self); + info->rw_sem = &info->rw_sem_self; spin_lock_init(&info->dev_lock); info->dev = dev; info->pdev = pdev; diff --git a/drivers/video/rockchip/mpp/mpp_iommu.h b/drivers/video/rockchip/mpp/mpp_iommu.h index 87d1b5c612d2..2787fc069df7 100644 --- a/drivers/video/rockchip/mpp/mpp_iommu.h +++ b/drivers/video/rockchip/mpp/mpp_iommu.h @@ -68,7 +68,8 @@ struct mpp_rk_iommu { struct mpp_dev; struct mpp_iommu_info { - struct rw_semaphore rw_sem; + struct rw_semaphore *rw_sem; + struct rw_semaphore rw_sem_self; struct device *dev; struct platform_device *pdev; @@ -126,7 +127,7 @@ int mpp_iommu_dev_deactivate(struct mpp_iommu_info *info, struct mpp_dev *dev); static inline int mpp_iommu_down_read(struct mpp_iommu_info *info) { if (info) - down_read(&info->rw_sem); + down_read(info->rw_sem); return 0; } @@ -134,7 +135,7 @@ static inline int mpp_iommu_down_read(struct mpp_iommu_info *info) static inline int mpp_iommu_up_read(struct mpp_iommu_info *info) { if (info) - up_read(&info->rw_sem); + up_read(info->rw_sem); return 0; } @@ -142,7 +143,7 @@ static inline int mpp_iommu_up_read(struct mpp_iommu_info *info) static inline int mpp_iommu_down_write(struct mpp_iommu_info *info) { if (info) - down_write(&info->rw_sem); + down_write(info->rw_sem); return 0; } @@ -150,7 +151,7 @@ static inline int mpp_iommu_down_write(struct mpp_iommu_info *info) static inline int mpp_iommu_up_write(struct mpp_iommu_info *info) { if (info) - up_write(&info->rw_sem); + up_write(info->rw_sem); return 0; }