Bug 277450 - "poweroff" does not power off the system when EFI is used
Summary: "poweroff" does not power off the system when EFI is used
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: amd64 Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-03 11:48 UTC by Thomas Dreibholz
Modified: 2025-01-01 02:43 UTC (History)
6 users (show)

See Also:


Attachments
Screenshot after "poweroff" (25.88 KB, image/png)
2024-03-03 11:53 UTC, Thomas Dreibholz
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Dreibholz 2024-03-03 11:48:40 UTC
"poweroff" does not automatically power off the system when EFI is used. Instead, the machine just halts buts remains running. I tested this with VirtualBox EFI guests (FreeBSD 14.0-RELEASE) using ICH9 chipset; the issue is reproducible and occurs always.

https://forums.freebsd.org/threads/efi-virtualbox-computer-non-stop-after-successful-shutdown-of-freebsd.84856/ suggests to change sysctl hw.efi.poweroff=0, which is 1 by default. This indeed fixes the issue.
Comment 1 Thomas Dreibholz 2024-03-03 11:53:28 UTC
Created attachment 248895 [details]
Screenshot after "poweroff"
Comment 2 Thomas Dreibholz 2024-03-03 11:53:58 UTC
nornetpp@burgsteinfurt:~ $ uname -a
FreeBSD burgsteinfurt.openstack 14.0-RELEASE-p5 FreeBSD 14.0-RELEASE-p5 #0: Tue Feb 13 23:37:36 UTC 2024     root@amd64-builder.daemonology.net:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64

nornetpp@burgsteinfurt:~ $ sysctl hw.acpi
hw.acpi.acline: 1
hw.acpi.battery.info_expire: 5
hw.acpi.battery.units: 1
hw.acpi.battery.state: 0
hw.acpi.battery.rate: 0
hw.acpi.battery.time: -1
hw.acpi.battery.life: 100
hw.acpi.cpu.cx_lowest: C1
hw.acpi.cpu.cppc_notify: 1
hw.acpi.reset_video: 0
hw.acpi.handle_reboot: 1
hw.acpi.disable_on_reboot: 0
hw.acpi.verbose: 0
hw.acpi.s4bios: 0
hw.acpi.sleep_delay: 1
hw.acpi.suspend_state: NONE
hw.acpi.standby_state: NONE
hw.acpi.lid_switch_state: NONE
hw.acpi.sleep_button_state: NONE
hw.acpi.power_button_state: S5
hw.acpi.supported_sleep_state: S5

nornetpp@burgsteinfurt:~ $ sudo sysctl hw.efi
hw.efi.poweroff: 1
(This is the default setting => the issue occurs in this case)
Comment 3 Thomas Dreibholz 2024-03-03 12:01:56 UTC
The issue is reproducible with a FreeBSD 13.2 machine as well.
Comment 4 Oleksandr Kryvulia 2024-03-03 12:43:28 UTC
This may be already addressed by 	e4ab361e53945a6c3e9d68c5e5ffc11de40a35f2 in main and MFC-ed to 14-stable. Can you try latest main or stable?

See https://cgit.freebsd.org/src/commit/sys/kern/kern_shutdown.c?id=e4ab361e53945a6c3e9d68c5e5ffc11de40a35f2
Comment 5 Thomas Dreibholz 2024-03-04 14:01:48 UTC
I tried 14.0-STABLE (202040229, i.e. the currently latest ISO available: https://download.freebsd.org/snapshots/amd64/amd64/ISO-IMAGES/14.0/FreeBSD-14.0-STABLE-amd64-20240229-d19769300126-266911-disc1.iso):

hw.efi.poweroff=1 (the default) => no success, the machine remains running.
hw.efi.poweroff=0 => the machine shuts down as intended.
Comment 6 Oleksandr Kryvulia 2024-03-04 15:05:34 UTC
What is a value of hw.acpi.handle_reboot?

Added avg@, may be he can help.
Comment 7 Thomas Dreibholz 2024-03-04 15:10:58 UTC
hw.acpi.handle_reboot: 1
Comment 8 Oleksandr Kryvulia 2024-03-04 16:14:32 UTC
Seems it is virtualbox-specific. I'll test it under bhyve and hyper-v and report it back.
Comment 9 Andriy Gapon freebsd_committer freebsd_triage 2024-03-04 16:30:39 UTC
When hw.efi.poweroff=1, EFI shutdown routine is invoked much earlier than ACPI, so ACPI has no play. It seems that the system hangs in the EFI routine instead of powering off. So it must be a problem with the EFI implementation or something like that.

FreeBSD EFI shutdown code is extremely simple:
    if ((howto & RB_POWEROFF) != 0 && efi_poweroff)
        (void)efi_reset_system(EFI_RESET_SHUTDOWN);
Comment 10 Oleksandr Kryvulia 2024-03-07 10:53:03 UTC
I cannot reproduce it with latest current and stable under both bhyve and hyper-v.
So apparently avg@ is right.
Comment 11 Thomas Dreibholz 2024-03-08 14:08:36 UTC
While the issue occurs under VirtualBox, it does not occur under Proxmox. That is, under Proxmox, "poweroff" works fine with the default setting hw.efi.poweroff=1. This reproducibly fails under VirtualBox.

Proxmox is using OVMF UEFI firmware. VirtualBox seems to use this as well, but may be with some differences.
Comment 12 Thomas Dreibholz 2024-03-08 14:17:54 UTC
I created a bug ticket for VirtualBox: https://www.virtualbox.org/ticket/22021
Comment 13 Gleb Smirnoff freebsd_committer freebsd_triage 2024-03-26 17:19:58 UTC
On Fri Mar  8 14:17:54  2024 UTC, thomas.dreibholz@gmail.com wrote:
> I created a bug ticket for VirtualBox: https://www.virtualbox.org/ticket/22021

Thomas, can this FreeBSD bug be closed?
Comment 14 Thomas Dreibholz 2024-04-04 16:58:35 UTC
The bug is very likely an issue of VirtualBox.

But may be FreeBSD could check whether the EFI shutdown call failed to shut down the system, to perform a fallback solution? This could possibly also help in case of problematic EFI implementations on other systems. Alternatively, it may be helpful to document the VirtualBox behaviour somewhere, to that users just set hw.efi.poweroff=0 as work-around.
Comment 15 Oleksandr Kryvulia 2024-04-11 10:52:17 UTC
(In reply to Thomas Dreibholz from comment #14)

I think port's pkg-message is a right place.
Comment 16 Thomas Dreibholz 2024-04-11 11:01:24 UTC
FreeBSD is the guest system in VirtualBox. It does not have any VirtualBox guest utilities port installed when the issue occurs. I only tried Linux as VirtualBox host, yet.

I useful place for some documentation around VirtualBox and hw.efi.poweroff may be https://docs.freebsd.org/en/books/handbook/virtualization/#virtualization-guest-virtualbox .
Comment 17 Graham Perrin 2024-06-23 12:04:00 UTC
Maybe add to <https://wiki.freebsd.org/VirtualBox> in the meantime.
Comment 18 snufflebear87 2025-01-01 02:43:35 UTC
I ran into this issue on actual hardware.  The motherboard is an Asus M5A99FX Pro 2.0, running an AMD FX-8350. 

I'm running Xigmanas 13.3.0.5 - Hesterion (revision 10153), which is based on FreeBSD 13.3-RELEASE-p4.

It is an older board, and it was the first implementation of UEFI that I had ever run across.  Since the ICH9 seems to be an older chipset and Virtualbox is using that, maybe older version of UEFI is what is causing this?

I was able to verify that the workaround of sysctl hw.efi.poweroff=0 solved the problem in this case as well.