Skip to contentSkip to conversation

MdeModulePkg: mark completion of PCI enumeration in PciEnumeratorLight

PATCH Ni, Ruiyu 4 participants 6 messages Feb 12, 2015 – Feb 13, 2015 4 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Ni, Ruiyu

author
#1 lore raw

Wei,
No you cannot install gEfiPciEnumerationCompleteProtocolGuid in PciEnumeratorLight().
For a real platform, PCI BUS is fully enumerated in PciEnumerator() and later if reconnect happens, it's light enumerated in PciEnumeratorLight(). The protocol should only be installed once in PeiEnumerator(). Your fix will cause this protocol installed every time a reconnect happens. The protocol 's meaning is that the PCI BUS is fully enumerated. If the PCI BUS is fully enumerated before starting PciBus driver, light PCI enumeration is used.
For your OVMF/QEMU case, an alternative fix is to install this protocol in a platform driver when it detects that the PCI BUS is fully enumerated.

Thanks,
Ray

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: Thursday, February 12, 2015 4:24 AM
To: [email protected]
Cc: [email protected]; Laszlo
Subject: [edk2] [PATCH] MdeModulePkg: mark completion of PCI enumeration in PciEnumeratorLight

I had an issue when trying to boot Xen HVM guest with latest OVMF master. Guest crashed with memory violation, and the bisection pointed to 66b280df2 ("OvmfPkg: AcpiPlatformDxe: make dependency on PCI enumeration explicit"). That commit made AcpiPlatformDxe depend on PCI enumeration using gEfiPciEnumerationCompleteProtocolGuid, which is a very reasonable change.

The real culprit is that Xen HVM is using PciEnumeratorLight which doesn't install gEfiPciEnumerationCompleteProtocolGuid. This, in combination with 66b280df2, makes AcpiPlatformDxe not able to be loaded, resulting in guest crash.

The fix is to install gEfiPciEnumerationCompleteProtocolGuid in PciEnumeratorLight.

Contributed-under: TianoCore Contribution Agreement 1.0

Cc Feng Tian <[email protected]>
Cc Anthony Perard <[email protected]>
Cc Laszlo Ersek <[email protected]>
Cc Jordan Justen <[email protected]>
---
 MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +14 -1
index 9e7ac74..7659585 100644
@@ -2256,6 +2256,7 @@ PciEnumeratorLight (
 {
 
   EFI_STATUS                        Status;
+  EFI_HANDLE                        HostBridgeHandle;
   EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL   *PciRootBridgeIo;
   PCI_IO_DEVICE                     *RootBridgeDev;
   UINT16                            MinBus;
@@ -2288,6 +2289,11 @@ PciEnumeratorLight (
     return Status;
   }
 
+  //
+  // Get the host bridge handle
+  //
+  HostBridgeHandle = PciRootBridgeIo->ParentHandle;
+
   Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Descriptors);
 
   if (EFI_ERROR (Status)) {
@@ -2348,7 +2354,14 @@ PciEnumeratorLight (
     Descriptors++;
   }
 
-  return EFI_SUCCESS;
+  Status = gBS->InstallProtocolInterface (
+                  &HostBridgeHandle,
+                  &gEfiPciEnumerationCompleteProtocolGuid,
+                  EFI_NATIVE_INTERFACE,
+                  NULL
+                  );
+
+  return Status;
 }
 
 /**
Signature · 13 lines
1.9.1


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

A message that is not in the archive (sent off-list or not yet received): 734D49CCEBEEF84792F5B80ED585239D0AAF0A81@SHSMSX103.ccr.corp.intel.com

#3 lore raw
Quoted 11 lines · Ruiyu

Wei,

No you cannot install gEfiPciEnumerationCompleteProtocolGuid in PciEnumeratorLight().

For a real platform, PCI BUS is fully enumerated in PciEnumerator() and later if reconnect happens, it's light enumerated in PciEnumeratorLight(). The protocol should only be installed once in PeiEnumerator(). Your fix will cause this protocol installed every time a reconnect happens.

Makes sense.

Quoted 8 lines

The protocol 's meaning is that the PCI BUS is fully enumerated. If the PCI BUS is fully enumerated before starting PciBus driver, light PCI enumeration is used.

For your OVMF/QEMU case, an alternative fix is to install this protocol in a platform driver when it detects that the PCI BUS is fully enumerated.

Cool, thanks for the pointer.

Then I shall fix it inside OVMF.

Wei.

#4 lore raw
In reply to a message not in the archive
Quoted 8 lines · Ruiyu

Wei,
No you cannot install gEfiPciEnumerationCompleteProtocolGuid in PciEnumeratorLight().
For a real platform, PCI BUS is fully enumerated in PciEnumerator() and later if reconnect happens, it's light enumerated in PciEnumeratorLight(). The protocol should only be installed once in PeiEnumerator(). Your fix will cause this protocol installed every time a reconnect happens.

I don't think it will, since the protocol is already installed on the Host Bridge Handle, I think EFI_INVALID_PARAMETER will be returned on subsequent calls to install the protocol.

But, getting that error back will lead to PciEnumeratorLight returning an error, and this could cause other issues.

Quoted 6 lines

The protocol 's meaning is that the PCI BUS is fully enumerated. If the PCI BUS is fully enumerated before starting PciBus driver, light PCI enumeration is used.
For your OVMF/QEMU case, an alternative fix is to install this protocol in a platform driver when it detects that the PCI BUS is fully enumerated.

I think the PciBusDxe driver is still the right place to install the protocol, but I agree we need to be careful to prevent trying to install the protocol multiple times.

I guess we could try to locate the protocol on the Host Bridge Handle before installing it to prevent multiple installation attempts.

-Jordan

Quoted 97 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: Thursday, February 12, 2015 4:24 AM
To: [email protected]
Cc: [email protected]; Laszlo
Subject: [edk2] [PATCH] MdeModulePkg: mark completion of PCI enumeration in PciEnumeratorLight

I had an issue when trying to boot Xen HVM guest with latest OVMF master. Guest crashed with memory violation, and the bisection pointed to 66b280df2 ("OvmfPkg: AcpiPlatformDxe: make dependency on PCI enumeration explicit"). That commit made AcpiPlatformDxe depend on PCI enumeration using gEfiPciEnumerationCompleteProtocolGuid, which is a very reasonable change.

The real culprit is that Xen HVM is using PciEnumeratorLight which doesn't install gEfiPciEnumerationCompleteProtocolGuid. This, in combination with 66b280df2, makes AcpiPlatformDxe not able to be loaded, resulting in guest crash.

The fix is to install gEfiPciEnumerationCompleteProtocolGuid in PciEnumeratorLight.

Contributed-under: TianoCore Contribution Agreement 1.0

Cc Feng Tian <[email protected]>
Cc Anthony Perard <[email protected]>
Cc Laszlo Ersek <[email protected]>
Cc Jordan Justen <[email protected]>
---
 MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +14 -1
index 9e7ac74..7659585 100644
@@ -2256,6 +2256,7 @@ PciEnumeratorLight (
 {
 
   EFI_STATUS                        Status;
+  EFI_HANDLE                        HostBridgeHandle;
   EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL   *PciRootBridgeIo;
   PCI_IO_DEVICE                     *RootBridgeDev;
   UINT16                            MinBus;
@@ -2288,6 +2289,11 @@ PciEnumeratorLight (
     return Status;
   }
 
+  //
+  // Get the host bridge handle
+  //
+  HostBridgeHandle = PciRootBridgeIo->ParentHandle;
+
   Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Descriptors);
 
   if (EFI_ERROR (Status)) {
@@ -2348,7 +2354,14 @@ PciEnumeratorLight (
     Descriptors++;
   }
 
-  return EFI_SUCCESS;
+  Status = gBS->InstallProtocolInterface (
+                  &HostBridgeHandle,
+                  &gEfiPciEnumerationCompleteProtocolGuid,
+                  EFI_NATIVE_INTERFACE,
+                  NULL
+                  );
+
+  return Status;
 }
 
 /**
Signature · 24 lines
1.9.1


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

A message that is not in the archive (sent off-list or not yet received): 20150212210250.11478.57343@jljusten-hsw

author
#6 lore raw

Jordan,
You are correct that subsequent installations of this protocol will fail.

But I don't think locating this protocol before installing it is a good implementation choice. This would make the code confusing.

Thanks,
Ray

-----Original Message-----
From: Justen, Jordan L
Sent: Friday, February 13, 2015 5:03 AM
To: [email protected]; Ni, Ruiyu; [email protected]
Cc: [email protected]
Subject: Re: [edk2] [PATCH] MdeModulePkg: mark completion of PCI enumeration in PciEnumeratorLight

Quoted 8 lines · Ruiyu

Wei,
No you cannot install gEfiPciEnumerationCompleteProtocolGuid in PciEnumeratorLight().
For a real platform, PCI BUS is fully enumerated in PciEnumerator() and later if reconnect happens, it's light enumerated in PciEnumeratorLight(). The protocol should only be installed once in PeiEnumerator(). Your fix will cause this protocol installed every time a reconnect happens.

I don't think it will, since the protocol is already installed on the Host Bridge Handle, I think EFI_INVALID_PARAMETER will be returned on subsequent calls to install the protocol.

But, getting that error back will lead to PciEnumeratorLight returning an error, and this could cause other issues.

Quoted 6 lines

The protocol 's meaning is that the PCI BUS is fully enumerated. If the PCI BUS is fully enumerated before starting PciBus driver, light PCI enumeration is used.
For your OVMF/QEMU case, an alternative fix is to install this protocol in a platform driver when it detects that the PCI BUS is fully enumerated.

I think the PciBusDxe driver is still the right place to install the protocol, but I agree we need to be careful to prevent trying to install the protocol multiple times.

I guess we could try to locate the protocol on the Host Bridge Handle before installing it to prevent multiple installation attempts.

-Jordan

Quoted 97 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: Thursday, February 12, 2015 4:24 AM
To: [email protected]
Cc: [email protected]; Laszlo
Subject: [edk2] [PATCH] MdeModulePkg: mark completion of PCI enumeration in PciEnumeratorLight

I had an issue when trying to boot Xen HVM guest with latest OVMF master. Guest crashed with memory violation, and the bisection pointed to 66b280df2 ("OvmfPkg: AcpiPlatformDxe: make dependency on PCI enumeration explicit"). That commit made AcpiPlatformDxe depend on PCI enumeration using gEfiPciEnumerationCompleteProtocolGuid, which is a very reasonable change.

The real culprit is that Xen HVM is using PciEnumeratorLight which doesn't install gEfiPciEnumerationCompleteProtocolGuid. This, in combination with 66b280df2, makes AcpiPlatformDxe not able to be loaded, resulting in guest crash.

The fix is to install gEfiPciEnumerationCompleteProtocolGuid in PciEnumeratorLight.

Contributed-under: TianoCore Contribution Agreement 1.0

Cc Feng Tian <[email protected]>
Cc Anthony Perard <[email protected]>
Cc Laszlo Ersek <[email protected]>
Cc Jordan Justen <[email protected]>
---
 MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +14 -1
index 9e7ac74..7659585 100644
@@ -2256,6 +2256,7 @@ PciEnumeratorLight (
 {
 
   EFI_STATUS                        Status;
+  EFI_HANDLE                        HostBridgeHandle;
   EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL   *PciRootBridgeIo;
   PCI_IO_DEVICE                     *RootBridgeDev;
   UINT16                            MinBus;
@@ -2288,6 +2289,11 @@ PciEnumeratorLight (
     return Status;
   }
 
+  //
+  // Get the host bridge handle
+  //
+  HostBridgeHandle = PciRootBridgeIo->ParentHandle;
+
   Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Descriptors);
 
   if (EFI_ERROR (Status)) {
@@ -2348,7 +2354,14 @@ PciEnumeratorLight (
     Descriptors++;
   }
 
-  return EFI_SUCCESS;
+  Status = gBS->InstallProtocolInterface (
+                  &HostBridgeHandle,
+                  &gEfiPciEnumerationCompleteProtocolGuid,
+                  EFI_NATIVE_INTERFACE,
+                  NULL
+                  );
+
+  return Status;
 }
 
 /**
Signature · 24 lines
1.9.1


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel
#7 lore raw
In reply to a message not in the archive
Quoted 56 lines · Wei Liu

I had an issue when trying to boot Xen HVM guest with latest OVMF master. Guest crashed with memory violation, and the bisection pointed to 66b280df2 ("OvmfPkg: AcpiPlatformDxe: make dependency on PCI enumeration explicit"). That commit made AcpiPlatformDxe depend on PCI enumeration using gEfiPciEnumerationCompleteProtocolGuid, which is a very reasonable change.

The real culprit is that Xen HVM is using PciEnumeratorLight which doesn't install gEfiPciEnumerationCompleteProtocolGuid. This, in combination with 66b280df2, makes AcpiPlatformDxe not able to be loaded, resulting in guest crash.

The fix is to install gEfiPciEnumerationCompleteProtocolGuid in PciEnumeratorLight.

Contributed-under: TianoCore Contribution Agreement 1.0

Cc Feng Tian <[email protected]>
Cc Anthony Perard <[email protected]>
Cc Laszlo Ersek <[email protected]>
Cc Jordan Justen <[email protected]>
---
 MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +7 -1
index 9e7ac74..7659585 100644
@@ -2256,6 +2256,7 @@ PciEnumeratorLight (
 {
 
   EFI_STATUS                        Status;
+  EFI_HANDLE                        HostBridgeHandle;
   EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL   *PciRootBridgeIo;
   PCI_IO_DEVICE                     *RootBridgeDev;
   UINT16                            MinBus;
@@ -2288,6 +2289,11 @@ PciEnumeratorLight (
     return Status;
   }
 
+  //
+  // Get the host bridge handle
+  //
+  HostBridgeHandle = PciRootBridgeIo->ParentHandle;
+
   Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Descriptors);
 
   if (EFI_ERROR (Status)) {
@@ -2348,7 +2354,14 @@ PciEnumeratorLight (
     Descriptors++;
   }
 
-  return EFI_SUCCESS;
+  Status = gBS->InstallProtocolInterface (

MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c PciEnumeratorLight ( · line 2367

Quoted 10 lines
MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +7 -0
+                  &HostBridgeHandle,
+                  &gEfiPciEnumerationCompleteProtocolGuid,
+                  EFI_NATIVE_INTERFACE,
+                  NULL
+                  );
+
+  return Status;
 }
 
 /**

I think this could result in several installations of gEfiPciEnumerationCompleteProtocolGuid. See the beginning of the PciEnumerator() function.

If gFullEnumeration is TRUE to begin with (which is the QEMU case), then the protocol will be installed at the end of PciEnumerator() first. At that point we flip gFullEnumeration to FALSE, which implies that further invocations of PciEnumerator() are possible and allowed. So at the next call gFullEnumeration will be false, ie. we'll call PciEnumeratorLight(). With the above patch PciEnumeratorLight() would add the 2nd (and possibly further) instances of EfiPciEnumerationCompleteProtocol.

I'll submit an alternative patch for OvmfPkg soon.

Thanks
Laszlo

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw
Quoted 72 lines · Laszlo Ersek
Quoted 56 lines · Wei Liu

I had an issue when trying to boot Xen HVM guest with latest OVMF master. Guest crashed with memory violation, and the bisection pointed to 66b280df2 ("OvmfPkg: AcpiPlatformDxe: make dependency on PCI enumeration explicit"). That commit made AcpiPlatformDxe depend on PCI enumeration using gEfiPciEnumerationCompleteProtocolGuid, which is a very reasonable change.

The real culprit is that Xen HVM is using PciEnumeratorLight which doesn't install gEfiPciEnumerationCompleteProtocolGuid. This, in combination with 66b280df2, makes AcpiPlatformDxe not able to be loaded, resulting in guest crash.

The fix is to install gEfiPciEnumerationCompleteProtocolGuid in PciEnumeratorLight.

Contributed-under: TianoCore Contribution Agreement 1.0

Cc Feng Tian <[email protected]>
Cc Anthony Perard <[email protected]>
Cc Laszlo Ersek <[email protected]>
Cc Jordan Justen <[email protected]>
---
 MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +7 -1
index 9e7ac74..7659585 100644
@@ -2256,6 +2256,7 @@ PciEnumeratorLight (
 {
 
   EFI_STATUS                        Status;
+  EFI_HANDLE                        HostBridgeHandle;
   EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL   *PciRootBridgeIo;
   PCI_IO_DEVICE                     *RootBridgeDev;
   UINT16                            MinBus;
@@ -2288,6 +2289,11 @@ PciEnumeratorLight (
     return Status;
   }
 
+  //
+  // Get the host bridge handle
+  //
+  HostBridgeHandle = PciRootBridgeIo->ParentHandle;
+
   Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Descriptors);
 
   if (EFI_ERROR (Status)) {
@@ -2348,7 +2354,14 @@ PciEnumeratorLight (
     Descriptors++;
   }
 
-  return EFI_SUCCESS;
+  Status = gBS->InstallProtocolInterface (

MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c PciEnumeratorLight ( · line 2367

Quoted 10 lines
MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +7 -0
+                  &HostBridgeHandle,
+                  &gEfiPciEnumerationCompleteProtocolGuid,
+                  EFI_NATIVE_INTERFACE,
+                  NULL
+                  );
+
+  return Status;
 }
 
 /**

I think this could result in several installations of gEfiPciEnumerationCompleteProtocolGuid. See the beginning of the PciEnumerator() function.

Quoted 9 lines

If gFullEnumeration is TRUE to begin with (which is the QEMU case), then the protocol will be installed at the end of PciEnumerator() first. At that point we flip gFullEnumeration to FALSE, which implies that further invocations of PciEnumerator() are possible and allowed. So at the next call gFullEnumeration will be false, ie. we'll call PciEnumeratorLight(). With the above patch PciEnumeratorLight() would add the 2nd (and possibly further) instances of EfiPciEnumerationCompleteProtocol.

Right. Xen guest starts with gFullEnumeration set to FALSE which means that protocol never gets installed.

Quoted 2 lines

I'll submit an alternative patch for OvmfPkg soon.

Thanks. I'm just about to write a patch as Ray suggested but now I will wait for your patch. :-)

Wei.

Quoted 2 lines

Thanks
Laszlo