浏览代码

efi: Use correct type for struct efi_memory_map::phys_map

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 <ard.biesheuvel@linaro.org>
Reviewed-by: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: izumi.taku@jp.fujitsu.com
Cc: kamezawa.hiroyu@jp.fujitsu.com
Cc: linux-efi@vger.kernel.org
Cc: matt.fleming@intel.com
Link: http://lkml.kernel.org/r/1445593697-1342-1-git-send-email-ard.biesheuvel@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Ard Biesheuvel 9 年之前
父节点
当前提交
44511fb9e5
共有 4 个文件被更改,包括 9 次插入9 次删除
  1. 2 2
      arch/arm64/kernel/efi.c
  2. 2 2
      arch/x86/platform/efi/efi.c
  3. 4 4
      drivers/firmware/efi/efi.c
  4. 1 1
      include/linux/efi.h

+ 2 - 2
arch/arm64/kernel/efi.c

@@ -208,7 +208,7 @@ void __init efi_init(void)
 
 
 	memblock_reserve(params.mmap & PAGE_MASK,
 	memblock_reserve(params.mmap & PAGE_MASK,
 			 PAGE_ALIGN(params.mmap_size + (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 = early_memremap(params.mmap, params.mmap_size);
 	memmap.map_end = memmap.map + params.mmap_size;
 	memmap.map_end = memmap.map + params.mmap_size;
 	memmap.desc_size = params.desc_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");
 	pr_info("Remapping and enabling EFI services.\n");
 
 
 	mapsize = memmap.map_end - memmap.map;
 	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);
 						   mapsize);
 	if (!memmap.map) {
 	if (!memmap.map) {
 		pr_err("Failed to remap EFI memory map\n");
 		pr_err("Failed to remap EFI memory map\n");

+ 2 - 2
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)
 int __init efi_memblock_x86_reserve_range(void)
 {
 {
 	struct efi_info *e = &boot_params.efi_info;
 	struct efi_info *e = &boot_params.efi_info;
-	unsigned long pmap;
+	phys_addr_t pmap;
 
 
 	if (efi_enabled(EFI_PARAVIRT))
 	if (efi_enabled(EFI_PARAVIRT))
 		return 0;
 		return 0;
@@ -209,7 +209,7 @@ int __init efi_memblock_x86_reserve_range(void)
 #else
 #else
 	pmap = (e->efi_memmap |	((__u64)e->efi_memmap_hi << 32));
 	pmap = (e->efi_memmap |	((__u64)e->efi_memmap_hi << 32));
 #endif
 #endif
-	memmap.phys_map		= (void *)pmap;
+	memmap.phys_map		= pmap;
 	memmap.nr_map		= e->efi_memmap_size /
 	memmap.nr_map		= e->efi_memmap_size /
 				  e->efi_memdesc_size;
 				  e->efi_memdesc_size;
 	memmap.desc_size	= e->efi_memdesc_size;
 	memmap.desc_size	= e->efi_memdesc_size;

+ 4 - 4
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)
 int __init efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md)
 {
 {
 	struct efi_memory_map *map = efi.memmap;
 	struct efi_memory_map *map = efi.memmap;
-	void *p, *e;
+	phys_addr_t p, e;
 
 
 	if (!efi_enabled(EFI_MEMMAP)) {
 	if (!efi_enabled(EFI_MEMMAP)) {
 		pr_err_once("EFI_MEMMAP is not enabled.\n");
 		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.
 		 * 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) {
 		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;
 			return -ENOMEM;
 		}
 		}
 
 

+ 1 - 1
include/linux/efi.h

@@ -680,7 +680,7 @@ typedef struct {
 } efi_system_table_t;
 } efi_system_table_t;
 
 
 struct efi_memory_map {
 struct efi_memory_map {
-	void *phys_map;
+	phys_addr_t phys_map;
 	void *map;
 	void *map;
 	void *map_end;
 	void *map_end;
 	int nr_map;
 	int nr_map;