From nobody Fri May 17 09:01:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+86966+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+86966+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1645704508; cv=none; d=zohomail.com; s=zohoarc; b=EyuagUTMGHXfytOsdxhJrnNAo2i5i0vbXQMI2mDLWS9qUt4gjKK5hfWtU0yLv5DGBhSX7Yx+maynVxQueqcQONiGKL4CIwSr7fTLkBvvDaOuErvbicEejewKUd6iyjzCP6903a90VBPJ6hmRHbMcMCvNDxhoX6BlUz1+8ZNyJp8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645704508; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=s77+tx9TmJToHzaEyeVSqMVG1t6dVTsfzgIqwkxLPmQ=; b=XDA4hhUpm49yK+B1ZPxhL2CC5seuu5hLawuRpLWLaUrSl+NsKeUd1PCiofcUDfHwj/cUaHUzloqLi29KcGEljbssvbN2w5hYtYuE0PBEpZuVdpCZ8rUsbHZM9aw8qdNhItq59uXyuLObMr7X4n6CMvSNXazTiswa/sHwYWSXEaQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+86966+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1645704508807705.4723644478546; Thu, 24 Feb 2022 04:08:28 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id XBRuYY1788612xcP1foRjPOM; Thu, 24 Feb 2022 04:08:28 -0800 X-Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by mx.groups.io with SMTP id smtpd.web10.9179.1645703293746018472 for ; Thu, 24 Feb 2022 03:48:13 -0800 X-Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by alexa-out-sd-02.qualcomm.com with ESMTP; 24 Feb 2022 03:48:13 -0800 X-QCInternal: smtphost X-Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg04-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2022 03:48:12 -0800 X-Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.15; Thu, 24 Feb 2022 03:48:12 -0800 X-Received: from krabica.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.15; Thu, 24 Feb 2022 03:48:11 -0800 From: Tomas Pilar To: CC: Ray Ni , Ard Biesheuvel , Leif Lindholm Subject: [edk2-devel] [PATCH] MdeModulePkg: Correct high-memory use in NvmExpressDxe Date: Thu, 24 Feb 2022 11:47:44 +0000 Message-ID: <20220224114744.1966974-1-quic_tpilar@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,quic_tpilar@quicinc.com X-Gm-Message-State: ABFgBhbOPuIIt91RpSskhWDkx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1645704508; bh=GjwspSKk8lZIktt4em6XaZeKVNrG6r5f/OBtboDdq9g=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Q+Ew3C4Cd89FPLykN01AnFXNZMZ3/geOhW2eJ1m+RhHxSN/zfaEmPND8VsIrQe6zomc BTcj9duljDMNyyEkv5JPC2YJufTtcMTxuboGh+cUBBFcmxTKO4rncdcpujGrwH7uUPuKc 1oPcTTE683gsJZJjbtHKkLpurhlRdgj1LJY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1645704510704100002 Content-Type: text/plain; charset="utf-8" Delay and move the allocation and mapping of memory that backs the DMA engine in NvmExpress devices to NvmeInit() to ensure that the allocation only happens after the EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE attribute is set on the PciIo controller. 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. Cc: Ray Ni Cc: Ard Biesheuvel Cc: Leif Lindholm Signed-off-by: Tomas Pilar --- .../Bus/Pci/NvmExpressDxe/NvmExpress.c | 41 ------------- .../Bus/Pci/NvmExpressDxe/NvmExpressHci.c | 57 ++++++++++++++++--- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c b/MdeModulePkg= /Bus/Pci/NvmExpressDxe/NvmExpress.c index 9d40f67e8e..cc921756f5 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c @@ -912,8 +912,6 @@ NvmExpressDriverBindingStart ( NVME_CONTROLLER_PRIVATE_DATA *Private; EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath; UINT32 NamespaceId; - EFI_PHYSICAL_ADDRESS MappedAddr; - UINTN Bytes; EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *Passthru; =20 DEBUG ((DEBUG_INFO, "NvmExpressDriverBindingStart: start\n")); @@ -959,45 +957,6 @@ NvmExpressDriverBindingStart ( goto Exit; } =20 - // - // 6 x 4kB aligned buffers will be carved out of this buffer. - // 1st 4kB boundary is the start of the admin submission queue. - // 2nd 4kB boundary is the start of the admin completion queue. - // 3rd 4kB boundary is the start of I/O submission queue #1. - // 4th 4kB boundary is the start of I/O completion queue #1. - // 5th 4kB boundary is the start of I/O submission queue #2. - // 6th 4kB boundary is the start of I/O completion queue #2. - // - // Allocate 6 pages of memory, then map it for bus master read and wri= te. - // - Status =3D PciIo->AllocateBuffer ( - PciIo, - AllocateAnyPages, - EfiBootServicesData, - 6, - (VOID **)&Private->Buffer, - 0 - ); - if (EFI_ERROR (Status)) { - goto Exit; - } - - Bytes =3D EFI_PAGES_TO_SIZE (6); - Status =3D PciIo->Map ( - PciIo, - EfiPciIoOperationBusMasterCommonBuffer, - Private->Buffer, - &Bytes, - &MappedAddr, - &Private->Mapping - ); - - if (EFI_ERROR (Status) || (Bytes !=3D EFI_PAGES_TO_SIZE (6))) { - goto Exit; - } - - Private->BufferPciAddr =3D (UINT8 *)(UINTN)MappedAddr; - Private->Signature =3D NVME_CONTROLLER_PRIVATE_DATA_SI= GNATURE; Private->ControllerHandle =3D Controller; Private->ImageHandle =3D This->DriverBindingHandle; diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c b/MdeModule= Pkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c index ac77afe113..359373300e 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressHci.c @@ -718,14 +718,16 @@ NvmeControllerInit ( IN NVME_CONTROLLER_PRIVATE_DATA *Private ) { - EFI_STATUS Status; - EFI_PCI_IO_PROTOCOL *PciIo; - UINT64 Supports; - NVME_AQA Aqa; - NVME_ASQ Asq; - NVME_ACQ Acq; - UINT8 Sn[21]; - UINT8 Mn[41]; + EFI_STATUS Status; + EFI_PCI_IO_PROTOCOL *PciIo; + UINT64 Supports; + NVME_AQA Aqa; + NVME_ASQ Asq; + NVME_ACQ Acq; + UINT8 Sn[21]; + UINT8 Mn[41]; + UINTN Bytes; + EFI_PHYSICAL_ADDRESS MappedAddr; =20 // // Save original PCI attributes and enable this controller. @@ -777,6 +779,45 @@ NvmeControllerInit ( DEBUG ((DEBUG_WARN, "NvmeControllerInit: failed to enable 64-bit DMA (= %r)\n", Status)); } =20 + // + // 6 x 4kB aligned buffers will be carved out of this buffer. + // 1st 4kB boundary is the start of the admin submission queue. + // 2nd 4kB boundary is the start of the admin completion queue. + // 3rd 4kB boundary is the start of I/O submission queue #1. + // 4th 4kB boundary is the start of I/O completion queue #1. + // 5th 4kB boundary is the start of I/O submission queue #2. + // 6th 4kB boundary is the start of I/O completion queue #2. + // + // Allocate 6 pages of memory, then map it for bus master read and write. + // + Status =3D PciIo->AllocateBuffer ( + PciIo, + AllocateAnyPages, + EfiBootServicesData, + 6, + (VOID **)&Private->Buffer, + 0 + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Bytes =3D EFI_PAGES_TO_SIZE (6); + Status =3D PciIo->Map ( + PciIo, + EfiPciIoOperationBusMasterCommonBuffer, + Private->Buffer, + &Bytes, + &MappedAddr, + &Private->Mapping + ); + + if (EFI_ERROR (Status) || (Bytes !=3D EFI_PAGES_TO_SIZE (6))) { + return Status; + } + + Private->BufferPciAddr =3D (UINT8 *)(UINTN)MappedAddr; + // // Read the Controller Capabilities register and verify that the NVM com= mand set is supported // --=20 2.30.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#86966): https://edk2.groups.io/g/devel/message/86966 Mute This Topic: https://groups.io/mt/89363151/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-