Skip to content

Update child handle validation in core_disconnect_controller() [Rebase & FF]#1045

Merged
makubacki merged 2 commits into
OpenDevicePartnership:mainfrom
makubacki:disconnect_cont_child_validation
Jul 15, 2026
Merged

Update child handle validation in core_disconnect_controller() [Rebase & FF]#1045
makubacki merged 2 commits into
OpenDevicePartnership:mainfrom
makubacki:disconnect_cont_child_validation

Conversation

@makubacki

@makubacki makubacki commented Nov 11, 2025

Copy link
Copy Markdown
Collaborator

Description

The first commit is the actual change and the second consolidates and cleans up related test code.


Update child handle validation in core_disconnect_controller()

Previously, when a specific child handle was requested but was not a
child created by a driver managing the controller, that driver was not
skipped. When the driver had no children its Stop() was still
invoked, and the function reported success even though nothing was
disconnected.

This change:

  1. Skips a driver when a specific child handle is requested but is not
    present in that driver's child list (checked via child_handles
    being empty after filtering). When no managing driver owns the
    child, the call returns NotFound.

  2. Uses total_children == child_handles.len() to detect that the
    requested child was the driver's only child, in which case the
    driver itself is disconnected (Stop() with zero children). This
    matches the UEFI spec's "if ChildHandle is the only child ... the
    driver will be disconnected" behavior.

Three unit tests are added:

  • test_disconnect_specific_child_not_managed_by_driver(): Checks
    that a specific child not owned by the single managing driver
    returns NotFound and Stop() is never called.

  • test_disconnect_specific_child_among_multiple_children(): Checks
    that a specific child among several is destroyed (Stop() called
    with that one child) while the driver-level Stop() is not called,
    so the driver stays connected.

  • test_disconnect_specific_child_not_owned_by_either_driver(): Checks
    that when two drivers are managing the controller and a child owned
    by neither is requested, that both drivers are skipped and NotFound
    is returned.

Note: EFI_NOT_FOUND is not listed as a return value in for
DisconnectController() in the UEFI 2.11 spec (section 7.3.13), but
returning it when the requested child is unmanaged matches EDK II
behavior.


patina_dxe_core: Consolidate disconnect controller test setup logic

The child-specific core_disconnect_controller() tests each repeated
a lot of related logic to install a driver binding, mark the driver as
managing the controller, and register its children.

This commit adds two test helpers, new_test_handle() and
setup_driver_managing_controller() to reduce the overall size of
test functions.


  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

  • Run all unit tests
  • Check that test_disconnect_specific_child_not_managed_by_driver() fails without the change and passes with it
  • QEMU boot to EFI shell

Integration Instructions

  • N/A

@makubacki makubacki self-assigned this Nov 11, 2025
@github-actions github-actions Bot added the impact:testing Affects testing label Nov 11, 2025
@codecov

codecov Bot commented Nov 11, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.52941% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
patina_dxe_core/src/driver_services.rs 83.53% 28 Missing ⚠️

📢 Thoughts on this report? Let us know!

@makubacki
makubacki marked this pull request as ready for review November 11, 2025 18:30
@makubacki
makubacki force-pushed the disconnect_cont_child_validation branch from 92efccb to 1a66d75 Compare December 19, 2025 19:52
@makubacki
makubacki force-pushed the disconnect_cont_child_validation branch 2 times, most recently from e28a222 to c2768ec Compare January 23, 2026 23:14
Previously, when a specific child handle was requested but was not a
child created by a driver managing the controller, that driver was not
skipped. When the driver had no children its `Stop()` was still
invoked, and the function reported success even though nothing was
disconnected.

This change:

1. Skips a driver when a specific child handle is requested but is not
   present in that driver's child list (checked via `child_handles`
   being empty after filtering). When no managing driver owns the
   child, the call returns `NotFound`.

2. Uses `total_children == child_handles.len()` to detect that the
   requested child was the driver's only child, in which case the
   driver itself is disconnected (`Stop()` with zero children). This
   matches the UEFI spec's "if ChildHandle is the only child ... the
   driver will be disconnected" behavior.

Three unit tests are added:

- `test_disconnect_specific_child_not_managed_by_driver()`: Checks
  that a specific child not owned by the single managing driver
  returns `NotFound` and `Stop()` is never called.

- `test_disconnect_specific_child_among_multiple_children()`: Checks
  that a specific child among several is destroyed (`Stop()` called
  with that one child) while the driver-level `Stop()` is not called,
  so the driver stays connected.

- `test_disconnect_specific_child_not_owned_by_either_driver()`: Checks
  that when two drivers are managing the controller and a child owned
  by neither is requested, that both drivers are skipped and `NotFound`
  is returned.

Note: `EFI_NOT_FOUND` is not listed as a return value in for
`DisconnectController()` in the UEFI 2.11 spec (section 7.3.13), but
returning it when the requested child is unmanaged matches EDK II
behavior.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
@makubacki
makubacki force-pushed the disconnect_cont_child_validation branch from c2768ec to 8196291 Compare July 14, 2026 22:24
@patina-automation

patina-automation Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

✅ QEMU Validation Passed

All QEMU validation jobs completed successfully.

Note: Q35 is only built on Windows hosts (QEMU boot is disabled due to a QEMU vfat issue).

Workflow run: https://github.com/OpenDevicePartnership/patina/actions/runs/29451283566

Boot Time to EFI Shell

Platform Elapsed
ArmVirt (Linux Host) 26.6s
Q35 (Linux Host) 25.6s

Dependencies

Repository Ref
patina 483270c
patina-dxe-core-qemu 423b4ab
patina-fw-patcher 4c7f2e0
patina-qemu firmware v4.0.3
patina-qemu build script fb7b09d

This comment was automatically generated by the Patina QEMU PR Validation Post workflow.

@makubacki makubacki changed the title Update child handle validation in core_disconnect_controller() Update child handle validation in core_disconnect_controller() [Rebase & FF] Jul 14, 2026
@makubacki

Copy link
Copy Markdown
Collaborator Author

@Javagedes, @os-d, @joschock, I finally returned to rebase this PR and clean up some test logic. Can someone please review again?

The child-specific `core_disconnect_controller()` tests each repeated
a lot of related logic to install a driver binding, mark the driver as
managing the controller, and register its children.

This commit adds two test helpers, `new_test_handle()` and
`setup_driver_managing_controller()` to reduce the size of test
functions.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
@makubacki
makubacki force-pushed the disconnect_cont_child_validation branch from 8196291 to 483270c Compare July 15, 2026 20:59
@makubacki
makubacki enabled auto-merge (rebase) July 15, 2026 20:59
@makubacki
makubacki merged commit edf2cd9 into OpenDevicePartnership:main Jul 15, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:testing Affects testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants