From patchwork Tue Nov 18 12:57:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 41016 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 34DB4241C9 for ; Tue, 18 Nov 2014 12:59:52 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id q1sf803714lam.1 for ; Tue, 18 Nov 2014 04:59:51 -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=7WticRJRaPDeLPJqMnfImNKROJArsywEgOKNE2w/IM4=; b=LXRrpy7NRSVa717JP9B9+4tFy6/TriGiM+XjGOh3scNUs8jTXmqWgZhEWBMo0A1bg1 IU4eO0ZCH6q/WYGAtdYjiT+y5X1NanIj/lMIrSBZBbAr8rDXqmyULhBQX1/UuiWNsvno WdySHibQpGR8e7pOIDg+KTKd6+Pxeu2UteepHQ+h4jKDfANheU8krJbPBGRIHGlcnHEQ BCIu48K/Ua/+gx0xrR54q/eZmwTvFY5bj6nrLec+znUHfH2+acZk3TW9T4MfpFsbo70H NMNvgDbFXr8qeh79+HkCN7rOT76T1Yvn3u9F1wrnx0ho1Ds/7Hmg4x8Brswyx5qirD4T 4i5w== X-Gm-Message-State: ALoCoQldCF9RZwK0NO1UPFVwseJewxSziKuo8OV04urq/usI+fvr3GGcfiJJ7hLf3peDVJtKLUQp X-Received: by 10.180.101.170 with SMTP id fh10mr5654334wib.4.1416315591116; Tue, 18 Nov 2014 04:59:51 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.30.5 with SMTP id o5ls215611lah.84.gmail; Tue, 18 Nov 2014 04:59:50 -0800 (PST) X-Received: by 10.112.146.162 with SMTP id td2mr30012799lbb.40.1416315590358; Tue, 18 Nov 2014 04:59:50 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id g2si55660283laf.43.2014.11.18.04.59.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 04:59:50 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id l4so17766482lbv.10 for ; Tue, 18 Nov 2014 04:59:49 -0800 (PST) X-Received: by 10.153.7.170 with SMTP id dd10mr35750767lad.44.1416315589927; Tue, 18 Nov 2014 04:59:49 -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 ew9csp1322863lbc; Tue, 18 Nov 2014 04:59:49 -0800 (PST) X-Received: by 10.70.88.101 with SMTP id bf5mr10888408pdb.148.1416315588328; Tue, 18 Nov 2014 04:59:48 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id hx9si37984639pad.168.2014.11.18.04.59.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Nov 2014 04:59:48 -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 1XqiMJ-0002mq-Me; Tue, 18 Nov 2014 12:58:15 +0000 Received: from mail-wi0-f180.google.com ([209.85.212.180]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XqiLm-0002SE-2S for linux-arm-kernel@lists.infradead.org; Tue, 18 Nov 2014 12:57:43 +0000 Received: by mail-wi0-f180.google.com with SMTP id n3so5132494wiv.1 for ; Tue, 18 Nov 2014 04:57:24 -0800 (PST) X-Received: by 10.194.189.81 with SMTP id gg17mr19833015wjc.115.1416315444548; Tue, 18 Nov 2014 04:57:24 -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.22 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 04:57:23 -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 06/13] efi: register iomem resources for UEFI reserved regions Date: Tue, 18 Nov 2014 13:57:05 +0100 Message-Id: <1416315432-8534-7-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_294089_67B5279B X-CRM114-Status: GOOD ( 12.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 [209.85.212.180 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.180 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.217.179 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 Register memory regions reserved by UEFI as IORESOURCE_MEM resources, so that they are reserved for other uses, and also makes them turn up in /proc/iomem. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/virtmap.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/firmware/efi/virtmap.c b/drivers/firmware/efi/virtmap.c index d1f1d416944f..98735fb43581 100644 --- a/drivers/firmware/efi/virtmap.c +++ b/drivers/firmware/efi/virtmap.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -52,6 +53,39 @@ static pgprot_t efi_md_access_prot(efi_memory_desc_t *md, pgprot_t prot) return pgprot_device(prot); } +static __init void efi_register_mem_resource(efi_memory_desc_t *md) +{ + struct resource *res, *parent; + + res = alloc_bootmem_low(sizeof(*res)); + res->start = md->phys_addr; + res->end = res->start + (md->num_pages << EFI_PAGE_SHIFT) - 1; + res->flags = IORESOURCE_MEM; + + if (md->type == EFI_MEMORY_MAPPED_IO && + (md->attribute & EFI_MEMORY_RUNTIME)) { + /* + * Device regions with the EFI_MEMORY_RUNTIME attribute + * are owned by the UEFI firmware, so make sure they are + * tagged as exclusive: this will also prevent access + * via /dev/mem if CONFIG_STRICT_DEVMEM is in effect. + */ + res->name = "UEFI Runtime I/O"; + res->flags |= IORESOURCE_EXCLUSIVE; + } else { + res->name = "UEFI Reserved"; + } + + /* + * Try to register this resource at the top level. If it conflicts with + * an existing entry ('System RAM', most likely), register it as its + * child instead. + */ + parent = request_resource_conflict(&iomem_resource, res); + if (parent) + request_resource(parent, res); +} + void __init efi_virtmap_init(void) { efi_memory_desc_t *md; @@ -63,6 +97,8 @@ void __init efi_virtmap_init(void) u64 paddr, npages, size; pgprot_t prot; + if (!efi_mem_is_usable_region(md)) + efi_register_mem_resource(md); if (!(md->attribute & EFI_MEMORY_RUNTIME)) continue; if (WARN(md->virt_addr == 0,