From nobody Tue Jan 24 22:09:39 2023 X-Original-To: dev-commits-src-all@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 4P1h3765nsz3bdYx; Tue, 24 Jan 2023 22:09:39 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P1h375gyHz4GWB; Tue, 24 Jan 2023 22:09:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598179; 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=hLAR8NxiHtcN/mOx97b4OHa3QLS66+RvY8VgTxFgJ4I=; b=LxKcpsmcpPRqq2p6681PD0wcBZoV5VfD18OOMTHsro45r8xIi0c4dP15H6ERhcSCVB5dLB Gur8oQzSFgt5G5kENBpkddlmsJgLNAa8GjbMFucJ2n1NA05431WiPIJlEpFR8awFPyUVmE A9wWzo9SaGBPHcq5EOeg/rErT3f8u7iTOCA2ZwqqbznoTWAtu9QIlL1wl0fWMZRwUEscDN MMUPp1x2vI/R08ibRaDXhkZ4uduaXaK1vB8cBWxBise333BIlNt7wZivV1fTfK2M4bPcgd X+aT1V6xjlN5kUQDPEVktCE5VQ0Y6ozCpKEzdscfHRLVVo4bgmaXT2gpxJHgmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598179; 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=hLAR8NxiHtcN/mOx97b4OHa3QLS66+RvY8VgTxFgJ4I=; b=WgCqfNh/MMTiVAm5BUFufHPabjqf3S9GVqlpIDvUkaRMztkoq5YJKfdkhegMa1cJJYV7uA xOgfqf2eobzxz2ttxRvWuOnyvHwGbOSggvy8CXQQrePqQZQJEXtRKMc4VEs/Fk+OOsNy1P yAjU7W2E2xIVIlsjo+LRWUIsOCGN3IgrVMDm/rT7S/m0SILLEQqfcexHpnGi/yeDfteilt YV8Xdx66EC/CDGHo+8ksmQNIt3I3ZZBGy+I3cJAFuhIdRKe1MQ8nAyhy322lVJ3xBLNFlj PsWR00dFu45utL8WIMFsZn/ziG1lbG71kd5HWq/gEEpjemfjUt6N9y0rF62jwQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598179; a=rsa-sha256; cv=none; b=KOZvWikkAa5IIu0iOm6fICw+Y+Cju6A8s4dMuS4iOiv35hsoMUHTgUTJVuZIsgTmOKC1yE mu/yeyKDAkiMKnswpJqDlmWiFzkMvo52sYvSv2TABc4CUCzRVV9rL9N5uN3x4Q724VEYxA 9oZFJtgoQFDWYM7lwE/7zClN04yUIHkfgbfoCAhhFWQAMyOcBFWOaFueYoyjbrXp5SGmHG hRS8LiNcXwV1cBupoLp/G/LZv/MtafA7IrgRpgQV5HdEzisWQQHuqt8mbqbqPN4kM3PWZm vL6n/R5S7kO5nVNIOTSpWWrTCPeGbR8VXEFUgypaTMAF9kq4qAZAILdbYZQA6Q== 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 4P1h374m2TzQT3; Tue, 24 Jan 2023 22:09:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30OM9dOD070468; Tue, 24 Jan 2023 22:09:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OM9dtu070467; Tue, 24 Jan 2023 22:09:39 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:09:39 GMT Message-Id: <202301242209.30OM9dtu070467@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: b38b585da053 - stable/13 - stand/efi: allow not exiting boot services List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: b38b585da0533b47c9545d239d6fca28cf673cac Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=b38b585da0533b47c9545d239d6fca28cf673cac commit b38b585da0533b47c9545d239d6fca28cf673cac Author: Roger Pau Monné AuthorDate: 2021-02-05 10:15:19 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:15 +0000 stand/efi: allow not exiting boot services Xen requires that UEFI BootServices are enabled in order to boot, so introduce a new parameter to bi_load in order to select whether BS should be exited. No functional change introduced in this patch, as all current users of bi_load request BS to be exited. Further changes will make use of this functionality. Note the memory map is still appended to the kernel metadata, even when it could be modified by further calls to the Boot Services, as it will be used to detect if the kernel has been booted from UEFI. Sponsored by: Citrix Systems R&D Reviewed by: tsoome, imp Differential revision: https://reviews.freebsd.org/D28495 (cherry picked from commit ed87efbe24a5734c7150153cf201f3db42b6ddab) --- stand/efi/loader/arch/amd64/elf64_freebsd.c | 5 +++-- stand/efi/loader/arch/arm/exec.c | 4 ++-- stand/efi/loader/arch/arm64/exec.c | 5 +++-- stand/efi/loader/arch/i386/elf32_freebsd.c | 5 +++-- stand/efi/loader/arch/riscv/exec.c | 4 ++-- stand/efi/loader/bootinfo.c | 13 ++++++++----- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/stand/efi/loader/arch/amd64/elf64_freebsd.c b/stand/efi/loader/arch/amd64/elf64_freebsd.c index 7aa5735e0cfc..354f86f090ce 100644 --- a/stand/efi/loader/arch/amd64/elf64_freebsd.c +++ b/stand/efi/loader/arch/amd64/elf64_freebsd.c @@ -54,7 +54,8 @@ __FBSDID("$FreeBSD$"); static EFI_GUID acpi_guid = ACPI_TABLE_GUID; static EFI_GUID acpi20_guid = ACPI_20_TABLE_GUID; -extern int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp); +extern int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, + bool exit_bs); static int elf64_exec(struct preloaded_file *amp); static int elf64_obj_exec(struct preloaded_file *amp); @@ -269,7 +270,7 @@ elf64_exec(struct preloaded_file *fp) printf("Start @ 0x%lx ...\n", ehdr->e_entry); efi_time_fini(); - err = bi_load(fp->f_args, &modulep, &kernend); + err = bi_load(fp->f_args, &modulep, &kernend, true); if (err != 0) { efi_time_init(); if (copy_auto) diff --git a/stand/efi/loader/arch/arm/exec.c b/stand/efi/loader/arch/arm/exec.c index 86c931bcbbe8..a110f3d07cbc 100644 --- a/stand/efi/loader/arch/arm/exec.c +++ b/stand/efi/loader/arch/arm/exec.c @@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$"); #include "loader_efi.h" extern vm_offset_t md_load(char *, vm_offset_t *); -extern int bi_load(char *, vm_offset_t *, vm_offset_t *); +extern int bi_load(char *, vm_offset_t *, vm_offset_t *, bool); static int __elfN(arm_load)(char *filename, uint64_t dest, @@ -80,7 +80,7 @@ __elfN(arm_exec)(struct preloaded_file *fp) printf("Kernel entry at %p...\n", entry); printf("Kernel args: %s\n", fp->f_args); - if ((error = bi_load(fp->f_args, &modulep, &kernend)) != 0) { + if ((error = bi_load(fp->f_args, &modulep, &kernend, true)) != 0) { efi_time_init(); return (error); } diff --git a/stand/efi/loader/arch/arm64/exec.c b/stand/efi/loader/arch/arm64/exec.c index a3021083dc08..6cf4a4fd8e4d 100644 --- a/stand/efi/loader/arch/arm64/exec.c +++ b/stand/efi/loader/arch/arm64/exec.c @@ -55,7 +55,8 @@ static EFI_GUID acpi20_guid = ACPI_20_TABLE_GUID; static int elf64_exec(struct preloaded_file *amp); static int elf64_obj_exec(struct preloaded_file *amp); -int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp); +int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, + bool exit_bs); static struct file_format arm64_elf = { elf64_loadfile, @@ -114,7 +115,7 @@ elf64_exec(struct preloaded_file *fp) entry = efi_translate(ehdr->e_entry); efi_time_fini(); - err = bi_load(fp->f_args, &modulep, &kernendp); + err = bi_load(fp->f_args, &modulep, &kernendp, true); if (err != 0) { efi_time_init(); return (err); diff --git a/stand/efi/loader/arch/i386/elf32_freebsd.c b/stand/efi/loader/arch/i386/elf32_freebsd.c index 847d6eead097..97d114f09610 100644 --- a/stand/efi/loader/arch/i386/elf32_freebsd.c +++ b/stand/efi/loader/arch/i386/elf32_freebsd.c @@ -43,7 +43,8 @@ __FBSDID("$FreeBSD$"); #include "../btx/lib/btxv86.h" extern void __exec(caddr_t addr, ...); -extern int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp); +extern int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, + bool exit_bs); static int elf32_exec(struct preloaded_file *amp); static int elf32_obj_exec(struct preloaded_file *amp); @@ -80,7 +81,7 @@ elf32_exec(struct preloaded_file *fp) printf("Start @ 0x%x ...\n", entry); - err = bi_load(fp->f_args, &modulep, &kernend); + err = bi_load(fp->f_args, &modulep, &kernend, true); if (err != 0) { efi_time_init(); return(err); diff --git a/stand/efi/loader/arch/riscv/exec.c b/stand/efi/loader/arch/riscv/exec.c index fe40003a475b..c7d90a4f31d0 100644 --- a/stand/efi/loader/arch/riscv/exec.c +++ b/stand/efi/loader/arch/riscv/exec.c @@ -43,7 +43,7 @@ __FBSDID("$FreeBSD$"); #include "bootstrap.h" #include "loader_efi.h" -extern int bi_load(char *, vm_offset_t *, vm_offset_t *); +extern int bi_load(char *, vm_offset_t *, vm_offset_t *, bool); static int __elfN(exec)(struct preloaded_file *fp) @@ -66,7 +66,7 @@ __elfN(exec)(struct preloaded_file *fp) printf("Kernel entry at %p...\n", entry); printf("Kernel args: %s\n", fp->f_args); - if ((error = bi_load(fp->f_args, &modulep, &kernend)) != 0) { + if ((error = bi_load(fp->f_args, &modulep, &kernend, true)) != 0) { efi_time_init(); return (error); } diff --git a/stand/efi/loader/bootinfo.c b/stand/efi/loader/bootinfo.c index b560bf268aad..1a6de233b8cf 100644 --- a/stand/efi/loader/bootinfo.c +++ b/stand/efi/loader/bootinfo.c @@ -60,7 +60,8 @@ __FBSDID("$FreeBSD$"); #include "geliboot.h" #endif -int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp); +int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, + bool exit_bs); extern EFI_SYSTEM_TABLE *ST; @@ -284,7 +285,7 @@ efi_do_vmap(EFI_MEMORY_DESCRIPTOR *mm, UINTN sz, UINTN mmsz, UINT32 mmver) } static int -bi_load_efi_data(struct preloaded_file *kfp) +bi_load_efi_data(struct preloaded_file *kfp, bool exit_bs) { EFI_MEMORY_DESCRIPTOR *mm; EFI_PHYSICAL_ADDRESS addr = 0; @@ -393,7 +394,9 @@ bi_load_efi_data(struct preloaded_file *kfp) sz = (EFI_PAGE_SIZE * pages) - efisz; } - status = efi_exit_boot_services(efi_mapkey); + if (!exit_bs) + break; + status = BS->ExitBootServices(IH, efi_mapkey); if (!EFI_ERROR(status)) break; } @@ -431,7 +434,7 @@ bi_load_efi_data(struct preloaded_file *kfp) * - Module metadata are formatted and placed in kernel space. */ int -bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp) +bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs) { struct preloaded_file *xp, *kfp; struct devdesc *rootdev; @@ -530,7 +533,7 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp) #ifdef LOADER_GELI_SUPPORT geli_export_key_metadata(kfp); #endif - bi_load_efi_data(kfp); + bi_load_efi_data(kfp, exit_bs); /* Figure out the size and location of the metadata. */ *modulep = addr;