From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
To: Shan Rizvi <shan@rizvi.nu>, Jonathan Cameron <jic23@kernel.org>,
Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>
Cc: linux-iio@vger.kernel.org, linux-input@vger.kernel.org
Subject: Re: iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor
Date: Mon, 30 Nov 2026 05:07:36 -0800 [thread overview]
Message-ID: <62dfb2d336378b0df89799e6c944ba4728a2b37c.camel@linux.intel.com> (raw)
In-Reply-To: <179597990855.41.2142056846322501706@rizvi.nu>
[-- Attachment #1: Type: text/plain, Size: 1964 bytes --]
On Sun, 2026-11-29 at 14:18 -0500, Shan Rizvi wrote:
> On Sun, 2026-11-29 at 09:54 -0800, Srinivas Pandruvada wrote:
> > This may be better. Try the attached:
>
> That works very cleanly on the HP 8EA2 laptop!
>
I think I want to fix by setting report interval rather than ignoring
that sensor. Try the attached.
Thanks,
Srinivas
> With invalid_sensor.diff applied to hid-sensor-iio-common:
> - HID-SENSOR-200011.6.auto (0.000100 Hz) is cleanly rejected at probe
> time before any iio:device is registered:
>
> hid-sensor-hub 0003:04F2:B872.0001: Invalid sampling interval,
> will cause task hangs
> hid_sensor_prox HID-SENSOR-200011.6.auto: failed to setup common
> attributes
> hid_sensor_prox HID-SENSOR-200011.6.auto: probe with driver
> hid_sensor_prox failed with error -22
>
> - The four real sensors (HID-SENSOR-200011.3.auto 10 Hz prox,
> HID-SENSOR-200041.4.auto ALS, HID-SENSOR-200073.9.auto accel_3d,
> HID-SENSOR-200076.10.auto gyro_3d) all probe and read normally,
> with
> no runtime PM underflows and clean module unload/reload.
>
> Tested-by: Shan Rizvi <shan@rizvi.nu>
>
> Three minor review notes for the formal patch:
> 1. value is s32 (hid-sensor-attributes.c:516), so casting
> (u64)value * 2 >= max_sleep_ms avoids signed 32-bit overflow for
> descriptors with large 32-bit Report Intervals (REPORT_ID 17 here
> declares max=2147483647).
> 2. Applying the same upper-bound check in
> hid_sensor_write_samp_freq_value() (and checking poll_value > 0 in
> hid-sensor-trigger.c:_hid_sensor_power_state()) would also prevent
> userspace from configuring a hang-inducing sampling frequency
> after
> probe or passing a negative error to msleep_interruptible().
> 3. Minor whitespace nit: "value =\thid_sensor_read_poll_value(st);"
> has
> a tab after '='.
>
> Thanks again for the fast turnaround!
>
> Shan Rizvi
[-- Attachment #2: 0001-iio-hid-sensors-Limit-the-poll-interval-when-powerin.patch --]
[-- Type: text/x-patch, Size: 2954 bytes --]
From ec0287c43105529903a335dbacf5775dbea73c46 Mon Sep 17 00:00:00 2001
From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Date: Mon, 30 Nov 2026 05:03:06 -0800
Subject: [PATCH] iio: hid-sensors: Limit the poll interval when powering on
When a sensor is powered on, _hid_sensor_power_state() waits for twice
the poll interval read from the sensor, so that the first sample is
available. On some platforms the poll interval is not initialized and
has a very large value. This results in a very long sleep in
msleep_interruptible(), and the user space process reading the sensor
appears to hang.
Raw sample reads time out after 5 seconds in
sensor_hub_input_attr_get_raw_value(), so there is no point in waiting
longer than that. When the poll interval is more than 2 seconds, set
the poll interval to 2 seconds, which limits the wait to 4 seconds.
Also when reading the poll interval fails, hid_sensor_read_poll_value()
returns -EINVAL, which is passed to msleep_interruptible() as a huge
unsigned value. Don't wait in this case.
Fixes: 2b89635e9a9e ("iio: hid_sensor_hub: Common PM functions")
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
.../common/hid-sensors/hid-sensor-trigger.c | 32 ++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index 60808e2430ca..33d38ea7b308 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -82,6 +82,36 @@ static const struct iio_dev_attr *hid_sensor_fifo_attributes[] = {
NULL,
};
+/*
+ * Raw sample reads time out after 5 seconds, and the power on path waits for
+ * twice the poll interval. Limit the poll interval, so that the wait is within
+ * the timeout.
+ */
+#define HID_SENSOR_MAX_POLL_INTERVAL_MS 2000
+
+static s32 hid_sensor_limit_poll_value(struct hid_sensor_common *st)
+{
+ s32 poll_value, value;
+
+ poll_value = hid_sensor_read_poll_value(st);
+ if (poll_value < 0)
+ return 0;
+
+ if (poll_value <= HID_SENSOR_MAX_POLL_INTERVAL_MS)
+ return poll_value;
+
+ if (st->poll.units == HID_USAGE_SENSOR_UNITS_SECOND)
+ value = HID_SENSOR_MAX_POLL_INTERVAL_MS / MSEC_PER_SEC;
+ else
+ value = HID_SENSOR_MAX_POLL_INTERVAL_MS;
+
+ if (!sensor_hub_set_feature(st->hsdev, st->poll.report_id,
+ st->poll.index, sizeof(value), &value))
+ st->poll_interval = value;
+
+ return HID_SENSOR_MAX_POLL_INTERVAL_MS;
+}
+
static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state)
{
int state_val;
@@ -103,7 +133,7 @@ static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state)
st->report_state.index,
HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM);
- poll_value = hid_sensor_read_poll_value(st);
+ poll_value = hid_sensor_limit_poll_value(st);
} else {
int val;
--
2.56.0
prev parent reply other threads:[~2026-11-30 13:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 2:03 iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor Shan Rizvi
2026-11-29 14:37 ` Srinivas Pandruvada
2026-11-29 17:26 ` Shan Rizvi
2026-11-29 17:54 ` Srinivas Pandruvada
2026-11-29 19:18 ` Shan Rizvi
2026-11-30 13:07 ` Srinivas Pandruvada [this message]
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=62dfb2d336378b0df89799e6c944ba4728a2b37c.camel@linux.intel.com \
--to=srinivas.pandruvada@linux.intel.com \
--cc=bentiss@kernel.org \
--cc=jic23@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=shan@rizvi.nu \
/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