Linux IIO development
 help / color / mirror / Atom feed
* iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor
@ 2026-11-29  2:03 Shan Rizvi
  2026-11-29 14:37 ` Srinivas Pandruvada
  0 siblings, 1 reply; 10+ messages in thread
From: Shan Rizvi @ 2026-11-29  2:03 UTC (permalink / raw)
  To: Jonathan Cameron, Srinivas Pandruvada, Jiri Kosina,
	Benjamin Tissoires
  Cc: linux-iio, linux-input

[-- Attachment #1: Type: text/plain, Size: 8859 bytes --]

Hi Jonathan, Srinivas, Jiri, Benjamin, and all,

On an HP OmniBook X Flip Laptop 16-cc0xxx (board HP 8EA2, BIOS Insyde
F.07), the integrated USB 2.0 camera (04f2:b872, "SunplusIT Inc HP 5MP
Camera", interface 1-1:1.4) binds hid-sensor-hub and exposes two
hid_sensor_prox (HID-SENSOR-200011) IIO devices:

  1. iio:device0 (HID-SENSOR-200011.3.auto)
     - Physical 0x20:0x11 inside standard Sensor Application 0x20:0x01
       (REPORT_ID 1).
     - in_proximity0_sampling_frequency = 10.000000 Hz (100 ms).
     - Works normally (live presence, distance, and attention readings).

  2. iio:device2 (HID-SENSOR-200011.6.auto)
     - Physical 0x20:0x11 nested inside Vendor-Defined Application
       Collection 0xff00:0x01 (HID-SENSOR-ff000001.5.auto, REPORT_ID
       17, 19, 18).
     - in_{proximity0,proximity1,attention}_sampling_frequency =
       0.000100 Hz.
     - Reading any value channel stalls runtime PM for hours and wedges
       any second concurrent reader in unkillable D-state inside
       rpm_resume().

Root cause
----------
In drivers/iio/common/hid-sensors/hid-sensor-trigger.c,
_hid_sensor_power_state() (lines 106, 146-147 on mainline master) does:

    poll_value = hid_sensor_read_poll_value(st);
    ...
    if (state && poll_value)
        msleep_interruptible(poll_value * 2);

There is no upper bound on poll_value * 2 (and checking poll_value
rather than poll_value > 0 would also pass a negative error such as
-EINVAL as a huge unsigned millisecond count to msleep_interruptible()).

On iio:device2, REPORT_ID 17 defines 0x20:0x30e (Property: Report
Interval, 32-bit, unit=0 -> ms, max=2147483647) and the device reports
sampling_frequency = 0.000100 Hz, corresponding to a poll_value in
[5,000,001 .. 10,000,000] ms (1.39 to 2.78 hours). When a reader
triggers hid_sensor_runtime_resume():

  - Reader 1 enters hid_sensor_runtime_resume() ->
    _hid_sensor_power_state(st, true) while dev->power.runtime_status
    is RPM_RESUMING, and sleeps in msleep_interruptible(poll_value * 2)
    for 2.78 to 5.56 hours (TASK_INTERRUPTIBLE).
  - Any concurrent Reader 2 (e.g., a second sysfs read or sensor
    daemon) enters prox_read_raw() -> hid_sensor_power_state() ->
    __pm_runtime_resume() -> rpm_resume(), sees RPM_RESUMING, and
    sleeps on &dev->power.wait_queue in TASK_UNINTERRUPTIBLE (D-state)
    until Reader 1's multi-hour sleep completes or is signaled.

In our observation on Nov 27, a concurrent cat (pid 858946) started
around 19:46 EST and hung in unkillable D-state for ~2h 14m (triggering
10 hung-task warnings from 19:49:05 at 122s through 20:07:30 at 1228s)
until system s2idle entry at 22:00:43, when the userspace freezer
signaled Reader 1 out of msleep_interruptible(), completed rpm_resume(),
and unblocked pid 858946 (freezing completed in 0.039s).

Environment
-----------
- Machine: HP OmniBook X Flip Laptop 16-cc0xxx (board HP 8EA2 rev 61.26,
  SKU D31MPUA#ABA, BIOS Insyde F.07 08/31/2026)
- Kernel: Linux 7.2.15-4-omarchy #1 SMP PREEMPT_DYNAMIC x86_64
  (untainted; downstream Arch/Omarchy kernel with out-of-tree BORE/ADIOS
  schedulers; hid-sensor-trigger/prox/hub behavior matches current
  mainline drivers/iio/common/hid-sensors/hid-sensor-trigger.c:146-147
  and I am happy to retest on vanilla mainline/rc or a test patch)
- Modules (srcversion):
    hid_sensor_trigger:    DC4B969EEA8A8985CCBB823
    hid_sensor_iio_common: 7B46F870DC1767B69877366
    hid_sensor_prox:       A2D3710A71BC0FCE010B937
    hid_sensor_hub:        B81ADED19C3243EFB66F46B
- USB device 1-1 / interface 1-1:1.4:
    idVendor=04f2, idProduct=b872, bcdDevice=10.20
    manufacturer="SunplusIT Inc", product="HP 5MP Camera"
    MODALIAS=usb:v04F2pB872d1020dcEFdsc02dp01ic03isc00ip00in04

HID report descriptor summary (1,846 bytes)
-------------------------------------------
(Full hex dump attached as 04f2-b872-report-descriptor.hex.)

  COLLECTION(Application) [0xff1b:0x8000]        # HID-SENSOR-ff1b8000.1.auto
  COLLECTION(Application) [0x20:0x01]            # HID-SENSOR-200001.2.auto
    REPORT_ID 1 (0x01)
    COLLECTION(Physical) [0x20:0x11]             # HID-SENSOR-200011.3.auto (iio:device0, 10.000000 Hz)
      Logical 0x20:0x309 (Property: Sensor Connection Type)
      Logical 0x20:0x31f (Property: Human Presence Detection Type)
      Logical 0x20:0x316 (Property: Reporting State)
      Logical 0x20:0x319 (Property: Power State)
      Feature 0x20:0x30e (Property: Report Interval, 32-bit, unit=0, max=2147483647)
      Input   0x20:0x4b1 (Human Presence), 0x20:0x4b2 (Human Proximity Range)
  COLLECTION(Physical) [0x20:0x41]               # HID-SENSOR-200041.4.auto (iio:device1, ALS)
  COLLECTION(Application) [0xff00:0x01]          # HID-SENSOR-ff000001.5.auto (vendor-defined)
    REPORT_ID 17 (0x11)
    COLLECTION(Physical) [0x20:0x11]             # HID-SENSOR-200011.6.auto (iio:device2, 0.000100 Hz)
      Logical 0x20:0x309 (Property: Sensor Connection Type)
      Logical 0x20:0x319 (Property: Power State)
      Logical 0x20:0x31f (Property: Human Presence Detection Type)
      Logical 0x20:0x316 (Property: Reporting State)
      Feature 0x20:0x30e (Property: Report Interval, 32-bit, unit=0, max=2147483647)
      REPORT_ID 19 (0x13), REPORT_ID 18 (0x12)
      Input   0x20:0x4b1 (Human Presence), 0x20:0x4b2 (Human Proximity Range)
  COLLECTION(Application) [0xff99:0x01]          # HID-SENSOR-ff990001.7.auto

Reproduction
------------
1. Start Reader 1 on iio:device2 (it stalls in msleep_interruptible()
   holding RPM_RESUMING):
     cat /sys/bus/iio/devices/iio:device2/in_proximity0_raw &
2. Start Reader 2 concurrently:
     cat /sys/bus/iio/devices/iio:device2/in_proximity0_raw
   Reader 2 enters uninterruptible D-state in rpm_resume() (unkillable
   by SIGKILL until Reader 1 is killed/signaled or the multi-hour sleep
   expires).

Hung-task call trace (Reader 2, pid 858946)
-------------------------------------------
Nov 27 19:49:05 sophia kernel: INFO: task cat:858946 blocked for more than 122 seconds.
Nov 27 19:49:05 sophia kernel:       Not tainted 7.2.15-4-omarchy #1
Nov 27 19:49:05 sophia kernel: "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
Nov 27 19:49:05 sophia kernel: task:cat             state:D stack:0     pid:858946 tgid:858946 ppid:858816 task_flags:0x400000 flags:0x00080000
Nov 27 19:49:05 sophia kernel: Call Trace:
Nov 27 19:49:05 sophia kernel:  <TASK>
Nov 27 19:49:05 sophia kernel:  __schedule+0x40f/0x1780
Nov 27 19:49:05 sophia kernel:  schedule+0x27/0xa0
Nov 27 19:49:05 sophia kernel:  rpm_resume+0x1cf/0x860
Nov 27 19:49:05 sophia kernel:  ? __pfx_autoremove_wake_function+0x10/0x10
Nov 27 19:49:05 sophia kernel:  __pm_runtime_resume+0x52/0x90
Nov 27 19:49:05 sophia kernel:  hid_sensor_power_state+0x55/0xe0 [hid_sensor_trigger 377a49e4e9428c72b857ea6ddd3ff77490c88f22]
Nov 27 19:49:05 sophia kernel:  prox_read_raw+0x159/0x350 [hid_sensor_prox 791fda5099b57d4de72068c9268ea72b5ae63472]
Nov 27 19:49:05 sophia kernel:  iio_read_channel_info+0x1b3/0x3f0 [industrialio df90c867801c29de6d58c14a6d53db307f32a0b7]
Nov 27 19:49:05 sophia kernel:  ? __kvmalloc_node_noprof+0x674/0x7d0
Nov 27 19:49:05 sophia kernel:  dev_attr_show+0x1f/0x50
Nov 27 19:49:05 sophia kernel:  sysfs_kf_seq_show+0xa8/0x110
Nov 27 19:49:05 sophia kernel:  seq_read_iter+0x131/0x4c0
Nov 27 19:49:05 sophia kernel:  ? security_file_permission+0x55/0x170
Nov 27 19:49:05 sophia kernel:  vfs_read+0x375/0x600
Nov 27 19:49:05 sophia kernel:  __x64_sys_read+0x7e/0x110
Nov 27 19:49:05 sophia kernel:  do_syscall_64+0xaa/0x630
Nov 27 19:49:05 sophia kernel:  ? do_syscall_64+0xaa/0x630
Nov 27 19:49:05 sophia kernel:  ? handle_mm_fault+0x1dd/0x2c0
Nov 27 19:49:05 sophia kernel:  ? do_syscall_64+0x5f/0x630
Nov 27 19:49:05 sophia kernel:  ? exc_page_fault+0x90/0x1c0
Nov 27 19:49:05 sophia kernel:  entry_SYSCALL_64_after_hwframe+0x76/0x7e
Nov 27 19:49:05 sophia kernel: RIP: 0033:0x7f4d25511b0d
[registers omitted]
Nov 27 19:49:05 sophia kernel:  </TASK>

Questions / possible fix directions
-----------------------------------
1. In drivers/iio/common/hid-sensors/hid-sensor-trigger.c:
   Should _hid_sensor_power_state() check poll_value > 0 (avoiding
   huge unsigned sleeps on negative errors) and clamp poll_value * 2
   to a reasonable upper bound (e.g., min(poll_value * 2, ...)), so a
   sensor reporting a multi-hour Report Interval cannot hold
   RPM_RESUMING for hours and wedge concurrent readers in D-state?
2. In drivers/hid/hid-sensor-hub.c:
   Should sensor_hub_probe() skip standard Sensor Physical collections
   (0x20:*) nested inside vendor-defined Application Collections
   (0xff00:0x01), or is a device quirk for 04f2:b872 preferred?

Happy to attach the raw binary descriptor, test a patch on vanilla
mainline/rc on this hardware, or submit a patch for (1) if you agree on
an appropriate cap.

Thanks,
Shan Rizvi

[-- Attachment #2: 04f2-b872-report-descriptor.hex --]
[-- Type: text/plain, Size: 7878 bytes --]

00000000: 061b ff0a 0080 a101 85f0 0900 1500 26ff  ..............&.
00000010: 0075 0895 3081 0285 f209 0195 3fb1 0285  .u..0.......?...
00000020: f309 0196 ff01 b102 85e0 0901 951f b102  ................
00000030: c005 2009 01a1 0185 0105 2009 11a1 0005  .. ....... .....
00000040: 200a 0903 1500 2502 7508 9501 a102 0a30   .....%.u......0
00000050: 080a 3108 0a32 08b1 00c0 0a1f 0315 0025  ..1..2.........%
00000060: 0375 0895 01a1 020a c009 0ac1 090a c209  .u..............
00000070: 0ac3 09b1 00c0 0a16 0315 0025 0575 0895  ...........%.u..
00000080: 01a1 020a 4008 0a41 080a 4208 0a43 080a  ....@..A..B..C..
00000090: 4408 0a45 08b1 00c0 0a19 0315 0025 0575  D..E.........%.u
000000a0: 0895 01a1 020a 5008 0a51 080a 5208 0a53  ......P..Q..R..S
000000b0: 080a 5408 0a55 08b1 00c0 0a01 0215 0025  ..T..U.........%
000000c0: 0675 0895 01a1 020a 0008 0a01 080a 0208  .u..............
000000d0: 0a03 080a 0408 0a05 080a 0608 b100 c00a  ................
000000e0: 0e03 1500 27ff ffff 7f75 2095 0155 00b1  ....'....u ..U..
000000f0: 020a 0403 1500 27ff ffff 7f75 2095 0155  ......'....u ..U
00000100: 00b1 020a b124 1500 26fe ff75 1095 0155  .....$..&..u...U
00000110: 0db1 020a b134 1500 26fe ff75 1095 0155  .....4..&..u...U
00000120: 0db1 020a b214 1500 26fe ff75 1095 0155  ........&..u...U
00000130: 0db1 020a b174 1500 26fe ff75 1095 0155  .....t..&..u...U
00000140: 0db1 020a be24 15a6 255a 7508 9501 5500  .....$..%Zu...U.
00000150: b102 0abe 3415 a625 5a75 0895 0155 00b1  ....4..%Zu...U..
00000160: 020a be14 1500 25b4 7508 9501 5500 b102  ......%.u...U...
00000170: 0abf 2415 a625 5a75 0895 0155 00b1 020a  ..$..%Zu...U....
00000180: bf34 15a6 255a 7508 9501 5500 b102 0abf  .4..%Zu...U.....
00000190: 1415 0025 b475 0895 0155 00b1 020a c014  ...%.u...U......
000001a0: 1500 2668 0175 1095 0155 00b1 020a c114  ..&h.u...U......
000001b0: 1500 2668 0175 1095 0155 00b1 020a c214  ..&h.u...U......
000001c0: 1500 25b4 7508 9501 5500 b102 0a01 0315  ..%.u...U.......
000001d0: 0026 ff7f 7510 9510 5500 b102 0a02 0315  .&..u...U.......
000001e0: 0026 ff7f 7510 9520 5500 b102 0520 0a01  .&..u.. U.... ..
000001f0: 0215 0025 0675 0895 01a1 020a 0008 0a01  ...%.u..........
00000200: 080a 0208 0a03 080a 0408 0a05 080a 0608  ................
00000210: 8100 c00a 0202 1500 2505 7508 9501 a102  ........%.u.....
00000220: 0a10 080a 1108 0a12 080a 1308 0a14 080a  ................
00000230: 1508 8100 c00a b104 1500 2501 7508 9501  ..........%.u...
00000240: 5500 8102 0abd 0415 0025 0175 0895 0155  U........%.u...U
00000250: 0081 020a b204 1500 26fe ff75 1095 0155  ........&..u...U
00000260: 0d81 0205 0a09 01a1 0205 200a b204 1500  .......... .....
00000270: 26fe ff75 1095 0155 0d81 420a bd04 1500  &..u...U..B.....
00000280: 2501 7508 9501 5500 8142 0abe 0415 a625  %.u...U..B.....%
00000290: 5a75 0895 0155 0081 420a bf04 15a6 255a  Zu...U..B.....%Z
000002a0: 7508 9501 5500 8142 0ac0 0416 0000 2668  u...U..B......&h
000002b0: 0175 1095 0155 0081 420a c104 164c ff26  .u...U..B....L.&
000002c0: b400 7510 9501 5500 8142 0ac2 0415 a625  ..u...U..B.....%
000002d0: 5a75 0895 0155 0081 420a c304 1500 26fe  Zu...U..B.....&.
000002e0: ff75 1095 0155 0081 42c0 050a 0902 a102  .u...U..B.......
000002f0: 0520 0ab2 0415 0026 feff 7510 9501 550d  . .....&..u...U.
00000300: 8142 0abd 0415 0025 0175 0895 0155 0081  .B.....%.u...U..
00000310: 420a be04 15a6 255a 7508 9501 5500 8142  B.....%Zu...U..B
00000320: 0abf 0415 a625 5a75 0895 0155 0081 420a  .....%Zu...U..B.
00000330: c004 1600 0026 6801 7510 9501 5500 8142  .....&h.u...U..B
00000340: 0ac1 0416 4cff 26b4 0075 1095 0155 0081  ....L.&..u...U..
00000350: 420a c204 15a6 255a 7508 9501 5500 8142  B.....%Zu...U..B
00000360: 0ac3 0415 0026 feff 7510 9501 5500 8142  .....&..u...U..B
00000370: c005 0a09 03a1 0205 200a b204 1500 26fe  ........ .....&.
00000380: ff75 1095 0155 0d81 420a bd04 1500 2501  .u...U..B.....%.
00000390: 7508 9501 5500 8142 0abe 0415 a625 5a75  u...U..B.....%Zu
000003a0: 0895 0155 0081 420a bf04 15a6 255a 7508  ...U..B.....%Zu.
000003b0: 9501 5500 8142 0ac0 0416 0000 2668 0175  ..U..B......&h.u
000003c0: 1095 0155 0081 420a c104 164c ff26 b400  ...U..B....L.&..
000003d0: 7510 9501 5500 8142 0ac2 0415 a625 5a75  u...U..B.....%Zu
000003e0: 0895 0155 0081 420a c304 1500 26fe ff75  ...U..B.....&..u
000003f0: 1095 0155 0081 42c0 c0c0 0520 0941 a100  ...U..B.... .A..
00000400: 850a 0520 0a09 0315 0025 0275 0895 01a1  ... .....%.u....
00000410: 020a 3008 0a31 080a 3208 b100 c00a 1603  ..0..1..2.......
00000420: 1500 2505 7508 9501 a102 0a40 080a 4108  ..%.u......@..A.
00000430: 0a42 080a 4308 0a44 080a 4508 b100 c00a  .B..C..D..E.....
00000440: 1903 1500 2505 7508 9501 a102 0a50 080a  ....%.u......P..
00000450: 5108 0a52 080a 5308 0a54 080a 5508 b100  Q..R..S..T..U...
00000460: c00a 0102 1500 2506 7508 9501 a102 0a00  ......%.u.......
00000470: 080a 0108 0a02 080a 0308 0a04 080a 0508  ................
00000480: 0a06 08b1 00c0 0a0e 0315 0027 ffff ffff  ...........'....
00000490: 7520 9501 5500 b102 0ad1 e415 0026 1027  u ..U........&.'
000004a0: 7510 9501 550e b102 0ad1 2415 0026 ff7f  u...U.....$..&..
000004b0: 7510 9501 550f b102 0ad1 3415 0026 ff7f  u...U.....4..&..
000004c0: 7510 9501 550f b102 0a01 0315 0026 ff7f  u...U........&..
000004d0: 7510 9510 5500 b102 0520 0a01 0215 0025  u...U.... .....%
000004e0: 0675 0895 01a1 020a 0008 0a01 080a 0208  .u..............
000004f0: 0a03 080a 0408 0a05 080a 0608 8100 c00a  ................
00000500: 0202 1500 2505 7508 9501 a102 0a10 080a  ....%.u.........
00000510: 1108 0a12 080a 1308 0a14 080a 1508 8100  ................
00000520: c00a d104 1500 26ff 7f55 0f75 1095 0181  ......&..U.u....
00000530: 020a d204 1500 26ff 7f55 0075 1095 0181  ......&..U.u....
00000540: 020a d404 1500 26ff 7f55 0c75 1095 0181  ......&..U.u....
00000550: 020a d504 1500 26ff 7f55 0c75 1095 0181  ......&..U.u....
00000560: 02c0 0600 ff09 01a1 0185 1105 2009 11a1  ............ ...
00000570: 0005 200a 0903 1500 2502 7508 9501 a102  .. .....%.u.....
00000580: 0a30 080a 3108 0a32 08b1 00c0 0a19 0315  .0..1..2........
00000590: 0025 0575 0895 01a1 020a 5008 0a51 080a  .%.u......P..Q..
000005a0: 5208 0a53 080a 5408 0a55 08b1 00c0 0a1f  R..S..T..U......
000005b0: 0315 0025 0375 0895 01a1 020a c009 0ac1  ...%.u..........
000005c0: 090a c209 0ac3 09b1 00c0 0a16 0315 0025  ...............%
000005d0: 0575 0895 01a1 020a 4008 0a41 080a 4208  .u......@..A..B.
000005e0: 0a43 080a 4408 0a45 08b1 00c0 0a01 0215  .C..D..E........
000005f0: 0025 0675 0895 01a1 020a 0008 0a01 080a  .%.u............
00000600: 0208 0a03 080a 0408 0a05 080a 0608 b100  ................
00000610: c00a 0e03 1500 27ff ffff 7f75 2095 0155  ......'....u ..U
00000620: 00b1 020a 0403 1500 27ff ffff 7f75 2095  ........'....u .
00000630: 0155 00b1 020a b124 1601 8026 ff7f 7510  .U.....$...&..u.
00000640: 9501 550d b102 0ab1 3416 0180 26ff 7f75  ..U.....4...&..u
00000650: 1095 0155 0db1 020a b214 1601 8026 ffff  ...U.........&..
00000660: 7510 9501 550d b102 0ab1 7416 0180 26ff  u...U.....t...&.
00000670: ff75 1095 0155 0db1 020a f103 1500 27ff  .u...U........'.
00000680: ffff 7f75 2095 0155 00b1 020a 0103 1500  ...u ..U........
00000690: 26ff 7f75 1095 1055 00b1 020a 0203 1500  &..u...U........
000006a0: 26ff 7f75 1095 2055 00b1 0285 130a f203  &..u.. U........
000006b0: 1500 26ff 7f75 1095 0155 00b1 0285 1205  ..&..u...U......
000006c0: 200a 0102 1500 2506 7508 9501 a102 0a00   .....%.u.......
000006d0: 080a 0108 0a02 080a 0308 0a04 080a 0508  ................
000006e0: 0a06 0881 00c0 0ab1 0415 0025 0175 0895  ...........%.u..
000006f0: 0155 0081 020a bd04 1500 2501 7508 9501  .U........%.u...
00000700: 5500 8102 0ab2 0416 0180 26ff 7f75 1095  U.........&..u..
00000710: 0155 0d81 02c0 c006 99ff 0901 a101 859a  .U..............
00000720: 0903 7508 957f 1500 26ff 00b1 0285 9b09  ..u.....&.......
00000730: 0495 7f81 02c0                           ......

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor
  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
  0 siblings, 1 reply; 10+ messages in thread
From: Srinivas Pandruvada @ 2026-11-29 14:37 UTC (permalink / raw)
  To: Shan Rizvi, Jonathan Cameron, Jiri Kosina, Benjamin Tissoires
  Cc: linux-iio, linux-input

On Sat, 2026-11-28 at 21:03 -0500, Shan Rizvi wrote:
> Hi Jonathan, Srinivas, Jiri, Benjamin, and all,
> 
> On an HP OmniBook X Flip Laptop 16-cc0xxx (board HP 8EA2, BIOS Insyde
> F.07), the integrated USB 2.0 camera (04f2:b872, "SunplusIT Inc HP
> 5MP
> Camera", interface 1-1:1.4) binds hid-sensor-hub and exposes two
> hid_sensor_prox (HID-SENSOR-200011) IIO devices:
> 
>   1. iio:device0 (HID-SENSOR-200011.3.auto)
>      - Physical 0x20:0x11 inside standard Sensor Application
> 0x20:0x01
>        (REPORT_ID 1).
>      - in_proximity0_sampling_frequency = 10.000000 Hz (100 ms).
>      - Works normally (live presence, distance, and attention
> readings).
> 
>   2. iio:device2 (HID-SENSOR-200011.6.auto)
>      - Physical 0x20:0x11 nested inside Vendor-Defined Application
>        Collection 0xff00:0x01 (HID-SENSOR-ff000001.5.auto, REPORT_ID
>        17, 19, 18).
>      - in_{proximity0,proximity1,attention}_sampling_frequency =
>        0.000100 Hz.

A huge value for report interval. One report per 10K seconds.
Not sure why add this optional field here.


>      - Reading any value channel stalls runtime PM for hours and
> wedges
>        any second concurrent reader in unkillable D-state inside
>        rpm_resume().
> 
> Root cause
> ----------
> In drivers/iio/common/hid-sensors/hid-sensor-trigger.c,
> _hid_sensor_power_state() (lines 106, 146-147 on mainline master)
> does:
> 
>     poll_value = hid_sensor_read_poll_value(st);
>     ...
>     if (state && poll_value)
>         msleep_interruptible(poll_value * 2);
> 

I think hung task warning when task is uninterruptible state:
:
Say Y here to enable the kernel to detect 'hung tasks', which are bugs
that cause the task to be stuck in uninterruptible 'D' state
indefinitely."
"


Anyway negative value check will not help, but should be added.
We can break msleep to 1 second loop to avoid hung task.
But "cat" will still wait for very long time here.

Try this:

Replace:
    if (state && poll_value)
        msleep_interruptible(poll_value * 2);

with

if (state && poll_value > 0) {
	unsigned long max_sleep_ms = 120 * MSEC_PER_SEC;
	unsigned long sleep_ms;

	if (IS_ENABLED(CONFIG_DETECT_HUNG_TASK) &&
	    CONFIG_DEFAULT_HUNG_TASK_TIMEOUT > 0)
		max_sleep_ms = CONFIG_DEFAULT_HUNG_TASK_TIMEOUT *
MSEC_PER_SEC;

	if (poll_value * 2 > max_sleep_ms)
		return -EIO;

	sleep_ms = min_t(u64, (u64)poll_value * 2, max_sleep_ms);
	msleep_interruptible(sleep_ms);
}

Thanks,
Srinivas


> There is no upper bound on poll_value * 2 (and checking poll_value
> rather than poll_value > 0 would also pass a negative error such as
> -EINVAL as a huge unsigned millisecond count to
> msleep_interruptible()).
> 
> On iio:device2, REPORT_ID 17 defines 0x20:0x30e (Property: Report
> Interval, 32-bit, unit=0 -> ms, max=2147483647) and the device
> reports
> sampling_frequency = 0.000100 Hz, corresponding to a poll_value in
> [5,000,001 .. 10,000,000] ms (1.39 to 2.78 hours). When a reader
> triggers hid_sensor_runtime_resume():
> 
>   - Reader 1 enters hid_sensor_runtime_resume() ->
>     _hid_sensor_power_state(st, true) while dev->power.runtime_status
>     is RPM_RESUMING, and sleeps in msleep_interruptible(poll_value *
> 2)
>     for 2.78 to 5.56 hours (TASK_INTERRUPTIBLE).
>   - Any concurrent Reader 2 (e.g., a second sysfs read or sensor
>     daemon) enters prox_read_raw() -> hid_sensor_power_state() ->
>     __pm_runtime_resume() -> rpm_resume(), sees RPM_RESUMING, and
>     sleeps on &dev->power.wait_queue in TASK_UNINTERRUPTIBLE (D-
> state)
>     until Reader 1's multi-hour sleep completes or is signaled.
> 
> In our observation on Nov 27, a concurrent cat (pid 858946) started
> around 19:46 EST and hung in unkillable D-state for ~2h 14m
> (triggering
> 10 hung-task warnings from 19:49:05 at 122s through 20:07:30 at
> 1228s)
> until system s2idle entry at 22:00:43, when the userspace freezer
> signaled Reader 1 out of msleep_interruptible(), completed
> rpm_resume(),
> and unblocked pid 858946 (freezing completed in 0.039s).
> 
> Environment
> -----------
> - Machine: HP OmniBook X Flip Laptop 16-cc0xxx (board HP 8EA2 rev
> 61.26,
>   SKU D31MPUA#ABA, BIOS Insyde F.07 08/31/2026)
> - Kernel: Linux 7.2.15-4-omarchy #1 SMP PREEMPT_DYNAMIC x86_64
>   (untainted; downstream Arch/Omarchy kernel with out-of-tree
> BORE/ADIOS
>   schedulers; hid-sensor-trigger/prox/hub behavior matches current
>   mainline drivers/iio/common/hid-sensors/hid-sensor-trigger.c:146-
> 147
>   and I am happy to retest on vanilla mainline/rc or a test patch)
> - Modules (srcversion):
>     hid_sensor_trigger:    DC4B969EEA8A8985CCBB823
>     hid_sensor_iio_common: 7B46F870DC1767B69877366
>     hid_sensor_prox:       A2D3710A71BC0FCE010B937
>     hid_sensor_hub:        B81ADED19C3243EFB66F46B
> - USB device 1-1 / interface 1-1:1.4:
>     idVendor=04f2, idProduct=b872, bcdDevice=10.20
>     manufacturer="SunplusIT Inc", product="HP 5MP Camera"
>     MODALIAS=usb:v04F2pB872d1020dcEFdsc02dp01ic03isc00ip00in04
> 
> HID report descriptor summary (1,846 bytes)
> -------------------------------------------
> (Full hex dump attached as 04f2-b872-report-descriptor.hex.)
> 
>   COLLECTION(Application) [0xff1b:0x8000]        # HID-SENSOR-
> ff1b8000.1.auto
>   COLLECTION(Application) [0x20:0x01]            # HID-SENSOR-
> 200001.2.auto
>     REPORT_ID 1 (0x01)
>     COLLECTION(Physical) [0x20:0x11]             # HID-SENSOR-
> 200011.3.auto (iio:device0, 10.000000 Hz)
>       Logical 0x20:0x309 (Property: Sensor Connection Type)
>       Logical 0x20:0x31f (Property: Human Presence Detection Type)
>       Logical 0x20:0x316 (Property: Reporting State)
>       Logical 0x20:0x319 (Property: Power State)
>       Feature 0x20:0x30e (Property: Report Interval, 32-bit, unit=0,
> max=2147483647)
>       Input   0x20:0x4b1 (Human Presence), 0x20:0x4b2 (Human
> Proximity Range)
>   COLLECTION(Physical) [0x20:0x41]               # HID-SENSOR-
> 200041.4.auto (iio:device1, ALS)
>   COLLECTION(Application) [0xff00:0x01]          # HID-SENSOR-
> ff000001.5.auto (vendor-defined)
>     REPORT_ID 17 (0x11)
>     COLLECTION(Physical) [0x20:0x11]             # HID-SENSOR-
> 200011.6.auto (iio:device2, 0.000100 Hz)
>       Logical 0x20:0x309 (Property: Sensor Connection Type)
>       Logical 0x20:0x319 (Property: Power State)
>       Logical 0x20:0x31f (Property: Human Presence Detection Type)
>       Logical 0x20:0x316 (Property: Reporting State)
>       Feature 0x20:0x30e (Property: Report Interval, 32-bit, unit=0,
> max=2147483647)
>       REPORT_ID 19 (0x13), REPORT_ID 18 (0x12)
>       Input   0x20:0x4b1 (Human Presence), 0x20:0x4b2 (Human
> Proximity Range)
>   COLLECTION(Application) [0xff99:0x01]          # HID-SENSOR-
> ff990001.7.auto
> 
> Reproduction
> ------------
> 1. Start Reader 1 on iio:device2 (it stalls in msleep_interruptible()
>    holding RPM_RESUMING):
>      cat /sys/bus/iio/devices/iio:device2/in_proximity0_raw &
> 2. Start Reader 2 concurrently:
>      cat /sys/bus/iio/devices/iio:device2/in_proximity0_raw
>    Reader 2 enters uninterruptible D-state in rpm_resume()
> (unkillable
>    by SIGKILL until Reader 1 is killed/signaled or the multi-hour
> sleep
>    expires).
> 
> Hung-task call trace (Reader 2, pid 858946)
> -------------------------------------------
> Nov 27 19:49:05 sophia kernel: INFO: task cat:858946 blocked for more
> than 122 seconds.
> Nov 27 19:49:05 sophia kernel:       Not tainted 7.2.15-4-omarchy #1
> Nov 27 19:49:05 sophia kernel: "echo 0 >
> /proc/sys/kernel/hung_task_timeout_secs" disables this message.
> Nov 27 19:49:05 sophia kernel: task:cat             state:D
> stack:0     pid:858946 tgid:858946 ppid:858816 task_flags:0x400000
> flags:0x00080000
> Nov 27 19:49:05 sophia kernel: Call Trace:
> Nov 27 19:49:05 sophia kernel:  <TASK>
> Nov 27 19:49:05 sophia kernel:  __schedule+0x40f/0x1780
> Nov 27 19:49:05 sophia kernel:  schedule+0x27/0xa0
> Nov 27 19:49:05 sophia kernel:  rpm_resume+0x1cf/0x860
> Nov 27 19:49:05 sophia kernel:  ?
> __pfx_autoremove_wake_function+0x10/0x10
> Nov 27 19:49:05 sophia kernel:  __pm_runtime_resume+0x52/0x90
> Nov 27 19:49:05 sophia kernel:  hid_sensor_power_state+0x55/0xe0
> [hid_sensor_trigger 377a49e4e9428c72b857ea6ddd3ff77490c88f22]
> Nov 27 19:49:05 sophia kernel:  prox_read_raw+0x159/0x350
> [hid_sensor_prox 791fda5099b57d4de72068c9268ea72b5ae63472]
> Nov 27 19:49:05 sophia kernel:  iio_read_channel_info+0x1b3/0x3f0
> [industrialio df90c867801c29de6d58c14a6d53db307f32a0b7]
> Nov 27 19:49:05 sophia kernel:  ? __kvmalloc_node_noprof+0x674/0x7d0
> Nov 27 19:49:05 sophia kernel:  dev_attr_show+0x1f/0x50
> Nov 27 19:49:05 sophia kernel:  sysfs_kf_seq_show+0xa8/0x110
> Nov 27 19:49:05 sophia kernel:  seq_read_iter+0x131/0x4c0
> Nov 27 19:49:05 sophia kernel:  ? security_file_permission+0x55/0x170
> Nov 27 19:49:05 sophia kernel:  vfs_read+0x375/0x600
> Nov 27 19:49:05 sophia kernel:  __x64_sys_read+0x7e/0x110
> Nov 27 19:49:05 sophia kernel:  do_syscall_64+0xaa/0x630
> Nov 27 19:49:05 sophia kernel:  ? do_syscall_64+0xaa/0x630
> Nov 27 19:49:05 sophia kernel:  ? handle_mm_fault+0x1dd/0x2c0
> Nov 27 19:49:05 sophia kernel:  ? do_syscall_64+0x5f/0x630
> Nov 27 19:49:05 sophia kernel:  ? exc_page_fault+0x90/0x1c0
> Nov 27 19:49:05 sophia kernel: 
> entry_SYSCALL_64_after_hwframe+0x76/0x7e
> Nov 27 19:49:05 sophia kernel: RIP: 0033:0x7f4d25511b0d
> [registers omitted]
> Nov 27 19:49:05 sophia kernel:  </TASK>
> 
> Questions / possible fix directions
> -----------------------------------
> 1. In drivers/iio/common/hid-sensors/hid-sensor-trigger.c:
>    Should _hid_sensor_power_state() check poll_value > 0 (avoiding
>    huge unsigned sleeps on negative errors) and clamp poll_value * 2
>    to a reasonable upper bound (e.g., min(poll_value * 2, ...)), so a
>    sensor reporting a multi-hour Report Interval cannot hold
>    RPM_RESUMING for hours and wedge concurrent readers in D-state?
> 2. In drivers/hid/hid-sensor-hub.c:
>    Should sensor_hub_probe() skip standard Sensor Physical
> collections
>    (0x20:*) nested inside vendor-defined Application Collections
>    (0xff00:0x01), or is a device quirk for 04f2:b872 preferred?
> 
> Happy to attach the raw binary descriptor, test a patch on vanilla
> mainline/rc on this hardware, or submit a patch for (1) if you agree
> on
> an appropriate cap.
> 
> Thanks,
> Shan Rizvi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor
  2026-11-29 14:37 ` Srinivas Pandruvada
@ 2026-11-29 17:26   ` Shan Rizvi
  2026-11-29 17:54     ` Srinivas Pandruvada
  0 siblings, 1 reply; 10+ messages in thread
From: Shan Rizvi @ 2026-11-29 17:26 UTC (permalink / raw)
  To: Srinivas Pandruvada, Jonathan Cameron, Jiri Kosina,
	Benjamin Tissoires
  Cc: linux-iio, linux-input

On Sun, 2026-11-29 at 06:37 -0800, Srinivas Pandruvada wrote:
> Try this:
>
> Replace:
>     if (state && poll_value)
>         msleep_interruptible(poll_value * 2);
>
> with
>
> if (state && poll_value > 0) {
> 	unsigned long max_sleep_ms = 120 * MSEC_PER_SEC;
> 	unsigned long sleep_ms;
>
> 	if (IS_ENABLED(CONFIG_DETECT_HUNG_TASK) &&
> 	    CONFIG_DEFAULT_HUNG_TASK_TIMEOUT > 0)
> 		max_sleep_ms = CONFIG_DEFAULT_HUNG_TASK_TIMEOUT *
> MSEC_PER_SEC;
>
> 	if (poll_value * 2 > max_sleep_ms)
> 		return -EIO;
>
> 	sleep_ms = min_t(u64, (u64)poll_value * 2, max_sleep_ms);
> 	msleep_interruptible(sleep_ms);
> }

Thanks for the quick reply!

I built and tested this on the HP 8EA2 laptop (with (u64)poll_value * 2
in the if condition as well, since poll_value is s32 and REPORT_ID 17
declares max=2147483647, so s32 * 2 could overflow).

Good news:
- The multi-hour stall and rpm_resume() D-state hang on
  HID-SENSOR-200011.6.auto are gone, and the working 10 Hz proximity
  sensor (HID-SENSOR-200011.3.auto) and ALS (HID-SENSOR-200041.4.auto)
  continue to work normally.

However, testing turned up a side effect from returning -EIO inside
_hid_sensor_power_state():

Every read of HID-SENSOR-200011.6.auto now triggers a runtime PM
underflow in dmesg:

  hid_sensor_prox HID-SENSOR-200011.6.auto: Runtime PM usage count underflow!

Tracing why:
1. drivers/iio/light/hid-sensor-prox.c:prox_read_raw() (lines 93, 103)
   calls hid_sensor_power_state(..., true) without checking the return
   value, proceeds into sensor_hub_input_attr_get_raw_value() (~5s sync
   timeout -> returns 0), and then unconditionally calls
   hid_sensor_power_state(..., false). Because
   pm_runtime_resume_and_get() already dropped the usage count on -EIO,
   the paired pm_runtime_put_autosuspend() underflows on every read.
2. Returning -EIO at line 146 also runs after sensor_hub_device_open(),
   atomic_inc(&st->data_ready), powering the sensor to D0/ALL_EVENTS,
   and atomic_inc(&st->user_requested_state) in hid_sensor_power_state()
   without unwinding them on the error path (affecting callers like
   buffer_postenable() that do check the return value), and latches
   dev->power.runtime_error = -EIO.

Two small additional notes:
- Capping sleep_ms to CONFIG_DEFAULT_HUNG_TASK_TIMEOUT (120s) could
  still let a concurrent reader in rpm_resume() trip the 120s hung-task
  warning if a device reports e.g. poll_value = 60000 ms; capping lower
  (or returning 0 after a smaller clamped sleep, e.g. a few seconds)
  would avoid both the hung-task warning and the -EIO unwind/underflow
  issues above.
- While unloading the unpatched stock module before this test,
  modprobe -r hid_sensor_prox also hit the same multi-hour
  msleep_interruptible() stall via __device_release_driver() ->
  pm_runtime_get_sync() -> hid_sensor_runtime_resume() once runtime PM
  had previously been enabled on HID-SENSOR-200011.6.auto (woken by
  SIGINT).

Would you prefer:
(a) clamping the sleep in _hid_sensor_power_state() and returning 0
    (no runtime PM error/underflow, e.g. capping at a few seconds or
    half of hung_task timeout), or
(b) keeping the -EIO rejection, checking poll_value before
    sensor_hub_device_open() (and decrementing user_requested_state on
    failure), plus checking hid_sensor_power_state() return values in
    hid-sensor-prox (and other hid-sensor-* callers)?

Happy to test either approach on this hardware and send a patch if you'd
like.

Thanks,
Shan Rizvi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor
  2026-11-29 17:26   ` Shan Rizvi
@ 2026-11-29 17:54     ` Srinivas Pandruvada
  2026-11-29 19:18       ` Shan Rizvi
  0 siblings, 1 reply; 10+ messages in thread
From: Srinivas Pandruvada @ 2026-11-29 17:54 UTC (permalink / raw)
  To: Shan Rizvi, Jonathan Cameron, Jiri Kosina, Benjamin Tissoires
  Cc: linux-iio, linux-input

[-- Attachment #1: Type: text/plain, Size: 3976 bytes --]

On Sun, 2026-11-29 at 12:26 -0500, Shan Rizvi wrote:
> On Sun, 2026-11-29 at 06:37 -0800, Srinivas Pandruvada wrote:
> > Try this:
> > 
> > Replace:
> >     if (state && poll_value)
> >         msleep_interruptible(poll_value * 2);
> > 
> > with
> > 
> > if (state && poll_value > 0) {
> > 	unsigned long max_sleep_ms = 120 * MSEC_PER_SEC;
> > 	unsigned long sleep_ms;
> > 
> > 	if (IS_ENABLED(CONFIG_DETECT_HUNG_TASK) &&
> > 	    CONFIG_DEFAULT_HUNG_TASK_TIMEOUT > 0)
> > 		max_sleep_ms = CONFIG_DEFAULT_HUNG_TASK_TIMEOUT *
> > MSEC_PER_SEC;
> > 
> > 	if (poll_value * 2 > max_sleep_ms)
> > 		return -EIO;
> > 
> > 	sleep_ms = min_t(u64, (u64)poll_value * 2, max_sleep_ms);
> > 	msleep_interruptible(sleep_ms);
> > }
> 
> Thanks for the quick reply!
> 
> I built and tested this on the HP 8EA2 laptop (with (u64)poll_value *
> 2
> in the if condition as well, since poll_value is s32 and REPORT_ID 17
> declares max=2147483647, so s32 * 2 could overflow).
> 
> Good news:
> - The multi-hour stall and rpm_resume() D-state hang on
>   HID-SENSOR-200011.6.auto are gone, and the working 10 Hz proximity
>   sensor (HID-SENSOR-200011.3.auto) and ALS (HID-SENSOR-
> 200041.4.auto)
>   continue to work normally.
> 
> However, testing turned up a side effect from returning -EIO inside
> _hid_sensor_power_state():
> 
> Every read of HID-SENSOR-200011.6.auto now triggers a runtime PM
> underflow in dmesg:
> 
>   hid_sensor_prox HID-SENSOR-200011.6.auto: Runtime PM usage count
> underflow!
> 
> Tracing why:
> 1. drivers/iio/light/hid-sensor-prox.c:prox_read_raw() (lines 93,
> 103)
>    calls hid_sensor_power_state(..., true) without checking the
> return
>    value, proceeds into sensor_hub_input_attr_get_raw_value() (~5s
> sync
>    timeout -> returns 0), and then unconditionally calls
>    hid_sensor_power_state(..., false). Because
>    pm_runtime_resume_and_get() already dropped the usage count on -
> EIO,
>    the paired pm_runtime_put_autosuspend() underflows on every read.
> 2. Returning -EIO at line 146 also runs after
> sensor_hub_device_open(),
>    atomic_inc(&st->data_ready), powering the sensor to D0/ALL_EVENTS,
>    and atomic_inc(&st->user_requested_state) in
> hid_sensor_power_state()
>    without unwinding them on the error path (affecting callers like
>    buffer_postenable() that do check the return value), and latches
>    dev->power.runtime_error = -EIO.
> 
> Two small additional notes:
> - Capping sleep_ms to CONFIG_DEFAULT_HUNG_TASK_TIMEOUT (120s) could
>   still let a concurrent reader in rpm_resume() trip the 120s hung-
> task
>   warning if a device reports e.g. poll_value = 60000 ms; capping
> lower
>   (or returning 0 after a smaller clamped sleep, e.g. a few seconds)
>   would avoid both the hung-task warning and the -EIO
> unwind/underflow
>   issues above.
> - While unloading the unpatched stock module before this test,
>   modprobe -r hid_sensor_prox also hit the same multi-hour
>   msleep_interruptible() stall via __device_release_driver() ->
>   pm_runtime_get_sync() -> hid_sensor_runtime_resume() once runtime
> PM
>   had previously been enabled on HID-SENSOR-200011.6.auto (woken by
>   SIGINT).
> 
> Would you prefer:
> (a) clamping the sleep in _hid_sensor_power_state() and returning 0
>     (no runtime PM error/underflow, e.g. capping at a few seconds or
>     half of hung_task timeout), or



> (b) keeping the -EIO rejection, checking poll_value before
>     sensor_hub_device_open() (and decrementing user_requested_state
> on
>     failure), plus checking hid_sensor_power_state() return values in
>     hid-sensor-prox (and other hid-sensor-* callers)?
> 
This may be better. Try the attached:

Thanks,
Srinivas

> Happy to test either approach on this hardware and send a patch if
> you'd
> like.
> 
> Thanks,
> Shan Rizvi

[-- Attachment #2: invalid_sensor.diff --]
[-- Type: text/x-patch, Size: 982 bytes --]

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index cb7713646e21..b995bbe0811f 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -518,6 +518,18 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 	int i;
 
 	hid_sensor_get_reporting_interval(hsdev, usage_id, st);
+	value =	hid_sensor_read_poll_value(st);
+	if (value > 0) {
+		unsigned long max_sleep_ms = 120 * MSEC_PER_SEC; /* default hung task timeout */
+
+		if (IS_ENABLED(CONFIG_DETECT_HUNG_TASK) && CONFIG_DEFAULT_HUNG_TASK_TIMEOUT > 0)
+			max_sleep_ms = CONFIG_DEFAULT_HUNG_TASK_TIMEOUT * MSEC_PER_SEC;
+
+		if (value * 2 >= max_sleep_ms) {
+			hid_err(hsdev->hdev, "Invalid sampling interval, will cause task hangs\n");
+			return -EINVAL;
+		}
+	}
 
 	sensor_hub_input_get_attribute_info(hsdev,
 					HID_FEATURE_REPORT, usage_id,

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor
  2026-11-29 17:54     ` Srinivas Pandruvada
@ 2026-11-29 19:18       ` Shan Rizvi
  2026-11-30 13:07         ` Srinivas Pandruvada
  0 siblings, 1 reply; 10+ messages in thread
From: Shan Rizvi @ 2026-11-29 19:18 UTC (permalink / raw)
  To: Srinivas Pandruvada, Jonathan Cameron, Jiri Kosina,
	Benjamin Tissoires
  Cc: linux-iio, linux-input

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!

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor
  2026-11-29 19:18       ` Shan Rizvi
@ 2026-11-30 13:07         ` Srinivas Pandruvada
  2026-11-30 17:45           ` Shan Rizvi
  0 siblings, 1 reply; 10+ messages in thread
From: Srinivas Pandruvada @ 2026-11-30 13:07 UTC (permalink / raw)
  To: Shan Rizvi, Jonathan Cameron, Jiri Kosina, Benjamin Tissoires
  Cc: linux-iio, linux-input

[-- 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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor
  2026-11-30 13:07         ` Srinivas Pandruvada
@ 2026-11-30 17:45           ` Shan Rizvi
  2026-11-30 19:03             ` Srinivas Pandruvada
  0 siblings, 1 reply; 10+ messages in thread
From: Shan Rizvi @ 2026-11-30 17:45 UTC (permalink / raw)
  To: Srinivas Pandruvada, Jonathan Cameron, Jiri Kosina,
	Benjamin Tissoires
  Cc: linux-iio, linux-input

On Mon, 2026-11-30 at 05:07 -0800, Srinivas Pandruvada wrote:
> I think I want to fix by setting report interval rather than ignoring
> that sensor. Try the attached.

Tested on the HP 8EA2 (Chicony 04F2:B872) against 7.2.15:

- Initial HID-SENSOR-200011.6.auto sampling frequency: 0.000100 Hz.
- First read of in_proximity0_raw returned 0 in 9560 ms (runtime_status
  transitioned to active, no hung task, no runtime PM underflow).
- Two concurrent reads of in_proximity0_raw both returned 0 cleanly in
  10237 ms with no D-state block.
- After runtime autosuspend (4 s idle -> suspended), a subsequent read
  returned 0 in 9303 ms and in_proximity0_sampling_frequency updated
  from 0.000100 Hz to 0.500000 Hz (2000 ms).
- The working sensors (HID-SENSOR-200011.3.auto 10 Hz prox and
  HID-SENSOR-200041.4.auto 10 Hz ALS) continued reading normally, and
  module unload/reload completed cleanly.

One small observation: in_proximity0_sampling_frequency still read
0.000100 Hz immediately after the first read and only switched to
0.500000 Hz after the post-autosuspend power-on (likely because
hid_sensor_limit_poll_value() runs before power_state/report_state are
written on the first D0 transition). Either way, the sleep was bounded
at 4 s from the very first read and the hang is completely gone.

Tested-by: Shan Rizvi <shan@rizvi.nu>

Thanks,
Shan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor
  2026-11-30 17:45           ` Shan Rizvi
@ 2026-11-30 19:03             ` Srinivas Pandruvada
  2026-12-01 19:52               ` Shan Rizvi
  0 siblings, 1 reply; 10+ messages in thread
From: Srinivas Pandruvada @ 2026-11-30 19:03 UTC (permalink / raw)
  To: Shan Rizvi, Jonathan Cameron, Jiri Kosina, Benjamin Tissoires
  Cc: linux-iio, linux-input

[-- Attachment #1: Type: text/plain, Size: 1578 bytes --]

On Mon, 2026-11-30 at 12:45 -0500, Shan Rizvi wrote:
> On Mon, 2026-11-30 at 05:07 -0800, Srinivas Pandruvada wrote:
> > I think I want to fix by setting report interval rather than
> > ignoring
> > that sensor. Try the attached.
> 
> Tested on the HP 8EA2 (Chicony 04F2:B872) against 7.2.15:
> 
> - Initial HID-SENSOR-200011.6.auto sampling frequency: 0.000100 Hz.
> - First read of in_proximity0_raw returned 0 in 9560 ms
> (runtime_status
>   transitioned to active, no hung task, no runtime PM underflow).
> - Two concurrent reads of in_proximity0_raw both returned 0 cleanly
> in
>   10237 ms with no D-state block.
> - After runtime autosuspend (4 s idle -> suspended), a subsequent
> read
>   returned 0 in 9303 ms and in_proximity0_sampling_frequency updated
>   from 0.000100 Hz to 0.500000 Hz (2000 ms).
> - The working sensors (HID-SENSOR-200011.3.auto 10 Hz prox and
>   HID-SENSOR-200041.4.auto 10 Hz ALS) continued reading normally, and
>   module unload/reload completed cleanly.
> 
> One small observation: in_proximity0_sampling_frequency still read
> 0.000100 Hz immediately after the first read and only switched to
> 0.500000 Hz after the post-autosuspend power-on (likely because
> hid_sensor_limit_poll_value() runs before power_state/report_state
> are
> written on the first D0 transition). Either way, the sleep was
> bounded
> at 4 s from the very first read and the hang is completely gone.
> 
Changed the order, please try.

Thanks,
Srinivas

> Tested-by: Shan Rizvi <shan@rizvi.nu>
> 
> Thanks,
> Shan

[-- Attachment #2: 0001-iio-hid-sensors-Limit-the-poll-interval-when-powerin.patch --]
[-- Type: text/x-patch, Size: 3726 bytes --]

From 0822bc3f280ddaf047fc3cc50f6d0362cb61decf 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 v2] 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.

Read and set the poll interval after the power state and reporting
state are set, as the sensor may not accept a new poll interval while
it is not powered on.

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")
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
 .../common/hid-sensors/hid-sensor-trigger.c   | 43 ++++++++++++++++---
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index 60808e2430ca..8e5c06d59d63 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -82,11 +82,40 @@ 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;
 	int report_val;
-	s32 poll_value = 0;
 
 	if (state) {
 		if (sensor_hub_device_open(st->hsdev))
@@ -102,8 +131,6 @@ static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state)
 			st->report_state.report_id,
 			st->report_state.index,
 			HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM);
-
-		poll_value = hid_sensor_read_poll_value(st);
 	} else {
 		int val;
 
@@ -143,8 +170,14 @@ static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state)
 	sensor_hub_get_feature(st->hsdev, st->power_state.report_id,
 			       st->power_state.index,
 			       sizeof(state_val), &state_val);
-	if (state && poll_value)
-		msleep_interruptible(poll_value * 2);
+	if (state) {
+		s32 poll_value;
+
+		/* The sensor may ignore the poll interval when not powered on */
+		poll_value = hid_sensor_limit_poll_value(st);
+		if (poll_value)
+			msleep_interruptible(poll_value * 2);
+	}
 
 	return 0;
 }
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor
  2026-11-30 19:03             ` Srinivas Pandruvada
@ 2026-12-01 19:52               ` Shan Rizvi
  2026-12-01 20:08                 ` Srinivas Pandruvada
  0 siblings, 1 reply; 10+ messages in thread
From: Shan Rizvi @ 2026-12-01 19:52 UTC (permalink / raw)
  To: Srinivas Pandruvada, Jonathan Cameron, Jiri Kosina,
	Benjamin Tissoires
  Cc: linux-iio, linux-input

On Mon, 2026-11-30 at 11:03 -0800, Srinivas Pandruvada wrote:
> Changed the order, please try.

Works here (HP 8EA2, Chicony 04F2:B872, 7.2.15). First read of
in_proximity0_raw takes 4.0 s, two concurrent reads 6 ms, a read after
autosuspend 4.0 s. No hung task, no runtime PM underflow.

But I owe you a correction: the order doesn't matter. I ran the
previous patch and this one back to back with the same debug prints
and they behave identically. The 9.5 s reads and the 0.5 Hz I reported
last time don't reproduce. The hub started logging "control queue
full" a few minutes after that run, so I suspect it was misbehaving
and sysfs was showing the cached value, but I can't prove that now.
Sorry for the noise.

While checking why the readback never changes, I dumped the feature
reports through hidraw. The interval isn't really huge. Report 17
doesn't match its descriptor. From offset 5, where both reports declare
Report Interval and then Minimum Report Interval as 32 bits each:

  report 1 (working prox), 128 bytes, as declared:
    64 00 00 00 64 00 00 00 a0 0f 32 00 c8 00 32 00 ...

  report 17 (this sensor), 119 bytes, 121 declared:
    d0 07 64 00 00 00 a0 0f 32 00 19 00 32 00 ...

Report 17 is 2 bytes short, and it only lines up with report 1 if
Report Interval is 16 bits on the wire: 2000, then Minimum Report
Interval 100, then 4000 and 50 as in report 1. So the driver reads
interval | (100 << 16), which is 6553600 ms or more whatever the
interval is. Writing sampling_frequency changes only the low 16 bits:

  10 Hz  -> 64 00 64 00
  1 Hz   -> e8 03 64 00
  0.5 Hz -> d0 07 64 00

(The 2000 above is left over from my earlier tests. I don't know what
the firmware starts with.)

So with the patch the SET of 2000 does reach the device, but the value
read back is always above the limit, and this sensor gets the write
and the 4 s wait on every power on. A descriptor fixup for 04F2:B872
would be the real fix for this device. I can test one or send one if
you want.

Tested-by: Shan Rizvi <shan@rizvi.nu>

Thanks,
Shan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor
  2026-12-01 19:52               ` Shan Rizvi
@ 2026-12-01 20:08                 ` Srinivas Pandruvada
  0 siblings, 0 replies; 10+ messages in thread
From: Srinivas Pandruvada @ 2026-12-01 20:08 UTC (permalink / raw)
  To: Shan Rizvi, Jonathan Cameron, Jiri Kosina, Benjamin Tissoires
  Cc: linux-iio, linux-input

On Tue, 2026-12-01 at 14:52 -0500, Shan Rizvi wrote:
> On Mon, 2026-11-30 at 11:03 -0800, Srinivas Pandruvada wrote:
> > Changed the order, please try.
> 
> Works here (HP 8EA2, Chicony 04F2:B872, 7.2.15). First read of
> in_proximity0_raw takes 4.0 s, two concurrent reads 6 ms, a read
> after
> autosuspend 4.0 s. No hung task, no runtime PM underflow.
> 
> But I owe you a correction: the order doesn't matter. I ran the
> previous patch and this one back to back with the same debug prints
> and they behave identically. The 9.5 s reads and the 0.5 Hz I
> reported
> last time don't reproduce. The hub started logging "control queue
> full" a few minutes after that run, so I suspect it was misbehaving
> and sysfs was showing the cached value, but I can't prove that now.
> Sorry for the noise.
> 
> While checking why the readback never changes, I dumped the feature
> reports through hidraw. The interval isn't really huge. Report 17
> doesn't match its descriptor. From offset 5, where both reports
> declare
> Report Interval and then Minimum Report Interval as 32 bits each:
> 
>   report 1 (working prox), 128 bytes, as declared:
>     64 00 00 00 64 00 00 00 a0 0f 32 00 c8 00 32 00 ...
> 
>   report 17 (this sensor), 119 bytes, 121 declared:
>     d0 07 64 00 00 00 a0 0f 32 00 19 00 32 00 ...
> 
> Report 17 is 2 bytes short, and it only lines up with report 1 if
> Report Interval is 16 bits on the wire: 2000, then Minimum Report
> Interval 100, then 4000 and 50 as in report 1. So the driver reads
> interval | (100 << 16), which is 6553600 ms or more whatever the
> interval is. Writing sampling_frequency changes only the low 16 bits:
> 
>   10 Hz  -> 64 00 64 00
>   1 Hz   -> e8 03 64 00
>   0.5 Hz -> d0 07 64 00
> 
> (The 2000 above is left over from my earlier tests. I don't know what
> the firmware starts with.)
> 
> So with the patch the SET of 2000 does reach the device, but the
> value
> read back is always above the limit, and this sensor gets the write
> and the 4 s wait on every power on. A descriptor fixup for 04F2:B872
> would be the real fix for this device. I can test one or send one if
> you want.
> 
> Tested-by: Shan Rizvi <shan@rizvi.nu>

I will submit v1 only as that order makes more sense. First set the
parameters like report interval and then power on.

Thanks,
Srinivas

> 
> Thanks,
> Shan

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-12-01 20:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-11-30 17:45           ` Shan Rizvi
2026-11-30 19:03             ` Srinivas Pandruvada
2026-12-01 19:52               ` Shan Rizvi
2026-12-01 20:08                 ` Srinivas Pandruvada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox