Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: <Unclosed BlockIo2 Protocol during DiskIoDriverBindingStart Error Handling> #10727

Open
2 of 5 tasks
kanagavels97 opened this issue Feb 6, 2025 · 0 comments
Open
2 of 5 tasks
Labels
package:mdemodulepkg priority:medium Moderate impact. Should be prioritized over lower priority issues. state:needs-maintainer-feedback state:needs-triage type:bug Something isn't working

Comments

@kanagavels97
Copy link
Contributor

Is there an existing issue for this?

  • I have searched existing issues

Bug Type

  • Firmware
  • Tool
  • Unit Test

Code first?

  • Yes

What packages are impacted?

MdeModulePkg

Which targets are impacted by this bug?

No response

Current Behavior

During the DiskIoDriverBindingStart, both the BlockIo and BlockIo2 protocols are opened for the specified controller handle. The Instance->SharedWorkingBuffer is then allocated based on the BlockSize. If the BlockSize is zero, indicating that the handle does not support Read/Write operations, the buffer will not be allocated. A NULL check is performed on the SharedWorkingBuffer, and if it is NULL, the process jumps to the ErrorExit. In the ErrorExit section, only the BlockIo protocol is closed, while the BlockIo2 protocol remains open.

We are facing an issue with Uninstalling the BlockIo2 protocol during the DriverBindingStop process because it remains open.

MdeModulePkg\Universal\DiskIoDxe\DiskIo.c

ErrorExit:
if (EFI_ERROR (Status)) {
if ((Instance != NULL) && (Instance->SharedWorkingBuffer != NULL)) {
FreeAlignedPages (
Instance->SharedWorkingBuffer,
EFI_SIZE_TO_PAGES (PcdGet32 (PcdDiskIoDataBufferBlockNum) * Instance->BlockIo->Media->BlockSize)
);
}
if (Instance != NULL) {
FreePool (Instance);
}
gBS->CloseProtocol (
ControllerHandle,
&gEfiBlockIoProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
}

Expected Behavior

The check needs to be added for the BlockIo2 protocol in the ErrorExit, and it should be closed properly if the BlockIo2 protocol is opened.

Steps To Reproduce

  1. Connect a UFS device that supports WLUN. This WLUN will be detected as a separate handle under the UFS host controller.
  2. In my case, the UFS device supports WLUN (44h), which is used for the RPMB feature. According to the UFS specification, the RPMB
    LUN does not support Read/Write operations.
  3. Add UFS module to the bios
  4. Flash the bios on SUT and boot to the shell.
  5. Run the devtree command to identify the controller handle numbers.
  6. In my case, the UFS Host controller number is 165.
  7. Run the disconnect 165 command.
  8. The command returns "Result Not Found." Upon analyzing the issue, we discovered that the BlockIo2 protocol is opened for the
    UFS WLUN handle and not closed.

Build Environment

Shell environment

Version Information

Tag: edk2-stable202411

Urgency

Medium

Are you going to fix this?

I will fix it

Do you need maintainer feedback?

Maintainer feedback requested

Anything else?

Hi @niruiyu

Please verify the issue on your end and provide confirmation.
I have a fix ready and will create a PR with the necessary changes.

CC: @lgao4 @mdkinney

Thanks,
Kanagavel

@kanagavels97 kanagavels97 added state:needs-triage type:bug Something isn't working labels Feb 6, 2025
@github-actions github-actions bot added package:mdemodulepkg priority:medium Moderate impact. Should be prioritized over lower priority issues. state:needs-maintainer-feedback labels Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:mdemodulepkg priority:medium Moderate impact. Should be prioritized over lower priority issues. state:needs-maintainer-feedback state:needs-triage type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant