Skip to contentSkip to conversation

Writing to /sys/../power/autosuspend when not root.

DISCUSSION Dave Mielke 3 participants 6 messages Apr 26, 2020 – Apr 28, 2020 USB

lore
Share & tools
lore
#0 lore raw

We're working on getting brltty to run as an unprivileged user with just a few required capabilities. We don't want one of those required capabilities to be CAP_DAC_OVERRIDE (bypass file permission checks).

Some USB-connected braille devices don't respond very well to being autosuspended. We get around this, when running as root, by writing to the SYSFS power/autosuspend file associated with the device. Our problem is that only the root user can write to it.

Other than using CAP_DAC_OVERRIDE (which we don't want to do), what other way(s) might we be able to use to overcome this restriction? For example, is there some kind of safe (enough) udev rule?

Signature · 4 lines
I believe the Bible to be the very Word of God: http://Mielke.cc/bible/
Dave Mielke            | 2213 Fox Crescent | WebHome: http://Mielke.cc/
EMail: [email protected]  | Ottawa, Ontario   | Twitter: @Dave_Mielke
Phone: +1 613 726 0014 | Canada  K2A 1H7   |
maintainer
#1 lore raw
Quoted 4 lines · Dave Mielke

We're working on getting brltty to run as an unprivileged user with just a few required capabilities. We don't want one of those required capabilities to be CAP_DAC_OVERRIDE (bypass file permission checks).

Quoted 8 lines

Some USB-connected braille devices don't respond very well to being autosuspended. We get around this, when running as root, by writing to the SYSFS power/autosuspend file associated with the device. Our problem is that only the root user can write to it.

Other than using CAP_DAC_OVERRIDE (which we don't want to do), what other way(s) might we be able to use to overcome this restriction? For example, is there some kind of safe (enough) udev rule?

Have a udev rule that turns autosuspend off for each specific USB device that you know does not work with autosuspend. Do you have such a list?

If so, we can add it to the USB core with the USB_QUIRK_DISCONNECT_SUSPEND flag. Or is it the USB_QUIRK_NO_LPM that they need? I can't remember, but you can test it out from userspace by reading about those in the Documentation/admin-guide/kernel-parameters.txt file.

Hope this helps,

greg k-h

#2 lore raw
Quoted 14 lines · Greg KH
Quoted 4 lines · Dave Mielke

We're working on getting brltty to run as an unprivileged user with just a few required capabilities. We don't want one of those required capabilities to be CAP_DAC_OVERRIDE (bypass file permission checks).

Quoted 8 lines

Some USB-connected braille devices don't respond very well to being autosuspended. We get around this, when running as root, by writing to the SYSFS power/autosuspend file associated with the device. Our problem is that only the root user can write to it.

Other than using CAP_DAC_OVERRIDE (which we don't want to do), what other way(s) might we be able to use to overcome this restriction? For example, is there some kind of safe (enough) udev rule?

Quoted 8 lines

Have a udev rule that turns autosuspend off for each specific USB device that you know does not work with autosuspend. Do you have such a list?

If so, we can add it to the USB core with the USB_QUIRK_DISCONNECT_SUSPEND flag. Or is it the USB_QUIRK_NO_LPM that they need? I can't remember, but you can test it out from userspace by reading about those in the Documentation/admin-guide/kernel-parameters.txt file.

A udev rule will probably work a lot better than a quirk flag. In fact, I don't think we have a quirk flag for "don't autosuspend". DISCONNECT_SUSPEND doesn't affect autosuspends, only system sleeps. And NO_LPM only affects USB-3 devices.

A suitable udev rule should be pretty easy to write.

Alan Stern

#3 lore raw
In reply to Greg KH

[quoted lines by Greg KH on 2020/04/27 at 12:30 +0200]

Quoted 2 lines

Have a udev rule that turns autosuspend off for each specific USB device that you know does not work with autosuspend.

Yes, thanks, that should work. I have another question, though. Our code first tries to write "-1" to power/autosuspend, and then, if that fails, it writes "0". I'm guessing that "-1" was an older way (but I've forgotten). How can a udev rule be written to accommodate that?

Signature · 4 lines
I believe the Bible to be the very Word of God: http://Mielke.cc/bible/
Dave Mielke            | 2213 Fox Crescent | WebHome: http://Mielke.cc/
EMail: [email protected]  | Ottawa, Ontario   | Twitter: @Dave_Mielke
Phone: +1 613 726 0014 | Canada  K2A 1H7   |
maintainer
#4 lore raw
Quoted 9 lines · Dave Mielke

[quoted lines by Greg KH on 2020/04/27 at 12:30 +0200]

Quoted 2 lines

Have a udev rule that turns autosuspend off for each specific USB device that you know does not work with autosuspend.

Yes, thanks, that should work. I have another question, though. Our code first tries to write "-1" to power/autosuspend, and then, if that fails, it writes "0". I'm guessing that "-1" was an older way (but I've forgotten). How can a udev rule be written to accommodate that?

udev rules can run any script/program that they want to :)

greg k-h

#5 lore raw
In reply to Dave Mielke
Quoted 9 lines · Dave Mielke

[quoted lines by Greg KH on 2020/04/27 at 12:30 +0200]

Quoted 2 lines

Have a udev rule that turns autosuspend off for each specific USB device that you know does not work with autosuspend.

Yes, thanks, that should work. I have another question, though. Our code first tries to write "-1" to power/autosuspend, and then, if that fails, it writes "0". I'm guessing that "-1" was an older way (but I've forgotten). How can a udev rule be written to accommodate that?

See the entry for "/sys/bus/usb/devices/.../power/autosuspend" in Documentation/ABI/stable/sysfs-bus-usb, or the corresponding entry for "/sys/devices/.../power/autosuspend_delay_ms" in Documentation/ABI/testing/sysfs-devices-power.

In short, -1 means "don't autosuspend", whereas 0 means "autosuspend as soon as possible".

Alan Stern