From patchwork Thu Aug 25 16:17:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 74693 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp923944qga; Thu, 25 Aug 2016 09:18:53 -0700 (PDT) X-Received: by 10.98.65.81 with SMTP id o78mr17769866pfa.48.1472141933933; Thu, 25 Aug 2016 09:18:53 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id xz3si16129621pab.244.2016.08.25.09.18.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Aug 2016 09:18:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; 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 linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bcxLi-000173-9V; Thu, 25 Aug 2016 16:17:50 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bcxLd-00014I-4M for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2016 16:17:46 +0000 Received: by mail-wm0-x229.google.com with SMTP id f65so245107332wmi.0 for ; Thu, 25 Aug 2016 09:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=tZZUXLuQD3cFTTOd8pgM/XUzyTMb5QkzYfkLDixLA58=; b=Cpe/YmTAY3zOZZbfjgxFZK7iB97lK+BZLTVU3Mjo7tMuDOhKnIAUPqOEfADnJ4JAWW q3tgxclVI/vYIvsOVKJ7Pi49kNjzO9d+cCiwDWueLyxqofwb0IFu042NR/FfdZE+uryg tzW4thr5d4zP7RygdkdYu7HA2LzYJe0TltDQM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=tZZUXLuQD3cFTTOd8pgM/XUzyTMb5QkzYfkLDixLA58=; b=bvLnhOg0ickLoGE9Vz0Ahu+b+0EpCln3ceiB7PjCdyOwpVWv9RZkvoho5nLG50eF2z NXcd/fGb4ZTZjUGder1yLqlzCFTvZjNykvmZZdLBJLUk6QIy10wB83mLhrpteh9NqyH6 LHdr0jFgL5EsvD87qJTnbUnSJXyKoYrW0YsKi/ib0Q6lR871+CokPLTg5ROKD7i75IMu zxTiecKe2YCgWV7UYVUdFfc5i9Krxh1KKLOG5BBWykdzva+Bm54dbhicv68C0CTFWrvz 7y4RzQUELAGRM/mdc5oloy2D+3XEb+VzMBPZ00aqIUL32w2e2Zem8ciFZzB3T2BwhGYz b+NA== X-Gm-Message-State: AEkooutQ4W1PSICrLsEsIWQvUmjSo96twy4DBhIbVIonLSZaVi9xEkN4nOLTfNwLPWDl4zD4 X-Received: by 10.194.81.137 with SMTP id a9mr9342314wjy.106.1472141842249; Thu, 25 Aug 2016 09:17:22 -0700 (PDT) Received: from localhost.localdomain (dynggepcrak-193-2-66-105.inwitelecom.net. [105.66.2.193]) by smtp.gmail.com with ESMTPSA id x203sm39434677wmg.0.2016.08.25.09.17.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Aug 2016 09:17:21 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, matt@codeblueprint.co.uk, james.morse@arm.com Subject: [PATCH v2] efi: arm64: treat regions with WT/WC set but WB cleared as memory Date: Thu, 25 Aug 2016 18:17:09 +0200 Message-Id: <1472141829-12026-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160825_091745_564943_D13EFFF4 X-CRM114-Status: GOOD ( 21.14 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:229 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, takahiro.akashi@linaro.org, lorenzo.pieralisi@arm.com, leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Currently, memory regions are only recorded in the memblock memory table if they have the EFI_MEMORY_WB memory type attribute set. In case the region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which will leave it out of the linear mapping. However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC attributes set, and the EFI_MEMORY_WB cleared, in which case the region in question is obviously backed by normal memory, but is not recorded in the memblock memory table at all. Since it would be useful to be able to identify any UEFI reported memory region using memblock_is_memory(), it makes sense to add all memory to the memblock memory table, and simply mark it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute. While implementing this, let's refactor the code slightly to make it easier to understand: replace is_normal_ram() with is_memory(), and make it return true for each region that has any of the WB|WT|WC bits set. (This follows the AArch64 bindings in the UEFI spec, which state that those are the attributes that map to normal memory) Also, replace is_reserve_region() with is_usable_memory(), and only invoke it if the region in question was identified as memory by is_memory() in the first place. The net result is the same (only reserved regions that are backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP flag set) but carried out in a more straightforward way. Finally, we remove the trailing asterisk in the EFI debug output. Keeping it clutters the code, and it serves no real purpose now that we no longer temporarily reserve BootServices code and data regions like we did in the early days of EFI support on arm64 Linux (which it inherited from the x86 implementation) Signed-off-by: Ard Biesheuvel --- v2: refactor is_normal_ram and is_reserve_region drop trailing asterisk in EFI debug output drivers/firmware/efi/arm-init.c | 32 +++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel Reviewed-by: Leif Lindholm diff --git a/drivers/firmware/efi/arm-init.c b/drivers/firmware/efi/arm-init.c index c49d50e68aee..c2ac5975fd5d 100644 --- a/drivers/firmware/efi/arm-init.c +++ b/drivers/firmware/efi/arm-init.c @@ -26,9 +26,9 @@ u64 efi_system_table; -static int __init is_normal_ram(efi_memory_desc_t *md) +static int __init is_memory(efi_memory_desc_t *md) { - if (md->attribute & EFI_MEMORY_WB) + if (md->attribute & (EFI_MEMORY_WB|EFI_MEMORY_WT|EFI_MEMORY_WC)) return 1; return 0; } @@ -152,9 +152,9 @@ out: } /* - * Return true for RAM regions we want to permanently reserve. + * Return true for regions that can be used as System RAM. */ -static __init int is_reserve_region(efi_memory_desc_t *md) +static __init int is_usable_memory(efi_memory_desc_t *md) { switch (md->type) { case EFI_LOADER_CODE: @@ -163,18 +163,22 @@ static __init int is_reserve_region(efi_memory_desc_t *md) case EFI_BOOT_SERVICES_DATA: case EFI_CONVENTIONAL_MEMORY: case EFI_PERSISTENT_MEMORY: - return 0; + /* + * According to the spec, these regions are no longer reserved + * after calling ExitBootServices(). However, we can only use + * them as System RAM if they can be mapped writeback cacheable. + */ + return (md->attribute & EFI_MEMORY_WB); default: break; } - return is_normal_ram(md); + return false; } static __init void reserve_regions(void) { efi_memory_desc_t *md; u64 paddr, npages, size; - int resv; if (efi_enabled(EFI_DBG)) pr_info("Processing EFI memory map:\n"); @@ -191,25 +195,23 @@ static __init void reserve_regions(void) paddr = md->phys_addr; npages = md->num_pages; - resv = is_reserve_region(md); if (efi_enabled(EFI_DBG)) { char buf[64]; - pr_info(" 0x%012llx-0x%012llx %s%s\n", + pr_info(" 0x%012llx-0x%012llx %s\n", paddr, paddr + (npages << EFI_PAGE_SHIFT) - 1, - efi_md_typeattr_format(buf, sizeof(buf), md), - resv ? "*" : ""); + efi_md_typeattr_format(buf, sizeof(buf), md)); } memrange_efi_to_native(&paddr, &npages); size = npages << PAGE_SHIFT; - if (is_normal_ram(md)) + if (is_memory(md)) { early_init_dt_add_memory_arch(paddr, size); - if (resv) - memblock_mark_nomap(paddr, size); - + if (!is_usable_memory(md)) + memblock_mark_nomap(paddr, size); + } } set_bit(EFI_MEMMAP, &efi.flags);