public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Jeff Brasen" <jbrasen@nvidia.com>
To: "Ni, Ray" <ray.ni@intel.com>,
	"Sindhu, Deepthi" <deepthi.sindhu@intel.com>
Cc: "Wu, Hao A" <hao.a.wu@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow partial FreeBuffer
Date: Thu, 3 Mar 2022 04:35:07 +0000	[thread overview]
Message-ID: <CH2PR12MB41365BCD93F3B2AF29C47424CB049@CH2PR12MB4136.namprd12.prod.outlook.com> (raw)
In-Reply-To: <MWHPR11MB1631E47DCC5F9623762502B38C359@MWHPR11MB1631.namprd11.prod.outlook.com>

Any thoughts on this patch, now that the stable tag is out?

> -----Original Message-----
> From: Ni, Ray <ray.ni@intel.com>
> Sent: Tuesday, February 15, 2022 11:52 PM
> To: Sindhu, Deepthi <deepthi.sindhu@intel.com>
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Jeff Brasen <jbrasen@nvidia.com>;
> devel@edk2.groups.io
> Subject: RE: [edk2-devel] [PATCH v2]
> MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow partial FreeBuffer
> 
> External email: Use caution opening links or attachments
> 
> 
> Deepthi,
> Can you please help to review the changes and provide comments?
> 
> Thanks,
> Ray
> 
> -----Original Message-----
> From: devel@edk2.groups.io <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 <hao.a.wu@intel.com>; Ni, Ray <ray.ni@intel.com>; Jeff
> Brasen <jbrasen@nvidia.com>
> Subject: [edk2-devel] [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 <jbrasen@nvidia.com>
> ---
>  .../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 != ALIGN_POINTER (HostAddress, EFI_PAGE_SIZE)) {
> +    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
> +    return EFI_INVALID_PARAMETER;
> +  }
> 
>    Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO (This);
> 
>    Found = FALSE;
>    Alloc = NULL;
> +  AllocHead = NULL;
> +  AllocTail = NULL;
> 
>    //
>    // Find the uncached allocation list entry associated @@ -976,9 +987,13 @@
> NonCoherentPciIoFreeBuffer (
>         Entry = Entry->ForwardLink)
>    {
>      Alloc = BASE_CR (Entry,
> NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION, List);
> -    if ((Alloc->HostAddress == HostAddress) && (Alloc->NumPages == Pages))
> {
> +    StartPages = 0;
> +    if (Alloc->HostAddress < HostAddress) {
> +      StartPages = (HostAddress - Alloc->HostAddress) / EFI_PAGE_SIZE;
> +    }
> +    if ((Alloc->HostAddress <= HostAddress) && (Alloc->NumPages >=
> + (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 = TRUE;
> @@ -991,7 +1006,41 @@ NonCoherentPciIoFreeBuffer (
>      return EFI_NOT_FOUND;
>    }
> 
> +  EndPages = Alloc->NumPages - (Pages + StartPages);
> +
> +  if (StartPages != 0) {
> +    AllocHead = AllocatePool (sizeof *AllocHead);
> +    if (AllocHead == NULL) {
> +      return EFI_OUT_OF_RESOURCES;
> +    }
> +
> +    AllocHead->HostAddress = Alloc->HostAddress;
> +    AllocHead->NumPages = StartPages;
> +    AllocHead->Attributes = Alloc->Attributes;  }
> +
> +  if (EndPages != 0) {
> +    AllocTail = AllocatePool (sizeof *AllocTail);
> +    if (AllocTail == NULL) {
> +      return EFI_OUT_OF_RESOURCES;
> +    }
> +
> +    AllocTail->HostAddress = Alloc->HostAddress + ((Pages + StartPages) *
> EFI_PAGE_SIZE);
> +    AllocTail->NumPages = EndPages;
> +    AllocTail->Attributes = 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 != NULL)
> + {
> +    InsertHeadList (&Dev->UncachedAllocationList, &AllocHead->List);  }
> + if (AllocTail != NULL) {
> +    InsertHeadList (&Dev->UncachedAllocationList, &AllocTail->List);  }
> 
>    Status = gDS->SetMemorySpaceAttributes (
>                    (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress,
> --
> 2.17.1
> 
> 
> 
> 
> 


  reply	other threads:[~2022-03-03  4:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-14 18:45 [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow partial FreeBuffer Jeff Brasen
2022-02-16  6:52 ` [edk2-devel] " Ni, Ray
2022-03-03  4:35   ` Jeff Brasen [this message]
2022-05-18  2:59     ` Jeff Brasen
2022-06-17 15:39 ` Jeff Brasen
2022-07-28 20:25   ` Jeff Brasen
2022-07-29 15:47     ` Ard Biesheuvel
2022-08-02 15:32       ` Jeff Brasen
2022-08-02 16:51         ` Ard Biesheuvel
2022-08-05 16:56           ` Jeff Brasen
2022-08-15 14:42             ` [edk2-devel] " Ard Biesheuvel
2022-09-08 15:39               ` Jeff Brasen
2022-09-08 15:54                 ` Ard Biesheuvel
2022-09-21 16:27                   ` Jeff Brasen
2022-09-21 16:31                     ` Ard Biesheuvel
2022-09-29 16:20                       ` Jeff Brasen
2022-09-30  1:32                         ` 回复: " gaoliming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CH2PR12MB41365BCD93F3B2AF29C47424CB049@CH2PR12MB4136.namprd12.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox