Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1195355rwd; Tue, 16 May 2023 13:17:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ41/fUvziSVq8u9UEHqyxh0zTuctJ1T0BolYBwFrEsIMt/8+EdlmZfr+IwY99he5nt0Sq8U X-Received: by 2002:a17:902:ee89:b0:1a6:74f6:fa92 with SMTP id a9-20020a170902ee8900b001a674f6fa92mr41340737pld.19.1684268225975; Tue, 16 May 2023 13:17:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1684268225; cv=pass; d=google.com; s=arc-20160816; b=M3V/xXClO6hPSae5Ly89TLA7yEL8hkO98h5TAyttdL41nVoiblrtJMicJ6PHLQOYtQ 3tV36jJLtlel6rYuAt/tf7aW5IKw8sNcdPLK2iLbcVKyNxsiXRhBasyMoe96JrhkK1Fh fbUUiWKUm3vYQfG8QPKvxhXgGnV6B3cbWlyPKTbqr47je6Hvy4N+kCeY3G36546Y7ynk lmFyfc77GA38k0ZWnKBjKmC5wcqYCg18N7+RPtYj4NWImEGWikdS8Hq1zqEA35MxZ+E0 Svets+Pe7BMv5hrm+w7RQMqGprSHcgS6X7usX89jCR9D5cpgrRrJrZWPC4bF85TMA8qj 9HfA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=9JgeRyZQOMilJyl4L7hQF5MJ6hskuO3MwuHwx/zdKO4=; b=l5FdRlHvacLmSUfnpdRM224+dpSrHVP7fpWqkeE07UgA0IgnrLFak73G/gHvExPSGb /agRVPJe8ifvdPbNKCXrAdm9Cg1XC/Uor6G0dXMh4xRi+RWOXiuAUYXxFlqnZ7niLHNq psB88G8M9hgzw9/cnQH4RQB7WImVVe6kuTd4Fw/mRFWtFxuOjKBjoj/ZmQnR0lzFJOcq IBEyuQ6ARdMw/IJGwwiqFRw3oI+/cFtoJQYvkyvSNaIBVbCk9CgFg9vx+vxHeIP194p8 xYux0nCjxXXIM74untCn7KP5JzYstCgOFY4zk4mxqx1rAxZ8pemzVEbYwKoWwxOirM0s n76w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=mzsW4jNA; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i2-20020a170902c94200b001ac9d63028esi20976937pla.575.2023.05.16.13.16.49; Tue, 16 May 2023 13:17:05 -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=@amd.com header.s=selector1 header.b=mzsW4jNA; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229572AbjEPTwv (ORCPT + 99 others); Tue, 16 May 2023 15:52:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjEPTwt (ORCPT ); Tue, 16 May 2023 15:52:49 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2070.outbound.protection.outlook.com [40.107.243.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2296FC1; Tue, 16 May 2023 12:52:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cKY/oQmzy23TIY0i0EteDyajYKwNnTRzt2phW/fPsxy7tujlVTsewEyqAnSQC28oV5OBUFGu208bmGb8uPM6LHOlBHQ/APfTNouf2CUKbLYlaYPkj2n4iJfa9MnChyH/y24fkPnunwJHt0dJ1358Ftv9zOTv6asv2V2fyZz9eZEqSzus6RM2T5e5SpmOsl3wr83WvCvMnsJGjJQXhf+n6C6+augf2CHwyqfm7dfAY8XLUrchL/6V0OjulQN4J6945WQoTt0VPAn6bejIXsHjOQXyQXkShZEOTXLgK1vc6edtFT1f/f6c20WUJi2ryuJCLywXj0uTrEmyA+/IFbnYVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9JgeRyZQOMilJyl4L7hQF5MJ6hskuO3MwuHwx/zdKO4=; b=hXAfK6GAilHoytW6/b0M6NIh38VW+DmR/Iuo//2S0fHCU8qfz8Z9iXU4sNz4LRFB6Ub2YnBa4utTKtLuqsEcOgoySve7aMGDPBaV4l7S9g+aJU6MJ0Zag/XDUJ8VK0TYRGaCjHNndRuyD1zxW6He/U15IxUCC4jcVxS3cjQrNPr2YC/J0YfLYgf5TJ8Qmrvt+5rIjyn6ipLJgTiZHHR86uHQXOri6DWHEIUpJfb3WAOvZkG1JDA8I4RCP0WC6ZYV3/p5OvpQkD7NkdEMrFJp2d6+4nkVYsfUOLpLswHHi0y1qL6R7NTiGtLjfRBQptln/dMQpvH/U84uj72q0gq8iw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9JgeRyZQOMilJyl4L7hQF5MJ6hskuO3MwuHwx/zdKO4=; b=mzsW4jNALl3ajqpne32cG+26G3l066KWUv9V+53huGTYUwKrJRYx5+UO/a+H38JnwTt367mlpMQ2fVSBR4c0XsuhcBTGFZAbZEffwTf/apoposzVNfIptjNNcpA8L0SXrWnoxWYboLLLyAlxuu51pFMJlLHEKYM65jZbNMFDCvg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by DS0PR12MB8563.namprd12.prod.outlook.com (2603:10b6:8:165::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.30; Tue, 16 May 2023 19:52:46 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::ea32:baf8:cc85:9648]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::ea32:baf8:cc85:9648%7]) with mapi id 15.20.6387.030; Tue, 16 May 2023 19:52:45 +0000 Message-ID: Date: Tue, 16 May 2023 14:52:43 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCHv11 2/9] efi/x86: Get full memory map in allocate_e820() Content-Language: en-US To: "Kirill A. Shutemov" , Borislav Petkov , Andy Lutomirski , Dave Hansen , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel Cc: Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , 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, Borislav Petkov References: <20230513220418.19357-1-kirill.shutemov@linux.intel.com> <20230513220418.19357-3-kirill.shutemov@linux.intel.com> From: Tom Lendacky In-Reply-To: <20230513220418.19357-3-kirill.shutemov@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: DM6PR06CA0087.namprd06.prod.outlook.com (2603:10b6:5:336::20) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5229:EE_|DS0PR12MB8563:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a4c45b1-59b5-42dd-8f9a-08db56471e69 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cXAxI6pCMNu01Ch/NcNUsmtAg1gtvwSxv9sHf0wHfRmhogy18j1fZHhdp732gaB64vZY76if6M4XTJXGS61D/sdNBvSobqE0qmvGQ+1yxWiQEBsiS1Vw4jEOyJfSYzBVolPhvRSmtHvNq4+jVDIZ1rAlvrBSJJUc0e7FYe/FXtocBcs80gAzgr533NX8g706NDB+3evUn/q8/Bmh0e0xTLQv+0DYioO8YWUV00PmP+o9S9yfoL0BrXENgC7zf6/DAAJU1Q6ZJao8PXysG1njAiZmw69L7UKq/OnniyYitiXToGsmAzETgSzVw3i+5Jlpv7m/rnSiRPKNI4Qz9u73k7542IrkZGSvCDCjgFJw7p79W1L1V5XM3s4kliSN/G91qFWMXZSAmn61+vP/lAm/Vzmj/Co3C0yyanVG1PAETqbJeCRUKyy+wAEpJS52dpQL1Xe+UHVpaOa3LG2P9xJC7274KFkvcd6HYGk56ibl3otqX1g8PzoJ1CCToXW7YRip2SfxtC+K7olAzidM61Ym1n5YahetOU3oYMOJSsxe4q3GysMFIYv/NFXk2dWrNY3zG7Qp5Bz3XfXynkcyWYQOSX2PDTg3B63gGrJj4Rg2CTfeJeX/om6+WVYA6Ze7uTCc62WL4ZwNgzdMBOGdBajC0A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5229.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(396003)(366004)(346002)(136003)(39860400002)(451199021)(31686004)(66476007)(110136005)(66556008)(4326008)(66946007)(478600001)(54906003)(6512007)(6506007)(53546011)(38100700002)(186003)(83380400001)(2616005)(36756003)(41300700001)(8936002)(2906002)(31696002)(8676002)(7416002)(6486002)(316002)(86362001)(5660300002)(26005)(7406005)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Q0s1V3IvMlorS0lBdXdvNWZXNEp6d2ROT1Yrdm16WTJGT0YzbXpycy8xc2lO?= =?utf-8?B?NVZ0UnNxdy9kaitKMEFRTFJyZW5Va0ZvQWtvTnFuWXdRWDVGYnUxVFBuMkg3?= =?utf-8?B?d293dHpzKzVoQUdFVjN6bkk1emh5dnNmUWE1QVhoZ0Q3MTdmeXplaXZDZGlK?= =?utf-8?B?WHdOUlRNMVZYVzlKS0xFMDJkaldGS3Z1bkI5Sm80M3diVEJqUmx6c1E5K2hy?= =?utf-8?B?L3pMcUJjV1BwN0JhSVg0VmJDN2RKaWZQUUpYWWluU3JxcUdCcXBsSXp5SU1I?= =?utf-8?B?UUNZSFRFcURZcGRyV0xDYnEyNDFLSmVIWk1xVk55N3hVanhLVE54RVdFb2tv?= =?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Pt2N62KbZq9W?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a4c45b1-59b5-42dd-8f9a-08db56471e69 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2023 19:52:45.8323 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 70yB6Os66WZhNelAYH/AN5T4G7enp5vs+AIYbPy0DOfMcpjqcp1ur3AFcHfXk3thTWYAkbDhuQhjjaLjRIXiwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8563 X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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 On 5/13/23 17:04, Kirill A. Shutemov wrote: > 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 {