The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Kiryl Shutsemau <kas@kernel.org>
To: Breno Leitao <leitao@debian.org>
Cc: Ard Biesheuvel <ardb@kernel.org>,
	 Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Miaohe Lin <linmiaohe@huawei.com>,
	 Naoya Horiguchi <nao.horiguchi@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	 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
Date: Fri, 21 Aug 2026 12:04:54 +0100	[thread overview]
Message-ID: <aogvGXKH2u7JsJiS@thinkstation> (raw)
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

  reply	other threads:[~2026-08-21 11:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 10:06 [PATCH v2 0/6] efi: mm/memory-failure: keep hardware-poisoned pages out of the next kexec Breno Leitao
2026-08-21 10:06 ` [PATCH v2 1/6] efi/libstub: add a helper for the top of usable RAM Breno Leitao
2026-08-21 11:04   ` Kiryl Shutsemau [this message]
2026-08-21 10:06 ` [PATCH v2 2/6] efi: add the LINUX_EFI_POISONED_MEMORY configuration table Breno Leitao
2026-08-21 11:51   ` Kiryl Shutsemau
2026-08-21 12:03     ` Pratyush Yadav
2026-08-21 14:11       ` Breno Leitao
2026-08-21 14:04     ` Breno Leitao
2026-08-21 10:06 ` [PATCH v2 3/6] efi/libstub: add the poisoned-memory EFI table Breno Leitao
2026-08-21 10:06 ` [PATCH v2 4/6] efi/libstub: install the poisoned-memory table from the stub Breno Leitao
2026-08-21 10:06 ` [PATCH v2 5/6] efi: record hardware-poisoned frames into the poisoned-memory table Breno Leitao
2026-08-21 10:06 ` [PATCH v2 6/6] efi: respect the poisoned pages coming from previous kernel Breno Leitao
2026-08-21 12:13   ` Kiryl Shutsemau
2026-08-21 14:03     ` Breno Leitao
2026-08-21 14:53       ` Kiryl Shutsemau
2026-08-21 16:43         ` Breno Leitao
2026-08-21 10:29 ` [PATCH v2 0/6] efi: mm/memory-failure: keep hardware-poisoned pages out of the next kexec Kiryl Shutsemau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aogvGXKH2u7JsJiS@thinkstation \
    --to=kas@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=kernel-team@meta.com \
    --cc=kexec@lists.infradead.org \
    --cc=leitao@debian.org \
    --cc=linmiaohe@huawei.com \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nao.horiguchi@gmail.com \
    --cc=riel@surriel.com \
    --cc=rmikey@meta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox