From patchwork Fri Jul 4 10:16:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 33083 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f198.google.com (mail-qc0-f198.google.com [209.85.216.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1D990203AC for ; Fri, 4 Jul 2014 10:18:32 +0000 (UTC) Received: by mail-qc0-f198.google.com with SMTP id m20sf4441906qcx.5 for ; Fri, 04 Jul 2014 03:18:32 -0700 (PDT) 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: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=6U6BdjA4afLD5M5BY9bSsrhd7YuXHDZiAO2Tb20ZUM0=; b=CLKMDz56AXbIMYKm4JhWdjKMLbEEwvMRVe1lA48kpBvlZoCMJ9+yEIIAOCSYYEHfwW eMZMWgmFY4Oo4atp5km5a6hTydV10UsOr6rc/FUmsENjfFHyGxUjbm51oyADgatxhDE7 jT5qq/4ACEaITxWZ3HwZuGgGX0PhkszaTnxkDcD9nElm+NQ7mzuGdISf3GFBrDMtUn8x vilNXSQ+q1Zxe8bn1wZcHMJoteoNfuhmHCIn1jcYiYefue6dFIh+D46qs/n9dnwQ3fqu FIqS1ZK+NQ7lg53vjlQwr34wwH1I99jnBwQHIyDAszfNbfO1q02o/Is6LqYOZf5LbQO5 ypmA== X-Gm-Message-State: ALoCoQnEsPtkPJctcqo8E5Qubll8XyDF2irNKXzlwkjoNtFL5fwMMoRhQMyb4GqEXevOs52g5igh X-Received: by 10.236.207.164 with SMTP id n24mr5014545yho.5.1404469112821; Fri, 04 Jul 2014 03:18:32 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.101 with SMTP id c92ls756522qge.90.gmail; Fri, 04 Jul 2014 03:18:32 -0700 (PDT) X-Received: by 10.52.253.131 with SMTP id aa3mr7516137vdd.25.1404469112689; Fri, 04 Jul 2014 03:18:32 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id g6si13265174vcn.29.2014.07.04.03.18.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 04 Jul 2014 03:18:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.175 as permitted sender) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id jx11so1451985veb.20 for ; Fri, 04 Jul 2014 03:18:32 -0700 (PDT) X-Received: by 10.52.248.146 with SMTP id ym18mr7531297vdc.8.1404469112573; Fri, 04 Jul 2014 03:18:32 -0700 (PDT) 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.221.37.5 with SMTP id tc5csp454805vcb; Fri, 4 Jul 2014 03:18:31 -0700 (PDT) X-Received: by 10.70.37.225 with SMTP id b1mr9439960pdk.78.1404469110953; Fri, 04 Jul 2014 03:18:30 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id kf9si34999899pad.73.2014.07.04.03.18.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Jul 2014 03:18:30 -0700 (PDT) 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 1X30YJ-0002vT-C3; Fri, 04 Jul 2014 10:17:11 +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 1X30YH-0002oA-JS for linux-arm-kernel@lists.infradead.org; Fri, 04 Jul 2014 10:17:10 +0000 Received: by mail-wi0-f182.google.com with SMTP id bs8so3559955wib.15 for ; Fri, 04 Jul 2014 03:16:44 -0700 (PDT) X-Received: by 10.180.74.9 with SMTP id p9mr17027909wiv.39.1404469004381; Fri, 04 Jul 2014 03:16:44 -0700 (PDT) Received: from ards-macbook-pro.local (89-164-111-59.dsl.iskon.hr. [89.164.111.59]) by mx.google.com with ESMTPSA id ed15sm72805137wic.9.2014.07.04.03.16.41 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 04 Jul 2014 03:16:43 -0700 (PDT) From: Ard Biesheuvel To: matt.fleming@intel.com, msalter@redhat.com Subject: [PATCH v2] efi/arm64: handle missing virtual mapping for UEFI System Table Date: Fri, 4 Jul 2014 12:16:37 +0200 Message-Id: <1404468997-6925-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140704_031709_799090_094D5E67 X-CRM114-Status: GOOD ( 14.59 ) 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: linux-efi@vger.kernel.org, leif.lindholm@linaro.org, linux-arm-kernel@lists.infradead.org, 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.128.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 If we cannot resolve the virtual address of the UEFI System Table, its physical offset must be missing from the virtual memory map, and there is really no point in proceeding with installing the virtual memory map and the runtime services dispatch table. So back out gracefully. Signed-off-by: Ard Biesheuvel --- v2: - release mappings and free virtmap before bailing arch/arm64/kernel/efi.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index 56c3327bbf79..23942158e0f8 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -416,11 +416,23 @@ static int __init arm64_enter_virtual_mode(void) continue; if (remap_region(md, &virt_md)) ++count; + else + goto err_unmap; } efi.systab = (__force void *)efi_lookup_mapped_addr(efi_system_table); - if (efi.systab) - set_bit(EFI_SYSTEM_TABLES, &efi.flags); + if (!efi.systab) { + /* + * If we have no virtual mapping for the System Table at this + * point, the memory map doesn't cover the physical offset where + * it resides. This means the System Table will be inaccessible + * to Runtime Services themselves once the virtual mapping is + * installed. + */ + pr_err("Failed to remap EFI System Table -- buggy firmware?\n"); + goto err_unmap; + } + set_bit(EFI_SYSTEM_TABLES, &efi.flags); local_irq_save(flags); cpu_switch_mm(idmap_pg_dir, &init_mm); @@ -453,5 +465,17 @@ static int __init arm64_enter_virtual_mode(void) set_bit(EFI_RUNTIME_SERVICES, &efi.flags); return 0; + +err_unmap: + /* unmap all mappings that succeeded: there are 'count' of those */ + for_each_efi_memory_desc(&memmap, md) { + if (!(md->attribute & EFI_MEMORY_RUNTIME)) + continue; + if (!count--) + break; + iounmap((__force void *)md->virt_addr); + } + kfree(virtmap); + return -1; } early_initcall(arm64_enter_virtual_mode);