From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x22a.google.com (mail-wm0-x22a.google.com [IPv6:2a00:1450:400c:c09::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CD9658034D for ; Tue, 7 Mar 2017 08:42:35 -0800 (PST) Received: by mail-wm0-x22a.google.com with SMTP id 196so25448115wmm.1 for ; Tue, 07 Mar 2017 08:42:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=6vHVBivOtCQOlsJgoTtRVAXoceJRhF8gOdUwuk7Coqc=; b=WLqLkm+PaqiDjPejMOfx21gfzMnAQzAg5yHaRFf+oOIUGspz/BJDhoG/eWz+LSqCKC NdD+2b46HFaTvtPg5sI6G6wARXun4vG/YZN59tdU9XqUKlcanGLSPO7oTPgD/yfX/+u1 SkQyx8dqHwHbHBk9xggWyp+cRmoiqnHH2bevI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=6vHVBivOtCQOlsJgoTtRVAXoceJRhF8gOdUwuk7Coqc=; b=pYWM6ep/TL8ikB2NzY4KUuXwhPVz8f2Jr0BraPKZooeR8wUzo+Uui+6WywBwseZP6i +P8494gzFWCwyvz+bXsnOre/xIVBVor0Bsz2vgyKN1q02S9XjqdBznTz5ffuF/AL0rGj wAx6FKr8SNZziMypx7ml4BHglU3dex5fYxwj8EKJWqJ1g6h9YCyOkhn1cpluUULj2zJg 14sHuTiWEQPs8/46p0/r9RdotaeWpy6z64D5cITYPdyxScAuT19PPF8Nqb4ZsKo9OJuH STCxXSGykiPc97N81A1fLT9arTSRrbWMU4lmYxx8v432g880bKs1UEjbWQPUTxx/Yzpd tedw== X-Gm-Message-State: AMke39mLQJ28bfr/AuLSPSENbCMfxe0B0oPjPca3Dl4ei/rqIxAuyjz5m+DzudoQj+h4ZU9z X-Received: by 10.28.109.147 with SMTP id b19mr19947822wmi.69.1488904954121; Tue, 07 Mar 2017 08:42:34 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id j184sm19687465wmd.31.2017.03.07.08.42.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Mar 2017 08:42:33 -0800 (PST) Date: Tue, 7 Mar 2017 16:42:31 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org Message-ID: <20170307164231.GU16034@bivouac.eciton.net> References: <1488283992-32104-1-git-send-email-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <1488283992-32104-1-git-send-email-ard.biesheuvel@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [PATCH 1/3] ArmPkg/UncachedMemoryAllocationLib: restore mapping attributes after free X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Mar 2017 16:42:36 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 Reviewed-by: Leif Lindholm > --- > 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 >