From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.67]) by mx.groups.io with SMTP id smtpd.web08.7472.1646282109344192154 for ; Wed, 02 Mar 2022 20:35:09 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=selector2 header.b=Ck+Asa6d; 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.94.67, mailfrom: jbrasen@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gd0Su6E/9p/692p4R960e+xGOywptZxKhvbnAVhDKZaFp0q5CDooqc3buTXkt5T5ZxfFpV2NX3IJyZZAsyK+yNBd7MGNpmaysQuhhcrNzWZ2RI9ngUrmPA/mrb4hVqqybUJz/QUUQhRD8H3qKYunT1/U56N1opRk8qpfJ53J5vuPodM+I8zC8Jri1F93XSX60yGUJcoYueROLyZJqnHdQfjPVr1By59RiF2WteV/ZMbiSHbjhTBP0YegmhkUDlfxUEqgCN1xCurOWU64W9MGtUIC97kelhvOLP7SL72Z8GySlMwPiBSxxmusRkbEx70mgmvcdChgd7yGxwL+M8u+sg== 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=LUYL3opBHw/4sr/GzTN0G/0FFHRtzfDvH3XIvJIUg7Q=; b=UixdhGTwuqR+kewct1P2vzUMpw82xcxxWyk0z1vjW4jOwpBqHh92e2YritHSlWXttspDJD2lMelGe+1V7GAf9DwxGH2PefKIMj4FaOZbOgQcWqTaExcEGarCHkLGn4y8WaXOKIma7NzXHBaQe75G6u90Rt3coNAarrUzoeEtHOLl7aW04cI+9b7r5cBnnP1np1atUu4qyxoX84hQ22uL9V4chq8c726IYT/arW4yloetStXnz/tpgzERhxLa1o3Mx0GoEVxh1GXIyF+KLwaWgW3qtWIsU8ZI8mDMJEhG+KbZz9Uir2TFVvv734xhqF8qyaUkP4xGmjVRf79eyT1q8Q== 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=LUYL3opBHw/4sr/GzTN0G/0FFHRtzfDvH3XIvJIUg7Q=; b=Ck+Asa6dlCkeKa7m5kzZgpYVxPoNJwoAbTs9Cc1YyFaPj2VBcZhGoSLBpbvHAv1vv8+ieCBfjy0OZj5UHkA2v6mKxb5e34LXhpLimsTGYY3EmTtATOfPd8WTIF1MGzGxL61y6ebzNS6ZFUH2esqza/8c/6jRSssq4DMdeyKyKayoBzO4lc8g9g91xyuFG18galy4WPDpqYOcYzlbKi8eKwxZcnH1pT441we8pn+yk2V15DUZ9EgO9HLBEB1ypimryrDtmxLufV8vLSPauKm+eeuBbwqPIfH6eIUIZU0NhRvSRdyqRcMMYKJ6W+9c+NIFYrK5pMIXBDqm5nAuKfg+0A== Received: from CH2PR12MB4136.namprd12.prod.outlook.com (2603:10b6:610:a4::14) by CH2PR12MB4857.namprd12.prod.outlook.com (2603:10b6:610:64::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Thu, 3 Mar 2022 04:35:07 +0000 Received: from CH2PR12MB4136.namprd12.prod.outlook.com ([fe80::102f:1c39:7ba1:a0a8]) by CH2PR12MB4136.namprd12.prod.outlook.com ([fe80::102f:1c39:7ba1:a0a8%5]) with mapi id 15.20.5038.015; Thu, 3 Mar 2022 04:35:07 +0000 From: "Jeff Brasen" To: "Ni, Ray" , "Sindhu, Deepthi" CC: "Wu, Hao A" , "devel@edk2.groups.io" Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow partial FreeBuffer Thread-Topic: [edk2-devel] [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow partial FreeBuffer Thread-Index: AQHYIwHGm6BWp8hidkaVlXLuCBryPqytKgiw Date: Thu, 3 Mar 2022 04:35:07 +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: 3a34da8d-4bf4-4e42-7bc3-08d9fccf31aa x-ms-traffictypediagnostic: CH2PR12MB4857: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: OQ7OHx73BLOgT9I4MaE0Xru44+tEw7Pmzt/Xej70DN9um3R+BAr8Za3fDysTSYRTxujD3eupArGNPaGVl2F1biYCdIx1U0ZuqpeX+x6Urj80zH76X2vfxT1VxNyt50wfbLbEOmLcLelgTRTKADp9g9a1Hpgn5x0rsXQQn0k7DZYIQKqUtHMc16ubcxzGYM+0feEwlu/q8d63qPjKZ7I1VJCS7pBbbeZzrXfUS4ITPB37FffWDfljLLgA9jCV5/yN5qmk9wsChMmc60SztYrWhWdB5AHSleoTO5HDnDXA4hTSMZ2gvsuPyaLpVfcC0LmkBeFsgd/oaVtq3hoTWI6DnUbMqLBy+vGIxeVmIS8bGGikCyOS4L5hIznEp8yZEOo1ckLmnHeXG8g/R55VsmuUB33M2ooidRUG0gu2G5Giq1E6k3HI6Grh9yTQMmqQwh53gA17lAc/coXzDD7laHn1li3ikADj9WTWoVF9v/jrF701An3Jt7KrXbWlyBiowmBikX2GusBgeRi8LAzkNCel4FP43TNYHf6GDqy1dpUxuO+qCFvzTiRLQoQzlKq6AU3ngyQV9bK1cW/6glZHHxOJU6rImrYlf52NYTE6iZWMAIAa7780+i/rr4wAjUNaQUv4gE/zByuHXufKRr45JHkGTHRaCIQzNY2QblIsI+n3FK8Kt7Kk3mxH39Cp9VURgU7mo0Oe5QcbEkoSD9/zoIvIhWKpFYu4XR8IHo/5PhCteAAYdeMKw4Eytv3e4yummnv3n/Eia2JNYspZglzHI4chDgjhh1lGGZiP6MKmwMWppGg/pgK8fZEBMho5xWNgUrDd x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR12MB4136.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(122000001)(54906003)(83380400001)(38100700002)(64756008)(966005)(508600001)(52536014)(8936002)(8676002)(316002)(76116006)(66556008)(66446008)(66946007)(66476007)(71200400001)(5660300002)(4326008)(110136005)(33656002)(6506007)(186003)(26005)(2906002)(7696005)(38070700005)(53546011)(55016003)(86362001)(9686003)(213903007);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?q1SbmoDr4LkfWmUcWXqsJ6S6pIsxhGC9Z68TFcMJgPFNq1aXoLKXN31+KCkp?= =?us-ascii?Q?PqYe5NGsnMIYZzaZFmfsD/SdNG1df0uQKO2JtwETd4M9Ngu0j2RNt/roLBBt?= =?us-ascii?Q?tIdIq1OY2UNccuMZUlnNqBgkZ11bKUIDPN8olzCBTiaRbi49/vtsywHM555g?= =?us-ascii?Q?+qPp0KfSQfyxwwSBurutIe6CGj6rwXPQVnkBWoCI1IhNpgbmtfQMPjAL6oud?= =?us-ascii?Q?/ZmS+Ap7FonbZNjZ5FgUqscG5XczPck37U3A+a5YnWSbbAP5VGEVqslfJXc0?= =?us-ascii?Q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90kia8dnuAEitKMCge?= =?us-ascii?Q?v4KxpAeUuKnl0uaTYhHe59Z5+M9AwUxrQYR0wQIFsUcAR1ZMzalAYm/ttRXX?= =?us-ascii?Q?AcKg10syq3rsZ4mKWl3/8QUnx9V434YRIRhgK1xvm/NXayasRb7GgT8sTjoE?= =?us-ascii?Q?2GF14TnCrPBVPyvWG9MAAZgBVdpZxiZuTju3F+kqAqmyCLJ5r+9LDaEd8kEJ?= =?us-ascii?Q?17q+apeINErRhAiC4w5fheI/811epuXs7RzUzg4hsbvxh/JWYDRQMWqQlVr9?= =?us-ascii?Q?Q3T/84YTqBU/bfsOmfIvpPU1/pQn0SQv1+OZQbeXveNw7aiMwKDsBWxhhnAw?= =?us-ascii?Q?3+RQYPvskwGmStJwzaAsoHFEpz2BVelEHkHpoK2lbAc87J7JvDGA1hv0WrxY?= =?us-ascii?Q?JcSLLdw1LZyQGYpUc8CU7ayMaPNmTNyFfHvhPud48M+w9VAL6r8vYFzL3tjK?= =?us-ascii?Q?zNxCa9wfLEP+4snB26pQNEw=3D?= MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4136.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a34da8d-4bf4-4e42-7bc3-08d9fccf31aa X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2022 04:35:07.0385 (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: iEctwSPl86g26zcj/9UHaNMdUPgl3SX/UMhhjR1xb+G9YZqAAWNioHR+p0KIwmyEk/+Tv1VxU5iTSs5B3EInBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4857 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Any thoughts on this patch, now that the stable tag is out? > -----Original Message----- > From: Ni, Ray > Sent: Tuesday, February 15, 2022 11:52 PM > To: Sindhu, Deepthi > Cc: Wu, Hao A ; Jeff Brasen ; > devel@edk2.groups.io > Subject: RE: [edk2-devel] [PATCH v2] > MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow partial FreeBuffer >=20 > External email: Use caution opening links or attachments >=20 >=20 > Deepthi, > Can you please help to review the changes and provide comments? >=20 > Thanks, > Ray >=20 > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Jeff > Brasen via groups.io > Sent: Tuesday, February 15, 2022 2:46 AM > To: devel@edk2.groups.io > Cc: Wu, Hao A ; Ni, Ray ; Jeff > Brasen > Subject: [edk2-devel] [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 >=20 >=20 >=20 >=20 >=20