From 0c202432145be9fe3df75d8d6ff9c6af8e4b8daa Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Sun, 6 Sep 2026 19:34:36 -0400 Subject: [PATCH] Bound GPU mode requests during sleep --- default/systemd/system-sleep/force-igpu | 5 ++++- .../system-sleep-ownership-migration-test.sh | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/default/systemd/system-sleep/force-igpu b/default/systemd/system-sleep/force-igpu index 85acebfd..8568067e 100644 --- a/default/systemd/system-sleep/force-igpu +++ b/default/systemd/system-sleep/force-igpu @@ -14,7 +14,10 @@ sleep_action=${SYSTEMD_SLEEP_ACTION:-$2} switch_mode() { local expected="$1" current - /usr/bin/supergfxctl -m "$expected" + if ! /usr/bin/timeout --kill-after=1s 3s /usr/bin/supergfxctl -m "$expected"; then + echo "Could not request the GPU transition to $expected mode" >&2 + return 1 + fi for _ in {1..10}; do if current=$(/usr/bin/timeout --kill-after=1s 2s /usr/bin/supergfxctl -g 2>/dev/null) && [[ $current == "$expected" ]]; then diff --git a/test/shell.d/system-sleep-ownership-migration-test.sh b/test/shell.d/system-sleep-ownership-migration-test.sh index 73558265..36d1c95c 100644 --- a/test/shell.d/system-sleep-ownership-migration-test.sh +++ b/test/shell.d/system-sleep-ownership-migration-test.sh @@ -529,6 +529,10 @@ cat >"$stub_bin/hook-supergfxctl" <<'SH' case "$1" in -m) printf '%s\n' "$*" >>"$HOOK_CALLS" + if [[ ${HOOK_BLOCK_MODE:-} == "$2" ]]; then + trap '' TERM + /usr/bin/sleep 30 + fi current=$(sed -n 's/.*"mode"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$HOOK_CONFIG") if [[ $current != "$2" ]]; then printf '%s %s\n' "$2" "${HOOK_CONFIRM_AFTER:-1}" >"$HOOK_PENDING" @@ -627,6 +631,22 @@ grep -Fq '"mode": "Integrated"' "$hook_config" || [[ ! -e $hook_marker ]] || fail "force-igpu leaves restore intent after a confirmed retry" pass "force-igpu retains restore intent until Integrated mode is confirmed" +: >"$hook_calls" +: >"$hook_queries" +printf '{ "mode": "Integrated" }\n' >"$hook_config" +env "${hook_env[@]}" bash "$hook_copy" pre suspend +set +e +HOOK_BLOCK_MODE=Vfio env "${hook_env[@]}" \ + bash "$hook_copy" post suspend >/dev/null 2>&1 +blocked_request_status=$? +set -e +(( blocked_request_status != 0 )) || fail "force-igpu waits forever for a blocked GPU transition request" +[[ -f $hook_marker ]] || fail "force-igpu discards restore intent after a blocked transition request" +[[ ! -s $hook_queries ]] || fail "force-igpu polls before a blocked transition request returns" +env "${hook_env[@]}" bash "$hook_copy" post suspend +[[ ! -e $hook_marker ]] || fail "force-igpu cannot retry after a blocked transition request" +pass "force-igpu bounds blocked transition requests and retains retry intent" + : >"$hook_calls" printf '{ "mode": "Integrated" }\n' >"$hook_config" env "${hook_env[@]}" bash "$hook_copy" pre hibernate