Skip to content

Commit

Permalink
Switch to elf notes for amd64 instead of the old key=value list to de…
Browse files Browse the repository at this point in the history
…scribe 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.
  • Loading branch information
bouyer committed May 29, 2016
1 parent 1c7d4ab commit c93ed34
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 17 deletions.
40 changes: 30 additions & 10 deletions sys/arch/amd64/amd64/locore.S
Original file line number Diff line number Diff line change
@@ -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!
Expand Down Expand Up @@ -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 */

/*
Expand Down
14 changes: 13 additions & 1 deletion sys/arch/xen/include/xen.h
Original file line number Diff line number Diff line change
@@ -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 $ */

/*
*
Expand Down Expand Up @@ -345,6 +345,18 @@ xen_atomic_clear_bit(volatile void *ptr, unsigned long bitno)

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_ */
6 changes: 4 additions & 2 deletions sys/arch/xen/x86/x86_xpmap.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -614,6 +614,8 @@ xen_pmap_bootstrap(void)
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 =
Expand Down
23 changes: 21 additions & 2 deletions sys/arch/xen/xen/hypervisor.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -212,6 +212,25 @@ hypervisor_attach(device_t parent, device_t self, void *aux)
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();

Expand Down
22 changes: 20 additions & 2 deletions sys/arch/xen/xen/xen_machdep.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"

Expand All @@ -68,6 +68,7 @@ __KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.13 2012/07/28 02:08:51 matt Exp $"

#include <xen/hypervisor.h>
#include <xen/shutdown_xenbus.h>
#include <xen/xen-public/version.h>

#define DPRINTK(x) printk x
#if 0
Expand Down Expand Up @@ -396,3 +397,20 @@ xen_suspend_domain(void)
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;
}
}
}

0 comments on commit c93ed34

Please sign in to comment.