From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2E7228E0 for ; Wed, 13 Apr 2022 09:59:32 +0000 (UTC) Received: from zn.tnic (p200300ea971b584e329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ea:971b:584e:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 5A3651EC0541; Wed, 13 Apr 2022 11:59:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1649843961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=Dzm9Q8xBuRXK4mGHHOX6fanOLpLEt+HqmgdG3ufabDI=; b=kH4m8hby7lSr/nMjW8zktpQlA5REnvZ5SauP0KqRlKsBQmvZycCStBD+i0x1w0MNO3FcVE heBC7WWUJoYOLsqKKZ9EHpGKiA/+a8NcKpj76cq7Rh59uWDhIM+8QBrghXme/2ZhybIA/O 8j+GVlgmmD0cxpv7CmiaWxrlWyNuLic= Date: Wed, 13 Apr 2022 11:59:21 +0200 From: Borislav Petkov To: "Kirill A. Shutemov" Cc: Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel , Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Varad Gautam , Dario Faggioli , Dave Hansen , Brijesh Singh , Mike Rapoport , David Hildenbrand , x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv4 2/8] efi/x86: Get full memory map in allocate_e820() Message-ID: References: <20220405234343.74045-1-kirill.shutemov@linux.intel.com> <20220405234343.74045-3-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220405234343.74045-3-kirill.shutemov@linux.intel.com> On Wed, Apr 06, 2022 at 02:43:37AM +0300, Kirill A. Shutemov wrote: > diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c > index 01ddd4502e28..d18cac8ab436 100644 > --- a/drivers/firmware/efi/libstub/x86-stub.c > +++ b/drivers/firmware/efi/libstub/x86-stub.c > @@ -569,30 +569,28 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext, > } > > static efi_status_t allocate_e820(struct boot_params *params, > + struct efi_boot_memmap *map, > struct setup_data **e820ext, > u32 *e820ext_size) > { > - unsigned long map_size, desc_size, map_key; > efi_status_t status; > - __u32 nr_desc, desc_version; > + __u32 nr_desc; > > - /* Only need the size of the mem map and size of each mem descriptor */ > - map_size = 0; > - status = efi_bs_call(get_memory_map, &map_size, NULL, &map_key, > - &desc_size, &desc_version); > - if (status != EFI_BUFFER_TOO_SMALL) > - return (status != EFI_SUCCESS) ? status : EFI_UNSUPPORTED; > - > - nr_desc = map_size / desc_size + EFI_MMAP_NR_SLACK_SLOTS; > + status = efi_get_memory_map(map); > + if (status != EFI_SUCCESS) > + return status; > > - if (nr_desc > ARRAY_SIZE(params->e820_table)) { > - u32 nr_e820ext = nr_desc - ARRAY_SIZE(params->e820_table); > + nr_desc = *map->map_size / *map->desc_size; > + if (nr_desc > ARRAY_SIZE(params->e820_table) - EFI_MMAP_NR_SLACK_SLOTS) { > + u32 nr_e820ext = nr_desc - ARRAY_SIZE(params->e820_table) + > + EFI_MMAP_NR_SLACK_SLOTS; > > status = alloc_e820ext(nr_e820ext, e820ext, e820ext_size); > if (status != EFI_SUCCESS) > - return status; > + goto out; This looks weird. With the goto out of the way, this code turns into: status = alloc_e820ext(nr_e820ext, e820ext, e820ext_size); if (status != EFI_SUCCESS) { efi_bs_call(free_pool, *map->map); return EFI_SUCCESS; } I think you want to return status as above after having called efi_bs_call(free_pool, *map->map); ... -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette