From owner-svn-src-stable@freebsd.org Wed Oct 3 17:17:39 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BED4210A733E; Wed, 3 Oct 2018 17:17:39 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6E0A886052; Wed, 3 Oct 2018 17:17:39 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 676E219E26; Wed, 3 Oct 2018 17:17:39 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w93HHdlv009994; Wed, 3 Oct 2018 17:17:39 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w93HHdrd009992; Wed, 3 Oct 2018 17:17:39 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201810031717.w93HHdrd009992@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 3 Oct 2018 17:17:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r339161 - in stable/11/stand: efi/loader fdt X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/11/stand: efi/loader fdt X-SVN-Commit-Revision: 339161 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Oct 2018 17:17:40 -0000 Author: kevans Date: Wed Oct 3 17:17:38 2018 New Revision: 339161 URL: https://svnweb.freebsd.org/changeset/base/339161 Log: MFC r338219, r338250: FDT in Loader fixes r338219: fdt_fixups: relocate the /chosen node after applying fixups As indicated by the comment, any fixups applied (which might include overlays) can invalidate the previously located node by adding nodes or setting/adding properties. The later fdt_setprop of fixup-applied property would then fail because of the bad/wrong node offset. This would have generally been harmless, but potentially caused multiple applications of fixups and caused a little bit of bloat. r338250: efiloader: Setup FDT in autoload to fix overlays clobbering kenv manu found in the noted PR that overlays seemed to be clobbering the kenv and killing the boot. Further inspection revealed that one can `fdt ls` at the loader prompt for a successful boot, but autoboot breaks it. In the autoboot case, first setup of FDT is happening in the middle of bi_load, which triggers loading of the DTBO from /boot. This is bad, bad, bad. Files in the loader are loaded somewhere in the middle of the address space one after another. bi_load starts building the needed kernel bootinfo immediately after the highest-addr loaded file. File loads in the middle of bi_load suddenly clobber bootinfo and everything goes off the rails. The solution to this is to use take advantage of arch_autoload to setup FDT in efiloader compiled with LOADER_FDT_SUPPORT. This matches how it works in ubldr land, and is how it should have worked when overlay support was added to efiloader since fdt_setup_fdtp now has the potential to load files (courtesy of fdt_platform_load_dtb). Modified: stable/11/stand/efi/loader/autoload.c stable/11/stand/fdt/fdt_loader_cmd.c Directory Properties: stable/11/ (props changed) Modified: stable/11/stand/efi/loader/autoload.c ============================================================================== --- stable/11/stand/efi/loader/autoload.c Wed Oct 3 17:16:18 2018 (r339160) +++ stable/11/stand/efi/loader/autoload.c Wed Oct 3 17:17:38 2018 (r339161) @@ -27,11 +27,30 @@ #include __FBSDID("$FreeBSD$"); +#if defined(LOADER_FDT_SUPPORT) +#include +#include +#endif + #include "loader_efi.h" int efi_autoload(void) { +#if defined(LOADER_FDT_SUPPORT) + /* + * Setup the FDT early so that we're not loading files during bi_load. + * Any such loading is inherently broken since bi_load uses the space + * just after all currently loaded files for the data that will be + * passed to the kernel and newly loaded files will be positioned in + * that same space. + * + * We're glossing over errors here because LOADER_FDT_SUPPORT does not + * imply that we're on a platform where FDT is a requirement. If we + * fix this, then the error handling here should be fixed accordingly. + */ + fdt_setup_fdtp(); +#endif return (0); } Modified: stable/11/stand/fdt/fdt_loader_cmd.c ============================================================================== --- stable/11/stand/fdt/fdt_loader_cmd.c Wed Oct 3 17:16:18 2018 (r339160) +++ stable/11/stand/fdt/fdt_loader_cmd.c Wed Oct 3 17:17:38 2018 (r339161) @@ -933,6 +933,12 @@ fdt_fixup(void) fdt_platform_fixups(); + /* + * Re-fetch the /chosen subnode; our fixups may apply overlays or add + * nodes/properties that invalidate the offset we grabbed or created + * above, so we can no longer trust it. + */ + chosen = fdt_subnode_offset(fdtp, 0, "chosen"); fdt_setprop(fdtp, chosen, "fixup-applied", NULL, 0); return (1); }