Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3665371rwr; Sun, 7 May 2023 17:24:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ49m5XP+t+HBzCG4bOfxq3cR/LHe/A/mNKkI39UK8cYT+Xge6nBbjLx5j9IwYoI2gKuLCuM X-Received: by 2002:a17:902:d504:b0:1a9:98ae:5970 with SMTP id b4-20020a170902d50400b001a998ae5970mr11969471plg.23.1683505490804; Sun, 07 May 2023 17:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683505490; cv=none; d=google.com; s=arc-20160816; b=HK6akx5hYutqr57UIKBK9Qu0mDLpfCsiTMv468TubKnb9BhvxXprda3NayMxuV3oLs 6iNYcWPLOIaOrbX1PkyJ1V3CcooxoQYXIeTlBHbEyKaLuM6PW8zPbD/00ag7Zh0wwWQz Q3/UTIGXfNYFnO6XB50BzlRMDkC0xKeUcc/YHaXobOWnoqioh+U44VtsNC32utyswydj pq+bMHbqa8oNzt0B9UfiIefFWpQ7NVEzx36JYGLQY1yUMOGMUO5UyEewrMfuAC6VbWqM tR7kuKXBzhyf1X+DjGvMh1dfi+jeMA9AlicIIyBHFU+7n9Nn51xQlJhWqr5qTma1BruJ 9v9w== 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=sv6wo6vxOffMBn9+KXstoWGKRgNi5dzIFAWw39uzvSo=; b=ej7GpY0feSv6YPrtyWUCfbEMZKLKqDLrfqAaawoB9Tjrofj56qMg08wBAJsjn9Ee41 ng1AddBFgsVorXkL69tWd+NeH242yapAssOH9ixM0jy/0va5D6cxW4zbYymNvfdRjowz ye6HlgGqQuPMtl9oMH9Nia/owSweTV5/b/QriY4JQdEbtnAO6jrOvYIWX5zUBjaWIT7T Wt/56hVMiEGPz6ykHk+YP7aZWncWCHH0fPyEQaHU5KEvMe7/7y6F8IWJMt940TO59iCf dG8BUsVc29LtSYKhCTezTdA5+NlVlzXWGr+w9l+2GTxwx/wVcU7e/YzUkbM9FBK39tGU xtCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HjIcfBaC; 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 c9-20020a170903234900b001a63ba2c894si6558355plh.548.2023.05.07.17.24.38; Sun, 07 May 2023 17:24:50 -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=HjIcfBaC; 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 S231967AbjEGXqh (ORCPT + 99 others); Sun, 7 May 2023 19:46:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231644AbjEGXqf (ORCPT ); Sun, 7 May 2023 19:46:35 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46F00A27E; Sun, 7 May 2023 16:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683503194; x=1715039194; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BwDi/PWmIK31K/TDtylUIn7yoV9Lz0nwLx+9+7bRLdU=; b=HjIcfBaCWbV37lZxHGWvRIM90/E/3/w03+DMOXP0OpefDhLYpR0So34E kQwXmtpI71p1kHED8HPKkA7KDeX4AjvVO9Djb+bRfZDyYOF6RaoDbgt8S 3l3SOTLjK1wYO0zJyy54SHYgssquQMEt06uC0ZIG1TgGrA+y8gS0mudOb CZh1hfkHzo/+vYCHdVc7cLVCcWTmngs2p9YXlzmU5LHkTYjtZ6BFkk0My Kqd0hm8UDVAIBLxY/bZTXcx9cOcHT/i9v1jDk44LnpTjv4mErqfUFY37+ r3sv4nXz5x2ySrdRpQ8X+x3W0LV1+ywVWzRK6NZh59O2s5vNcCZYOVcbS Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10703"; a="333953473" X-IronPort-AV: E=Sophos;i="5.99,258,1677571200"; d="scan'208";a="333953473" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 May 2023 16:46:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10703"; a="675852933" X-IronPort-AV: E=Sophos;i="5.99,258,1677571200"; d="scan'208";a="675852933" Received: from dancaspi-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.61.73]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 May 2023 16:46:22 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 1B12C10D1E8; Mon, 8 May 2023 02:46:20 +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: [PATCHv10 02/11] efi/x86: Get full memory map in allocate_e820() Date: Mon, 8 May 2023 02:46:09 +0300 Message-Id: <20230507234618.18067-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230507234618.18067-1-kirill.shutemov@linux.intel.com> References: <20230507234618.18067-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 --- 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