Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp619767imm; Mon, 2 Jul 2018 18:54:12 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfu7qHFZbGVH+xoBZfRQE5E5PeZdkOaJ4ue5GQx7a3rtiCo0VGcj5XRaZoGBvcmwWgudZ2u X-Received: by 2002:a62:8d7:: with SMTP id 84-v6mr6918387pfi.172.1530582852231; Mon, 02 Jul 2018 18:54:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530582852; cv=none; d=google.com; s=arc-20160816; b=GrWsI0kTFF0xZIpwF4cBS87umjUhB5Q9nLCtPl/BisVuAoSaf0nLKR4mGhgwW80j8H nxFHfMc5jorQlrksYv9igkUg/E6HUK2BIZBivr4cmydL8ps+N0KMkgCMNJaWbQsJGgw2 3i9siu3Vaw3U3UoqbWwRCYkZOWfspViNMjsn+h+wmLqXT0/0rKobSCvlOr4GSXHnMlSV E41KacaSuL5fiQO2gj+vxL4Mr3PEi6w3XrULBQcJweA0MM6i62I+OAqQqIsRdkQSDxuP Zczg68KpeTZk/i6c+h7e8Fc5qPw6ZIw7bL05dn6uoEFUq6vxXMuPOt56yCzhAlVdePU6 yaAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=NfohVp+UDbsQSGitz6I+ItoFIiYaH3+fd3+0MKHlBkQ=; b=CKN+skr4KRPFN9YcRAQ36KUfonHhcVAL39uBqgNS9BBTnRDbxn0wWw2ijm4u/l/Mup Ek7As/aF64/BqruYRKLyCoTvKIGvPi9eP9l2Ram+ooBC1rXodvrElKsvrqpZBYG5L/Qe cfqtrnp9oeKpCiq/uws+9c37C78x/pu1NY0fzB4jbiu3BqbKxzZyNEgLEOkwrs+eCTtR e4cXPjo5lyVpAFnc7dDxeEdQCIMDHp4T/rH1h/CPjDAKUME8FB/ldWRQSs2N2gEhRKRy fx7R0iMVCJcOqOUVWjqAzf/gM6FrxOOdEuzckai3cwAB/uxfgwz7ldlfIVII+61AAmQu UBzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4-v6si14607120pge.173.2018.07.02.18.53.58; Mon, 02 Jul 2018 18:54:12 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932443AbeGCBwi (ORCPT + 99 others); Mon, 2 Jul 2018 21:52:38 -0400 Received: from mga07.intel.com ([134.134.136.100]:5209 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753530AbeGCBvW (ORCPT ); Mon, 2 Jul 2018 21:51:22 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jul 2018 18:51:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,301,1526367600"; d="scan'208";a="212956409" Received: from sai-dev-mach.sc.intel.com ([143.183.140.52]) by orsmga004.jf.intel.com with ESMTP; 02 Jul 2018 18:51:13 -0700 From: Sai Praneeth Prakhya To: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sai Praneeth , Lee Chun-Yi , Dave Young , Borislav Petkov , Laszlo Ersek , Jan Kiszka , Dave Hansen , Bhupesh Sharma , Nicolai Stange , Naresh Bhat , Ricardo Neri , Peter Zijlstra , Taku Izumi , Ravi Shankar , Matt Fleming , Dan Williams , Ard Biesheuvel Subject: [PATCH 3/6] efi: Use efi.memmap.alloc_type instead of efi.memmap.late Date: Mon, 2 Jul 2018 18:50:51 -0700 Message-Id: <1530582654-25662-4-git-send-email-sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530582654-25662-1-git-send-email-sai.praneeth.prakhya@intel.com> References: <1530582654-25662-1-git-send-email-sai.praneeth.prakhya@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth Memory used by efi memory map could be one among the three different types, namely a) memblock_reserved b) memblock_alloc'ed c) normal paged memory. Presently, we use efi.memmap.late which is of type "bool" to record the type of memory in use by efi memory map. As "bool" doesn't suffice our needs, replace it with enum to represent one among the three different available types of memory and hence also change all the corresponding memmap API's to reflect the same. Also, presently, we never freed memblock_reserved memory and hence never recorded it's usage. Change efi_memmap_init_early() so that it could now record the usage of memblock_reserved memory and can be freed when appropriate. Also, change efi_memmap_install() and __efi_memmap_init() so that at every point of time we could record the type of memory in use by efi memory map and hence use "efi.memmap.alloc_type" to free the existing memory before installing a new memory map. Signed-off-by: Sai Praneeth Prakhya Suggested-by: Ard Biesheuvel Cc: Lee Chun-Yi Cc: Dave Young Cc: Borislav Petkov Cc: Laszlo Ersek Cc: Jan Kiszka Cc: Dave Hansen Cc: Bhupesh Sharma Cc: Nicolai Stange Cc: Naresh Bhat Cc: Ricardo Neri Cc: Peter Zijlstra Cc: Taku Izumi Cc: Ravi Shankar Cc: Matt Fleming Cc: Dan Williams Cc: Ard Biesheuvel --- arch/x86/platform/efi/efi.c | 4 ++-- arch/x86/platform/efi/quirks.c | 4 ++-- drivers/firmware/efi/arm-init.c | 2 +- drivers/firmware/efi/fake_mem.c | 2 +- drivers/firmware/efi/memmap.c | 34 +++++++++++++++++++--------------- include/linux/efi.h | 8 +++++--- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 9061babfbc83..cda54abf25a6 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -196,7 +196,7 @@ int __init efi_memblock_x86_reserve_range(void) data.desc_size = e->efi_memdesc_size; data.desc_version = e->efi_memdesc_version; - rv = efi_memmap_init_early(&data); + rv = efi_memmap_init_early(&data, EFI_STUB); if (rv) return rv; @@ -272,7 +272,7 @@ static void __init efi_clean_memmap(void) u64 size = efi.memmap.nr_map - n_removal; pr_warn("Removing %d invalid memory map entries.\n", n_removal); - efi_memmap_install(efi.memmap.phys_map, size); + efi_memmap_install(efi.memmap.phys_map, size, EFI_STUB); } } diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index 84e8d077adf6..11fa6ac9f0c2 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -292,7 +292,7 @@ void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size) efi_memmap_insert(&efi.memmap, new, &mr); early_memunmap(new, new_size); - efi_memmap_install(new_phys, num_entries); + efi_memmap_install(new_phys, num_entries, alloc_type); } /* @@ -452,7 +452,7 @@ void __init efi_free_boot_services(void) memunmap(new); - if (efi_memmap_install(new_phys, num_entries)) { + if (efi_memmap_install(new_phys, num_entries, alloc_type)) { pr_err("Could not install new EFI memmap\n"); return; } diff --git a/drivers/firmware/efi/arm-init.c b/drivers/firmware/efi/arm-init.c index b5214c143fee..f0de8df6f396 100644 --- a/drivers/firmware/efi/arm-init.c +++ b/drivers/firmware/efi/arm-init.c @@ -239,7 +239,7 @@ void __init efi_init(void) data.size = params.mmap_size; data.phys_map = params.mmap; - if (efi_memmap_init_early(&data) < 0) { + if (efi_memmap_init_early(&data, EFI_STUB) < 0) { /* * If we are booting via UEFI, the UEFI memory map is the only * description of memory we have, so there is little point in diff --git a/drivers/firmware/efi/fake_mem.c b/drivers/firmware/efi/fake_mem.c index 955e690b8325..82dcfa1c340b 100644 --- a/drivers/firmware/efi/fake_mem.c +++ b/drivers/firmware/efi/fake_mem.c @@ -90,7 +90,7 @@ void __init efi_fake_memmap(void) /* swap into new EFI memmap */ early_memunmap(new_memmap, efi.memmap.desc_size * new_nr_map); - efi_memmap_install(new_memmap_phy, new_nr_map); + efi_memmap_install(new_memmap_phy, new_nr_map, alloc_type); /* print new EFI memmap */ efi_print_memmap(); diff --git a/drivers/firmware/efi/memmap.c b/drivers/firmware/efi/memmap.c index 69b81d355619..d4e3e114cf86 100644 --- a/drivers/firmware/efi/memmap.c +++ b/drivers/firmware/efi/memmap.c @@ -88,7 +88,7 @@ void __init efi_memmap_free(phys_addr_t mem, unsigned int num_entries, /** * __efi_memmap_init - Common code for mapping the EFI memory map * @data: EFI memory map data - * @late: Use early or late mapping function? + * @alloc_type: Use early or late mapping function? * * This function takes care of figuring out which function to use to * map the EFI memory map in efi.memmap based on how far into the boot @@ -101,8 +101,8 @@ void __init efi_memmap_free(phys_addr_t mem, unsigned int num_entries, * * Returns zero on success, a negative error code on failure. */ -static int __init -__efi_memmap_init(struct efi_memory_map_data *data, bool late) +static int __init __efi_memmap_init(struct efi_memory_map_data *data, + enum efi_memmap_type alloc_type) { struct efi_memory_map map; phys_addr_t phys_map; @@ -112,7 +112,7 @@ __efi_memmap_init(struct efi_memory_map_data *data, bool late) phys_map = data->phys_map; - if (late) + if (alloc_type == BUDDY_ALLOCATOR) map.map = memremap(phys_map, data->size, MEMREMAP_WB); else map.map = early_memremap(phys_map, data->size); @@ -128,7 +128,7 @@ __efi_memmap_init(struct efi_memory_map_data *data, bool late) map.desc_version = data->desc_version; map.desc_size = data->desc_size; - map.late = late; + map.alloc_type = alloc_type; set_bit(EFI_MEMMAP, &efi.flags); @@ -140,27 +140,29 @@ __efi_memmap_init(struct efi_memory_map_data *data, bool late) /** * efi_memmap_init_early - Map the EFI memory map data structure * @data: EFI memory map data + * @alloc_type: Type of allocated memory map (EFI_STUB or MEMBLOCK)? * * Use early_memremap() to map the passed in EFI memory map and assign * it to efi.memmap. */ -int __init efi_memmap_init_early(struct efi_memory_map_data *data) +int __init efi_memmap_init_early(struct efi_memory_map_data *data, + enum efi_memmap_type alloc_type) { /* Cannot go backwards */ - WARN_ON(efi.memmap.late); + WARN_ON(efi.memmap.alloc_type == BUDDY_ALLOCATOR); - return __efi_memmap_init(data, false); + return __efi_memmap_init(data, alloc_type); } void __init efi_memmap_unmap(void) { - if (!efi.memmap.late) { + if (efi.memmap.alloc_type == BUDDY_ALLOCATOR) { + memunmap(efi.memmap.map); + } else { unsigned long size; size = efi.memmap.desc_size * efi.memmap.nr_map; early_memunmap(efi.memmap.map, size); - } else { - memunmap(efi.memmap.map); } efi.memmap.map = NULL; @@ -201,7 +203,7 @@ int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size) WARN_ON(efi.memmap.map); /* Were we already called? */ - WARN_ON(efi.memmap.late); + WARN_ON(efi.memmap.alloc_type == BUDDY_ALLOCATOR); /* * It makes no sense to allow callers to register different @@ -211,13 +213,14 @@ int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size) data.desc_version = efi.memmap.desc_version; data.desc_size = efi.memmap.desc_size; - return __efi_memmap_init(&data, true); + return __efi_memmap_init(&data, BUDDY_ALLOCATOR); } /** * efi_memmap_install - Install a new EFI memory map in efi.memmap * @addr: Physical address of the memory map * @nr_map: Number of entries in the memory map + * @alloc_type: Type of allocation performed to get @addr. * * Unlike efi_memmap_init_*(), this function does not allow the caller * to switch from early to late mappings. It simply uses the existing @@ -225,7 +228,8 @@ int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size) * * Returns zero on success, a negative error code on failure. */ -int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map) +int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map, + enum efi_memmap_type alloc_type) { struct efi_memory_map_data data; @@ -236,7 +240,7 @@ int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map) data.desc_version = efi.memmap.desc_version; data.desc_size = efi.memmap.desc_size; - return __efi_memmap_init(&data, efi.memmap.late); + return __efi_memmap_init(&data, alloc_type); } /** diff --git a/include/linux/efi.h b/include/linux/efi.h index 53495e854d2a..c9752c67d184 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -778,7 +778,7 @@ struct efi_memory_map { int nr_map; unsigned long desc_version; unsigned long desc_size; - bool late; + enum efi_memmap_type alloc_type; }; struct efi_mem_range { @@ -1015,10 +1015,12 @@ extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr); extern phys_addr_t __init efi_memmap_alloc(unsigned int num_entries, enum efi_memmap_type *alloc_type); -extern int __init efi_memmap_init_early(struct efi_memory_map_data *data); +extern int __init efi_memmap_init_early(struct efi_memory_map_data *data, + enum efi_memmap_type alloc_type); extern int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size); extern void __init efi_memmap_unmap(void); -extern int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map); +extern int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map, + enum efi_memmap_type alloc_type); extern int __init efi_memmap_split_count(efi_memory_desc_t *md, struct range *range); extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap, -- 2.7.4