From patchwork Thu Nov 6 14:13:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 40293 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 73B0124237 for ; Thu, 6 Nov 2014 14:17:27 +0000 (UTC) Received: by mail-la0-f69.google.com with SMTP id q1sf1810669lam.8 for ; Thu, 06 Nov 2014 06:17: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=PGcAtrGz65+8q7GvOQUrI/izbLsQcDzUByL0FSVZiKQ=; b=PPKo+Qkh9KZucl8UArWOxWeEu5iB73yE/Ycr8p4l9i8eXW6SpAPcc8csnHp/MQFf8r pZitd37DpUJl9EGAGT3s4dysE2D51A5PcvQjha8d+95Lquo9oY+w6djOF/ih7pYLZYjj I89DGek4vCa9a0w6aep4ore5XRvTFkmObQlm77P98X1EqwxIPJ0WfeXnEWoPf4S2lFPw OVPdAtavWGyRRjLlLdgxCJEC8OA0nx7OQhmZCn8RMNU9KvGAdxNmPz1IPIO9JbOcq0rX s5BYkg7McGlDRZ75hBmLOEUmWT62kTuH7Rt+iG89Eohdq2lVeQV4ZCyVpeHptf4cJ+Vd 70uA== X-Gm-Message-State: ALoCoQn5IWwyCK9VcczYTEF/EG5ccWdYQM5V/bWaiFDv2QxLi3Re9nDgpj1Itp+jFxklfDTYDWgT X-Received: by 10.180.90.234 with SMTP id bz10mr4106870wib.0.1415283446437; Thu, 06 Nov 2014 06:17:26 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.41 with SMTP id q9ls74008lag.67.gmail; Thu, 06 Nov 2014 06:17:26 -0800 (PST) X-Received: by 10.152.8.100 with SMTP id q4mr5233384laa.48.1415283446158; Thu, 06 Nov 2014 06:17:26 -0800 (PST) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id s10si11678166lal.38.2014.11.06.06.17.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Nov 2014 06:17:26 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by mail-lb0-f175.google.com with SMTP id n15so979792lbi.34 for ; Thu, 06 Nov 2014 06:17:26 -0800 (PST) X-Received: by 10.112.52.37 with SMTP id q5mr5335852lbo.32.1415283446083; Thu, 06 Nov 2014 06:17:26 -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 ew9csp50040lbc; Thu, 6 Nov 2014 06:17:25 -0800 (PST) X-Received: by 10.70.55.40 with SMTP id o8mr4520511pdp.87.1415283444390; Thu, 06 Nov 2014 06:17:24 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id bp17si6091589pdb.37.2014.11.06.06.17.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Nov 2014 06:17:24 -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 1XmNqq-00077y-TX; Thu, 06 Nov 2014 14:15:52 +0000 Received: from mail-wi0-f181.google.com ([209.85.212.181]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XmNpc-0005Ca-8T for linux-arm-kernel@lists.infradead.org; Thu, 06 Nov 2014 14:14:36 +0000 Received: by mail-wi0-f181.google.com with SMTP id n3so1625808wiv.2 for ; Thu, 06 Nov 2014 06:14:14 -0800 (PST) X-Received: by 10.180.103.233 with SMTP id fz9mr40390776wib.80.1415283253685; Thu, 06 Nov 2014 06:14:13 -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 mw7sm8450413wib.14.2014.11.06.06.14.11 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Nov 2014 06:14:12 -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 Subject: [PATCH v2 10/10] arm64/efi: improve /dev/mem mmap() handling under UEFI Date: Thu, 6 Nov 2014 15:13:26 +0100 Message-Id: <1415283206-14713-11-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1415283206-14713-1-git-send-email-ard.biesheuvel@linaro.org> References: <1415283206-14713-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141106_061436_502227_AA554F40 X-CRM114-Status: GOOD ( 10.86 ) 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 [209.85.212.181 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.181 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.217.175 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 When booting via UEFI, we need to ensure that mappings of arbitrary physical ranges through /dev/mem do not violate architectural rules regarding conflicting cacheability attributes of overlapping regions. Also, when CONFIG_STRICT_DEVMEM is in effect, memory regions with special significance to UEFI should be protected sufficiently. Signed-off-by: Ard Biesheuvel --- arch/arm64/mm/mmu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 3e8b3732ca87..9ae3904f386c 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -28,6 +29,7 @@ #include #include +#include #include #include #include @@ -121,6 +123,8 @@ 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 (efi_enabled(EFI_MEMMAP) && efi_mem_access_prot(pfn, &vma_prot)) + return vma_prot; if (!pfn_valid(pfn)) return pgprot_noncached(vma_prot); else if (file->f_flags & O_SYNC) @@ -129,6 +133,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) +{ + if (efi_enabled(EFI_MEMMAP)) + return efi_mem_access_allowed(pfn, size, + pgprot_val(*prot) & PTE_WRITE); + return 1; +} + static void __init *early_alloc(unsigned long sz) { void *ptr = __va(memblock_alloc(sz, sz));