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: 90896 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1830368vqo; Sun, 7 May 2023 17:35:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5e94PPnSVUDvFY/kpyd444QFw2L0EWksbpnD0mKsVgkjQznF6/l2dYGWRgoqWFYXroHDe5 X-Received: by 2002:a17:90a:db4d:b0:250:8258:1a5 with SMTP id u13-20020a17090adb4d00b00250825801a5mr2128772pjx.33.1683506116495; Sun, 07 May 2023 17:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683506116; cv=none; d=google.com; s=arc-20160816; b=IjNMzYJGQ85LhRunLkkbV4QcIAv+yHGMl0ueFLEMH3eaqmY9+BxtfHu1UqZNqN413d Vd+sGvDO+csjiGdum+AIdy5FPjZ1DzsUn84dZpkPeE67LVSLKs/Sb4AT+nQUoMyvsK0D Oi37r3XyhYXJ1Tlu+62cAntS3e9yFfre7dXHz51mCoKi7SISYJqnqG2a957tLwUxD8wF e+VxwcUg38iV7vv2DlN6Udkn9jy+lLUWMpWpyaqxt/N10req8o7ovcu+oM0X9eL6WSas DbC5Ske/CAonM/xr2/Wej8M+PhE+WM4ild4xCDiyisZOI9Snt70ai9sH6Zd74ieefqY/ wTOw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j22-20020a633c16000000b004c259db61fdsi6936721pga.561.2023.05.07.17.35.04; Sun, 07 May 2023 17:35:16 -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 S232017AbjEGXqh (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765284109419822292?= X-GMAIL-MSGID: =?utf-8?q?1765284109419822292?= 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 {