Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4910407imm; Tue, 26 Jun 2018 02:40:21 -0700 (PDT) X-Google-Smtp-Source: ADUXVKICcAMejEUXQJNGSUmo5W9nahHL+HfoJZFTG1ieWlB/PF5OtwxQX18r/RtvE4WyWJLsjc0w X-Received: by 2002:a17:902:7202:: with SMTP id ba2-v6mr813215plb.119.1530006021011; Tue, 26 Jun 2018 02:40:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530006020; cv=none; d=google.com; s=arc-20160816; b=CjqsQnaZV10I1n0JhNS+ziLcEcJJU4nqI5jgTAcigfNr5VXnuuxCpcTEQJdOw4ti9/ XltxnMs59AyICeIikNXaO3BEHRmkslXYJa0bnCEJ5GNIv+yPVJnOiwQPP1tYKWgeLCek PyMEpmrHeXXMRDyEZyLYUZiFIr4qBR4cc4AVPmhxg6o8MDUexdDtwGPViS4BeUeNLYZa 7mP2AjeoqHvnTItVgdq9V+UnJpjCKwsErnF5TK3NBW8NVu/Yqq+FT1zu5alp5TXqDWgy 4KHbORcM1xgIlsd7wDU8fQcbZSU1Kiyu3/mqjr1aMgiMV466Z9abomP5NpeaFlXH6v1w GbZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=O1PE21a+PRmUcGf63OZtspYftsekjt9p1IUenxV/JDA=; b=iD5P1Si+O4r7FFIYLgFCn4E4nkDeQRfjwvD0qDC9OOZWXhelQRBDSgMvSU8MWaWPjY pfdQJsIUUvdsMf6G6SfQXik8bvU6cqHGhxiKVsDfp5fwYqGUEBOBGRiQ5lhMoEYX7CWn i599eH1QLzpM6LPR/UU/seesOH2AMOABe+2NbNsyT/mBPKpkUtSOS/x5fshh9PVGefbI F1y+p6TEEkHNSLfUqvuJmAaYZBbW8sBnWQWtn4oFdbbOo1M3d/EDbJ4yXhK7OE0Yyv+g XuZTgfVDo43bMJlCmam51nOp7MXcGr2t32EpNliDnNugAn5cLQb51TDsld3eqoQzfo5z 7sHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EjIQqMRo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b18-v6si1223338pls.292.2018.06.26.02.40.06; Tue, 26 Jun 2018 02:40:20 -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; dkim=pass header.i=@linaro.org header.s=google header.b=EjIQqMRo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934275AbeFZJiN (ORCPT + 99 others); Tue, 26 Jun 2018 05:38:13 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:51090 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932206AbeFZJiL (ORCPT ); Tue, 26 Jun 2018 05:38:11 -0400 Received: by mail-it0-f66.google.com with SMTP id u4-v6so1353579itg.0 for ; Tue, 26 Jun 2018 02:38:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=O1PE21a+PRmUcGf63OZtspYftsekjt9p1IUenxV/JDA=; b=EjIQqMRooMXXwjYEhg9PFq167AIiU9/hsGMciPvt8S09dfDaHQmJ3OEV5i6Ee29Qwu FjZd10uhRRzbih+8VFmF08nXbVXRAWItrbt4xirc+dW9G5Btn863rDqgnBYLMo++RhGn dP9UgBLzcAmZpl3Z8Np1QuDmr5PPIxcRWB9Xw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=O1PE21a+PRmUcGf63OZtspYftsekjt9p1IUenxV/JDA=; b=MArRxg91Wxar2Zxvg28UeUHMwm43pr8y+n9//6uvEsuo22Y3UhansMEy8UwZrm58qz VQJ0qPBsDGUU1/mgDqrJEU/fKYs8OgVYUgvXGr+NQABzalTJuTfytlLNOW8lu7T6knNH 67aYqYFkU5+FC26UlPS3oDJRbXMW1hgGi7n1eMep1izjHA5+qUgd7GMemyosg/Bd20Ed RxW3L+CB+s152fmpoqHFcMvpypPinBbp7nftQJg9cRN4m76s9xzcZlvy1Cc4GtHdpxma gXmop7E5BDl8u7LLvVmzpAIKQoJ9pp1NkaI7oriLxQJwV84ShvXAuaQeJ1i2L9bISuDR gA7w== X-Gm-Message-State: APt69E0Qf7T41VnryOWAsbEyyu+125ezFKT3fLmk5u0P/nyOPFDZnN7w BJ2XRTOLXuFRPZUrcwi6/o1uFAgDCJqv+WckZDfNTg== X-Received: by 2002:a24:d7c5:: with SMTP id y188-v6mr782300itg.50.1530005890530; Tue, 26 Jun 2018 02:38:10 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:bbc7:0:0:0:0:0 with HTTP; Tue, 26 Jun 2018 02:38:10 -0700 (PDT) In-Reply-To: <1529980892-11833-1-git-send-email-sai.praneeth.prakhya@intel.com> References: <1529980892-11833-1-git-send-email-sai.praneeth.prakhya@intel.com> From: Ard Biesheuvel Date: Tue, 26 Jun 2018 11:38:10 +0200 Message-ID: Subject: Re: [PATCH] efi: Free existing memory map before installing new memory map To: Sai Praneeth Prakhya Cc: linux-efi , Linux Kernel Mailing List , Lee Chun-Yi , Borislav Petkov , Dave Young , Laszlo Ersek , Bhupesh Sharma , Ricardo Neri , Ravi Shankar , Matt Fleming Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26 June 2018 at 04:41, Sai Praneeth Prakhya wrote: > From: Sai Praneeth > > efi_memmap_install(), unmaps the existing memory map and installs the > new memory map but doesn't free the memory allocated to the existing > memory map. Fortunately, the details about the existing memory map are > stored in efi.memmap. Hence, use them to free the memory. > > Signed-off-by: Sai Praneeth Prakhya > Reported-by: Ard Biesheuvel > Cc: Lee Chun-Yi > Cc: Borislav Petkov > Cc: Dave Young > Cc: Laszlo Ersek > Cc: Bhupesh Sharma > Cc: Ricardo Neri > Cc: Ravi Shankar > Cc: Matt Fleming > Cc: Ard Biesheuvel > --- > > Note: Patch based on efi tree @https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git > > drivers/firmware/efi/memmap.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/firmware/efi/memmap.c b/drivers/firmware/efi/memmap.c > index 678e85704054..68b27b14fe94 100644 > --- a/drivers/firmware/efi/memmap.c > +++ b/drivers/firmware/efi/memmap.c > @@ -229,6 +229,9 @@ int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map) > > efi_memmap_unmap(); > > + /* Free the memory allocated to the existing memory map */ > + 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; > data.desc_version = efi.memmap.desc_version; > -- > 2.7.4 > If only it were so simple :-) At this point, efi.memmap.phys_map could point to memory that was allocated early, allocated late or simply passed to the OS at boot time by the stub (in which case it was memblock_reserve()d but not memblock_alloc()d, and it should not be freed) So only allocations made with efi_memmap_alloc() should be freed here. I'm not sure /how/ we should keep track of that: perhaps it is simply a matter of replacing the boolean 'late' with an enum that describes where the memory came from that phys_map points to.