Skip to content

[chassisd]: Enhance DPU auto-recovery robustness and race condition handling#829

Merged
vvolam merged 12 commits into
sonic-net:masterfrom
vvolam:dpu_ras_fix
Jul 20, 2026
Merged

[chassisd]: Enhance DPU auto-recovery robustness and race condition handling#829
vvolam merged 12 commits into
sonic-net:masterfrom
vvolam:dpu_ras_fix

Conversation

@vvolam

@vvolam vvolam commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Description

Enhance the DPU auto-recovery state machine in chassisd to fix race conditions between concurrent operations (shutdown/reboot vs power-cycle), improve correctness of the default behavior, and refactor for maintainability.

Key changes:

  • Read dpu_auto_recovery from DEVICE_METADATA instead of FEATURE table
  • Default to disabled when the dpu_auto_recovery field is missing (safer default)
  • Direct transition to ManualIntervention when auto-recovery is disabled (skip WaitForSelfRecovery)
  • PCIe detach/reattach around power-cycle for clean hardware reset
  • Check reset_limit before issuing power-cycle to avoid wasted resets
  • Acquire state transition lock during power-cycle to prevent races with gnoi shutdown/reboot
  • Re-check transition_in_progress after lock acquisition to close TOCTOU window
  • Abort power-cycle if lock cannot be acquired (another operation in progress)
  • Unify field name: use transition_in_progress (drop legacy state_transition_in_progress)
  • Ignore transition_type == 'recovery' so chassisd does not suppress itself
  • Refactor: extract _process_single_dpu_recovery to reduce update_dpu_recovery_state size
  • Refactor: extract _enter_booting/_enter_ready/_enter_wait_for_self_recovery transition helpers
  • Refactor: extract _should_handle_hw_offline for offline-state guard clarity
  • Refactor: extract _handle_boot_timeout_expired shared by Booting and PowerCycle states

Depends on sonic-net/sonic-platform-common PR for get_module_state_transition/set_module_state_transition/clear_module_state_transition platform API.

Motivation and Context

Addresses review comments from PR #815. The DPU auto-recovery feature had several race conditions:

  1. Power-cycle recovery vs planned shutdown: If gnoi initiated a shutdown while chassisd was about to power-cycle, both operations would conflict, potentially bricking the DPU.
  2. TOCTOU between check and lock: A gap between checking if a transition was in progress and acquiring the lock allowed concurrent operations to slip through.
  3. Default-enabled risk: Missing dpu_auto_recovery field defaulted to enabled, which could cause unexpected power-cycles on systems without explicit configuration.

How Has This Been Tested?

  1. Unit tests: Comprehensive unit tests added in tests/test_dpu_auto_recovery.py covering all state transitions, race conditions, lock acquisition failures, and edge cases.

  2. On-device testing on a 202605/master image (SmartSwitch), via the sonic-mgmt smartswitch/platform_tests suite, which exercises the DPU failure-mode / auto-recovery scenarios:

    • Control-plane-down → auto-recovery power-cycle → DPU returns to ready_status=true
    • Auto-recovery disabled → direct ManualIntervention (no power-cycle)
    • Power-cycle with lock contention (gnoi shutdown holding the transition lock)
    • TOCTOU re-check after lock acquisition
    • Self-suppression (transition_type == 'recovery' exclusion)
    • Unrecoverable state after reset_limit exceeded; admin-down/up clears it
    • NPU crash → bulk power-cycle of all admin-up DPUs

    Final results (202605/master): the end-to-end auto-recovery path was confirmed — chassisd power-cycled the failed DPU and it returned to ready_status=true. After the accompanying fixes (device DEVICE_METADATA.dpu_auto_recovery YANG leaf, the module_base recovery transition-timeout default, and a recovery-timeout bump), test_dpu_failure_modes finished 5 passed / 2 failed / 1 skipped (0 errored). Both remaining failures were environmental/test-harness — a databasedpu container inactive at test start, and a config-reload case that ran on pre-fix test code — not auto-recovery regressions.

  3. Verified: No regressions on remaining DPUs (remained in Ready state throughout DPU0 destructive testing)

Additional Information (Optional)

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

…andling

- Read dpu_auto_recovery from DEVICE_METADATA instead of FEATURE table
- Default to disabled when dpu_auto_recovery field is missing
- Direct ManualIntervention when auto-recovery disabled (skip WaitForSelfRecovery)
- PCIe detach/reattach around power-cycle for clean hardware reset
- Check reset_limit before issuing power-cycle to avoid wasted resets
- Acquire state transition lock during power-cycle to prevent races
- Re-check transition_in_progress after lock to close TOCTOU window
- Abort power-cycle if lock cannot be acquired (another operation in progress)
- Unify field name: use transition_in_progress (drop legacy state_transition_in_progress)
- Ignore transition_type == 'recovery' so chassisd does not suppress itself
- Refactor: extract _process_single_dpu_recovery to reduce update_dpu_recovery_state size
- Refactor: extract _enter_booting/_enter_ready/_enter_wait_for_self_recovery helpers
- Refactor: extract _should_handle_hw_offline for offline-state guard clarity
- Refactor: extract _handle_boot_timeout_expired shared by Booting and PowerCycle
- Add comprehensive unit tests for all new behaviors

Signed-off-by: Vasundhara Volam <vvolam@microsoft.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Vasundhara Volam <vvolam@microsoft.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Vasundhara Volam <vvolam@microsoft.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment thread sonic-chassisd/scripts/chassisd
@chartsai-nvidia

Copy link
Copy Markdown

Hi Vasundhara

When the reboot cause is unknown, the log still reports a kernel crash as the reboot cause.
Please update the logic so that an unknown reboot cause is reported correctly instead of being classified as a kernel crash. Thanks

Signed-off-by: Vasundhara Volam <vvolam@microsoft.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@vvolam

vvolam commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Hi Vasundhara

When the reboot cause is unknown, the log still reports a kernel crash as the reboot cause. Please update the logic so that an unknown reboot cause is reported correctly instead of being classified as a kernel crash. Thanks

@chartsai-nvidia for 4280 sku, nvidia is reporting unknown for kernel crashes and unable to distinguish. Once it is fixed, we could tighten the chassisd code.

@chartsai-nvidia

Copy link
Copy Markdown

Hi Vasundhara
When the reboot cause is unknown, the log still reports a kernel crash as the reboot cause. Please update the logic so that an unknown reboot cause is reported correctly instead of being classified as a kernel crash. Thanks

@chartsai-nvidia for 4280 sku, nvidia is reporting unknown for kernel crashes and unable to distinguish. Once it is fixed, we could tighten the chassisd code.

I understand, at this time we also report unknown reboot cause for first boot, and it would cause additional unwanted power cycle for DPU on each first boot. This will break test flows. Until there's a clarification on the reboot cause we need to fix this issue.

@vvolam
vvolam requested a review from gpunathilell June 10, 2026 17:53
Comment thread sonic-chassisd/scripts/chassisd Outdated
Comment thread sonic-chassisd/scripts/chassisd Outdated
Comment thread sonic-chassisd/scripts/chassisd Outdated
Comment thread sonic-chassisd/scripts/chassisd Outdated
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment thread sonic-chassisd/scripts/chassisd Outdated
Comment thread sonic-chassisd/scripts/chassisd Outdated
Comment thread sonic-chassisd/scripts/chassisd Outdated
Comment thread sonic-chassisd/scripts/chassisd
Address PR sonic-net#829 review feedback:

- _should_handle_hw_offline(): gate on a Ready-only allow-list instead of
  an exclusion list. A stale Offline snapshot seen while still AdminDown now
  takes the clean restart path (-> Booting) rather than power-cycling,
  avoiding a `module startup` race. Fail-safe for future states.
- _npu_crash_on_last_boot(): treat only "kernel panic" as a crash. "unknown"
  is reported on first boot and must not force a power-cycle; drop the unused
  NPU_CRASH_REBOOT_CAUSE_KEYWORDS constant.
- Update unit tests to cover the new behavior.

Signed-off-by: Vasundhara Volam <vvolam@microsoft.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@vvolam

vvolam commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@gpunathilell I have addressed the comments in the latest changes.

@vvolam
vvolam requested a review from gpunathilell July 10, 2026 16:42
Comment thread sonic-chassisd/scripts/chassisd Outdated
Comment thread sonic-chassisd/scripts/chassisd
set_module_state_transition() is an atomic compare-and-acquire under a
cross-process fcntl flock, and every writer of transition_in_progress goes
through that same API. So the `if not lock_acquired` abort already closes
the TOCTOU window against a concurrent planned shutdown/reboot: whoever grabs
the lock first wins and the other's set returns False. Once recovery holds the
lock, transition_type == 'recovery', so _is_planned_transition_in_progress()
returns False by construction and the subsequent re-check is unreachable in
real execution (only reachable by mocking).

Remove the re-check block in _enter_power_cycle_or_unrecoverable() and the
test_power_cycle_aborted_when_legacy_field_set_after_lock test that only
exercised it via mocking. The earlier suppression gate and the
lock-not-acquired abort are retained.

Signed-off-by: Vasundhara Volam <vvolam@microsoft.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@gpunathilell

Copy link
Copy Markdown
Contributor

Hi @vvolam, I think I only have two points, everything else looks good, I want to use graceful shutdown/startup use since that automatically covers the transition lock etc, so Please update that once we have fix for this command: https://github.com/sonic-net/sonic-platform-daemons/pull/829/changes#r3475789446

@vvolam

vvolam commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Hi @vvolam, I think I only have two points, everything else looks good, I want to use graceful shutdown/startup use since that automatically covers the transition lock etc, so Please update that once we have fix for this command: https://github.com/sonic-net/sonic-platform-daemons/pull/829/changes#r3475789446

Sure, we could modify the path once we have the fix.

@vvolam
vvolam merged commit 6acdb85 into sonic-net:master Jul 20, 2026
6 checks passed
@vvolam
vvolam deleted the dpu_ras_fix branch July 20, 2026 17:25
@vvolam vvolam added the Tested for 202605 branch Tested for 202605 branch label Jul 21, 2026
@vaibhavhd

Copy link
Copy Markdown

202605 testing results are not updated

@vvolam

vvolam commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

202605 testing results are not updated

@vaibhavhd Tests ran on both master and 202605 images on a smartswitch. Updated the PR description with the same.

@vaibhavhd

Copy link
Copy Markdown

Both remaining failures were environmental/test-harness — a databasedpu container inactive at test start, and a config-reload case that ran on pre-fix test code — not auto-recovery regressions.

What about this? The failures likely are due to setup/state of tb, but that also means that these cases cannot be run and change is not evaluated.

@vaibhavhd

Copy link
Copy Markdown

Are the failing cases not relevant to the change being made here? Do you want to rerun to ensure you get a green run for these cases?

mssonicbld added a commit to sonic-net/sonic-platform-common that referenced this pull request Jul 24, 2026
…DEFAULTS (#726)

#### Description

Add a `"recovery": 600` (10 min) entry to `ModuleBase._TRANSITION_TIMEOUT_DEFAULTS`.

`set_module_state_transition()` validates the requested `transition_type` against the keys of `_TRANSITION_TIMEOUT_DEFAULTS`. chassisd's DPU power-cycle auto-recovery acquires the module state-transition lock via `set_module_state_transition(name, 'recovery')`; because `'recovery'` was missing from the defaults, every recovery acquisition was rejected ("Cannot acquire state transition lock") and the power-cycle was silently skipped — blocking DPU auto-recovery.

#### Motivation and Context

The `'recovery'` transition type is used by chassisd (sonic-platform-daemons) to power-cycle an unresponsive DPU. Without a matching entry in `_TRANSITION_TIMEOUT_DEFAULTS`, the transition is never accepted, so a DPU that loses its control plane is never power-cycled. This unblocks the DPU auto-recovery path in sonic-net/sonic-platform-daemons#829.

`recovery` has no `platform.json` override (only `startup`/`shutdown`/`reboot`/`halt_services` are overridable in `_load_transition_timeouts()`), so the 600 s default applies uniformly. The timeout only bounds the power-cycle critical section (pre_shutdown → admin down → admin up → post_startup), which is cleared in `finally`; 600 s is ample headroom.

#### How Has This Been Tested?

- Unit tests: updated the timeout-loading tests in `tests/module_base_test.py` to expect the new key. `python3 -m pytest tests/module_base_test.py` → **115 passed**.
- On-device with both master and 202605 image: with the fix, a control-plane-down DPU was power-cycled (reboot-cause "Switch rebooted DPU") and recovered to `ready_status=true`.

#### Additional Information (Optional)

Companion to sonic-net/sonic-platform-daemons#829 (chassisd DPU auto-recovery robustness), which issues the `'recovery'` transition this default enables.

Signed-off-by: Sonic Build Admin <sonicbld@microsoft.com>
@vvolam

vvolam commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Are the failing cases not relevant to the change being made here? Do you want to rerun to ensure you get a green run for these cases?

Failure cases were because of PSU not ok on the DPUs which is fixed by [system-health]: Honor 'psu' and 'pdb' device ignore independently in hardware checker by vvolam · … and this makes all tests run clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants