Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2005922rwl; Thu, 30 Mar 2023 04:53:51 -0700 (PDT) X-Google-Smtp-Source: AKy350Zzczv3PK/qlzXZxb2V51gA4zisJEPqVaLW8fQWurgyKKbF+7DOCgEamSArWWtoCx3QGsSS X-Received: by 2002:a17:903:647:b0:19a:7217:32af with SMTP id kh7-20020a170903064700b0019a721732afmr1950243plb.5.1680177231493; Thu, 30 Mar 2023 04:53:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680177231; cv=none; d=google.com; s=arc-20160816; b=RrhIr7jwr7Y4brCU3cLpwe1/lwz9UKtU0wuIqHiyClV9RklRG1vWrD9eybpDIPKIOk 91uFNdnWL7t0GX5CNi4e8eZUfTveAQnoMkrCbAY691i8WzkXtQ+ZJlzBCSJzO7sUeW3G whsSlxpfBeXZ90eJjag8bsm9dRzoEXqhWt+Q4RDe4icfHHRqWKNqPm2FQb7Nr+/gQamf PpljVTIkAkR+sLYHe79VY04x5gb19NlZSd7d5sA7QN9TqBIqVq71NAjtoY/2wMXh2nUg O7FBrDOWt3WW/iHYDO4v8A4TGqDwwDnKYs0pjj+pz4AINxK1z0O629juYhf+SzBt1rXE eJxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ruFNRYlkeA7U/LySXAwK77bGHsdZfakSttMzy8rXOc4=; b=LTbvB6/CGOdidj35id70LZ9NowexCny1/62uIV8rzncCDW69Kxbv1pielSz3gLydcX mE1v6aOZR1k/YNlPekuGAlAE79qupcmM/BVtOKliFD6dGvnlo0wM8zYgUWwKvGb+29/I Et/LXY3mOVDu+TP3vOlrFRXqEMDF2hArU+mCpvYXiBdY7JxnAzXL9qWsnGTCmZlW5s1E S2YRYqQCq1tzhJFPMIIGo9bTxzemWEGVEeqcGvCooE6i45WNJeXAl3mCW/lfqzK9KeuL 6VizeigB7Ydbl6qL13mCiOwmMxm07wG15a31y7Cqz9V3cOkLp6dCP/zgWGZvur6Lb53n ZNDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Uv/jmmuo"; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h5-20020a170902ac8500b001a220a6b915si13842094plr.613.2023.03.30.04.53.33; Thu, 30 Mar 2023 04:53:51 -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=@intel.com header.s=Intel header.b="Uv/jmmuo"; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231676AbjC3Lvr (ORCPT + 99 others); Thu, 30 Mar 2023 07:51:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231389AbjC3LvZ (ORCPT ); Thu, 30 Mar 2023 07:51:25 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18281B752; Thu, 30 Mar 2023 04:50:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680177052; x=1711713052; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hKxUht4bI1oBBOH1u/ajoAci1RdtaLogFa2+swkKZCg=; b=Uv/jmmuoLoYKJ8UjANEx2N6XOOeAhaSg5B+qklgkL2E/7Qwego/4EHXG Una+hqXS/Ti1zO7L9o2vS+t/BM04oaj+RRFM/jd/f6FEnZ/LUcHd72eVz x1sNfCaUMiajo8ilKx1C/zoLfXvXYQVJ96pyDqLiv8A2bh/rgHSPywmIG +pCPR4EvciEbP9AAUNl7y/o/TMkYgl4jgElflClq/sctJQukEeqMp3Epc Ua4TnaaMXrVWolFHoIQiGTuU9mXZltqfFfJ+sqfN60jjz1B6Sk6TbqxHA WjHix9i0vxBWKqu/vwYo27XkDSznCcqYNbLTJiaJeR1e1aMyK3mR6Z2Xz g==; X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="342756785" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="342756785" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="634856509" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="634856509" Received: from ngreburx-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.209.91]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:17 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 1B89A104390; Thu, 30 Mar 2023 14:50:00 +0300 (+03) From: "Kirill A. Shutemov" To: Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel Cc: Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Dario Faggioli , Dave Hansen , 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, "Kirill A. Shutemov" , Borislav Petkov Subject: [PATCHv9 05/14] efi/x86: Get full memory map in allocate_e820() Date: Thu, 30 Mar 2023 14:49:47 +0300 Message-Id: <20230330114956.20342-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> References: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 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 --- 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; - - nr_desc = map_size / desc_size + EFI_MMAP_NR_SLACK_SLOTS; + status = efi_get_memory_map(&map, false); + 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; } - return EFI_SUCCESS; + efi_bs_call(free_pool, map); + return status; } struct exit_boot_struct { -- 2.39.2