Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Switch to elf notes for amd64 instead of the old ke...



details:   https://anonhg.NetBSD.org/src/rev/f7bed76c73b7
branches:  trunk
changeset: 345456:f7bed76c73b7
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sun May 29 17:06:17 2016 +0000

description:
Switch to elf notes for amd64 instead of the old key=value list to describe the
  guest requirements and support.
Add infrastructure to query the hypervisor about features support.
For verbose boot, print the features suppoted by the hypervisor for this
  guest.

diffstat:

 sys/arch/amd64/amd64/locore.S  |  40 ++++++++++++++++++++++++++++++----------
 sys/arch/xen/include/xen.h     |  14 +++++++++++++-
 sys/arch/xen/x86/x86_xpmap.c   |   6 ++++--
 sys/arch/xen/xen/hypervisor.c  |  23 +++++++++++++++++++++--
 sys/arch/xen/xen/xen_machdep.c |  22 ++++++++++++++++++++--
 5 files changed, 88 insertions(+), 17 deletions(-)

diffs (206 lines):

diff -r 9c591159e1d4 -r f7bed76c73b7 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S     Sun May 29 17:00:35 2016 +0000
+++ b/sys/arch/amd64/amd64/locore.S     Sun May 29 17:06:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.98 2016/05/29 09:16:11 maxv Exp $ */
+/*     $NetBSD: locore.S,v 1.99 2016/05/29 17:06:17 bouyer Exp $       */
 
 /*
  * Copyright-o-rama!
@@ -271,21 +271,41 @@
 
 
 #ifdef XEN
+#define __ASSEMBLY__
+#include <xen/xen-public/elfnote.h>
+#include <xen/xen-public/xen.h>
+#define ELFNOTE(name, type, desctype, descdata...) \
+.pushsection .note.name                        ;       \
+  .align 4                             ;       \
+  .long 2f - 1f                /* namesz */    ;       \
+  .long 4f - 3f                /* descsz */    ;       \
+  .long type                           ;       \
+1:.asciz #name                         ;       \
+2:.align 4                             ;       \
+3:desctype descdata                    ;       \
+4:.align 4                             ;       \
+.popsection
+
 /*
  * Xen guest identifier and loader selection
  */
 .section __xen_guest
-       .ascii  "GUEST_OS=NetBSD,GUEST_VER=4.99"
-       .ascii  ",XEN_VER=xen-3.0"
-       .ascii  ",LOADER=generic"
-       .ascii  ",VIRT_BASE=0xffffffff80000000"
-       .ascii  ",ELF_PADDR_OFFSET=0xffffffff80000000"
-       .ascii  ",VIRT_ENTRY=0xffffffff80100000"
-       .ascii  ",HYPERCALL_PAGE=0x00000101" /*  (???+HYPERCALL_PAGE_OFFSET)/PAGE_SIZE) */
+       ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS,       .asciz, "NetBSD")
+       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)
+       ELFNOTE(Xen, XEN_ELFNOTE_PADDR_OFFSET,   .quad,  KERNBASE)
+       ELFNOTE(Xen, XEN_ELFNOTE_ENTRY,          .quad,  start)
+       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_PAE_MODE,       .asciz, "yes")
+       ELFNOTE(Xen, XEN_ELFNOTE_L1_MFN_VALID,   .long,  PG_V, PG_V)\
+       ELFNOTE(Xen, XEN_ELFNOTE_LOADER,         .asciz, "generic")     
+       ELFNOTE(Xen, XEN_ELFNOTE_SUSPEND_CANCEL, .long,  0)
 #if NKSYMS > 0 || defined(DDB) || defined(MODULAR)
-       .ascii  ",BSD_SYMTAB=yes"
+       ELFNOTE(Xen, XEN_ELFNOTE_BSD_SYMTAB,     .asciz, "yes")
 #endif
-       .byte   0
 #endif /* XEN */
 
 /*
diff -r 9c591159e1d4 -r f7bed76c73b7 sys/arch/xen/include/xen.h
--- a/sys/arch/xen/include/xen.h        Sun May 29 17:00:35 2016 +0000
+++ b/sys/arch/xen/include/xen.h        Sun May 29 17:06:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xen.h,v 1.35 2011/09/20 00:12:24 jym Exp $     */
+/*     $NetBSD: xen.h,v 1.36 2016/05/29 17:06:17 bouyer Exp $  */
 
 /*
  *
@@ -345,6 +345,18 @@
 
 void   wbinvd(void);
 
+#include <xen/xen-public/features.h>
+#include <sys/systm.h>
+
+extern bool xen_feature_tables[];
+void xen_init_features(void);
+static __inline bool
+xen_feature(int f)
+{
+       KASSERT(f < XENFEAT_NR_SUBMAPS * 32);
+       return xen_feature_tables[f];
+}
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* _OS_H_ */
diff -r 9c591159e1d4 -r f7bed76c73b7 sys/arch/xen/x86/x86_xpmap.c
--- a/sys/arch/xen/x86/x86_xpmap.c      Sun May 29 17:00:35 2016 +0000
+++ b/sys/arch/xen/x86/x86_xpmap.c      Sun May 29 17:06:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_xpmap.c,v 1.53 2014/05/06 04:26:24 cherry Exp $    */
+/*     $NetBSD: x86_xpmap.c,v 1.54 2016/05/29 17:06:17 bouyer Exp $    */
 
 /*
  * Copyright (c) 2006 Mathieu Ropert <mro%adviseo.fr@localhost>
@@ -69,7 +69,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.53 2014/05/06 04:26:24 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.54 2016/05/29 17:06:17 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -614,6 +614,8 @@
        long mapsize;
        vaddr_t bootstrap_tables, init_tables;
 
+       xen_init_features();
+
        memset(xpq_idx_array, 0, sizeof xpq_idx_array);
 
        xpmap_phys_to_machine_mapping =
diff -r 9c591159e1d4 -r f7bed76c73b7 sys/arch/xen/xen/hypervisor.c
--- a/sys/arch/xen/xen/hypervisor.c     Sun May 29 17:00:35 2016 +0000
+++ b/sys/arch/xen/xen/hypervisor.c     Sun May 29 17:06:17 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.65 2014/02/01 20:07:07 bouyer Exp $ */
+/* $NetBSD: hypervisor.c,v 1.66 2016/05/29 17:06:17 bouyer Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.65 2014/02/01 20:07:07 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.66 2016/05/29 17:06:17 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -212,6 +212,25 @@
        aprint_normal(": Xen version %d.%d%s\n", XEN_MAJOR(xen_version),
                XEN_MINOR(xen_version), xen_extra_version);
 
+       aprint_verbose_dev(self, "features: ");
+#define XEN_TST_F(n) \
+       if (xen_feature(XENFEAT_##n)) \
+               aprint_verbose(" %s", #n);
+
+       XEN_TST_F(writable_page_tables);
+       XEN_TST_F(writable_descriptor_tables);
+       XEN_TST_F(auto_translated_physmap);
+       XEN_TST_F(supervisor_mode_kernel);
+       XEN_TST_F(pae_pgdir_above_4gb);
+       XEN_TST_F(mmu_pt_update_preserve_ad);
+       XEN_TST_F(highmem_assist);
+       XEN_TST_F(gnttab_map_avail_bits);
+       XEN_TST_F(hvm_callback_vector);
+       XEN_TST_F(hvm_safe_pvclock);
+       XEN_TST_F(hvm_pirqs);
+#undef XEN_TST_F
+       aprint_verbose("\n");
+
        xengnt_init();
        events_init();
 
diff -r 9c591159e1d4 -r f7bed76c73b7 sys/arch/xen/xen/xen_machdep.c
--- a/sys/arch/xen/xen/xen_machdep.c    Sun May 29 17:00:35 2016 +0000
+++ b/sys/arch/xen/xen/xen_machdep.c    Sun May 29 17:06:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xen_machdep.c,v 1.13 2012/07/28 02:08:51 matt Exp $    */
+/*     $NetBSD: xen_machdep.c,v 1.14 2016/05/29 17:06:17 bouyer Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.13 2012/07/28 02:08:51 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.14 2016/05/29 17:06:17 bouyer Exp $");
 
 #include "opt_xen.h"
 
@@ -68,6 +68,7 @@
 
 #include <xen/hypervisor.h>
 #include <xen/shutdown_xenbus.h>
+#include <xen/xen-public/version.h>
 
 #define DPRINTK(x) printk x
 #if 0
@@ -396,3 +397,20 @@
        aprint_verbose("domain resumed\n");
 
 }
+
+bool xen_feature_tables[XENFEAT_NR_SUBMAPS * 32];
+
+void
+xen_init_features(void)
+{
+       xen_feature_info_t features;
+
+       for (int sm = 0; sm < XENFEAT_NR_SUBMAPS; sm++) {
+               if (HYPERVISOR_xen_version(XENVER_get_features, &features) < 0)
+                       break;
+               for (int f = 0; f < 32; f++) {
+                       xen_feature_tables[sm * 32 + f] =
+                           (features.submap & (1 << f)) ? 1 : 0;
+               }
+       }
+}



Home | Main Index | Thread Index | Old Index