public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@linaro.org>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: edk2-devel@lists.01.org
Subject: Re: [PATCH 1/3] ArmPkg/UncachedMemoryAllocationLib: restore mapping attributes after free
Date: Tue, 7 Mar 2017 16:42:31 +0000	[thread overview]
Message-ID: <20170307164231.GU16034@bivouac.eciton.net> (raw)
In-Reply-To: <1488283992-32104-1-git-send-email-ard.biesheuvel@linaro.org>

On Tue, Feb 28, 2017 at 12:13:10PM +0000, Ard Biesheuvel wrote:
> In order to play nice with platforms that use strict memory permission
> policies, restore the original mapping attributes when freeing uncached
> allocations.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

> ---
>  ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c b/ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c
> index f6c692f9a403..cd13a7da92e0 100644
> --- a/ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c
> +++ b/ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c
> @@ -42,11 +42,6 @@ UncachedInternalAllocateAlignedPages (
>  
>  
>  
> -//
> -// Assume all of memory has the same cache attributes, unless we do our magic
> -//
> -UINT64  gAttributes;
> -
>  typedef struct {
>    EFI_PHYSICAL_ADDRESS  Base;
>    VOID                  *Allocation;
> @@ -54,6 +49,7 @@ typedef struct {
>    EFI_MEMORY_TYPE       MemoryType;
>    BOOLEAN               Allocated;
>    LIST_ENTRY            Link;
> +  UINT64                Attributes;
>  } FREE_PAGE_NODE;
>  
>  STATIC LIST_ENTRY  mPageList = INITIALIZE_LIST_HEAD_VARIABLE (mPageList);
> @@ -153,10 +149,7 @@ AllocatePagesFromList (
>    }
>  
>    Status = gDS->GetMemorySpaceDescriptor (Memory, &Descriptor);
> -  if (!EFI_ERROR (Status)) {
> -    // We are making an assumption that all of memory has the same default attributes
> -    gAttributes = Descriptor.Attributes;
> -  } else {
> +  if (EFI_ERROR (Status)) {
>      gBS->FreePages (Memory, Pages);
>      return Status;
>    }
> @@ -181,6 +174,7 @@ AllocatePagesFromList (
>    NewNode->Pages      = Pages;
>    NewNode->Allocated  = TRUE;
>    NewNode->MemoryType = MemoryType;
> +  NewNode->Attributes = Descriptor.Attributes;
>  
>    InsertTailList (&mPageList, &NewNode->Link);
>  
> @@ -266,6 +260,10 @@ UncachedMemoryAllocationLibDestructor (
>      // We only free the non-allocated buffer
>      if (OldNode->Allocated == FALSE) {
>        gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base, OldNode->Pages);
> +
> +      gDS->SetMemorySpaceAttributes ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base,
> +             EFI_PAGES_TO_SIZE (OldNode->Pages), OldNode->Attributes);
> +
>        RemoveEntryList (&OldNode->Link);
>        FreePool (OldNode);
>      }
> -- 
> 2.7.4
> 


      parent reply	other threads:[~2017-03-07 16:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-28 12:13 [PATCH 1/3] ArmPkg/UncachedMemoryAllocationLib: restore mapping attributes after free Ard Biesheuvel
2017-02-28 12:13 ` [PATCH 2/3] ArmPkg/UncachedMemoryAllocationLib: use CWG value to align pool allocations Ard Biesheuvel
2017-03-07 16:49   ` Leif Lindholm
2017-02-28 12:13 ` [PATCH 3/3] ArmPkg/UncachedMemoryAllocationLib: map uncached allocations non-executable Ard Biesheuvel
2017-03-07 16:49   ` Leif Lindholm
2017-03-07 16:42 ` Leif Lindholm [this message]

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=20170307164231.GU16034@bivouac.eciton.net \
    --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