Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp618707imm; Mon, 2 Jul 2018 18:52:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLEv0lXGEolWWvLT1z62qOEKERjjjAgTyVOl/Znf3fo7ml2YgvPlYodVzQ7fJxprd6bdE/U X-Received: by 2002:a17:902:904c:: with SMTP id w12-v6mr27822561plz.34.1530582737560; Mon, 02 Jul 2018 18:52:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530582737; cv=none; d=google.com; s=arc-20160816; b=qw+iXrWEkmNLDSBg4qEKpkDcNaScq0B004YFLrtJ/Xl9HI9jVAN7XmhlBViAQszfIc yrn2rc5zftHgcUOjgFFpM5jZB5OGV9lbWDk7Q2yvXFp+ew4PEi2MWtOahIPb6KhCBMpF rtaqZ8wR9DsTD9eV60AhNPG9mlXZxFI14laLiJHxAqacxc3/zjkI1oRItRUWINXQkpgj vuJNdir6eZtbEqlXquVOUexRjQDsdJBSIsTzEgetEcDTgfG6JiRTl30Tq5gbC76hd2ut FxcM0ZmEnbxQwwcg63s4BoU9eu8NvUFdE8Ijm/fcTXQUMcoRlMm/Y15u2g7LyyEakFeI SFTQ== 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=jU/X/GxH5UuxssgdIDkngAD8dllg28lVmlPFqA9el6M=; b=rG/Fbzzc3LM/RTHO6rzkMZjN9BX/3WCOJflmkeiIhPoyVc0CQoQRTE3Bt+k3vBADjm fd3nJyKy2o6CYbh1ybRU1JsI0gLXknplmMbVB83DECZO4N1M9oA29KgwyohYHbRnIyUA JZ4d6ul13qngor7RibBYabwI4Q8jvYQTNw44nfSyiI6U3benZfmJ+bceR28BNeSj46Bo g5/zqNYZvt1EGfVq/sTpVbhAApHYzXnowYyKPtlrMP2f/Zg2iRKtVYXsMPlaeVjs2EWS 3JnpEchFH4B0bSDrvv8PLrDpBxXdFv6UbsmJ9Yht6NaB5v8ZiYWaajQ0mAYzPP4KICMj k+GA== 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 c3-v6si17418578pld.87.2018.07.02.18.52.02; Mon, 02 Jul 2018 18:52:17 -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 S932207AbeGCBvY (ORCPT + 99 others); Mon, 2 Jul 2018 21:51:24 -0400 Received: from mga07.intel.com ([134.134.136.100]:5207 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753264AbeGCBvW (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="212956403" Received: from sai-dev-mach.sc.intel.com ([143.183.140.52]) by orsmga004.jf.intel.com with ESMTP; 02 Jul 2018 18:51:10 -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 1/6] efi: Introduce efi_memmap_free() to free memory allocated by efi_memmap_alloc() Date: Mon, 2 Jul 2018 18:50:49 -0700 Message-Id: <1530582654-25662-2-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 efi_memmap_alloc() allocates memory depending on whether mm_init() has already been invoked or not. Apart from memblock_alloc() memory and alloc_pages() memory, efi memory map could also have a third variant of memory allocation and that is memblock_reserved. This happens only for the memory map passed to kernel by firmware and thus can happen only once during boot process. In order to identify these three different types of allocations and thus to call the appropriate free() variant, introduce an enum named efi_memmap_type and also introduce a efi memmap API named efi_memmap_free() to free memory allocated by efi_memmap_alloc(). 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 --- drivers/firmware/efi/memmap.c | 28 ++++++++++++++++++++++++++++ include/linux/efi.h | 8 ++++++++ 2 files changed, 36 insertions(+) diff --git a/drivers/firmware/efi/memmap.c b/drivers/firmware/efi/memmap.c index 5fc70520e04c..0686e063c644 100644 --- a/drivers/firmware/efi/memmap.c +++ b/drivers/firmware/efi/memmap.c @@ -12,6 +12,7 @@ #include #include #include +#include static phys_addr_t __init __efi_memmap_alloc_early(unsigned long size) { @@ -50,6 +51,33 @@ phys_addr_t __init efi_memmap_alloc(unsigned int num_entries) } /** + * efi_memmap_free - Free memory allocated by efi_memmap_alloc() + * @mem: Physical address allocated by efi_memmap_alloc(). + * @num_entries: Number of entries in the allocated map. + * @alloc_type: What type of allocation did efi_memmap_alloc() perform? + * + * Use this function to free memory allocated by efi_memmap_alloc(). + * efi_memmap_alloc() allocates memory depending on whether mm_init() + * has already been invoked or not. It uses either memblock or "normal" + * page allocation, similarly, we free it in two different ways. Also + * note that there is a third type of memory used by memmap which is + * memblock_reserved() and is passed by EFI stub to kernel. + */ +void __init efi_memmap_free(phys_addr_t mem, unsigned int num_entries, + enum efi_memmap_type alloc_type) +{ + unsigned long size = num_entries * efi.memmap.desc_size; + unsigned int order = get_order(size); + + if (alloc_type == BUDDY_ALLOCATOR) + __free_pages(pfn_to_page(PHYS_PFN(mem)), order); + else if (alloc_type == MEMBLOCK) + memblock_free(mem, size); + else + free_bootmem(mem, size); +} + +/** * __efi_memmap_init - Common code for mapping the EFI memory map * @data: EFI memory map data * @late: Use early or late mapping function? diff --git a/include/linux/efi.h b/include/linux/efi.h index 56add823f190..455875c01ed1 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -765,6 +765,12 @@ struct efi_memory_map_data { unsigned long desc_size; }; +enum efi_memmap_type { + EFI_STUB, + MEMBLOCK, + BUDDY_ALLOCATOR, +}; + struct efi_memory_map { phys_addr_t phys_map; void *map; @@ -1016,6 +1022,8 @@ 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, void *buf, struct efi_mem_range *mem); +extern void __init efi_memmap_free(phys_addr_t mem, unsigned int num_entries, + enum efi_memmap_type alloc_type); extern int efi_config_init(efi_config_table_type_t *arch_tables); #ifdef CONFIG_EFI_ESRT -- 2.7.4