From: Bo Ye <bo.ye@mediatek.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Amit Kucheria <amitk@kernel.org>, Zhang Rui <rui.zhang@intel.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>
Cc: <yugang.wang@mediatek.com>, <yongdong.zhang@mediatek.com>,
<browse.zhang@mediatek.com>, Bo Ye <bo.ye@mediatek.com>,
<linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>
Subject: [PATCH] Subject: thermal: Fix potential race condition in suspend/resume
Date: Sat, 16 Sep 2023 19:33:26 +0800 [thread overview]
Message-ID: <20230916113327.85693-1-bo.ye@mediatek.com> (raw)
From: "yugang.wang" <yugang.wang@mediatek.com>
Body:
This patch fixes a race condition during system resume. It occurs if
the system is exiting a suspend state and a user is trying to
register/unregister a thermal zone concurrently. The root cause is
that both actions access the `thermal_tz_list`.
In detail:
1. At PM_POST_SUSPEND during the resume, the system reads all thermal
zones in `thermal_tz_list`, then resets and updates their
temperatures.
2. When registering/unregistering a thermal zone, the
`thermal_tz_list` gets manipulated.
These two actions might occur concurrently, causing a race condition.
To solve this issue, we introduce a mutex lock to protect
`thermal_tz_list` from being modified while it's being read and
updated during the resume from suspend.
Kernel oops excerpt related to this fix:
[ 5201.869845] [T316822] pc: [0xffffffeb7d4876f0] mutex_lock+0x34/0x170
[ 5201.869856] [T316822] lr: [0xffffffeb7ca98a84] thermal_pm_notify+0xd4/0x26c
[... cut for brevity ...]
[ 5201.871061] [T316822] suspend_prepare+0x150/0x470
[ 5201.871067] [T316822] enter_state+0x84/0x6f4
[ 5201.871076] [T316822] state_store+0x15c/0x1e8
Change-Id: Ifdbdecba17093f91eab7e36ce04b46d311ca6568
Signed-off-by: yugang.wang <yugang.wang@mediatek.com>
Signed-off-by: Bo Ye <bo.ye@mediatek.com>
---
drivers/thermal/thermal_core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 8717a3343512..a7a18ed57b6d 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1529,12 +1529,14 @@ static int thermal_pm_notify(struct notifier_block *nb,
case PM_POST_HIBERNATION:
case PM_POST_RESTORE:
case PM_POST_SUSPEND:
+ mutex_lock(&thermal_list_lock);
atomic_set(&in_suspend, 0);
list_for_each_entry(tz, &thermal_tz_list, node) {
thermal_zone_device_init(tz);
thermal_zone_device_update(tz,
THERMAL_EVENT_UNSPECIFIED);
}
+ mutex_unlock(&thermal_list_lock);
break;
default:
break;
--
2.17.0
WARNING: multiple messages have this Message-ID (diff)
From: Bo Ye <bo.ye@mediatek.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Amit Kucheria <amitk@kernel.org>, Zhang Rui <rui.zhang@intel.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>
Cc: <yugang.wang@mediatek.com>, <yongdong.zhang@mediatek.com>,
<browse.zhang@mediatek.com>, Bo Ye <bo.ye@mediatek.com>,
<linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>
Subject: [PATCH] Subject: thermal: Fix potential race condition in suspend/resume
Date: Sat, 16 Sep 2023 19:33:26 +0800 [thread overview]
Message-ID: <20230916113327.85693-1-bo.ye@mediatek.com> (raw)
From: "yugang.wang" <yugang.wang@mediatek.com>
Body:
This patch fixes a race condition during system resume. It occurs if
the system is exiting a suspend state and a user is trying to
register/unregister a thermal zone concurrently. The root cause is
that both actions access the `thermal_tz_list`.
In detail:
1. At PM_POST_SUSPEND during the resume, the system reads all thermal
zones in `thermal_tz_list`, then resets and updates their
temperatures.
2. When registering/unregistering a thermal zone, the
`thermal_tz_list` gets manipulated.
These two actions might occur concurrently, causing a race condition.
To solve this issue, we introduce a mutex lock to protect
`thermal_tz_list` from being modified while it's being read and
updated during the resume from suspend.
Kernel oops excerpt related to this fix:
[ 5201.869845] [T316822] pc: [0xffffffeb7d4876f0] mutex_lock+0x34/0x170
[ 5201.869856] [T316822] lr: [0xffffffeb7ca98a84] thermal_pm_notify+0xd4/0x26c
[... cut for brevity ...]
[ 5201.871061] [T316822] suspend_prepare+0x150/0x470
[ 5201.871067] [T316822] enter_state+0x84/0x6f4
[ 5201.871076] [T316822] state_store+0x15c/0x1e8
Change-Id: Ifdbdecba17093f91eab7e36ce04b46d311ca6568
Signed-off-by: yugang.wang <yugang.wang@mediatek.com>
Signed-off-by: Bo Ye <bo.ye@mediatek.com>
---
drivers/thermal/thermal_core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 8717a3343512..a7a18ed57b6d 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1529,12 +1529,14 @@ static int thermal_pm_notify(struct notifier_block *nb,
case PM_POST_HIBERNATION:
case PM_POST_RESTORE:
case PM_POST_SUSPEND:
+ mutex_lock(&thermal_list_lock);
atomic_set(&in_suspend, 0);
list_for_each_entry(tz, &thermal_tz_list, node) {
thermal_zone_device_init(tz);
thermal_zone_device_update(tz,
THERMAL_EVENT_UNSPECIFIED);
}
+ mutex_unlock(&thermal_list_lock);
break;
default:
break;
--
2.17.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2023-09-16 11:33 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-16 11:33 Bo Ye [this message]
2023-09-16 11:33 ` [PATCH] Subject: thermal: Fix potential race condition in suspend/resume Bo Ye
2023-10-12 7:35 ` [PATCH] " Bo Ye (叶波)
2023-10-12 7:35 ` Bo Ye (叶波)
2023-10-23 1:19 ` Bo Ye (叶波)
2023-10-23 1:19 ` Bo Ye (叶波)
2023-10-25 18:21 ` Rafael J. Wysocki
2023-10-25 18:21 ` Rafael J. Wysocki
2023-11-01 14:58 ` [PATCH] thermal: Fix " Bo Ye (叶波)
2023-11-01 14:58 ` Bo Ye (叶波)
2023-11-16 15:06 ` Bo Ye (叶波)
2023-11-16 15:06 ` Bo Ye (叶波)
2023-12-06 14:32 ` Bo Ye (叶波)
2023-12-06 14:32 ` Bo Ye (叶波)
2023-10-12 15:39 ` [PATCH] Subject: thermal: Fix potential " Daniel Lezcano
2023-10-12 15:39 ` Daniel Lezcano
2023-10-12 17:03 ` Rafael J. Wysocki
2023-10-12 17:03 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230916113327.85693-1-bo.ye@mediatek.com \
--to=bo.ye@mediatek.com \
--cc=amitk@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=browse.zhang@mediatek.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.com \
--cc=yongdong.zhang@mediatek.com \
--cc=yugang.wang@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.