Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1701665rwd; Thu, 18 May 2023 16:18:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5iUMuag/rVSUbTJqKVlH0oglV/as7nSpsysikZY5kYYaaG37dYLuDi9+5EjpzfJaojgZd7 X-Received: by 2002:a05:6a00:1a12:b0:643:aa2:4dd9 with SMTP id g18-20020a056a001a1200b006430aa24dd9mr725685pfv.7.1684451933686; Thu, 18 May 2023 16:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684451933; cv=none; d=google.com; s=arc-20160816; b=CS7yWBJ8Od0BwjB4YX0STMBBjzN6LrmVfmQuR1deYyL0pn5B49jRkyY1oSGdMgq0oQ xW88Pk2dT+XAV5MdsDGDoi8txnpQwth8DcEzMEQsnGEoPCXEVkSkcnur3rIdxNxo1zac 5Iu5R0yvukgmmqbkB6UP2gNs4O0P/IPrIk2Qwdxo5CATMbdImbGHgBj0R6q+VB4pxDSi lG/VXpVr0O3Okx4Lj9U+4+4WtDhNZJQBQerwfV/bV3kh0gRLyhPxPJf7CsNen2zyRYpQ pkW/Ksrpoi6a/fosZKalC9MkPp1K05PvDM6zVJnCj+ZS1nV4ujU5JkXI5NY0uvq/Mojd 9syg== 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=BaZyb9j0toOFpXjTH7X5V8WTk1CeGrfyPyJRw/21oXU=; b=qagKVvoU3V7Vg+WEru9VGSau+7W1NMcFcqJ4+iQ17dKHqEXu7CyEpOoQtnXv0oTW8t UjzbdKMPge6CwCjqFUZKrCeTOoP+1J2QnkuYywniHWUAlTLZUYNQtAx5X3MEZuq4B+bh HdirNwsbkX79fD8hJ+MxgyuY2xmuu8+p31JKGUy1/inBDUMHbocxPCuk9CNwbO/oxLgA iLtF3SUEo0irLKqwB1Zr/MO9jgrSF7M8Y9D0Jcv7TsnIfdWfs8XWoPR3u8F7KPcAV4jo 9+FMtjJHk6+oqtqg13r8j5QprkRYm+kqF/h7rMk6LDgxtKULodejREBbcWCcgGF+YTac Ik3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="G303A/Qu"; 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 z13-20020aa79f8d000000b0063c2972543esi2745387pfr.335.2023.05.18.16.18.40; Thu, 18 May 2023 16:18:53 -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="G303A/Qu"; 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 S230044AbjERXO7 (ORCPT + 99 others); Thu, 18 May 2023 19:14:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbjERXOv (ORCPT ); Thu, 18 May 2023 19:14:51 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E89E3E48; Thu, 18 May 2023 16:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684451690; x=1715987690; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LJWuKaqvYOvqAXDR1TKqUlI78Dny7nmmQ0aMOVcXkCg=; b=G303A/QuLi10GQZWr2fLSW5eXRV/AgkIALDsn9v66paL4d28vAn+Rk5q cm815CRJ/xxVRPtuAXo25cTfanOQDRYJRkc4Z4xkJershL+zT0xuQb5Lj 3VDRi5gN657SeoYnxDzwiJX6Qw5xDJLKAFmv7eh2lp6l/C1AaoTtwIdha KeDhg4SM32DRnwWDSGsHEGBf4BH1CYGfKmZdZP5WW/nHnf9yFenjRY2gk 0y1uf8KFCKAPcBM+9fPtH6V16dyV8GPX+T8Y9wusXZkTmV6tjK09xP/lK rujNWcdqsPkcDmXEdi+TjviiBWmcZhRKC6K+9nBr3qm052EevgLcXTeKS w==; X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="341652063" X-IronPort-AV: E=Sophos;i="6.00,175,1681196400"; d="scan'208";a="341652063" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 16:14:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="772065073" X-IronPort-AV: E=Sophos;i="6.00,175,1681196400"; d="scan'208";a="772065073" Received: from rkiyama-mobl1.amr.corp.intel.com (HELO box.shutemov.name) ([10.251.222.16]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 16:14:42 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 2A6C610DFC6; Fri, 19 May 2023 02:14:40 +0300 (+03) From: "Kirill A. Shutemov" To: Borislav Petkov , Andy Lutomirski , Dave Hansen , 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 , 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: [PATCHv12 2/9] efi/x86: Get full memory map in allocate_e820() Date: Fri, 19 May 2023 02:14:27 +0300 Message-Id: <20230518231434.26080-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230518231434.26080-1-kirill.shutemov@linux.intel.com> References: <20230518231434.26080-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,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, 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 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 Reviewed-by: Tom Lendacky --- 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