From patchwork Fri Oct 23 09:48:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 55474 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id 18AFB22A9D for ; Fri, 23 Oct 2015 09:48:46 +0000 (UTC) Received: by wiyb4 with SMTP id b4sf8654733wiy.2 for ; Fri, 23 Oct 2015 02:48:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=3KyKvGmBcRgFPgs/9leedieifbkc/AaXCUGyLAcjahk=; b=XfVSNyYHI1CnD5PlxTOZBrswvucZxnoT7qNeNOAvZKvu0dajLdU4DFPcwS7Gmnwsss sU86Fh6opFBJPhlJBodb6vp+qTsUfP+19CHCZpXB+qFmRXaK2vIZT7XQYgAwMjw1KD/9 RFns0RXVsaOxXfswC42yLUQY9EjV5H4bRviw+DEBgl5LcGB484PJQ4V8A7utvOi0hWf5 rkVVy/nclJE4P98lqg/faaJUtQRGGtaZS/36KYvk5YzDmqdrULKTiwKsc8T7HYV0Y5Yz k5H9qQr+rF8P5lgEYIlfZCydeUAAinBWvpDyLQIjA5aJACj3HtdGnE9Vu3pYeho06ziC r1Pg== X-Gm-Message-State: ALoCoQksL3DSIgfk0uNvzC85HUgwPhLYgqRZHOwNWMFhBmGgdimzcc3E2SiKGldZrczeuBA/dNt6 X-Received: by 10.194.248.131 with SMTP id ym3mr4709755wjc.7.1445593725439; Fri, 23 Oct 2015 02:48:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.152.211 with SMTP id a202ls267322lfe.32.gmail; Fri, 23 Oct 2015 02:48:45 -0700 (PDT) X-Received: by 10.112.13.136 with SMTP id h8mr10650440lbc.23.1445593725256; Fri, 23 Oct 2015 02:48:45 -0700 (PDT) Received: from mail-lf0-x22e.google.com (mail-lf0-x22e.google.com. [2a00:1450:4010:c07::22e]) by mx.google.com with ESMTPS id zf4si12181488lbb.129.2015.10.23.02.48.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Oct 2015 02:48:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c07::22e as permitted sender) client-ip=2a00:1450:4010:c07::22e; Received: by lffz202 with SMTP id z202so77457827lff.3 for ; Fri, 23 Oct 2015 02:48:45 -0700 (PDT) X-Received: by 10.112.135.9 with SMTP id po9mr11124990lbb.56.1445593725119; Fri, 23 Oct 2015 02:48:45 -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.112.59.35 with SMTP id w3csp1109153lbq; Fri, 23 Oct 2015 02:48:44 -0700 (PDT) X-Received: by 10.68.57.205 with SMTP id k13mr10983752pbq.4.1445593723974; Fri, 23 Oct 2015 02:48:43 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yo3si28269790pab.227.2015.10.23.02.48.43; Fri, 23 Oct 2015 02:48:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752596AbbJWJsm (ORCPT + 28 others); Fri, 23 Oct 2015 05:48:42 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:36744 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751031AbbJWJsi (ORCPT ); Fri, 23 Oct 2015 05:48:38 -0400 Received: by pacfv9 with SMTP id fv9so119543717pac.3 for ; Fri, 23 Oct 2015 02:48:38 -0700 (PDT) X-Received: by 10.66.193.134 with SMTP id ho6mr3884256pac.52.1445593718273; Fri, 23 Oct 2015 02:48:38 -0700 (PDT) Received: from jessie.localdomain ([103.232.89.42]) by smtp.gmail.com with ESMTPSA id xm4sm18117871pab.27.2015.10.23.02.48.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 23 Oct 2015 02:48:37 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, izumi.taku@jp.fujitsu.com, matt.fleming@intel.com, linux-kernel@vger.kernel.org, mingo@kernel.org Cc: kamezawa.hiroyu@jp.fujitsu.com, Ard Biesheuvel Subject: [PATCH 1/2] efi: use correct type for struct efi_memory_map::phys_map Date: Fri, 23 Oct 2015 11:48:16 +0200 Message-Id: <1445593697-1342-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <20151023085011.GB21631@gmail.com> References: <20151023085011.GB21631@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 2a00:1450:4010:c07::22e as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , We have been getting away with using a void* for the physical address of the UEFI memory map, since, even on 32-bit platforms with 64-bit physical addresses, no truncation takes place if the memory map has been allocated by the firmware (which only uses 1:1 virtually addressable memory), which is usually the case. However, commit 0f96a99dab36 ("efi: Add "efi_fake_mem" boot option") adds code that clones and modifies the UEFI memory map, and the clone may live above 4 GB on 32-bit platforms. This means our use of void* for struct efi_memory_map::phys_map has graduated from 'incorrect but working' to 'incorrect and broken', and we need to fix it. So redefine struct efi_memory_map::phys_map as phys_addr_t, and get rid of a bunch of casts that are now unneeded. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi.c | 4 ++-- arch/x86/platform/efi/efi.c | 4 ++-- drivers/firmware/efi/efi.c | 8 ++++---- include/linux/efi.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index 4b7df346e388..61eb1d17586a 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -208,7 +208,7 @@ void __init efi_init(void) memblock_reserve(params.mmap & PAGE_MASK, PAGE_ALIGN(params.mmap_size + (params.mmap & ~PAGE_MASK))); - memmap.phys_map = (void *)params.mmap; + memmap.phys_map = params.mmap; memmap.map = early_memremap(params.mmap, params.mmap_size); memmap.map_end = memmap.map + params.mmap_size; memmap.desc_size = params.desc_size; @@ -282,7 +282,7 @@ static int __init arm64_enable_runtime_services(void) pr_info("Remapping and enabling EFI services.\n"); mapsize = memmap.map_end - memmap.map; - memmap.map = (__force void *)ioremap_cache((phys_addr_t)memmap.phys_map, + memmap.map = (__force void *)ioremap_cache(memmap.phys_map, mapsize); if (!memmap.map) { pr_err("Failed to remap EFI memory map\n"); diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 3e1d09e885c0..ad285404ea7f 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -194,7 +194,7 @@ static void __init do_add_efi_memmap(void) int __init efi_memblock_x86_reserve_range(void) { struct efi_info *e = &boot_params.efi_info; - unsigned long pmap; + phys_addr_t pmap; if (efi_enabled(EFI_PARAVIRT)) return 0; @@ -209,7 +209,7 @@ int __init efi_memblock_x86_reserve_range(void) #else pmap = (e->efi_memmap | ((__u64)e->efi_memmap_hi << 32)); #endif - memmap.phys_map = (void *)pmap; + memmap.phys_map = pmap; memmap.nr_map = e->efi_memmap_size / e->efi_memdesc_size; memmap.desc_size = e->efi_memdesc_size; diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 31fc864eb037..027ca212179f 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -254,7 +254,7 @@ subsys_initcall(efisubsys_init); int __init efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md) { struct efi_memory_map *map = efi.memmap; - void *p, *e; + phys_addr_t p, e; if (!efi_enabled(EFI_MEMMAP)) { pr_err_once("EFI_MEMMAP is not enabled.\n"); @@ -286,10 +286,10 @@ int __init efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md) * So just always get our own virtual map on the CPU. * */ - md = early_memremap((phys_addr_t)p, sizeof (*md)); + md = early_memremap(p, sizeof (*md)); if (!md) { - pr_err_once("early_memremap(%p, %zu) failed.\n", - p, sizeof (*md)); + pr_err_once("early_memremap(%pa, %zu) failed.\n", + &p, sizeof (*md)); return -ENOMEM; } diff --git a/include/linux/efi.h b/include/linux/efi.h index 4d01c1033fce..569b5a866bb1 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -680,7 +680,7 @@ typedef struct { } efi_system_table_t; struct efi_memory_map { - void *phys_map; + phys_addr_t phys_map; void *map; void *map_end; int nr_map;