From: Ninad Palsule <ninad@linux.ibm.com>
To: eajames@linux.ibm.com, linux@roeck-us.net, psanman@juniper.net,
arnd@arndb.de, ninad@linux.ibm.com, linux-hwmon@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v1 1/1] hwmon: (occ) Fix sysfs device unreg deadlock
Date: Thu, 25 Jun 2026 11:46:53 -0500 [thread overview]
Message-ID: <20260625164700.2797362-2-ninad@linux.ibm.com> (raw)
In-Reply-To: <20260625164700.2797362-1-ninad@linux.ibm.com>
Release the driver lock before unregistering the hwmon device to prevent
a deadlock. The device_unregister() call can block waiting for sysfs
operations to complete, but those operations may be blocked waiting for
the same lock held during unregistration.
The deadlock occurs when:
1. Thread A holds the driver lock and calls device_unregister()
2. device_unregister() waits for sysfs operations to drain
3. Thread B is blocked in a sysfs read operation waiting for the driver
lock
4. Neither thread can proceed, causing a hung task
This was observed during power system remote restart operations when
concurrent sysfs accesses occurred during OCC active state transitions.
Kernel log excerpt showing the deadlock:
INFO: task openpower-occ-c:1430 blocked for more than 122 seconds.
Call trace:
schedule+0x28/0xfc
kernfs_drain+0xc8/0x174
__kernfs_remove.part.0+0x138/0x21c
kernfs_remove_by_name_ns+0x7c/0xcc
[...]
device_unregister+0x1c/0x5c
hwmon_device_unregister+0x58/0xb0
occ_active+0x6c/0xe74
occ_active_store+0x54/0x80
Reproducer:
Run these two scripts in parallel:
Script 1 (continuous sysfs read):
while true; do
cat /sys/class/hwmon/hwmon14/power15_cap_user
done
Script 2 (OCC active state toggle):
while true; do
echo 0 > /sys/bus/platform/drivers/occ-hwmon/occ-hwmon.1/occ_active
echo 1 > /sys/bus/platform/drivers/occ-hwmon/occ-hwmon.1/occ_active
sleep 0.2
done
Signed-off-by: Ninad Palsule <ninad@linux.ibm.com>
---
drivers/hwmon/occ/common.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/occ/common.c b/drivers/hwmon/occ/common.c
index 42cc6068bb08..a5641dbbba2f 100644
--- a/drivers/hwmon/occ/common.c
+++ b/drivers/hwmon/occ/common.c
@@ -1149,15 +1149,22 @@ int occ_active(struct occ *occ, bool active)
goto unlock;
}
} else {
+ struct device *hwmon_dev = occ->hwmon;
+
if (!occ->active) {
rc = -EALREADY;
goto unlock;
}
- if (occ->hwmon)
- hwmon_device_unregister(occ->hwmon);
occ->active = false;
occ->hwmon = NULL;
+
+ mutex_unlock(&occ->lock);
+
+ if (hwmon_dev)
+ hwmon_device_unregister(hwmon_dev);
+
+ return 0;
}
unlock:
--
2.51.0
next prev parent reply other threads:[~2026-06-25 16:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-25 16:46 [PATCH v1 0/1] Fix sysfs device unregistration deadlock Ninad Palsule
2026-06-25 16:46 ` Ninad Palsule [this message]
2026-06-25 16:59 ` [PATCH v1 1/1] hwmon: (occ) Fix sysfs device unreg deadlock sashiko-bot
2026-06-29 23:35 ` Guenter Roeck
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=20260625164700.2797362-2-ninad@linux.ibm.com \
--to=ninad@linux.ibm.com \
--cc=arnd@arndb.de \
--cc=eajames@linux.ibm.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=psanman@juniper.net \
/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