Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Introduce Xen PVH support in GENERIC.



details:   https://anonhg.NetBSD.org/src/rev/11fb4b838c30
branches:  trunk
changeset: 971723:11fb4b838c30
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sat May 02 16:44:34 2020 +0000

description:
Introduce Xen PVH support in GENERIC.
This is compiled in with
options XENPVHVM
x86 changes:
- add Xen section and xen pvh entry points to locore.S. Set vm_guest
  to VM_GUEST_XENPVH in this entry point.
  Most of the boot procedure (especially page table setup and switch to
  paged mode) is shared with native.
- change some x86_delay() to delay_func(), which points to x86_delay() for
  native/HVM, and xen_delay() for PVH

Xen changes:
- remove Xen bits from init_x86_64_ksyms() and init386_ksyms()
  and move to xen_init_ksyms(), used for both PV and PVH
- set ISA no-legacy-devices property for PVH
- factor out code from Xen's cpu_bootconf() to xen_bootconf()
  in xen_machdep.c
- set up a specific pvh_consinit() which starts with printk()
  (which uses a simple hypercall that is available early) and switch to
  xencons when we can use pmap_kenter_pa().

diffstat:

 sys/arch/amd64/amd64/autoconf.c       |   11 +-
 sys/arch/amd64/amd64/genassym.cf      |    6 +-
 sys/arch/amd64/amd64/locore.S         |   89 +++++++++++-
 sys/arch/amd64/amd64/machdep.c        |   31 ++-
 sys/arch/amd64/conf/GENERIC           |    5 +-
 sys/arch/i386/i386/autoconf.c         |   11 +-
 sys/arch/i386/i386/genassym.cf        |    6 +-
 sys/arch/i386/i386/locore.S           |  140 +++++++++++++++---
 sys/arch/i386/i386/machdep.c          |   28 +++-
 sys/arch/x86/acpi/acpi_machdep.c      |   15 +-
 sys/arch/x86/include/cpu.h            |   14 +-
 sys/arch/x86/isa/clock.c              |    9 +-
 sys/arch/x86/isa/isa_machdep.c        |    7 +-
 sys/arch/x86/x86/consinit.c           |   15 +-
 sys/arch/x86/x86/cpu.c                |   18 +-
 sys/arch/x86/x86/lapic.c              |    8 +-
 sys/arch/x86/x86/pmap.c               |   10 +-
 sys/arch/x86/x86/x86_autoconf.c       |   12 +-
 sys/arch/x86/x86/x86_machdep.c        |   30 +++-
 sys/arch/xen/conf/Makefile.xen        |    4 +-
 sys/arch/xen/conf/files.xen           |    4 +-
 sys/arch/xen/include/hypervisor.h     |   10 +-
 sys/arch/xen/include/xen.h            |    6 +-
 sys/arch/xen/x86/autoconf.c           |   85 +-----------
 sys/arch/xen/x86/hypervisor_machdep.c |   36 ++++-
 sys/arch/xen/x86/pvh_consinit.c       |  115 +++++++++++++++
 sys/arch/xen/x86/x86_xpmap.c          |    5 +-
 sys/arch/xen/x86/xen_mainbus.c        |    5 +-
 sys/arch/xen/xen/hypervisor.c         |  249 +++++++++++++++++++++------------
 sys/arch/xen/xen/xen_clock.c          |   37 ++--
 sys/arch/xen/xen/xen_machdep.c        |  114 ++++++++++++++-
 31 files changed, 827 insertions(+), 308 deletions(-)

diffs (truncated from 2151 to 300 lines):

diff -r 35288de96243 -r 11fb4b838c30 sys/arch/amd64/amd64/autoconf.c
--- a/sys/arch/amd64/amd64/autoconf.c   Sat May 02 16:28:37 2020 +0000
+++ b/sys/arch/amd64/amd64/autoconf.c   Sat May 02 16:44:34 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.c,v 1.29 2019/12/27 12:51:56 ad Exp $ */
+/*     $NetBSD: autoconf.c,v 1.30 2020/05/02 16:44:34 bouyer Exp $     */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.29 2019/12/27 12:51:56 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.30 2020/05/02 16:44:34 bouyer Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_intrdebug.h"
@@ -92,7 +92,14 @@
 void
 cpu_configure(void)
 {
+#ifdef XEN
+       if (vm_guest == VM_GUEST_XENPVH)
+               xen_startrtclock();
+       else
+               startrtclock();
+#else
        startrtclock();
+#endif
 
 #if NBIOS32 > 0
        efi_init();
diff -r 35288de96243 -r 11fb4b838c30 sys/arch/amd64/amd64/genassym.cf
--- a/sys/arch/amd64/amd64/genassym.cf  Sat May 02 16:28:37 2020 +0000
+++ b/sys/arch/amd64/amd64/genassym.cf  Sat May 02 16:44:34 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: genassym.cf,v 1.83 2020/04/25 15:26:16 bouyer Exp $
+#      $NetBSD: genassym.cf,v 1.84 2020/05/02 16:44:34 bouyer Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -120,6 +120,7 @@
 
 ifdef XEN
 include <xen/include/public/xen.h>
+include <xen/include/public/arch-x86/hvm/start_info.h>
 endif  
 
 include <sys/bus.h>
@@ -361,6 +362,7 @@
 define BST_TYPE                offsetof(struct bus_space_tag, bst_type)
 
 define VM_GUEST_XENPV          VM_GUEST_XENPV
+define VM_GUEST_XENPVH         VM_GUEST_XENPVH
 
 ifdef XEN
 define CPU_INFO_VCPU           offsetof(struct cpu_info, ci_vcpu)
@@ -373,7 +375,7 @@
 define XEN_NR_PT_FRAMES                offsetof(struct start_info, nr_pt_frames)
 define __HYPERVISOR_iret       __HYPERVISOR_iret
 endif /* XENPV */
-endif
+endif /* XEN */
 
 define NKL4_KIMG_ENTRIES       NKL4_KIMG_ENTRIES
 define NKL3_KIMG_ENTRIES       NKL3_KIMG_ENTRIES
diff -r 35288de96243 -r 11fb4b838c30 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S     Sat May 02 16:28:37 2020 +0000
+++ b/sys/arch/amd64/amd64/locore.S     Sat May 02 16:44:34 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.205 2020/05/02 16:28:37 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.206 2020/05/02 16:44:34 bouyer Exp $      */
 
 /*
  * Copyright-o-rama!
@@ -279,9 +279,7 @@
 #define __ASSEMBLY__
 #include <xen/include/public/elfnote.h>
 #include <xen/include/public/xen.h>
-#endif /* XEN */
 
-#ifdef XENPV   
 #define ELFNOTE(name, type, desctype, descdata...) \
 .pushsection .note.name                        ;       \
   .align 4                             ;       \
@@ -302,11 +300,16 @@
        ELFNOTE(Xen, XEN_ELFNOTE_GUEST_VERSION,  .asciz, "4.99")
        ELFNOTE(Xen, XEN_ELFNOTE_XEN_VERSION,    .asciz, "xen-3.0")
        ELFNOTE(Xen, XEN_ELFNOTE_VIRT_BASE,      .quad,  KERNBASE)
+#ifdef XENPV
        ELFNOTE(Xen, XEN_ELFNOTE_PADDR_OFFSET,   .quad,  KERNBASE)
        ELFNOTE(Xen, XEN_ELFNOTE_ENTRY,          .quad,  start)
+#else
+       ELFNOTE(Xen, XEN_ELFNOTE_PADDR_OFFSET,   .quad,  0)
+       ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY,   .long,  RELOC(start_xen32))
+#endif /* XENPV */
        ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, .quad,  hypercall_page)
        ELFNOTE(Xen, XEN_ELFNOTE_HV_START_LOW,   .quad,  HYPERVISOR_VIRT_START)
-       ELFNOTE(Xen, XEN_ELFNOTE_FEATURES,       .asciz, "")
+       ELFNOTE(Xen, XEN_ELFNOTE_FEATURES,       .asciz, "writable_descriptor_tables|auto_translated_physmap|supervisor_mode_kernel|hvm_callback_vector")
        ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE,       .asciz, "yes")
        ELFNOTE(Xen, XEN_ELFNOTE_L1_MFN_VALID,   .long,  PTE_P, PTE_P)\
        ELFNOTE(Xen, XEN_ELFNOTE_LOADER,         .asciz, "generic")     
@@ -314,7 +317,7 @@
 #if NKSYMS > 0 || defined(DDB) || defined(MODULAR)
        ELFNOTE(Xen, XEN_ELFNOTE_BSD_SYMTAB,     .asciz, "yes")
 #endif
-#endif  /* XENPV */    
+#endif  /* XEN */
 
 /*
  * Initialization
@@ -418,6 +421,21 @@
        .word   GSEL(GCODE_SEL, SEL_KPL)
 END(farjmp64)
 
+#ifdef XEN
+/* 32bit GDT */
+gdtdesc32:
+       .word   gdt32end - gdt32
+       .long   RELOC(gdt32)
+       .long   0
+gdt32:  
+       .long   0                       # null descriptor
+       .long   0
+       .long   0x0000ffff              # %cs
+       .long   0x00cf9a00 
+       .long   0x0000ffff              # %ds, %es, %ss
+       .long   0x00cf9200
+gdt32end:
+#endif /* XEN */
 #endif /* !XENPV */
 
        /* Space for the temporary stack */
@@ -973,6 +991,9 @@
 #endif /* XENPV */
 
        pushq   %rdi
+#if defined(XEN) && !defined(XENPV)
+       call    _C_LABEL(init_xen_early)
+#endif
        call    _C_LABEL(init_bootspace)
 #ifdef KASAN
        movq    _C_LABEL(lwp0uarea)(%rip),%rdi
@@ -984,6 +1005,64 @@
        call    _C_LABEL(main)
 END(start)
 
+#ifndef XENPV
+/* entry point for Xen PVH */
+       .code32
+ENTRY(start_xen32)
+       /* Xen doesn't start us with a valid gdt */
+       movl    $RELOC(gdtdesc32), %eax
+       lgdt    (%eax)
+       jmp     $GSEL(GCODE_SEL, SEL_KPL), $RELOC(.Lreload_cs)
+
+.Lreload_cs:
+       movw    $GSEL(GDATA_SEL, SEL_KPL), %ax          
+       movw    %ax, %ds
+       movw    %ax, %es
+       movw    %ax, %ss   
+
+       /* we need a valid stack */
+       movl    $RELOC(tmpstk),%esp
+
+       /* clear BSS */
+        xorl    %eax,%eax
+       movl    $RELOC(__bss_start),%edi
+       movl    $RELOC(_end),%ecx
+       subl    %edi,%ecx
+       rep
+       stosb
+
+       /*
+        * save addr of the hvm_start_info structure. This is also the end
+        * of the symbol table
+        */
+       movl    %ebx, RELOC(hvm_start_paddr)
+       movl    %ebx, %eax
+       addl    $KERNBASE_LO,%eax
+       movl    $RELOC(esym),%ebp
+       movl    %eax,(%ebp)
+       movl    $KERNBASE_HI,4(%ebp)
+       /* get a page for HYPERVISOR_shared_info */
+       addl    $PAGE_SIZE, %ebx
+       addl    $PGOFSET,%ebx
+       andl    $~PGOFSET,%ebx
+       movl    $RELOC(HYPERVISOR_shared_info_pa),%ebp
+       movl    %ebx,(%ebp)
+       movl    $0,4(%ebp)
+       /* XXX assume hvm_start_info+dependant struture fits in a single page */
+       addl    $PAGE_SIZE, %ebx
+       addl    $PGOFSET,%ebx
+       andl    $~PGOFSET,%ebx
+       addl    $KERNBASE_LO,%ebx
+       movl    $RELOC(eblob),%ebp
+       movl    %ebx,(%ebp)
+       movl    $KERNBASE_HI,4(%ebp)
+
+       /* annouce ourself */
+       movl    $VM_GUEST_XENPVH, RELOC(vm_guest)
+       jmp .Lbiosbasemem_finished
+END(start_xen32)
+       .code64
+#endif /* XENPV */
 #if defined(XEN)
 /* space for the hypercall call page */
 #define HYPERCALL_PAGE_OFFSET 0x1000
diff -r 35288de96243 -r 11fb4b838c30 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Sat May 02 16:28:37 2020 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Sat May 02 16:44:34 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.351 2020/05/02 16:28:37 maxv Exp $       */
+/*     $NetBSD: machdep.c,v 1.352 2020/05/02 16:44:34 bouyer Exp $     */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.351 2020/05/02 16:28:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.352 2020/05/02 16:44:34 bouyer Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -1483,22 +1483,20 @@
 extern vector IDTVEC(osyscall);
 extern vector *x86_exceptions[];
 
+#ifndef XENPV
 static void
 init_x86_64_ksyms(void)
 {
 #if NKSYMS || defined(DDB) || defined(MODULAR)
        extern int end;
        extern int *esym;
-#ifndef XENPV
        struct btinfo_symtab *symtab;
        vaddr_t tssym, tesym;
-#endif
 
 #ifdef DDB
        db_machine_init();
 #endif
 
-#ifndef XENPV
        symtab = lookup_bootinfo(BTINFO_SYMTAB);
        if (symtab) {
 #ifdef KASLR
@@ -1512,15 +1510,9 @@
        } else
                ksyms_addsyms_elf(*(long *)(void *)&end,
                    ((long *)(void *)&end) + 1, esym);
-#else  /* XENPV */
-       esym = xen_start_info.mod_start ?
-           (void *)xen_start_info.mod_start :
-           (void *)xen_start_info.mfn_list;
-       ksyms_addsyms_elf(*(int *)(void *)&end,
-           ((int *)(void *)&end) + 1, esym);
-#endif /* XENPV */
 #endif
 }
+#endif /* XENPV */
 
 void __noasan
 init_bootspace(void)
@@ -1676,6 +1668,10 @@
        cpu_info_primary.ci_vcpu = &HYPERVISOR_shared_info->vcpu_info[0];
 #endif
 
+#ifdef XEN
+       if (vm_guest == VM_GUEST_XENPVH)
+               xen_parse_cmdline(XEN_PARSE_BOOTFLAGS, NULL);
+#endif
        init_pte();
 
        uvm_lwp_setuarea(&lwp0, lwp0uarea);
@@ -1903,7 +1899,16 @@
 
        cpu_init_idt();
 
-       init_x86_64_ksyms();
+#ifdef XENPV
+       xen_init_ksyms();
+#else /* XENPV */
+#ifdef XEN
+       if (vm_guest == VM_GUEST_XENPVH)
+               xen_init_ksyms();
+       else
+#endif /* XEN */
+               init_x86_64_ksyms();
+#endif /* XENPV */
 
 #ifndef XENPV
        intr_default_setup();
diff -r 35288de96243 -r 11fb4b838c30 sys/arch/amd64/conf/GENERIC
--- a/sys/arch/amd64/conf/GENERIC       Sat May 02 16:28:37 2020 +0000



Home | Main Index | Thread Index | Old Index