From nobody Fri Feb 03 15:50:55 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 4P7g9W5d3Lz3kRxR; Fri, 3 Feb 2023 15:50:55 +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 4P7g9W1v4Kz3JGH; Fri, 3 Feb 2023 15:50:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675439455; 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=+yfUjEn7umqOCYk1O3bdFCG+gZQwdOyPhGykFpbdkGE=; b=weCNx5QpP7WSbhrm2dBt2TY51Dn/IlR+X3SCMPCvMzvUJBicCtmBrFt1j3u+n3dIR0mX0E LWKyFGEuyIXn3wjWEYULtZEWennZvOTGNp3d94PuqR0rxJFr8hiQzn0AVXZ6ZdsXaHL6En 5X4iNviwJtMAeKTz/RHVhbqJwlGI16eUhUY6pG9trY1/Ji31KcUSHl1IikFFmcNvkporEQ KNfRcgLucMnR08aWBOcoec5WTGWLkC8XLKc02qSoSS0zwbSf81ca33FVPzGmKGM07AOodq N9XF7P6ylDGJTtkkNhHvBWki3O7Os+dSNYhCq05wiQ22oxn84vohljBJcz502g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675439455; 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=+yfUjEn7umqOCYk1O3bdFCG+gZQwdOyPhGykFpbdkGE=; b=W0jE/Hjbk2oGG+EiITMb7nP5A5dsknsHK0l30i0JiTzfYG8pdv9SIisPYElz3Zl/SGO+FR 9eaUx4If7YHaCD7MifbryFQr69MPFVE+C6huVEe5m9taEbLsr8tmSI+n1oEjzJWlxlwUpO y9aU0U1tpmk7PdA2zQK0lcP0A/jtWiQwNXHvg8Ipy3UpioZcFowGmCuKtxQ3zXmSD/WwHp G6OuGazUoalmix15yMq5VlR7xpVS/d85jYftpeh2ENvMvmN6045MnxS9KAQdUgciXQD/87 cAcmGlNnuhK86BU/J8e0bMN515PbdHcb6NN1QUSh4xiIkJ/xJo/uAiJTLAGV7g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675439455; a=rsa-sha256; cv=none; b=LUCk2QXxb8rZwqX/67ah3niwe9cGdWlC7ZT2gxl1XZZjxeLF7fTvBYF880apoQSLY67mE2 pMQ2812iSSdHYjMriU5BuCuoIGYwMqVjWBJ5KGCmJl3dGFjYgRvRl8vKI9ReAdMUTK6LqW I64flgcgQgFOSN3uko2xEY3FL+7lVM46A1iJfhd00o/8RTuPY3+zSM3N9xFdkJl0TVgLqP HUNOWvz1SJRYHEjfvIe2I8HGELQiYgpX6taWZaYivOmjeLSd6ONCI8JY7U5eIhJ/aH10bI +S5ZHpuhy6LQZHZNZeo4HTZwhVMsx+Jy7tM3428SUkYWkBZ7fwDXEErF2OM27g== 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 4P7g9W10PPzgb3; Fri, 3 Feb 2023 15:50:55 +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 313Fotej024156; Fri, 3 Feb 2023 15:50:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 313Fot7T024155; Fri, 3 Feb 2023 15:50:55 GMT (envelope-from git) Date: Fri, 3 Feb 2023 15:50:55 GMT Message-Id: <202302031550.313Fot7T024155@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: 045fa2801a8b - main - kboot: Try to read UEFI memory from physical memory on aarch64 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/main X-Git-Reftype: branch X-Git-Commit: 045fa2801a8bfd1cc05098757afa0f19df996027 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=045fa2801a8bfd1cc05098757afa0f19df996027 commit 045fa2801a8bfd1cc05098757afa0f19df996027 Author: Warner Losh AuthorDate: 2023-02-03 15:40:45 +0000 Commit: Warner Losh CommitDate: 2023-02-03 15:41:41 +0000 kboot: Try to read UEFI memory from physical memory on aarch64 Try to open /dev/mem to read in the UEFI memory map. If we can't, then we'll read it in the trampoline. Retain reading in /proc/iomem to find reserved areas in Linux. We need to know them for good places to put the kernel. These are not reflected in the UEFI memory map. However, we should not adjust the UEFI memory map since these reserved areas of the Linux kernel are free to be used once we enter the kexec trampoline... Sponsored by: Netflix Reviewed by: tsoome, kevans, andrew Differential Revision: https://reviews.freebsd.org/D38264 --- stand/kboot/arch/aarch64/load_addr.c | 51 +++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/stand/kboot/arch/aarch64/load_addr.c b/stand/kboot/arch/aarch64/load_addr.c index ae8a599645c9..4cbbd5192f5b 100644 --- a/stand/kboot/arch/aarch64/load_addr.c +++ b/stand/kboot/arch/aarch64/load_addr.c @@ -28,7 +28,7 @@ do_memory_from_fdt(int fd) { struct stat sb; char *buf = NULL; - int len, offset; + int len, offset, fd2 = -1; uint32_t sz, ver, esz, efisz; uint64_t mmap_pa; const uint32_t *u32p; @@ -83,10 +83,10 @@ do_memory_from_fdt(int fd) ver, esz, sz, mmap_pa); /* - * We have no ability to read the PA that this map is in, so - * pass the address to FreeBSD via a rather odd flag entry as - * the first map so early boot can copy the memory map into - * this space and have the rest of the code cope. + * We may have no ability to read the PA that this map is in, so pass + * the address to FreeBSD via a rather odd flag entry as the first map + * so early boot can copy the memory map into this space and have the + * rest of the code cope. */ efisz = (sizeof(*efihdr) + 0xf) & ~0xf; buf = malloc(sz + efisz); @@ -98,11 +98,45 @@ do_memory_from_fdt(int fd) efihdr->memory_size = sz; efihdr->descriptor_size = esz; efihdr->descriptor_version = ver; - efi_map_phys_src = mmap_pa; + + /* + * Save EFI table. Either this will be an empty table filled in by the trampoline, + * or we'll read it below. Either way, set these two variables so we share the best + * UEFI memory map with the kernel. + */ efi_map_hdr = efihdr; efi_map_size = sz + efisz; - return true; + /* + * Try to read in the actual UEFI map. + */ + fd2 = open("host:/dev/mem", O_RDONLY); + if (fd2 < 0) { + printf("Will read UEFI mem map in tramp: no /dev/mem, need CONFIG_DEVMEM=y\n"); + goto no_read; + } + if (lseek(fd2, mmap_pa, SEEK_SET) < 0) { + printf("Will read UEFI mem map in tramp: lseek failed\n"); + goto no_read; + } + len = read(fd2, map, sz); + if (len != sz) { + if (len < 0 && errno == EPERM) + printf("Will read UEFI mem map in tramp: kernel needs CONFIG_STRICT_DEVMEM=n\n"); + else + printf("Will read UEFI mem map in tramp: lean = %d errno = %d\n", len, errno); + goto no_read; + } + printf("Read UEFI mem map from physmem\n"); + efi_map_phys_src = 0; /* Mark MODINFOMD_EFI_MAP as valid */ + close(fd2); + return true; /* OK, we really have the memory map */ + +no_read: + efi_map_phys_src = mmap_pa; + close(fd2); + return true; /* We can get it the trampoline */ + errout: free(buf); return false; @@ -157,6 +191,9 @@ void bi_loadsmap(struct preloaded_file *kfp) { + /* + * Make a note of a systbl. This is nearly mandatory on AARCH64. + */ if (efi_systbl_phys) file_addmetadata(kfp, MODINFOMD_FW_HANDLE, sizeof(efi_systbl_phys), &efi_systbl_phys);