From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.76]) by mx.groups.io with SMTP id smtpd.web08.31584.1655480353802769446 for ; Fri, 17 Jun 2022 08:39:14 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=selector2 header.b=kX89OhT3; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.237.76, mailfrom: jbrasen@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gB1/FhpPrUKs2cFe5dxoMdmUPLtEQIFO0d2kTv/rnFKpo++yb20ul3XmUgoJLLcO3VuN1TEAqrp4DYCOdDzoChUxDnqmB7WvBi1uxyDK2lD5oF95PGXepgRi9qDRZL5uOAsO4IhznTgmz6QKcwfIAsPbQ5rEHjvRYel5kpEM6smml8nxkW3HQumsL4a2srz1SSHUyFJbMgzPe5F0XCvpZKNsm12QgbKkPQihSnROrQzDenPIrLDnpyZ6K6KpLCQm4RrC+Y/JLeYHanAOFYles59Kn6BihcMEOY2BSoPfNYZ0OjxMW3Guuid+G16EHGdJ4WJZslcvePr7mVAQ2ABFgA== 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=/A9ZK8jCrbebc7SvAPyqpEXpNjW2/ShHM07kGacDHZU=; b=b0cvbNCIXCVjukHxhsVqTj+5jThaaQaYvLhGNaO5XuXHv7Uw3OnxggNeUCMDXZwFf5/5iXx8p+9sH2y/pJqz6wDddCHwg0vL8xntGr1moW3NqnBVa5gPN2ihPDuJOau0BPRMsaDOHBeWB6BNQ8OIFOLJPAvyyXrQrVumEKio5UNiWclQL7eZVpT2nxvpEErNd/1eKwFfnGt6CDaCGYrMSQRJPWliUGWfbgkxD/USD47szejjEhPizhuL6T48Jli5QLd/+/DB57iIskHN+hmrG7tM0V8Fbn9s/PMg+vTOJlrit4Q02VYWyLbWpbyo01yWuCde7y3XeaoUH9u5gy3C0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/A9ZK8jCrbebc7SvAPyqpEXpNjW2/ShHM07kGacDHZU=; b=kX89OhT3coHQNON+cRsNEejK5JNQMnmUTHdLaXSFPZy0vgtiGvRuYq9QVclQNie4qX/JR2RUDLkMmaE220IYvDVbU08M8z+48WzZzQzMjaflHdIW3AGffiXPzMH4iVZA7z1Xj9/60Lnr267cwNfFaAcKOx8PuhKoT58PFNpDmvztGWW5mYbe4IKJI4UoEX7gylzGmnJxMusT4verbbPFhGeQYQdbRF4c5y/iZvQhIR14++cyYgJz0s1xQkvBrUunIREHbEsx4gniJGGvGx9ZeJGyzbu+6fw6HJ05NwurKoL/2O5TSRqfpRjkWbUd8rwPSbZuyJEYO1M/mo6mABAY/w== Received: from DS7PR12MB5789.namprd12.prod.outlook.com (2603:10b6:8:74::21) by DM6PR12MB3932.namprd12.prod.outlook.com (2603:10b6:5:1c1::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.14; Fri, 17 Jun 2022 15:39:11 +0000 Received: from DS7PR12MB5789.namprd12.prod.outlook.com ([fe80::2d7a:a12e:f513:1db1]) by DS7PR12MB5789.namprd12.prod.outlook.com ([fe80::2d7a:a12e:f513:1db1%7]) with mapi id 15.20.5353.014; Fri, 17 Jun 2022 15:39:11 +0000 From: "Jeff Brasen" To: "devel@edk2.groups.io" CC: "hao.a.wu@intel.com" , "ray.ni@intel.com" Subject: Re: [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow partial FreeBuffer Thread-Topic: [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow partial FreeBuffer Thread-Index: AQHYIdMhkN1aolyobUmozuz9retSnq1UfRZg Date: Fri, 17 Jun 2022 15:39:11 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: da6a78b6-fb5f-4a75-8f77-08da507786ac x-ms-traffictypediagnostic: DM6PR12MB3932:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 9+8M39ab47AMZBGpfQz5fdrh4PSXuzaiTXYVGz8XIQejatCdNu333P7EJIIC3TBRLwh15c3I7tgGqBOUYhxTiz6wrKNsJi0JLH7jkMkrDLve/kx1/TsEuglxj8NLFEOm4H30BPI2e6ySitYLcCG8NRjP2oJFh2o6ShVKft7XG3Gw9A0vHjFL+5nymN5ygIHkOgzFvZj0vXynsmU2iaZv6cmXHecORdNpqODB4yeRqIYyd7+evT7Jgd7Jj5SHwfCRUZhW57vOO5PJPMSTFIkk0PAZSb9IRySbZ2UtEhNUaGlUgw2+E432/0YzFmoisIw536gd3+vWiMYaDxeiO6yYq8Ru+cCCeCuJ6oWhWzAB14b0Gk/0y+/eKukHwKO8/SliQWKVNvjjPe1qdtVx+Obs4X0lXbimMFPqG6NK/uE03QJGfA/+JnhWJulx51N89PvvszJndwU9hCrxxB2FkdF5xUZRASs7M0UtuKTbf7kXHfUoQDllQ/VyrBd3gAGhAEFc5FK/LwyTM1iMFFXAw4jzBuBPIJrMNw1wpLuSogpdTByfmchfdJeUOJnnR3QuIuRBAGLzQsWhcIqKXSd5FjWbsY894knYOYQEup6VXDFkZg5O83FU7+VV5tQqct11ZyaX5bGzF55hIRXQO8JR9vP/LjHp9mBEnO8P6UAFfWufWIfPwW073J5dHVdxFF4U3PQaue2OHr2SrBuSDXnNSikVA/FtAcKePiweSi/1zIBv68c= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB5789.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(26005)(52536014)(316002)(6916009)(5660300002)(71200400001)(38070700005)(8936002)(6506007)(4326008)(86362001)(186003)(498600001)(55016003)(9686003)(53546011)(7696005)(66476007)(66556008)(2906002)(8676002)(66446008)(83380400001)(38100700002)(76116006)(64756008)(66946007)(122000001)(54906003)(33656002)(213903007);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?85wvdg9JYJGsRV9P2m7JhSHvS47OKu6hudpTRB1i15WiDb+6HA7anwyu78Jr?= =?us-ascii?Q?KPyyY0zPZ7TA8fUcFLv4r0AkFarSP3WeJ4IEBpVFxxSa/vHf3GpnK5h0xt+q?= =?us-ascii?Q?T6sBCY4CjsSYEK56C9/BSsadWR2hxQEGWE5eCYrUUTL6+abjY5ok31/nlRLO?= =?us-ascii?Q?u6g1zqZYqDLHHW/0Px79THRDxL2rlzFO9z7cPygBLOS0gyvUOm5Z8CFhiygL?= =?us-ascii?Q?L5G9FVRIAj7uUJaqkkwocouJAiy7yQcvsfbtBLquX71jHzHwug1x0B2RyEAg?= =?us-ascii?Q?EE37IHbytLeGo69iNRJCaQEfBXNPyOyLCAVStf7IXi5OAA80b47uH8DOIICN?= =?us-ascii?Q?OmYmBiHjkGW2oT7vTDCUiUPxuMuSavAh2Wuz5srTQ1UESGn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9dcBmDT1RMW6aJ8vFfNifJPYRyO08SkEp0tkb2aTa40NZfaNmmw2aA52?= =?us-ascii?Q?Wfrn1PibLOGPfzJ6ZKzHveLbxzUhq1EzjNNE4vTZCtCGf58RhzEEaOl0sf3z?= =?us-ascii?Q?QaK/QtT260rc9sxJutvNOq/7gjV7yrhj9RTAAdRHZJUsix85ixTXEKTyfElQ?= =?us-ascii?Q?P6orenNY7TjA+cAXOKbfozxucpYW8N8geN+4A8rw3fIKMjodSBdCmkkqjP9f?= =?us-ascii?Q?KBPezFYIer1rPgaJ8jP9DBI60R2OTcpbysfNHpyq3Ub3xbVLtHBoNh6XhSRl?= =?us-ascii?Q?2cdO/5LWLadTBDbc4bV2Qjn0eXiY3JQ2aouVtDoZi9JdCzN4KPpZ/soaaczD?= =?us-ascii?Q?Xq0Vp8b4kzK894hv6yUB5UxzcybsT+2cGbsgPveYfvIZ/uP3ZNOu+ymwl0Oo?= =?us-ascii?Q?kTluX3IIwa12uw11vZrzC6A3uC6jt4wt7xbg5lnqn5g3I5zzrU+79/dPGDwW?= =?us-ascii?Q?FK+muVkOSg=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB5789.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: da6a78b6-fb5f-4a75-8f77-08da507786ac X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jun 2022 15:39:11.6664 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: tXunUuIUEeDHyEeD8UtVT36MZ+WcPc66exHh4w6o1w4biEgnwDtm5XfZV4ogPHma/ckGhl9zsTX9xUde4V/d2w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3932 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Any thoughts on this patch? > -----Original Message----- > From: Jeff Brasen > Sent: Monday, February 14, 2022 11:46 AM > To: devel@edk2.groups.io > Cc: hao.a.wu@intel.com; ray.ni@intel.com; Jeff Brasen > > Subject: [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow > partial FreeBuffer >=20 > 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. >=20 > Signed-off-by: Jeff Brasen > --- > .../NonDiscoverablePciDeviceIo.c | 53 ++++++++++++++++++- > 1 file changed, 51 insertions(+), 2 deletions(-) >=20 > diff --git > a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverable > PciDeviceIo.c > b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverable > PciDeviceIo.c > index c1c5c6267c..77809cfedf 100644 > --- > a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverable > PciDeviceIo.c > +++ > b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverable > Pc > +++ iDeviceIo.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,1= 3 @@ > 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 > + (Pages + 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, > -- > 2.17.1