From patchwork Mon Dec 22 19:08:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 42546 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 45D2C25BA1 for ; Mon, 22 Dec 2014 19:14:49 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf3274367eek.9 for ; Mon, 22 Dec 2014 11:14:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=4JxNdJJyvgWKsecJVvdkIvdEUg3Aoe5Mp1lFeSUvbGI=; b=f+xBjgunVRCw0qn3scazyR4YAW9ZHDLM4qcLEJb/Cz3dgsrKq5D4MFZFxy/1MRey1q lEsF2+3WCDjhbZmuA39/XIP8veZ2bIoIbzJo2Aq5/wY4GpqM9KOhZHh/pENHsCx/Y1/r 0YYkOI+QqrQC+Jwo+PtK1/KCG3MogAebONULC6weZJl7niX/E5bzSrh8z57utIcEPjsz pbYLxpB2iYDvesUDLVIh2aNN84vf4g+m6aXM5fBIYYBfKLx9xFbIVC6eSATvdBRVCcl9 JTwVc251ZIAZ0wAYTmF/ZBE8Oyxt0CksVkc0wDkS6ojrxrVPHGd7UotZS7zj+a4KKp+3 gFpA== X-Gm-Message-State: ALoCoQkZYNrk1WjQXMgNBH/Tob9UMBsjOYc/TxxBc+DU1RTJzUcMv78+Ovo7IboOYW8LMMlPrW6j X-Received: by 10.152.2.40 with SMTP id 8mr418703lar.7.1419275688380; Mon, 22 Dec 2014 11:14:48 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.99 with SMTP id s3ls1352623lag.79.gmail; Mon, 22 Dec 2014 11:14:48 -0800 (PST) X-Received: by 10.112.135.6 with SMTP id po6mr23577041lbb.69.1419275688236; Mon, 22 Dec 2014 11:14:48 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id n3si10853485laj.50.2014.12.22.11.14.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Dec 2014 11:14:48 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by mail-la0-f53.google.com with SMTP id gm9so4370791lab.40 for ; Mon, 22 Dec 2014 11:14:48 -0800 (PST) X-Received: by 10.112.64.35 with SMTP id l3mr4345062lbs.82.1419275688093; Mon, 22 Dec 2014 11:14:48 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp1119303lbb; Mon, 22 Dec 2014 11:14:46 -0800 (PST) X-Received: by 10.66.66.42 with SMTP id c10mr38566272pat.4.1419275685081; Mon, 22 Dec 2014 11:14:45 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id tt9si26444982pac.51.2014.12.22.11.14.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Dec 2014 11:14:45 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; 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 1Y38PJ-0000o2-Ee; Mon, 22 Dec 2014 19:12:41 +0000 Received: from mail-wg0-f45.google.com ([74.125.82.45]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Y38MW-0006TA-TF for linux-arm-kernel@lists.infradead.org; Mon, 22 Dec 2014 19:09:50 +0000 Received: by mail-wg0-f45.google.com with SMTP id b13so7389394wgh.32 for ; Mon, 22 Dec 2014 11:09:27 -0800 (PST) X-Received: by 10.181.12.17 with SMTP id em17mr34270577wid.45.1419275366691; Mon, 22 Dec 2014 11:09:26 -0800 (PST) Received: from ards-macbook-pro.local ([41.248.55.245]) by mx.google.com with ESMTPSA id t6sm24758726wjf.49.2014.12.22.11.09.22 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Dec 2014 11:09:26 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, leif.lindholm@linaro.org, roy.franz@linaro.org, mark.rutland@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, matt.fleming@intel.com, bp@alien8.de, dyoung@redhat.com, msalter@redhat.com, grant.likely@linaro.org Subject: [PATCH 7/8] arm64: use 'physmem' memblock to improve CONFIG_STRICT_DEVMEM handling Date: Mon, 22 Dec 2014 19:08:41 +0000 Message-Id: <1419275322-29811-8-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1419275322-29811-1-git-send-email-ard.biesheuvel@linaro.org> References: <1419275322-29811-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141222_110949_117128_8E20AA16 X-CRM114-Status: GOOD ( 15.47 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.45 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.45 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 The 'physmem' memblock table allows us to classify memory as RAM even if it is not covered by the ordinary 'memory' memblock table. Under CONFIG_STRICT_DEVMEM, we can use this to: - allow read-only access to parts of RAM that are not considered memory by the kernel, this is mainly intended for exposing UEFI configuration tables such as SMBIOS to userland; - avoid using non-cached mappings for those parts of RAM, as it may result in mismatched attributes. Signed-off-by: Ard Biesheuvel --- arch/arm64/Kconfig | 1 + arch/arm64/mm/mmap.c | 2 +- arch/arm64/mm/mmu.c | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index b1f9a20a3677..86902f8d8e36 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -60,6 +60,7 @@ config ARM64 select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_MEMBLOCK + select HAVE_MEMBLOCK_PHYS_MAP select HAVE_PATA_PLATFORM select HAVE_PERF_EVENTS select HAVE_PERF_REGS diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index 54922d1275b8..9f558ab41f39 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -126,7 +126,7 @@ int devmem_is_allowed(unsigned long pfn) { if (iomem_is_exclusive(pfn << PAGE_SHIFT)) return 0; - if (!page_is_ram(pfn)) + if (!pfn_valid(pfn)) return 1; return 0; } diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 328638548871..083be3de1a87 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -122,7 +122,7 @@ early_param("cachepolicy", early_cachepolicy); pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, unsigned long size, pgprot_t vma_prot) { - if (!pfn_valid(pfn)) + if (!memblock_is_physmem(PFN_PHYS(pfn))) return pgprot_noncached(vma_prot); else if (file->f_flags & O_SYNC) return pgprot_writecombine(vma_prot); @@ -130,6 +130,19 @@ pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, } EXPORT_SYMBOL(phys_mem_access_prot); +/* + * This definition of phys_mem_access_prot_allowed() overrides + * the __weak definition in drivers/char/mem.c + */ +int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn, + unsigned long size, pgprot_t *prot) +{ + /* Disallow read-write access to system RAM */ + if (memblock_is_physmem(PFN_PHYS(pfn)) && pgprot_val(*prot) & PTE_WRITE) + return 0; + return 1; +} + static void __init *early_alloc(unsigned long sz) { void *ptr = __va(memblock_alloc(sz, sz));