From patchwork Mon Dec 22 19:08:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 42539 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6051525BA1 for ; Mon, 22 Dec 2014 19:11:44 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id l15sf3287643wiw.4 for ; Mon, 22 Dec 2014 11:11:43 -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=ACyBCCfrCJbX4AV3boddhn43bKJcpDONnYo4PRNuIvs=; b=jx1p6wxgjYrxem9kR34faWsny/zuF8IGostfA6TAFQIRwn6uqYI6WQrXvP3Bf2mmP3 VH4jzMNgVXb6sBJkzjWZ0XAfypFNOeDNT4nkjKVgNQs6hK5aMjYdwgz58htrrfLwCfLk M9sIGgk6+wHndXMbeyPbf2nwQvG2VtMGzp79BR10R5u4VLXjM1gbgbGRbdOG4+5OBHWc gr7Is8anpSOmvVaQ+H7tIqQfnof+a+Z7oDCZHpyMAcy2whXcMAyuGD1Kc4vShIi85Our VRADbt1mTW27cb5PH1/rYTkvo2KczDr2Gy373tRVluBU06fd4TKidw3/ZLximif+iA/w CAIw== X-Gm-Message-State: ALoCoQmDqBovflounYHrQXeL+XW2Jyn0YPQ+mmmRzKsjiiYQE/69UuZLwSaNK1UeizhujgnGW2Tj X-Received: by 10.112.42.104 with SMTP id n8mr7480lbl.19.1419275503519; Mon, 22 Dec 2014 11:11:43 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.7 with SMTP id 7ls1330157laq.88.gmail; Mon, 22 Dec 2014 11:11:43 -0800 (PST) X-Received: by 10.112.99.71 with SMTP id eo7mr23758764lbb.26.1419275503347; Mon, 22 Dec 2014 11:11:43 -0800 (PST) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id k12si19398423laa.24.2014.12.22.11.11.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Dec 2014 11:11:43 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id ms9so4457909lab.38 for ; Mon, 22 Dec 2014 11:11:43 -0800 (PST) X-Received: by 10.112.131.1 with SMTP id oi1mr23114638lbb.2.1419275503215; Mon, 22 Dec 2014 11:11:43 -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 ru5csp1118540lbb; Mon, 22 Dec 2014 11:11:42 -0800 (PST) X-Received: by 10.68.241.130 with SMTP id wi2mr37307027pbc.89.1419275500167; Mon, 22 Dec 2014 11:11:40 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id vp9si26445133pab.47.2014.12.22.11.11.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Dec 2014 11:11:40 -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 1Y38MN-0006VY-CA; Mon, 22 Dec 2014 19:09:39 +0000 Received: from mail-wi0-f182.google.com ([209.85.212.182]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Y38MA-0006P9-Db for linux-arm-kernel@lists.infradead.org; Mon, 22 Dec 2014 19:09:27 +0000 Received: by mail-wi0-f182.google.com with SMTP id h11so8844852wiw.15 for ; Mon, 22 Dec 2014 11:09:02 -0800 (PST) X-Received: by 10.194.92.37 with SMTP id cj5mr45038858wjb.81.1419275342673; Mon, 22 Dec 2014 11:09:02 -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.08.58 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Dec 2014 11:09:01 -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 2/8] arm64/efi: register UEFI reserved regions as iomem resources Date: Mon, 22 Dec 2014 19:08:36 +0000 Message-Id: <1419275322-29811-3-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_110926_654270_77E50184 X-CRM114-Status: GOOD ( 13.34 ) 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.182 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.182 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.51 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 To prevent device drivers from attaching to device or memory regions owned by the firmware, register all UEFI reserved regions in the iomem resource table at init time. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index d2f483a7cffe..ba5fe66c3634 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -305,6 +305,50 @@ void efi_virtmap_unload(void) efi_set_pgd(current->active_mm); } +static __init void efi_reserve_iomem_resource(efi_memory_desc_t *md) +{ + struct resource *res; + + res = alloc_bootmem_low(sizeof(*res)); + res->start = md->phys_addr; + res->end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - 1; + res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; + + if (!is_reserve_region(md)) { + /* + * Non-RAM regions with the EFI_MEMORY_RUNTIME attribute + * are owned by the UEFI firmware, so make sure they are + * tagged as exclusive: this will prevent device drivers + * from binding to the memory region, and will also prevent + * access via /dev/mem if CONFIG_STRICT_DEVMEM is in effect. + */ + res->name = "UEFI Runtime [MMIO]"; + res->flags |= IORESOURCE_EXCLUSIVE; + } else if (md->type == EFI_RUNTIME_SERVICES_DATA) { + /* + * UEFI Runtime Services Data regions may be used to store + * configuration tables such as SMBIOS, which are often + * accessed using userland tools such as 'dmidecode', that + * are /dev/mem based. So don't set the exclusive flag in + * this case. + */ + res->name = "UEFI Runtime [Data]"; + } else { + /* + * Register all remaining reserved RAM regions as both busy + * and exclusive in the iomem resource table. This prevents + * drivers from claiming the region, and also disallows + * /dev/mem access. + */ + if (md->type == EFI_RUNTIME_SERVICES_CODE) + res->name = "UEFI Runtime [Code]"; + else + res->name = "UEFI Reserved"; + res->flags |= IORESOURCE_EXCLUSIVE; + } + request_resource(&iomem_resource, res); +} + void __init efi_virtmap_init(void) { efi_memory_desc_t *md; @@ -316,6 +360,8 @@ void __init efi_virtmap_init(void) u64 paddr, npages, size; pgprot_t prot; + if (is_reserve_region(md) || md->attribute & EFI_MEMORY_RUNTIME) + efi_reserve_iomem_resource(md); if (!(md->attribute & EFI_MEMORY_RUNTIME)) continue; if (WARN(md->virt_addr == 0,