From: Shivendra Pratap <shivendra.pratap@oss.qualcomm.com>
To: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Cc: Bjorn Andersson <andersson@kernel.org>,
Sebastian Reichel <sre@kernel.org>, Rob Herring <robh@kernel.org>,
Sudeep Holla <sudeep.holla@arm.com>,
Souvik Chakravarty <Souvik.Chakravarty@arm.com>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Andy Yan <andy.yan@rock-chips.com>,
Mark Rutland <mark.rutland@arm.com>,
Lorenzo Pieralisi <lpieralisi@kernel.org>,
Arnd Bergmann <arnd@arndb.de>,
Konrad Dybcio <konradybcio@kernel.org>,
cros-qcom-dts-watchers@chromium.org,
Vinod Koul <vkoul@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Florian Fainelli <florian.fainelli@broadcom.com>,
Moritz Fischer <moritz.fischer@ettus.com>,
John Stultz <john.stultz@linaro.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>,
Stephen Boyd <swboyd@chromium.org>,
Andre Draszik <andre.draszik@linaro.org>,
Kathiravan Thirumoorthy
<kathiravan.thirumoorthy@oss.qualcomm.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-arm-msm@vger.kernel.org,
Elliot Berman <quic_eberman@quicinc.com>,
Srinivas Kandagatla <srini@kernel.org>
Subject: Re: [PATCH v16 01/14] power: reset: reboot-mode: Synchronize list traversal
Date: Fri, 17 Oct 2025 20:17:33 +0530 [thread overview]
Message-ID: <2c8e7d94-cacb-427f-02ec-ecc83a189479@oss.qualcomm.com> (raw)
In-Reply-To: <CACMJSeu_Y2Rra8x22kWN0B38jKZEwq7=B9C75zH18QdjDHAWqg@mail.gmail.com>
On 10/15/2025 8:02 PM, Bartosz Golaszewski wrote:
> On Wed, 15 Oct 2025 at 06:38, Shivendra Pratap
> <shivendra.pratap@oss.qualcomm.com> wrote:
>>
>> List traversals must be synchronized to prevent race conditions
>> and data corruption. The reboot-mode list is not protected by a
>> lock currently, which can lead to concurrent access and race.
>>
>> Introduce a mutex lock to guard all operations on the reboot-mode
>> list and ensure thread-safe access. The change prevents unsafe
>> concurrent access on reboot-mode list.
>>
>> Fixes: 4fcd504edbf7 ("power: reset: add reboot mode driver")
>> Fixes: ca3d2ea52314 ("power: reset: reboot-mode: better compatibility with DT (replace ' ,/')")
>>
>> Signed-off-by: Shivendra Pratap <shivendra.pratap@oss.qualcomm.com>
>> ---
>> drivers/power/reset/reboot-mode.c | 96 +++++++++++++++++++++------------------
>> include/linux/reboot-mode.h | 4 ++
>> 2 files changed, 57 insertions(+), 43 deletions(-)
>>
>> diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
>> index fba53f638da04655e756b5f8b7d2d666d1379535..8fc3e14638ea757c8dc3808c240ff569cbd74786 100644
>> --- a/drivers/power/reset/reboot-mode.c
>> +++ b/drivers/power/reset/reboot-mode.c
>> @@ -29,9 +29,11 @@ static unsigned int get_reboot_mode_magic(struct reboot_mode_driver *reboot,
>> if (!cmd)
>> cmd = normal;
>>
>> - list_for_each_entry(info, &reboot->head, list)
>> - if (!strcmp(info->mode, cmd))
>> - return info->magic;
>> + scoped_guard(mutex, &reboot->rb_lock) {
>> + list_for_each_entry(info, &reboot->head, list)
>> + if (!strcmp(info->mode, cmd))
>> + return info->magic;
>> + }
>>
>> /* try to match again, replacing characters impossible in DT */
>> if (strscpy(cmd_, cmd, sizeof(cmd_)) == -E2BIG)
>> @@ -41,9 +43,11 @@ static unsigned int get_reboot_mode_magic(struct reboot_mode_driver *reboot,
>> strreplace(cmd_, ',', '-');
>> strreplace(cmd_, '/', '-');
>>
>> - list_for_each_entry(info, &reboot->head, list)
>> - if (!strcmp(info->mode, cmd_))
>> - return info->magic;
>> + scoped_guard(mutex, &reboot->rb_lock) {
>> + list_for_each_entry(info, &reboot->head, list)
>> + if (!strcmp(info->mode, cmd_))
>> + return info->magic;
>> + }
>>
>> return 0;
>> }
>> @@ -78,46 +82,50 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
>>
>> INIT_LIST_HEAD(&reboot->head);
>>
>> - for_each_property_of_node(np, prop) {
>> - if (strncmp(prop->name, PREFIX, len))
>> - continue;
>> -
>> - info = devm_kzalloc(reboot->dev, sizeof(*info), GFP_KERNEL);
>> - if (!info) {
>> - ret = -ENOMEM;
>> - goto error;
>> - }
>> -
>> - if (of_property_read_u32(np, prop->name, &info->magic)) {
>> - dev_err(reboot->dev, "reboot mode %s without magic number\n",
>> - info->mode);
>> - devm_kfree(reboot->dev, info);
>> - continue;
>> - }
>> -
>> - info->mode = kstrdup_const(prop->name + len, GFP_KERNEL);
>> - if (!info->mode) {
>> - ret = -ENOMEM;
>> - goto error;
>> - } else if (info->mode[0] == '\0') {
>> - kfree_const(info->mode);
>> - ret = -EINVAL;
>> - dev_err(reboot->dev, "invalid mode name(%s): too short!\n",
>> - prop->name);
>> - goto error;
>> + mutex_init(&reboot->rb_lock);
>> +
>> + scoped_guard(mutex, &reboot->rb_lock) {
>> + for_each_property_of_node(np, prop) {
>> + if (strncmp(prop->name, PREFIX, len))
>> + continue;
>> +
>> + info = devm_kzalloc(reboot->dev, sizeof(*info), GFP_KERNEL);
>> + if (!info) {
>> + ret = -ENOMEM;
>> + goto error;
>> + }
>> +
>> + if (of_property_read_u32(np, prop->name, &info->magic)) {
>> + dev_err(reboot->dev, "reboot mode %s without magic number\n",
>> + info->mode);
>> + devm_kfree(reboot->dev, info);
>> + continue;
>> + }
>> +
>> + info->mode = kstrdup_const(prop->name + len, GFP_KERNEL);
>> + if (!info->mode) {
>> + ret = -ENOMEM;
>> + goto error;
>> + } else if (info->mode[0] == '\0') {
>> + kfree_const(info->mode);
>> + ret = -EINVAL;
>> + dev_err(reboot->dev, "invalid mode name(%s): too short!\n",
>> + prop->name);
>> + goto error;
>> + }
>> +
>> + list_add_tail(&info->list, &reboot->head);
>
> This seems to be the only call that actually needs synchronization.
> All of the above can be run outside the critical section.
sure. will add it only around the required lines.
>
>> }
>>
>> - list_add_tail(&info->list, &reboot->head);
>> - }
>> -
>> - reboot->reboot_notifier.notifier_call = reboot_mode_notify;
>> - register_reboot_notifier(&reboot->reboot_notifier);
>> + reboot->reboot_notifier.notifier_call = reboot_mode_notify;
>> + register_reboot_notifier(&reboot->reboot_notifier);
>>
>> - return 0;
>> + return 0;
>>
>> error:
>> - list_for_each_entry(info, &reboot->head, list)
>> - kfree_const(info->mode);
>> + list_for_each_entry(info, &reboot->head, list)
>> + kfree_const(info->mode);
>> + }
>>
>> return ret;
>> }
>> @@ -133,8 +141,10 @@ int reboot_mode_unregister(struct reboot_mode_driver *reboot)
>>
>> unregister_reboot_notifier(&reboot->reboot_notifier);
>>
>> - list_for_each_entry(info, &reboot->head, list)
>> - kfree_const(info->mode);
>> + scoped_guard(mutex, &reboot->rb_lock) {
>> + list_for_each_entry(info, &reboot->head, list)
>> + kfree_const(info->mode);
>> + }
>
> Please destroy the mutex here.
sure thanks. will add destroy here.
thanks,
Shivendra
next prev parent reply other threads:[~2025-10-17 14:47 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 4:38 [PATCH v16 00/14] Implement vendor resets for PSCI SYSTEM_RESET2 Shivendra Pratap
2025-10-15 4:38 ` [PATCH v16 01/14] power: reset: reboot-mode: Synchronize list traversal Shivendra Pratap
2025-10-15 14:32 ` Bartosz Golaszewski
2025-10-17 14:47 ` Shivendra Pratap [this message]
2025-10-28 3:34 ` Bjorn Andersson
2025-10-29 17:48 ` Shivendra Pratap
2025-11-03 8:16 ` Mukesh Ojha
2025-10-15 4:38 ` [PATCH v16 02/14] power: reset: reboot-mode: Add device tree node-based registration Shivendra Pratap
2025-10-15 14:40 ` Bartosz Golaszewski
2025-10-16 17:19 ` Shivendra Pratap
2025-10-17 9:06 ` Bartosz Golaszewski
2025-10-17 14:24 ` Shivendra Pratap
2025-10-15 4:38 ` [PATCH v16 03/14] power: reset: reboot-mode: Add support for 64 bit magic Shivendra Pratap
2025-10-15 8:40 ` Nirmesh Kumar Singh
2025-10-15 4:38 ` [PATCH v16 04/14] Documentation: ABI: Add sysfs-class-reboot-mode-reboot_modes Shivendra Pratap
2025-10-15 4:38 ` [PATCH v16 05/14] power: reset: reboot-mode: Expose sysfs for registered reboot_modes Shivendra Pratap
2025-10-15 8:45 ` Nirmesh Kumar Singh
2025-10-15 14:47 ` Bartosz Golaszewski
2025-10-17 19:40 ` Shivendra Pratap
2025-10-20 7:40 ` Bartosz Golaszewski
2025-10-22 14:21 ` Shivendra Pratap
2025-10-23 15:02 ` Bartosz Golaszewski
2025-10-23 15:54 ` Shivendra Pratap
2025-10-15 4:38 ` [PATCH v16 06/14] dt-bindings: arm: Document reboot mode magic Shivendra Pratap
2025-10-15 4:38 ` [PATCH v16 07/14] firmware: psci: Implement vendor-specific resets as reboot-mode Shivendra Pratap
2025-10-15 6:55 ` Pavan Kondeti
2025-10-15 7:47 ` Shivendra Pratap
2025-10-15 4:38 ` [PATCH v16 08/14] arm64: dts: qcom: qcm6490-idp: Add PSCI SYSTEM_RESET2 types Shivendra Pratap
2025-10-15 4:38 ` [PATCH v16 09/14] arm64: dts: qcom: qcs6490-rb3gen2: " Shivendra Pratap
2025-10-15 4:38 ` [PATCH v16 10/14] arm64: dts: qcom: lemans-ride: " Shivendra Pratap
2025-11-03 8:36 ` Mukesh Ojha
2025-10-15 4:38 ` [PATCH v16 11/14] arm64: dts: qcom: lemans-evk: " Shivendra Pratap
2025-10-15 4:38 ` [PATCH v16 12/14] arm64: dts: qcom: qcs8300-ride: " Shivendra Pratap
2025-10-15 4:38 ` [PATCH v16 13/14] arm64: dts: qcom: monaco-evk: " Shivendra Pratap
2025-10-15 4:38 ` [PATCH v16 14/14] arm64: dts: qcom: qcs615-ride: " Shivendra Pratap
2025-11-07 8:08 ` Xin Liu
2025-11-07 8:00 ` [PATCH v16 00/14] Implement vendor resets for PSCI SYSTEM_RESET2 Xin Liu
2025-11-07 8:10 ` Krzysztof Kozlowski
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=2c8e7d94-cacb-427f-02ec-ecc83a189479@oss.qualcomm.com \
--to=shivendra.pratap@oss.qualcomm.com \
--cc=Souvik.Chakravarty@arm.com \
--cc=andersson@kernel.org \
--cc=andre.draszik@linaro.org \
--cc=andy.yan@rock-chips.com \
--cc=arnd@arndb.de \
--cc=bartosz.golaszewski@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=conor+dt@kernel.org \
--cc=cros-qcom-dts-watchers@chromium.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=florian.fainelli@broadcom.com \
--cc=john.stultz@linaro.org \
--cc=kathiravan.thirumoorthy@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mark.rutland@arm.com \
--cc=matthias.bgg@gmail.com \
--cc=moritz.fischer@ettus.com \
--cc=mukesh.ojha@oss.qualcomm.com \
--cc=quic_eberman@quicinc.com \
--cc=robh@kernel.org \
--cc=sre@kernel.org \
--cc=srini@kernel.org \
--cc=sudeep.holla@arm.com \
--cc=swboyd@chromium.org \
--cc=vkoul@kernel.org \
--cc=will@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox