git: 8f6f1e27fd18 - stable/13 - stand/efi: add modulep to kernel metadata

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 24 Jan 2023 22:09:40 UTC
The branch stable/13 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=8f6f1e27fd187622edcbd7c8d3b36ffa6bbdba70

commit 8f6f1e27fd187622edcbd7c8d3b36ffa6bbdba70
Author:     Roger Pau Monné <royger@FreeBSD.org>
AuthorDate: 2021-02-05 10:11:36 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-24 21:49:16 +0000

    stand/efi: add modulep to kernel metadata
    
    This mirrors the functionality of the BIOS amd64 bi_load function,
    that stashes the absolute address of the module metadata. This is
    required for booting as a Xen dom0 that does relocate the modulep and
    the loaded modules, and thus requires adjusting the offset.
    
    No functional change introduced, further patches will make use of this
    functionality for Xen dom0 loading.
    
    Sponsored by:           Citrix Systems R&D
    Reviewed by:            imp
    Differential revision:  https://reviews.freebsd.org/D28496
    
    (cherry picked from commit 7d3259775cb69f250df3e7fe51d6fff2283c6f20)
---
 stand/efi/loader/bootinfo.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/stand/efi/loader/bootinfo.c b/stand/efi/loader/bootinfo.c
index 1a6de233b8cf..74be4f8f5d74 100644
--- a/stand/efi/loader/bootinfo.c
+++ b/stand/efi/loader/bootinfo.c
@@ -440,7 +440,7 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs)
 	struct devdesc *rootdev;
 	struct file_metadata *md;
 	vm_offset_t addr;
-	uint64_t kernend;
+	uint64_t kernend, module;
 	uint64_t envp;
 	vm_offset_t size;
 	char *rootdevname;
@@ -519,6 +519,10 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs)
 	if (kfp == NULL)
 		panic("can't find kernel file");
 	kernend = 0;	/* fill it in later */
+
+	/* Figure out the size and location of the metadata. */
+	module = *modulep = addr;
+
 	file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof(howto), &howto);
 	file_addmetadata(kfp, MODINFOMD_ENVP, sizeof(envp), &envp);
 #if defined(LOADER_FDT_SUPPORT)
@@ -529,14 +533,13 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs)
 		    "device tree blob found!\n");
 #endif
 	file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof(kernend), &kernend);
+	file_addmetadata(kfp, MODINFOMD_MODULEP, sizeof(module), &module);
 	file_addmetadata(kfp, MODINFOMD_FW_HANDLE, sizeof(ST), &ST);
 #ifdef LOADER_GELI_SUPPORT
 	geli_export_key_metadata(kfp);
 #endif
 	bi_load_efi_data(kfp, exit_bs);
 
-	/* Figure out the size and location of the metadata. */
-	*modulep = addr;
 	size = bi_copymodules(0);
 	kernend = roundup(addr + size, PAGE_SIZE);
 	*kernendp = kernend;