diff --git a/sys/arch/amd64/amd64/genassym.cf b/sys/arch/amd64/amd64/genassym.cf index facd9216f75..ca40975affc 100644 --- a/sys/arch/amd64/amd64/genassym.cf +++ b/sys/arch/amd64/amd64/genassym.cf @@ -121,7 +121,7 @@ include <machine/i82093reg.h> include <machine/i82093var.h> endif -ifdef XEN +if defined(XEN) || defined(GENPVH) include <xen/include/public/xen.h> include <xen/include/public/arch-x86/hvm/start_info.h> endif @@ -375,6 +375,14 @@ define VM_GUEST_XENPV VM_GUEST_XENPV define VM_GUEST_XENPVH VM_GUEST_XENPVH define VM_GUEST_GENPVH VM_GUEST_GENPVH +if defined(XEN) || defined(GENPVH) +define HVM_START_INFO_SIZE sizeof(struct hvm_start_info) +define START_INFO_VERSION offsetof(struct hvm_start_info, version) +define MMAP_PADDR offsetof(struct hvm_start_info, memmap_paddr) +define MMAP_ENTRIES offsetof(struct hvm_start_info, memmap_entries) +define MMAP_ENTRY_SIZE sizeof(struct hvm_memmap_table_entry) +define CMDLINE_PADDR offsetof(struct hvm_start_info, cmdline_paddr) +endif ifdef XEN define CPU_INFO_VCPU offsetof(struct cpu_info, ci_vcpu) define IH_PENDING offsetof(struct intrhand, ih_pending) @@ -382,12 +390,6 @@ define SIR_XENIPL_VM SIR_XENIPL_VM define SIR_XENIPL_SCHED SIR_XENIPL_SCHED define SIR_XENIPL_HIGH SIR_XENIPL_HIGH define EVTCHN_UPCALL_MASK offsetof(struct vcpu_info, evtchn_upcall_mask) -define HVM_START_INFO_SIZE sizeof(struct hvm_start_info) -define START_INFO_VERSION offsetof(struct hvm_start_info, version) -define MMAP_PADDR offsetof(struct hvm_start_info, memmap_paddr) -define MMAP_ENTRIES offsetof(struct hvm_start_info, memmap_entries) -define MMAP_ENTRY_SIZE sizeof(struct hvm_memmap_table_entry) -define CMDLINE_PADDR offsetof(struct hvm_start_info, cmdline_paddr) ifdef XENPV define XEN_PT_BASE offsetof(struct start_info, pt_base) define XEN_NR_PT_FRAMES offsetof(struct start_info, nr_pt_frames) diff --git a/sys/arch/amd64/amd64/locore.S b/sys/arch/amd64/amd64/locore.S index 97519bcb6a1..ceee716d951 100644 --- a/sys/arch/amd64/amd64/locore.S +++ b/sys/arch/amd64/amd64/locore.S @@ -276,7 +276,7 @@ loop 1b ; -#ifdef XEN +#if defined(XEN) || defined(GENPVH) #define __ASSEMBLY__ #include <xen/include/public/arch-x86/cpuid.h> #include <xen/include/public/elfnote.h> @@ -319,7 +319,7 @@ #if NKSYMS > 0 || defined(DDB) || defined(MODULAR) ELFNOTE(Xen, XEN_ELFNOTE_BSD_SYMTAB, .asciz, "yes") #endif -#endif /* XEN */ +#endif /* XEN || GENPVH */ /* * Initialization @@ -423,7 +423,7 @@ _C_LABEL(farjmp64): .word GSEL(GCODE_SEL, SEL_KPL) END(farjmp64) -#ifdef XEN +#if defined(XEN) || defined(GENPVH) /* 32bit GDT */ gdtdesc32: .word gdt32end - gdt32 @@ -437,7 +437,7 @@ gdt32: .long 0x0000ffff # %ds, %es, %ss .long 0x00cf9200 gdt32end: -#endif /* XEN */ +#endif /* XEN || GENPVH */ #endif /* !XENPV */ /* Space for the temporary stack */ @@ -1022,6 +1022,7 @@ longmode_hi: call _C_LABEL(kasan_early_init) #endif /* <-- DO NOT INSERT C CALLS BEFORE THIS POINT --> */ + call _C_LABEL(init_start_info) #if defined(XEN) && !defined(XENPV) call _C_LABEL(init_xen_early) #endif @@ -1031,7 +1032,7 @@ longmode_hi: call _C_LABEL(main) END(start) -#if defined(XEN) +#if defined(XEN) || defined(GENPVH) # if !defined(XENPV) /* entry point for Xen PVH */ .code32 @@ -1187,7 +1188,7 @@ ENTRY(hypercall_page) /* Returns -1, on HYPERVISOR_xen_version() */ .align HYPERCALL_PAGE_OFFSET, 0x90 END(hypercall_page) -#endif /* XEN */ +#endif /* XEN || GENPVH */ /* * int setjmp(label_t *) diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index f1c8f5c66a6..389b2f458ce 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -196,13 +196,13 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.367 2023/07/16 19:55:43 riastradh Exp #include <machine/isa_machdep.h> #include <dev/ic/i8042reg.h> -#ifdef XEN +#if defined(XEN) || defined(GENPVH) #include <xen/xen.h> #include <xen/hypervisor.h> #include <xen/evtchn.h> #include <xen/include/public/version.h> #include <xen/include/public/vcpu.h> -#endif /* XEN */ +#endif /* XEN || GENPVH */ #include <ddb/db_active.h> @@ -1711,7 +1711,7 @@ init_x86_64(paddr_t first_avail) cpu_info_primary.ci_vcpu = &HYPERVISOR_shared_info->vcpu_info[0]; #endif -#ifdef XEN +#if defined(XEN) || defined(GENPVH) if (vm_guest == VM_GUEST_XENPVH || vm_guest == VM_GUEST_GENPVH) xen_parse_cmdline(XEN_PARSE_BOOTFLAGS, NULL); #endif @@ -1974,7 +1974,7 @@ init_x86_64(paddr_t first_avail) #ifdef XENPV xen_init_ksyms(); #else /* XENPV */ -#ifdef XEN +#if defined(XEN) if (vm_guest == VM_GUEST_XENPVH) xen_init_ksyms(); else diff --git a/sys/arch/x86/x86/consinit.c b/sys/arch/x86/x86/consinit.c index f72f872ab54..de0617c8110 100644 --- a/sys/arch/x86/x86/consinit.c +++ b/sys/arch/x86/x86/consinit.c @@ -99,7 +99,7 @@ __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.38 2023/10/17 16:06:36 bouyer Exp $") #endif #endif -#ifdef XENPVHVM +#if defined(XENPVHVM) || defined(GENPVH) #include <xen/hypervisor.h> #include <xen/xen.h> #endif @@ -173,12 +173,14 @@ consinit(void) #endif char console_devname[16] = ""; -#ifdef XENPVHVM +#if defined(XENPVHVM) || defined(GENPVH) +#ifndef GENPVH if (vm_guest == VM_GUEST_XENPVH) { if (xen_pvh_consinit() != 0) return; /* fallback to native console selection, usefull for dom0 PVH */ } +#endif if (vm_guest == VM_GUEST_GENPVH) { union xen_cmdline_parseinfo xcp; /* get console= parameter from generic PVH VMM */ diff --git a/sys/arch/x86/x86/mainbus.c b/sys/arch/x86/x86/mainbus.c index a74fbbe31b9..f7dfd102269 100644 --- a/sys/arch/x86/x86/mainbus.c +++ b/sys/arch/x86/x86/mainbus.c @@ -247,7 +247,7 @@ mainbus_attach(device_t parent, device_t self, void *aux) int mainbus_rescan(device_t self, const char *ifattr, const int *locators) { -#if defined(__i386__) && !defined(XEN) +#if defined(__i386__) && !defined(XEN) && !defined(GENPVH) return i386_mainbus_rescan(self, ifattr, locators); #endif return ENOTTY; /* Inappropriate ioctl for this device */ @@ -256,7 +256,7 @@ mainbus_rescan(device_t self, const char *ifattr, const int *locators) void mainbus_childdetached(device_t self, device_t child) { -#if defined(__i386__) && !defined(XEN) +#if defined(__i386__) && !defined(XEN) && !defined(GENPVH) i386_mainbus_childdetached(self, child); #endif } diff --git a/sys/arch/x86/x86/x86_autoconf.c b/sys/arch/x86/x86/x86_autoconf.c index ba4b698d067..9184b9419e6 100644 --- a/sys/arch/x86/x86/x86_autoconf.c +++ b/sys/arch/x86/x86/x86_autoconf.c @@ -539,7 +539,7 @@ findroot(void) void cpu_bootconf(void) { -#ifdef XEN +#if defined(XEN) || defined(GENPVH) if (vm_guest == VM_GUEST_XENPVH || vm_guest == VM_GUEST_GENPVH) { xen_bootconf(); return; diff --git a/sys/arch/x86/x86/x86_machdep.c b/sys/arch/x86/x86/x86_machdep.c index 8a2364b6ecc..0144bf25c23 100644 --- a/sys/arch/x86/x86/x86_machdep.c +++ b/sys/arch/x86/x86/x86_machdep.c @@ -99,7 +99,7 @@ static char x86_cpu_idle_text[16]; static bool x86_user_ldt_enabled __read_mostly = false; -#ifdef XEN +#if defined(XEN) || defined(GENPVH) #include <xen/xen.h> #include <xen/hypervisor.h> @@ -855,7 +855,7 @@ x86_load_region(uint64_t seg_start, uint64_t seg_end) } } -#ifdef XEN +#if defined(XEN) || defined(GENPVH) static void x86_add_xen_clusters(void) { @@ -895,7 +895,7 @@ x86_add_xen_clusters(void) x86_parse_clusters(&xen_mmap.bim); } } -#endif /* XEN */ +#endif /* XEN || GENPVH */ /* * init_x86_clusters: retrieve the memory clusters provided by the BIOS, and * initialize mem_clusters. @@ -910,7 +910,7 @@ init_x86_clusters(void) * Check to see if we have a memory map from the BIOS (passed to us by * the boot program). */ -#ifdef XEN +#if defined(XEN) || defined(GENPVH) if (vm_guest == VM_GUEST_XENPVH || vm_guest == VM_GUEST_GENPVH) { x86_add_xen_clusters(); } diff --git a/sys/arch/xen/conf/files.xen b/sys/arch/xen/conf/files.xen index 3c30954627b..55958e803fd 100644 --- a/sys/arch/xen/conf/files.xen +++ b/sys/arch/xen/conf/files.xen @@ -1,10 +1,10 @@ # $NetBSD: files.xen,v 1.189 2023/10/17 16:06:36 bouyer Exp $ -defflag opt_xen.h XEN XENPVHVM PAE DOM0OPS +defflag opt_xen.h XEN XENPVHVM PAE DOM0OPS GENPVH file arch/xen/x86/hypervisor_machdep.c xen file arch/xen/x86/xen_intr.c xen -file arch/xen/xen/xen_machdep.c xen +file arch/xen/xen/xen_machdep.c xen | genpvh file arch/xen/xen/evtchn.c xen file arch/xen/xen/xengnt.c xen file arch/xen/xen/xenmem.c xen & !xenpv @@ -15,6 +15,8 @@ file arch/xen/xen/genfb_xen.c xen & genfb file arch/xen/x86/pvh_consinit.c xenpvhvm +file arch/xen/xen/init_start_info.c xenpvhvm | genpvh + define hypervisorbus {} define xendevbus {} diff --git a/sys/arch/xen/include/hypervisor.h b/sys/arch/xen/include/hypervisor.h index fdc66e18e4b..b2b2da7f1b8 100644 --- a/sys/arch/xen/include/hypervisor.h +++ b/sys/arch/xen/include/hypervisor.h @@ -140,6 +140,8 @@ union start_info_union }; extern union start_info_union start_info_union; #define xen_start_info (start_info_union.start_info) +extern paddr_t HYPERVISOR_shared_info_pa; +extern uint32_t hvm_start_paddr; CTASSERT(sizeof(start_info_t) <= PAGE_SIZE); diff --git a/sys/arch/xen/xen/hypervisor.c b/sys/arch/xen/xen/hypervisor.c index 7e26b7696a6..b62236bc464 100644 --- a/sys/arch/xen/xen/hypervisor.c +++ b/sys/arch/xen/xen/hypervisor.c @@ -184,11 +184,6 @@ extern vector *x86_exceptions[]; extern vector IDTVEC(hypervisor_pvhvm_callback); extern struct xenstore_domain_interface *xenstore_interface; /* XXX */ -volatile shared_info_t *HYPERVISOR_shared_info __read_mostly; -paddr_t HYPERVISOR_shared_info_pa; -union start_info_union start_info_union __aligned(PAGE_SIZE); -struct hvm_start_info *hvm_start_info; - static int xen_hvm_vec = 0; #endif @@ -234,28 +229,10 @@ xen_init_hypercall_page(void) wrmsr(descs[1], (uintptr_t)&hypercall_page - KERNBASE); } -uint32_t hvm_start_paddr; - void init_xen_early(void); void init_xen_early(void) { - const char *cmd_line; - if (vm_guest != VM_GUEST_XENPVH && vm_guest != VM_GUEST_GENPVH) - return; - - hvm_start_info = (void *)((uintptr_t)hvm_start_paddr + KERNBASE); - - if (hvm_start_info->cmdline_paddr != 0) { - cmd_line = - (void *)((uintptr_t)hvm_start_info->cmdline_paddr + KERNBASE); - strlcpy(xen_start_info.cmd_line, cmd_line, - sizeof(xen_start_info.cmd_line)); - } else { - xen_start_info.cmd_line[0] = '\0'; - } - xen_start_info.flags = hvm_start_info->flags; - if (vm_guest != VM_GUEST_XENPVH) return; diff --git a/sys/arch/xen/xen/init_start_info.c b/sys/arch/xen/xen/init_start_info.c new file mode 100644 index 00000000000..65fc14d01ca --- /dev/null +++ b/sys/arch/xen/xen/init_start_info.c @@ -0,0 +1,57 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 2024 Emile 'iMil' Heitor. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <sys/param.h> +#include <xen/hypervisor.h> + +volatile shared_info_t *HYPERVISOR_shared_info __read_mostly; +paddr_t HYPERVISOR_shared_info_pa; +union start_info_union start_info_union __aligned(PAGE_SIZE); +struct hvm_start_info *hvm_start_info; + +uint32_t hvm_start_paddr; + +void init_start_info(void); +void +init_start_info(void) +{ + const char *cmd_line; + if (vm_guest != VM_GUEST_XENPVH && vm_guest != VM_GUEST_GENPVH) + return; + + hvm_start_info = (void *)((uintptr_t)hvm_start_paddr + KERNBASE); + + if (hvm_start_info->cmdline_paddr != 0) { + cmd_line = + (void *)((uintptr_t)hvm_start_info->cmdline_paddr + KERNBASE); + strlcpy(xen_start_info.cmd_line, cmd_line, + sizeof(xen_start_info.cmd_line)); + } else { + xen_start_info.cmd_line[0] = '\0'; + } + xen_start_info.flags = hvm_start_info->flags; +} diff --git a/sys/arch/xen/xen/xen_machdep.c b/sys/arch/xen/xen/xen_machdep.c index 3bb07c7c1d4..afae91b0ff9 100644 --- a/sys/arch/xen/xen/xen_machdep.c +++ b/sys/arch/xen/xen/xen_machdep.c @@ -90,8 +90,9 @@ __KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.29 2023/10/17 10:24:11 riastradh E #define DPRINTF(a) #endif - +#ifndef GENPVH bool xen_suspend_allow; +#endif void xen_parse_cmdline(int what, union xen_cmdline_parseinfo *xcp) @@ -442,6 +443,7 @@ printk(const char *fmt, ...) (void)HYPERVISOR_console_io(CONSOLEIO_write, ret, buf); } +#ifndef GENPVH static int early_xenconscn_getc(dev_t); static void early_xenconscn_putc(dev_t, int); static void early_xenconscn_pollc(dev_t, int); @@ -494,6 +496,7 @@ xen_init_features(void) } } } +#endif /* !GENPVH */ /* * Attempt to find the device from which we were booted.