[Bug 1980991] Re: /usr/sbin/on_ac_power incorrectly reporting ac power status

Robie Basak 1980991 at bugs.launchpad.net
Wed Sep 4 11:27:46 UTC 2024


Thank you for working on this!

SRU review

> Currently there is an issue with the ac_on_power script where it
thinks that USB-c ports with devices plugged in to them are plugged in
to power.

This isn't a statement of user impact, making it difficult to understand
how changing the stable releases is justified.

But looking through the bug, I found a mention of unattended-upgrades
not running on some systems because they are falsely believing that they
are never on AC power. That implies a user impact of "system isn't
automatically updated as expected". That does justify updating the
stable release.

Is that the only user impact, or are there other cases we need to
consider as well? This is important because if we identify other use
cases then we will be able to know to test them.

> [Test Plan]

Please try to test the actual user impact, which in this case might mean
running unattended-upgrades and ensuring that it does update on such a
system. Running on_ac_power is a helpful diagnostic but it would be
preferable to ensure that nothing else has been missed by testing the
end goal directly as close as is possible.

Further, changing this code could regress existing systems into thinking
they never are on AC power any more and therefore never run unattended-
upgrades any more. This would stop security updates and so the
consequences would be quite severe.

For this reason please further test:

a) Not just one power state of the machine, but that all reasonable
power states of the machine return the expected result...

b) ...across some reasonable set of combinations of machines with and
without USB-C sink and/or source capability...

c) ...considering different "online" states of sinks and sources, given
my review point below and that the current separated code paths suggest
that a bug may be present in this area.

On the actual upload:

1. There are spurious development artifacts being added - various
combinations of {focal,jammy,noble}-powermgmt.debdiff. Please re-upload
with these removed.

2.

> +               power_type="USB*"

This does a glob expansion right here, which I think isn't what is
intended. If there are files in the current directory with this pattern
then they will be expanded here. This needs fixing.

3. I also don't follow the logic used here. What if a sink is found but
it isn't online, and a source exists but is online? Wouldn't that
incorrectly identify the system as being on AC power? As far as I can
tell from just reading the code, the systemd example presented in the MP
doesn't have this behaviour, but the code in this upload would. It's
difficult to tell just from inspection though because the addition of
this code makes it quite convoluted. Am I missing something?

Point 1 above requires re-upload, so I'm rejecting the current items
from the Unapproved queue for now. Please address the other matters
raised above before re-uploading.


** Changed in: powermgmt-base (Ubuntu Focal)
       Status: Confirmed => Incomplete

** Changed in: powermgmt-base (Ubuntu Jammy)
       Status: Confirmed => Incomplete

** Changed in: powermgmt-base (Ubuntu Noble)
       Status: Confirmed => Incomplete

-- 
You received this bug notification because you are a member of Ubuntu
Sponsors, which is subscribed to the bug report.
https://bugs.launchpad.net/bugs/1980991

Title:
  /usr/sbin/on_ac_power incorrectly reporting ac power status

Status in powermgmt-base package in Ubuntu:
  Fix Released
Status in powermgmt-base source package in Focal:
  Incomplete
Status in powermgmt-base source package in Jammy:
  Incomplete
Status in powermgmt-base source package in Kinetic:
  Won't Fix
Status in powermgmt-base source package in Lunar:
  Won't Fix
Status in powermgmt-base source package in Mantic:
  Won't Fix
Status in powermgmt-base source package in Noble:
  Incomplete
Status in powermgmt-base source package in Oracular:
  Fix Released
Status in powermgmt-base package in Debian:
  New

Bug description:
  Thank you @kevintate for the original bug report.

  [Impact]

  Currently there is an issue with the ac_on_power script where it thinks that USB-c ports with devices plugged in to them are plugged in to power. This is because the script does not check first if these usb-c ports are in sink or source mode first.
  The solution is to check /sys/class/typec/* for the mode these usb ports are in, and ignore them if none of them are running in source mode.

  [Test Plan]

  On a device with a USB-c port (it does not matter if the port can be
  used for powering the device or not) run the following test:

  1. Install the patched version of on_ac_power

  2. run: $ on_ac_power

  3. check the return value: $ echo $?

  compare the return value with the actual state of the machine. If the
  machine is not plugged in to power, you should expect 0 as the return
  code.

  If the machine is plugged in then the return code should be 1.

  If you receive 255 as an return code then the script was unable to
  determine the power profile of the machine and is related to the
  kernel not exposing enough information to user space. Consumers of
  on_ac_power generally consider such a return code as the machine being
  plugged in to power.

  [Where problems could occur]

  * the script could still incorrectly return the state of power of the
  machine, specially if the kernel incorrectly advertises a usbc port to
  be in a different mode then it is in.

  
  [Original Description]
  Good afternoon, folks.

  I believe I discovered a bug in the /usr/sbin/on_ac_power script. I
  have a Dell OptiPlex 5090 host that has an entry in
  /sys/class/power_supply for "ucsi-source-psy-USBC000:001". I believe
  this is the USB-C power delivery port on the front of the chassis. The
  issue I'm encountering is that /usr/sbin/on_ac_power is exiting with
  code 1 which states: (1 (false) if not on AC power) when that isn't
  the case.

  This looks to be because of the ucsi-source-psy-USBC000:001 entry
  reporting the "online" status as 0, presumably because nothing is
  currently connected to that USB-C port.

  This causes /usr/sbin/on_ac_power to incorrectly report that the
  machine isn't connected to AC power and causes other utilities like
  unattended-upgrades to quit when using the default configuration since
  it believes the machine isn't connected to AC power.

  There is a workaround with unattended-upgrades where you can specify
  it to run regardless of if AC power is connected, but as more and more
  chassis implement power-delivery USB-C ports I foresee this becoming
  more of an issue.

  I'm not sure if it's anything to look into, but I figured I would
  share my findings. Please let me know if you have any questions or if
  I can provide any additional information, troubleshooting, or testing.

  Thanks!
  -Kevin

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/powermgmt-base/+bug/1980991/+subscriptions




More information about the Ubuntu-sponsors mailing list