From patchwork Sun May 7 23:46:09 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: 13233947 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 58421C77B75 for ; Sun, 7 May 2023 23:46:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9EBFC6B0078; Sun, 7 May 2023 19:46:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9757C6B007D; Sun, 7 May 2023 19:46:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EEE36B007E; Sun, 7 May 2023 19:46:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6CAC16B0078 for ; Sun, 7 May 2023 19:46:36 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 383DB1404A5 for ; Sun, 7 May 2023 23:46:36 +0000 (UTC) X-FDA: 80765095992.29.C959DDA Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf05.hostedemail.com (Postfix) with ESMTP id 65A2F10000B for ; Sun, 7 May 2023 23:46:33 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=GgGKz6j6; spf=none (imf05.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.126) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683503194; 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=sv6wo6vxOffMBn9+KXstoWGKRgNi5dzIFAWw39uzvSo=; b=rTRTYJe/UIABq/PSBwxDVk/br2xk1fz772ASlgvkl/Z/tSwAVitcqj5/1znN+4BZfC/154 IBLfFS83Fwz6Nd1kTULokmbCDELtCMyf6DZglVr2DiBnvaUGJzPFfwF+GfVUVgms1ehelb bemtgHbimCDj2jVux9i5pdyWhyDnU68= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683503194; a=rsa-sha256; cv=none; b=zifZakairheBqAGzvEQbk1ZGOy3zReh1L0F8uH7Mkay5cxSiBze2bMo15PQsaDQ7LQII03 H6wuDzk2SJk98/HjC8L2O8i4gA3uGfp67dZiebja3ZMO/GMBSLuGyVqJK8J1AdFoP0gLNZ IYY/U5uRkTcayDjidSRaO6gDnmXGkAo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=GgGKz6j6; spf=none (imf05.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.126) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683503193; x=1715039193; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BwDi/PWmIK31K/TDtylUIn7yoV9Lz0nwLx+9+7bRLdU=; b=GgGKz6j6bAtu+7cuCkvNdShM1JnjhaqevSabiFvyIRLYT1sEMTBixWFp mLubHGOGoPoCSzvuUSKft5bSuwp2tsEbByi1XgR7iBf7jNqpcQmjj31Cm y/3/iv18pQkJRAhM77xpsA8kVaQX2jPWKXYq42RGv7wJbk1k80l6C+M/n pEhtxFKnmT1GM4EeE8wE2C+laXFpOkiyc4dcUUK75VXwPC9CfzPkZ/Nbd ZbTbfeQB2HZIcaktlWqnazhemfb8sfHhKw0BECSgqsIlen+8FqXiKRJnl pM90vowXlbqrVET8HqfM+FJ69LYRjZ/pZ08kow9GvsynBlNPBsXGhTGiv g==; X-IronPort-AV: E=McAfee;i="6600,9927,10703"; a="333953470" X-IronPort-AV: E=Sophos;i="5.99,258,1677571200"; d="scan'208";a="333953470" 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 X-Rspamd-Queue-Id: 65A2F10000B X-Stat-Signature: adh56iwhif71gsw5xb8auaw8isuf7991 X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1683503193-955832 X-HE-Meta: U2FsdGVkX1/hYHsVvXoAb908Ip4lasWzEdWtGF5nTFdQWLqeISTA6S3O6sGNLmNJggvVk/QHXxl+jaiYYE4J8CrxLH45nlBQZdD7HCGW74RspnYa4ADNto2xXmAgnQ8N25oDUHqVbQZN8bV/F+f5Qqfa/uLAqsbnY1xjxZDpRccQGe+yVzDGwZXuyeoYA6+TQix7J+ZjwRDlnr+chJ9WhvLO9le89pb6HwwYIkGB+o7Z+vmniWEjE4Q4AmVu8EZOYIsL3Uz4Mx+/BzWn9/qRQQFedoFVSe/c9wiTet8MdtwyRIfiHOOhJ/D00x3DuDZzIEuJgLXZn2l07HhOpc9nbURBbCCWmD+AHTkSx1DhWt+fAklg6dsDy1KKpIAdCLWpjP9gHgT27/7R7y5T+tmKtABVTbX6HuNCbU+VTYTR5USA3UJsT/VJYYw3AtQT7+mvbuDM4I8oY+LYUh13ZGCeOwgmbZZLRhraoRcqKZxuDToeIailsdVpKQsJxexKUvdek+/VLBcY6WzaEo4Xa0bdNeeRv+ldHPl6KOnKEdoAEdXrCtUOeuOCOe8RVU3U8A/tEusbPC8DTyHMZseI37B/OKDfymWKqImJuGq3S1+JW72n4iZW/C7i+ZTy98mpAkNEAJCCZZxlPJIIadNjyGV5eAAFZcoNSrBhmC9bflJbBz922hf7/v0QCBpiavmM17+AA6C1E5vMHCdSO/wIzOvvN3zPXpkNheO9ImFpglaf2W7UpthSXUnq50GxCI3yDTt6EE/HPX8VWhnhMXlniYGoBVsx2bfpNW9BwNmhxtyMysbx/wBWtdVju/+/v+ie1lSbmC1Bxn7phOuc39I9t09Fc9ZHN86eKGrhYAbnd9DsLDRxW4HFAnekVd3ii7HPHuZIjYAPhF7YfxIc75etp0GE1sE2+EgtegUVexfa9rQ7h66qaCPxK8iA2nD13ieG4WWAt1N0vWd0qQTcGKLnYPk qV8S9jXl HYbLK0kkEI0TBj82IRWsmTAf8QuWjxdDCjsVgtnwT0q+1kUbG8TwSl+pVajcEhjh6mCqYJeUy0ogWZGvoo/JOwbMDVLctDTTPviqRWcqB+zjaQi40149EhuHhWitF37aMQiCzOykRp3D2vyA1job+eIoRtOxblrX2vWfNl79f+KMT+pmORa/17o2t4A== 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 --- 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 {