From patchwork Tue Feb 28 12:13:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 94608 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1291447qgi; Tue, 28 Feb 2017 04:13:24 -0800 (PST) X-Received: by 10.99.122.71 with SMTP id j7mr2276470pgn.52.1488284004871; Tue, 28 Feb 2017 04:13:24 -0800 (PST) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id w28si1620524pfk.112.2017.02.28.04.13.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 04:13:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 460D581F3A; Tue, 28 Feb 2017 04:13:24 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org 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 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: [edk2] [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: , Cc: Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm 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); }