From patchwork Tue Jun 6 14:26:30 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: 103858 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3440326vqr; Tue, 6 Jun 2023 07:33:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Rw+dz56NCpv/zB5H5IuQprLbUIL1LfUxUZP5HgNzJoorisKLvje1xZm9CiJ8rsn1ZLqwu X-Received: by 2002:a37:a855:0:b0:75d:5076:cec1 with SMTP id r82-20020a37a855000000b0075d5076cec1mr1971513qke.7.1686062021964; Tue, 06 Jun 2023 07:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686062021; cv=none; d=google.com; s=arc-20160816; b=MmA8a7T0brfd+GShT1jJP1qc4dHBq9Z2lax5CKYnPxN/lCPTmsHwliqQd1dcz4utEd YDxfrUp+/vsEiLCJtKYY6I150ZVx6QZsLQUpSEyTmCP3JgkHeCAdzKKf4hthattIn64B SChxeQffBn/mpaWQiaZ6h4Fdju/CI836vXeNnCHVM03ShgD+G1bnKJRuu3mt41QdT3S2 3DefopmxjRaRe4MwBWc6i73DyoTeMY38YP+3RYQLeihrm/6HF42RjBV5FNmPqag/7jqB ZOq+OgYRqof+JuMuYjv/kIGSArlH6T0TJya5eku3B1Ig4ZM5yOBgr1wU9M2Klc6z/qeo fNeQ== 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=L1R59CUsCvlREQbgQJ+T7TXFWlE1qQKWxKe4sKVKWpeZdvZH0vjYUjClCmHovrgyez 0lef0pXMNuKG6IChSozU/MwCq30R7omjESsrahBr/9xYbWg8HGqVYmD/EwSBdgGV83Nr AS0322XpoR/L/BN2w7VTjf6yLmtBUOoq4GLWMMm3ma+JoVxjpyWOUzKFLK4Rz0Py8WLy ICj9WwdFtM939w7lCpVofX1FtMci9kOVi8hnzsLd9O+/w0nXA2PORfznA8WGu6gU4wr0 PubnWe5yhm9juhbDrqDZ+bGQ0gT1T3k6jRq0dmVdSYdQaw610AyNEIjaPg1tTAs1+Vmp xF1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QS91vOTz; 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 dy51-20020a05620a60f300b0075cc75f9790si5859471qkb.579.2023.06.06.07.33.27; Tue, 06 Jun 2023 07:33:41 -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=QS91vOTz; 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 S237735AbjFFO2F (ORCPT + 99 others); Tue, 6 Jun 2023 10:28:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235857AbjFFO1m (ORCPT ); Tue, 6 Jun 2023 10:27:42 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66034171D; Tue, 6 Jun 2023 07:27:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686061661; x=1717597661; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LJWuKaqvYOvqAXDR1TKqUlI78Dny7nmmQ0aMOVcXkCg=; b=QS91vOTzgQrvE3ksU1GHsXwnCNdDMp8cAnGXa9r0gt3ybzXmqrtfpyGL b/6XBqncp5pNNSvlpM0QHgZEdh3rdJOFpH5W0Ih0Gms1+kE2xJOLMltoi UXGQBDl5DqO/cfdmX/SzcUiSm+KYoQ16p/CMcGYmnjEV9gEGYaCW3XQ4n pzSIcrNLuqBxR7r29ZogKZQXChcmNJZbEpBMcp+krz681sKiRPMscVQuI yLSFI5MEepRg668Ji5BSeecuCEIkPkho3hOUrCz1DpHVwwWVVqxMqXsIg 8aONt2BhhdGO5gbxS/jhrHIcWGhCxQqrjlMQlS3Ss0STthYe8MIFTSQh3 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10733"; a="341336956" X-IronPort-AV: E=Sophos;i="6.00,221,1681196400"; d="scan'208";a="341336956" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jun 2023 07:26:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="738815142" X-IronPort-AV: E=Sophos;i="6.00,221,1681196400"; d="scan'208";a="738815142" Received: from rgraefe-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.58.173]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jun 2023 07:26:44 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 358B910D348; Tue, 6 Jun 2023 17:26:42 +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: [PATCHv14 2/9] efi/x86: Get full memory map in allocate_e820() Date: Tue, 6 Jun 2023 17:26:30 +0300 Message-Id: <20230606142637.5171-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230606142637.5171-1-kirill.shutemov@linux.intel.com> References: <20230606142637.5171-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?1767964170744492196?= X-GMAIL-MSGID: =?utf-8?q?1767964170744492196?= 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 {