Skip to contentSkip to conversation

xen: add PV/PVH kernel entry point

PATCH Superseded Roger Pau Monne 5 participants 43 messages Dec 19, 2013 – Jan 3, 2014 19 messages not in the archive

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v7 1/19 xen: add PV/PVH kernel entry point

Add the PV/PVH entry point and the low level functions for PVH initialization.

---
 sys/amd64/amd64/locore.S     |   53 +++++++++++++++++++++++++++++++
 sys/amd64/amd64/machdep.c    |   72 ++++++++++++++++++++++++++++++++++++++++++
 sys/amd64/include/asmacros.h |   26 +++++++++++++++
 sys/i386/xen/xen_machdep.c   |    2 +
 sys/x86/xen/hvm.c            |    1 +
 sys/xen/xen-os.h             |    4 ++
 6 files changed, 158 insertions(+), 0 deletions(-)
sys/amd64/amd64/locore.S +53 -0
index 55cda3a..e04cc48 100644
@@ -31,6 +31,12 @@
 #include <machine/pmap.h>
 #include <machine/specialreg.h>
 
+#ifdef XENHVM
+#include <xen/xen-os.h>
+#define __ASSEMBLY__
+#include <xen/interface/elfnote.h>
+#endif
+
 #include "assym.s"
 
 /*
@@ -86,3 +92,50 @@ NON_GPROF_ENTRY(btext)
 	ALIGN_DATA			/* just to be sure */
 	.space	0x1000			/* space for bootstack - temporary stack */
 bootstack:
+
+#ifdef XENHVM
+/* Xen */
+.section __xen_guest
+	ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS,       .asciz, "FreeBSD")
+	ELFNOTE(Xen, XEN_ELFNOTE_GUEST_VERSION,  .asciz, "HEAD")
+	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) /* Xen honours elf->p_paddr; compensate for this */
+	ELFNOTE(Xen, XEN_ELFNOTE_ENTRY,          .quad,  xen_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, "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,  PG_V, PG_V)
+	ELFNOTE(Xen, XEN_ELFNOTE_LOADER,         .asciz, "generic")
+	ELFNOTE(Xen, XEN_ELFNOTE_SUSPEND_CANCEL, .long,  0)
+	ELFNOTE(Xen, XEN_ELFNOTE_BSD_SYMTAB,	 .asciz, "yes")
+
+	.text
+.p2align PAGE_SHIFT, 0x90	/* Hypercall_page needs to be PAGE aligned */
+
+NON_GPROF_ENTRY(hypercall_page)
+	.skip	0x1000, 0x90	/* Fill with "nop"s */
+
+NON_GPROF_ENTRY(xen_start)
+	/* Don't trust what the loader gives for rflags. */
+	pushq	$PSL_KERNEL
+	popfq
+
+	/* Parameters for the xen init function */
+	movq	%rsi, %rdi		/* shared_info (arg 1) */
+	movq	%rsp, %rsi		/* xenstack    (arg 2) */
+
+	/* Use our own stack */
+	movq	$bootstack,%rsp
+	xorl	%ebp, %ebp
+
+	/* u_int64_t hammer_time_xen(start_info_t *si, u_int64_t xenstack); */
+	call	hammer_time_xen
+	movq	%rax, %rsp		/* set up kstack for mi_startup() */
+	call	mi_startup		/* autoconfiguration, mountroot etc */
+
+	/* NOTREACHED */
+0:	hlt
+	jmp 	0b
+#endif
sys/amd64/amd64/machdep.c +72 -0

88 lines not on this page · raw message

sys/amd64/include/asmacros.h +26 -0
index 1fb592a..ce8dce4 100644
@@ -201,4 +201,30 @@
 
 #endif /* LOCORE */
 
+#ifdef __STDC__
+#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
+#else /* !__STDC__, i.e. -traditional */
+#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
+#endif /* __STDC__ */
+
 #endif /* !_MACHINE_ASMACROS_H_ */
sys/i386/xen/xen_machdep.c +2 -0
index 7049be6..fd575ee 100644
@@ -89,6 +89,7 @@ IDTVEC(div), IDTVEC(dbg), IDTVEC(nmi), IDTVEC(bpt), IDTVEC(ofl),
 
 int xendebug_flags; 
 start_info_t *xen_start_info;
+start_info_t *HYPERVISOR_start_info;
 shared_info_t *HYPERVISOR_shared_info;
 xen_pfn_t *xen_machine_phys = machine_to_phys_mapping;
 xen_pfn_t *xen_phys_machine;
@@ -927,6 +928,7 @@ initvalues(start_info_t *startinfo)
 	HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments_notify);	
 #endif	
 	xen_start_info = startinfo;
+	HYPERVISOR_start_info = startinfo;
 	xen_phys_machine = (xen_pfn_t *)startinfo->mfn_list;
 
 	IdlePTD = (pd_entry_t *)((uint8_t *)startinfo->pt_base + PAGE_SIZE);
sys/x86/xen/hvm.c +1 -0
index 72811dc..b397721 100644
@@ -159,6 +159,7 @@ DPCPU_DEFINE(xen_intr_handle_t, ipi_handle[nitems(xen_ipis)]);
 /** Hypercall table accessed via HYPERVISOR_*_op() methods. */
 char *hypercall_stubs;
 shared_info_t *HYPERVISOR_shared_info;
+start_info_t *HYPERVISOR_start_info;
 
 #ifdef SMP
 /*---------------------------- XEN PV IPI Handlers ---------------------------*/
sys/xen/xen-os.h +4 -0
index 87644e9..c7474d8 100644
@@ -51,6 +51,10 @@
 void force_evtchn_callback(void);
 
 extern shared_info_t *HYPERVISOR_shared_info;
+extern start_info_t *HYPERVISOR_start_info;
+
+/* XXX: we need to get rid of this and use HYPERVISOR_start_info directly */
+extern struct xenstore_domain_interface *xen_store;
 
 enum xen_domain_type {
 	XEN_NATIVE,             /* running on bare hardware    */
Signature · 1 line
1.7.7.5 (Apple Git-26)
#2 lore raw

PATCH v7 2/19 xen: add macro to detect if running as Dom0

In reply to a message not in the archive
---
 sys/xen/xen-os.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
sys/xen/xen-os.h +7 -0
index c7474d8..e8a5a99 100644
@@ -82,6 +82,13 @@ xen_hvm_domain(void)
 	return (xen_domain_type == XEN_HVM_DOMAIN);
 }
 
+static inline int
+xen_initial_domain(void)
+{
+	return (xen_domain() && HYPERVISOR_start_info &&
+	        HYPERVISOR_start_info->flags & SIF_INITDOMAIN);
+}
+
 #ifndef xen_mb
 #define xen_mb() mb()
 #endif
Signature · 1 line
1.7.7.5 (Apple Git-26)
#3 lore raw

PATCH v7 3/19 xen: add and enable Xen console for PVH guests

In reply to a message not in the archive

This adds and enables the console used on XEN kernels.

---
 sys/amd64/amd64/machdep.c          |    4 +++
 sys/conf/files                     |    4 +-
 sys/dev/xen/console/console.c      |   45 ++++++++++++++++++++++-------------
 sys/dev/xen/console/xencons_ring.c |   15 ++++++++----
 sys/i386/include/xen/xen-os.h      |    1 -
 sys/i386/xen/xen_machdep.c         |   17 -------------
 sys/xen/xen-os.h                   |    4 +++
 7 files changed, 48 insertions(+), 42 deletions(-)
sys/amd64/amd64/machdep.c +4 -0
index a73e33e..1880f23 100644
@@ -1709,6 +1709,8 @@ hammer_time_xen(start_info_t *si, u_int64_t xenstack)
 	KASSERT((si != NULL && xenstack != 0),
 	        ("invalid start_info or xenstack"));
 
+	xc_printf("FreeBSD PVH running on %s\n", si->magic);
+
 	/* We use 3 pages of xen stack for the boot pagetables */
 	physfree = xenstack + 3 * PAGE_SIZE - KERNBASE;
 
@@ -1726,6 +1728,8 @@ hammer_time_xen(start_info_t *si, u_int64_t xenstack)
 	 */
 	xen_store = (struct xenstore_domain_interface *)
 	            (ptoa(si->store_mfn) + KERNBASE);
+	console_page =
+		(char *)(ptoa(si->console.domU.mfn) + KERNBASE);
 
 	xen_domain_type = XEN_PV_DOMAIN;
 	vm_guest = VM_GUEST_XEN;
sys/conf/files +2 -2
index a73d31e..f55479d 100644
@@ -2523,8 +2523,8 @@ dev/xe/if_xe_pccard.c		optional xe pccard
 dev/xen/balloon/balloon.c	optional xen | xenhvm
 dev/xen/blkfront/blkfront.c	optional xen | xenhvm
 dev/xen/blkback/blkback.c	optional xen | xenhvm
-dev/xen/console/console.c	optional xen
-dev/xen/console/xencons_ring.c	optional xen
+dev/xen/console/console.c	optional xen | xenhvm
+dev/xen/console/xencons_ring.c	optional xen | xenhvm
 dev/xen/control/control.c	optional xen | xenhvm
 dev/xen/netback/netback.c	optional xen | xenhvm
 dev/xen/netfront/netfront.c	optional xen | xenhvm
sys/dev/xen/console/console.c +28 -17

105 lines not on this page · raw message

sys/dev/xen/console/xencons_ring.c +10 -5
index 3701551..d826363 100644
@@ -32,9 +32,9 @@ __FBSDID("$FreeBSD$");
 
 #define console_evtchn	console.domU.evtchn
 xen_intr_handle_t console_handle;
-extern char *console_page;
 extern struct mtx              cn_mtx;
 extern device_t xencons_dev;
+extern int cnsl_evt_reg;
 
 static inline struct xencons_interface *
 xencons_interface(void)
@@ -60,6 +60,8 @@ xencons_ring_send(const char *data, unsigned len)
 	struct xencons_interface *intf; 
 	XENCONS_RING_IDX cons, prod;
 	int sent;
+	struct evtchn_send send = { .port =
+	                            HYPERVISOR_start_info->console_evtchn };
 
 	intf = xencons_interface();
 	cons = intf->out_cons;
@@ -76,7 +78,10 @@ xencons_ring_send(const char *data, unsigned len)
 	wmb();
 	intf->out_prod = prod;
 
-	xen_intr_signal(console_handle);
+	if (cnsl_evt_reg)
+		xen_intr_signal(console_handle);
+	else
+		HYPERVISOR_event_channel_op(EVTCHNOP_send, &send);
 
 	return sent;
 
@@ -125,11 +130,11 @@ xencons_ring_init(void)
 {
 	int err;
 
-	if (!xen_start_info->console_evtchn)
+	if (!HYPERVISOR_start_info->console_evtchn)
 		return 0;
 
 	err = xen_intr_bind_local_port(xencons_dev,
-	    xen_start_info->console_evtchn, NULL, xencons_handle_input, NULL,
+	    HYPERVISOR_start_info->console_evtchn, NULL, xencons_handle_input, NULL,
 	    INTR_TYPE_MISC | INTR_MPSAFE, &console_handle);
 	if (err) {
 		return err;
@@ -145,7 +150,7 @@ void
 xencons_suspend(void)
 {
 
-	if (!xen_start_info->console_evtchn)
+	if (!HYPERVISOR_start_info->console_evtchn)
 		return;
 
 	xen_intr_unbind(&console_handle);
sys/i386/include/xen/xen-os.h +0 -1
index a8fba61..3d1ef04 100644
@@ -45,7 +45,6 @@ static inline void rep_nop(void)
 #define cpu_relax() rep_nop()
 
 #ifndef XENHVM
-void xc_printf(const char *fmt, ...);
 
 #ifdef SMP
 extern int gdtset;
sys/i386/xen/xen_machdep.c +0 -17
index fd575ee..09c01f1 100644
@@ -186,21 +186,6 @@ xen_boothowto(char *envp)
 	return howto;
 }
 
-#define XC_PRINTF_BUFSIZE 1024
-void
-xc_printf(const char *fmt, ...)
-{
-        __va_list ap;
-        int retval;
-        static char buf[XC_PRINTF_BUFSIZE];
-
-        va_start(ap, fmt);
-        retval = vsnprintf(buf, XC_PRINTF_BUFSIZE - 1, fmt, ap);
-        va_end(ap);
-        buf[retval] = 0;
-        (void)HYPERVISOR_console_write(buf, retval);
-}
-
 
 #define XPQUEUE_SIZE 128
 
@@ -745,8 +730,6 @@ void initvalues(start_info_t *startinfo);
 struct xenstore_domain_interface;
 extern struct xenstore_domain_interface *xen_store;
 
-char *console_page;
-
 void *
 bootmem_alloc(unsigned int size) 
 {
sys/xen/xen-os.h +4 -0
index e8a5a99..e005ccd 100644
@@ -55,6 +55,7 @@ extern start_info_t *HYPERVISOR_start_info;
 
 /* XXX: we need to get rid of this and use HYPERVISOR_start_info directly */
 extern struct xenstore_domain_interface *xen_store;
+extern char *console_page;
 
 enum xen_domain_type {
 	XEN_NATIVE,             /* running on bare hardware    */
@@ -89,6 +90,9 @@ xen_initial_domain(void)
 	        HYPERVISOR_start_info->flags & SIF_INITDOMAIN);
 }
 
+/* Debug function, prints directly to hypervisor console */
+void xc_printf(const char *, ...);
+
 #ifndef xen_mb
 #define xen_mb() mb()
 #endif
Signature · 1 line
1.7.7.5 (Apple Git-26)
#4 lore raw

PATCH v7 4/19 amd64: introduce hook for custom preload metadata parsers

In reply to a message not in the archive
---
 sys/amd64/amd64/machdep.c   |   45 +++++++++++++----
 sys/amd64/include/sysarch.h |   12 +++++
 sys/conf/files.amd64        |    1 +
 sys/x86/xen/pv.c            |  114 +++++++++++++++++++++++++++++++++++++++++++
 sys/xen/pv.h                |   28 +++++++++++
 5 files changed, 189 insertions(+), 11 deletions(-)
 create mode 100644 sys/x86/xen/pv.c
 create mode 100644 sys/xen/pv.h
sys/amd64/amd64/machdep.c +34 -11
index 1880f23..09d9a1a 100644
@@ -126,6 +126,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/reg.h>
 #include <machine/sigframe.h>
 #include <machine/specialreg.h>
+#include <machine/sysarch.h>
 #ifdef PERFMON
 #include <machine/perfmon.h>
 #endif
@@ -148,6 +149,7 @@ __FBSDID("$FreeBSD$");
 
 #ifdef XENHVM
 #include <xen/xen-os.h>
+#include <xen/pv.h>
 #endif
 
 /* Sanity check for __curthread() */
@@ -172,6 +174,14 @@ static int  set_fpcontext(struct thread *td, const mcontext_t *mcp,
     char *xfpustate, size_t xfpustate_len);
 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
 
+/* Preload data parse function */
+static caddr_t native_parse_preload_data(u_int64_t);
+
+/* Default init_ops implementation. */
+struct init_ops init_ops = {
+	.parse_preload_data =	native_parse_preload_data,
+};
+
 /*
  * The file "conf/ldscript.amd64" defines the symbol "kernphys".  Its value is
  * the physical address at which the kernel is loaded.
@@ -1690,6 +1700,26 @@ do_next:
 	msgbufp = (struct msgbuf *)PHYS_TO_DMAP(phys_avail[pa_indx]);
 }
 
+static caddr_t
+native_parse_preload_data(u_int64_t modulep)
+{
+	caddr_t kmdp;
+
+	preload_metadata = (caddr_t)(uintptr_t)(modulep + KERNBASE);
+	preload_bootstrap_relocate(KERNBASE);
+	kmdp = preload_search_by_type("elf kernel");
+	if (kmdp == NULL)
+		kmdp = preload_search_by_type("elf64 kernel");
+	boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
+	kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *) + KERNBASE;
+#ifdef DDB
+	ksym_start = MD_FETCH(kmdp, MODINFOMD_SSYM, uintptr_t);
+	ksym_end = MD_FETCH(kmdp, MODINFOMD_ESYM, uintptr_t);
+#endif
+
+	return (kmdp);
+}
+
 #ifdef XENHVM
 /*
  * First function called by the Xen PVH boot sequence.
@@ -1754,6 +1784,9 @@ hammer_time_xen(start_info_t *si, u_int64_t xenstack)
 	}
 	load_cr3(((u_int64_t)&PT4[0]) - KERNBASE);
 
+	/* Set the hooks for early functions that diverge from bare metal */
+	xen_pv_set_init_ops();
+
 	/* Now we can jump into the native init function */
 	return (hammer_time(0, physfree));
 }
@@ -1783,17 +1816,7 @@ hammer_time(u_int64_t modulep, u_int64_t physfree)
 	 */
 	proc_linkup0(&proc0, &thread0);
 
-	preload_metadata = (caddr_t)(uintptr_t)(modulep + KERNBASE);
-	preload_bootstrap_relocate(KERNBASE);
-	kmdp = preload_search_by_type("elf kernel");
-	if (kmdp == NULL)
-		kmdp = preload_search_by_type("elf64 kernel");
-	boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
-	kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *) + KERNBASE;
-#ifdef DDB
-	ksym_start = MD_FETCH(kmdp, MODINFOMD_SSYM, uintptr_t);
-	ksym_end = MD_FETCH(kmdp, MODINFOMD_ESYM, uintptr_t);
-#endif
+	kmdp = init_ops.parse_preload_data(modulep);
 
 	/* Init basic tunables, hz etc */
 	init_param1();
sys/amd64/include/sysarch.h +12 -0
index cd380d4..58ac8cd 100644
@@ -4,3 +4,15 @@
 /* $FreeBSD$ */
 
 #include <x86/sysarch.h>
+
+/*
+ * Struct containing pointers to init functions whose
+ * implementation is run time selectable.  Selection can be made,
+ * for example, based on detection of a BIOS variant or
+ * hypervisor environment.
+ */
+struct init_ops {
+	caddr_t	(*parse_preload_data)(u_int64_t);
+};
+
+extern struct init_ops init_ops;
sys/conf/files.amd64 +1 -0
index d1bdcd9..b3b1319 100644
@@ -566,3 +566,4 @@ x86/x86/nexus.c			standard
 x86/x86/tsc.c			standard
 x86/xen/hvm.c			optional	xenhvm
 x86/xen/xen_intr.c		optional	xen | xenhvm
+x86/xen/pv.c			optional	xenhvm
sys/x86/xen/pv.c new file +114 -0

114 lines not on this page · raw message

sys/xen/pv.h new file +28 -0
new file mode 100644
index 0000000..71b8776
@@ -0,0 +1,28 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef	__XEN_PV_H__
+#define	__XEN_PV_H__
+
+void	xen_pv_set_init_ops(void);
+
+#endif	/* __XEN_PV_H__ */
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#5 lore raw

PATCH v7 5/19 xen: rework xen timer so it can be used early in boot process

In reply to a message not in the archive

This should not introduce any functional change, and makes the functions suitable to be called before we have actually mapped the vcpu_info struct on a per-cpu basis.

---
 sys/dev/xen/timer/timer.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)
sys/dev/xen/timer/timer.c +20 -9
index 354085b..b2f6bcd 100644
@@ -230,22 +230,22 @@ xen_fetch_vcpu_tinfo(struct vcpu_time_info *dst, struct vcpu_time_info *src)
 /**
  * \brief Get the current time, in nanoseconds, since the hypervisor booted.
  *
+ * \param vcpu		vcpu_info structure to fetch the time from.
+ *
  * \note This function returns the current CPU's idea of this value, unless
  *       it happens to be less than another CPU's previously determined value.
  */
 static uint64_t
-xen_fetch_vcpu_time(void)
+xen_fetch_vcpu_time(struct vcpu_info *vcpu)
 {
 	struct vcpu_time_info dst;
 	struct vcpu_time_info *src;
 	uint32_t pre_version;
 	uint64_t now;
 	volatile uint64_t last;
-	struct vcpu_info *vcpu = DPCPU_GET(vcpu_info);
 
 	src = &vcpu->time;
 
-	critical_enter();
 	do {
 		pre_version = xen_fetch_vcpu_tinfo(&dst, src);
 		barrier();
@@ -266,16 +266,19 @@ xen_fetch_vcpu_time(void)
 		}
 	} while (!atomic_cmpset_64(&xen_timer_last_time, last, now));
 
-	critical_exit();
-
 	return (now);
 }
 
 static uint32_t
 xentimer_get_timecount(struct timecounter *tc)
 {
+	uint32_t xen_time;
 
-	return ((uint32_t)xen_fetch_vcpu_time() & UINT_MAX);
+	critical_enter();
+	xen_time = (uint32_t)xen_fetch_vcpu_time(DPCPU_GET(vcpu_info)) & UINT_MAX;
+	critical_exit();
+
+	return (xen_time);
 }
 
 /**
@@ -305,7 +308,12 @@ xen_fetch_wallclock(struct timespec *ts)
 static void
 xen_fetch_uptime(struct timespec *ts)
 {
-	uint64_t uptime = xen_fetch_vcpu_time();
+	uint64_t uptime;
+
+	critical_enter();
+	uptime = xen_fetch_vcpu_time(DPCPU_GET(vcpu_info));
+	critical_exit();
+
 	ts->tv_sec = uptime / NSEC_IN_SEC;
 	ts->tv_nsec = uptime % NSEC_IN_SEC;
 }
@@ -354,7 +362,7 @@ xentimer_intr(void *arg)
 	struct xentimer_softc *sc = (struct xentimer_softc *)arg;
 	struct xentimer_pcpu_data *pcpu = DPCPU_PTR(xentimer_pcpu);
 
-	pcpu->last_processed = xen_fetch_vcpu_time();
+	pcpu->last_processed = xen_fetch_vcpu_time(DPCPU_GET(vcpu_info));
 	if (pcpu->timer != 0 && sc->et.et_active)
 		sc->et.et_event_cb(&sc->et, sc->et.et_arg);
 
@@ -415,7 +423,10 @@ xentimer_et_start(struct eventtimer *et,
 	do {
 		if (++i == 60)
 			panic("can't schedule timer");
-		next_time = xen_fetch_vcpu_time() + first_in_ns;
+		critical_enter();
+		next_time = xen_fetch_vcpu_time(DPCPU_GET(vcpu_info)) +
+		            first_in_ns;
+		critical_exit();
 		error = xentimer_vcpu_start_timer(cpu, next_time);
 	} while (error == -ETIME);
 
Signature · 1 line
1.7.7.5 (Apple Git-26)
#6 lore raw

PATCH v7 6/19 xen: implement an early timer for Xen PVH

In reply to a message not in the archive

When running as a PVH guest, there's no emulated i8254, so we need to use the Xen PV timer as the early source for DELAY. This change allows for different implementations of the early DELAY function and implements a Xen variant for it.

---
 sys/amd64/amd64/machdep.c   |   15 ++++++-
 sys/amd64/include/clock.h   |    6 +++
 sys/amd64/include/sysarch.h |    2 +
 sys/conf/files.amd64        |    1 +
 sys/conf/files.i386         |    1 +
 sys/dev/xen/timer/timer.c   |   33 +++++++++++++++
 sys/i386/i386/machdep.c     |   11 +++++
 sys/i386/include/clock.h    |    6 +++
 sys/x86/isa/clock.c         |   53 +-----------------------
 sys/x86/x86/delay.c         |   95 +++++++++++++++++++++++++++++++++++++++++++
 sys/x86/xen/pv.c            |    3 +
 11 files changed, 172 insertions(+), 54 deletions(-)
 create mode 100644 sys/x86/x86/delay.c
sys/amd64/amd64/machdep.c +13 -2
index 09d9a1a..a2dcb90 100644
@@ -180,6 +180,8 @@ static caddr_t native_parse_preload_data(u_int64_t);
 /* Default init_ops implementation. */
 struct init_ops init_ops = {
 	.parse_preload_data =	native_parse_preload_data,
+	.early_delay_init =	i8254_init,
+	.early_delay =		i8254_delay,
 };
 
 /*
@@ -232,6 +234,15 @@ struct mem_range_softc mem_range_softc;
 
 struct mtx dt_lock;	/* lock for GDT and LDT */
 
+void
+DELAY(int n)
+{
+	if (delay_tc(n))
+		return;
+
+	init_ops.early_delay(n);
+}
+
 static void
 cpu_startup(dummy)
 	void *dummy;
@@ -1900,10 +1911,10 @@ hammer_time(u_int64_t modulep, u_int64_t physfree)
 	lidt(&r_idt);
 
 	/*
-	 * Initialize the i8254 before the console so that console
+	 * Initialize the early delay before the console so that console
 	 * initialization can use DELAY().
 	 */
-	i8254_init();
+	init_ops.early_delay_init();
 
 	/*
 	 * Initialize the console before we print anything out.
sys/amd64/include/clock.h +6 -0
index d7f7d82..e7817ab 100644
@@ -25,6 +25,12 @@ extern int	smp_tsc;
 #endif
 
 void	i8254_init(void);
+void	i8254_delay(int);
+#ifdef XENHVM
+void	xen_delay_init(void);
+void	xen_delay(int);
+#endif
+int	delay_tc(int);
 
 /*
  * Driver to clock driver interface.
sys/amd64/include/sysarch.h +2 -0
index 58ac8cd..60fa635 100644
@@ -13,6 +13,8 @@
  */
 struct init_ops {
 	caddr_t	(*parse_preload_data)(u_int64_t);
+	void	(*early_delay_init)(void);
+	void	(*early_delay)(int);
 };
 
 extern struct init_ops init_ops;
sys/conf/files.amd64 +1 -0
index b3b1319..bdc1517 100644
@@ -564,6 +564,7 @@ x86/x86/mptable_pci.c		optional	mptable pci
 x86/x86/msi.c			optional	pci
 x86/x86/nexus.c			standard
 x86/x86/tsc.c			standard
+x86/x86/delay.c			standard
 x86/xen/hvm.c			optional	xenhvm
 x86/xen/xen_intr.c		optional	xen | xenhvm
 x86/xen/pv.c			optional	xenhvm
sys/conf/files.i386 +1 -0
index eb8697c..790296d 100644
@@ -600,5 +600,6 @@ x86/x86/mptable_pci.c		optional apic native pci
 x86/x86/msi.c			optional apic pci
 x86/x86/nexus.c			standard
 x86/x86/tsc.c			standard
+x86/x86/delay.c			standard
 x86/xen/hvm.c			optional xenhvm
 x86/xen/xen_intr.c		optional xen | xenhvm
sys/dev/xen/timer/timer.c +33 -0
index b2f6bcd..96372ab 100644
@@ -59,6 +59,9 @@ __FBSDID("$FreeBSD$");
 #include <machine/_inttypes.h>
 #include <machine/smp.h>
 
+/* For the declaration of clock_lock */
+#include <isa/rtc.h>
+
 #include "clock_if.h"
 
 static devclass_t xentimer_devclass;
@@ -584,6 +587,36 @@ xentimer_suspend(device_t dev)
 	return (0);
 }
 
+/*
+ * Xen delay early init
+ */
+void xen_delay_init(void)
+{
+	/* Init the clock lock */
+	mtx_init(&clock_lock, "clk", NULL, MTX_SPIN | MTX_NOPROFILE);
+}
+/*
+ * Xen PV DELAY function
+ *
+ * When running on PVH mode we don't have an emulated i8524, so
+ * make use of the Xen time info in order to code a simple DELAY
+ * function that can be used during early boot.
+ */
+void xen_delay(int n)
+{
+	uint64_t end_ns;
+	uint64_t current;
+
+	end_ns = xen_fetch_vcpu_time(&HYPERVISOR_shared_info->vcpu_info[0]);
+	end_ns += n * NSEC_IN_USEC;
+
+	for (;;) {
+		current = xen_fetch_vcpu_time(&HYPERVISOR_shared_info->vcpu_info[0]);
+		if (current >= end_ns)
+			break;
+	}
+}
+
 static device_method_t xentimer_methods[] = {
 	DEVMETHOD(device_identify, xentimer_identify),
 	DEVMETHOD(device_probe, xentimer_probe),
sys/i386/i386/machdep.c +11 -0
index d43abbf..ad2734f 100644
@@ -253,6 +253,17 @@ struct mtx icu_lock;
 
 struct mem_range_softc mem_range_softc;
 
+#ifndef XEN
+void
+DELAY(int n)
+{
+	if (delay_tc(n))
+		return;
+
+	i8254_delay(n);
+}
+#endif
+
 static void
 cpu_startup(dummy)
 	void *dummy;
sys/i386/include/clock.h +6 -0
index d980ec7..287b2c8 100644
@@ -22,6 +22,12 @@ extern int	tsc_is_invariant;
 extern int	tsc_perf_stat;
 
 void	i8254_init(void);
+void	i8254_delay(int);
+#ifdef XENHVM
+void	xen_delay_init(void);
+void	xen_delay(int);
+#endif
+int	delay_tc(int);
 
 /*
  * Driver to clock driver interface.
sys/x86/isa/clock.c +1 -52

71 lines not on this page · raw message

sys/x86/x86/delay.c new file +95 -0

95 lines not on this page · raw message

sys/x86/xen/pv.c +3 -0
index bbaca32..f8d8cfa 100644
@@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/systm.h>
 
 #include <machine/sysarch.h>
+#include <machine/clock.h>
 
 #include <xen/xen-os.h>
 #include <xen/pv.h>
@@ -47,6 +48,8 @@ static caddr_t xen_pv_parse_preload_data(u_int64_t);
 /* Xen init_ops implementation. */
 struct init_ops xen_init_ops = {
 	.parse_preload_data =	xen_pv_parse_preload_data,
+	.early_delay_init =	xen_delay_init,
+	.early_delay =		xen_delay,
 };
 
 static struct
Signature · 1 line
1.7.7.5 (Apple Git-26)
#7 lore raw

Re: [PATCH v7 06/19] xen: implement an early timer for Xen PVH

Quoted 4 lines · Roger Pau Monne

When running as a PVH guest, there's no emulated i8254, so we need to use the Xen PV timer as the early source for DELAY. This change allows for different implementations of the early DELAY function and implements a Xen variant for it.

This mostly looks good to me. I would perhaps move DELAY() itself into delay.c if it isn't too ugly to do so. I guess it would look something like:

#if !(defined(__i386__) && defined(XEN))
void
DELAY(int n)
{

	if (delay_tc(n))
		return;
#ifdef __amd64__
	init_ops.early_delay(n);
#else
	i8254_delay(n);
}

#endif

This would let you leave delay_tc() private to delay.c.

Signature · 1 line
John Baldwin
#8 lore raw

PATCH v7 7/19 xen: implement hook to fetch e820 memory map

In reply to a message not in the archive
---
 sys/amd64/amd64/machdep.c   |   50 ++++++++++++++++++++++++++----------------
 sys/amd64/include/pc/bios.h |    2 +
 sys/amd64/include/sysarch.h |    1 +
 sys/x86/xen/pv.c            |   26 ++++++++++++++++++++++
 4 files changed, 60 insertions(+), 19 deletions(-)
sys/amd64/amd64/machdep.c +31 -19
index a2dcb90..6bbfe5a 100644
@@ -177,11 +177,15 @@ SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
 /* Preload data parse function */
 static caddr_t native_parse_preload_data(u_int64_t);
 
+/* Native function to fetch and parse the e820 map */
+static void native_parse_memmap(caddr_t, vm_paddr_t *, int *);
+
 /* Default init_ops implementation. */
 struct init_ops init_ops = {
 	.parse_preload_data =	native_parse_preload_data,
 	.early_delay_init =	i8254_init,
 	.early_delay =		i8254_delay,
+	.parse_memmap =		native_parse_memmap,
 };
 
 /*
@@ -1418,21 +1422,12 @@ add_physmap_entry(uint64_t base, uint64_t length, vm_paddr_t *physmap,
 	return (1);
 }
 
-static void
-add_smap_entries(struct bios_smap *smapbase, vm_paddr_t *physmap,
-    int *physmap_idx)
+void
+bios_add_smap_entries(struct bios_smap *smapbase, u_int32_t smapsize,
+                      vm_paddr_t *physmap, int *physmap_idx)
 {
 	struct bios_smap *smap, *smapend;
-	u_int32_t smapsize;
 
-	/*
-	 * Memory map from INT 15:E820.
-	 *
-	 * subr_module.c says:
-	 * "Consumer may safely assume that size value precedes data."
-	 * ie: an int32_t immediately precedes smap.
-	 */
-	smapsize = *((u_int32_t *)smapbase - 1);
 	smapend = (struct bios_smap *)((uintptr_t)smapbase + smapsize);
 
 	for (smap = smapbase; smap < smapend; smap++) {
@@ -1449,6 +1444,29 @@ add_smap_entries(struct bios_smap *smapbase, vm_paddr_t *physmap,
 	}
 }
 
+static void
+native_parse_memmap(caddr_t kmdp, vm_paddr_t *physmap, int *physmap_idx)
+{
+	struct bios_smap *smap;
+	u_int32_t size;
+
+	/*
+	 * Memory map from INT 15:E820.
+	 *
+	 * subr_module.c says:
+	 * "Consumer may safely assume that size value precedes data."
+	 * ie: an int32_t immediately precedes smap.
+	 */
+
+	smap = (struct bios_smap *)preload_search_info(kmdp,
+	    MODINFO_METADATA | MODINFOMD_SMAP);
+	if (smap == NULL)
+		panic("No BIOS smap info from loader!");
+	size = *((u_int32_t *)smap - 1);
+
+	bios_add_smap_entries(smap, size, physmap, physmap_idx);
+}
+
 /*
  * Populate the (physmap) array with base/bound pairs describing the
  * available physical memory in the system, then test this memory and
@@ -1466,19 +1484,13 @@ getmemsize(caddr_t kmdp, u_int64_t first)
 	vm_paddr_t pa, physmap[PHYSMAP_SIZE];
 	u_long physmem_start, physmem_tunable, memtest;
 	pt_entry_t *pte;
-	struct bios_smap *smapbase;
 	quad_t dcons_addr, dcons_size;
 
 	bzero(physmap, sizeof(physmap));
 	basemem = 0;
 	physmap_idx = 0;
 
-	smapbase = (struct bios_smap *)preload_search_info(kmdp,
-	    MODINFO_METADATA | MODINFOMD_SMAP);
-	if (smapbase == NULL)
-		panic("No BIOS smap info from loader!");
-
-	add_smap_entries(smapbase, physmap, &physmap_idx);
+	init_ops.parse_memmap(kmdp, physmap, &physmap_idx);
 
 	/*
 	 * Find the 'base memory' segment for SMP
sys/amd64/include/pc/bios.h +2 -0
index e7d568e..92d4265 100644
@@ -106,6 +106,8 @@ struct bios_oem {
 int	bios_oem_strings(struct bios_oem *oem, u_char *buffer, size_t maxlen);
 uint32_t bios_sigsearch(uint32_t start, u_char *sig, int siglen, int paralen,
 	    int sigofs);
+void bios_add_smap_entries(struct bios_smap *smapbase, u_int32_t smapsize,
+                           vm_paddr_t *physmap, int *physmap_idx);
 #endif
 
 #endif /* _MACHINE_PC_BIOS_H_ */
sys/amd64/include/sysarch.h +1 -0
index 60fa635..084223e 100644
@@ -15,6 +15,7 @@ struct init_ops {
 	caddr_t	(*parse_preload_data)(u_int64_t);
 	void	(*early_delay_init)(void);
 	void	(*early_delay)(int);
+	void	(*parse_memmap)(caddr_t, vm_paddr_t *, int *);
 };
 
 extern struct init_ops init_ops;
sys/x86/xen/pv.c +26 -0
index f8d8cfa..db576e0 100644
@@ -37,12 +37,17 @@ __FBSDID("$FreeBSD$");
 
 #include <machine/sysarch.h>
 #include <machine/clock.h>
+#include <machine/pc/bios.h>
 
 #include <xen/xen-os.h>
 #include <xen/pv.h>
+#include <xen/hypervisor.h>
+
+#define MAX_E820_ENTRIES	128
 
 /*--------------------------- Forward Declarations ---------------------------*/
 static caddr_t xen_pv_parse_preload_data(u_int64_t);
+static void xen_pv_parse_memmap(caddr_t, vm_paddr_t *, int *);
 
 /*-------------------------------- Global Data -------------------------------*/
 /* Xen init_ops implementation. */
@@ -50,6 +55,7 @@ struct init_ops xen_init_ops = {
 	.parse_preload_data =	xen_pv_parse_preload_data,
 	.early_delay_init =	xen_delay_init,
 	.early_delay =		xen_delay,
+	.parse_memmap =		xen_pv_parse_memmap,
 };
 
 static struct
@@ -70,6 +76,8 @@ static struct
 	{NULL,	0}
 };
 
+static struct bios_smap xen_smap[MAX_E820_ENTRIES];
+
 /*
  * Functions to convert the "extra" parameters passed by Xen
  * into FreeBSD boot options (from the i386 Xen port).
@@ -109,6 +117,24 @@ xen_pv_parse_preload_data(u_int64_t modulep)
 	return (NULL);
 }
 
+static void
+xen_pv_parse_memmap(caddr_t kmdp, vm_paddr_t *physmap, int *physmap_idx)
+{
+	struct xen_memory_map memmap;
+	u_int32_t size;
+	int rc;
+
+	/* Fetch the E820 map from Xen */
+	memmap.nr_entries = MAX_E820_ENTRIES;
+	set_xen_guest_handle(memmap.buffer, xen_smap);
+	rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
+	if (rc)
+		panic("unable to fetch Xen E820 memory map");
+	size = memmap.nr_entries * sizeof(xen_smap[0]);
+
+	bios_add_smap_entries(xen_smap, size, physmap, physmap_idx);
+}
+
 void
 xen_pv_set_init_ops(void)
 {
Signature · 1 line
1.7.7.5 (Apple Git-26)
#9 lore raw

Re: [PATCH v7 07/19] xen: implement hook to fetch e820 memory map

This also looks fine, with the style nit noted in the patch.

Quoted 108 lines · Roger Pau Monne
---
 sys/amd64/amd64/machdep.c   |   50 ++++++++++++++++++++++++++----------------
 sys/amd64/include/pc/bios.h |    2 +
 sys/amd64/include/sysarch.h |    1 +
 sys/x86/xen/pv.c            |   26 ++++++++++++++++++++++
 4 files changed, 60 insertions(+), 19 deletions(-)
sys/amd64/amd64/machdep.c +31 -19
index a2dcb90..6bbfe5a 100644
@@ -177,11 +177,15 @@ SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
 /* Preload data parse function */
 static caddr_t native_parse_preload_data(u_int64_t);
 
+/* Native function to fetch and parse the e820 map */
+static void native_parse_memmap(caddr_t, vm_paddr_t *, int *);
+
 /* Default init_ops implementation. */
 struct init_ops init_ops = {
 	.parse_preload_data =	native_parse_preload_data,
 	.early_delay_init =	i8254_init,
 	.early_delay =		i8254_delay,
+	.parse_memmap =		native_parse_memmap,
 };
 
 /*
@@ -1418,21 +1422,12 @@ add_physmap_entry(uint64_t base, uint64_t length, vm_paddr_t *physmap,
 	return (1);
 }
 
-static void
-add_smap_entries(struct bios_smap *smapbase, vm_paddr_t *physmap,
-    int *physmap_idx)
+void
+bios_add_smap_entries(struct bios_smap *smapbase, u_int32_t smapsize,
+                      vm_paddr_t *physmap, int *physmap_idx)
 {
 	struct bios_smap *smap, *smapend;
-	u_int32_t smapsize;
 
-	/*
-	 * Memory map from INT 15:E820.
-	 *
-	 * subr_module.c says:
-	 * "Consumer may safely assume that size value precedes data."
-	 * ie: an int32_t immediately precedes smap.
-	 */
-	smapsize = *((u_int32_t *)smapbase - 1);
 	smapend = (struct bios_smap *)((uintptr_t)smapbase + smapsize);
 
 	for (smap = smapbase; smap < smapend; smap++) {
@@ -1449,6 +1444,29 @@ add_smap_entries(struct bios_smap *smapbase, vm_paddr_t *physmap,
 	}
 }
 
+static void
+native_parse_memmap(caddr_t kmdp, vm_paddr_t *physmap, int *physmap_idx)
+{
+	struct bios_smap *smap;
+	u_int32_t size;
+
+	/*
+	 * Memory map from INT 15:E820.
+	 *
+	 * subr_module.c says:
+	 * "Consumer may safely assume that size value precedes data."
+	 * ie: an int32_t immediately precedes smap.
+	 */
+
+	smap = (struct bios_smap *)preload_search_info(kmdp,
+	    MODINFO_METADATA | MODINFOMD_SMAP);
+	if (smap == NULL)
+		panic("No BIOS smap info from loader!");
+	size = *((u_int32_t *)smap - 1);
+
+	bios_add_smap_entries(smap, size, physmap, physmap_idx);
+}
+
 /*
  * Populate the (physmap) array with base/bound pairs describing the
  * available physical memory in the system, then test this memory and
@@ -1466,19 +1484,13 @@ getmemsize(caddr_t kmdp, u_int64_t first)
 	vm_paddr_t pa, physmap[PHYSMAP_SIZE];
 	u_long physmem_start, physmem_tunable, memtest;
 	pt_entry_t *pte;
-	struct bios_smap *smapbase;
 	quad_t dcons_addr, dcons_size;
 
 	bzero(physmap, sizeof(physmap));
 	basemem = 0;
 	physmap_idx = 0;
 
-	smapbase = (struct bios_smap *)preload_search_info(kmdp,
-	    MODINFO_METADATA | MODINFOMD_SMAP);
-	if (smapbase == NULL)
-		panic("No BIOS smap info from loader!");
-
-	add_smap_entries(smapbase, physmap, &physmap_idx);
+	init_ops.parse_memmap(kmdp, physmap, &physmap_idx);
 
 	/*
 	 * Find the 'base memory' segment for SMP
sys/amd64/include/pc/bios.h +0 -0
index e7d568e..92d4265 100644

sys/amd64/include/pc/bios.h struct bios_oem { · line 110

Quoted 5 lines
sys/amd64/include/pc/bios.h +2 -0
@@ -106,6 +106,8 @@ struct bios_oem {
 int	bios_oem_strings(struct bios_oem *oem, u_char *buffer, size_t maxlen);
 uint32_t bios_sigsearch(uint32_t start, u_char *sig, int siglen, int paralen,
 	    int sigofs);
+void bios_add_smap_entries(struct bios_smap *smapbase, u_int32_t smapsize,
+                           vm_paddr_t *physmap, int *physmap_idx);

This uses the GNU formatting conventions, please indent the continuation line same as the previous line.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#10 lore raw

PATCH v7 8/19 xen: use the same hypercall mechanism for XEN and XENHVM

In reply to a message not in the archive
---
 sys/amd64/include/xen/hypercall.h |    7 -------
 sys/i386/i386/locore.s            |    9 +++++++++
 sys/i386/include/xen/hypercall.h  |    8 --------
 sys/x86/xen/hvm.c                 |   24 ++++++++++--------------
 4 files changed, 19 insertions(+), 29 deletions(-)
sys/amd64/include/xen/hypercall.h +0 -7
index a1b2a5c..499fb4d 100644
@@ -51,15 +51,8 @@
 #define CONFIG_XEN_COMPAT	0x030002
 #define __must_check
 
-#ifdef XEN
 #define HYPERCALL_STR(name)					\
 	"call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"
-#else
-#define HYPERCALL_STR(name)					\
-	"mov $("STR(__HYPERVISOR_##name)" * 32),%%eax; "\
-	"add hypercall_stubs(%%rip),%%rax; "			\
-	"call *%%rax"
-#endif
 
 #define _hypercall0(type, name)			\
 ({						\
sys/i386/i386/locore.s +9 -0
index 68cb430..bd136b1 100644
@@ -898,3 +898,12 @@ done_pde:
 #endif
 
 	ret
+
+#ifdef XENHVM
+/* Xen Hypercall page */
+	.text
+.p2align PAGE_SHIFT, 0x90	/* Hypercall_page needs to be PAGE aligned */
+
+NON_GPROF_ENTRY(hypercall_page)
+	.skip	0x1000, 0x90	/* Fill with "nop"s */
+#endif
sys/i386/include/xen/hypercall.h +0 -8
index edc13f4..16b5ee2 100644
@@ -39,16 +39,8 @@
 #define	ENOXENSYS	38
 #define CONFIG_XEN_COMPAT	0x030002
 
-
-#if defined(XEN)
 #define HYPERCALL_STR(name)                                     \
         "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"
-#else
-#define HYPERCALL_STR(name)                                     \
-        "mov hypercall_stubs,%%eax; "                           \
-        "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; "        \
-        "call *%%eax"
-#endif
 
 #define _hypercall0(type, name)                 \
 ({                                              \
sys/x86/xen/hvm.c +10 -14
index b397721..9a0411e 100644
@@ -157,7 +157,7 @@ DPCPU_DEFINE(xen_intr_handle_t, ipi_handle[nitems(xen_ipis)]);
 
 /*------------------ Hypervisor Access Shared Memory Regions -----------------*/
 /** Hypercall table accessed via HYPERVISOR_*_op() methods. */
-char *hypercall_stubs;
+extern char *hypercall_page;
 shared_info_t *HYPERVISOR_shared_info;
 start_info_t *HYPERVISOR_start_info;
 
@@ -559,7 +559,7 @@ xen_hvm_cpuid_base(void)
  * Allocate and fill in the hypcall page.
  */
 static int
-xen_hvm_init_hypercall_stubs(void)
+xen_hvm_init_hypercall_stubs(enum xen_hvm_init_type init_type)
 {
 	uint32_t base, regs[4];
 	int i;
@@ -568,7 +568,7 @@ xen_hvm_init_hypercall_stubs(void)
 	if (base == 0)
 		return (ENXIO);
 
-	if (hypercall_stubs == NULL) {
+	if (init_type == XEN_HVM_INIT_COLD) {
 		do_cpuid(base + 1, regs);
 		printf("XEN: Hypervisor version %d.%d detected.\n",
 		    regs[0] >> 16, regs[0] & 0xffff);
@@ -578,18 +578,9 @@ xen_hvm_init_hypercall_stubs(void)
 	 * Find the hypercall pages.
 	 */
 	do_cpuid(base + 2, regs);
-	
-	if (hypercall_stubs == NULL) {
-		size_t call_region_size;
-
-		call_region_size = regs[0] * PAGE_SIZE;
-		hypercall_stubs = malloc(call_region_size, M_XENHVM, M_NOWAIT);
-		if (hypercall_stubs == NULL)
-			panic("Unable to allocate Xen hypercall region");
-	}
 
 	for (i = 0; i < regs[0]; i++)
-		wrmsr(regs[1], vtophys(hypercall_stubs + i * PAGE_SIZE) + i);
+		wrmsr(regs[1], vtophys(&hypercall_page + i * PAGE_SIZE) + i);
 
 	return (0);
 }
@@ -692,7 +683,12 @@ xen_hvm_init(enum xen_hvm_init_type init_type)
 	if (init_type == XEN_HVM_INIT_CANCELLED_SUSPEND)
 		return;
 
-	error = xen_hvm_init_hypercall_stubs();
+	if (xen_pv_domain()) {
+		/* hypercall page is already set in the PV case */
+		error = 0;
+	} else {
+		error = xen_hvm_init_hypercall_stubs(init_type);
+	}
 
 	switch (init_type) {
 	case XEN_HVM_INIT_COLD:
Signature · 1 line
1.7.7.5 (Apple Git-26)
#11 lore raw

PATCH v7 9/19 xen: add a apic_enumerator for PVH

In reply to a message not in the archive
---
 sys/conf/files.amd64  |    1 +
 sys/x86/xen/mptable.c |  136 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 137 insertions(+), 0 deletions(-)
 create mode 100644 sys/x86/xen/mptable.c
sys/conf/files.amd64 +1 -0
index bdc1517..3bdc05e 100644
@@ -568,3 +568,4 @@ x86/x86/delay.c			standard
 x86/xen/hvm.c			optional	xenhvm
 x86/xen/xen_intr.c		optional	xen | xenhvm
 x86/xen/pv.c			optional	xenhvm
+x86/xen/mptable.c		optional	xenhvm
sys/x86/xen/mptable.c new file +136 -0

136 lines not on this page · raw message

Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#12 lore raw

PATCH v7 10/19 xen: add hook for AP bootstrap memory reservation

In reply to a message not in the archive

This hook will only be implemented for bare metal, Xen doesn't require any bootstrap code since APs are started in long mode with paging enabled.

---
 sys/amd64/amd64/machdep.c   |    6 +++++-
 sys/amd64/include/sysarch.h |    3 +++
 2 files changed, 8 insertions(+), 1 deletions(-)
sys/amd64/amd64/machdep.c +5 -1
index 6bbfe5a..a811a9b 100644
@@ -186,6 +186,9 @@ struct init_ops init_ops = {
 	.early_delay_init =	i8254_init,
 	.early_delay =		i8254_delay,
 	.parse_memmap =		native_parse_memmap,
+#ifdef SMP
+	.mp_bootaddress =	mp_bootaddress,
+#endif
 };
 
 /*
@@ -1507,7 +1510,8 @@ getmemsize(caddr_t kmdp, u_int64_t first)
 
 #ifdef SMP
 	/* make hole for AP bootstrap code */
-	physmap[1] = mp_bootaddress(physmap[1] / 1024);
+	if (init_ops.mp_bootaddress)
+		physmap[1] = init_ops.mp_bootaddress(physmap[1] / 1024);
 #endif
 
 	/*
sys/amd64/include/sysarch.h +3 -0
index 084223e..77f4b29 100644
@@ -16,6 +16,9 @@ struct init_ops {
 	void	(*early_delay_init)(void);
 	void	(*early_delay)(int);
 	void	(*parse_memmap)(caddr_t, vm_paddr_t *, int *);
+#ifdef SMP
+	u_int	(*mp_bootaddress)(u_int);
+#endif
 };
 
 extern struct init_ops init_ops;
Signature · 1 line
1.7.7.5 (Apple Git-26)
#13 lore raw

PATCH v7 11/19 xen: changes to hvm code in order to support PVH guests

In reply to a message not in the archive

On PVH we don't need to init the shared info page, or disable emulated devices. Also, make sure PV IPIs are set before starting the APs.

---
 sys/x86/xen/hvm.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)
sys/x86/xen/hvm.c +12 -5
index 9a0411e..fb1ed79 100644
@@ -523,7 +523,7 @@ xen_setup_cpus(void)
 {
 	int i;
 
-	if (!xen_hvm_domain() || !xen_vector_callback_enabled)
+	if (!xen_vector_callback_enabled)
 		return;
 
 #ifdef __amd64__
@@ -712,10 +712,13 @@ xen_hvm_init(enum xen_hvm_init_type init_type)
 	}
 
 	xen_vector_callback_enabled = 0;
-	xen_domain_type = XEN_HVM_DOMAIN;
-	xen_hvm_init_shared_info_page();
 	xen_hvm_set_callback(NULL);
-	xen_hvm_disable_emulated_devices();
+
+	if (!xen_pv_domain()) {
+		xen_domain_type = XEN_HVM_DOMAIN;
+		xen_hvm_init_shared_info_page();
+		xen_hvm_disable_emulated_devices();
+	}
 } 
 
 void
@@ -746,6 +749,9 @@ xen_set_vcpu_id(void)
 	struct pcpu *pc;
 	int i;
 
+	if (!xen_hvm_domain())
+		return;
+
 	/* Set vcpu_id to acpi_id */
 	CPU_FOREACH(i) {
 		pc = pcpu_find(i);
@@ -789,7 +795,8 @@ xen_hvm_cpu_init(void)
 
 SYSINIT(xen_hvm_init, SI_SUB_HYPERVISOR, SI_ORDER_FIRST, xen_hvm_sysinit, NULL);
 #ifdef SMP
-SYSINIT(xen_setup_cpus, SI_SUB_SMP, SI_ORDER_FIRST, xen_setup_cpus, NULL);
+/* We need to setup IPIs before APs are started */
+SYSINIT(xen_setup_cpus, SI_SUB_SMP-1, SI_ORDER_FIRST, xen_setup_cpus, NULL);
 #endif
 SYSINIT(xen_hvm_cpu_init, SI_SUB_INTR, SI_ORDER_FIRST, xen_hvm_cpu_init, NULL);
 SYSINIT(xen_set_vcpu_id, SI_SUB_CPU, SI_ORDER_ANY, xen_set_vcpu_id, NULL);
Signature · 1 line
1.7.7.5 (Apple Git-26)
#14 lore raw

PATCH v7 12/19 xen: add a hook to perform AP startup

In reply to a message not in the archive

AP startup on PVH follows the PV method, so we need to add a hook in order to diverge from bare metal.

---
 sys/amd64/amd64/mp_machdep.c |   16 ++++---
 sys/amd64/include/cpu.h      |    1 +
 sys/x86/xen/hvm.c            |   17 +++++++-
 sys/x86/xen/pv.c             |   90 ++++++++++++++++++++++++++++++++++++++++++
 sys/xen/pv.h                 |    1 +
 5 files changed, 117 insertions(+), 8 deletions(-)
sys/amd64/amd64/mp_machdep.c +9 -7
index 4ef4b3d..e302886 100644
@@ -90,7 +90,7 @@ extern  struct pcpu __pcpu[];
 
 /* AP uses this during bootstrap.  Do not staticize.  */
 char *bootSTK;
-static int bootAP;
+int bootAP;
 
 /* Free these after use */
 void *bootstacks[MAXCPU];
@@ -122,9 +122,12 @@ u_long *ipi_rendezvous_counts[MAXCPU];
 static u_long *ipi_hardclock_counts[MAXCPU];
 #endif
 
+int native_start_all_aps(void);
+
 /* Default cpu_ops implementation. */
 struct cpu_ops cpu_ops = {
-	.ipi_vectored = lapic_ipi_vectored
+	.ipi_vectored = lapic_ipi_vectored,
+	.start_all_aps = native_start_all_aps,
 };
 
 extern inthand_t IDTVEC(fast_syscall), IDTVEC(fast_syscall32);
@@ -138,7 +141,7 @@ extern int pmap_pcid_enabled;
 static volatile cpuset_t ipi_nmi_pending;
 
 /* used to hold the AP's until we are ready to release them */
-static struct mtx ap_boot_mtx;
+struct mtx ap_boot_mtx;
 
 /* Set to 1 once we're ready to let the APs out of the pen. */
 static volatile int aps_ready = 0;
@@ -165,7 +168,6 @@ static int cpu_cores;			/* cores per package */
 
 static void	assign_cpu_ids(void);
 static void	set_interrupt_apic_ids(void);
-static int	start_all_aps(void);
 static int	start_ap(int apic_id);
 static void	release_aps(void *dummy);
 
@@ -569,7 +571,7 @@ cpu_mp_start(void)
 	assign_cpu_ids();
 
 	/* Start each Application Processor */
-	start_all_aps();
+	cpu_ops.start_all_aps();
 
 	set_interrupt_apic_ids();
 }
@@ -908,8 +910,8 @@ assign_cpu_ids(void)
 /*
  * start each AP in our list
  */
-static int
-start_all_aps(void)
+int
+native_start_all_aps(void)
 {
 	vm_offset_t va = boot_address + KERNBASE;
 	u_int64_t *pt4, *pt3, *pt2;
sys/amd64/include/cpu.h +1 -0
index 3d9ff531..ed9f1db 100644
@@ -64,6 +64,7 @@ struct cpu_ops {
 	void (*cpu_init)(void);
 	void (*cpu_resume)(void);
 	void (*ipi_vectored)(u_int, int);
+	int  (*start_all_aps)(void);
 };
 
 extern struct	cpu_ops cpu_ops;
sys/x86/xen/hvm.c +16 -1
index fb1ed79..5ec9f3a 100644
@@ -53,6 +53,9 @@ __FBSDID("$FreeBSD$");
 #include <xen/hypervisor.h>
 #include <xen/hvm.h>
 #include <xen/xen_intr.h>
+#ifdef __amd64__
+#include <xen/pv.h>
+#endif
 
 #include <xen/interface/hvm/params.h>
 #include <xen/interface/vcpu.h>
@@ -97,6 +100,11 @@ extern void pmap_lazyfix_action(void);
 /* Variables used by mp_machdep to perform the bitmap IPI */
 extern volatile u_int cpu_ipi_pending[MAXCPU];
 
+#ifdef __amd64__
+/* Native AP start used on PVHVM */
+extern int native_start_all_aps(void);
+#endif
+
 /*---------------------------------- Macros ----------------------------------*/
 #define	IPI_TO_IDX(ipi) ((ipi) - APIC_IPI_INTS)
 
@@ -119,7 +127,10 @@ enum xen_domain_type xen_domain_type = XEN_NATIVE;
 struct cpu_ops xen_hvm_cpu_ops = {
 	.ipi_vectored	= lapic_ipi_vectored,
 	.cpu_init	= xen_hvm_cpu_init,
-	.cpu_resume	= xen_hvm_cpu_resume
+	.cpu_resume	= xen_hvm_cpu_resume,
+#ifdef __amd64__
+	.start_all_aps = native_start_all_aps,
+#endif
 };
 
 static MALLOC_DEFINE(M_XENHVM, "xen_hvm", "Xen HVM PV Support");
@@ -698,6 +709,10 @@ xen_hvm_init(enum xen_hvm_init_type init_type)
 		setup_xen_features();
 		cpu_ops = xen_hvm_cpu_ops;
  		vm_guest = VM_GUEST_XEN;
+#ifdef __amd64__
+		if (xen_pv_domain())
+			cpu_ops.start_all_aps = xen_pv_start_all_aps;
+#endif
 		break;
 	case XEN_HVM_INIT_RESUME:
 		if (error != 0)
sys/x86/xen/pv.c +90 -0

117 lines not on this page · raw message

sys/xen/pv.h +1 -0
index 71b8776..60d9def 100644
@@ -24,5 +24,6 @@
 #define	__XEN_PV_H__
 
 void	xen_pv_set_init_ops(void);
+int	xen_pv_start_all_aps(void);
 
 #endif	/* __XEN_PV_H__ */
Signature · 1 line
1.7.7.5 (Apple Git-26)
#15 lore raw

PATCH v7 13/19 xen: introduce flag to disable the local apic

In reply to a message not in the archive

PVH guests don't have an emulated lapic.

---
 sys/amd64/amd64/mp_machdep.c |   10 ++++++----
 sys/amd64/include/apicvar.h  |    1 +
 sys/i386/include/apicvar.h   |    1 +
 sys/i386/xen/xen_machdep.c   |    2 ++
 sys/x86/x86/local_apic.c     |    8 +++++---
 sys/x86/xen/pv.c             |    3 +++
 6 files changed, 18 insertions(+), 7 deletions(-)
sys/amd64/amd64/mp_machdep.c +6 -4
index e302886..0296a92 100644
@@ -709,7 +709,8 @@ init_secondary(void)
 	wrmsr(MSR_SF_MASK, PSL_NT|PSL_T|PSL_I|PSL_C|PSL_D);
 
 	/* Disable local APIC just to be sure. */
-	lapic_disable();
+	if (!lapic_disabled)
+		lapic_disable();
 
 	/* signal our startup to the BSP. */
 	mp_naps++;
@@ -735,7 +736,7 @@ init_secondary(void)
 
 	/* A quick check from sanity claus */
 	cpuid = PCPU_GET(cpuid);
-	if (PCPU_GET(apic_id) != lapic_id()) {
+	if (!lapic_disabled && (PCPU_GET(apic_id) != lapic_id())) {
 		printf("SMP: cpuid = %d\n", cpuid);
 		printf("SMP: actual apic_id = %d\n", lapic_id());
 		printf("SMP: correct apic_id = %d\n", PCPU_GET(apic_id));
@@ -751,7 +752,8 @@ init_secondary(void)
 	mtx_lock_spin(&ap_boot_mtx);
 
 	/* Init local apic for irq's */
-	lapic_setup(1);
+	if (!lapic_disabled)
+		lapic_setup(1);
 
 	/* Set memory range attributes for this CPU to match the BSP */
 	mem_range_AP_init();
@@ -766,7 +768,7 @@ init_secondary(void)
 	if (cpu_logical > 1 && PCPU_GET(apic_id) % cpu_logical != 0)
 		CPU_SET(cpuid, &logical_cpus_mask);
 
-	if (bootverbose)
+	if (!lapic_disabled && bootverbose)
 		lapic_dump("AP");
 
 	if (smp_cpus == mp_ncpus) {
sys/amd64/include/apicvar.h +1 -0
index e7423a3..84e01d4 100644
@@ -169,6 +169,7 @@ inthand_t
 
 extern vm_paddr_t lapic_paddr;
 extern int apic_cpuids[];
+extern bool lapic_disabled;
 
 u_int	apic_alloc_vector(u_int apic_id, u_int irq);
 u_int	apic_alloc_vectors(u_int apic_id, u_int *irqs, u_int count,
sys/i386/include/apicvar.h +1 -0
index df99ebe..24c99f0 100644
@@ -168,6 +168,7 @@ inthand_t
 
 extern vm_paddr_t lapic_paddr;
 extern int apic_cpuids[];
+extern bool lapic_disabled;
 
 u_int	apic_alloc_vector(u_int apic_id, u_int irq);
 u_int	apic_alloc_vectors(u_int apic_id, u_int *irqs, u_int count,
sys/i386/xen/xen_machdep.c +2 -0
index 09c01f1..7039b4a 100644
@@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/intr_machdep.h>
 #include <machine/md_var.h>
 #include <machine/asmacros.h>
+#include <machine/apicvar.h>
 
 
 
@@ -912,6 +913,7 @@ initvalues(start_info_t *startinfo)
 #endif	
 	xen_start_info = startinfo;
 	HYPERVISOR_start_info = startinfo;
+	lapic_disabled = true;
 	xen_phys_machine = (xen_pfn_t *)startinfo->mfn_list;
 
 	IdlePTD = (pd_entry_t *)((uint8_t *)startinfo->pt_base + PAGE_SIZE);
sys/x86/x86/local_apic.c +5 -3
index 41bd602..85736c8 100644
@@ -156,6 +156,7 @@ extern inthand_t IDTVEC(rsvd);
 
 volatile lapic_t *lapic;
 vm_paddr_t lapic_paddr;
+bool lapic_disabled;
 static u_long lapic_timer_divisor;
 static struct eventtimer lapic_et;
 
@@ -1367,9 +1368,10 @@ apic_setup_io(void *dummy __unused)
 	if (retval != 0)
 		printf("%s: Failed to setup I/O APICs: returned %d\n",
 		    best_enum->apic_name, retval);
-#ifdef XEN
-	return;
-#endif
+
+	if (lapic_disabled)
+		return;
+
 	/*
 	 * Finish setting up the local APIC on the BSP once we know how to
 	 * properly program the LINT pins.
sys/x86/xen/pv.c +3 -0
index 7e45a83..e783bb8 100644
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/clock.h>
 #include <machine/pc/bios.h>
 #include <machine/smp.h>
+#include <machine/apicvar.h>
 
 #include <xen/xen-os.h>
 #include <xen/pv.h>
@@ -230,4 +231,6 @@ xen_pv_set_init_ops(void)
 {
 	/* Init ops for Xen PV */
 	init_ops = xen_init_ops;
+	/* Disable lapic */
+	lapic_disabled = true;
 }
Signature · 1 line
1.7.7.5 (Apple Git-26)
#16 lore raw

PATCH v7 14/19 xen: introduce a dummy pvcpu device

In reply to a message not in the archive

Since Xen PVH guests doesn't have ACPI, we need to create a dummy pvcpu device that will be used to fill the pcpu->pc_device field.

---
 sys/conf/files.amd64 |    1 +
 sys/x86/xen/pvcpu.c  |   84 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 0 deletions(-)
 create mode 100644 sys/x86/xen/pvcpu.c
sys/conf/files.amd64 +1 -0
index 3bdc05e..4a3f612 100644
@@ -569,3 +569,4 @@ x86/xen/hvm.c			optional	xenhvm
 x86/xen/xen_intr.c		optional	xen | xenhvm
 x86/xen/pv.c			optional	xenhvm
 x86/xen/mptable.c		optional	xenhvm
+x86/xen/pvcpu.c			optional	xenhvm
sys/x86/xen/pvcpu.c new file +84 -0

84 lines not on this page · raw message

Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#17 lore raw

PATCH v7 15/19 xen: create a Xen nexus to use in PV/PVH

In reply to a message not in the archive

Introduce a Xen specific nexus that is going to be in charge for attaching Xen specific devices. Remove the identify routine from Xen devices and instead attach them from the nexus (PV/PVH) or xenpci (HVM).

---
 sys/conf/files.amd64        |    1 +
 sys/conf/files.i386         |    1 +
 sys/dev/xen/timer/timer.c   |   14 ------
 sys/dev/xen/xenpci/xenpci.c |    5 ++
 sys/x86/xen/xen_nexus.c     |   99 +++++++++++++++++++++++++++++++++++++++++++
 sys/xen/xenstore/xenstore.c |    7 ---
 6 files changed, 106 insertions(+), 21 deletions(-)
 create mode 100644 sys/x86/xen/xen_nexus.c
sys/conf/files.amd64 +1 -0
index 4a3f612..8bb0b5c 100644
@@ -570,3 +570,4 @@ x86/xen/xen_intr.c		optional	xen | xenhvm
 x86/xen/pv.c			optional	xenhvm
 x86/xen/mptable.c		optional	xenhvm
 x86/xen/pvcpu.c			optional	xenhvm
+x86/xen/xen_nexus.c		optional	xenhvm
sys/conf/files.i386 +1 -0
index 790296d..751db32 100644
@@ -603,3 +603,4 @@ x86/x86/tsc.c			standard
 x86/x86/delay.c			standard
 x86/xen/hvm.c			optional xenhvm
 x86/xen/xen_intr.c		optional xen | xenhvm
+x86/xen/xen_nexus.c		optional xen | xenhvm
sys/dev/xen/timer/timer.c +0 -14
index 96372ab..b047786 100644
@@ -98,19 +98,6 @@ struct xentimer_softc {
 /* Last time; this guarantees a monotonically increasing clock. */
 volatile uint64_t xen_timer_last_time = 0;
 
-static void
-xentimer_identify(driver_t *driver, device_t parent)
-{
-	if (!xen_domain())
-		return;
-
-	/* Handle all Xen PV timers in one device instance. */
-	if (devclass_get_device(xentimer_devclass, 0))
-		return;
-
-	BUS_ADD_CHILD(parent, 0, "xen_et", 0);
-}
-
 static int
 xentimer_probe(device_t dev)
 {
@@ -618,7 +605,6 @@ void xen_delay(int n)
 }
 
 static device_method_t xentimer_methods[] = {
-	DEVMETHOD(device_identify, xentimer_identify),
 	DEVMETHOD(device_probe, xentimer_probe),
 	DEVMETHOD(device_attach, xentimer_attach),
 	DEVMETHOD(device_detach, xentimer_detach),
sys/dev/xen/xenpci/xenpci.c +5 -0
index dd2ad92..cac8022 100644
@@ -270,6 +270,11 @@ xenpci_attach(device_t dev)
 		goto errexit;
 	}
 
+	if (BUS_ADD_CHILD(dev, 0, "xenstore", 0) == NULL)
+		panic("xenpci: unable to add xenstore device");
+	if (BUS_ADD_CHILD(nexus, 0, "xen_et", 0) == NULL)
+		panic("xenpci: unable to add xen pv timer device");
+
 	return (bus_generic_attach(dev));
 
 errexit:
sys/x86/xen/xen_nexus.c new file +99 -0

99 lines not on this page · raw message

sys/xen/xenstore/xenstore.c +0 -7
index d404862..bcf6357 100644
@@ -1079,12 +1079,6 @@ xs_init_comms(void)
 }
 
 /*------------------ Private Device Attachment Functions  --------------------*/
-static void
-xs_identify(driver_t *driver, device_t parent)
-{
-
-	BUS_ADD_CHILD(parent, 0, "xenstore", 0);
-}
 
 /**
  * Probe for the existance of the XenStore.
@@ -1240,7 +1234,6 @@ xs_resume(device_t dev __unused)
 /*-------------------- Private Device Attachment Data  -----------------------*/
 static device_method_t xenstore_methods[] = { 
 	/* Device interface */ 
-	DEVMETHOD(device_identify,	xs_identify),
 	DEVMETHOD(device_probe,         xs_probe), 
 	DEVMETHOD(device_attach,        xs_attach), 
 	DEVMETHOD(device_detach,        bus_generic_detach), 
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#18 lore raw

Re: [PATCH v7 15/19] xen: create a Xen nexus to use in PV/PVH

Quoted 4 lines · Roger Pau Monne

Introduce a Xen specific nexus that is going to be in charge for attaching Xen specific devices. Remove the identify routine from Xen devices and instead attach them from the nexus (PV/PVH) or xenpci (HVM).

As with my previous mail, I would encourage you to create a xenpv0 device and have the xen nexus be very minimal. This would let you leave the existing identify routines in place (which is cleaner / more extensible than a static table of devices that you explicitly add), but by having the PV-specific drivers attach as children of xenpv0, their identify routines would only be invoked when xenpv0 attached. You can even use an identify routine for CPUs (see cpu_identify in sys/x86/x86/legacy.c).

Signature · 1 line
John Baldwin
#19 lore raw

PATCH v7 16/19 xen: add shutdown hook for PVH

In reply to a message not in the archive

Add the PV shutdown hook to PVH.

---
 sys/dev/xen/control/control.c |   37 ++++++++++++++++++-------------------
 1 files changed, 18 insertions(+), 19 deletions(-)
sys/dev/xen/control/control.c +18 -19
index bc0609d..78894ba 100644
@@ -316,21 +316,6 @@ xctrl_suspend()
 	EVENTHANDLER_INVOKE(power_resume);
 }
 
-static void
-xen_pv_shutdown_final(void *arg, int howto)
-{
-	/*
-	 * Inform the hypervisor that shutdown is complete.
-	 * This is not necessary in HVM domains since Xen
-	 * emulates ACPI in that mode and FreeBSD's ACPI
-	 * support will request this transition.
-	 */
-	if (howto & (RB_HALT | RB_POWEROFF))
-		HYPERVISOR_shutdown(SHUTDOWN_poweroff);
-	else
-		HYPERVISOR_shutdown(SHUTDOWN_reboot);
-}
-
 #else
 
 /* HVM mode suspension. */
@@ -440,6 +425,21 @@ xctrl_crash()
 	panic("Xen directed crash");
 }
 
+static void
+xen_pv_shutdown_final(void *arg, int howto)
+{
+	/*
+	 * Inform the hypervisor that shutdown is complete.
+	 * This is not necessary in HVM domains since Xen
+	 * emulates ACPI in that mode and FreeBSD's ACPI
+	 * support will request this transition.
+	 */
+	if (howto & (RB_HALT | RB_POWEROFF))
+		HYPERVISOR_shutdown(SHUTDOWN_poweroff);
+	else
+		HYPERVISOR_shutdown(SHUTDOWN_reboot);
+}
+
 /*------------------------------ Event Reception -----------------------------*/
 static void
 xctrl_on_watch_event(struct xs_watch *watch, const char **vec, unsigned int len)
@@ -522,10 +522,9 @@ xctrl_attach(device_t dev)
 	xctrl->xctrl_watch.callback_data = (uintptr_t)xctrl;
 	xs_register_watch(&xctrl->xctrl_watch);
 
-#ifndef XENHVM
-	EVENTHANDLER_REGISTER(shutdown_final, xen_pv_shutdown_final, NULL,
-			      SHUTDOWN_PRI_LAST);
-#endif
+	if (xen_pv_domain())
+		EVENTHANDLER_REGISTER(shutdown_final, xen_pv_shutdown_final, NULL,
+		                      SHUTDOWN_PRI_LAST);
 
 	return (0);
 }
Signature · 1 line
1.7.7.5 (Apple Git-26)
#20 lore raw

PATCH v7 17/19 xen: xenstore changes to support PVH

In reply to a message not in the archive
---
 sys/xen/xenstore/xenstore.c |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)
sys/xen/xenstore/xenstore.c +10 -11
index bcf6357..2893c84 100644
@@ -229,13 +229,11 @@ struct xs_softc {
 	 */
 	struct sx xenwatch_mutex;
 
-#ifdef XENHVM
 	/**
 	 * The HVM guest pseudo-physical frame number.  This is Xen's mapping
 	 * of the true machine frame number into our "physical address space".
 	 */
 	unsigned long gpfn;
-#endif
 
 	/**
 	 * The event channel for communicating with the
@@ -1141,13 +1139,15 @@ xs_attach(device_t dev)
 	/* Initialize the interface to xenstore. */
 	struct proc *p;
 
-#ifdef XENHVM
-	xs.evtchn = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN);
-	xs.gpfn = hvm_get_parameter(HVM_PARAM_STORE_PFN);
-	xen_store = pmap_mapdev(xs.gpfn * PAGE_SIZE, PAGE_SIZE);
-#else
-	xs.evtchn = xen_start_info->store_evtchn;
-#endif
+	if (xen_hvm_domain()) {
+		xs.evtchn = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN);
+		xs.gpfn = hvm_get_parameter(HVM_PARAM_STORE_PFN);
+		xen_store = pmap_mapdev(xs.gpfn * PAGE_SIZE, PAGE_SIZE);
+	} else if (xen_pv_domain()) {
+		xs.evtchn = HYPERVISOR_start_info->store_evtchn;
+	} else {
+		panic("Unknown domain type, cannot initialize xenstore\n");
+	}
 
 	TAILQ_INIT(&xs.reply_list);
 	TAILQ_INIT(&xs.watch_events);
@@ -1256,9 +1256,8 @@ static devclass_t xenstore_devclass;
  
 #ifdef XENHVM
 DRIVER_MODULE(xenstore, xenpci, xenstore_driver, xenstore_devclass, 0, 0);
-#else
-DRIVER_MODULE(xenstore, nexus, xenstore_driver, xenstore_devclass, 0, 0);
 #endif
+DRIVER_MODULE(xenstore, nexus, xenstore_driver, xenstore_devclass, 0, 0);
 
 /*------------------------------- Sysctl Data --------------------------------*/
 /* XXX Shouldn't the node be somewhere else? */
Signature · 1 line
1.7.7.5 (Apple Git-26)
#21 lore raw

PATCH v7 18/19 xen: changes to gnttab for PVH

In reply to a message not in the archive
---
 sys/xen/gnttab.c |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)
sys/xen/gnttab.c +21 -5
index 03c32b7..6949be5 100644
@@ -25,6 +25,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/lock.h>
 #include <sys/malloc.h>
 #include <sys/mman.h>
+#include <sys/limits.h>
 
 #include <xen/xen-os.h>
 #include <xen/hypervisor.h>
@@ -607,6 +608,7 @@ gnttab_resume(void)
 {
 	int error;
 	unsigned int max_nr_gframes, nr_gframes;
+	void *alloc_mem;
 
 	nr_gframes = nr_grant_frames;
 	max_nr_gframes = max_nr_grant_frames();
@@ -614,11 +616,25 @@ gnttab_resume(void)
 		return (ENOSYS);
 
 	if (!resume_frames) {
-		error = xenpci_alloc_space(PAGE_SIZE * max_nr_gframes,
-		    &resume_frames);
-		if (error) {
-			printf("error mapping gnttab share frames\n");
-			return (error);
+		if (xen_pv_domain()) {
+			/*
+			 * This is a waste of physical memory,
+			 * we should use ballooned pages instead,
+			 * but it will do for now.
+			 */
+			alloc_mem = contigmalloc(max_nr_gframes * PAGE_SIZE,
+			                         M_DEVBUF, M_NOWAIT, 0,
+			                         ULONG_MAX, PAGE_SIZE, 0);
+			KASSERT((alloc_mem != NULL),
+				("unable to alloc memory for gnttab"));
+			resume_frames = vtophys(alloc_mem);
+		} else {
+			error = xenpci_alloc_space(PAGE_SIZE * max_nr_gframes,
+			    &resume_frames);
+			if (error) {
+				printf("error mapping gnttab share frames\n");
+				return (error);
+			}
 		}
 	}
 
Signature · 1 line
1.7.7.5 (Apple Git-26)
#22 lore raw

PATCH v7 19/19 isa: allow ISA bus to attach to the nexus

In reply to a message not in the archive
---
 sys/x86/isa/isa.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
sys/x86/isa/isa.c +3 -0
index 1a57137..09d1ab7 100644
@@ -241,3 +241,6 @@ isa_release_resource(device_t bus, device_t child, int type, int rid,
  * On this platform, isa can also attach to the legacy bus.
  */
 DRIVER_MODULE(isa, legacy, isa_driver, isa_devclass, 0, 0);
+#ifdef XENHVM
+DRIVER_MODULE(isa, nexus, isa_driver, isa_devclass, 0, 0);
+#endif
Signature · 1 line
1.7.7.5 (Apple Git-26)

A message that is not in the archive (sent off-list or not yet received): [email protected]

#24 lore raw

Thank you for doing the split.

Quoted 6 lines · Roger Pau Monne

Add the PV/PVH entry point and the low level functions for PVH initialization.

---
 sys/amd64/amd64/locore.S     |   53 +++++++++++++++++++++++++++++++
 sys/amd64/amd64/machdep.c    |   72 ++++++++++++++++++++++++++++++++++++++++++
 sys/amd64/include/asmacros.h |   26 +++++++++++++++

The changes to the three files above all protected by #ifdef XENHVM. IMO it is more logical to move the code into xen-specific files. The support would be localized and somewhat postpone morphing the sys/amd64 into the maze of #ifdefs, which is the sys/i386 already.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#25 lore raw
In reply to a message not in the archive
Quoted 11 lines · Roger Pau Monne

Add the PV/PVH entry point and the low level functions for PVH initialization.

---
  sys/amd64/amd64/locore.S     |   53 +++++++++++++++++++++++++++++++
  sys/amd64/amd64/machdep.c    |   72 ++++++++++++++++++++++++++++++++++++++++++
  sys/amd64/include/asmacros.h |   26 +++++++++++++++
  sys/i386/xen/xen_machdep.c   |    2 +
  sys/x86/xen/hvm.c            |    1 +
  sys/xen/xen-os.h             |    4 ++
  6 files changed, 158 insertions(+), 0 deletions(-)

[..]

Quoted 34 lines
sys/amd64/amd64/machdep.c +15 -0
index eae657b..a73e33e 100644
@@ -146,10 +146,17 @@ __FBSDID("$FreeBSD$");
  #include <isa/isareg.h>
  #include <isa/rtc.h>
 
+#ifdef XENHVM
+#include <xen/xen-os.h>
+#endif
+
  /* Sanity check for __curthread() */
  CTASSERT(offsetof(struct pcpu, pc_curthread) == 0);
 
  extern u_int64_t hammer_time(u_int64_t, u_int64_t);
+#ifdef XENHVM
+extern u_int64_t hammer_time_xen(start_info_t *, u_int64_t);
+#endif
 
  extern void printcpuinfo(void);	/* XXX header file */
  extern void identify_cpu(void);
@@ -1683,6 +1690,71 @@ do_next:
  	msgbufp = (struct msgbuf *)PHYS_TO_DMAP(phys_avail[pa_indx]);
  }
 
+#ifdef XENHVM
+/*
+ * First function called by the Xen PVH boot sequence.
+ *
+ * Set some Xen global variables and prepare the environment so it is
+ * as similar as possible to what native FreeBSD init function expects.
+ */
+u_int64_t

sys/amd64/amd64/machdep.c do_next: · line 1710

Quoted 10 lines
sys/amd64/amd64/machdep.c +10 -0
+hammer_time_xen(start_info_t *si, u_int64_t xenstack)
+{
+	u_int64_t physfree;
+	u_int64_t *PT4 = (u_int64_t *)xenstack;
+	u_int64_t *PT3 = (u_int64_t *)(xenstack + PAGE_SIZE);
+	u_int64_t *PT2 = (u_int64_t *)(xenstack + 2 * PAGE_SIZE);
+	int i;
+
+	KASSERT((si != NULL && xenstack != 0),
+	        ("invalid start_info or xenstack"));

If I'm not mistaken, the user won't see the error if the assert failed (the console is not yet initialized). Perhaps xc_printf is more suitable here.

Signature · 1 line
Julien Grall

A message that is not in the archive (sent off-list or not yet received): [email protected]

#27 lore raw

Re: [PATCH v7 04/19] amd64: introduce hook for custom preload metadata parsers

Quoted 4 lines · Roger Pau Monne
---
 sys/amd64/amd64/machdep.c   |   45 +++++++++++++----
 sys/amd64/include/sysarch.h |   12 +++++
 sys/conf/files.amd64        |    1 +

This looks fine for me.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#28 lore raw

Re: [PATCH v7 04/19] amd64: introduce hook for custom preload metadata parsers

In reply to a message not in the archive
Quoted 11 lines · Roger Pau Monne
sys/xen/pv.h new file +8 -0
@@ -0,0 +1,28 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *

sys/xen/pv.h line 18

Quoted 10 lines
sys/xen/pv.h new file +10 -0
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.

One non-technical question. This license statement doesn't actually say who the copyright belongs to which seems problematic. Would it be possible to use FreeBSD's preferred 2-clause BSD license on this file?

Signature · 1 line
John Baldwin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#30 lore raw

Re: [PATCH v7 04/19] amd64: introduce hook for custom preload metadata parsers

Quoted 18 lines · John Baldwin
Quoted 17 lines · Roger Pau Monne
sys/xen/pv.h new file +14 -0
@@ -0,0 +1,28 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Quoted 8 lines

sys/xen/pv.h line 18

Quoted 4 lines
sys/xen/pv.h new file +4 -0
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.

One non-technical question. This license statement doesn't actually say who the copyright belongs to which seems problematic. Would it be possible to use FreeBSD's preferred 2-clause BSD license on this file?

I copied the license from sys/xen/hvm.h without realizing it was not the standard 2-clause BSD one, but I don't have any problem changing it (maybe we should also change hvm.h?) to match the license in pv.c.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#32 lore raw

Re: [PATCH v7 04/19] amd64: introduce hook for custom preload metadata parsers

Quoted 28 lines · Roger Pau Monné
Quoted 18 lines · John Baldwin
Quoted 17 lines · Roger Pau Monne
sys/xen/pv.h new file +14 -0
@@ -0,0 +1,28 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Quoted 8 lines

sys/xen/pv.h line 18

Quoted 4 lines
sys/xen/pv.h new file +4 -0
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.

One non-technical question. This license statement doesn't actually say who the copyright belongs to which seems problematic. Would it be possible to use FreeBSD's preferred 2-clause BSD license on this file?

Quoted 3 lines

I copied the license from sys/xen/hvm.h without realizing it was not the standard 2-clause BSD one, but I don't have any problem changing it (maybe we should also change hvm.h?) to match the license in pv.c.

The license in pv.c is perfect. For hvm.h, if that could be changed to the 2-clause BSD license, that would also be great. I'll leave that up you to and Justin to determine if that change is ok to make.

Signature · 6 lines
John Baldwin

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#34 lore raw

Re: [PATCH v7 10/19] xen: add hook for AP bootstrap memory reservation

Quoted 37 lines · Roger Pau Monne

This hook will only be implemented for bare metal, Xen doesn't require any bootstrap code since APs are started in long mode with paging enabled.

---
 sys/amd64/amd64/machdep.c   |    6 +++++-
 sys/amd64/include/sysarch.h |    3 +++
 2 files changed, 8 insertions(+), 1 deletions(-)
sys/amd64/amd64/machdep.c +5 -1
index 6bbfe5a..a811a9b 100644
@@ -186,6 +186,9 @@ struct init_ops init_ops = {
 	.early_delay_init =	i8254_init,
 	.early_delay =		i8254_delay,
 	.parse_memmap =		native_parse_memmap,
+#ifdef SMP
+	.mp_bootaddress =	mp_bootaddress,
+#endif
 };
 
 /*
@@ -1507,7 +1510,8 @@ getmemsize(caddr_t kmdp, u_int64_t first)
 
 #ifdef SMP
 	/* make hole for AP bootstrap code */
-	physmap[1] = mp_bootaddress(physmap[1] / 1024);
+	if (init_ops.mp_bootaddress)
+		physmap[1] = init_ops.mp_bootaddress(physmap[1] / 1024);
 #endif
 
 	/*
sys/amd64/include/sysarch.h +0 -0
index 084223e..77f4b29 100644

sys/amd64/include/sysarch.h struct init_ops { · line 24

Quoted 9 lines
sys/amd64/include/sysarch.h +3 -0
@@ -16,6 +16,9 @@ struct init_ops {
 	void	(*early_delay_init)(void);
 	void	(*early_delay)(int);
 	void	(*parse_memmap)(caddr_t, vm_paddr_t *, int *);
+#ifdef SMP
+	u_int	(*mp_bootaddress)(u_int);
+#endif
 };
 
 extern struct init_ops init_ops;

I suggest to make the init_ops contain the mp_bootaddress unconditionally, instead of making it depended on SMP. The #ifdef makes the kernel binary interface fragile and depended on the config, which would cause problems in future if any module needs any interation with init_ops.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#36 lore raw

Re: [PATCH v7 02/19] xen: add macro to detect if running as Dom0

Quoted 12 lines · Roger Pau Monne
---
 sys/xen/xen-os.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
sys/xen/xen-os.h +0 -0
index c7474d8..e8a5a99 100644
@@ -82,6 +82,13 @@ xen_hvm_domain(void)
 	return (xen_domain_type == XEN_HVM_DOMAIN);
 }
 

sys/xen/xen-os.h xen_hvm_domain(void) · line 94

Quoted 10 lines
sys/xen/xen-os.h +7 -0
+static inline int
+xen_initial_domain(void)
+{
+	return (xen_domain() && HYPERVISOR_start_info &&
+	        HYPERVISOR_start_info->flags & SIF_INITDOMAIN);
+}
+
 #ifndef xen_mb
 #define xen_mb() mb()
 #endif

This looks fine to me.

Signature · 1 line
John Baldwin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#38 lore raw

Re: [PATCH v7 03/19] xen: add and enable Xen console for PVH guests

Quoted 5 lines · Roger Pau Monne
sys/dev/xen/console/console.c +0 -0
index 23eaee2..e8079da 100644

sys/dev/xen/console/console.c struct mtx cn_mtx; · line 77

Quoted 10 lines
sys/dev/xen/console/console.c +2 -1
@@ -69,11 +69,14 @@ struct mtx              cn_mtx;
 static char wbuf[WBUF_SIZE];
 static char rbuf[RBUF_SIZE];
 static int rc, rp;
-static unsigned int cnsl_evt_reg;
+unsigned int cnsl_evt_reg;
 static unsigned int wc, wp; /* write_cons, write_prod */
 xen_intr_handle_t xen_intr_handle;
 device_t xencons_dev;
 
+/* Virt address of the shared console page */

Tiny nit: I would expand "Virt" to "Virtual"

Quoted 15 lines
sys/dev/xen/console/console.c +8 -0
+char *console_page;
+
 #ifdef KDB
 static int	xc_altbrk;
 #endif
@@ -110,9 +113,28 @@ static struct ttydevsw xc_ttydevsw = {
         .tsw_outwakeup	= xcoutwakeup,
 };
 
+/*----------------------------- Debug function -------------------------------*/
+#define XC_PRINTF_BUFSIZE 1024
+void
+xc_printf(const char *fmt, ...)
+{
+        __va_list ap;

sys/dev/xen/console/console.c static struct ttydevsw xc_ttydevsw = { · line 131

Quoted 10 lines
sys/dev/xen/console/console.c +10 -0
+        int retval;
+        static char buf[XC_PRINTF_BUFSIZE];
+
+        va_start(ap, fmt);
+        retval = vsnprintf(buf, XC_PRINTF_BUFSIZE - 1, fmt, ap);
+        va_end(ap);
+        buf[retval] = 0;
+        HYPERVISOR_console_write(buf, retval);
+}
+

vsnprintf() always nul-terminates, so you can simplify this slightly to:

	retval = vsnprintf(buf, sizeof(buf), fmt, ap);

OTOH, you can't actually use 'retval' from vsnprintf as it returns the number of characters that would have been output if the buffer were infinitely long, not the number of characters output into the string.

Quoted 1 line

From printf(3):

These functions return the number of characters printed (not including the trailing `\0' used to end output to strings) or a negative value if an output error occurs, except for snprintf() and vsnprintf(), which return the number of characters that would have been printed if the size were unlimited (again, not including the final `\0').

So I think what you actually want is this:

void
xc_printf(const char *fmt, ...)

{
	static char buf[XC_PRINTF_BUFSIZE];
	__va_list ap;

	va_start(ap, fmt);
	vsnprintf(buf, sizeof(buf), fmt, ap);
	va_end(ap);
	HYPERVISOR_console_write(buf, strlen(buf));
}

(And I realize this is an old bug, you were just moving an existing function)

sys/dev/xen/console/console.c

Quoted 10 lines
sys/dev/xen/console/console.c +0 -9
-static void
-xc_identify(driver_t *driver, device_t parent)
-{
-	device_t child;
-	child = BUS_ADD_CHILD(parent, 0, driver_name, 0);
-	device_set_driver(child, driver);
-	device_set_desc(child, "Xen Console");
-}
-

Hmm, how does the device get created without an identify routine?

Signature · 1 line
John Baldwin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#40 lore raw

Re: [PATCH v7 05/19] xen: rework xen timer so it can be used early in boot process

Quoted 3 lines · Roger Pau Monne

This should not introduce any functional change, and makes the functions suitable to be called before we have actually mapped the vcpu_info struct on a per-cpu basis.

Looks fine to me.

Signature · 1 line
John Baldwin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#42 lore raw

Re: [PATCH v7 08/19] xen: use the same hypercall mechanism for XEN and XENHVM

Quoted 6 lines · Roger Pau Monne
---
 sys/amd64/include/xen/hypercall.h |    7 -------
 sys/i386/i386/locore.s            |    9 +++++++++
 sys/i386/include/xen/hypercall.h  |    8 --------
 sys/x86/xen/hvm.c                 |   24 ++++++++++--------------
 4 files changed, 19 insertions(+), 29 deletions(-)

Looks good to me.

Signature · 1 line
John Baldwin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#44 lore raw

Re: [PATCH v7 09/19] xen: add a apic_enumerator for PVH

Quoted 3 lines · Roger Pau Monne
---
 sys/conf/files.amd64  |    1 +
 sys/x86/xen/mptable.c |  136

My only request would be to not call this 'mptable.c' as it has nothing to do with the MP Table spec. (I realize the older Xen code made this error previously.) You could maybe call it sys/x86/xen/pv_vcpu.c or some such.

Signature · 1 line
John Baldwin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#46 lore raw

Re: [PATCH v7 11/19] xen: changes to hvm code in order to support PVH guests

Quoted 2 lines · Roger Pau Monne

On PVH we don't need to init the shared info page, or disable emulated devices. Also, make sure PV IPIs are set before starting the APs.

Looks ok to me.

Signature · 1 line
John Baldwin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#48 lore raw

Re: [PATCH v7 12/19] xen: add a hook to perform AP startup

Review

Quoted 6 lines · Roger Pau Monne

AP startup on PVH follows the PV method, so we need to add a hook in order to diverge from bare metal.
---

(quoted diff) +2 -0
+int native_start_all_aps(void);
+

Please put this in a header instead of using an extern in the Xen PV code. <machine/smp.h> is probably the best header to use.

Signature · 1 line
John Baldwin
#49 lore raw

Re: [PATCH v7 12/19] xen: add a hook to perform AP startup

In reply to a message not in the archive
Quoted 202 lines · Roger Pau Monne

AP startup on PVH follows the PV method, so we need to add a hook in order to diverge from bare metal.

---
 sys/amd64/amd64/mp_machdep.c |   16 ++++---
 sys/amd64/include/cpu.h      |    1 +
 sys/x86/xen/hvm.c            |   17 +++++++-
 sys/x86/xen/pv.c             |   90 ++++++++++++++++++++++++++++++++++++++++++
 sys/xen/pv.h                 |    1 +
 5 files changed, 117 insertions(+), 8 deletions(-)
sys/amd64/amd64/mp_machdep.c +9 -7
index 4ef4b3d..e302886 100644
@@ -90,7 +90,7 @@ extern  struct pcpu __pcpu[];
 
 /* AP uses this during bootstrap.  Do not staticize.  */
 char *bootSTK;
-static int bootAP;
+int bootAP;
 
 /* Free these after use */
 void *bootstacks[MAXCPU];
@@ -122,9 +122,12 @@ u_long *ipi_rendezvous_counts[MAXCPU];
 static u_long *ipi_hardclock_counts[MAXCPU];
 #endif
 
+int native_start_all_aps(void);
+
 /* Default cpu_ops implementation. */
 struct cpu_ops cpu_ops = {
-	.ipi_vectored = lapic_ipi_vectored
+	.ipi_vectored = lapic_ipi_vectored,
+	.start_all_aps = native_start_all_aps,
 };
 
 extern inthand_t IDTVEC(fast_syscall), IDTVEC(fast_syscall32);
@@ -138,7 +141,7 @@ extern int pmap_pcid_enabled;
 static volatile cpuset_t ipi_nmi_pending;
 
 /* used to hold the AP's until we are ready to release them */
-static struct mtx ap_boot_mtx;
+struct mtx ap_boot_mtx;
 
 /* Set to 1 once we're ready to let the APs out of the pen. */
 static volatile int aps_ready = 0;
@@ -165,7 +168,6 @@ static int cpu_cores;			/* cores per package */
 
 static void	assign_cpu_ids(void);
 static void	set_interrupt_apic_ids(void);
-static int	start_all_aps(void);
 static int	start_ap(int apic_id);
 static void	release_aps(void *dummy);
 
@@ -569,7 +571,7 @@ cpu_mp_start(void)
 	assign_cpu_ids();
 
 	/* Start each Application Processor */
-	start_all_aps();
+	cpu_ops.start_all_aps();
 
 	set_interrupt_apic_ids();
 }
@@ -908,8 +910,8 @@ assign_cpu_ids(void)
 /*
  * start each AP in our list
  */
-static int
-start_all_aps(void)
+int
+native_start_all_aps(void)
 {
 	vm_offset_t va = boot_address + KERNBASE;
 	u_int64_t *pt4, *pt3, *pt2;
sys/amd64/include/cpu.h +1 -0
index 3d9ff531..ed9f1db 100644
@@ -64,6 +64,7 @@ struct cpu_ops {
 	void (*cpu_init)(void);
 	void (*cpu_resume)(void);
 	void (*ipi_vectored)(u_int, int);
+	int  (*start_all_aps)(void);
 };
 
 extern struct	cpu_ops cpu_ops;
sys/x86/xen/hvm.c +16 -1
index fb1ed79..5ec9f3a 100644
@@ -53,6 +53,9 @@ __FBSDID("$FreeBSD$");
 #include <xen/hypervisor.h>
 #include <xen/hvm.h>
 #include <xen/xen_intr.h>
+#ifdef __amd64__
+#include <xen/pv.h>
+#endif
 
 #include <xen/interface/hvm/params.h>
 #include <xen/interface/vcpu.h>
@@ -97,6 +100,11 @@ extern void pmap_lazyfix_action(void);
 /* Variables used by mp_machdep to perform the bitmap IPI */
 extern volatile u_int cpu_ipi_pending[MAXCPU];
 
+#ifdef __amd64__
+/* Native AP start used on PVHVM */
+extern int native_start_all_aps(void);
+#endif
+
 /*---------------------------------- Macros ----------------------------------*/
 #define	IPI_TO_IDX(ipi) ((ipi) - APIC_IPI_INTS)
 
@@ -119,7 +127,10 @@ enum xen_domain_type xen_domain_type = XEN_NATIVE;
 struct cpu_ops xen_hvm_cpu_ops = {
 	.ipi_vectored	= lapic_ipi_vectored,
 	.cpu_init	= xen_hvm_cpu_init,
-	.cpu_resume	= xen_hvm_cpu_resume
+	.cpu_resume	= xen_hvm_cpu_resume,
+#ifdef __amd64__
+	.start_all_aps = native_start_all_aps,
+#endif
 };
 
 static MALLOC_DEFINE(M_XENHVM, "xen_hvm", "Xen HVM PV Support");
@@ -698,6 +709,10 @@ xen_hvm_init(enum xen_hvm_init_type init_type)
 		setup_xen_features();
 		cpu_ops = xen_hvm_cpu_ops;
  		vm_guest = VM_GUEST_XEN;
+#ifdef __amd64__
+		if (xen_pv_domain())
+			cpu_ops.start_all_aps = xen_pv_start_all_aps;
+#endif
 		break;
 	case XEN_HVM_INIT_RESUME:
 		if (error != 0)
sys/x86/xen/pv.c +37 -0
index db576e0..7e45a83 100644
@@ -34,21 +34,43 @@ __FBSDID("$FreeBSD$");
 #include <sys/kernel.h>
 #include <sys/reboot.h>
 #include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/smp.h>
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
+#include <vm/vm_extern.h>
+#include <vm/vm_kern.h>
 
 #include <machine/sysarch.h>
 #include <machine/clock.h>
 #include <machine/pc/bios.h>
+#include <machine/smp.h>
 
 #include <xen/xen-os.h>
 #include <xen/pv.h>
 #include <xen/hypervisor.h>
 
+#include <xen/interface/vcpu.h>
+
 #define MAX_E820_ENTRIES	128
 
 /*--------------------------- Forward Declarations ---------------------------*/
 static caddr_t xen_pv_parse_preload_data(u_int64_t);
 static void xen_pv_parse_memmap(caddr_t, vm_paddr_t *, int *);
 
+/*---------------------------- Extern Declarations ---------------------------*/
+/* Variables used by amd64 mp_machdep to start APs */
+extern struct mtx ap_boot_mtx;
+extern void *bootstacks[];
+extern char *doublefault_stack;
+extern char *nmi_stack;
+extern void *dpcpu;
+extern int bootAP;
+extern char *bootSTK;
+
 /*-------------------------------- Global Data -------------------------------*/
 /* Xen init_ops implementation. */
 struct init_ops xen_init_ops = {
@@ -78,6 +100,74 @@ static struct
 
 static struct bios_smap xen_smap[MAX_E820_ENTRIES];
 
+static int
+start_xen_ap(int cpu)
+{
+	struct vcpu_guest_context *ctxt;
+	int ms, cpus = mp_naps;
+
+	ctxt = malloc(sizeof(*ctxt), M_TEMP, M_NOWAIT | M_ZERO);
+	if (ctxt == NULL)
+		panic("unable to allocate memory");
+
+	ctxt->flags = VGCF_IN_KERNEL;
+	ctxt->user_regs.rip = (unsigned long) init_secondary;
+	ctxt->user_regs.rsp = (unsigned long) bootSTK;
+
+	/* Set the AP to use the same page tables */

sys/x86/xen/pv.c static struct · line 127

Quoted 10 lines
sys/x86/xen/pv.c +10 -0
+	ctxt->ctrlreg[3] = KPML4phys;
+
+	if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt))
+		panic("unable to initialize AP#%d\n", cpu);
+
+	free(ctxt, M_TEMP);
+
+	/* Launch the vCPU */
+	if (HYPERVISOR_vcpu_op(VCPUOP_up, cpu, NULL))
+		panic("unable to start AP#%d\n", cpu);

Why the panic? Why not just return 0 (which I presume would mean we failed to init the CPU?)

sys/x86/xen/pv.c static struct · line 135

Quoted 8 lines
sys/x86/xen/pv.c +8 -0
+
+	/* Wait up to 5 seconds for it to start. */
+	for (ms = 0; ms < 5000; ms++) {
+		if (mp_naps > cpus)
+			return (1);	/* return SUCCESS */
+		DELAY(1000);
+	}
+

Wow. So much simpler than the PV path.

sys/x86/xen/pv.c static struct · line 136

Quoted 1 line
sys/x86/xen/pv.c +1 -0
+	return (0);

There isn't a doorbell mechanism for the booted processor to tell the BSP it is up?

Quoted 56 lines
sys/x86/xen/pv.c +34 -0
+}
+
+int
+xen_pv_start_all_aps(void)
+{
+	int cpu;
+
+	mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN);
+
+	for (cpu = 1; cpu < mp_ncpus; cpu++) {
+
+		/* allocate and set up an idle stack data page */
+		bootstacks[cpu] = (void *)kmem_malloc(kernel_arena,
+		    KSTACK_PAGES * PAGE_SIZE, M_WAITOK | M_ZERO);
+		doublefault_stack = (char *)kmem_malloc(kernel_arena,
+		    PAGE_SIZE, M_WAITOK | M_ZERO);
+		nmi_stack = (char *)kmem_malloc(kernel_arena, PAGE_SIZE,
+		    M_WAITOK | M_ZERO);
+		dpcpu = (void *)kmem_malloc(kernel_arena, DPCPU_SIZE,
+		    M_WAITOK | M_ZERO);
+
+		bootSTK = (char *)bootstacks[cpu] + KSTACK_PAGES * PAGE_SIZE - 8;
+		bootAP = cpu;
+
+		/* attempt to start the Application Processor */
+		if (!start_xen_ap(cpu))
+			panic("AP #%d failed to start!", cpu);
+
+		CPU_SET(cpu, &all_cpus);	/* record AP in CPU map */
+	}
+
+	return (mp_naps);
+}
+
 /*
  * Functions to convert the "extra" parameters passed by Xen
  * into FreeBSD boot options (from the i386 Xen port).
sys/xen/pv.h +1 -0
index 71b8776..60d9def 100644
@@ -24,5 +24,6 @@
 #define	__XEN_PV_H__
 
 void	xen_pv_set_init_ops(void);
+int	xen_pv_start_all_aps(void);
 
 #endif	/* __XEN_PV_H__ */
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#51 lore raw

Re: [PATCH v7 13/19] xen: introduce flag to disable the local apic

Quoted 1 line · Roger Pau Monne

PVH guests don't have an emulated lapic.

Since the tests all use '!lapic_disabled' I think I would prefer to flip the name to 'lapic_valid' and have it default to true. It would just be a cosmetic change to the current patch, but I think it is more readable long- term.

Signature · 1 line
John Baldwin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#53 lore raw

Re: [PATCH v7 14/19] xen: introduce a dummy pvcpu device

Quoted 2 lines · Roger Pau Monne

Since Xen PVH guests doesn't have ACPI, we need to create a dummy pvcpu device that will be used to fill the pcpu->pc_device field.

Rather than have this hang directly off of nexus0, it might be better to create some sort of 'xenov0' device that takes the place of acpi0 and have the CPUs hang off of that. This is how the non-ACPI case works in the native case where the default nexus creates a 'legacy0' device that sits at the same spot in the device tree as acpi0. In sys/x86/legacy.c we create CPU devices that are a child of legacy0.

In general the way the native code handes ACPI vs non-ACPI is to have a different nexus (as you've adopted) create a specific child bus (acpi0 vs legacy0). Drivers that want to only attach in one of the cases at the top- level then attach as children of those rather than children of 'nexus0'. This just adds an extra layer of protection to avoid the possibility of a top-level driver that is ACPI or non-ACPI specific being probed in the "wrong" case. Right now, all drivers that attach to 'nexus' aside from the top-level busses (acpi0 vs legacy0) are intended to work on any machine.

I think the CPU driver itself looks fine, I would just encourage you to consider a xenpv0 device and to move anything PV specific to hang off of that rather than directly attaching to nexus0.

Signature · 1 line
John Baldwin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#55 lore raw

Re: [PATCH v7 16/19] xen: add shutdown hook for PVH

Quoted 4 lines · Roger Pau Monne

Add the PV shutdown hook to PVH.

---
 sys/dev/xen/control/control.c |   37 ++++++++++++++++++-------------------
 1 files changed, 18 insertions(+), 19 deletions(-)

This looks fine to me.

Signature · 1 line
John Baldwin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#57 lore raw

Re: [PATCH v7 17/19] xen: xenstore changes to support PVH

Quoted 3 lines · Roger Pau Monne
---
 sys/xen/xenstore/xenstore.c |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)

This looks fine modulo possibly making it a xenpv child instead of a nexus child.

Note that even in the old XEN code in FreeBSD I would argue that attaching directly to nexus is wrong and that even the old XEN code should create some sort of top-level device below nexus0 that is XEN-specific for XEN- specific drivers to attach to. I've no idea what shape the old XEN-specific code is in or if it can be tested, but I'd really like PVH to do the right thing if at all possible.

Quoted 42 lines
sys/xen/xenstore/xenstore.c +9 -9
index bcf6357..2893c84 100644
@@ -229,13 +229,11 @@ struct xs_softc {
 	 */
 	struct sx xenwatch_mutex;
 
-#ifdef XENHVM
 	/**
 	 * The HVM guest pseudo-physical frame number.  This is Xen's mapping
 	 * of the true machine frame number into our "physical address space".
 	 */
 	unsigned long gpfn;
-#endif
 
 	/**
 	 * The event channel for communicating with the
@@ -1141,13 +1139,15 @@ xs_attach(device_t dev)
 	/* Initialize the interface to xenstore. */
 	struct proc *p;
 
-#ifdef XENHVM
-	xs.evtchn = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN);
-	xs.gpfn = hvm_get_parameter(HVM_PARAM_STORE_PFN);
-	xen_store = pmap_mapdev(xs.gpfn * PAGE_SIZE, PAGE_SIZE);
-#else
-	xs.evtchn = xen_start_info->store_evtchn;
-#endif
+	if (xen_hvm_domain()) {
+		xs.evtchn = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN);
+		xs.gpfn = hvm_get_parameter(HVM_PARAM_STORE_PFN);
+		xen_store = pmap_mapdev(xs.gpfn * PAGE_SIZE, PAGE_SIZE);
+	} else if (xen_pv_domain()) {
+		xs.evtchn = HYPERVISOR_start_info->store_evtchn;
+	} else {
+		panic("Unknown domain type, cannot initialize xenstore\n");
+	}
 
 	TAILQ_INIT(&xs.reply_list);
 	TAILQ_INIT(&xs.watch_events);

sys/xen/xenstore/xenstore.c static devclass_t xenstore_devclass; · line 1262

Quoted 9 lines
sys/xen/xenstore/xenstore.c +1 -2
@@ -1256,9 +1256,8 @@ static devclass_t xenstore_devclass;
 
 #ifdef XENHVM
 DRIVER_MODULE(xenstore, xenpci, xenstore_driver, xenstore_devclass, 0, 0);
-#else
-DRIVER_MODULE(xenstore, nexus, xenstore_driver, xenstore_devclass, 0, 0);
 #endif
+DRIVER_MODULE(xenstore, nexus, xenstore_driver, xenstore_devclass, 0, 0);
 
 /*------------------------------- Sysctl Data 

--------------------------------*/

Quoted 5 lines
sys/xen/xenstore/xenstore.c +0 -0
 /* XXX Shouldn't the node be somewhere else? */
Signature · 1 line
1.7.7.5 (Apple Git-26)
Signature · 1 line
John Baldwin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#59 lore raw

Re: [PATCH v7 18/19] xen: changes to gnttab for PVH

Quoted 3 lines · Roger Pau Monne
---
 sys/xen/gnttab.c |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)

I can't really speak to the correctness of this as I don't know the Xen internals well enough, but I don't see anything that looks wrong. :)

Signature · 1 line
John Baldwin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#61 lore raw

Re: [PATCH v7 19/19] isa: allow ISA bus to attach to the nexus

Quoted 3 lines · Roger Pau Monne
---
 sys/x86/isa/isa.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

If you go the xenpv route, you would replace 'nexus' with 'xenpv' here.

sys/x86/isa/isa.c isa_release_resource(device_t bus, device_t child, int

Quoted 5 lines
sys/x86/isa/isa.c +0 -0
index 1a57137..09d1ab7 100644
@@ -241,3 +241,6 @@ isa_release_resource(device_t bus, device_t child, int 

type, int rid,

Quoted 10 lines
sys/x86/isa/isa.c +3 -0
  * On this platform, isa can also attach to the legacy bus.
  */
 DRIVER_MODULE(isa, legacy, isa_driver, isa_devclass, 0, 0);
+#ifdef XENHVM
+DRIVER_MODULE(isa, nexus, isa_driver, isa_devclass, 0, 0);
+#endif
Signature · 1 line
1.7.7.5 (Apple Git-26)
Signature · 1 line
John Baldwin