public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 1/1] MdeModulePkg: UsbBusDxe: Build Descriptor table after resetting port
@ 2023-05-16 22:15 brit.chesley
  2023-06-06  3:14 ` Wu, Hao A
  0 siblings, 1 reply; 3+ messages in thread
From: brit.chesley @ 2023-05-16 22:15 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Liming Gao, Hao A Wu, Ray Ni

From: Britton Chesley <Brit.Chesley@amd.com>

Fixed a bug which led to an ASSERT due to the USB device context being
maintained after a port reset, but the underlying XHCI context was
uninitialized. Added build descriptor table call in UsbIoPortReset

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Britton Chesley <Brit.Chesley@amd.com>
---
 MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
index c25f3cc2f279..55e0e1f16cdb 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
@@ -882,6 +882,12 @@ UsbIoPortReset (
   // is in CONFIGURED state.
   //
   if (Dev->ActiveConfig != NULL) {
+    Status = UsbBuildDescTable (Dev);
+
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "UsbIoPortReset: failed to build descriptor table - %r\n", Status));
+    }
+
     Status = UsbSetConfig (Dev, Dev->ActiveConfig->Desc.ConfigurationValue);
 
     if (EFI_ERROR (Status)) {
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1 1/1] MdeModulePkg: UsbBusDxe: Build Descriptor table after resetting port
  2023-05-16 22:15 [PATCH v1 1/1] MdeModulePkg: UsbBusDxe: Build Descriptor table after resetting port brit.chesley
@ 2023-06-06  3:14 ` Wu, Hao A
  2023-06-28 23:38   ` [edk2-devel] " Mike Maslenkin
  0 siblings, 1 reply; 3+ messages in thread
From: Wu, Hao A @ 2023-06-06  3:14 UTC (permalink / raw)
  To: brit.chesley@amd.com, devel@edk2.groups.io
  Cc: Wang, Jian J, Gao, Liming, Ni, Ray

Sorry for the late response, inline comments below:


> -----Original Message-----
> From: brit.chesley@amd.com <brit.chesley@amd.com>
> Sent: Wednesday, May 17, 2023 6:16 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Wu, Hao A <hao.a.wu@intel.com>; Ni, Ray
> <ray.ni@intel.com>
> Subject: [PATCH v1 1/1] MdeModulePkg: UsbBusDxe: Build Descriptor table
> after resetting port
> 
> From: Britton Chesley <Brit.Chesley@amd.com>
> 
> Fixed a bug which led to an ASSERT due to the USB device context being
> maintained after a port reset, but the underlying XHCI context was
> uninitialized. Added build descriptor table call in UsbIoPortReset


Could you help to elaborate on what data in XHCI is not initialized that leads to the assert? Thanks.


> 
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Signed-off-by: Britton Chesley <Brit.Chesley@amd.com>
> ---
>  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> index c25f3cc2f279..55e0e1f16cdb 100644
> --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> @@ -882,6 +882,12 @@ UsbIoPortReset (
>    // is in CONFIGURED state.
>    //
>    if (Dev->ActiveConfig != NULL) {
> +    Status = UsbBuildDescTable (Dev);


The UsbBuildDescTable function will allocate new buffer resources for and under Dev->DevDesc (device, configuration and interface descriptors).
Could you help to double check if the old buffers are properly freed for the proposed change?

Best Regards,
Hao Wu


> +
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR, "UsbIoPortReset: failed to build descriptor
> table - %r\n", Status));
> +    }
> +
>      Status = UsbSetConfig (Dev, Dev->ActiveConfig-
> >Desc.ConfigurationValue);
> 
>      if (EFI_ERROR (Status)) {
> --
> 2.36.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [PATCH v1 1/1] MdeModulePkg: UsbBusDxe: Build Descriptor table after resetting port
  2023-06-06  3:14 ` Wu, Hao A
@ 2023-06-28 23:38   ` Mike Maslenkin
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Maslenkin @ 2023-06-28 23:38 UTC (permalink / raw)
  To: devel, hao.a.wu; +Cc: brit.chesley@amd.com, Wang, Jian J, Gao, Liming, Ni, Ray

Hi Britton and the community.

I've faced with some assert in XHCI too.
In my case this is:
ASSERT [XhciDxe]
/Users/test/edk2_workspace/edk2/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c(1989):
TrsRing != ((void *) 0)

Your patch helps to avoid this assert, but as was noticed by Hao Wu,it
introduces resources leak,
because UsbBusDxe doesn't deallocate configs for devices. I added
checks to UsbBuildDescTable like
ASSERT (UsbDev->DevDesc == NULL);  ASSERT (UsbDev->DevDesc->Configs == NULL);
and those fired.

I believe there is a problem with XhciDxe, not UsbBusDxe.
Meanwhile I have another workaround for initial  problem described
above and it works.
It works fine for virtual machines, but I guess it costs a time for
physical environment.

My workaround is:
--- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c
+++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c
@@ -173,7 +173,7 @@ UsbMassReadBlocks (

   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "UsbMassReadBlocks: UsbBootReadBlocks (%r)
-> Reset\n", Status));
-    UsbMassReset (This, TRUE);
+    UsbMassReset (This, FALSE);
   }

 ON_EXIT:
---

Just for the context: I was told that some physical device like Zalman
ZM-VE500 doesn't work with edk2.
I do not have such device in hands, but I guess it is multi-lun USB device.
I tried to reproduce such case in QEMU.
Because of USB multi-lun devices are not emulated properly in QEMU,
such config causes assert in XhciDxe.





On Tue, Jun 6, 2023 at 6:14 AM Wu, Hao A <hao.a.wu@intel.com> wrote:
>
> Sorry for the late response, inline comments below:
>
>
> > -----Original Message-----
> > From: brit.chesley@amd.com <brit.chesley@amd.com>
> > Sent: Wednesday, May 17, 2023 6:16 AM
> > To: devel@edk2.groups.io
> > Cc: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming
> > <gaoliming@byosoft.com.cn>; Wu, Hao A <hao.a.wu@intel.com>; Ni, Ray
> > <ray.ni@intel.com>
> > Subject: [PATCH v1 1/1] MdeModulePkg: UsbBusDxe: Build Descriptor table
> > after resetting port
> >
> > From: Britton Chesley <Brit.Chesley@amd.com>
> >
> > Fixed a bug which led to an ASSERT due to the USB device context being
> > maintained after a port reset, but the underlying XHCI context was
> > uninitialized. Added build descriptor table call in UsbIoPortReset
>
>
> Could you help to elaborate on what data in XHCI is not initialized that leads to the assert? Thanks.
>
>
> >
> > Cc: Jian J Wang <jian.j.wang@intel.com>
> > Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > Cc: Hao A Wu <hao.a.wu@intel.com>
> > Cc: Ray Ni <ray.ni@intel.com>
> > Signed-off-by: Britton Chesley <Brit.Chesley@amd.com>
> > ---
> >  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> > b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> > index c25f3cc2f279..55e0e1f16cdb 100644
> > --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> > +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> > @@ -882,6 +882,12 @@ UsbIoPortReset (
> >    // is in CONFIGURED state.
> >    //
> >    if (Dev->ActiveConfig != NULL) {
> > +    Status = UsbBuildDescTable (Dev);
>
>
> The UsbBuildDescTable function will allocate new buffer resources for and under Dev->DevDesc (device, configuration and interface descriptors).
> Could you help to double check if the old buffers are properly freed for the proposed change?
>
> Best Regards,
> Hao Wu
>
>
> > +
> > +    if (EFI_ERROR (Status)) {
> > +      DEBUG ((DEBUG_ERROR, "UsbIoPortReset: failed to build descriptor
> > table - %r\n", Status));
> > +    }
> > +
> >      Status = UsbSetConfig (Dev, Dev->ActiveConfig-
> > >Desc.ConfigurationValue);
> >
> >      if (EFI_ERROR (Status)) {
> > --
> > 2.36.1
>
>
>
> 
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-28 23:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-16 22:15 [PATCH v1 1/1] MdeModulePkg: UsbBusDxe: Build Descriptor table after resetting port brit.chesley
2023-06-06  3:14 ` Wu, Hao A
2023-06-28 23:38   ` [edk2-devel] " Mike Maslenkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox