From 929211010da4da715d819f24a69b7bdccab5b8bc Mon Sep 17 00:00:00 2001 From: saiththerobo Date: Wed, 4 Nov 2026 08:43:54 +0000 Subject: [PATCH 1/2] omamobile-modem: a start refused before any driver loads releases the sleep block omamobile-modem-inhibit holds a block on sleep from before the modem's drivers load until the reboot, since suspend with the modem up isn't qualified. But a start that refuses before any driver loads (a stale modem-up marker after a forced restart, the bring-up latch) left that block in place for the whole boot, so the phone never slept although no modem was up, and systemctl suspend needed -i (#390). refuse() now kills the inhibitor (it refuses a manual stop) when it is running and none of pcie_gs201_cp, shm_ipc and cpif is loaded. Once a driver has loaded, nothing changes: the block stays until the reboot. An unprovisioned phone skips the inhibitor by its own conditions, so nothing is released there. Co-Authored-By: Claude Opus 5.5 --- .../omamobile-modem/lib/omamobile-modem-start | 21 ++++++++++++++++++- .../systemd/omamobile-modem-inhibit.service | 13 +++++++----- packages/omamobile-modem/test/all | 21 +++++++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/packages/omamobile-modem/lib/omamobile-modem-start b/packages/omamobile-modem/lib/omamobile-modem-start index 8b90ad187..aa643befd 100755 --- a/packages/omamobile-modem/lib/omamobile-modem-start +++ b/packages/omamobile-modem/lib/omamobile-modem-start @@ -72,15 +72,34 @@ PROPS=${OMAMOBILE_MODEM_PROPS:-/var/lib/omamobile-vendor/modem/props.conf} # for it. Suspend with the modem on has never run on this phone (MODEM-PLAN # section 6.3), so nothing may sleep once they are loaded. INHIBITOR=omamobile-modem +# Where a refusal looks for the modem's drivers, and what releases the +# inhibitor (overridden by the test). +SYSMODULE=${OMAMOBILE_MODEM_SYSMODULE:-/sys/module} +SYSTEMCTL=${OMAMOBILE_MODEM_SYSTEMCTL:-systemctl} say() { printf 'omamobile-modem: %s\n' "$*" >&2; } boot_id() { cat /proc/sys/kernel/random/boot_id; } # A refusal's one-line reason for the shell (short: it is a tile's status -# line), then exit 1. Nothing else is written by a refusal. +# line), then exit 1. Nothing else is written by a refusal. A refusal with +# none of the modem's drivers loaded never touched the modem, so the sleep +# block has nothing to guard this boot: release it (a kill, since the +# inhibitor refuses a manual stop). Once a driver has loaded, it stays until +# the reboot, as before. refuse() { mkdir -p "$(dirname "$REFUSED")" 2>/dev/null && printf '%s\n' "$1" > "$REFUSED" 2>/dev/null || true + release_inhibitor exit 1 } +release_inhibitor() { + local m + for m in pcie_gs201_cp shm_ipc cpif; do + [[ -d $SYSMODULE/$m ]] && return 0 + done + "$SYSTEMCTL" is-active -q omamobile-modem-inhibit.service 2>/dev/null || return 0 + "$SYSTEMCTL" kill omamobile-modem-inhibit.service >/dev/null 2>&1 && + say "no modem driver loaded: sleep is no longer blocked this boot" + return 0 +} # The refused copies a stale marker leaves (the retry counter), as words. refused_copies() { local c; c=$(compgen -G "$UP.refused-*" 2>/dev/null) || true; printf '%s' "${c//$'\n'/ }"; } diff --git a/packages/omamobile-modem/systemd/omamobile-modem-inhibit.service b/packages/omamobile-modem/systemd/omamobile-modem-inhibit.service index 95a68df5b..71112bf3f 100644 --- a/packages/omamobile-modem/systemd/omamobile-modem-inhibit.service +++ b/packages/omamobile-modem/systemd/omamobile-modem-inhibit.service @@ -3,11 +3,14 @@ # modem on has never run on the Pixel 7 Pro (device/cheetah/MODEM-PLAN.md # 6.3), and the one 9a try with the CP up never woke. omamobile-modem.service # requires this and starts after it, and its start script refuses to load -# a driver until the lock shows in `systemd-inhibit --list`. Nothing stops -# it but the reboot: stopping the modem unit by hand leaves it (Requires= -# is one way), and a manual stop is refused. A phone with the modem at boot -# therefore never sleeps; the shell's auto-sleep and upower's critical -# action are told so by logind ("Operation inhibited"). The modem unit's +# a driver until the lock shows in `systemd-inhibit --list`. Once a driver +# has loaded, nothing stops it but the reboot: stopping the modem unit by +# hand leaves it (Requires= is one way), and a manual stop is refused. A +# phone with the modem up therefore never sleeps; the shell's auto-sleep +# and upower's critical action are told so by logind ("Operation +# inhibited"). A start that refuses before any driver loads (a stale marker, +# the latch, no CPIF) kills it, and the phone sleeps as without a modem +# (omamobile-modem-start's refuse()). The modem unit's # Requires= pulls this in even when that unit's own conditions skip it, so # the same three conditions are here: a phone that isn't provisioned (no # modem files, checksums or board id) keeps sleeping. diff --git a/packages/omamobile-modem/test/all b/packages/omamobile-modem/test/all index 239a8d599..e5b0ebc99 100755 --- a/packages/omamobile-modem/test/all +++ b/packages/omamobile-modem/test/all @@ -199,6 +199,11 @@ pass "start script: markers before the drivers, the check after them, READY befo m=$t/markers; mkdir -p "$m/root"; : > "$m/nv.sha256"; printf 'ro.boot.cdt_hwid=TESTID\n' > "$m/props.conf" export OMAMOBILE_MODEM_LATCH=$m/latch OMAMOBILE_MODEM_UP_MARK=$m/up OMAMOBILE_MODEM_HOLD=$m/hold OMAMOBILE_MODEM_REFUSED=$m/run/refused export OMAMOBILE_MODEM_CHROOT=$m/root OMAMOBILE_MODEM_NV_SUMS=$m/nv.sha256 OMAMOBILE_MODEM_PROPS=$m/props.conf +# What a refusal releases: a fake systemctl that logs its arguments, and an +# empty module directory (no modem driver loaded) unless a test adds one. +mkdir -p "$m/sysmodule" +printf '#!/bin/sh\ncase $1 in is-active) [ -e %s/inhibit-active ];; *) echo "$*" >> %s/systemctl.log;; esac\n' "$m" "$m" > "$m/systemctl"; chmod +x "$m/systemctl" +export OMAMOBILE_MODEM_SYSMODULE=$m/sysmodule OMAMOBILE_MODEM_SYSTEMCTL=$m/systemctl start() { timeout 20 bash $s "$@" 2>&1; } past() { OMAMOBILE_MODEM_TEST_STOP_AFTER_CHECKS=1 start "$@"; } stop_line='past the marker checks, stopping here (test only)' @@ -232,6 +237,22 @@ out=$(start) && fail "a bring-up latch is refused" [[ -e $m/latch && $(cat "$m/run/refused") == "Off: last bring-up hung" ]] || fail "the latch stays, with its reason for the tile" out=$(start) && fail "the latch refuses the boot after too" rm -f "$m/latch" +# A refusal before any modem driver loads releases the sleep block; with a +# driver loaded (here cpif) it stays until the reboot, and an inhibitor that +# isn't running (an unprovisioned phone skips it) is left alone. +rm -f "$m/systemctl.log"; printf 'x boot y\n' > "$m/latch" +out=$(start) && fail "a latch refusal fails" +[[ ! -e $m/systemctl.log ]] || fail "no inhibitor running: nothing to release" +: > "$m/inhibit-active" +out=$(start) && fail "a latch refusal fails" +[[ $(cat "$m/systemctl.log" 2>/dev/null) == "kill omamobile-modem-inhibit.service" && $out == *"sleep is no longer blocked"* ]] || + fail "a refusal with no modem driver loaded kills the inhibitor: $(cat "$m/systemctl.log" 2>/dev/null) / $out" +rm -f "$m/systemctl.log"; mkdir -p "$m/sysmodule/cpif" +out=$(start) && fail "a latch refusal fails" +[[ ! -e $m/systemctl.log && $out != *"no longer blocked"* ]] || fail "with a modem driver loaded the inhibitor stays: $(cat "$m/systemctl.log" 2>/dev/null)" +rmdir "$m/sysmodule/cpif"; rm -f "$m/latch" "$m/systemctl.log" "$m/inhibit-active" +grep -q 'release_inhibitor$' $s && [[ $(grep -c 'release_inhibitor' $s) -eq 2 ]] || fail "only refuse() releases the inhibitor" +pass "a refusal before any modem driver loads releases the sleep block; after one, it stays" # A stale modem-up marker (a boot that ended with the modem up and no clean # stop) refuses once: the marker moves aside, named by the time, and the # next boot gets past the markers (here: to the test stop point, with the From b50995ef8191d5572c397466257e7c8f840e1db0 Mon Sep 17 00:00:00 2001 From: saiththerobo Date: Tue, 10 Nov 2026 07:37:53 +0000 Subject: [PATCH 2/2] omamobile-modem: a driver that doesn't load is a refusal too Review of #424: a modprobe that failed left through set -e, not refuse(), so the sleep block stayed although the unit comment said "no CPIF" released it. Each modprobe now refuses with its module's name for the tile ("Off: cpif didn't load"). refuse() then releases the block only when none of the modem's drivers is loaded, and that list now takes the device's link stack from link.conf (#568) as well as pcie_gs201_cp, shm_ipc and cpif: a module that loaded and failed in probe keeps the block, one that never loaded releases it. The latch stays either way, as it did. test_link.py runs the real starter through both cases (the first link module fails: the block goes; the second fails with the first loaded, a module named only in link.conf: it stays), with a fake systemctl so the tests never ask the host's. The inhibitor's and the modem unit's headers and cheetah's MODEM-PLAN M4.6 get the dated release. Co-Authored-By: Claude Opus 5.5 --- device/cheetah/MODEM-PLAN.md | 5 +++ .../omamobile-modem/lib/omamobile-modem-start | 21 ++++++++---- .../systemd/omamobile-modem-inhibit.service | 7 ++-- .../systemd/omamobile-modem.service | 4 ++- packages/omamobile-modem/test/all | 8 ++++- packages/omamobile-modem/test/test_link.py | 34 +++++++++++++++++-- 6 files changed, 64 insertions(+), 15 deletions(-) diff --git a/device/cheetah/MODEM-PLAN.md b/device/cheetah/MODEM-PLAN.md index 3299dbfa2..720ab05ea 100644 --- a/device/cheetah/MODEM-PLAN.md +++ b/device/cheetah/MODEM-PLAN.md @@ -2717,6 +2717,11 @@ What the packages now do, opt-in and nothing enabled by them: with the modem on has never run on this phone, 6.3). The start script refuses to load a driver until the lock shows in `systemd-inhibit --list`. With the stack at boot the phone never sleeps. + Since 2026-11-10 (#424) a start that refuses with none of the modem's + drivers loaded (a stale `modem-up` marker, the bring-up latch, a link + driver that didn't load) kills the lock, so the phone sleeps that boot + as it would without a modem; once a driver has loaded, the lock stays + until the reboot. - **`omamobile-modem.service` is `Type=notify`**: ready once CPIF's ports exist and the profile's read-only check has passed, before the CP is powered on. The device's sitd drop-in diff --git a/packages/omamobile-modem/lib/omamobile-modem-start b/packages/omamobile-modem/lib/omamobile-modem-start index aa643befd..e92f02a75 100755 --- a/packages/omamobile-modem/lib/omamobile-modem-start +++ b/packages/omamobile-modem/lib/omamobile-modem-start @@ -91,9 +91,14 @@ refuse() { exit 1 } release_inhibitor() { - local m - for m in pcie_gs201_cp shm_ipc cpif; do - [[ -d $SYSMODULE/$m ]] && return 0 + local m entry mods=(pcie_gs201_cp shm_ipc cpif) + # The device's link stack too, once link.conf is read (refusals come + # before it as well). + for entry in ${LINK_MODULES[@]+"${LINK_MODULES[@]}"}; do + mods+=("${entry%%[[:blank:]]*}") + done + for m in "${mods[@]}"; do + [[ -d $SYSMODULE/${m//-/_} ]] && return 0 done "$SYSTEMCTL" is-active -q omamobile-modem-inhibit.service 2>/dev/null || return 0 "$SYSTEMCTL" kill omamobile-modem-inhibit.service >/dev/null 2>&1 && @@ -240,13 +245,15 @@ sync # CPIF and the regions are blacklisted by the device's modem policy (the # package providing omamobile-modem-policy): only this loads them. Never -# unload cpif (it is permanent by design). +# unload cpif (it is permanent by design). A module that doesn't load is a +# refusal: with none of them loaded the sleep block goes, and one that +# loaded before it keeps the block (refuse()). The latch stays either way. for entry in "${LINK_MODULES[@]}"; do read -r -a words <<< "$entry" - modprobe "${words[@]}" + modprobe "${words[@]}" || refuse "Off: ${words[0]} didn't load" done -modprobe shm_ipc -modprobe cpif +modprobe shm_ipc || refuse "Off: shm_ipc didn't load" +modprobe cpif || refuse "Off: cpif didn't load" # The link to the modem with ASPM off, as every link test so far ran # (M3.1); the endpoint's own L1 substates are never enabled (the link API's # l1ss control is a no-op). diff --git a/packages/omamobile-modem/systemd/omamobile-modem-inhibit.service b/packages/omamobile-modem/systemd/omamobile-modem-inhibit.service index 71112bf3f..ad2ff841b 100644 --- a/packages/omamobile-modem/systemd/omamobile-modem-inhibit.service +++ b/packages/omamobile-modem/systemd/omamobile-modem-inhibit.service @@ -8,9 +8,10 @@ # hand leaves it (Requires= is one way), and a manual stop is refused. A # phone with the modem up therefore never sleeps; the shell's auto-sleep # and upower's critical action are told so by logind ("Operation -# inhibited"). A start that refuses before any driver loads (a stale marker, -# the latch, no CPIF) kills it, and the phone sleeps as without a modem -# (omamobile-modem-start's refuse()). The modem unit's +# inhibited"). A start that refuses with none of the modem's drivers loaded +# (a stale marker, the latch, a link driver that didn't load) kills it, and +# the phone sleeps as without a modem (omamobile-modem-start's refuse()). +# The modem unit's # Requires= pulls this in even when that unit's own conditions skip it, so # the same three conditions are here: a phone that isn't provisioned (no # modem files, checksums or board id) keeps sleeping. diff --git a/packages/omamobile-modem/systemd/omamobile-modem.service b/packages/omamobile-modem/systemd/omamobile-modem.service index d360acae4..8f1de2d7f 100644 --- a/packages/omamobile-modem/systemd/omamobile-modem.service +++ b/packages/omamobile-modem/systemd/omamobile-modem.service @@ -5,7 +5,9 @@ # boot the whole stack comes from omamobile-modem-boot.target (M4.6), which # the Pixel 7 Pro's device package enables. It starts the modem after the # audio stack (the AoC carries call audio) and behind the sleep inhibitor -# (omamobile-modem-inhibit.service), which stays until the reboot. +# (omamobile-modem-inhibit.service), which stays until the reboot once a +# modem driver has loaded; since 2026-11-10 a start refused before that +# releases it. # # The three conditions are what tools/phone-provision puts on the phone: # Google's modem files, the NV checksums from the owner's backup and the diff --git a/packages/omamobile-modem/test/all b/packages/omamobile-modem/test/all index e5b0ebc99..b40c13f17 100755 --- a/packages/omamobile-modem/test/all +++ b/packages/omamobile-modem/test/all @@ -250,7 +250,13 @@ out=$(start) && fail "a latch refusal fails" rm -f "$m/systemctl.log"; mkdir -p "$m/sysmodule/cpif" out=$(start) && fail "a latch refusal fails" [[ ! -e $m/systemctl.log && $out != *"no longer blocked"* ]] || fail "with a modem driver loaded the inhibitor stays: $(cat "$m/systemctl.log" 2>/dev/null)" -rmdir "$m/sysmodule/cpif"; rm -f "$m/latch" "$m/systemctl.log" "$m/inhibit-active" +rmdir "$m/sysmodule/cpif"; mkdir -p "$m/sysmodule/pcie_gs201_cp" +out=$(start) && fail "a latch refusal fails" +[[ ! -e $m/systemctl.log ]] || fail "with the link driver loaded (pcie-gs201-cp as pcie_gs201_cp) the inhibitor stays" +rmdir "$m/sysmodule/pcie_gs201_cp"; rm -f "$m/latch" "$m/systemctl.log" "$m/inhibit-active" +# A driver that doesn't load is a refusal too (so it can release the block), +# not an exit through set -e. +[[ $(grep -c '^[[:space:]]*modprobe .*|| refuse "Off: ' $s) -eq 3 ]] || fail "every modprobe refuses when it fails" grep -q 'release_inhibitor$' $s && [[ $(grep -c 'release_inhibitor' $s) -eq 2 ]] || fail "only refuse() releases the inhibitor" pass "a refusal before any modem driver loads releases the sleep block; after one, it stays" # A stale modem-up marker (a boot that ended with the modem up and no clean diff --git a/packages/omamobile-modem/test/test_link.py b/packages/omamobile-modem/test/test_link.py index c7893dd42..b43446ccc 100644 --- a/packages/omamobile-modem/test/test_link.py +++ b/packages/omamobile-modem/test/test_link.py @@ -38,7 +38,7 @@ def test_mismatched_values_refuse(self): self.assertNotEqual(self.run_value(value, wanted), 0) def test_device_modules_load_in_order_with_arguments(self): - loop = re.search(r'for entry in "\$\{LINK_MODULES\[@\]\}"; do\n read -r -a words <<< "\$entry"\n modprobe "\$\{words\[@\]\}"\ndone', SOURCE).group() + loop = re.search(r'for entry in "\$\{LINK_MODULES\[@\]\}"; do\n read -r -a words <<< "\$entry"\n modprobe "\$\{words\[@\]\}" \|\| refuse "Off: \$\{words\[0\]\} didn\'t load"\ndone', SOURCE).group() script = ('LINK_MODULES=("first allow_hw=1" "second cpif=1")\n' 'modprobe() { printf "%s " "$@"; printf "\\n"; }\n' + loop) result = subprocess.run(['bash', '-c', script], text=True, capture_output=True, check=True) @@ -61,7 +61,7 @@ def test_loaded_module_mismatch_refuses_before_loading(self): self.assertEqual(result.returncode, 0 if value == 'Y' else 7) self.assertEqual('load-reached' in result.stdout, value == 'Y') - def run_starter(self, config, loaded=None): + def run_starter(self, config, loaded=None, fail_module=None, inhibitor=False): """Run actual starter with only paths redirected and inert external tools.""" config_path = self.root / 'link.conf' if config is not None: @@ -86,7 +86,9 @@ def run_starter(self, config, loaded=None): for name, body in { 'systemd-inhibit': 'echo inhibitor >> "$TRACE"; echo "omamobile-modem held"', 'sync': ':', - 'modprobe': 'test -f "$OMAMOBILE_MODEM_LATCH" || exit 23; echo "load:$*" >> "$TRACE"', + 'modprobe': 'test -f "$OMAMOBILE_MODEM_LATCH" || exit 23; echo "load:$*" >> "$TRACE"; ' + '[[ $1 != "${FAIL_MODULE:-}" ]] || exit 1; mkdir -p "$SYSMODULE/${1//-/_}"', + 'systemctl': 'case $1 in is-active) test -e "$INHIBIT_ACTIVE";; *) echo "systemctl:$*" >> "$TRACE";; esac', }.items(): tool = tools / name tool.write_text('#!/bin/bash\n' + body + '\n') @@ -109,6 +111,14 @@ def run_starter(self, config, loaded=None): OMAMOBILE_MODEM_CHROOT=str(provision), OMAMOBILE_MODEM_NV_SUMS=str(provision), OMAMOBILE_MODEM_PROPS=str(provision)) + modules = self.root / 'loaded' + modules.mkdir() + if inhibitor: + (self.root / 'inhibit-active').touch() + env.update(OMAMOBILE_MODEM_SYSMODULE=str(modules), SYSMODULE=str(modules), + OMAMOBILE_MODEM_SYSTEMCTL=str(tools / 'systemctl'), + INHIBIT_ACTIVE=str(self.root / 'inhibit-active'), + FAIL_MODULE=fail_module or '') env.pop('OMAMOBILE_MODEM_TEST_STOP_AFTER_CHECKS', None) result = subprocess.run(['bash', str(starter)], env=env, capture_output=True, text=True, timeout=5) @@ -120,6 +130,24 @@ def test_data_list_reaches_inhibitor_then_ordered_loads_with_latch(self): self.assertEqual(trace, ['inhibitor', 'inhibitor', 'load:first allow_hw=1', 'load:second cpif=1', 'load:shm_ipc', 'load:cpif', 'profile-check']) + def test_first_module_failing_refuses_and_releases_the_sleep_block(self): + result, trace = self.run_starter('first allow_hw=1\nsecond cpif=1\n', 'Y', + fail_module='first', inhibitor=True) + self.assertEqual(result.returncode, 1) + self.assertEqual(trace, ['inhibitor', 'inhibitor', 'load:first allow_hw=1', + 'systemctl:kill omamobile-modem-inhibit.service']) + self.assertEqual((self.root / 'refused').read_text().strip(), "Off: first didn't load") + self.assertTrue((self.root / 'latch').exists()) + + def test_later_module_failing_keeps_the_sleep_block(self): + # Only first is loaded, a module known by its name in link.conf alone. + result, trace = self.run_starter('first allow_hw=1\nsecond cpif=1\n', 'Y', + fail_module='second', inhibitor=True) + self.assertEqual(result.returncode, 1) + self.assertEqual(trace, ['inhibitor', 'inhibitor', 'load:first allow_hw=1', + 'load:second cpif=1']) + self.assertEqual((self.root / 'refused').read_text().strip(), "Off: second didn't load") + def test_no_config_preserves_real_default_load(self): result, trace = self.run_starter(None) self.assertEqual(result.returncode, 1)