Created attachment 244872 [details] grub2-bhyve.patch By the following commit, OpenBSD Current kernel has dropped supporting old console device structure. It causes grub-bhyve not to boot the OpenBSD Current kernel. The new release 7.4 is coming soon will also unbootable from the current grub2-bhyve. https://github.com/Openbsd/src/commit/745c2f60e98fd1f418c104960a567e120624d705 I wrote a patch for this problem that changes to use the new console device structure by default. And my patch switches to use the old console device structure if the loading kernel is older than '7.3' release. The version number is written in the value of 'osrelease' symbol in the OpenBSD kernel. My patch reads it to see if the kernel is older than '7.3' or not. All the previous releases contain symbol tables, so no problem. If users strip the OpenBSD kernel, reading the version number will fail. I added 'kopenbsd -l' option to force to use the old console device structure. If users boot the OpenBSD Current or newer kernel, just 'kopenbsd' command works fine although the kernel is stripped. Because the new console device structure is chosen by default. Implementation Note: (record for maintainers) Reading symbol tables is already implemented in 'grub_openbsd_find_ramdisk' function. I added reading the value of 'osrelease' symbol in this function to share the symbol lookup code. And building console device structure is implemented in 'grub_cmd_openbsd' function, but it is called earlier than 'grub_openbsd_find_ramdisk' function. So 'grub_cmd_openbsd' function never knows the version number. I changed to build both the new and old console device structures in 'grub_cmd_openbsd'. They are added to 'tag' list and 'grub_openbsd_boot' function reads the 'tag' list and build stack frame that is passed to OpenBSD kernel. I changed the building stack frame code to ignore unnecessary console device structure checked by the 'osrelease' value. I also added 'openbsd_force_legacy_console' global variable. It's a flag to force to use the old console device structure. This flag is set by '-l' option. Testing: My poudriere build successfully finished with my patch. And I confirmed my patch booted OpenBSD kernel from 6.9 to 7.3 and Current successfully. And also the installers of OpenBSD 6.9 - 7.3 was booted successfully. Please apply the attached 'grub2-bhyve.patch' to Ports tree.
Take
I updated my patch to simplify the logic. The new logic always allocates the new console boot parameter. If the loading kernel is prior to 7.3, the console boot parameter is replaced by the legacy one. The new one is bigger than the legacy one. So, it doesn't need to reallocate the memory for the legacy boot parameter. It just rearranges the memory image. And I also fixed a "use after free" bug in the previous patch.
Created attachment 246762 [details] grub2-bhyve.patch.2
Can this be merged, please? I can confirm that OpenBSD 7.4 boots in bhyve after this patch is applied.
Created attachment 247472 [details] grub2-bhyve.patch.3
Hi, my previous patch has been committed in the upstream repository. I updated grub2-bhyve patch to refer to the commit. This change minimizes the patch for the Ports tree. Please apply the `grub2-bhyve.patch.3`. Thank you.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=c918e3f780ddd4cc6a0b6650854a1a10fe96644f commit c918e3f780ddd4cc6a0b6650854a1a10fe96644f Author: Hiroki Sato <hrs@FreeBSD.org> AuthorDate: 2024-01-07 12:32:30 +0000 Commit: Hiroki Sato <hrs@FreeBSD.org> CommitDate: 2024-01-07 12:32:30 +0000 sysutils/grub2-bhyve: Add patches to fix loading OpenBSD kernel PR: 273814 Submitted by: Yuichiro NAITO sysutils/grub2-bhyve/Makefile | 5 +++-- sysutils/grub2-bhyve/distinfo | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-)
Committed.