From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.18198.1646043670362006302 for ; Mon, 28 Feb 2022 02:21:10 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t73bkgJO; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 79D5861320 for ; Mon, 28 Feb 2022 10:21:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF1EFC340EE for ; Mon, 28 Feb 2022 10:21:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646043668; bh=MxLCVnYlDMttzzVJW68DlnkYU0geymQsF3EglIYPm60=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=t73bkgJOnMYwsaqgBwuSzNKyBZopEDFfcWhbLe44UNEUYSTdt/NW94JewIQFHVPNp R9qkpYSAKtIaGKUIFU3o0UfAbccxgu+s7d8w7e5xD052WldDR86nOMkjLYE83bzwv0 A5cqHUd7FD2ubgCjOVGj20ElLlSQ42HIPFKtwUk/E4RiJSGGJlVpDV8ty8P9PMlw68 Gx4Sx3r45q04L3kd1Z7zpic25OCEaq7klnIZRYIMF085nOysdG9pftlJj33hsjDfBv YLUUaEEkU7daoMCxZSJRohC+qjyygnxCwnTZ+YJJ1QIRCeBH9kxXI0QD+iIzk5e9MU x+sQZFMW5UUYg== Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-2d6d0cb5da4so101951397b3.10 for ; Mon, 28 Feb 2022 02:21:08 -0800 (PST) X-Gm-Message-State: AOAM531CuwWuljV2XDsdwEFTCFxybxhOyhfMTehjNKVZKjYpt/EXeY1k i5PsBx12q41j2WdWZcAtEinZk9xAOwgK6gGqm3Q= X-Google-Smtp-Source: ABdhPJy0yTWM2W3ghhxbiN41J15l39/guqswvfIE1l45FMDMMsiP94JCMNc+DFvaNAaDO8L2exzZqRf6vpuF+qr7gAE= X-Received: by 2002:a81:7d04:0:b0:2d0:d0e2:126f with SMTP id y4-20020a817d04000000b002d0d0e2126fmr18922219ywc.485.1646043667947; Mon, 28 Feb 2022 02:21:07 -0800 (PST) MIME-Version: 1.0 References: <20220224162219.2133918-1-quic_tpilar@quicinc.com> In-Reply-To: From: "Ard Biesheuvel" Date: Mon, 28 Feb 2022 11:20:55 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5] MdeModulePkg: Correct high-memory use in NvmExpressDxe To: "Wu, Hao A" Cc: Tomas Pilar , "devel@edk2.groups.io" , "Ni, Ray" , Ard Biesheuvel , Leif Lindholm Content-Type: text/plain; charset="UTF-8" On Fri, 25 Feb 2022 at 09:17, Wu, Hao A wrote: > > Acked-by: Hao A Wu > Merged as #2561 Thanks all > > -----Original Message----- > > From: Tomas Pilar > > Sent: Friday, February 25, 2022 12:22 AM > > To: devel@edk2.groups.io > > Cc: Ni, Ray ; Ard Biesheuvel > > ; Leif Lindholm ; > > Wu, Hao A ; Ard Biesheuvel > > Subject: [PATCH v5] MdeModulePkg: Correct high-memory use in > > NvmExpressDxe > > > > 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 > > Cc: Ard Biesheuvel > > Cc: Leif Lindholm > > Cc: Hao A Wu > > Reviewed-by: Ard Biesheuvel > > Signed-off-by: Tomas Pilar > > --- > > MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c | 27 > > ++++++++++++++++++++ > > MdeModulePkg/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..5a1eda8e8d 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, "NvmExpressDriverBindingStart: 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