Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp215919imm; Tue, 19 Jun 2018 19:37:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI71K6UpOv7qZwWZvrzGndcRg7M7PxSQ6yJOTJtCD+bNwYGy/kmU5+nHCtusoxRBdoGrmn2 X-Received: by 2002:a65:494b:: with SMTP id q11-v6mr17392882pgs.105.1529462275495; Tue, 19 Jun 2018 19:37:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529462275; cv=none; d=google.com; s=arc-20160816; b=JBsJ/hxn+FiLtTMobaQ5F1V4hLT0HxCuzdimsNHKMS4uRlp5KK/w+0ZO+hyatKFfXv aaX5UtIovcDF4eJRQIbd2SQpz+XDUWyEX2d10madzdZ75uL9PcD1SBu08Bm/zEbroEiI N1PXnXfbcHHF7ko3Ba8DV7FzbCFnbJ+mfLqhnWRsj/dtYGnpnM7jmkum37fynOjehTyu 1JnSy+6lQM8fZug+PN9dM8iT5+j7E3za8ejW+hTTGgatWQf0yioMxEG3Ceu44iZROqVj +kdGXckR4jP3N3mHGysYxY5/8/+3m3HCRxvrSBsTJC1Np7T860lfY/oefSHTnPbDh3cm lDEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=G8v6z+1XiTvMLjMIXWTQa+01zMlco8fuOIrWY9qv+5g=; b=EFKDawFJVE7hIJ3/2O8fvjTn+9oGqyHlnC3RwR/+bYuEeOQt5MTU54KGA5GZzRlWcW CcDNymzD+fRCOdGwKhItGvAYIwGxgJ2rEUjd5j0nhm1RtIytUGJxU9Cq9Ttfe5ygCMih /M6O+RJgSwnRaCmPvexY28JRp/qriOCWbmrBVnjUZ4Qw00Gr+diA4u5nwncTAkLTPxBG Y+mY+tA3XOMpniyHlM3nPXqmvth1qccuX4tXehVOssMLvWvDUPIScYihJ33xpexlLNEx RE2hIBc0zCOtNe/sGN0t5v/ta0HhfRmi/6T0/YgnmUdgZdVuDfEz+UlriDfZ9ujs9IBt GeKw== 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 e67-v6si1232266pfa.217.2018.06.19.19.37.41; Tue, 19 Jun 2018 19:37:55 -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 S1754178AbeFTCgz (ORCPT + 99 others); Tue, 19 Jun 2018 22:36:55 -0400 Received: from mga07.intel.com ([134.134.136.100]:41554 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752951AbeFTCgw (ORCPT ); Tue, 19 Jun 2018 22:36:52 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jun 2018 19:36:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,245,1526367600"; d="scan'208";a="64677556" Received: from sai-dev-mach.sc.intel.com ([143.183.140.145]) by fmsmga004.fm.intel.com with ESMTP; 19 Jun 2018 19:36:51 -0700 Message-ID: <1529462205.2333.83.camel@intel.com> Subject: Re: [PATCH V2] x86/efi: Free allocated memory if remap fails From: Sai Praneeth Prakhya To: Ard Biesheuvel Cc: linux-efi , Linux Kernel Mailing List , Lee Chun-Yi , Borislav Petkov , Tony Luck , Dave Hansen , Bhupesh Sharma , Ricardo Neri , Peter Zijlstra , Ravi Shankar , Matt Fleming Date: Tue, 19 Jun 2018 19:36:45 -0700 In-Reply-To: References: <1529350614-15555-1-git-send-email-sai.praneeth.prakhya@intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > > Thank you Sai. > > But this is not really what I meant. > Ya.. sorry! about that. I had a hunch that you might be suggesting something like below but I went ahead with this implementation as it looked very simple (just 3 insertions and no deletions) > How about we modify efi_memmap_alloc() like this > It sounds like a good idea to me. Leaving aside the pros (which are obvious), the only con I could see is few extra checks and some code but I don't think it's an issue at all because this code is not in fast path and it dosen't impact performance. So, I will post a V3 with suggested changes. > @@ -39,10 +39,12 @@ static phys_addr_t __init > __efi_memmap_alloc_late(unsigned long size) >   * Returns the physical address of the allocated memory map on >   * success, zero on failure. >   */ > -phys_addr_t __init efi_memmap_alloc(unsigned int num_entries) > +phys_addr_t __init efi_memmap_alloc(unsigned int num_entries, bool *late) >  { >         unsigned long size = num_entries * efi.memmap.desc_size; > > +       if (late) > +               *late = slab_is_available(); >         if (slab_is_available()) >                 return __efi_memmap_alloc_late(size); > > and introduce efi_memmap_free() as before, but pass it the 'late' > parameter you received from efi_memmap_alloc(). That way, it is the > caller's job to take care of this. > Sure! makes sense. > Also, it seems to me that efi_arch_mem_reserve() leaks the old memory > map every time you create a new one, no? I think you are right. The issue I see is (please let me know if you think otherwise): 1. efi_arch_mem_reserve() comes up with a new memory map and then tries to install it via efi_memmap_install(). 2. efi_memmap_install(), unmaps the existing memory map and installs the new memory map but doesn't free the memory used by the existing memory map. Hence, as you said, leaks the old memory map. If this you what you meant, I think, the issue is not just limited to efi_arch_mem_reserve() but to all the places that call efi_memmap_install(). I think, we could solve it as below diff --git a/drivers/firmware/efi/memmap.c b/drivers/firmware/efi/memmap.c index 678e85704054..50ae4ffbf058 100644 --- a/drivers/firmware/efi/memmap.c +++ b/drivers/firmware/efi/memmap.c @@ -228,6 +228,7 @@ int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map)         struct efi_memory_map_data data;           efi_memmap_unmap(); +       efi_memmap_free(efi.memmap.phys_map, efi.memmap.nr_map, efi.memmap.late);           data.phys_map = addr;         data.size = efi.memmap.desc_size * nr_map; Please let me know your thoughts on it. > That is a separate issue that > you may want to look into, but it affects the design of this API as > well. Probably, I could have misunderstood you here.. but I think the efi_memmap_free() API in V3 should work (without changes). Don't you think so? Regards, Sai