From patchwork Tue Nov 18 12:57:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 41018 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 01BBC241C9 for ; Tue, 18 Nov 2014 13:00:27 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id ex7sf4553196wid.3 for ; Tue, 18 Nov 2014 05:00:26 -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:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=tvSmwGS57pHNUaolEUobaksjjWa/mJbF2OtKyztj4og=; b=lmKCrrqURE/kFXhAWT/bRKZudBWxPiUEhMOBvrZORYDSf1ZypykBDVgB7aWbZlLHTx og1hqeQZCv6IoY4ICDl13vc4cAD6pTh1jhZL+iRetcruvx5+XuCQSq8W4Zh57k9jiHeV dOxe5nnmwGKacOB9EsKApuQXJpDjtd8y333DE7j4Lz0Y3qdPaW+Z8KI3ZwF3dA2yIVEk nWLvEEXOPzbnvxEKfZS32SszLcQjAwHXSH3RvGcUnznHiucIY7NiQwwbtLytYlTV63OC 51hQYPxoX694vs0Gdkms1SfyzBFrx3URwTqOSsEKsOavJ6943Pfil3/qqxey+Vfb0fdg xhgg== X-Gm-Message-State: ALoCoQm9J7AD/N+KLMHXByYpAUWn2cAfQWPVIEl5LTUWWKFn8NXOtFzbb7mMTFjTNKabhEXU5kk5 X-Received: by 10.112.119.194 with SMTP id kw2mr323861lbb.16.1416315625979; Tue, 18 Nov 2014 05:00:25 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.205 with SMTP id ba13ls1358102lab.33.gmail; Tue, 18 Nov 2014 05:00:25 -0800 (PST) X-Received: by 10.152.87.18 with SMTP id t18mr36213210laz.0.1416315625748; Tue, 18 Nov 2014 05:00:25 -0800 (PST) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id d3si55754374lbc.14.2014.11.18.05.00.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 05:00:25 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by mail-la0-f41.google.com with SMTP id gf13so8248083lab.28 for ; Tue, 18 Nov 2014 05:00:25 -0800 (PST) X-Received: by 10.153.7.170 with SMTP id dd10mr35755337lad.44.1416315625662; Tue, 18 Nov 2014 05:00:25 -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.184.201 with SMTP id ew9csp1322963lbc; Tue, 18 Nov 2014 05:00:24 -0800 (PST) X-Received: by 10.66.66.42 with SMTP id c10mr17024284pat.4.1416315619661; Tue, 18 Nov 2014 05:00:19 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id cc14si37998185pac.137.2014.11.18.05.00.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Nov 2014 05:00:19 -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 1XqiMt-00034o-8P; Tue, 18 Nov 2014 12:58:51 +0000 Received: from mail-wg0-f44.google.com ([74.125.82.44]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XqiLm-0002QK-6R for linux-arm-kernel@lists.infradead.org; Tue, 18 Nov 2014 12:57:43 +0000 Received: by mail-wg0-f44.google.com with SMTP id b13so1093123wgh.31 for ; Tue, 18 Nov 2014 04:57:18 -0800 (PST) X-Received: by 10.194.9.1 with SMTP id v1mr3505376wja.124.1416315438182; Tue, 18 Nov 2014 04:57:18 -0800 (PST) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id cz3sm55726799wjb.23.2014.11.18.04.57.16 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 04:57:17 -0800 (PST) From: Ard Biesheuvel To: leif.lindholm@linaro.org, roy.franz@linaro.org, linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com, msalter@redhat.com, dyoung@redhat.com, linux-efi@vger.kernel.org, matt.fleming@intel.com, will.deacon@arm.com, catalin.marinas@arm.com, grant.likely@linaro.org, geoff.levand@linaro.org Subject: [PATCH v3 03/13] arm64: improve CONFIG_STRICT_DEVMEM handling Date: Tue, 18 Nov 2014 13:57:02 +0100 Message-Id: <1416315432-8534-4-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1416315432-8534-1-git-send-email-ard.biesheuvel@linaro.org> References: <1416315432-8534-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141118_045742_460144_C4C9B762 X-CRM114-Status: GOOD ( 13.69 ) 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.44 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.44 listed in wl.mailspike.net] -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.41 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 Improve the handling of /dev/mem mappings under CONFIG_STRICT_DEVMEM by: - allowing read-only access to parts of System RAM that are not considered memory by the kernel, this is mainly intended for exposing UEFI Configuration tables to userland; - avoid using non-cached mappings for those parts of System RAM, as it may result in mismatched attributes. Signed-off-by: Ard Biesheuvel --- arch/arm64/mm/mmap.c | 5 +++-- arch/arm64/mm/mmu.c | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index 1d73662f00ff..802cdf0df921 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -127,14 +127,15 @@ int valid_mmap_phys_addr_range(unsigned long pfn, size_t size) /* * devmem_is_allowed() checks to see if /dev/mem access to a certain address * is valid. The argument is a physical page number. We mimic x86 here by - * disallowing access to system RAM as well as device-exclusive MMIO regions. + * disallowing access to system RAM that is in active use by the kernel, as + * well as device-exclusive MMIO regions. * This effectively disable read()/write() on /dev/mem. */ 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 4d583aa9ff4e..93ba10838359 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -121,7 +121,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 (!page_is_ram(pfn)) return pgprot_noncached(vma_prot); else if (file->f_flags & O_SYNC) return pgprot_writecombine(vma_prot); @@ -129,6 +129,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 reserved system RAM */ + if ((pgprot_val(*prot) & PTE_WRITE) && page_is_ram(pfn)) + return 0; + return 1; +} + static void __init *early_alloc(unsigned long sz) { void *ptr = __va(memblock_alloc(sz, sz));