Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4003140rwr; Mon, 8 May 2023 01:03:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7/44cO7KrDmnKjmkk8OF1hMHpd8svsvKYFnKhURPZDpfy++7ndMT24lGFIKFJSv3U5MwNy X-Received: by 2002:a05:6a20:918e:b0:f2:45fd:1de2 with SMTP id v14-20020a056a20918e00b000f245fd1de2mr12792795pzd.19.1683533021518; Mon, 08 May 2023 01:03:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683533021; cv=none; d=google.com; s=arc-20160816; b=xumK7j3c/BMxJvsl3lFeWywFIByAWXW/fcpgL+vLgst+Iill1ynv/+539Q5/8EZrG+ ZX5Det993hvNATYBodH973sTeR7C6DUS0mhzMaxqsTMvY4lGmZD7xGoB6mJAypqYY1kW B2kHGu0xCrU6eEUNmNNxdQmIiK+MBOM8G5A/yz/9mJM6PwWghVSZwqQavlGs/1p/eEIo uDNhvpc0BKbefiLFh3UZWNRaq3BYjw96Kz09BHtMUkmgwGCsAMe43yAn1qxwfv9ket/V kfVw5J9D2XdOQrquuDTf2oAaRcSbx1gVnR8mtJrXVDOhKyzsOrQ8HdSjvFM3B60gF7Zw PqCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=MuCrFG+6XI9zHt/XFSgNbP6lGV8sGfC9nxx+jDBSzgk=; b=aqR6+P9HX8hV/zYzlJNZfzfdAe5b5ztUuh0u0Ea7XopC/Cyvi/I3z+Q+WXu2TJ6Ire Uyb3bNWj+nD3Jom5nQMrhDjkgkbYcVCtF8oBuBQQ5JNugqFjwVW6qa+Ucfz03sUGjbJ9 a+46e7aUdFpZ1wd4cfBiB+qO7/04XxSOcq1dVdyfs1BHt35asZa7rv40hV6nFD6UKScL gbYybtZpF9RcYEN2zNO0tIDKsSUOdKPrQjq/2xrhf4YxBDWm/BVHwFa2FIjlpKd1X1MW xHvvvA4J25VWys03a2T9RyGzLa/ARvunbn6w7PvRQifQvMZUVEaYMIgpvssUiNotgoIS 9iDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="AVS+L7/p"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o29-20020a63731d000000b0052875a200fesi7784414pgc.215.2023.05.08.01.03.27; Mon, 08 May 2023 01:03:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="AVS+L7/p"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233072AbjEHHUB (ORCPT + 99 others); Mon, 8 May 2023 03:20:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233217AbjEHHTy (ORCPT ); Mon, 8 May 2023 03:19:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6A55E56; Mon, 8 May 2023 00:19:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 323FD61FED; Mon, 8 May 2023 07:19:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E252C43444; Mon, 8 May 2023 07:19:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683530391; bh=6rOQ5NbJZcxzZSxkaCY+XurJ69PAlQjGw84WzWS8G1Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=AVS+L7/pJIeUn0n9W87kFXUcETAPzGxN1m4r3j+rxHh93FZ+1kjOn8qxRwvpgwW4D kQdYGkurJwrrrIlYczUphQq37LlzvhJp/N5CMEzYZVmiGUkfe7q0l6C0xEH5dUlpl1 kPrXbyapvWYUWgJwTrrcklDJEpiQseQNMtwdBv/tFCepoMTAUIsBZpGAs1/2BF8wQO ACqilnqVQBBkMBURdaWjbNl7U32u7zfWQlyHqe2MBNzNg79/030jTKztqI9qQz3+jt TVK8xaCXS/KfhhE2LChb/9+HDLoIrXSJuwkeNIDEa2rR5XEQLkHHFKMVTozoFdzN6C F0mWb9E/MAZ7Q== Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-4ec8149907aso4782500e87.1; Mon, 08 May 2023 00:19:51 -0700 (PDT) X-Gm-Message-State: AC+VfDz2PZELH03i0EN5RAdrfSSNtuxuXi09EEZ0cSMNdxQ01VaX2+7g 6wJDU8N1lBQxDmvNfboXfXYEc5YQJRcfdO97p5Y= X-Received: by 2002:ac2:511d:0:b0:4f1:4040:8143 with SMTP id q29-20020ac2511d000000b004f140408143mr2574670lfb.60.1683530389163; Mon, 08 May 2023 00:19:49 -0700 (PDT) MIME-Version: 1.0 References: <20230507234618.18067-1-kirill.shutemov@linux.intel.com> <20230507234618.18067-3-kirill.shutemov@linux.intel.com> In-Reply-To: <20230507234618.18067-3-kirill.shutemov@linux.intel.com> From: Ard Biesheuvel Date: Mon, 8 May 2023 09:19:37 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCHv10 02/11] efi/x86: Get full memory map in allocate_e820() To: "Kirill A. Shutemov" Cc: Borislav Petkov , Andy Lutomirski , Dave Hansen , Sean Christopherson , Andrew Morton , Joerg Roedel , Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Dario Faggioli , Mike Rapoport , David Hildenbrand , Mel Gorman , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, aarcange@redhat.com, peterx@redhat.com, x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 8 May 2023 at 01:46, Kirill A. Shutemov wrote: > > Currently allocate_e820() is only interested in the size of map and size > of memory descriptor to determine how many e820 entries the kernel > needs. > > UEFI Specification version 2.9 introduces a new memory type -- > unaccepted memory. To track unaccepted memory kernel needs to allocate > a bitmap. The size of the bitmap is dependent on the maximum physical > address present in the system. A full memory map is required to find > the maximum address. > > Modify allocate_e820() to get a full memory map. > > Signed-off-by: Kirill A. Shutemov > Reviewed-by: Borislav Petkov Acked-by: Ard Biesheuvel > --- > drivers/firmware/efi/libstub/x86-stub.c | 26 +++++++++++-------------- > 1 file changed, 11 insertions(+), 15 deletions(-) > > diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c > index a0bfd31358ba..fff81843169c 100644 > --- a/drivers/firmware/efi/libstub/x86-stub.c > +++ b/drivers/firmware/efi/libstub/x86-stub.c > @@ -681,28 +681,24 @@ static efi_status_t allocate_e820(struct boot_params *params, > struct setup_data **e820ext, > u32 *e820ext_size) > { > - unsigned long map_size, desc_size, map_key; > + struct efi_boot_memmap *map; > 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; > + status = efi_get_memory_map(&map, false); > + if (status != EFI_SUCCESS) > + return status; > > - nr_desc = map_size / desc_size + EFI_MMAP_NR_SLACK_SLOTS; > - > - 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; > } > > - return EFI_SUCCESS; > + efi_bs_call(free_pool, map); > + return status; > } > > struct exit_boot_struct { > -- > 2.39.3 >