Re: buildworld fails with Zero byte read from file, skipping rest of line

2014-01-14 Thread Gleb Smirnoff
  Jeremie,

On Tue, Jan 14, 2014 at 08:26:21AM +0100, Jeremie Le Hen wrote:
J Hi,
J 
J I have a FreeBSD -CURRENT in Virtualbox (running on Linux).  I have been
J unable to buildworld for a while.
J 
J I suspect this is not a problem with the source because I didn't see any
J report so far, whereas I've been experiencing this for a month or more.
J Thus I naturally suspected it was a binary problem, so I've upgraded
J to the latest snapshot, but the problem still exists.
J 
J   === gnu/usr.bin/groff/src/libs/libgroff (all)
J   make[6]: 
/usr/obj/usr/src.svn/tmp/usr/src.svn/gnu/usr.bin/groff/src/libs/libgroff/.depend
 line 3: warning: Zero byte read from file, skipping rest of line.
J   make[6]: 
/usr/obj/usr/src.svn/tmp/usr/src.svn/gnu/usr.bin/groff/src/libs/libgroff/.depend
 line 3: Need an operator
J   make[6]: 
/usr/obj/usr/src.svn/tmp/usr/src.svn/gnu/usr.bin/groff/src/libs/libgroff/.depend
 line 4: Need an operator
J   make[6]: Fatal errors encountered -- cannot continue
J   make[6]: stopped in /usr/src.svn/gnu/usr.bin/groff/src/libs/libgroff
J   *** [all] Error code 1
J 
J Typscript available here:
J http://people.freebsd.org/~jlh/typescript.buildworld.txt
J 
J Any ideas?

Can you try to reproduce this with unmapped I/O turned off in boot loader?

-- 
Totus tuus, Glebius.
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


mtree acl support

2014-01-14 Thread Mark Felder
I was recently talking to someone about how one would backup / restore
ACLs reliably. I didn't see any mention of ACLs in the mtree man page
and after a quick google I came upon this old mailing list post:

http://lists.freebsd.org/pipermail/freebsd-hackers/2008-April/024173.html

patch in list is here: http://heka.cenkes.org/sat/diffs/mtree_acl.diff
I've mirrored it here: https://feld.me/freebsd/mtree_acl.diff

This old patch appears to still apply cleanly. I hate to see a patch die
and be forgotten.
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


[PATCH v10 05/20] xen: rework xen timer so it can be used early in boot process

2014-01-14 Thread 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.
---
 sys/dev/xen/timer/timer.c |   29 -
 1 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/sys/dev/xen/timer/timer.c b/sys/dev/xen/timer/timer.c
index 354085b..b2f6bcd 100644
--- a/sys/dev/xen/timer/timer.c
+++ b/sys/dev/xen/timer/timer.c
@@ -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);
 
-- 
1.7.7.5 (Apple Git-26)

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


[PATCH v10 02/20] xen: add macro to detect if running as Dom0

2014-01-14 Thread Roger Pau Monne
---
 sys/xen/xen-os.h |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/sys/xen/xen-os.h b/sys/xen/xen-os.h
index c7474d8..e8a5a99 100644
--- a/sys/xen/xen-os.h
+++ b/sys/xen/xen-os.h
@@ -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
-- 
1.7.7.5 (Apple Git-26)

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


[PATCH v10 07/20] xen: implement hook to fetch e820 memory map

2014-01-14 Thread 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|   25 +
 4 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index b8d6dc2..64df89a 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -169,11 +169,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,
 };
 
 /*
@@ -1403,21 +1407,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++) {
@@ -1434,6 +1429,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
@@ -1451,19 +1469,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
diff --git a/sys/amd64/include/pc/bios.h b/sys/amd64/include/pc/bios.h
index e7d568e..95ef703 100644
--- a/sys/amd64/include/pc/bios.h
+++ b/sys/amd64/include/pc/bios.h
@@ -106,6 +106,8 @@ struct bios_oem {
 intbios_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_ */
diff --git a/sys/amd64/include/sysarch.h b/sys/amd64/include/sysarch.h
index 60fa635..084223e 100644
--- a/sys/amd64/include/sysarch.h
+++ b/sys/amd64/include/sysarch.h
@@ -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;
diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c
index 0ec4b54..d11bc1a 100644
--- a/sys/x86/xen/pv.c
+++ b/sys/x86/xen/pv.c
@@ -48,6 +48,7 @@ __FBSDID($FreeBSD$);
 
 #include machine/sysarch.h
 #include machine/clock.h
+#include machine/pc/bios.h
 
 #include xen/xen-os.h
 #include xen/hypervisor.h
@@ -57,8 +58,11 @@ extern u_int64_t hammer_time(u_int64_t, u_int64_t);
 /* Xen initial function */
 extern u_int64_t hammer_time_xen(start_info_t *, u_int64_t);
 
+#define 

[PATCH v10 06/20] xen: implement an early timer for Xen PVH

2014-01-14 Thread 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.
---
 sys/amd64/amd64/machdep.c   |6 ++-
 sys/amd64/include/clock.h   |5 ++
 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/include/clock.h|5 ++
 sys/x86/isa/clock.c |   53 +
 sys/x86/x86/delay.c |  112 +++
 sys/x86/xen/pv.c|3 +
 10 files changed, 167 insertions(+), 54 deletions(-)
 create mode 100644 sys/x86/x86/delay.c

diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index 343f9b8..b8d6dc2 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -172,6 +172,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,
 };
 
 /*
@@ -1822,10 +1824,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.
diff --git a/sys/amd64/include/clock.h b/sys/amd64/include/clock.h
index d7f7d82..ac8818f 100644
--- a/sys/amd64/include/clock.h
+++ b/sys/amd64/include/clock.h
@@ -25,6 +25,11 @@ 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
 
 /*
  * Driver to clock driver interface.
diff --git a/sys/amd64/include/sysarch.h b/sys/amd64/include/sysarch.h
index 58ac8cd..60fa635 100644
--- a/sys/amd64/include/sysarch.h
+++ b/sys/amd64/include/sysarch.h
@@ -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;
diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64
index 16029d8..109a796 100644
--- a/sys/conf/files.amd64
+++ b/sys/conf/files.amd64
@@ -565,6 +565,7 @@ x86/x86/mptable_pci.c   optionalmptable 
pci
 x86/x86/msi.c  optionalpci
 x86/x86/nexus.cstandard
 x86/x86/tsc.c  standard
+x86/x86/delay.cstandard
 x86/xen/hvm.c  optionalxenhvm
 x86/xen/xen_intr.c optionalxen | xenhvm
 x86/xen/pv.c   optionalxenhvm
diff --git a/sys/conf/files.i386 b/sys/conf/files.i386
index eb8697c..790296d 100644
--- a/sys/conf/files.i386
+++ b/sys/conf/files.i386
@@ -600,5 +600,6 @@ x86/x86/mptable_pci.c   optional apic native pci
 x86/x86/msi.c  optional apic pci
 x86/x86/nexus.cstandard
 x86/x86/tsc.c  standard
+x86/x86/delay.cstandard
 x86/xen/hvm.c  optional xenhvm
 x86/xen/xen_intr.c optional xen | xenhvm
diff --git a/sys/dev/xen/timer/timer.c b/sys/dev/xen/timer/timer.c
index b2f6bcd..96372ab 100644
--- a/sys/dev/xen/timer/timer.c
+++ b/sys/dev/xen/timer/timer.c
@@ -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),
diff --git a/sys/i386/include/clock.h b/sys/i386/include/clock.h

[PATCH v10 01/20] xen: add PV/PVH kernel entry point

2014-01-14 Thread Roger Pau Monne
Add the PV/PVH entry point and the low level functions for PVH
initialization.
---
 sys/amd64/amd64/locore.S |1 +
 sys/amd64/amd64/xen-locore.S |   83 +
 sys/amd64/include/asmacros.h |   26 +
 sys/conf/files.amd64 |2 +
 sys/i386/xen/xen_machdep.c   |2 +
 sys/x86/xen/hvm.c|1 +
 sys/x86/xen/pv.c |  119 ++
 sys/xen/xen-os.h |4 ++
 8 files changed, 238 insertions(+), 0 deletions(-)
 create mode 100644 sys/amd64/amd64/xen-locore.S
 create mode 100644 sys/x86/xen/pv.c

diff --git a/sys/amd64/amd64/locore.S b/sys/amd64/amd64/locore.S
index 55cda3a..4acef97 100644
--- a/sys/amd64/amd64/locore.S
+++ b/sys/amd64/amd64/locore.S
@@ -84,5 +84,6 @@ NON_GPROF_ENTRY(btext)
 
.bss
ALIGN_DATA  /* just to be sure */
+   .globl  bootstack
.space  0x1000  /* space for bootstack - temporary 
stack */
 bootstack:
diff --git a/sys/amd64/amd64/xen-locore.S b/sys/amd64/amd64/xen-locore.S
new file mode 100644
index 000..84287c4
--- /dev/null
+++ b/sys/amd64/amd64/xen-locore.S
@@ -0,0 +1,83 @@
+/*-
+ * Copyright (c) 2003 Peter Wemm pe...@freebsd.org
+ * Copyright (c) 2013 Roger Pau Monne roy...@freebsd.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include machine/asmacros.h
+#include machine/psl.h
+#include machine/pmap.h
+#include machine/specialreg.h
+
+#include xen/xen-os.h
+#define __ASSEMBLY__
+#include xen/interface/elfnote.h
+
+#include assym.s
+
+.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 nops */
+
+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); */
+   callhammer_time_xen
+   movq%rax, %rsp  /* set up kstack for mi_startup() */
+   callmi_startup  /* autoconfiguration, mountroot etc */
+
+   /* NOTREACHED */
+0: hlt
+   jmp 0b
diff --git a/sys/amd64/include/asmacros.h b/sys/amd64/include/asmacros.h
index 1fb592a..ce8dce4 100644

[PATCH v10 00/20] FreeBSD PVH DomU support

2014-01-14 Thread Roger Pau Monne
This series is a split of the previous patch Xen x86 DomU PVH 
support, with the aim to make the review of the code easier.

The series can also be found on my git repo:

git://xenbits.xen.org/people/royger/freebsd.git pvh_v10

or

http://xenbits.xen.org/gitweb/?p=people/royger/freebsd.git;a=shortlog;h=refs/heads/pvh_v10

PVH mode is basically a PV guest inside an HVM container, and shares
a great amount of code with PVHVM. The main difference is the way the
guest is started, PVH uses the PV start sequence, jumping directly
into the kernel entry point in long mode and with page tables set.
The main work of this patch consists in setting the environment as
similar as possible to what native FreeBSD expects, and then adding
hooks to the PV ops when necessary.

This new version of the series (v10) addresses the comments from the 
previous posted version (v9). Major changes between v9 and v10:

 * Add a identify routine to xenpv instead of attaching it manually 
   from the Xen nexus.
 * Remove bus routines from xenpci (devices are now attached to xenpv 
   instead).
 * Add __printflike modifier to xc_printf.
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


[PATCH v10 03/20] xen: add and enable Xen console for PVH guests

2014-01-14 Thread Roger Pau Monne
This adds and enables the console used on XEN kernels.
---
 sys/conf/files |4 +-
 sys/dev/xen/console/console.c  |   37 +--
 sys/dev/xen/console/xencons_ring.c |   15 +
 sys/i386/include/xen/xen-os.h  |1 -
 sys/i386/xen/xen_machdep.c |   17 
 sys/x86/xen/pv.c   |4 +++
 sys/xen/xen-os.h   |4 +++
 7 files changed, 50 insertions(+), 32 deletions(-)

diff --git a/sys/conf/files b/sys/conf/files
index 33fc75d..bddf021 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -2493,8 +2493,8 @@ dev/xe/if_xe_pccard.c optional xe pccard
 dev/xen/balloon/balloon.c  optional xen | xenhvm
 dev/xen/blkfront/blkfront.coptional 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.coptional xen | xenhvm
diff --git a/sys/dev/xen/console/console.c b/sys/dev/xen/console/console.c
index 23eaee2..899dffc 100644
--- a/sys/dev/xen/console/console.c
+++ b/sys/dev/xen/console/console.c
@@ -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;
 
+/* Virtual address of the shared console page */
+char *console_page;
+
 #ifdef KDB
 static int xc_altbrk;
 #endif
@@ -110,9 +113,26 @@ static struct ttydevsw xc_ttydevsw = {
 .tsw_outwakeup = xcoutwakeup,
 };
 
+/*- Debug function 
---*/
+#define XC_PRINTF_BUFSIZE 1024
+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));
+}
+
 static void
 xc_cnprobe(struct consdev *cp)
 {
+   if (!xen_pv_domain())
+   return;
+
cp-cn_pri = CN_REMOTE;
sprintf(cp-cn_name, %s0, driver_name);
 }
@@ -175,7 +195,7 @@ static void
 xc_cnputc(struct consdev *dev, int c)
 {
 
-   if (xen_start_info-flags  SIF_INITDOMAIN)
+   if (xen_initial_domain())
xc_cnputc_dom0(dev, c);
else
xc_cnputc_domu(dev, c);
@@ -206,8 +226,7 @@ xcons_putc(int c)
xcons_force_flush();
 #endif 
}
-   if (cnsl_evt_reg)
-   __xencons_tx_flush();
+   __xencons_tx_flush();

/* inform start path that we're pretty full */
return ((wp - wc) = WBUF_SIZE - 100) ? TRUE : FALSE;
@@ -217,6 +236,10 @@ static void
 xc_identify(driver_t *driver, device_t parent)
 {
device_t child;
+
+   if (!xen_pv_domain())
+   return;
+
child = BUS_ADD_CHILD(parent, 0, driver_name, 0);
device_set_driver(child, driver);
device_set_desc(child, Xen Console);
@@ -245,7 +268,7 @@ xc_attach(device_t dev)
cnsl_evt_reg = 1;
callout_reset(xc_callout, XC_POLLTIME, xc_timeout, xccons);
 
-   if (xen_start_info-flags  SIF_INITDOMAIN) {
+   if (xen_initial_domain()) {
error = xen_intr_bind_virq(dev, VIRQ_CONSOLE, 0, NULL,
   xencons_priv_interrupt, NULL,
   INTR_TYPE_TTY, xen_intr_handle);
@@ -309,7 +332,7 @@ __xencons_tx_flush(void)
sz = wp - wc;
if (sz  (WBUF_SIZE - WBUF_MASK(wc)))
sz = WBUF_SIZE - WBUF_MASK(wc);
-   if (xen_start_info-flags  SIF_INITDOMAIN) {
+   if (xen_initial_domain()) {
HYPERVISOR_console_io(CONSOLEIO_write, sz, 
wbuf[WBUF_MASK(wc)]);
wc += sz;
} else {
@@ -424,7 +447,7 @@ xcons_force_flush(void)
 {
intsz;
 
-   if (xen_start_info-flags  SIF_INITDOMAIN)
+   if (xen_initial_domain())
return;
 
/* Spin until console data is flushed through to the domain controller. 
*/
diff --git a/sys/dev/xen/console/xencons_ring.c 
b/sys/dev/xen/console/xencons_ring.c
index 3701551..d826363 100644
--- a/sys/dev/xen/console/xencons_ring.c
+++ b/sys/dev/xen/console/xencons_ring.c
@@ -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 

[PATCH v10 08/20] xen: use the same hypercall mechanism for XEN and XENHVM

2014-01-14 Thread 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(-)

diff --git a/sys/amd64/include/xen/hypercall.h 
b/sys/amd64/include/xen/hypercall.h
index a1b2a5c..499fb4d 100644
--- a/sys/amd64/include/xen/hypercall.h
+++ b/sys/amd64/include/xen/hypercall.h
@@ -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)\
 ({ \
diff --git a/sys/i386/i386/locore.s b/sys/i386/i386/locore.s
index 68cb430..bd136b1 100644
--- a/sys/i386/i386/locore.s
+++ b/sys/i386/i386/locore.s
@@ -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 nops */
+#endif
diff --git a/sys/i386/include/xen/hypercall.h b/sys/i386/include/xen/hypercall.h
index edc13f4..16b5ee2 100644
--- a/sys/i386/include/xen/hypercall.h
+++ b/sys/i386/include/xen/hypercall.h
@@ -39,16 +39,8 @@
 #defineENOXENSYS   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) \
 ({  \
diff --git a/sys/x86/xen/hvm.c b/sys/x86/xen/hvm.c
index b397721..9a0411e 100644
--- a/sys/x86/xen/hvm.c
+++ b/sys/x86/xen/hvm.c
@@ -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]  0x);
@@ -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:
-- 
1.7.7.5 (Apple Git-26)

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


[PATCH v10 09/20] xen: add a apic_enumerator for PVH

2014-01-14 Thread Roger Pau Monne
---
 sys/conf/files.amd64 |1 +
 sys/x86/xen/pvcpu_enum.c |  136 ++
 2 files changed, 137 insertions(+), 0 deletions(-)
 create mode 100644 sys/x86/xen/pvcpu_enum.c

diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64
index 109a796..a3491da 100644
--- a/sys/conf/files.amd64
+++ b/sys/conf/files.amd64
@@ -569,3 +569,4 @@ x86/x86/delay.c standard
 x86/xen/hvm.c  optionalxenhvm
 x86/xen/xen_intr.c optionalxen | xenhvm
 x86/xen/pv.c   optionalxenhvm
+x86/xen/pvcpu_enum.c   optionalxenhvm
diff --git a/sys/x86/xen/pvcpu_enum.c b/sys/x86/xen/pvcpu_enum.c
new file mode 100644
index 000..0384886
--- /dev/null
+++ b/sys/x86/xen/pvcpu_enum.c
@@ -0,0 +1,136 @@
+/*-
+ * Copyright (c) 2003 John Baldwin j...@freebsd.org
+ * Copyright (c) 2013 Roger Pau Monné roger@citrix.com
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of any co-contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+__FBSDID($FreeBSD$);
+
+#include sys/param.h
+#include sys/systm.h
+#include sys/bus.h
+#include sys/kernel.h
+#include sys/smp.h
+#include sys/pcpu.h
+#include vm/vm.h
+#include vm/pmap.h
+
+#include machine/intr_machdep.h
+#include machine/apicvar.h
+
+#include machine/cpu.h
+#include machine/smp.h
+
+#include xen/xen-os.h
+#include xen/hypervisor.h
+
+#include xen/interface/vcpu.h
+
+static int xenpv_probe(void);
+static int xenpv_probe_cpus(void);
+static int xenpv_setup_local(void);
+static int xenpv_setup_io(void);
+
+static struct apic_enumerator xenpv_enumerator = {
+   Xen PV,
+   xenpv_probe,
+   xenpv_probe_cpus,
+   xenpv_setup_local,
+   xenpv_setup_io
+};
+
+/*
+ * This enumerator will only be registered on PVH
+ */
+static int
+xenpv_probe(void)
+{
+   return (-100);
+}
+
+/*
+ * Test each possible vCPU in order to find the number of vCPUs
+ */
+static int
+xenpv_probe_cpus(void)
+{
+#ifdef SMP
+   int i, ret;
+
+   for (i = 0; i  MAXCPU; i++) {
+   ret = HYPERVISOR_vcpu_op(VCPUOP_is_up, i, NULL);
+   if (ret = 0)
+   cpu_add((i * 2), (i == 0));
+   }
+#endif
+   return (0);
+}
+
+/*
+ * Initialize the vCPU id of the BSP
+ */
+static int
+xenpv_setup_local(void)
+{
+   PCPU_SET(vcpu_id, 0);
+   return (0);
+}
+
+/*
+ * On PVH guests there's no IO APIC
+ */
+static int
+xenpv_setup_io(void)
+{
+   return (0);
+}
+
+static void
+xenpv_register(void *dummy __unused)
+{
+   if (xen_pv_domain()) {
+   apic_register_enumerator(xenpv_enumerator);
+   }
+}
+SYSINIT(xenpv_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST, xenpv_register, 
NULL);
+
+/*
+ * Setup per-CPU vCPU IDs
+ */
+static void
+xenpv_set_ids(void *dummy)
+{
+   struct pcpu *pc;
+   int i;
+
+   CPU_FOREACH(i) {
+   pc = pcpu_find(i);
+   pc-pc_vcpu_id = i;
+   }
+}
+SYSINIT(xenpv_set_ids, SI_SUB_CPU, SI_ORDER_MIDDLE, xenpv_set_ids, NULL);
-- 
1.7.7.5 (Apple Git-26)

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org

[PATCH v10 04/20] amd64: introduce hook for custom preload metadata parsers

2014-01-14 Thread Roger Pau Monne
---
 sys/amd64/amd64/machdep.c   |   41 --
 sys/amd64/include/sysarch.h |   12 ++
 sys/x86/xen/pv.c|   82 +++
 3 files changed, 124 insertions(+), 11 deletions(-)

diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index f0d4ea8..343f9b8 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -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
@@ -165,6 +166,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.
@@ -1685,6 +1694,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);
+}
+
 u_int64_t
 hammer_time(u_int64_t modulep, u_int64_t physfree)
 {
@@ -1709,17 +1738,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();
diff --git a/sys/amd64/include/sysarch.h b/sys/amd64/include/sysarch.h
index cd380d4..58ac8cd 100644
--- a/sys/amd64/include/sysarch.h
+++ b/sys/amd64/include/sysarch.h
@@ -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;
diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c
index db3b7a3..908b50b 100644
--- a/sys/x86/xen/pv.c
+++ b/sys/x86/xen/pv.c
@@ -46,6 +46,8 @@ __FBSDID($FreeBSD$);
 #include vm/vm_pager.h
 #include vm/vm_param.h
 
+#include machine/sysarch.h
+
 #include xen/xen-os.h
 #include xen/hypervisor.h
 
@@ -54,6 +56,36 @@ extern u_int64_t hammer_time(u_int64_t, u_int64_t);
 /* Xen initial function */
 extern u_int64_t hammer_time_xen(start_info_t *, u_int64_t);
 
+/*--- Forward Declarations 
---*/
+static caddr_t xen_pv_parse_preload_data(u_int64_t);
+
+static void xen_pv_set_init_ops(void);
+
+/* Global Data 
---*/
+/* Xen init_ops implementation. */
+struct init_ops xen_init_ops = {
+   .parse_preload_data =   xen_pv_parse_preload_data,
+};
+
+static struct
+{
+   const char  *ev;
+   int mask;
+} howto_names[] = {
+   {boot_askname,RB_ASKNAME},
+   {boot_single, RB_SINGLE},
+   {boot_nosync, RB_NOSYNC},
+   {boot_halt,   RB_ASKNAME},
+   {boot_serial, RB_SERIAL},
+   {boot_cdrom,  RB_CDROM},
+   {boot_gdb,RB_GDB},
+   {boot_gdb_pause,  RB_RESERVED1},
+   {boot_verbose,RB_VERBOSE},
+   {boot_multicons,  RB_MULTIPLE},
+   {NULL,  0}
+};
+
+/* Xen PV init 
---*/
 /*
  * First function called by the Xen PVH boot sequence.
  *
@@ -118,6 +150,56 @@ hammer_time_xen(start_info_t *si, u_int64_t xenstack)
}
load_cr3(((u_int64_t)PT4[0]) - 

Shared IRQ on ATOM based Soekris net6501 board

2014-01-14 Thread Christophe Prevotaux

I have found out that when I use 2 AR9580 mini PCIe board
some irq (namely in that case irq18 is shared over 3 devices)

I wonder why it is done like this and if this could be something to fix ? 

Kernel is 30/12/2014 CURRENT ( FreeBSD/amd64) with :

options mptable


vmstat -i
interrupt  total   rate
irq4: uart0 1006  0
irq17: ath0 12857761   2078
irq18: ath1++   11204038   1811
cpu0:timer   5775445933
irq256: ahci0   3761  0
irq257: em0:rx 0   43769  7
irq258: em0:tx 06667  1
irq259: em0:link   2  0
irq260: em1:rx 06157  0
irq261: em1:tx 0  46  0
irq262: em1:link   2  0
irq263: em2:rx 0   21929  3
irq264: em2:tx 0   17803  2
irq265: em2:link   4  0
irq266: em3:rx 012326978   1992
irq267: em3:tx 013653018   2207
irq268: em3:link  11  0
cpu1:timer   5734729927
Total   61653126   9966


ACPI BIOS Error (bug): A valid RSDP was not found (20130823/tbxfroot-223)
Copyright (c) 1992-2013 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 11.0-CURRENT #1: Wed Jan  8 20:42:57 EST 2014
root@ap01:/usr/obj/usr/src/sys/NET6501 amd64
FreeBSD clang version 3.3 (tags/RELEASE_33/final 183502) 20130610
CPU: Genuine Intel(R) CPU@  600MHz (600.01-MHz K8-class CPU)
  Origin = GenuineIntel  Id = 0x20661  Family = 0x6  Model = 0x26  Stepping = 
1
  
Features=0xbfe9fbffFPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE
  
Features2=0x40e3bdSSE3,DTES64,MON,DS_CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,MOVBE
  AMD Features=0x20100800SYSCALL,NX,LM
  AMD Features2=0x1LAHF
  TSC: P-state invariant, performance statistics
real memory  = 536739840 (511 MB)
avail memory = 496316416 (473 MB)
MPTable: Soekris  net6501 
Event timer LAPIC quality 400
FreeBSD/SMP: Multiprocessor System Detected: 2 CPUs
FreeBSD/SMP: 1 package(s) x 1 core(s) x 2 HTT threads
 cpu0 (BSP): APIC ID:  0
 cpu1 (AP/HT): APIC ID:  1
ioapic0: Assuming intbase of 0
ioapic0 Version 2.0 irqs 0-23 on motherboard
random: Software, Yarrow initialized
kbd0 at kbdmux0
module_register_init: MOD_LOAD (vesa, 0x80ab3c10, 0) error 19
ACPI BIOS Error (bug): A valid RSDP was not found (20130823/tbxfroot-223)
ACPI: Table initialisation failed: AE_NOT_FOUND
ACPI: Try disabling either ACPI or apic support.
pcib0: MPTable Host-PCI bridge pcibus 0 on motherboard
pci0: PCI bus on pcib0
pcib1: PCI-PCI bridge irq 16 at device 23.0 on pci0
pci1: PCI bus on pcib1
pcib2: PCI-PCI bridge irq 16 at device 0.0 on pci1
pci2: PCI bus on pcib2
pci2: unknown at device 0.0 (no driver attached)
pci2: network, ethernet at device 0.1 (no driver attached)
pci2: unknown at device 0.2 (no driver attached)
ohci0: OHCI (generic) USB controller mem 0xab00-0xabff irq 19 at 
device 2.0 on pci2
usbus0 on ohci0
ohci1: OHCI (generic) USB controller mem 0xac00-0xacff irq 19 at 
device 2.1 on pci2
usbus1 on ohci1
ohci2: OHCI (generic) USB controller mem 0xad00-0xadff irq 19 at 
device 2.2 on pci2
usbus2 on ohci2
ehci0: EHCI (generic) USB 2.0 controller mem 0xae00-0xaeff irq 19 at 
device 2.3 on pci2
usbus3: EHCI version 1.0
usbus3 on ehci0
pci2: serial bus, USB at device 2.4 (no driver attached)
sdhci_pci0: Generic SD HCI mem 0xa0004000-0xa00041ff irq 18 at device 4.0 on 
pci2
sdhci_pci0: 1 slot(s) allocated
sdhci_pci1: Generic SD HCI mem 0xa0004200-0xa00043ff irq 18 at device 4.1 on 
pci2
sdhci_pci1: 1 slot(s) allocated
ahci0: AHCI SATA controller port 0x1020-0x103f mem 0xa0004400-0xa00047ff irq 
17 at device 6.0 on pci2
ahci0: AHCI v1.10 with 2 3Gbps ports, Port Multiplier supported
ahcich0: AHCI channel at channel 0 on ahci0
ahcich1: AHCI channel at channel 1 on ahci0
ohci3: OHCI (generic) USB controller mem 0xa0004800-0xa00048ff irq 16 at 
device 8.0 on pci2
usbus4 on ohci3
ohci4: OHCI (generic) USB controller mem 0xa0004900-0xa00049ff irq 16 at 
device 8.1 on pci2
usbus5 on ohci4
ohci5: OHCI (generic) USB controller mem 0xa0004a00-0xa0004aff irq 16 at 
device 8.2 on pci2
usbus6 on ohci5
ehci1: EHCI (generic) USB 2.0 controller mem 0xa0004b00-0xa0004bff irq 16 at 
device 8.3 on pci2
usbus7: EHCI version 1.0
usbus7 on ehci1
pci2: unknown at device 10.0 (no driver attached)
uart2: Intel EG20T Serial Port 0 port 0x1040-0x1047 mem 0xa0004d00-0xa0004d0f 
irq 19 at device 10.1 on pci2
uart3: Intel EG20T Serial 

[PATCH v10 12/20] xen: add a hook to perform AP startup

2014-01-14 Thread 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 |   14 +++---
 sys/amd64/include/cpu.h  |1 +
 sys/amd64/include/smp.h  |1 +
 sys/x86/xen/hvm.c|   12 +-
 sys/x86/xen/pv.c |   85 ++
 sys/xen/pv.h |   32 
 6 files changed, 137 insertions(+), 8 deletions(-)
 create mode 100644 sys/xen/pv.h

diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c
index 4af4f8f..17e957d 100644
--- a/sys/amd64/amd64/mp_machdep.c
+++ b/sys/amd64/amd64/mp_machdep.c
@@ -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];
@@ -124,7 +124,8 @@ static u_long *ipi_hardclock_counts[MAXCPU];
 
 /* 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 +139,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 +166,6 @@ static int cpu_cores;   /* cores per 
package */
 
 static voidassign_cpu_ids(void);
 static voidset_interrupt_apic_ids(void);
-static int start_all_aps(void);
 static int start_ap(int apic_id);
 static voidrelease_aps(void *dummy);
 
@@ -569,7 +569,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 +908,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;
diff --git a/sys/amd64/include/cpu.h b/sys/amd64/include/cpu.h
index 3c5d5df..98dc3e0 100644
--- a/sys/amd64/include/cpu.h
+++ b/sys/amd64/include/cpu.h
@@ -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;
diff --git a/sys/amd64/include/smp.h b/sys/amd64/include/smp.h
index d1b366b..15bc823 100644
--- a/sys/amd64/include/smp.h
+++ b/sys/amd64/include/smp.h
@@ -79,6 +79,7 @@ void  smp_masked_invlpg_range(cpuset_t mask, struct pmap 
*pmap,
vm_offset_t startva, vm_offset_t endva);
 void   smp_invltlb(struct pmap *pmap);
 void   smp_masked_invltlb(cpuset_t mask, struct pmap *pmap);
+intnative_start_all_aps(void);
 
 #endif /* !LOCORE */
 #endif /* SMP */
diff --git a/sys/x86/xen/hvm.c b/sys/x86/xen/hvm.c
index fb1ed79..49caacf 100644
--- a/sys/x86/xen/hvm.c
+++ b/sys/x86/xen/hvm.c
@@ -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
@@ -119,7 +122,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 +704,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)
diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c
index d11bc1a..22fd6a6 100644
--- a/sys/x86/xen/pv.c
+++ b/sys/x86/xen/pv.c
@@ -34,8 +34,11 @@ __FBSDID($FreeBSD$);
 #include sys/kernel.h
 #include sys/reboot.h
 #include sys/systm.h
+#include sys/malloc.h
 #include sys/lock.h
 #include sys/rwlock.h
+#include sys/mutex.h
+#include sys/smp.h
 
 #include vm/vm.h
 #include vm/vm_extern.h
@@ -49,9 +52,13 @@ __FBSDID($FreeBSD$);
 #include machine/sysarch.h
 #include machine/clock.h
 #include machine/pc/bios.h
+#include machine/smp.h
 
 #include xen/xen-os.h
 #include xen/hypervisor.h
+#include xen/pv.h
+
+#include xen/interface/vcpu.h
 
 /* Native initial function */
 extern 

[PATCH v10 20/20] isa: allow ISA bus to attach to xenpv device

2014-01-14 Thread Roger Pau Monne
---
 sys/x86/isa/isa.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/sys/x86/isa/isa.c b/sys/x86/isa/isa.c
index 1a57137..9287ff2 100644
--- a/sys/x86/isa/isa.c
+++ b/sys/x86/isa/isa.c
@@ -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, xenpv, isa_driver, isa_devclass, 0, 0);
+#endif
-- 
1.7.7.5 (Apple Git-26)

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


[PATCH v10 15/20] xen: create a PV CPU device for PVH guests

2014-01-14 Thread Roger Pau Monne
Since there's no ACPI on PVH guests, we need to create a dummy CPU
device in order to fill the pcpu-pc_device field.
---
 sys/conf/files|1 +
 sys/dev/xen/pvcpu/pvcpu.c |  101 +
 2 files changed, 102 insertions(+), 0 deletions(-)
 create mode 100644 sys/dev/xen/pvcpu/pvcpu.c

diff --git a/sys/conf/files b/sys/conf/files
index bddf021..178d5e2 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -2500,6 +2500,7 @@ dev/xen/netback/netback.c optional xen | xenhvm
 dev/xen/netfront/netfront.coptional xen | xenhvm
 dev/xen/xenpci/xenpci.coptional xenpci
 dev/xen/timer/timer.c  optional xen | xenhvm
+dev/xen/pvcpu/pvcpu.c  optional xen | xenhvm
 dev/xl/if_xl.c optional xl pci
 dev/xl/xlphy.c optional xl pci
 fs/deadfs/dead_vnops.c standard
diff --git a/sys/dev/xen/pvcpu/pvcpu.c b/sys/dev/xen/pvcpu/pvcpu.c
new file mode 100644
index 000..7f3697c
--- /dev/null
+++ b/sys/dev/xen/pvcpu/pvcpu.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2013 Roger Pau Monné roger@citrix.com
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+__FBSDID($FreeBSD$);
+
+#include sys/param.h
+#include sys/systm.h
+#include sys/bus.h
+#include sys/kernel.h
+#include sys/module.h
+#include sys/pcpu.h
+#include sys/smp.h
+
+#include xen/xen-os.h
+
+/*
+ * Dummy Xen cpu device
+ *
+ * Since there's no ACPI on PVH guests, we need to create a dummy
+ * CPU device in order to fill the pcpu-pc_device field.
+ */
+
+static void
+xenpvcpu_identify(driver_t *driver, device_t parent)
+{
+   device_t child;
+   int i;
+
+   /* Only attach to PV guests, HVM guests use the ACPI CPU devices */
+   if (!xen_pv_domain())
+   return;
+
+   CPU_FOREACH(i) {
+   child = BUS_ADD_CHILD(parent, 0, pvcpu, i);
+   if (child == NULL)
+   panic(xenpvcpu_identify add pvcpu);
+   }
+}
+
+static int
+xenpvcpu_probe(device_t dev)
+{
+
+   device_set_desc(dev, Xen PV CPU);
+   return (BUS_PROBE_NOWILDCARD);
+}
+
+static int
+xenpvcpu_attach(device_t dev)
+{
+   struct pcpu *pc;
+   int cpu;
+
+   cpu = device_get_unit(dev);
+   pc = pcpu_find(cpu);
+   pc-pc_device = dev;
+   return (0);
+}
+
+static device_method_t xenpvcpu_methods[] = {
+   DEVMETHOD(device_identify, xenpvcpu_identify),
+   DEVMETHOD(device_probe, xenpvcpu_probe),
+   DEVMETHOD(device_attach, xenpvcpu_attach),
+
+   DEVMETHOD_END
+};
+
+static driver_t xenpvcpu_driver = {
+   pvcpu,
+   xenpvcpu_methods,
+   0,
+};
+
+devclass_t xenpvcpu_devclass;
+
+DRIVER_MODULE(xenpvcpu, xenpv, xenpvcpu_driver, xenpvcpu_devclass, 0, 0);
+MODULE_DEPEND(xenpvcpu, xenpv, 1, 1, 1);
-- 
1.7.7.5 (Apple Git-26)

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org

[PATCH v10 16/20] xen: create a Xen nexus to use in PV/PVH

2014-01-14 Thread Roger Pau Monne
Introduce a Xen specific nexus that is going to be in charge for
attaching Xen specific devices.
---
 sys/conf/files.amd64  |1 +
 sys/conf/files.i386   |1 +
 sys/dev/xen/console/console.c |2 +-
 sys/dev/xen/timer/timer.c |4 +-
 sys/dev/xen/xenpci/xenpci.c   |   64 ++-
 sys/x86/xen/xen_nexus.c   |   76 +
 sys/xen/xenstore/xenstore.c   |6 +---
 7 files changed, 85 insertions(+), 69 deletions(-)
 create mode 100644 sys/x86/xen/xen_nexus.c

diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64
index d7c98cc..f378983 100644
--- a/sys/conf/files.amd64
+++ b/sys/conf/files.amd64
@@ -571,3 +571,4 @@ x86/xen/xen_intr.c  optionalxen | xenhvm
 x86/xen/pv.c   optionalxenhvm
 x86/xen/pvcpu_enum.c   optionalxenhvm
 x86/xen/xenpv.coptionalxenhvm
+x86/xen/xen_nexus.coptionalxenhvm
diff --git a/sys/conf/files.i386 b/sys/conf/files.i386
index 81142e3..02887a33 100644
--- a/sys/conf/files.i386
+++ b/sys/conf/files.i386
@@ -604,3 +604,4 @@ x86/x86/delay.c standard
 x86/xen/hvm.c  optional xenhvm
 x86/xen/xen_intr.c optional xen | xenhvm
 x86/xen/xenpv.coptional xen | xenhvm
+x86/xen/xen_nexus.coptional xen | xenhvm
diff --git a/sys/dev/xen/console/console.c b/sys/dev/xen/console/console.c
index 899dffc..91538fe 100644
--- a/sys/dev/xen/console/console.c
+++ b/sys/dev/xen/console/console.c
@@ -462,4 +462,4 @@ xcons_force_flush(void)
}
 }
 
-DRIVER_MODULE(xc, nexus, xc_driver, xc_devclass, 0, 0);
+DRIVER_MODULE(xc, xenpv, xc_driver, xc_devclass, 0, 0);
diff --git a/sys/dev/xen/timer/timer.c b/sys/dev/xen/timer/timer.c
index 96372ab..f16f5a5 100644
--- a/sys/dev/xen/timer/timer.c
+++ b/sys/dev/xen/timer/timer.c
@@ -636,5 +636,5 @@ static driver_t xentimer_driver = {
sizeof(struct xentimer_softc),
 };
 
-DRIVER_MODULE(xentimer, nexus, xentimer_driver, xentimer_devclass, 0, 0);
-MODULE_DEPEND(xentimer, nexus, 1, 1, 1);
+DRIVER_MODULE(xentimer, xenpv, xentimer_driver, xentimer_devclass, 0, 0);
+MODULE_DEPEND(xentimer, xenpv, 1, 1, 1);
diff --git a/sys/dev/xen/xenpci/xenpci.c b/sys/dev/xen/xenpci/xenpci.c
index dd2ad92..e334051 100644
--- a/sys/dev/xen/xenpci/xenpci.c
+++ b/sys/dev/xen/xenpci/xenpci.c
@@ -51,8 +51,6 @@ __FBSDID($FreeBSD$);
 
 extern void xen_intr_handle_upcall(struct trapframe *trap_frame);
 
-static device_t nexus;
-
 /*
  * This is used to find our platform device instance.
  */
@@ -188,36 +186,6 @@ xenpci_alloc_space(size_t sz, vm_paddr_t *pa)
}
 }
 
-static struct resource *
-xenpci_alloc_resource(device_t dev, device_t child, int type, int *rid,
-u_long start, u_long end, u_long count, u_int flags)
-{
-   return (BUS_ALLOC_RESOURCE(nexus, child, type, rid, start,
-   end, count, flags));
-}
-
-
-static int
-xenpci_release_resource(device_t dev, device_t child, int type, int rid,
-struct resource *r)
-{
-   return (BUS_RELEASE_RESOURCE(nexus, child, type, rid, r));
-}
-
-static int
-xenpci_activate_resource(device_t dev, device_t child, int type, int rid,
-struct resource *r)
-{
-   return (BUS_ACTIVATE_RESOURCE(nexus, child, type, rid, r));
-}
-
-static int
-xenpci_deactivate_resource(device_t dev, device_t child, int type,
-int rid, struct resource *r)
-{
-   return (BUS_DEACTIVATE_RESOURCE(nexus, child, type, rid, r));
-}
-
 /*
  * Probe - just check device ID.
  */
@@ -229,7 +197,7 @@ xenpci_probe(device_t dev)
return (ENXIO);
 
device_set_desc(dev, Xen Platform Device);
-   return (bus_generic_probe(dev));
+   return (BUS_PROBE_DEFAULT);
 }
 
 /*
@@ -239,20 +207,8 @@ static int
 xenpci_attach(device_t dev)
 {
struct xenpci_softc *scp = device_get_softc(dev);
-   devclass_t dc;
int error;
 
-   /*
-* Find and record nexus0.  Since we are not really on the
-* PCI bus, all resource operations are directed to nexus
-* instead of through our parent.
-*/
-   if ((dc = devclass_find(nexus))  == 0
-|| (nexus = devclass_get_device(dc, 0)) == 0) {
-   device_printf(dev, unable to find nexus.);
-   return (ENOENT);
-   }
-
error = xenpci_allocate_resources(dev);
if (error) {
device_printf(dev, xenpci_allocate_resources failed(%d).\n,
@@ -270,7 +226,7 @@ xenpci_attach(device_t dev)
goto errexit;
}
 
-   return (bus_generic_attach(dev));
+   return (0);
 
 errexit:
/*
@@ -309,16 +265,10 @@ xenpci_detach(device_t dev)
 }
 
 static int
-xenpci_suspend(device_t dev)
-{
-   return (bus_generic_suspend(dev));
-}
-
-static int
 xenpci_resume(device_t dev)
 {
xen_hvm_set_callback(dev);
-   return (bus_generic_resume(dev));
+   return (0);
 }
 

[PATCH v10 13/20] xen: introduce flag to disable the local apic

2014-01-14 Thread Roger Pau Monne
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(-)

diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c
index 17e957d..cea0306 100644
--- a/sys/amd64/amd64/mp_machdep.c
+++ b/sys/amd64/amd64/mp_machdep.c
@@ -707,7 +707,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_valid)
+   lapic_disable();
 
/* signal our startup to the BSP. */
mp_naps++;
@@ -733,7 +734,7 @@ init_secondary(void)
 
/* A quick check from sanity claus */
cpuid = PCPU_GET(cpuid);
-   if (PCPU_GET(apic_id) != lapic_id()) {
+   if (lapic_valid  (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));
@@ -749,7 +750,8 @@ init_secondary(void)
mtx_lock_spin(ap_boot_mtx);
 
/* Init local apic for irq's */
-   lapic_setup(1);
+   if (lapic_valid)
+   lapic_setup(1);
 
/* Set memory range attributes for this CPU to match the BSP */
mem_range_AP_init();
@@ -764,7 +766,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_valid  bootverbose)
lapic_dump(AP);
 
if (smp_cpus == mp_ncpus) {
diff --git a/sys/amd64/include/apicvar.h b/sys/amd64/include/apicvar.h
index e7423a3..c04a238 100644
--- a/sys/amd64/include/apicvar.h
+++ b/sys/amd64/include/apicvar.h
@@ -169,6 +169,7 @@ inthand_t
 
 extern vm_paddr_t lapic_paddr;
 extern int apic_cpuids[];
+extern bool lapic_valid;
 
 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,
diff --git a/sys/i386/include/apicvar.h b/sys/i386/include/apicvar.h
index df99ebe..ea8a3c3 100644
--- a/sys/i386/include/apicvar.h
+++ b/sys/i386/include/apicvar.h
@@ -168,6 +168,7 @@ inthand_t
 
 extern vm_paddr_t lapic_paddr;
 extern int apic_cpuids[];
+extern bool lapic_valid;
 
 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,
diff --git a/sys/i386/xen/xen_machdep.c b/sys/i386/xen/xen_machdep.c
index 09c01f1..25b9cfc 100644
--- a/sys/i386/xen/xen_machdep.c
+++ b/sys/i386/xen/xen_machdep.c
@@ -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_valid = false;
xen_phys_machine = (xen_pfn_t *)startinfo-mfn_list;
 
IdlePTD = (pd_entry_t *)((uint8_t *)startinfo-pt_base + PAGE_SIZE);
diff --git a/sys/x86/x86/local_apic.c b/sys/x86/x86/local_apic.c
index 41bd602..fddf1fb 100644
--- a/sys/x86/x86/local_apic.c
+++ b/sys/x86/x86/local_apic.c
@@ -156,6 +156,7 @@ extern inthand_t IDTVEC(rsvd);
 
 volatile lapic_t *lapic;
 vm_paddr_t lapic_paddr;
+bool lapic_valid = true;
 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_valid)
+   return;
+
/*
 * Finish setting up the local APIC on the BSP once we know how to
 * properly program the LINT pins.
diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c
index 22fd6a6..6ea1e2a 100644
--- a/sys/x86/xen/pv.c
+++ b/sys/x86/xen/pv.c
@@ -53,6 +53,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/hypervisor.h
@@ -315,4 +316,6 @@ xen_pv_set_init_ops(void)
 {
/* Init ops for Xen PV */
init_ops = xen_init_ops;
+   /* Disable lapic */
+   lapic_valid = false;
 }
-- 
1.7.7.5 (Apple Git-26)

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


[PATCH v10 14/20] xen: introduce xenpv bus and a dummy pvcpu device

2014-01-14 Thread Roger Pau Monne
Since Xen PVH guests doesn't have ACPI, we need to create a dummy
bus so top level Xen devices can attach to it (instead of
attaching directly to the nexus) and a pvcpu device that will be used
to fill the pcpu-pc_device field.
---
 sys/conf/files.amd64 |1 +
 sys/conf/files.i386  |1 +
 sys/x86/xen/xenpv.c  |  128 ++
 3 files changed, 130 insertions(+), 0 deletions(-)
 create mode 100644 sys/x86/xen/xenpv.c

diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64
index a3491da..d7c98cc 100644
--- a/sys/conf/files.amd64
+++ b/sys/conf/files.amd64
@@ -570,3 +570,4 @@ x86/xen/hvm.c   optionalxenhvm
 x86/xen/xen_intr.c optionalxen | xenhvm
 x86/xen/pv.c   optionalxenhvm
 x86/xen/pvcpu_enum.c   optionalxenhvm
+x86/xen/xenpv.coptionalxenhvm
diff --git a/sys/conf/files.i386 b/sys/conf/files.i386
index 790296d..81142e3 100644
--- a/sys/conf/files.i386
+++ b/sys/conf/files.i386
@@ -603,3 +603,4 @@ x86/x86/tsc.c   standard
 x86/x86/delay.cstandard
 x86/xen/hvm.c  optional xenhvm
 x86/xen/xen_intr.c optional xen | xenhvm
+x86/xen/xenpv.coptional xen | xenhvm
diff --git a/sys/x86/xen/xenpv.c b/sys/x86/xen/xenpv.c
new file mode 100644
index 000..e1282cf
--- /dev/null
+++ b/sys/x86/xen/xenpv.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2013 Roger Pau Monné roger@citrix.com
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+__FBSDID($FreeBSD$);
+
+#include sys/param.h
+#include sys/systm.h
+#include sys/bus.h
+#include sys/kernel.h
+#include sys/module.h
+#include sys/pcpu.h
+#include sys/smp.h
+
+#include xen/xen-os.h
+
+static devclass_t xenpv_devclass;
+
+static void
+xenpv_identify(driver_t *driver, device_t parent)
+{
+   if (!xen_domain())
+   return;
+
+   /* Make sure there's only one xenpv device. */
+   if (devclass_get_device(xenpv_devclass, 0))
+   return;
+
+   /*
+* Use a high order number so xenpv is attached after
+* xenpci on HVM guests.
+*/
+   BUS_ADD_CHILD(parent, 200, xenpv, 0);
+}
+
+static int
+xenpv_probe(device_t dev)
+{
+
+   device_set_desc(dev, Xen PV bus);
+   device_quiet(dev);
+   return (BUS_PROBE_NOWILDCARD);
+}
+
+static int
+xenpv_attach(device_t dev)
+{
+   device_t child;
+
+   if (xen_hvm_domain()) {
+   device_t xenpci;
+   devclass_t dc;
+
+   /* Make sure xenpci has been attached */
+   dc = devclass_find(xenpci);
+   if (dc == NULL)
+   panic(unable to find xenpci devclass);
+
+   xenpci = devclass_get_device(dc, 0);
+   if (xenpci == NULL)
+   panic(unable to find xenpci device);
+
+   if (!device_is_attached(xenpci))
+   panic(trying to attach xenpv before xenpci);
+   }
+
+   /*
+* Let our child drivers identify any child devices that they
+* can find.  Once that is done attach any devices that we
+* found.
+*/
+   bus_generic_probe(dev);
+   bus_generic_attach(dev);
+
+   if (!devclass_get_device(devclass_find(isa), 0)) {
+   child = BUS_ADD_CHILD(dev, 0, isa, 0);
+   if (child == NULL)
+   panic(xenpv_attach isa);
+   device_probe_and_attach(child);
+   }
+
+   return 0;
+}
+
+static device_method_t xenpv_methods[] = {
+   /* Device interface */
+   

[PATCH v10 19/20] xen: changes to gnttab for PVH

2014-01-14 Thread Roger Pau Monne
---
 sys/xen/gnttab.c |   26 +-
 1 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/sys/xen/gnttab.c b/sys/xen/gnttab.c
index 03c32b7..6949be5 100644
--- a/sys/xen/gnttab.c
+++ b/sys/xen/gnttab.c
@@ -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);
+   }
}
}
 
-- 
1.7.7.5 (Apple Git-26)

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


[PATCH v10 17/20] xen: add shutdown hook for PVH

2014-01-14 Thread Roger Pau Monne
Add the PV shutdown hook to PVH.
---
 sys/dev/xen/control/control.c |   37 ++---
 1 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/sys/dev/xen/control/control.c b/sys/dev/xen/control/control.c
index bc0609d..78894ba 100644
--- a/sys/dev/xen/control/control.c
+++ b/sys/dev/xen/control/control.c
@@ -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);
 }
-- 
1.7.7.5 (Apple Git-26)

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


[PATCH v10 11/20] xen: changes to hvm code in order to support PVH guests

2014-01-14 Thread 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.
---
 sys/x86/xen/hvm.c |   17 -
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/sys/x86/xen/hvm.c b/sys/x86/xen/hvm.c
index 9a0411e..fb1ed79 100644
--- a/sys/x86/xen/hvm.c
+++ b/sys/x86/xen/hvm.c
@@ -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);
-- 
1.7.7.5 (Apple Git-26)

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


[PATCH v10 10/20] xen: add hook for AP bootstrap memory reservation

2014-01-14 Thread 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 |1 +
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index 64df89a..3a2db30 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -178,6 +178,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
 };
 
 /*
@@ -1492,7 +1495,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
 
/*
diff --git a/sys/amd64/include/sysarch.h b/sys/amd64/include/sysarch.h
index 084223e..7696064 100644
--- a/sys/amd64/include/sysarch.h
+++ b/sys/amd64/include/sysarch.h
@@ -16,6 +16,7 @@ struct init_ops {
void(*early_delay_init)(void);
void(*early_delay)(int);
void(*parse_memmap)(caddr_t, vm_paddr_t *, int *);
+   u_int   (*mp_bootaddress)(u_int);
 };
 
 extern struct init_ops init_ops;
-- 
1.7.7.5 (Apple Git-26)

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


[PATCH v10 18/20] xen: xenstore changes to support PVH

2014-01-14 Thread Roger Pau Monne
---
 sys/xen/xenstore/xenstore.c |   18 +-
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/sys/xen/xenstore/xenstore.c b/sys/xen/xenstore/xenstore.c
index b5cf413..7fa08cc 100644
--- a/sys/xen/xenstore/xenstore.c
+++ b/sys/xen/xenstore/xenstore.c
@@ -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
@@ -1147,13 +1145,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);
-- 
1.7.7.5 (Apple Git-26)

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: [PATCH v10 14/20] xen: introduce xenpv bus and a dummy pvcpu device

2014-01-14 Thread Julien Grall
On 01/14/2014 02:59 PM, Roger Pau Monne wrote:
 +static int
 +xenpv_attach(device_t dev)
 +{
 + device_t child;
 +
 + if (xen_hvm_domain()) {
 + device_t xenpci;
 + devclass_t dc;
 +
 + /* Make sure xenpci has been attached */
 + dc = devclass_find(xenpci);
 + if (dc == NULL)
 + panic(unable to find xenpci devclass);
 +
 + xenpci = devclass_get_device(dc, 0);
 + if (xenpci == NULL)
 + panic(unable to find xenpci device);
 +
 + if (!device_is_attached(xenpci))
 + panic(trying to attach xenpv before xenpci);
 + }

Can you use the identify method to add the xenpci device?

As I said earlier, I will reuse this code for ARM guest and this device
is not used on this architecture.

-- 
Julien Grall
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: [PATCH v10 14/20] xen: introduce xenpv bus and a dummy pvcpu device

2014-01-14 Thread Roger Pau Monné
On 14/01/14 16:41, Julien Grall wrote:
 On 01/14/2014 02:59 PM, Roger Pau Monne wrote:
 +static int
 +xenpv_attach(device_t dev)
 +{
 +device_t child;
 +
 +if (xen_hvm_domain()) {
 +device_t xenpci;
 +devclass_t dc;
 +
 +/* Make sure xenpci has been attached */
 +dc = devclass_find(xenpci);
 +if (dc == NULL)
 +panic(unable to find xenpci devclass);
 +
 +xenpci = devclass_get_device(dc, 0);
 +if (xenpci == NULL)
 +panic(unable to find xenpci device);
 +
 +if (!device_is_attached(xenpci))
 +panic(trying to attach xenpv before xenpci);
 +}
 
 Can you use the identify method to add the xenpci device?

I don't think so, xenpci is a pci device, it is detected and plugged by
the pci bus code.

 As I said earlier, I will reuse this code for ARM guest and this device
 is not used on this architecture.

You could move this chunk of code (the check for xenpci) to a static
inline function and make it a noop for ARM.

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: [PATCH v10 14/20] xen: introduce xenpv bus and a dummy pvcpu device

2014-01-14 Thread Roger Pau Monné
On 14/01/14 17:14, Julien Grall wrote:
 On 01/14/2014 04:08 PM, Roger Pau Monné wrote:
 On 14/01/14 16:41, Julien Grall wrote:
 On 01/14/2014 02:59 PM, Roger Pau Monne wrote:
 +static int
 +xenpv_attach(device_t dev)
 +{
 +  device_t child;
 +
 +  if (xen_hvm_domain()) {
 +  device_t xenpci;
 +  devclass_t dc;
 +
 +  /* Make sure xenpci has been attached */
 +  dc = devclass_find(xenpci);
 +  if (dc == NULL)
 +  panic(unable to find xenpci devclass);
 +
 +  xenpci = devclass_get_device(dc, 0);
 +  if (xenpci == NULL)
 +  panic(unable to find xenpci device);
 +
 +  if (!device_is_attached(xenpci))
 +  panic(trying to attach xenpv before xenpci);
 +  }

 Can you use the identify method to add the xenpci device?

 I don't think so, xenpci is a pci device, it is detected and plugged by
 the pci bus code.
 
 Oups, I though you are trying to add the device. In this case, the check
 seems pointless. In which case the xenpci couldn't exist?

It's just a belt and suspenders, if we attach the xenpv bus without
xenpci being attached first a bunch of things are going to fail, I
though it might be best to print a clear error message about what went
wrong in order to help debug it.

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org

Re: [PATCH v10 14/20] xen: introduce xenpv bus and a dummy pvcpu device

2014-01-14 Thread Julien Grall
On 01/14/2014 04:08 PM, Roger Pau Monné wrote:
 On 14/01/14 16:41, Julien Grall wrote:
 On 01/14/2014 02:59 PM, Roger Pau Monne wrote:
 +static int
 +xenpv_attach(device_t dev)
 +{
 +   device_t child;
 +
 +   if (xen_hvm_domain()) {
 +   device_t xenpci;
 +   devclass_t dc;
 +
 +   /* Make sure xenpci has been attached */
 +   dc = devclass_find(xenpci);
 +   if (dc == NULL)
 +   panic(unable to find xenpci devclass);
 +
 +   xenpci = devclass_get_device(dc, 0);
 +   if (xenpci == NULL)
 +   panic(unable to find xenpci device);
 +
 +   if (!device_is_attached(xenpci))
 +   panic(trying to attach xenpv before xenpci);
 +   }

 Can you use the identify method to add the xenpci device?
 
 I don't think so, xenpci is a pci device, it is detected and plugged by
 the pci bus code.

Oups, I though you are trying to add the device. In this case, the check
seems pointless. In which case the xenpci couldn't exist?

-- 
Julien Grall
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org

Re: [PATCH v10 14/20] xen: introduce xenpv bus and a dummy pvcpu device

2014-01-14 Thread Julien Grall
On 01/14/2014 04:20 PM, Roger Pau Monné wrote:
 On 14/01/14 17:14, Julien Grall wrote:
 On 01/14/2014 04:08 PM, Roger Pau Monné wrote:
 On 14/01/14 16:41, Julien Grall wrote:
 On 01/14/2014 02:59 PM, Roger Pau Monne wrote:
 +static int
 +xenpv_attach(device_t dev)
 +{
 + device_t child;
 +
 + if (xen_hvm_domain()) {
 + device_t xenpci;
 + devclass_t dc;
 +
 + /* Make sure xenpci has been attached */
 + dc = devclass_find(xenpci);
 + if (dc == NULL)
 + panic(unable to find xenpci devclass);
 +
 + xenpci = devclass_get_device(dc, 0);
 + if (xenpci == NULL)
 + panic(unable to find xenpci device);
 +
 + if (!device_is_attached(xenpci))
 + panic(trying to attach xenpv before xenpci);
 + }

 Can you use the identify method to add the xenpci device?

 I don't think so, xenpci is a pci device, it is detected and plugged by
 the pci bus code.

 Oups, I though you are trying to add the device. In this case, the check
 seems pointless. In which case the xenpci couldn't exist?
 
 It's just a belt and suspenders, if we attach the xenpv bus without
 xenpci being attached first a bunch of things are going to fail, I
 though it might be best to print a clear error message about what went
 wrong in order to help debug it.

I only see one place which could failed, and we are already protected.
It's when we are trying to allocate space from grant-table via
xenpci_alloc_space.

I think this error should be enough to understand the problem. At the
same time, it's the same things with xenstore. If grant-table
initialization has failed, an error message is just printed and FreeBSD
will likely failed later when it will try to initialized the PV disk.

-- 
Julien Grall
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org

Regression on 10-RC5 with a multicast routing daemon

2014-01-14 Thread Olivier Cochard-Labbé
Hi all,

I'm trying to port a PIM sparse-mode daemon (
https://github.com/troglobit/pimd/) and I've meet a problem:
This daemon compile and run fine on FreeBSD 9.2 but on 10-RC5 this daemon
can't understand received multicast packets (received from other PIM
neighbors) and display this kind of error message in debug mode warning -
Received packet from 10.0.12.2 shorter (28 bytes) than hdr+data length
(20+28).
How to troubleshoot this problem ?

My current work of this port can be tested with theses commands:

cd /usr/ports
fetch -o ports.pimd.shar 
https://sourceforge.net/p/bsdrp/code/HEAD/tree/trunk/BSDRP/patches/ports.pimd.shar?format=raw

sh ./ports.pimd.shar
cd net/pimd
make install
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: error message from pkg on HEAD

2014-01-14 Thread Freddie Cash
On Mon, Jan 13, 2014 at 8:22 PM, Glen Barber g...@freebsd.org wrote:

 On Mon, Jan 13, 2014 at 08:15:34PM -0800, John-Mark Gurney wrote:
  So, now when I run pkg I get the following:
  pkg: Ignoring bad configuration entry in
 /usr/local/etc/pkg/repos/FreeBSD.conf: URL:
 http://pkg.freebsd.org/${ABI}/latest;
  pkg: Ignoring bad configuration entry in
 /usr/local/etc/pkg/repos/FreeBSD.conf: true
  pkg: Ignoring bad configuration entry in
 /usr/local/etc/pkg/repos/FreeBSD.conf: SRV
 
  pkg does seem to work so I'm not sure what I need to do.  I think I was
  told to add these lines to the file, though I'm not sure, so I don't want
  to delete them.
 
  Thanks for help in letting me know what the solution is.
 
  # pkg -v
  1.2.4_1
  # uname -a
  FreeBSD carbon.funkthat.com 11.0-CURRENT FreeBSD 11.0-CURRENT #4
 r260082M: Wed Jan  1 12:08:41 PST 2014 
 j...@carbon.funkthat.com:/usr/obj/usr/src/sys/lockprof
  amd64
  # cat /usr/local/etc/pkg/repos/FreeBSD.conf
  FreeBSD:
URL: http://pkg.freebsd.org/${ABI}/latest
ENABLED: YES
MIRROR_TYPE: SRV
 

 The file format is incorrect.

 FreeBSD: {
 url: http://pkg.freebsd.org/${ABI}/latest;,
 enabled: yes,
 mirror_type: srv
 }

 Shouldn't the URL start with pkg+http://?​​

-- 
Freddie Cash
fjwc...@gmail.com
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org

Final Call for FreeBSD 2013Q4 (October-December) Status Reports

2014-01-14 Thread Gabor Pali
Dear FreeBSD Community,

Please note that the submission date for the October to December
Quarterly Status Reports is, January 14th, 2014, today.  Please
consult my earlier message for the details:

On Sat, Dec 14, 2013 at 2:05 PM, Gabor Pali p...@freebsd.org wrote:
 Dear FreeBSD Community,

 Please note that the next submission date for the October to December
 Quarterly Status Reports is January 14th, 2014, about a month away.

 They do not have to be very long -- basically they may be about
 anything that lets people know what is going on around the FreeBSD
 Project.  Submission of reports is not restricted to committers:
 Anyone who is doing anything interesting and FreeBSD-related can (and
 therefore encouraged to) write one!

 The preferred and easiest submission method is to use the XML
 generator [1] with the result emailed as an attachment to us, that is,
 mont...@freebsd.org [2].  There is also an XML template [3] which can
 be filled out manually and attached if preferred.  For the expected
 content and style, please study our guidelines on how to write a good
 status reports [4].

 To enable compilation and publication of the Q4 report as soon as
 possible for the January 14th deadline, please be prompt with any
 report submissions you may have.

 We are looking forward to all of your 2013Q4 reports!

 Thanks,
 Gabor


 [1] http://www.freebsd.org/cgi/monthly.cgi
 [2] mailto:mont...@freebsd.org
 [3] http://www.freebsd.org/news/status/report-sample.xml
 [4] http://www.freebsd.org/news/status/howto.html
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: Shared IRQ on ATOM based Soekris net6501 board

2014-01-14 Thread John Baldwin
On Tuesday, January 14, 2014 10:03:46 am Christophe Prevotaux wrote:
 
 I have found out that when I use 2 AR9580 mini PCIe board
 some irq (namely in that case irq18 is shared over 3 devices)
 
 I wonder why it is done like this and if this could be something to fix ? 

You can't fix it.  This is how the interrupts are connected on your 
motherboard.  It's true that in PCI-e there are no longer physical
interrupt lines, but the connections may still be hardcoded in silicon.  The 
only chance you might possibly have is to use ACPI (which doesn't work on your 
board) as if the PCI interrupts are hooked up to an interrupt router prior to 
the I/O APIC you might be able to shuffle things.  A far better idea would be 
to use a board that supports MSI interrupts (and/or fix the driver to use MSI 
if it is not doing so already).

-- 
John Baldwin
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: ARC pressured out, how to control/stabilize ? (reformatted to text/plain)

2014-01-14 Thread Andriy Gapon
on 14/01/2014 07:27 Vladimir Sharun said the following:
 Dear Andriy and FreeBSD community,
 
 I am not sure if the buffers are leaked somehow or if they are actually in 
 use.
 It's one of the very few places where data buffers are allocated without
 charging ARC.  In all other places it's quite easy to match allocations and
 deallocations.  But in L2ARC it is not obvious that all buffers get freed or
 when that happens.
 
 After one week under load I think we figure out the cause: it's L2ARC. 
 Here's the top's header for 7d17h of the runtime:
 
 last pid: 46409;  load averages:  0.37,  0.62,  0.70 up 7+17:14:01  07:24:10
 173 processes: 1 running, 171 sleeping, 1 zombie
 CPU:  2.0% user,  0.0% nice,  3.5% system,  0.4% interrupt, 94.2% idle
 Mem: 8714M Active, 14G Inact, 96G Wired, 1929M Cache, 3309M Buf, 3542M Free
 ARC: 85G Total, 2558M MFU, 77G MRU, 28M Anon, 1446M Header, 4802M Other
 
 ARC related tunables:
 
 vm.kmem_size=110G
 vfs.zfs.arc_max=90G
 vfs.zfs.arc_min=42G
 
 For more than 7 days of hard runtime the picture clearly shows: 
 Wired minus ARC = 11..12Gb, ARC grow and shrinks in 80-87Gb range and the
 system runs just fine.
 
 So what shall we do with L2ARC leakage ?


Could you please try this patch
http://cr.illumos.org/~webrev/skiselkov/3995/illumos-gate.patch ?

-- 
Andriy Gapon
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: FreeBSD 10-RC4: Got crash in igb driver

2014-01-14 Thread Eric Joyner
All,

I work with Jack on FreeBSD network drivers, and we have a patch that we
think might fix this problem. It re-implements the header pull-up code that
was in the driver pre-2.4.0, but with IPv6 support. Alexandre, could you
apply this patch to the igb version in HEAD and try it out on your network?
We can't replicate your setup here.

If it solves your problem, then the next step would be to port the patch to
the ixgbe driver since, as Yonghyeon noted, it looks like that driver will
encounter the same problem. We could then modify em to add IPv6 offload
support as well.

Thanks,

---
- Eric Joyner

On Fri, Jan 10, 2014 at 02:35:29PM +0400, Gleb Smirnoff wrote:
   Yonghyeon,

 On Fri, Jan 10, 2014 at 10:21:14AM +0900, Yonghyeon PYUN wrote:
 Y  I experience some troubles with the igb device driver on FreeBSD
10-RC4.
 Y 
 Y  The kernel make a pagefault in the igb_tx_ctx_setup function when
accessing to
 Y  a IPv6 header.
 Y 
 Y  The network configuration is the following:
 Y   - box acting as an IPv6 router
 Y   - one interface with an IPv6 (igb0)
 Y   - another interface with a vlan, and IPv6 on it (vlan0 on igb1)
 Y 
 Y  Vlan Hardware tagging is set on both interfaces.
 Y 
 Y  The packet that cause the crash come from igb0 and go to vlan0.
 Y 
 Y  After investigation, i see that the mbuf is split in two. The first
one carry
 Y  the ethernet header, the second, the IPv6 header and data payload.
 Y 
 Y  The split is due to the m_copy done in ip6_forward, that make the
mbuf not
 Y  writable and the M_PREPEND in ether_output that insert the new
mbuf before
 Y  the original one.
 Y 
 Y  The kernel crashes only if the newly allocated mbuf is at the end of
a memory
 Y  page, and no page is available after this one. So, it's extremly
rare.
 Y 
 Y  I inserted a KASSERT into the function (see attached patch) to
check this
 Y  behavior, and it raises on every IPv6 forwarded packet to the vlan.
The
 Y  problem disapear if i remove hardware tagging.
 Y 
 Y  In the commit 256200, i see that pullups has been removed. May it be
related ?
 Y
 Y I think I introduced the header parsing code to meet controller
 Y requirement in em(4) and Jack borrowed that code in the past but it
 Y seems it was removed in r256200.  It seems igb_tx_ctx_setup()
 Y assumes it can access ethernet/IP/TCP/UDP headers in the first mbuf
 Y of the chain.
 Y This looks wrong to me.

 Can you please restore the important code in head ASAP? Although crashes
happen
 only when the mbuf is last in a page and page isn't mapped, we read
thrash from
 next allocation on almost every packet.


It seems other Intel ethernet drivers except em(4) have similar
issues.  I didn't check recent Intel controllers/drivers for long
time so I don't know details on hardware requirements of
offloading.
Since Jack is very responsive and has hardwares to verify, he would
be more appropriate person to handle these issues.
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


fix.patch
Description: Binary data
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org

Re: buildworld fails with Zero byte read from file, skipping rest of line

2014-01-14 Thread Jeremie Le Hen
On Tue, Jan 14, 2014 at 12:58:18PM +0400, Gleb Smirnoff wrote:
   Jeremie,
 
 On Tue, Jan 14, 2014 at 08:26:21AM +0100, Jeremie Le Hen wrote:
 J Hi,
 J 
 J I have a FreeBSD -CURRENT in Virtualbox (running on Linux).  I have been
 J unable to buildworld for a while.
 J 
 J I suspect this is not a problem with the source because I didn't see any
 J report so far, whereas I've been experiencing this for a month or more.
 J Thus I naturally suspected it was a binary problem, so I've upgraded
 J to the latest snapshot, but the problem still exists.
 J 
 J   === gnu/usr.bin/groff/src/libs/libgroff (all)
 J   make[6]: 
 /usr/obj/usr/src.svn/tmp/usr/src.svn/gnu/usr.bin/groff/src/libs/libgroff/.depend
  line 3: warning: Zero byte read from file, skipping rest of line.
 J   make[6]: 
 /usr/obj/usr/src.svn/tmp/usr/src.svn/gnu/usr.bin/groff/src/libs/libgroff/.depend
  line 3: Need an operator
 J   make[6]: 
 /usr/obj/usr/src.svn/tmp/usr/src.svn/gnu/usr.bin/groff/src/libs/libgroff/.depend
  line 4: Need an operator
 J   make[6]: Fatal errors encountered -- cannot continue
 J   make[6]: stopped in /usr/src.svn/gnu/usr.bin/groff/src/libs/libgroff
 J   *** [all] Error code 1
 J 
 J Typscript available here:
 J http://people.freebsd.org/~jlh/typescript.buildworld.txt
 J 
 J Any ideas?
 
 Can you try to reproduce this with unmapped I/O turned off in boot loader?

I've never heard of that.  Can you please point me to the right
code/doc?
 
Thanks?
-- 
Jeremie Le Hen

Scientists say the world is made up of Protons, Neutrons and Electrons.
They forgot to mention Morons.
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org