From nobody Sat May 4 02:04:25 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+48851+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+48851+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1570820147; cv=none; d=zoho.com; s=zohoarc; b=dQ7fz7eWGdLMwEW1brT/LPJg4odL24pL1BuPlz0J/J0MU/tRm0Kx1W8etddkMxrRrKV2ajabMRHv1kSIvFUGtBeensxyNncALtEntUGJ5xVowuCeojGC57BtpUOBY3hvD8pzx1M5V7vSVHJIfcr7a1kc6KIAnbobT0Lo5QrnSiE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570820147; h=Content-Type:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=vsCwf1hJuezQgqUozrEXK23BiJOtE07wmL/Tlgp16Yw=; b=XR4Ed1DOLnoxX/V3OzsxwEXuMKN44m71yBpCHJOPdWHI0jLM1GYMGwIm6LLiR2yTGL/p3ELIu3GBzo7mcSCDGLo3K/4y9LgmuefkilBT1LzvUuTyH7eiDBTxIA6Y9cL5ZSlpFYwC+L2PpbqT6Usc22Vya8pW5UlQXcuoIVuYZqk= 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+48851+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 1570820147332370.39879636896126; Fri, 11 Oct 2019 11:55:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Fri, 11 Oct 2019 11:55:46 -0700 X-Received: from hqemgate16.nvidia.com (hqemgate16.nvidia.com [216.228.121.65]) by mx.groups.io with SMTP id smtpd.web10.4086.1570820143879622600 for ; Fri, 11 Oct 2019 11:55:43 -0700 X-Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 11 Oct 2019 11:55:45 -0700 X-Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 11 Oct 2019 11:55:43 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 11 Oct 2019 11:55:43 -0700 X-Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 11 Oct 2019 18:55:43 +0000 X-Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Fri, 11 Oct 2019 18:55:43 +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:55:43 -0700 From: "Ashish Singhal" To: , , CC: Ashish Singhal Subject: [edk2-devel] [PATCH v3] MdeModulePkg/XhciDxe: Fix Aligned Page Allocation Date: Fri, 11 Oct 2019 12:55:38 -0600 Message-ID: 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=1570820146; bh=LyVEfb6NwLuHNlXbZRk16yX4/Iaaoq4tw8Q5uTljOIA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=AaiZLeco0msBQvaN5Mv7e3RB8r8EGmo8QPciruSZz5fMDVwViJTxG5ZOk4EUsveHPE6 9mCU1pFPeDYTP9kjSYj4aEQhpU7tjOBckIDsnYepUS21IBNtfAq+7M5XhCAIStS9RW1CN /PoWgD68ZjATvI+wTdFTY3vpqFBp7w/ySaU= 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 | 20 +++++++++++++++++++- 2 files changed, 20 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..f95b5e5 100644 --- a/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c +++ b/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c @@ -567,6 +567,7 @@ UsbHcAllocateAlignedPages ( EFI_PHYSICAL_ADDRESS DeviceMemory; UINTN AlignedDeviceMemory; UINTN RealPages; + UINTN UnalignedPages; =20 // // Alignment must be a power of two or zero. @@ -593,7 +594,7 @@ UsbHcAllocateAlignedPages ( ASSERT (RealPages > Pages); =20 Status =3D IoMmuAllocateBuffer ( - Pages, + RealPages, &Memory, &DeviceMemory, Mapping @@ -603,6 +604,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 (#48851): https://edk2.groups.io/g/devel/message/48851 Mute This Topic: https://groups.io/mt/34502854/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-