NetBSD Problem Report #57813

From www@netbsd.org  Wed Jan  3 09:10:02 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id E58E11A9238
	for <gnats-bugs@gnats.NetBSD.org>; Wed,  3 Jan 2024 09:10:01 +0000 (UTC)
Message-Id: <20240103091000.1AC0B1A923A@mollari.NetBSD.org>
Date: Wed,  3 Jan 2024 09:10:00 +0000 (UTC)
From: imil@home.imil.net
Reply-To: imil@home.imil.net
To: gnats-bugs@NetBSD.org
Subject: Support for non-Xen PVH boot on amd64
X-Send-Pr-Version: www-1.0

>Number:         57813
>Category:       kern
>Synopsis:       Support for non-Xen PVH boot on amd64
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bouyer
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Jan 03 09:15:00 +0000 2024
>Closed-Date:    Wed Feb 19 16:53:20 +0000 2025
>Last-Modified:  Sat Mar 29 10:35:01 +0000 2025
>Originator:     Emile 'iMil' Heitor
>Release:        current
>Organization:
NetBSD
>Environment:
NetBSD netbsd 10.99.10 NetBSD 10.99.10 (MICROVM) #811: Wed Jan  3 09:30:48 CET 2024  imil@tatooine:/
home/imil/src/github.com/NetBSD-src/sys/arch/amd64/compile/obj/MICROVM amd64
>Description:
PVH mode, introduced by Xen in version 4.4, permits to boot and pass informations to a kernel using a structure named start_info instead of going through the typical boot process involving the BIOS and a bootloader, which makes PVH boot much faster.

PVH specification which can be read here https://xenbits.xen.org/docs/4.6-testing/misc/pvh.html
NetBSD/Xen is able to boot using the PVH boot mechanism, but can't boot using other hypervisors such as qemu or Firecracker which now support PVH booting.

This is due to the fact that locore.S/start_xen32 expects start_info being passed by the calling hypervisor on %ebx to be located at the end of the symbol table. Qemu and Firecracker don't follow this rule which is not part of the official Xen ABI.
The following patch makes memory mapping loops happy by copying the start_info structure where it's expected.
After that, memory locations and boot parameters are correctly found and
boot can proceed.
Of course, the hypervisor not being Xen, a lot of Xen-related code is
useless, hence the new VM_GUEST_GENPVH (for Generic PVH) vm_guest type.

What's been tested:

- PVH boot with qemu
- PVH boot with Firecracker
- Regular boot with qemu
- Standard Xen domU boot
>How-To-Repeat:
N/A
>Fix:
Apply this patch to NetBSD-current, tested until 10.99.10 https://imil.net/NetBSD/GENPVH.patch

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: kern-bug-people->bouyer
Responsible-Changed-By: bouyer@NetBSD.org
Responsible-Changed-When: Mon, 02 Dec 2024 13:35:11 +0000
Responsible-Changed-Why:
I commited the patch
.


State-Changed-From-To: open->feedback
State-Changed-By: bouyer@NetBSD.org
State-Changed-When: Mon, 02 Dec 2024 13:35:11 +0000
State-Changed-Why:
Hello
sorry for the delay in handling this. I commited your patch with some cosmetic
changes. Can you check if it works as expected ? I don't have a non-Xen PVH
setup.
Also, should a similar change be done for i386 ? Or maybe there's no
support for 32 bits non-Xen PVH guests in hypervisors ?


From: "Manuel Bouyer" <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57813 CVS commit: src/sys/arch
Date: Mon, 2 Dec 2024 13:31:33 +0000

 Module Name:	src
 Committed By:	bouyer
 Date:		Mon Dec  2 13:31:33 UTC 2024

 Modified Files:
 	src/sys/arch/amd64/amd64: genassym.cf locore.S machdep.c
 	src/sys/arch/x86/acpi: acpi_machdep.c
 	src/sys/arch/x86/include: cpu.h
 	src/sys/arch/x86/x86: consinit.c identcpu.c x86_autoconf.c
 	    x86_machdep.c
 	src/sys/arch/xen/xen: hypervisor.c

 Log Message:
 Add support for non-Xen PVH guests to amd64. Patch from
 Emile 'iMil' Heitor in PR kern/57813, with some cosmetic tweaks by me.
 Tested on bare metal, Xen PV and Xen PVH by me.


 To generate a diff of this commit:
 cvs rdiff -u -r1.97 -r1.98 src/sys/arch/amd64/amd64/genassym.cf
 cvs rdiff -u -r1.225 -r1.226 src/sys/arch/amd64/amd64/locore.S
 cvs rdiff -u -r1.369 -r1.370 src/sys/arch/amd64/amd64/machdep.c
 cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x86/acpi/acpi_machdep.c
 cvs rdiff -u -r1.136 -r1.137 src/sys/arch/x86/include/cpu.h
 cvs rdiff -u -r1.39 -r1.40 src/sys/arch/x86/x86/consinit.c
 cvs rdiff -u -r1.130 -r1.131 src/sys/arch/x86/x86/identcpu.c
 cvs rdiff -u -r1.87 -r1.88 src/sys/arch/x86/x86/x86_autoconf.c
 cvs rdiff -u -r1.154 -r1.155 src/sys/arch/x86/x86/x86_machdep.c
 cvs rdiff -u -r1.96 -r1.97 src/sys/arch/xen/xen/hypervisor.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Manuel Bouyer" <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57813 CVS commit: src/sys/arch/amd64/amd64
Date: Tue, 3 Dec 2024 15:16:42 +0000

 Module Name:	src
 Committed By:	bouyer
 Date:		Tue Dec  3 15:16:42 UTC 2024

 Modified Files:
 	src/sys/arch/amd64/amd64: locore.S

 Log Message:
 Get one more change from PR kern/57813, needed for non-Xen PVH.


 To generate a diff of this commit:
 cvs rdiff -u -r1.226 -r1.227 src/sys/arch/amd64/amd64/locore.S

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Emile 'iMil' Heitor <imil@home.imil.net>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/57813 (Support for non-Xen PVH boot on amd64)
Date: Fri, 3 Jan 2025 14:48:37 +0100

 I must admit I didn't look at 32 bits guests, mainly because those
 already can boot with qemu's -kernel flag thanks to MULTIBOOT support.
 I might give it a shot when the current work on qemu/firecracker is
 merged.

From: Emile `iMil' Heitor <imil@home.imil.net>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/57813
Date: Mon, 6 Jan 2025 13:38:01 +0100 (CET)

 i386 port was pretty straightforward, here it is:
 https://imil.net/NetBSD/PVH-i386.patch

From: "Emile iMil Heitor" <imil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57813 CVS commit: src/sys/arch/i386
Date: Tue, 18 Feb 2025 10:16:04 +0000

 Module Name:	src
 Committed By:	imil
 Date:		Tue Feb 18 10:16:04 UTC 2025

 Modified Files:
 	src/sys/arch/i386/i386: genassym.cf locore.S machdep.c
 Added Files:
 	src/sys/arch/i386/conf: MICROVM

 Log Message:
 Add support for non-Xen PVH guests to i386, PR kern/57813
 Tested on QEMU by me, Xen PV & PVH by bouyer@.


 To generate a diff of this commit:
 cvs rdiff -u -r0 -r1.1 src/sys/arch/i386/conf/MICROVM
 cvs rdiff -u -r1.135 -r1.136 src/sys/arch/i386/i386/genassym.cf
 cvs rdiff -u -r1.198 -r1.199 src/sys/arch/i386/i386/locore.S
 cvs rdiff -u -r1.842 -r1.843 src/sys/arch/i386/i386/machdep.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: feedback->closed
State-Changed-By: bouyer@NetBSD.org
State-Changed-When: Wed, 19 Feb 2025 16:53:20 +0000
State-Changed-Why:
All patches have been commited to HEAD


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57813 CVS commit: [netbsd-10] src/sys/arch
Date: Sat, 29 Mar 2025 10:32:44 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Sat Mar 29 10:32:44 UTC 2025

 Modified Files:
 	src/sys/arch/amd64/amd64 [netbsd-10]: genassym.cf locore.S machdep.c
 	src/sys/arch/x86/acpi [netbsd-10]: acpi_machdep.c
 	src/sys/arch/x86/include [netbsd-10]: cpu.h
 	src/sys/arch/x86/x86 [netbsd-10]: consinit.c identcpu.c x86_autoconf.c
 	    x86_machdep.c
 	src/sys/arch/xen/xen [netbsd-10]: hypervisor.c

 Log Message:
 Pull up following revision(s) (requested by imil in ticket #1074):

 	sys/arch/x86/x86/x86_machdep.c: revision 1.155
 	sys/arch/x86/include/cpu.h: revision 1.137
 	sys/arch/x86/x86/x86_machdep.c: revision 1.156
 	sys/arch/x86/include/cpu.h: revision 1.138
 	sys/arch/x86/x86/consinit.c: revision 1.40
 	sys/arch/x86/acpi/acpi_machdep.c: revision 1.37
 	sys/arch/x86/acpi/acpi_machdep.c: revision 1.38
 	sys/arch/amd64/amd64/machdep.c: revision 1.370
 	sys/arch/xen/xen/hypervisor.c: revision 1.97
 	sys/arch/xen/xen/hypervisor.c: revision 1.98
 	sys/arch/amd64/amd64/genassym.cf: revision 1.98
 	sys/arch/x86/x86/x86_autoconf.c: revision 1.88
 	sys/arch/x86/x86/x86_autoconf.c: revision 1.89
 	sys/arch/amd64/amd64/locore.S: revision 1.226
 	sys/arch/amd64/amd64/locore.S: revision 1.227
 	sys/arch/x86/x86/identcpu.c: revision 1.131

 Add support for non-Xen PVH guests to amd64. Patch from
 Emile 'iMil' Heitor in PR kern/57813, with some cosmetic tweaks by me.
 Tested on bare metal, Xen PV and Xen PVH by me.

 Get one more change from PR kern/57813, needed for non-Xen PVH.

 Introduce vm_guest_is_pvh() and use it in place of
         (vm_guest == VM_GUEST_XENPVH || vm_guest == VM_GUEST_GENPVH)


 To generate a diff of this commit:
 cvs rdiff -u -r1.89 -r1.89.4.1 src/sys/arch/amd64/amd64/genassym.cf
 cvs rdiff -u -r1.214.4.2 -r1.214.4.3 src/sys/arch/amd64/amd64/locore.S
 cvs rdiff -u -r1.366 -r1.366.2.1 src/sys/arch/amd64/amd64/machdep.c
 cvs rdiff -u -r1.34.2.1 -r1.34.2.2 src/sys/arch/x86/acpi/acpi_machdep.c
 cvs rdiff -u -r1.133.4.1 -r1.133.4.2 src/sys/arch/x86/include/cpu.h
 cvs rdiff -u -r1.35.4.2 -r1.35.4.3 src/sys/arch/x86/x86/consinit.c
 cvs rdiff -u -r1.123.4.2 -r1.123.4.3 src/sys/arch/x86/x86/identcpu.c
 cvs rdiff -u -r1.87 -r1.87.4.1 src/sys/arch/x86/x86/x86_autoconf.c
 cvs rdiff -u -r1.152.4.1 -r1.152.4.2 src/sys/arch/x86/x86/x86_machdep.c
 cvs rdiff -u -r1.96 -r1.96.4.1 src/sys/arch/xen/xen/hypervisor.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2025 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.