head 1.5; access; symbols netbsd-11-0-RELEASE:1.3.2.2 netbsd-11-0-RC7:1.3.2.2 netbsd-11-0-RC6:1.3.2.2 netbsd-11-0-RC5:1.3.2.2 netbsd-11-0-RC4:1.3.2.2 netbsd-11-0-RC3:1.3.2.2 netbsd-11-0-RC2:1.3.2.2 netbsd-11-0-RC1:1.3.2.2 perseant-exfatfs:1.3.0.4 perseant-exfatfs-base-20250801:1.3 netbsd-11:1.3.0.2 netbsd-11-base:1.3; locks; strict; comment @# @; 1.5 date 2025.12.05.17.58.11; author khorben; state Exp; branches; next 1.4; commitid 0hsDTEqevuWTjflG; 1.4 date 2025.08.23.08.48.13; author imil; state Exp; branches; next 1.3; commitid dkdTwum72XJoEP7G; 1.3 date 2025.03.28.05.54.49; author imil; state Exp; branches 1.3.2.1 1.3.4.1; next 1.2; commitid 9Om3ccALSyfPsNOF; 1.2 date 2025.03.27.12.22.43; author riastradh; state Exp; branches; next 1.1; commitid E7rF9ahYVUe0EHOF; 1.1 date 2025.01.15.13.16.22; author imil; state Exp; branches; next ; commitid DrfRFjAynasFbAFF; 1.3.2.1 date 2025.08.25.16.04.04; author martin; state Exp; branches; next 1.3.2.2; commitid 8giT1njN4WY2188G; 1.3.2.2 date 2026.02.02.17.46.18; author martin; state Exp; branches; next ; commitid Olpij3RufGSfpPsG; 1.3.4.1 date 2025.03.28.05.54.49; author perseant; state dead; branches; next 1.3.4.2; commitid 23j6GFaDws3O875G; 1.3.4.2 date 2025.08.02.05.55.24; author perseant; state Exp; branches; next ; commitid 23j6GFaDws3O875G; desc @@ 1.5 log @sys/arch/amd64: support ramdisks when booting in GENPVH mode This adds support for booting NetBSD/amd64 with QEMU’s -kernel/-initrd combination, in generic PVH mode (GENPVH). This includes the MICROVM kernel, which now defaults to supporting modules and root on memory disks. This patch probes the first few bytes loaded in memory for differentiating between modules, splash screens (PNG or JPEG), or assumes filesystem images otherwise. It works with plain filesystem images, but not with modules yet. Supporting any combination of filesystem, modules or splash screen images should be possible in the future. Tested on NetBSD/amd64 by iMil and myself; measured to gain another 1~3 ms of boot time with the MICROVM kernel on the reference hardware. As posted on tech-kern@@ on 26/11/2025, with no objections. XXX pull-up to -11 and adapt for -10 @ text @# $NetBSD: MICROVM,v 1.4 2025/08/23 08:48:13 imil Exp $ # # MICROVM kernel configuration, for use with Qemu microvm machine type # or Firecracker. # Stripped-down configuration with no PCI, use VirtIO over MMIO virtual # bus instead. ACPI is disabled as Firecracker doesn't support it, # use legacy MP tables instead. # # Exemple qemu usage on a Linux host to boot a NetBSD guest: # # qemu-system-x86_64 \ # -M microvm,x-option-roms=off,rtc=on,acpi=off,pic=off,accel=kvm \ # -m 256 -cpu host,+invtsc -kernel ${KERNEL} \ # -append "root=ld0a console=com rw -z" \ # -display none -device virtio-blk-device,drive=hd0 \ # -drive file=${IMG},format=raw,id=hd0 \ # -device virtio-net-device,netdev=net0 \ # -netdev user,id=net0,ipv6=off,hostfwd=::2200-:22 \ # -global virtio-mmio.force-legacy=false -serial stdio machine amd64 x86 xen include "arch/x86/conf/MICROVM.common" options EXEC_ELF64 # exec ELF binaries options MODULAR # new style module(7) framework options MEMORY_DISK_HOOKS # enable md specific hooks options MEMORY_DISK_DYNAMIC # enable dynamic resizing @ 1.4 log @Add `+invtsc` to the QEMU command line example, this enables the invariant TSC feature, allowing the kernel to use CPUID 0x40000010 to read TSC and LAPIC frequencies from the host, thus avoiding the need for frequency calculation and gaining over 200ms in boot speed. @ text @d1 1 a1 1 # $NetBSD: MICROVM,v 1.3 2025/03/28 05:54:49 imil Exp $ d26 4 @ 1.3 log @x86: consolidate MICROVM kernel configurations Move common configuration options from amd64/conf/MICROVM and i386/conf/MICROVM into a shared x86/conf/MICROVM.common file. @ text @d1 1 a1 1 # $NetBSD: MICROVM,v 1.2 2025/03/27 12:22:43 riastradh Exp $ d13 1 a13 1 # -m 256 -cpu host -kernel ${KERNEL} \ @ 1.3.2.1 log @Pull up following revision(s) (requested by imil in ticket #14): sys/arch/amd64/conf/MICROVM: revision 1.4 sys/arch/i386/conf/MICROVM: revision 1.4 Add `+invtsc` to the QEMU command line example, this enables the invariant TSC feature, allowing the kernel to use CPUID 0x40000010 to read TSC and LAPIC frequencies from the host, thus avoiding the need for frequency calculation and gaining over 200ms in boot speed. @ text @d1 1 a1 1 # $NetBSD: MICROVM,v 1.3 2025/03/28 05:54:49 imil Exp $ d13 1 a13 1 # -m 256 -cpu host,+invtsc -kernel ${KERNEL} \ @ 1.3.2.2 log @Pull up following revision(s) (requested by khorben in ticket #170): sys/arch/amd64/conf/MICROVM: revision 1.5 sys/arch/amd64/amd64/locore.S: revision 1.234 sys/arch/x86/x86/x86_machdep.c: revision 1.160 sys/arch/amd64/amd64/genassym.cf: revision 1.100 sys/arch/amd64: support ramdisks when booting in GENPVH mode This adds support for booting NetBSD/amd64 with QEMU's -kernel/-initrd combination, in generic PVH mode (GENPVH). This includes the MICROVM kernel, which now defaults to supporting modules and root on memory disks. This patch probes the first few bytes loaded in memory for differentiating between modules, splash screens (PNG or JPEG), or assumes filesystem images otherwise. It works with plain filesystem images, but not with modules yet. Supporting any combination of filesystem, modules or splash screen images should be possible in the future. Tested on NetBSD/amd64 by iMil and myself; measured to gain another 1~3 ms of boot time with the MICROVM kernel on the reference hardware. As posted on tech-kern@@ on 26/11/2025, with no objections. @ text @d1 1 a1 1 # $NetBSD: MICROVM,v 1.3.2.1 2025/08/25 16:04:04 martin Exp $ a25 4 options MODULAR # new style module(7) framework options MEMORY_DISK_HOOKS # enable md specific hooks options MEMORY_DISK_DYNAMIC # enable dynamic resizing @ 1.3.4.1 log @file MICROVM was added on branch perseant-exfatfs on 2025-08-02 05:55:24 +0000 @ text @d1 25 @ 1.3.4.2 log @Sync with HEAD @ text @a0 25 # $NetBSD: MICROVM,v 1.3 2025/03/28 05:54:49 imil Exp $ # # MICROVM kernel configuration, for use with Qemu microvm machine type # or Firecracker. # Stripped-down configuration with no PCI, use VirtIO over MMIO virtual # bus instead. ACPI is disabled as Firecracker doesn't support it, # use legacy MP tables instead. # # Exemple qemu usage on a Linux host to boot a NetBSD guest: # # qemu-system-x86_64 \ # -M microvm,x-option-roms=off,rtc=on,acpi=off,pic=off,accel=kvm \ # -m 256 -cpu host -kernel ${KERNEL} \ # -append "root=ld0a console=com rw -z" \ # -display none -device virtio-blk-device,drive=hd0 \ # -drive file=${IMG},format=raw,id=hd0 \ # -device virtio-net-device,netdev=net0 \ # -netdev user,id=net0,ipv6=off,hostfwd=::2200-:22 \ # -global virtio-mmio.force-legacy=false -serial stdio machine amd64 x86 xen include "arch/x86/conf/MICROVM.common" options EXEC_ELF64 # exec ELF binaries @ 1.2 log @virtio(4): Consolidate kernel configs. No functional change intended. Leave `# XXX ?' comments where I don't know why the driver in question is excluded. (Typical reason is that PAGE_SIZE is not 4096 but I didn't investigate -- if you do investigate, please either update the comment if you determine a reason, or enable the driver if you don't.) PR kern/59211: vio9p(4): missing from various GENERICs and MAKEDEVs @ text @d1 1 a1 1 # $NetBSD: MICROVM,v 1.1 2025/01/15 13:16:22 imil Exp $ a21 2 include "conf/std" # MI standard options include "arch/xen/conf/std.xenversion" d23 2 a24 1 options CPU_IN_CKSUM a25 111 options EXEC_SCRIPT # exec #! scripts options MTRR options MULTIPROCESSOR options CHILD_MAX=1024 # 160 is too few options OPEN_MAX=1024 # 128 is too few mainbus0 at root cpu* at mainbus? ioapic* at mainbus? apid ? options INCLUDE_CONFIG_FILE # embed config file in kernel binary maxusers 8 # estimated number of users options INSECURE # disable kernel security levels - X needs this options RTC_OFFSET=0 # hardware clock is this many mins. west of GMT options PIPE_SOCKETPAIR # smaller, but slower pipe(2) # Xen PV support for PVH and HVM guests, needed for PVH boot options XENPVHVM options XEN hypervisor* at mainbus? # Xen hypervisor xenbus* at hypervisor? # Xen virtual bus xencons* at hypervisor? # Xen virtual console # Include NetBSD 10 compatibility options COMPAT_100 # # Because gcc omits the frame pointer for any -O level, the line below # is needed to make backtraces in DDB work. # makeoptions COPTS="-O2 -fno-omit-frame-pointer" # File systems #include "conf/filesystems.config" file-system FFS file-system EXT2FS file-system KERNFS file-system MFS file-system TMPFS file-system PTYFS file-system MSDOSFS file-system PROCFS options DKWEDGE_AUTODISCOVER options DKWEDGE_METHOD_GPT # File system options # ffs options FFS_NO_SNAPSHOT # No FFS snapshot support options WAPBL # File system journaling support # Networking options #options GATEWAY # packet forwarding options INET # IP + ICMP + TCP + UDP options INET6 # IPV6 # Kernel root file system and dump configuration. config netbsd root on ? type ? # # Device configuration # # ACPI will be used if present. If not it will fall back to MPBIOS options MPBIOS # configure CPUs and APICs using MPBIOS # Provide bug-for-bug compatibility with Linux in MP Table searching # and parsing. Firecracker relies on these bugs. options MPTABLE_LINUX_BUG_COMPAT #pci* at mainbus? bus ? #acpi0 at mainbus0 # ISA bus support isa0 at mainbus? # ISA serial interfaces com0 at isa? port 0x3f8 irq 4 # Standard PC serial ports # Virtual bus for non-PCI devices pv* at pvbus? ## Virtio devices # Use MMIO by default virtio* at pv? #virtio* at acpi? #virtio* at pci? dev ? function ? # Virtio PCI device include "dev/virtio/virtio.config" no viomb* at virtio? # XXX ? no vioscsi* at virtio? # XXX ? pseudo-device md # memory disk device (ramdisk) #options MEMORY_DISK_HOOKS # enable md specific hooks #options MEMORY_DISK_DYNAMIC # enable dynamic resizing # pseudo-device vnd # disk-like interface to files #options VND_COMPRESSION # compressed vnd(4) ## network pseudo-devices pseudo-device bpfilter # Berkeley packet filter pseudo-device loop # network loopback ## miscellaneous pseudo-devices pseudo-device pty # pseudo-terminals # userland interface to drivers, including autoconf and properties retrieval pseudo-device drvctl file-system PUFFS pseudo-device putter @ 1.1 log @Add support for command line MMIO devices, at least qemu and Firecracker pass MMIO virtual devices mapping through the kernel command line. This driver is based on Colin Percival's FreeBSD virtio_mmio_cmdline.c https://github.com/freebsd/freebsd-src/blob/main/sys/dev/virtio/mmio/virtio_mmio_cmdline.c The following kernel options are needed options MPBIOS options MPTABLE_LINUX_BUG_COMPAT As are these drivers pv* at pvbus? virtio* at pv? Exemple qemu usage on a Linux host to boot a NetBSD guest: qemu-system-x86_64 \ -M microvm,x-option-roms=off,rtc=on,acpi=off,pic=off,accel=kvm \ -m 256 -cpu host -kernel ${KERNEL} \ -append "root=ld0a console=com rw -v" \ -device virtio-blk-device,drive=hd0 \ -drive file=${IMG},format=raw,id=hd0 \ -device virtio-net-device,netdev=net0 \ -netdev user,id=net0,ipv6=off,hostfwd=::2200-:22 \ -global virtio-mmio.force-legacy=false -display none -serial stdio A lightweight kernel configuration named MICROVM if available for this use case. @ text @d1 1 a1 1 # $NetBSD$ a114 1 #viomb* at virtio? # Virtio memory balloon device d116 3 a118 8 ld* at virtio? # Virtio disk device vioif* at virtio? # Virtio network device viornd* at virtio? # Virtio entropy device viocon* at virtio? vio9p* at virtio? # Virtio 9P device #vioscsi* at virtio? #scsibus* at vioscsi? @