From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x22e.google.com (mail-wm0-x22e.google.com [IPv6:2a00:1450:400c:c09::22e]) (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 2A76D81F28 for ; Tue, 28 Feb 2017 04:13:22 -0800 (PST) Received: by mail-wm0-x22e.google.com with SMTP id v77so83522059wmv.1 for ; Tue, 28 Feb 2017 04:13:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=4FYdnnIfbLPnBGy02WKAl72gEX2CkYEq0HkgAsCN6bs=; b=R5V17kPG8EKrCFzBmN3ZKyAt75vLT7surlv3r97tIwANJrG/HZZJN2PzK9ifa5NOV+ cUMINxdw9jxp2awaCJmZSXAsAc1u1Bi0xwwx/EBXWOAU0rYurPwK1RqLfbEWd3RIVv8k AO7PBSlAiGMyEPT3PS2P22xP0ErlP5fRVddUA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4FYdnnIfbLPnBGy02WKAl72gEX2CkYEq0HkgAsCN6bs=; b=pQN1ME80fwxMkH8vmatD/TJwqXovw2TNG/Y7KW76qvIju+CbxeVsI6nA4Jg9mRJF/K qBR2D5xXKhPZ5EfXiFhRUOaizlXYfcJeVJc8OnxvuHGTEFdzoJI0InnSZWcCLsCAPd/B Lv2z3NSh52wr/5uYlUp0I+giu0GgUFbQRUXx7iKeIYMHXYgs+tB6fVNiiADYuMS1jrI3 WJVCcWhhMntiC5TbWkcokBb9zo8oxGGR2U13e8aU3olud5TkX39cwczrLa6hEj+L7oPn DbDXpO2tmhnegR4rMI4RcHEY8i8efCBWQ6D5bIWZ+dR2lzxO+NM0ZtmQXRj7I6AKibcc TJYA== X-Gm-Message-State: AMke39mkOid7JuExAx7l0+wdkduys14g+AvD7kDKp9WfBd2whk2TW5RwIRT0w4I2zeCW1r3a X-Received: by 10.28.210.139 with SMTP id j133mr17657022wmg.67.1488284000242; Tue, 28 Feb 2017 04:13:20 -0800 (PST) Received: from localhost.localdomain ([105.149.201.216]) by smtp.gmail.com with ESMTPSA id x193sm2403690wme.23.2017.02.28.04.13.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Feb 2017 04:13:19 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Cc: Ard Biesheuvel Date: Tue, 28 Feb 2017 12:13:10 +0000 Message-Id: <1488283992-32104-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [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, 28 Feb 2017 12:13:22 -0000 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 --- 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