From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9381B472536 for ; Fri, 21 Aug 2026 11:05:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787310305; cv=none; b=pdYXgVKXjf0ekOAhf4BgCRbW7qu/rLG1Cy3sXDrPiwwnF+2um7SruvSLItYvhi7LaGJq10SeVTDnuH6LG8gtqqv75t0AlOUsPt73e/d4/sLThodrXbusxvFDrHc5FB/ScHiJePCFrrRSkH962DNgvIqdLyjFgZ3U4y6rgwjdjoc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787310305; c=relaxed/simple; bh=+XA7XIPxJkktEP/nUfXHpcEIp/KX5C0v7mJMsyrzvR4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZLb0f4uP1/0vBUhgbheoZ5hEc7ff4l0sIvvYAhpF7KtKASfqqFcWYVEheVrOOO3X5/NZbCT9RrczpUMksxFo8Fleb7Qam6gc3twRdHGJaWVORGCumVl1u7jf+I5BU6bxwKcvOz8H02U0fLGKNV0BAKB/9mlD0cTrPue2r5TSObI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bXA/xwwX; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bXA/xwwX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87E9B1F00A3A; Fri, 21 Aug 2026 11:05:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787310301; bh=pCvD1MdzsW2akKjjzWWz1w5C615w+H1/o/P1Mz5Sgas=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=bXA/xwwXn4mlknABhcs+eK/JMOJK6tbygxJOQMNISU2axQcGedUiq+oXFvNCNv9L/ vzUAFDuljuxzu/8t0oydhoubTIBLPP6wUYL7BeADjIqaiFHglf/IOQFNKIvvl4mRGU kOJp1+hurzzvo+cMau+URL845baPVGUlLydXRMaMZKOK+eCDNnoIFzXEJY9oV7kPTh PWHSunSaxuBbMgoCpqz2XyO0ndwTytWoLzqja5SK7kFCfOGtCva7Bw+QHs92OZrau7 K0olHV4ldLh2SYkjdBHS+RKu5ZV4kBjiTdTHFwlwt3pcpqSKL/4Bnb7nVOz5EPPLAT DfrTxeGm5Kdmw== Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfauth.ams.internal (Postfix) with ESMTP id DE9AA1980070; Fri, 21 Aug 2026 07:04:56 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 21 Aug 2026 07:04:58 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEWM2E58ZDI3GBPHZLDZKPHLTpyhDURcoURdljfk4cH7f/KXOu0wRWhhh9eH1QjfP Hp+aXrB4+gX0+3nQ2wUB/0Zvpvx7qc4d6/fk8+4IbRswX34lPo/BdJFV5G0qe+PMX54acE 6lv00gVtxDmgkIP6CGEleZL9qbWoXqA2tuV52C0yG7xpsMWNkMvCN/v51+Hhf9fW7iEsCg hWuFYjNdn5OKp/KjkJpYfUEGv+I0qBpjxsHBdjZoULL4G0EWgCiVun6QBLQ4Z7I97oMxO8 mNESgb5/JqWf4uBVnaYDM02rPLOn4fEGSZpAAxIkmMXoRT23duwEkNmZ8Ga5IT+v8ho/XJ PCkb/fhaZZo0oGr/0/ozdbDPV67SewXLZ9ZpakNXpjAdrdBwRFy+FFPt2Hf3TYa3C5mYTC mSmfqEJm+P2jiYXI3Wokb3IFaRvrt1CpmPnuhV33AUFAXTs/MSpZXW7OMtxyIbdNQV6tYu BPBXQrx2p7xQAcZwZGycAznwajnw2F3Qtl/nAlWxLxpJnj91KTaq0Ko8/jEJbCjeTCCdDl KVtgulxJo8BKttcTC+Yo5KG5o+tQZrkJRkwqA0vRG+6lWRpC67Kj1PdtYZz0eIPjUZrGA2 RTIwa8c910SS/a9bxUETGsMRVOALUBl/insQ0UaPZevyX2e+/klPyDBCu4ww X-ME-Proxy: Feedback-ID: i10464835:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 21 Aug 2026 07:04:55 -0400 (EDT) Date: Fri, 21 Aug 2026 12:04:54 +0100 From: Kiryl Shutsemau To: Breno Leitao Cc: Ard Biesheuvel , Ilias Apalodimas , Miaohe Lin , Naoya Horiguchi , Andrew Morton , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, rmikey@meta.com, riel@surriel.com, kexec@lists.infradead.org, kernel-team@meta.com Subject: Re: [PATCH v2 1/6] efi/libstub: add a helper for the top of usable RAM Message-ID: References: <20260821-hwpoison-kho-v2-0-5743791e48e6@debian.org> <20260821-hwpoison-kho-v2-1-5743791e48e6@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260821-hwpoison-kho-v2-1-5743791e48e6@debian.org> On Fri, Aug 21, 2026 at 03:06:01AM -0700, Breno Leitao wrote: > diff --git a/drivers/firmware/efi/libstub/mem.c b/drivers/firmware/efi/libstub/mem.c > index 59f3f83de50c2..777f1f180c66e 100644 > --- a/drivers/firmware/efi/libstub/mem.c > +++ b/drivers/firmware/efi/libstub/mem.c > @@ -64,6 +64,59 @@ efi_status_t efi_get_memory_map(struct efi_boot_memmap **map, > return EFI_SUCCESS; > } > > +/** > + * efi_get_ram_top() - find the top of usable RAM > + * @top: on return, the end of the highest memory map entry that becomes > + * usable RAM > + * > + * Walk the UEFI memory map for the entry types that become usable RAM, the set > + * setup_e820() maps to E820_TYPE_RAM, and return the highest address any of > + * them reaches. Memory a confidential guest has not accepted yet counts as > + * well, since it becomes RAM once accepted. This is what the stub has in place > + * of max_pfn, which is only set once the kernel proper is up. > + * > + * Memory the firmware hot-adds later is not described by the memory map and so > + * is not accounted for here. > + * > + * Return: status code > + */ > +efi_status_t efi_get_ram_top(u64 *top) > +{ > + struct efi_boot_memmap *map __free(efi_pool) = NULL; > + efi_status_t status; > + u64 ram_top = 0; > + int i, nr_desc; > + > + status = efi_get_memory_map(&map, false); > + if (status != EFI_SUCCESS) > + return status; > + > + nr_desc = map->map_size / map->desc_size; > + for (i = 0; i < nr_desc; i++) { > + efi_memory_desc_t *d; > + > + d = efi_memdesc_ptr((unsigned long)map->map, map->desc_size, i); > + switch (d->type) { > + case EFI_LOADER_CODE: > + case EFI_LOADER_DATA: > + case EFI_BOOT_SERVICES_CODE: > + case EFI_BOOT_SERVICES_DATA: > + case EFI_CONVENTIONAL_MEMORY: > + case EFI_UNACCEPTED_MEMORY: > + ram_top = max(ram_top, > + d->phys_addr + d->num_pages * EFI_PAGE_SIZE); > + break; > + default: > + break; > + } > + } You model it after setup_e820() which is x86-specific. On ARM is_memory() adds anything with WB/WT/WC, and is_usable_memory() also counts EFI_ACPI_RECLAIM_MEMORY and EFI_PERSISTENT_MEMORY. -- Kiryl Shutsemau / Kirill A. Shutemov