From nobody Wed May 15 19:07:31 2024 Delivered-To: importer@patchew.org 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+86661+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1644864340907106.2021058024693; Mon, 14 Feb 2022 10:45:40 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id d5xhYY1788612xsearPFxmq8; Mon, 14 Feb 2022 10:45:40 -0800 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.49]) by mx.groups.io with SMTP id smtpd.web08.38823.1644864339479701509 for ; Mon, 14 Feb 2022 10:45:40 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YwNWJbexpKkkHM/j4o+B0nibqgMj2I3+9wQAgZFN9RgkbvxKk/RO6rg6CBhiJoy0IFZfxeXe+7PdL8MSolYuUyRFb65CkXkF7cgeLkSg6ngNWA8nZM3Wsgl0WnHdlGxitmC7k/cItRrm1OGHwLlcRpEIjm8JcemVNyMRaGyOIEnuEFohS+ZLtBYa6qOm0aKIgoX45hiPCWvaG0td01irJjqXMhB/h3d02wAmtlwYcOr0vy3IMCmeYiiKFrcRKRD1d1ggUU+9ClC5sa00SLTZhDKiQzHPKYBdPuITZrzW37djY0NiX6G5rLp5MEbrg9gFAg6bc0EVWU+7lT9sHPftGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4hT4bhnHlpvgv7KvTRpgxeLnKU/4PcRo1Yf6+mMhwGA=; b=LhqAXRhbvd4Nzsu0YsA4/f1O/Ior0q4DRx2iZEZ9sVF1kAe5xZnc+jRi3kVdF1ld6ChM6IhNE3icrl0227NCTLLmptG4Pz7mDrsMr7DM2AxtdzROcYbBQPJGYImPZUnXwdIX4ZEyv77truYEmZLgnNUMGdkWJo+AnJHS/H0aNEP3oYzvhZKqrNmvA/8/7cOUAsBwCFlNKxgRW+DjiV6srBi2NIZqgZc3eNTLWCfeobE+NzZs5WZnmqbxqkc7pG8tf7JI5EDc9gmhJ5Yqj41Rn7OG4Stl5p/AXBBxjoq/hAs1/aALiO7sgyP6w3DMQbj9M4tuZ4hDFy+sSIxNYWfKOA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none X-Received: from MWHPR07CA0020.namprd07.prod.outlook.com (2603:10b6:300:116::30) by DM6PR12MB4777.namprd12.prod.outlook.com (2603:10b6:5:16f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 14 Feb 2022 18:45:37 +0000 X-Received: from CO1NAM11FT049.eop-nam11.prod.protection.outlook.com (2603:10b6:300:116:cafe::e9) by MWHPR07CA0020.outlook.office365.com (2603:10b6:300:116::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11 via Frontend Transport; Mon, 14 Feb 2022 18:45:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; 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+86661+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; X-Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT049.mail.protection.outlook.com (10.13.175.50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4975.11 via Frontend Transport; Mon, 14 Feb 2022 18:45:36 +0000 X-Received: from rnnvmail202.nvidia.com (10.129.68.7) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 14 Feb 2022 18:45:36 +0000 X-Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Mon, 14 Feb 2022 10:45:35 -0800 X-Received: from build-jbrasen-20220214T083816909.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.9 via Frontend Transport; Mon, 14 Feb 2022 10:45:35 -0800 From: "Jeff Brasen via groups.io" To: CC: , , Jeff Brasen Subject: [edk2-devel] [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow partial FreeBuffer Date: Mon, 14 Feb 2022 18:45:31 +0000 Message-ID: X-NVConfidentiality: public MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b5c1dbb9-fa9b-4cd9-bb72-08d9efea30bd X-MS-TrafficTypeDiagnostic: DM6PR12MB4777:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2733; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: nPpojOxefpc9wggImZQnB3iKeFq+550R/wJMAE5f2s32S18Suc5OxB3u1va4Cg9xlfqxUZez5LnGas48qP+rchMWxQ7MM+HPDrHqLdklOtuQqBQBdCrRQoM7+MNIRXVThZYEgDNG9ZFM8qBF0VN1XLBRVQyPDm2GnuVBJ4SMcllo/mWw1pPhY2hzq7eBzpgZYhpcDjcdnuByOio38wWn3zp5kan1zghzb66jeVUCTWVm2astrI1YnzxAqauKjtYT+YIkBnHQgXtxBJt7jvwJp0k+Zc7PxI/+ZqCgglz3fBvJywaBHvy5DZJJ+XeNvhQzowfz79DNCc8DAlDUJttLiqnRHw3rqzy/slgWOMkDfOaxFSQf3kkOAss0T9TaMNEbhYb/CNn5ain5y5eKK7Y92iQXT93SVWnPjU6+WhEnWnL7XzSbZQTuNFNRTCeMFD1oztDUO3MoHgJi8m8dyD6dPf/I30jq+MQo2p1bQ7/HyvniLo1Dx5lch8Uv/R+2b4W64VFPD3gh/ULs+TDCly13zQ4Ac/ZpjOyTLga60TAfxuq3X+tu3YY1/9SiLm2r4bwOQPZdJVwX62byQug+3QPeW2mbHTpOk05nSzeVPU8a7G0s5Kxi7CJ05PxICCnPr64U0o23PSI1XiT2E+Ix2mV24A29QoS21MjqMkDmY7iwaEdsZKOucGIJG936avwqmmVCwRMq7qbQVBozpAxuvZ1JhozOgHlRvCJP4DZmS8Ps/Q8= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2022 18:45:36.6731 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b5c1dbb9-fa9b-4cd9-bb72-08d9efea30bd X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.236];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT049.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4777 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,jbrasen@nvidia.com X-Gm-Message-State: kmm8zoCCdlqE1a1wU7hXr7q5x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1644864340; bh=P+ZRXcCndnd+8nMp3wJBqnzngGSTrIlmoQW3nBw79Jk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=muQx+PbWeossIDyc8/F9qWXruthNDijsIYDyIEw+mqjZrU+qJ7sBH7op9bkRZslLXnX iD6gFnt0FAJg/9Z1WLWE9KTcrbmFDlZ0ZvK1/cT+e3NoxSQm9fZ4ZeqBHgSG7wBi9plbf 4RxNYs7fyb9D3aoUZIbwQvvUlnV+Kq//tu0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1644864342420100002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for partial free of non cached buffers. If a request for less than the full size is requested new allocations for the remaining head and tail of the buffer are added to the list. Added verification that Buffer is EFI_PAGE_SIZE aligned. The XHCI driver does this if the page size for the controller is >4KB. Signed-off-by: Jeff Brasen Reviewed-by: Ard Biesheuvel --- .../NonDiscoverablePciDeviceIo.c | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverab= lePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDisco= verablePciDeviceIo.c index c1c5c6267c..77809cfedf 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.c @@ -960,12 +960,23 @@ NonCoherentPciIoFreeBuffer ( LIST_ENTRY *Entry; EFI_STATUS Status; NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION *Alloc; + NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION *AllocHead; + NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION *AllocTail; BOOLEAN Found; + UINTN StartPages; + UINTN EndPages; + + if (HostAddress !=3D ALIGN_POINTER (HostAddress, EFI_PAGE_SIZE)) { + ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER); + return EFI_INVALID_PARAMETER; + } =20 Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO (This); =20 Found =3D FALSE; Alloc =3D NULL; + AllocHead =3D NULL; + AllocTail =3D NULL; =20 // // Find the uncached allocation list entry associated @@ -976,9 +987,13 @@ NonCoherentPciIoFreeBuffer ( Entry =3D Entry->ForwardLink) { Alloc =3D BASE_CR (Entry, NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION,= List); - if ((Alloc->HostAddress =3D=3D HostAddress) && (Alloc->NumPages =3D=3D= Pages)) { + StartPages =3D 0; + if (Alloc->HostAddress < HostAddress) { + StartPages =3D (HostAddress - Alloc->HostAddress) / EFI_PAGE_SIZE; + } + if ((Alloc->HostAddress <=3D HostAddress) && (Alloc->NumPages >=3D (Pa= ges + StartPages))) { // - // We are freeing the exact allocation we were given + // We are freeing at least part of what we were given // before by AllocateBuffer() // Found =3D TRUE; @@ -991,7 +1006,41 @@ NonCoherentPciIoFreeBuffer ( return EFI_NOT_FOUND; } =20 + EndPages =3D Alloc->NumPages - (Pages + StartPages); + + if (StartPages !=3D 0) { + AllocHead =3D AllocatePool (sizeof *AllocHead); + if (AllocHead =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + AllocHead->HostAddress =3D Alloc->HostAddress; + AllocHead->NumPages =3D StartPages; + AllocHead->Attributes =3D Alloc->Attributes; + } + + if (EndPages !=3D 0) { + AllocTail =3D AllocatePool (sizeof *AllocTail); + if (AllocTail =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + AllocTail->HostAddress =3D Alloc->HostAddress + ((Pages + StartPages) = * EFI_PAGE_SIZE); + AllocTail->NumPages =3D EndPages; + AllocTail->Attributes =3D Alloc->Attributes; + } + RemoveEntryList (&Alloc->List); + // + // Record this new sub allocations in the linked list, so we + // can restore the memory space attributes later + // + if (AllocHead !=3D NULL) { + InsertHeadList (&Dev->UncachedAllocationList, &AllocHead->List); + } + if (AllocTail !=3D NULL) { + InsertHeadList (&Dev->UncachedAllocationList, &AllocTail->List); + } =20 Status =3D gDS->SetMemorySpaceAttributes ( (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress, --=20 2.17.1 -=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 (#86661): https://edk2.groups.io/g/devel/message/86661 Mute This Topic: https://groups.io/mt/89143704/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-