* [PATCH v3] MdeModulePkg: Correct high-memory use in NvmExpressDxe
@ 2022-02-24 13:29 Tomas Pilar (tpilar)
2022-02-24 14:19 ` [edk2-devel] " Ard Biesheuvel
2022-02-24 16:10 ` Rebecca Cran
0 siblings, 2 replies; 3+ messages in thread
From: Tomas Pilar (tpilar) @ 2022-02-24 13:29 UTC (permalink / raw)
To: devel; +Cc: Ray Ni, Ard Biesheuvel, Leif Lindholm
Move the logic that stores starting PCI attributes and sets the
EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE attribute to
DriverBindingStart() before the memory that backs the
DMA engine is allocated.
This ensures that the DMA-backing memory is not forcibly allocated
below 4G in system address map. Otherwise the allocation fails on
platforms that do not have any memory below the 4G mark and the drive
initialisation fails.
Leave the PCI device enabling attribute logic in NvmeControllerInit()
to ensure that the device is re-enabled on reset in case it was
disabled via PCI attributes.
Cc: Ray Ni <ray.ni@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Leif Lindholm <leif@nuviainc.com>
Signed-off-by: Tomas Pilar <quic_tpilar@quicinc.com>
---
.../Bus/Pci/NvmExpressDxe/NvmExpress.c | 27 +++++++++++++++++++
.../Bus/Pci/NvmExpressDxe/NvmExpressHci.c | 26 +-----------------
2 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
index 9d40f67e8e..b70499e3be 100644
--- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
+++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
@@ -959,6 +959,33 @@ NvmExpressDriverBindingStart (
goto Exit;
}
+ //
+ // Save original PCI attributes
+ //
+ Status = PciIo->Attributes (
+ PciIo,
+ EfiPciIoAttributeOperationGet,
+ 0,
+ &Private->PciAttributes
+ );
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Enable 64-bit DMA support in the PCI layer.
+ //
+ Status = PciIo->Attributes (
+ PciIo,
+ EfiPciIoAttributeOperationEnable,
+ EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_WARN, "NvmeControllerInit: failed to enable 64-bit DMA (%r)\n", Status));
+ }
+
//
// 6 x 4kB aligned buffers will be carved out of this buffer.
// 1st 4kB boundary is the start of the admin submission queue.
diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c
index ac77afe113..d87212ffb2 100644
--- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c
+++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c
@@ -728,20 +728,9 @@ NvmeControllerInit (
UINT8 Mn[41];
//
- // Save original PCI attributes and enable this controller.
+ // Enable this controller.
//
PciIo = Private->PciIo;
- Status = PciIo->Attributes (
- PciIo,
- EfiPciIoAttributeOperationGet,
- 0,
- &Private->PciAttributes
- );
-
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
Status = PciIo->Attributes (
PciIo,
EfiPciIoAttributeOperationSupported,
@@ -764,19 +753,6 @@ NvmeControllerInit (
return Status;
}
- //
- // Enable 64-bit DMA support in the PCI layer.
- //
- Status = PciIo->Attributes (
- PciIo,
- EfiPciIoAttributeOperationEnable,
- EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE,
- NULL
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_WARN, "NvmeControllerInit: failed to enable 64-bit DMA (%r)\n", Status));
- }
-
//
// Read the Controller Capabilities register and verify that the NVM command set is supported
//
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [edk2-devel] [PATCH v3] MdeModulePkg: Correct high-memory use in NvmExpressDxe
2022-02-24 13:29 [PATCH v3] MdeModulePkg: Correct high-memory use in NvmExpressDxe Tomas Pilar (tpilar)
@ 2022-02-24 14:19 ` Ard Biesheuvel
2022-02-24 16:10 ` Rebecca Cran
1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2022-02-24 14:19 UTC (permalink / raw)
To: edk2-devel-groups-io, Tomas Pilar, Hao A Wu
Cc: Ray Ni, Ard Biesheuvel, Leif Lindholm
(+ Hao Wu)
On Thu, 24 Feb 2022 at 14:29, Tomas Pilar (tpilar)
<quic_tpilar@quicinc.com> wrote:
>
> Move the logic that stores starting PCI attributes and sets the
> EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE attribute to
> DriverBindingStart() before the memory that backs the
> DMA engine is allocated.
>
> This ensures that the DMA-backing memory is not forcibly allocated
> below 4G in system address map. Otherwise the allocation fails on
> platforms that do not have any memory below the 4G mark and the drive
> initialisation fails.
>
> Leave the PCI device enabling attribute logic in NvmeControllerInit()
> to ensure that the device is re-enabled on reset in case it was
> disabled via PCI attributes.
>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
> Cc: Leif Lindholm <leif@nuviainc.com>
> Signed-off-by: Tomas Pilar <quic_tpilar@quicinc.com>
This is still not exactly what I had in mind, but I think it's
actually better: the manipulation of the MMIO/IO decode and bus master
attributes occurs in the same place as before (and therefore
potentially multiple times), whereas recording the original value of
the attributes now occurs only once. In that sense, this patch fixes
more than one bug.
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
> ---
> .../Bus/Pci/NvmExpressDxe/NvmExpress.c | 27 +++++++++++++++++++
> .../Bus/Pci/NvmExpressDxe/NvmExpressHci.c | 26 +-----------------
> 2 files changed, 28 insertions(+), 25 deletions(-)
>
> diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
> index 9d40f67e8e..b70499e3be 100644
> --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
> +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
> @@ -959,6 +959,33 @@ NvmExpressDriverBindingStart (
> goto Exit;
> }
>
> + //
> + // Save original PCI attributes
> + //
> + Status = PciIo->Attributes (
> + PciIo,
> + EfiPciIoAttributeOperationGet,
> + 0,
> + &Private->PciAttributes
> + );
> +
> + if (EFI_ERROR (Status)) {
> + return Status;
> + }
> +
> + //
> + // Enable 64-bit DMA support in the PCI layer.
> + //
> + Status = PciIo->Attributes (
> + PciIo,
> + EfiPciIoAttributeOperationEnable,
> + EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE,
> + NULL
> + );
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_WARN, "NvmeControllerInit: failed to enable 64-bit DMA (%r)\n", Status));
> + }
> +
> //
> // 6 x 4kB aligned buffers will be carved out of this buffer.
> // 1st 4kB boundary is the start of the admin submission queue.
> diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c
> index ac77afe113..d87212ffb2 100644
> --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c
> +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c
> @@ -728,20 +728,9 @@ NvmeControllerInit (
> UINT8 Mn[41];
>
> //
> - // Save original PCI attributes and enable this controller.
> + // Enable this controller.
> //
> PciIo = Private->PciIo;
> - Status = PciIo->Attributes (
> - PciIo,
> - EfiPciIoAttributeOperationGet,
> - 0,
> - &Private->PciAttributes
> - );
> -
> - if (EFI_ERROR (Status)) {
> - return Status;
> - }
> -
> Status = PciIo->Attributes (
> PciIo,
> EfiPciIoAttributeOperationSupported,
> @@ -764,19 +753,6 @@ NvmeControllerInit (
> return Status;
> }
>
> - //
> - // Enable 64-bit DMA support in the PCI layer.
> - //
> - Status = PciIo->Attributes (
> - PciIo,
> - EfiPciIoAttributeOperationEnable,
> - EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE,
> - NULL
> - );
> - if (EFI_ERROR (Status)) {
> - DEBUG ((DEBUG_WARN, "NvmeControllerInit: failed to enable 64-bit DMA (%r)\n", Status));
> - }
> -
> //
> // Read the Controller Capabilities register and verify that the NVM command set is supported
> //
> --
> 2.30.2
>
>
>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [edk2-devel] [PATCH v3] MdeModulePkg: Correct high-memory use in NvmExpressDxe
2022-02-24 13:29 [PATCH v3] MdeModulePkg: Correct high-memory use in NvmExpressDxe Tomas Pilar (tpilar)
2022-02-24 14:19 ` [edk2-devel] " Ard Biesheuvel
@ 2022-02-24 16:10 ` Rebecca Cran
1 sibling, 0 replies; 3+ messages in thread
From: Rebecca Cran @ 2022-02-24 16:10 UTC (permalink / raw)
To: devel, quic_tpilar; +Cc: Ray Ni, Ard Biesheuvel, Leif Lindholm
On 2/24/22 06:29, Tomas Pilar (tpilar) wrote:
> + //
> + // Enable 64-bit DMA support in the PCI layer.
> + //
> + Status = PciIo->Attributes (
> + PciIo,
> + EfiPciIoAttributeOperationEnable,
> + EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE,
> + NULL
> + );
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_WARN, "NvmeControllerInit: failed to enable 64-bit DMA (%r)\n", Status));
> + }
> +
The message should probably mention NvmExpressDriverBindingStart instead
of NvmeControllerInit.
--
Rebecca Cran
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-24 16:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-24 13:29 [PATCH v3] MdeModulePkg: Correct high-memory use in NvmExpressDxe Tomas Pilar (tpilar)
2022-02-24 14:19 ` [edk2-devel] " Ard Biesheuvel
2022-02-24 16:10 ` Rebecca Cran
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox