From patchwork Thu Oct 29 13:40:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 55770 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp573106lbr; Thu, 29 Oct 2015 06:42:56 -0700 (PDT) X-Received: by 10.107.134.198 with SMTP id q67mr3670653ioi.90.1446126175963; Thu, 29 Oct 2015 06:42:55 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id x4si3150269igr.34.2015.10.29.06.42.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Oct 2015 06:42:55 -0700 (PDT) Received-SPF: pass (google.com: 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; spf=pass (google.com: 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; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZrnSP-0006rg-05; Thu, 29 Oct 2015 13:41:33 +0000 Received: from mail-wi0-x234.google.com ([2a00:1450:400c:c05::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZrnSL-0006ol-F8 for linux-arm-kernel@lists.infradead.org; Thu, 29 Oct 2015 13:41:30 +0000 Received: by wicfv8 with SMTP id fv8so43336517wic.0 for ; Thu, 29 Oct 2015 06:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=13Fi09aNn1SbilSQFjQn+8/fDBY9HIyebsbpiyfxfGY=; b=kYVLr6BE4z3KvFIGhRwnsW3Mb8++AYRtSJAHmH7QVGJQyBAxcGAEcp2Bisk2DCa/qP p0iQnNJiQqcy0DV1N9w2+7lnI6NLvKK+C0WVYanFvezO3LwZgpbo0AlK6qkw/FJ/5YYe A1AOq2nCWtQ7YK7bg2Bie/r7mv+sUwfFbn6Wzp1/rL2BhJPLWgVoz/RbPEtpL01NGCy0 +AAI7kpVezKDh+CgwJJBspdJgzsue/YvdLkRO0qZgzJbE3z6GRIMAq1bXBWxRPpYDByG oDPR0EtxUxMXrtMR81A2OL76ZSpYlW8KEyCL9ZHD42G41fwqCA3KeC7Qy9yO72oa+bMH yeIQ== 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:in-reply-to :references; bh=13Fi09aNn1SbilSQFjQn+8/fDBY9HIyebsbpiyfxfGY=; b=NHkxSjfg3Dhp2r5K02M6yl/hsJrLdiLkKaCSCcwUDp1SVRnPq8MF760rN0Ei1B0cz1 cY7WZT7webiU10PMcH1nqHAabzv1VmxEpcygfGm0H2WO0fcr2Ag3FEE1Rk/7xwGlOFwK x3L1uicsDE+A2fFUkhBZfSroxPvKNNB/syY/S0SRwXSnUL9PcOUrtMd7rIaK4XwH+SQB JhlwgyPVqn+AGY1jkw2K3YR1Flavx+DabBokVgCd1O3si6JyvOTuIGBPWd8s4VyVssQU DpQyti+VEfp0BhX43+nmvmXmEPOKZ1XUh3fEU0askzia4heV7VVbwIvvmM6YajIHmf2G 1ECg== X-Gm-Message-State: ALoCoQnyB+9RdtOK+2NV1fsmFGQFQMH91guKIb71GzBB212xxdlsuGIB47CHt+MuQ+jlzSrB2B4W X-Received: by 10.194.142.166 with SMTP id rx6mr2393777wjb.54.1446126068119; Thu, 29 Oct 2015 06:41:08 -0700 (PDT) Received: from jessie.localdomain ([85.119.43.29]) by smtp.gmail.com with ESMTPSA id p75sm3578918wmd.22.2015.10.29.06.41.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Oct 2015 06:41:07 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, leif.lindholm@linaro.org, mark.rutland@arm.com, will.deacon@arm.com Subject: [PATCH 2/3] arm64: reimplement page_is_ram() using memblock and UEFI memory map Date: Thu, 29 Oct 2015 14:40:58 +0100 Message-Id: <1446126059-25336-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1446126059-25336-1-git-send-email-ard.biesheuvel@linaro.org> References: <1446126059-25336-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151029_064129_709475_C3AA53EC X-CRM114-Status: GOOD ( 17.27 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c05:0:0:0:234 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: matt@codeblueprint.co.uk, catalin.marinas@arm.com, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org This patch overrides the __weak default implementation of page_is_ram(), which uses string comparisons to find entries called 'System RAM' in /proc/iomem. Since we used the contents of memblock to create those entries in the first place, let's use memblock directly. Also, since the UEFI memory map may describe regions backed by RAM that are not in memblock (i.e., reserved regions that were removed from the linear mapping), check the pfn against the UEFI memory map as well. Signed-off-by: Ard Biesheuvel --- arch/arm64/mm/mmu.c | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) -- 2.1.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index c2fa6b56613c..737bfaecb489 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include +#include #include #include #include @@ -743,3 +745,35 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys) return dt_virt; } + +/* + * On a UEFI system, the memory map may describe regions that are backed by + * memory, but are not covered by the linear mapping and so are not listed as + * 'System RAM' in /proc/iomem, which is what the default __weak implementation + * of page_is_ram looks for. So check the UEFI memory map as well if the pfn is + * not covered by memblock. + */ +int page_is_ram(unsigned long pfn) +{ + u64 addr = PFN_PHYS(pfn); + efi_memory_desc_t *md; + + if (memblock_is_memory(addr)) + return 1; + + if (!efi_enabled(EFI_MEMMAP)) + return 0; + + /* + * A pfn could intersect multiple regions in the UEFI memory map if the + * OS page size exceeds 4 KB. However, the UEFI spec explicitly forbids + * mixed attribute mappings within the same 64 KB page frame so just use + * the region that intersects the page address. + */ + for_each_efi_memory_desc(&memmap, md) + if (md->phys_addr <= addr && + (addr - md->phys_addr) < (md->num_pages << EFI_PAGE_SHIFT)) + return !!(md->attribute & EFI_MEMORY_WB); + + return 0; +}