From nobody Mon May 6 23:44:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+48848+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+48848+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1570817230; cv=none; d=zoho.com; s=zohoarc; b=n4safzpgFAbnhX9zVxB3WGB3SjMyZMkJtTbKA5ri51Zvd49GRE7BkRwjScQzesR8diAov3f2nank6LGDdNL+fpA9kP2lFQ+jGFrEVwG/YS/MCAs7tGaGKFSIb3x5NLs3bmT/O3dNOzhvjwQan8iuziYH8MTfSkiLV8yYmeqz3FQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570817230; h=Content-Type:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=baDLODQpT1YoUTI3KSyW4qwFrq0eQZ7quCBJShfCsNQ=; b=NGzPfMUnVK3xV0rIxsZ0569jJ4ALImm1dhta/Qxug9QiTJzwvZJKkL1RuUZOxKUiFgJA4lLJnQD3ZJgflz+q/Amdrb04c3wghWjou0M0yiK3RqIjh7OkNGDAaNBkEtdhHU8CcbETkNQxx4Mckm2+BaqLs0jt8i+AbOHMD8bpOcg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+48848+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1570817230798207.152808825457; Fri, 11 Oct 2019 11:07:10 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Fri, 11 Oct 2019 11:07:10 -0700 X-Received: from hqemgate14.nvidia.com (hqemgate14.nvidia.com [216.228.121.143]) by mx.groups.io with SMTP id smtpd.web12.3604.1570817229861393863 for ; Fri, 11 Oct 2019 11:07:09 -0700 X-Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 11 Oct 2019 11:07:13 -0700 X-Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 11 Oct 2019 11:07:09 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 11 Oct 2019 11:07:09 -0700 X-Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 11 Oct 2019 18:07:09 +0000 X-Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Fri, 11 Oct 2019 18:07:09 +0000 X-Received: from ashishsingha-lnx.nvidia.com (Not Verified[10.28.48.147]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Fri, 11 Oct 2019 11:07:09 -0700 From: "Ashish Singhal" To: , , CC: Ashish Singhal Subject: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Fix Aligned Page Allocation Date: Fri, 11 Oct 2019 12:07:03 -0600 Message-ID: <1f0bc680ed44632b3aa2e961a711708355cbb890.1570816666.git.ashishsingha@nvidia.com> In-Reply-To: References: X-NVConfidentiality: public MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ashishsingha@nvidia.com X-Gm-Message-State: aaaaaaaaaaaaaaaaaaaaaaaax1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1570817230; bh=4MKLnpERVvihPckQTJl3vuC7JRDu0/cojLRzz6lGlFE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=J1M8YBjQ+KoXox62ZaRBWJpcUKfh7m9z8xwGZJbb2MaMSZSY1TV/zXuOhR+EU8tLFK9 /0qqQKEqJUXlAbCwKCRYq24Gln+OP7DLETEcx4A1NgqrK9PKWnfExB2sTpLf135VsXQtY uo+zQJZS3EzQ+RlitvAkvzvqtFo/HqGw7ZI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" While allocating pages aligned at an alignment higher than 4K, allocate memory taking into consideration the padding required for that alignment. The calls to free pages takes care of this already. Signed-off-by: Ashish Singhal --- MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c | 2 +- MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c b/MdeModulePkg/Bus/Pci= /XhciDxe/UsbHcMem.c index fd79988..aa69c47 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c @@ -656,7 +656,7 @@ UsbHcAllocateAlignedPages ( PciIo, AllocateAnyPages, EfiBootServicesData, - Pages, + RealPages, &Memory, 0 ); diff --git a/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c b/MdeModulePkg/Bus/Pci= /XhciPei/UsbHcMem.c index 56c0b90..074beee 100644 --- a/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c +++ b/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c @@ -593,7 +593,7 @@ UsbHcAllocateAlignedPages ( ASSERT (RealPages > Pages); =20 Status =3D IoMmuAllocateBuffer ( - Pages, + RealPages, &Memory, &DeviceMemory, Mapping @@ -603,6 +603,23 @@ UsbHcAllocateAlignedPages ( } AlignedMemory =3D ((UINTN) Memory + AlignmentMask) & ~AlignmentMask; AlignedDeviceMemory =3D ((UINTN) DeviceMemory + AlignmentMask) & ~Alig= nmentMask; + UnalignedPages =3D EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN) Memory); + if (UnalignedPages > 0) { + // + // Free first unaligned page(s). + // + Status =3D IoMmuFreeBuffer (UnalignedPages, Memory, Mapping); + ASSERT_EFI_ERROR (Status); + } + Memory =3D (VOID *)(UINTN)(AlignedMemory + EFI_PAGES_TO_SIZE (Pages)); + UnalignedPages =3D RealPages - Pages - UnalignedPages; + if (UnalignedPages > 0) { + // + // Free last unaligned page(s). + // + Status =3D IoMmuFreeBuffer (UnalignedPages, Memory, Mapping); + ASSERT_EFI_ERROR (Status); + } } else { // // Do not over-allocate pages in this case. --=20 2.7.4 -=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 (#48848): https://edk2.groups.io/g/devel/message/48848 Mute This Topic: https://groups.io/mt/34502003/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-