From patchwork Fri Jul 4 15:25:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 33109 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f198.google.com (mail-vc0-f198.google.com [209.85.220.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 571F720C88 for ; Fri, 4 Jul 2014 15:27:42 +0000 (UTC) Received: by mail-vc0-f198.google.com with SMTP id hy10sf5248181vcb.5 for ; Fri, 04 Jul 2014 08:27:41 -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=uSYz/JBSkEnTFmcKTLELr4nQX93fnp4I6hECafma2II=; b=PlzNBJDuv9GfpFCCIOn6/wRuQOrbP9hN/2tqXbuS/857CjkdpJEDxE69hK9s8/Brtl RPmcWEgbZtF2Vf6LU/PhC1DikIdGdDtaM77S1YB/dyvEBqGCT+2wPRBIAAKigK6ayfXo cgfgW8nNRw2cxizImVzpdQjC8qbnObCq4s2uUkwXKe1v7V/Z+P3FXp/7oPFQkPocbFKC BxFpvhh2oG/MTGjCdxHEqrN/CXxzN61TIMU/BHMj0MF2GVIUhuZYTqRv7HYpCEoQcO20 paE5ksJbUeF5G2wqrVCaeRxbxjR54QVm3NgQUm/1E0ulU0oRA6v6YxyWZnjnwpOtPRP5 1dBQ== X-Gm-Message-State: ALoCoQmrKs7YP1Fk8PmXF/1Cdwkxi5H40gzYXq+z74NnUxRoBDeTVTU5gRbDs02sO1h0fpw47j5Z X-Received: by 10.224.97.8 with SMTP id j8mr5700933qan.0.1404487661871; Fri, 04 Jul 2014 08:27:41 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.92.131 with SMTP id b3ls960273qge.29.gmail; Fri, 04 Jul 2014 08:27:41 -0700 (PDT) X-Received: by 10.58.132.136 with SMTP id ou8mr7593068veb.0.1404487661687; Fri, 04 Jul 2014 08:27:41 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id sg10si15666016vec.88.2014.07.04.08.27.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 04 Jul 2014 08:27:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id id10so1743919vcb.30 for ; Fri, 04 Jul 2014 08:27:41 -0700 (PDT) X-Received: by 10.52.232.133 with SMTP id to5mr8535650vdc.16.1404487661600; Fri, 04 Jul 2014 08:27:41 -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 tc5csp473647vcb; Fri, 4 Jul 2014 08:27:41 -0700 (PDT) X-Received: by 10.66.141.109 with SMTP id rn13mr3882424pab.117.1404487660712; Fri, 04 Jul 2014 08:27:40 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id vq10si35500060pab.121.2014.07.04.08.27.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Jul 2014 08:27:40 -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 1X35Mu-0004BT-8K; Fri, 04 Jul 2014 15:25:44 +0000 Received: from mail-wi0-f175.google.com ([209.85.212.175]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X35Mr-0004AB-CV for linux-arm-kernel@lists.infradead.org; Fri, 04 Jul 2014 15:25:41 +0000 Received: by mail-wi0-f175.google.com with SMTP id r20so13096544wiv.14 for ; Fri, 04 Jul 2014 08:25:15 -0700 (PDT) X-Received: by 10.180.76.132 with SMTP id k4mr18721905wiw.1.1404487515504; Fri, 04 Jul 2014 08:25:15 -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 nc19sm25897512wic.4.2014.07.04.08.25.13 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 04 Jul 2014 08:25:14 -0700 (PDT) From: Ard Biesheuvel To: matt.fleming@intel.com, catalin.marinas@arm.com, msalter@redhat.com Subject: [PATCH v3] efi/arm64: handle missing virtual mapping for UEFI System Table Date: Fri, 4 Jul 2014 17:25:09 +0200 Message-Id: <1404487509-26084-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_082541_573348_0E80D0B3 X-CRM114-Status: GOOD ( 14.25 ) 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.175 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.175 listed in wl.mailspike.net] -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.220.171 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 Acked-by: Mark Salter Acked-by: Catalin Marinas --- arch/arm64/kernel/efi.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index 56c3327bbf79..e72f3100958f 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -414,13 +414,24 @@ static int __init arm64_enter_virtual_mode(void) for_each_efi_memory_desc(&memmap, md) { if (!(md->attribute & EFI_MEMORY_RUNTIME)) continue; - if (remap_region(md, &virt_md)) - ++count; + if (!remap_region(md, &virt_md)) + goto err_unmap; + ++count; } 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 +464,14 @@ 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 (virt_md = virtmap; count--; virt_md += memmap.desc_size) { + md = virt_md; + iounmap((__force void __iomem *)md->virt_addr); + } + kfree(virtmap); + return -1; } early_initcall(arm64_enter_virtual_mode);