From nobody Thu Apr 17 21:59:16 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ZdsHT6FRgz5sqsG; Thu, 17 Apr 2025 21:59:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZdsHS6FK1z3VGC; Thu, 17 Apr 2025 21:59:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744927156; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x+EtFs1BWvhHYrIvjmdj73Rj6Qoifw5nvxZgtPj1MIg=; b=T/P/WN6+j3Zp+BgzSHQ3WpPlnvu8ughJj8yzNN6CaANRzFsk0YgBZYvLsV+fpoLJNgH0OU XMjQp3GHnBJh2VCrsC2Q+nyvlm6deszfLmG+VNYLUUY2B1dCOZU4F/yfM3yNBuHRnqFxUC PhES55yvp1ayAVe9CtgoAEqwLB/kuwBEWcPBi4qRoTuTbG18oWn2OcylF0Tla+z+iQTpQm 4cIySpFIa779U7ecByXG6/+pvYsCvLiAZ5eOfBGx3XwO5a31Vldc3te2/+4fqLS50YHtse vhW+MCXhwTr4gsFHFEjtWPwPUmlROT6Nh7b6rFPQJYafsM6llL/mF4yGh2y97w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1744927156; a=rsa-sha256; cv=none; b=dwAy2cu28c8jl/KiJUhD9UvR6gXRScL6Xx4rZ7HHNIqIrlqJoRRLn4HJ8mCDINiEB2eQkY LlAA7ZOpvbdsp+qx6Tm7NkpoAlKE6gPtA5FsWhAQvDOw/dmNCVu/14xwFIRi4XOQ4ycCnF h/rX/0OeO8ioLSRE2Mvn5aM7Cv4SiiHR5SQ+IWYZmnjqmle1VjhuwH++/OkF5CJyNNn0pg 5edclpURVfMH8j/YwHM799ZUrv5pIqeFX8MPZMpo/qDymmQ1zDM/pIQwju2c3CjUu/Y5A8 QmLG84dpBTuny3rLlFUnVIQsmtYC51RO6JZqP1x6GYLbWF2Vz8xX0BF1X1L+xQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744927156; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x+EtFs1BWvhHYrIvjmdj73Rj6Qoifw5nvxZgtPj1MIg=; b=vD0/jYstZ8259zOdaUuuZmyMAH2pBv2ydUv8BkiPkmrTDTdztNGw+v4NgK3LvDWJbPlCBu 2YTXXhbj72KU44Gti3ebpzdTKOT7j3FfpDiETzTVlmVLagiHdirdUsLgQE8y5uFT763NPS YMVZaSLLX0Nf3aDmEg6T//FDZJewkVXq/DVV1YrlemWVr60Vqo4JhmVsOvEQhOwT/VS4G0 Un6Cqen3DQfpBrFzsFNt8HpxOWLDCCSr4zw8hKaz/8GeNXJbv5wYtBSaP+O/44x1zIhBj7 CDGRYbx1IanKWe6S0v2oFz/UI9Tv0d9zsnvFrIjmdZL698tWaCJ8nRxF8xzQ9g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ZdsHS5hCsz153x; Thu, 17 Apr 2025 21:59:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53HLxGEg002731; Thu, 17 Apr 2025 21:59:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53HLxGOl002728; Thu, 17 Apr 2025 21:59:16 GMT (envelope-from git) Date: Thu, 17 Apr 2025 21:59:16 GMT Message-Id: <202504172159.53HLxGOl002728@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 988ee1cc6858 - main - kboot: Method to populate the avail array from EFI map List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 988ee1cc6858136298008df674c13fa17e943f1b Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=988ee1cc6858136298008df674c13fa17e943f1b commit 988ee1cc6858136298008df674c13fa17e943f1b Author: Warner Losh AuthorDate: 2025-04-17 04:04:24 +0000 Commit: Warner Losh CommitDate: 2025-04-17 21:56:46 +0000 kboot: Method to populate the avail array from EFI map If we can get an efi memory map, populate_avail_from_efi will create an avail array. We only use the regiions marked as 'free' to find a place for the kernel to land. The other regions are also eligible, but usually too small to materially affect where we'd put the kernel (not to worry, the kernel will use that memory). Sponsored by: Netflix Reviewed by: kevans, jhibbits Differential Revision: https://reviews.freebsd.org/D49862 --- stand/kboot/include/efi.h | 1 + stand/kboot/libkboot/efi.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/stand/kboot/include/efi.h b/stand/kboot/include/efi.h index 10368bd4a829..f75a9ea055d3 100644 --- a/stand/kboot/include/efi.h +++ b/stand/kboot/include/efi.h @@ -15,3 +15,4 @@ typedef void (*efi_map_entry_cb)(struct efi_md *, void *argp); void foreach_efi_map_entry(struct efi_map_header *efihdr, efi_map_entry_cb cb, void *argp); void print_efi_map(struct efi_map_header *efihdr); +bool populate_avail_from_efi(struct efi_map_header *efihdr); diff --git a/stand/kboot/libkboot/efi.c b/stand/kboot/libkboot/efi.c index 1f7f28093819..1c1d9a34d297 100644 --- a/stand/kboot/libkboot/efi.c +++ b/stand/kboot/libkboot/efi.c @@ -7,6 +7,7 @@ #include #include "stand.h" #include "efi.h" +#include "seg.h" void foreach_efi_map_entry(struct efi_map_header *efihdr, efi_map_entry_cb cb, void *argp) @@ -32,6 +33,7 @@ foreach_efi_map_entry(struct efi_map_header *efihdr, efi_map_entry_cb cb, void * } } +/* XXX REFACTOR WITH KERNEL */ static void print_efi_map_entry(struct efi_md *p, void *argp __unused) { @@ -95,3 +97,38 @@ print_efi_map(struct efi_map_header *efihdr) foreach_efi_map_entry(efihdr, print_efi_map_entry, NULL); } + +static void +efi_map_entry_add_avail(struct efi_md *p, void *argp) +{ + bool *retval = argp; + + /* + * The kernel itself uses a lot more types as memory it can use. Be + * conservative here so we don't overwrite anything during the reboot + * process which copies the new kernel (so we can't use the Linux kenrel + * space for example). Anything that's not free, we simply don't add to + * the system ram space. We just need to find a big enough place we can + * land the kernel, and most of the other types we might use are + * typically too small anyway, even if we could safely use them. + */ + if (p->md_type != EFI_MD_TYPE_FREE) + return; + + /* + * The memory map is always disjoint, so we never have to remove avail. + */ + add_avail(p->md_phys, p->md_phys + p->md_pages * EFI_PAGE_SIZE - 1, + SYSTEM_RAM); + *retval = true; +} + +bool +populate_avail_from_efi(struct efi_map_header *efihdr) +{ + bool retval = false; + + init_avail(); + foreach_efi_map_entry(efihdr, efi_map_entry_add_avail, &retval); + return retval; +}