* [PATCH v2 0/3] Fix sleeping function called from invalid context
@ 2025-08-29 9:15 Jason-JH Lin
2025-08-29 9:15 ` [PATCH v2 1/3] mailbox: mtk-cmdq: Remove pm_runtime APIs from cmdq_mbox_send_data() Jason-JH Lin
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jason-JH Lin @ 2025-08-29 9:15 UTC (permalink / raw)
To: Chun-Kuang Hu, AngeloGioacchino Del Regno, Jassi Brar,
Mauro Carvalho Chehab
Cc: Philipp Zabel, David Airlie, Simona Vetter, Jason-JH Lin,
Nancy Lin, Singo Chang, Paul-PL Chen, Yongqiang Niu, Zhenxing Qin,
Xiandong Wang, Sirius Wang, Xavier Chang, Jarried Lin, Fei Shao,
Chen-yu Tsai, Project_Global_Chrome_Upstream_Group, dri-devel,
linux-mediatek, linux-kernel, linux-arm-kernel, linux-media
We found that there is a spin_lock_irqsave protection in msg_submit()
of mailbox.c and it is in the atomic context.
So when the mailbox controller driver calls pm_runtime_get_sync() in
mbox_chan_ops->send_data(), it will get this BUG report.
"BUG: sleeping function called from invalid context at drivers/base/power/runtime.c:1164"
Additionally, pm_runtime_put_autosuspend() should be invoked from the
GCE IRQ handler to ensure the hardware has actually completed its work.
To resolve these issues, remove the pm_runtime calls from
cmdq_mbox_send_data() and delegate power management responsibilities
to the client driver.
---
Changes in v2:
- Move pm_runtmie APIs from cmdq driver to client drivers.
- Move pm_runtime_put_autosuspend to GCE irq callback function.
- Link to v1: https://lore.kernel.org/r/20240614040133.24967-1-jason-jh.lin@mediatek.com
---
Jason-JH Lin (3):
mailbox: mtk-cmdq: Remove pm_runtime APIs from cmdq_mbox_send_data()
drm/mediatek: Add pm_runtime support for GCE power control
media: platform: mtk-mdp3: Add pm_runtime support for GCE power
control
drivers/gpu/drm/mediatek/mtk_crtc.c | 7 +++++++
drivers/mailbox/mtk-cmdq-mailbox.c | 12 +-----------
drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c | 11 +++++++++++
3 files changed, 19 insertions(+), 11 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] mailbox: mtk-cmdq: Remove pm_runtime APIs from cmdq_mbox_send_data()
2025-08-29 9:15 [PATCH v2 0/3] Fix sleeping function called from invalid context Jason-JH Lin
@ 2025-08-29 9:15 ` Jason-JH Lin
2025-08-29 9:15 ` [PATCH v2 2/3] drm/mediatek: Add pm_runtime support for GCE power control Jason-JH Lin
2025-08-29 9:16 ` [PATCH v2 3/3] media: platform: mtk-mdp3: " Jason-JH Lin
2 siblings, 0 replies; 4+ messages in thread
From: Jason-JH Lin @ 2025-08-29 9:15 UTC (permalink / raw)
To: Chun-Kuang Hu, AngeloGioacchino Del Regno, Jassi Brar,
Mauro Carvalho Chehab
Cc: Philipp Zabel, David Airlie, Simona Vetter, Jason-JH Lin,
Nancy Lin, Singo Chang, Paul-PL Chen, Yongqiang Niu, Zhenxing Qin,
Xiandong Wang, Sirius Wang, Xavier Chang, Jarried Lin, Fei Shao,
Chen-yu Tsai, Project_Global_Chrome_Upstream_Group, dri-devel,
linux-mediatek, linux-kernel, linux-arm-kernel, linux-media
pm_runtime_get_sync() and pm_runtime_put_autosuspend() were previously
called in cmdq_mbox_send_data(), which is under a spinlock in msg_submit()
(mailbox.c). This caused lockdep warnings such as "sleeping function
called from invalid context" when running with lockdebug enabled.
The BUG report:
BUG: sleeping function called from invalid context at drivers/base/power/runtime.c:1164
in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 3616, name: kworker/u17:3
preempt_count: 1, expected: 0
RCU nest depth: 0, expected: 0
INFO: lockdep is turned off.
irq event stamp: 0
CPU: 1 PID: 3616 Comm: kworker/u17:3 Not tainted 6.1.87-lockdep-14133-g26e933aca785 #1
Hardware name: Google Ciri sku0/unprovisioned board (DT)
Workqueue: imgsys_runner imgsys_runner_func
Call trace:
dump_backtrace+0x100/0x120
show_stack+0x20/0x2c
dump_stack_lvl+0x84/0xb4
dump_stack+0x18/0x48
__might_resched+0x354/0x4c0
__might_sleep+0x98/0xe4
__pm_runtime_resume+0x70/0x124
cmdq_mbox_send_data+0xe4/0xb1c
msg_submit+0x194/0x2dc
mbox_send_message+0x190/0x330
imgsys_cmdq_sendtask+0x1618/0x2224
imgsys_runner_func+0xac/0x11c
process_one_work+0x638/0xf84
worker_thread+0x808/0xcd0
kthread+0x24c/0x324
ret_from_fork+0x10/0x20
Additionally, pm_runtime_put_autosuspend() should be invoked from the
GCE IRQ handler to ensure the hardware has actually completed its work.
To resolve these issues, remove the pm_runtime calls from
cmdq_mbox_send_data() and delegate power management responsibilities
to the client driver.
Fixes: 8afe816b0c99 ("mailbox: mtk-cmdq-mailbox: Implement Runtime PM with autosuspend")
Signed-off-by: Jason-JH Lin <jason-jh.lin@mediatek.com>
---
drivers/mailbox/mtk-cmdq-mailbox.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c
index 532929916e99..654a60f63756 100644
--- a/drivers/mailbox/mtk-cmdq-mailbox.c
+++ b/drivers/mailbox/mtk-cmdq-mailbox.c
@@ -379,20 +379,13 @@ static int cmdq_mbox_send_data(struct mbox_chan *chan, void *data)
struct cmdq *cmdq = dev_get_drvdata(chan->mbox->dev);
struct cmdq_task *task;
unsigned long curr_pa, end_pa;
- int ret;
/* Client should not flush new tasks if suspended. */
WARN_ON(cmdq->suspended);
- ret = pm_runtime_get_sync(cmdq->mbox.dev);
- if (ret < 0)
- return ret;
-
task = kzalloc(sizeof(*task), GFP_ATOMIC);
- if (!task) {
- pm_runtime_put_autosuspend(cmdq->mbox.dev);
+ if (!task)
return -ENOMEM;
- }
task->cmdq = cmdq;
INIT_LIST_HEAD(&task->list_entry);
@@ -439,9 +432,6 @@ static int cmdq_mbox_send_data(struct mbox_chan *chan, void *data)
}
list_move_tail(&task->list_entry, &thread->task_busy_list);
- pm_runtime_mark_last_busy(cmdq->mbox.dev);
- pm_runtime_put_autosuspend(cmdq->mbox.dev);
-
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] drm/mediatek: Add pm_runtime support for GCE power control
2025-08-29 9:15 [PATCH v2 0/3] Fix sleeping function called from invalid context Jason-JH Lin
2025-08-29 9:15 ` [PATCH v2 1/3] mailbox: mtk-cmdq: Remove pm_runtime APIs from cmdq_mbox_send_data() Jason-JH Lin
@ 2025-08-29 9:15 ` Jason-JH Lin
2025-08-29 9:16 ` [PATCH v2 3/3] media: platform: mtk-mdp3: " Jason-JH Lin
2 siblings, 0 replies; 4+ messages in thread
From: Jason-JH Lin @ 2025-08-29 9:15 UTC (permalink / raw)
To: Chun-Kuang Hu, AngeloGioacchino Del Regno, Jassi Brar,
Mauro Carvalho Chehab
Cc: Philipp Zabel, David Airlie, Simona Vetter, Jason-JH Lin,
Nancy Lin, Singo Chang, Paul-PL Chen, Yongqiang Niu, Zhenxing Qin,
Xiandong Wang, Sirius Wang, Xavier Chang, Jarried Lin, Fei Shao,
Chen-yu Tsai, Project_Global_Chrome_Upstream_Group, dri-devel,
linux-mediatek, linux-kernel, linux-arm-kernel, linux-media
Call pm_runtime_resume_and_get() before accessing GCE hardware in
mbox_send_message(), and invoke pm_runtime_put_autosuspend() in the
cmdq callback to release the PM reference and start autosuspend for
GCE. This ensures correct power management for the GCE device.
Fixes: 8afe816b0c99 ("mailbox: mtk-cmdq-mailbox: Implement Runtime PM with autosuspend")
Signed-off-by: Jason-JH Lin <jason-jh.lin@mediatek.com>
---
drivers/gpu/drm/mediatek/mtk_crtc.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c
index bc7527542fdc..c4c6d0249df5 100644
--- a/drivers/gpu/drm/mediatek/mtk_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
@@ -283,6 +283,10 @@ static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
unsigned int i;
unsigned long flags;
+ /* release GCE HW usage and start autosuspend */
+ pm_runtime_mark_last_busy(cmdq_cl->chan->mbox->dev);
+ pm_runtime_put_autosuspend(cmdq_cl->chan->mbox->dev);
+
if (data->sta < 0)
return;
@@ -618,6 +622,9 @@ static void mtk_crtc_update_config(struct mtk_crtc *mtk_crtc, bool needs_vblank)
mtk_crtc->config_updating = false;
spin_unlock_irqrestore(&mtk_crtc->config_lock, flags);
+ if (pm_runtime_resume_and_get(mtk_crtc->cmdq_client.chan->mbox->dev) < 0)
+ goto update_config_out;
+
mbox_send_message(mtk_crtc->cmdq_client.chan, cmdq_handle);
mbox_client_txdone(mtk_crtc->cmdq_client.chan, 0);
goto update_config_out;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] media: platform: mtk-mdp3: Add pm_runtime support for GCE power control
2025-08-29 9:15 [PATCH v2 0/3] Fix sleeping function called from invalid context Jason-JH Lin
2025-08-29 9:15 ` [PATCH v2 1/3] mailbox: mtk-cmdq: Remove pm_runtime APIs from cmdq_mbox_send_data() Jason-JH Lin
2025-08-29 9:15 ` [PATCH v2 2/3] drm/mediatek: Add pm_runtime support for GCE power control Jason-JH Lin
@ 2025-08-29 9:16 ` Jason-JH Lin
2 siblings, 0 replies; 4+ messages in thread
From: Jason-JH Lin @ 2025-08-29 9:16 UTC (permalink / raw)
To: Chun-Kuang Hu, AngeloGioacchino Del Regno, Jassi Brar,
Mauro Carvalho Chehab
Cc: Philipp Zabel, David Airlie, Simona Vetter, Jason-JH Lin,
Nancy Lin, Singo Chang, Paul-PL Chen, Yongqiang Niu, Zhenxing Qin,
Xiandong Wang, Sirius Wang, Xavier Chang, Jarried Lin, Fei Shao,
Chen-yu Tsai, Project_Global_Chrome_Upstream_Group, dri-devel,
linux-mediatek, linux-kernel, linux-arm-kernel, linux-media
Call pm_runtime_resume_and_get() before accessing GCE hardware in
mbox_send_message(), and invoke pm_runtime_put_autosuspend() in the
cmdq callback to release the PM reference and start autosuspend for
GCE. This ensures correct power management for the GCE device.
Fixes: 8afe816b0c99 ("mailbox: mtk-cmdq-mailbox: Implement Runtime PM with autosuspend")
Signed-off-by: Jason-JH Lin <jason-jh.lin@mediatek.com>
---
drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c
index e5ccf673e152..bb7a895318af 100644
--- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c
+++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c
@@ -6,6 +6,7 @@
#include <linux/mailbox_controller.h>
#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
#include "mtk-mdp3-cfg.h"
#include "mtk-mdp3-cmdq.h"
#include "mtk-mdp3-comp.h"
@@ -521,6 +522,9 @@ static void mdp_handle_cmdq_callback(struct mbox_client *cl, void *mssg)
mdp = cmd->mdp;
dev = &mdp->pdev->dev;
+ pm_runtime_mark_last_busy(mdp->cmdq_clt[cmd->pp_idx]->chan->mbox->dev);
+ pm_runtime_put_autosuspend(mdp->cmdq_clt[cmd->pp_idx]->chan->mbox->dev);
+
INIT_WORK(&cmd->auto_release_work, mdp_auto_release_work);
if (!queue_work(mdp->clock_wq, &cmd->auto_release_work)) {
struct mtk_mutex *mutex;
@@ -702,6 +706,13 @@ int mdp_cmdq_send(struct mdp_dev *mdp, struct mdp_cmdq_param *param)
cmd[i]->pkt.pa_base, cmd[i]->pkt.cmd_buf_size,
DMA_TO_DEVICE);
+ ret = pm_runtime_resume_and_get(mdp->cmdq_clt[i]->chan->mbox->dev);
+ if (ret < 0) {
+ dev_err(dev, "pm_runtime_resume_and_get fail: %d!\n", ret);
+ i = pp_used;
+ goto err_clock_off;
+ }
+
ret = mbox_send_message(mdp->cmdq_clt[i]->chan, &cmd[i]->pkt);
if (ret < 0) {
dev_err(dev, "mbox send message fail %d!\n", ret);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-29 9:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-29 9:15 [PATCH v2 0/3] Fix sleeping function called from invalid context Jason-JH Lin
2025-08-29 9:15 ` [PATCH v2 1/3] mailbox: mtk-cmdq: Remove pm_runtime APIs from cmdq_mbox_send_data() Jason-JH Lin
2025-08-29 9:15 ` [PATCH v2 2/3] drm/mediatek: Add pm_runtime support for GCE power control Jason-JH Lin
2025-08-29 9:16 ` [PATCH v2 3/3] media: platform: mtk-mdp3: " Jason-JH Lin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).