From nobody Sun Jun 19 14:47:37 2022 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 600F6872188; Sun, 19 Jun 2022 14:47:37 +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 4LQwc927Xjz4qDP; Sun, 19 Jun 2022 14:47:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655650057; 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=4S6DsrxSezOoWwuK66Uv3HBVj9fP0PSyp0elxCFFTAI=; b=ABa6l6+ho9OfbOfVZNqQa5lhbSctwrbHdSXIVO74lFJxE2V58aw4l41wWMKSynY7dmcDC3 M4+HoVp2rbc4MRvdfu++dbXbghUOvPHd/ngqPdsWeqN+XdmWrxWM6Pk5WPKQWIfFz5vzPU VKVfqSEoSrAwsOgpWm5DwdzF3JJvxo6e4qbKrcHlNZeKz82D0EZi/LYircuE4nf59Z0hT0 H6LdAHw/r7EFKAMV5+MijhM7eNv/aB46j5u3b4zgLJqcjs0uISF1yJu2PSHVjaOAKjIxsU T7t6h7vJ2P9ApQYSZ9kkNRWAncxZFE4GfMg5DDVY7epZsM8O1yK9uQW3JUGVqw== 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 28EAE2995; Sun, 19 Jun 2022 14:47:37 +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 25JElbkv018914; Sun, 19 Jun 2022 14:47:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25JElbam018913; Sun, 19 Jun 2022 14:47:37 GMT (envelope-from git) Date: Sun, 19 Jun 2022 14:47:37 GMT Message-Id: <202206191447.25JElbam018913@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Toomas Soome Subject: git: a2e02d9d8e10 - main - loader.efi: fix panic() after BS off 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: tsoome X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a2e02d9d8e100bc41cf99b8fd04738954e48a94e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655650057; 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=4S6DsrxSezOoWwuK66Uv3HBVj9fP0PSyp0elxCFFTAI=; b=yo1sCxRXRJHNPk7Yo0cgmWMp9MZPGgtyQQMwVf36ET3mfq30y6XQVET71kO5xJJEG/jq/u Z9XyxEwfw3032mZoy+ftR5mX/qce8GvLNabY++l9PrA7EcJbkkLNIJEQmayO6ukj2kClcR /TRnOLICWQQ0Wnhhu8TmE9jPzKMg687k/t+S2/vZatKF2Ns2osW184VCLr7KV2MzrRjxjW blRu23ICvOputN6MpePEa4/TPs2ZL5T+aSyuwDkbXz3yRbNgvzJ7YF6RnXikpoeEpBDnIn BdGQIWwSzCikh2NffkjQuh6G7A3mB95ODt+r9CswW8yiqpEmeM1JE1WmLsg4+w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655650057; a=rsa-sha256; cv=none; b=uZa7QwgbXLOzIRvO64Tid2wI9jkrI2Y62hEASEmtuaYRCJY0L+THx94UH7mF4TcX822kvX OxaLdf6AbF1fonykDTKEizR+VcRQ5A80UYrr2WDEQ6tDYlIBxZwhWfKqwHsz0Wkqk/NzyC XAIetfpuQjhesAT02asrUucE445Tjd5hlwIpivDlYoIYn7mWkPHe3jxVx1RoXG7pMui1Uy 4ajewTc8L7XxHXweFJw/8ttnj8KAmyqaBEfX91DIPR9VhT/vVYjl2LRtwUNQ0qtVLkw5qk 9OipA5VWBPdVDcpaPyjF0wvYUwwwqILiAfn8jU+lYpVzR7nr03OunuRdAqMY3w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by tsoome: URL: https://cgit.FreeBSD.org/src/commit/?id=a2e02d9d8e100bc41cf99b8fd04738954e48a94e commit a2e02d9d8e100bc41cf99b8fd04738954e48a94e Author: Toomas Soome AuthorDate: 2021-09-08 00:14:51 +0000 Commit: Toomas Soome CommitDate: 2022-06-19 14:46:35 +0000 loader.efi: fix panic() after BS off panic() is using multiple services - attempting to read keyboard, accessing time functions and finally, exiting the loader. Protect all the accessed listed above. Note, when BS are off, we really can not just exit the loader, we only can reboot. MFC after: 1 week --- stand/efi/include/efiapi.h | 2 +- stand/efi/libefi/delay.c | 3 ++- stand/efi/libefi/efi_console.c | 6 ++++++ stand/efi/loader/efi_main.c | 8 ++++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/stand/efi/include/efiapi.h b/stand/efi/include/efiapi.h index 0118027d4b3c..2347a4d9cf73 100644 --- a/stand/efi/include/efiapi.h +++ b/stand/efi/include/efiapi.h @@ -438,7 +438,7 @@ VOID IN EFI_STATUS ResetStatus, IN UINTN DataSize, IN CHAR16 *ResetData OPTIONAL - ); + ) __dead2; typedef EFI_STATUS diff --git a/stand/efi/libefi/delay.c b/stand/efi/libefi/delay.c index 9eb123096636..9bf40d28f96b 100644 --- a/stand/efi/libefi/delay.c +++ b/stand/efi/libefi/delay.c @@ -33,5 +33,6 @@ __FBSDID("$FreeBSD$"); void delay(int usecs) { - BS->Stall(usecs); + if (boot_services_active) + BS->Stall(usecs); } diff --git a/stand/efi/libefi/efi_console.c b/stand/efi/libefi/efi_console.c index 7166b7a3cfbe..1aeb94344c58 100644 --- a/stand/efi/libefi/efi_console.c +++ b/stand/efi/libefi/efi_console.c @@ -1362,6 +1362,9 @@ efi_cons_getchar(void) if ((c = keybuf_getchar()) != 0) return (c); + if (!boot_services_active) + return (-1); + key_pending = 0; if (coninex == NULL) { @@ -1383,6 +1386,9 @@ efi_cons_poll(void) if (keybuf_ischar() || key_pending) return (1); + if (!boot_services_active) + return (0); + /* * Some EFI implementation (u-boot for example) do not support * WaitForKey(). diff --git a/stand/efi/loader/efi_main.c b/stand/efi/loader/efi_main.c index 736c1aa56c99..3e1fa06638e9 100644 --- a/stand/efi/loader/efi_main.c +++ b/stand/efi/loader/efi_main.c @@ -40,8 +40,12 @@ void efi_exit(EFI_STATUS exit_code) { - BS->FreePages(heap, EFI_SIZE_TO_PAGES(heapsize)); - BS->Exit(IH, exit_code, 0, NULL); + if (boot_services_active) { + BS->FreePages(heap, EFI_SIZE_TO_PAGES(heapsize)); + BS->Exit(IH, exit_code, 0, NULL); + } else { + RS->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL); + } } void