From patchwork Thu May 18 23:14:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 13247504 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 672C0C77B73 for ; Thu, 18 May 2023 23:14:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5739900005; Thu, 18 May 2023 19:14:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADF94900003; Thu, 18 May 2023 19:14:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 958DF900005; Thu, 18 May 2023 19:14:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7E473900004 for ; Thu, 18 May 2023 19:14:55 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 31449AE40B for ; Thu, 18 May 2023 23:14:55 +0000 (UTC) X-FDA: 80804932950.26.3FADB30 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf18.hostedemail.com (Postfix) with ESMTP id 4AAEA1C0011 for ; Thu, 18 May 2023 23:14:51 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=DC06KNWH; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf18.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.20) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684451693; a=rsa-sha256; cv=none; b=Kdaj1ed8EbyJjXS+yWgzMmElb6EKhZpmUemf+ZQRYv41xPuFSjhAI7kzFLn+npc6/MylK5 w+9bSwOlajIxYa+2N2J7OSBk9fy/tvljsAVxPM58Wy09FJ5UqmGxLekGPgeml7WechGFxq xFM5ut+H2pixQYLU7xoOO3kw7wDvj14= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=DC06KNWH; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf18.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.20) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684451693; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BaZyb9j0toOFpXjTH7X5V8WTk1CeGrfyPyJRw/21oXU=; b=r10B1LYTAyP3ZakP4lSYDgjIUSe1BipQv/SFWznQDk0F0bn7kERZ33fv58iKvUprjDm02N DuTC+NiVYKOYK0TMGAKMRSQ0zFSGEerYeMJROQ4z69IpDxiLkFmQSZLsLOaqoKC1ezzLOq XEkcjtiilaZK1g9QdAZp86h2IaF4iYM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684451692; x=1715987692; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LJWuKaqvYOvqAXDR1TKqUlI78Dny7nmmQ0aMOVcXkCg=; b=DC06KNWHKgwqrKSPdqeutaWGgg4aR4MpDQSCdxojG7oFVamKFMwJU2my OMN7+byX4ULn9guExbElvZHUZpf97x7JXIsm8lPlpX/zMavDUb0l6d3NO Ae3y1jKZ4XA8Fr11lD4jW1qg5wizBk4UPYNptrzKNVnze1Uj7+SRNIRIU 31jPoJAT4qsu21fxyKDuYvsmKbQaEV26jsugFNTYEmtwPSCK0t+lnDAns 4KJcJCPid6UfF6CNK2EBibQSGvW/vNew8xBb/x45AvzK0RHbduK7kE0mR PZ9I6inpd0YZ7T3WvG47Dc9RemGFXrmLjbJZQSBkvdvs/7lLN6QVZvGUL A==; X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="341652060" X-IronPort-AV: E=Sophos;i="6.00,175,1681196400"; d="scan'208";a="341652060" 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 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4AAEA1C0011 X-Stat-Signature: wk8xbrzgkne16tqjx696mtfk51gmkq8k X-HE-Tag: 1684451691-588167 X-HE-Meta: U2FsdGVkX185gN+qYs8Bqmp/XWa4B0cKsvGA1al1xerz8tJTXbr91FKRx39ziyjxc7fATjILbesQtWubjN7d0sjWuTOolhtzEpt+ddhvPBiffX7cVibE0zEGMG+U6Glg/dmFKNV62iOCr/haQ2MAlitbgvGtz7ft7Vt3fXEfX6KLe8LDlPNvjL2gN8cZ2ye+cVby9Qkek3pGjEqttqzGnccNl5v4+ceBlgL00Jg97kknbsRUkYXhzjhDRA6bkovCtGCrTPFs693Cabbngb2d+122Vq3d6cVMxoJV2SQdPS7XTGsIJNmgzZc9MKrBtWchLCzqc4QtFdhoacGUgaUjx+/8vJCfKqUgskVPzc4/aJHHihaEmMj8oHycJWDCbbhGhzYD7pWjsDlQRQesruziv0edTt29atkv5idGlf7UtVk4X11yujM/ksdOXhGqkLEEtxHumaIugJrjQdAWtIOt6eMj5h8kARw5Fgm60d/7dDh3M6XR1GfiPQlL+LRUH/8Z4I6FScG+qB8XQzn/y1lHDQFmmPbRzASKNKLd2Sr2yKc/wUCTaCG3e0Fiwl7RZrf6foVK7l6i5MrszPKlhxgkNZ4MwG5FxixK/mQM+Wys5GkEPD8fMaaD0v9FzaRahbXe0WXTyzQ0L/jMeqtVXJgPLeBjZHhV4kmjmA0EKp2MTFbv34Dkv+ILtTCvB+Lgnu0bhXvvGzkf3KvljM8cgHb+Q7IAQA394xP5KUsOYOp/a/NeCNP7Zjl6WBr4Q9d8Fu7zlzNQ0gORulRJZ8vnLgZWew4WqOurQXyc8+1CtpgtT7NTODLchNiChKnuVrNaCbDNRGw9I9Bi44UR5BQqEJSddob/jHQl2d72wQ8Dk1WFm/4qGTvVI5X7I1uRlWjKG5OgVUDQX+5xvRuD6lhnkHaSnWDed/VH1na08M9wBtILpwybg3mnktCunhaPEePYz3qLnJ9S8V3D4dW1M4fbx7O AsKa3ZGV eFHpBsQrBMAOr3hbkhnkjRvwREoNBi6xNutF2pD+YDiUJd1rAxCECYKOO0Jx9DXWyaG+XpfSkh2rJDJN3j5+RjhZK//t/EsuM22ANbQmTju61K2Do92tjgMqdQscYEXkmR2QuOn3SXBI6QT53soT3JDSSgQ7NH0q+k0MMsJRHaru0P7QtgnfKYHmRrjOpizC7+4Eevxmwio2czPCYo2G4eF4r+ldh9WZ4RakrvQKMPrA3D335zVaSPDgJ5FxRBtTcBzW0397bpaeZbJw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 {