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.57]) by mx.groups.io with SMTP id smtpd.web12.292.1659039905063035010 for ; Thu, 28 Jul 2022 13:25:05 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=selector2 header.b=QH3J/zBE; 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.57, mailfrom: jbrasen@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZeJsau+rUNMndEfoMi8LzbiWd/iU+v/FgPf5l3ugzYLJBIfJ/bNVy5+lJSwV3Q+Atli0DhmD+y6NbIaLl4rk8jSl2MQoszKndq4bkKtUMufgaWbAKkjCbntaQAcSuAesZuyolgTXzjm4vscOPCWf8qnw0KJbN98fdWCJau/KJMwlQrd/BG6bcbrPEft4n3FwewPw0dH6hCb2Twcgjg7S92PJ33OqTnpfTmCeLOOGen70mEr7AbT7UtXDjkg4wS1Pgfgw0Chqwm1ZWs4qlxXWhYj4seAjWgRoJqwR7S3tgH4FG3iZ9NeYNQPmAuVzFg6WsKPYgfmNbGRNva4nK6JZ9g== 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=RIEvW0W+Tlez3fY3pHkizIw8CMzzNhE2q7MPM/PvpN8=; b=am4q7O0EVhIPURg6CfdlJtpoYylWYtW7bFWwyuuVWgS9hXdAcWn7qKoW+SRUG3slP8DfqW5JBtLHfcL5k9J+KtbwqWvT5+TeZnS51LVz4pKgKepJxHEHr3PZ0AKjIqxBEkXCaN4oiWU8Wk9AZFB9JOb0LFUidBTCCfsySs4PeVvg7l8cfNj/8TDHfMDNERGv9kySjmZCjLzeBGNhQ8fh1Iry1qaAjOi5kJ90/Ku+W2cc3oJEt16PsJqZibubRZfAEfzeWrF0aWZsJFYWp+DXyY7fP5+TbQzHC8PyKpdH9+uh2Qfaz0j1hmSwI07EiYbVjerVd3+Crwv9WQIJJpTExg== 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=RIEvW0W+Tlez3fY3pHkizIw8CMzzNhE2q7MPM/PvpN8=; b=QH3J/zBEqZFRtZxzGE3rrNEQl8wt7dCKWAuE5cdP4n+4fgeZr4qmRsPXslEMIHmbzKOSgZ0XZc3d1c9NNlzCnjc/p5iz3XiMv/4/QzBw94bgK6VnpLkoo8Z1MBIhkCHHQcREf06COvHfrRp5kZwBed+htl7CVN1snKtYXjaQ820FcTHcM4lVb2I46D0xAVia9UAvFHvYvo4mxOk0EJ7S2HQKhXBwcDcW5iUxl95nJcQqr7V/nSXPhwj1Zt4rIube4eEzxcS9kanWI9uAxbK+rS5U5+5gvRng3HHg3TPQd5IRz8UqmiPqxvAk9515bdFhhCS6+kv34/g+SzIbbtFu4w== Received: from LV2PR12MB5800.namprd12.prod.outlook.com (2603:10b6:408:178::12) by DM4PR12MB5136.namprd12.prod.outlook.com (2603:10b6:5:393::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.11; Thu, 28 Jul 2022 20:25:01 +0000 Received: from LV2PR12MB5800.namprd12.prod.outlook.com ([fe80::587:cb96:31d8:c32f]) by LV2PR12MB5800.namprd12.prod.outlook.com ([fe80::587:cb96:31d8:c32f%6]) with mapi id 15.20.5458.025; Thu, 28 Jul 2022 20:25:01 +0000 From: "Jeff Brasen" To: "devel@edk2.groups.io" CC: "hao.a.wu@intel.com" , "ray.ni@intel.com" , "quic_llindhol@quicinc.com" , "ardb+tianocore@kernel.org" Subject: Re: [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow partial FreeBuffer Thread-Topic: [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow partial FreeBuffer Thread-Index: AQHYIdMhkN1aolyobUmozuz9retSnq1UfRZggEC/ViA= Date: Thu, 28 Jul 2022 20:25:01 +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: 1637b4dc-3de5-430b-d5d4-08da70d73f80 x-ms-traffictypediagnostic: DM4PR12MB5136:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: fHkukqX5fm8v1DbZ4NARQtzT4LjAWcnhsv6G1FA4NaL9erS4zt/wx6dgTC9IAmjDp9WQ1uOLGoVy7wXilN/pblUf3iESJDWmcRrbBydjwS0Wcjf5gKDvpAfrLp9zAzK6t3KSEurUPXb65B4mm1h3kqMHrDdAZCzXt2YkDSQYhluQ0KfjkEQfFLL9Fj3RAtS5aWxFIXLB1oOi94IE8oG3ggASqGM/0XDGMt63sYTbFoUtplPRHTsNBmUACaLFqodzdteu+HIgGEyYoRKSRoOsJteIrhT/zsRrwNZ190D/pfO3c5fa1l6Gvaapw1bNlDQqMYs14DTNfZRSzdD0m2u6x5SZetrUqqmsCBHb+pzbU9zZmWZUKiuh2ZwkE79H7SW8+3bs/juPMayvv7CX7PbOxX8Ct+JMs2pargy3ezxlthJ929xFUmfOCQcddRmejuOHzVqUOQ63XItlxmdrZMGHcocL1ZEqgY6IxIKnWGMctdCz0Gve8a/l6Km9VEsce8Iry87H4QiMx3oAeFKXiKRp/XXbNY25RxcIJvnz01oiJXMCHQGAf/Yt6z8eamtP2nMdW8HocQrnACjxDf/msfPVvs2COrPPsg4WbckFgWJN7Js9+u+OG7dgMpDyUNwJLsqSd9Gis3Fh7TzQ1A4/Wln9QbW+137IRPswUhCLDCN9jQs3nBuTqwNToGQTDqrcKpPxYVZ+sSmH+lUHSly82wEPQe8XDjMrEP1TUkmHTKWVh5Qe/ERlhEfu8Xk5sr3+r0mG7CXA2rtaBiSkfmJJFMq7H6L4ymMuppDr2Mf1srNZg5RLSR6fVgLYCJnOV0Hu+9Bul7u6C+/tcgKpSk85sfeSSA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5800.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(396003)(39860400002)(346002)(376002)(136003)(86362001)(38100700002)(83380400001)(38070700005)(66556008)(66946007)(66446008)(76116006)(64756008)(8676002)(55016003)(6916009)(122000001)(4326008)(316002)(54906003)(66476007)(2906002)(6506007)(52536014)(8936002)(26005)(7696005)(53546011)(9686003)(5660300002)(33656002)(186003)(41300700001)(478600001)(71200400001)(213903007);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?1yfys5hr9/xqoZvw95KBxR3odRYJFIR9bfVyrQBZauVWMIUhvbU50lQa5SbM?= =?us-ascii?Q?N67yoMPZmtuh9e1LJd8WZD3S399OfMQcuco6yMYbwxklzsXM7gp6FMtfdi99?= =?us-ascii?Q?9z8/+arfrlE1XHm3Fm64OvaOUsmaNn3QZWNACc8p/G1wOVdUf8lWSzWKWHwB?= =?us-ascii?Q?qzgFfa528W7A6HTY8Hmn1rc4hDlfRqZWO2btnjB8QwVEW00rGlVTRxVFADxk?= =?us-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Jnf01fJ6dfkD2CUwrsyU0w6xTlJ?= =?us-ascii?Q?tg1NfXcY59kzZYNIlYgILhL9VZgZBy3rgbUiFc7RvJ0GhKygfsD6er1j+wSu?= =?us-ascii?Q?zGcfG4EnDmVTcvnCS5L4/vD/4zgz23IqINKdqB2gWSvUuzDON0c6MLjqYrOF?= =?us-ascii?Q?Sl3KAqqSr5gIw2WSO/oghUJm9q96vuJE+mQjDbC1naE6roosjTRiQm1v2c2c?= =?us-ascii?Q?8SIcAmaiA0TvjFzA6tk9UczOXn16n4X0qBiYK3ao0hhLfajrvkhgBaGj6I4o?= =?us-ascii?Q?6sH5eXRox8hit1TI4dcBmqmWFSfIkbv27v1lkvwDHh7ub9VKIUFrS82QtKK/?= =?us-ascii?Q?LyNDfflFHBcfVUML36POxzIJG4kZtvKKfWPO88AdgUsBy0kfDcidcvgxdy0H?= =?us-ascii?Q?gsEXQF8n7BAn20lgv3o+h8ky6IoIeiX+dzXrNifrax6/7wCMge2OJmac8wH2?= =?us-ascii?Q?emCgKa2mAvp3uw7BXmkVH4uXbb44UpYRCNbKyyXO?= MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5800.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1637b4dc-3de5-430b-d5d4-08da70d73f80 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Jul 2022 20:25:01.1877 (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: YRi1ymvt+ul5kCsuXWdy32eOFOYm6SWHCgrGc21XA69rJfgopoxB8hFpjw5VezCjfhmOYitnaAGOAfnDzJyjig== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5136 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Adding Leif/Ard to CC incase they have any comments on this patch. Thanks Jeff > -----Original Message----- > From: Jeff Brasen > Sent: Friday, June 17, 2022 9:39 AM > To: devel@edk2.groups.io > Cc: hao.a.wu@intel.com; ray.ni@intel.com > Subject: RE: [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: > Allow partial FreeBuffer >=20 > Any thoughts on this patch? >=20 > > -----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 > > > > 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 > > --- > > .../NonDiscoverablePciDeviceIo.c | 53 ++++++++++++++++++- > > 1 file changed, 51 insertions(+), 2 deletions(-) > > > > 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; > > + } > > > > Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO (This); > > > > Found =3D FALSE; > > Alloc =3D NULL; > > + AllocHead =3D NULL; > > + AllocTail =3D NULL; > > > > // > > // 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_SIZ= E; > > + } > > + 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; > > } > > > > + 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); > > + } > > > > Status =3D gDS->SetMemorySpaceAttributes ( > > (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress, > > -- > > 2.17.1