Hi all,

I've attached a patch which eliminates the XENHVM kernel configuration and
instead allows FreeBSD to run under Xen/HVM with PV drivers by loading a
new xenhvm.ko module from the boot loader.  This will mean that FreeBSD
virtual machines running under Xen/HVM will be able to run "straight off
the ISO" binaries; this will also mean they will be able to use FreeBSD
Update to update the kernel.

I have spent about 10 minutes testing this in Amazon EC2.  Please help me
out by doing some more testing. ;-)

The fine details:
1. I've created a new kernel module for i386 and amd64, "xenhvm", with all
of the source files which were added via "options XENHVM" and "device xenpci".
2. I have removed those from sys/conf/files and sys/conf/options.*; those
options are now meaningless.
3. I moved the "detect Xen and disable QEMU emulated devices" code from
sys/amd64/amd64/machdep.c to the kernel module MOD_LOAD event handler.
4. I have made the PCPU values required by Xen/HVM support -- two unsigned
ints -- unconditionally compiled in.  This is the only change to the GENERIC
kernel.
5. I have removed the XENHVM kernel configuration files.

Depending on feedback from freebsd-xen@ I hope to send this to freebsd-current
for wider review later this week and then commit it before the FreeBSD 10.0
code freeze starts on September 7th.

-- 
Colin Percival
Security Officer Emeritus, FreeBSD | The power to serve
Founder, Tarsnap | www.tarsnap.com | Online backups for the truly paranoid
Index: sys/amd64/amd64/machdep.c
===================================================================
--- sys/amd64/amd64/machdep.c   (revision 254941)
+++ sys/amd64/amd64/machdep.c   (working copy)
@@ -1910,14 +1910,6 @@
        if (env != NULL)
                strlcpy(kernelname, env, sizeof(kernelname));
 
-#ifdef XENHVM
-       if (inw(0x10) == 0x49d2) {
-               if (bootverbose)
-                       printf("Xen detected: disabling emulated block and 
network devices\n");
-               outw(0x10, 3);
-       }
-#endif
-
        cpu_probe_amdc1e();
 
 #ifdef FDT
Index: sys/amd64/conf/XENHVM
===================================================================
--- sys/amd64/conf/XENHVM       (revision 254941)
+++ sys/amd64/conf/XENHVM       (working copy)
@@ -1,22 +0,0 @@
-#
-# XENHVM -- Xen HVM kernel configuration file for FreeBSD/amd64
-#
-# $FreeBSD$
-#
-include                GENERIC
-ident          XENHVM
-
-#
-# Adaptive locks rely on a lock-free pointer read to determine the run state
-# of the thread holding a lock when under contention; under a virtualisation
-# system, the thread run state may not accurately reflect whether the thread
-# (or rather its host VCPU) is actually executing.  As such, disable this
-# optimisation.
-#
-options        NO_ADAPTIVE_MUTEXES
-options        NO_ADAPTIVE_RWLOCKS
-options        NO_ADAPTIVE_SX
-
-# Xen HVM support
-options        XENHVM
-device         xenpci
Index: sys/amd64/include/pcpu.h
===================================================================
--- sys/amd64/include/pcpu.h    (revision 254941)
+++ sys/amd64/include/pcpu.h    (working copy)
@@ -42,14 +42,10 @@
 #endif
 #endif
 
-#ifdef XENHVM
 #define PCPU_XEN_FIELDS                                                        
\
        ;                                                               \
        unsigned int pc_last_processed_l1i;                             \
        unsigned int pc_last_processed_l2i
-#else
-#define PCPU_XEN_FIELDS
-#endif
 
 /*
  * The SMP parts are setup in pmap.c and locore.s for the BSP, and
Index: sys/conf/files
===================================================================
--- sys/conf/files      (revision 254941)
+++ sys/conf/files      (working copy)
@@ -2490,16 +2490,14 @@
        clean           "wpi.fw"
 dev/xe/if_xe.c                 optional xe
 dev/xe/if_xe_pccard.c          optional xe pccard
-dev/xen/balloon/balloon.c      optional xen | xenhvm
-dev/xen/blkfront/blkfront.c    optional xen | xenhvm
-dev/xen/blkback/blkback.c      optional xen | xenhvm
+dev/xen/balloon/balloon.c      optional xen
+dev/xen/blkfront/blkfront.c    optional xen
+dev/xen/blkback/blkback.c      optional xen
 dev/xen/console/console.c      optional xen
 dev/xen/console/xencons_ring.c optional xen
-dev/xen/control/control.c      optional xen | xenhvm
-dev/xen/netback/netback.c      optional xen | xenhvm
-dev/xen/netfront/netfront.c    optional xen | xenhvm
-dev/xen/xenpci/xenpci.c                optional xenpci
-dev/xen/xenpci/evtchn.c         optional xenpci
+dev/xen/control/control.c      optional xen
+dev/xen/netback/netback.c      optional xen
+dev/xen/netfront/netfront.c    optional xen
 dev/xl/if_xl.c                 optional xl pci
 dev/xl/xlphy.c                 optional xl pci
 fs/deadfs/dead_vnops.c         standard
@@ -3813,18 +3811,18 @@
 vm/vm_unix.c                   standard
 vm/vm_zeroidle.c               standard
 vm/vnode_pager.c               standard
-xen/gnttab.c                   optional xen | xenhvm
-xen/features.c                 optional xen | xenhvm
+xen/gnttab.c                   optional xen
+xen/features.c                 optional xen
 xen/evtchn/evtchn.c            optional xen
-xen/evtchn/evtchn_dev.c                optional xen | xenhvm
-xen/xenbus/xenbus_if.m         optional xen | xenhvm
-xen/xenbus/xenbus.c            optional xen | xenhvm
-xen/xenbus/xenbusb_if.m                optional xen | xenhvm
-xen/xenbus/xenbusb.c           optional xen | xenhvm
-xen/xenbus/xenbusb_front.c     optional xen | xenhvm
-xen/xenbus/xenbusb_back.c      optional xen | xenhvm
-xen/xenstore/xenstore.c                optional xen | xenhvm
-xen/xenstore/xenstore_dev.c    optional xen | xenhvm
+xen/evtchn/evtchn_dev.c                optional xen
+xen/xenbus/xenbus_if.m         optional xen
+xen/xenbus/xenbus.c            optional xen
+xen/xenbus/xenbusb_if.m                optional xen
+xen/xenbus/xenbusb.c           optional xen
+xen/xenbus/xenbusb_front.c     optional xen
+xen/xenbus/xenbusb_back.c      optional xen
+xen/xenstore/xenstore.c                optional xen
+xen/xenstore/xenstore_dev.c    optional xen
 xdr/xdr.c                      optional krpc | nfslockd | nfsclient | 
nfsserver | nfscl | nfsd
 xdr/xdr_array.c                        optional krpc | nfslockd | nfsclient | 
nfsserver | nfscl | nfsd
 xdr/xdr_mbuf.c                 optional krpc | nfslockd | nfsclient | 
nfsserver | nfscl | nfsd
Index: sys/conf/options.amd64
===================================================================
--- sys/conf/options.amd64      (revision 254941)
+++ sys/conf/options.amd64      (working copy)
@@ -64,7 +64,5 @@
 # BPF just-in-time compiler
 BPF_JITTER             opt_bpf.h
 
-XENHVM                 opt_global.h
-
 # options for the Intel C600 SAS driver (isci)
 ISCI_LOGGING   opt_isci.h
Index: sys/conf/options.i386
===================================================================
--- sys/conf/options.i386       (revision 254941)
+++ sys/conf/options.i386       (working copy)
@@ -119,7 +119,6 @@
 
 NATIVE                 opt_global.h
 XEN                    opt_global.h
-XENHVM                 opt_global.h
 
 # options for the Intel C600 SAS driver (isci)
 ISCI_LOGGING   opt_isci.h
Index: sys/i386/conf/XENHVM
===================================================================
--- sys/i386/conf/XENHVM        (revision 254941)
+++ sys/i386/conf/XENHVM        (working copy)
@@ -1,22 +0,0 @@
-#
-# XENHVM -- Xen HVM kernel configuration file for FreeBSD/i386
-#
-# $FreeBSD$
-#
-include                GENERIC
-ident          XENHVM
-
-#
-# Adaptive locks rely on a lock-free pointer read to determine the run state
-# of the thread holding a lock when under contention; under a virtualisation
-# system, the thread run state may not accurately reflect whether the thread
-# (or rather its host VCPU) is actually executing.  As such, disable this
-# optimisation.
-#
-options        NO_ADAPTIVE_MUTEXES
-options        NO_ADAPTIVE_RWLOCKS
-options        NO_ADAPTIVE_SX
-
-# Xen HVM support
-options        XENHVM
-device         xenpci
Index: sys/i386/include/pcpu.h
===================================================================
--- sys/i386/include/pcpu.h     (revision 254941)
+++ sys/i386/include/pcpu.h     (working copy)
@@ -77,7 +77,7 @@
        int     pc_ipi_to_irq[NR_IPIS];                                 \
        char    __pad[77]
 
-#elif defined(XENHVM)
+#else /* !XEN */
 
 #define        PCPU_XEN_FIELDS                                                 
\
        ;                                                               \
@@ -84,13 +84,6 @@
        unsigned int pc_last_processed_l1i;                             \
        unsigned int pc_last_processed_l2i;                             \
        char    __pad[229]
-
-#else /* !XEN && !XENHVM */
-
-#define PCPU_XEN_FIELDS                                                        
\
-       ;                                                               \
-       char    __pad[237]
-
 #endif
 
 #define        PCPU_MD_FIELDS                                                  
\
Index: sys/modules/Makefile
===================================================================
--- sys/modules/Makefile        (revision 254941)
+++ sys/modules/Makefile        (working copy)
@@ -363,6 +363,7 @@
        ${_wpifw} \
        ${_x86bios} \
        ${_xe} \
+       ${_xenhvm} \
        xl \
        ${_zfs} \
        zlib \
@@ -370,6 +371,7 @@
 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
 _filemon=      filemon
 _vmware=       vmware
+_xenhvm=       xenhvm
 .endif
 
 .if ${MACHINE_CPUARCH} != "powerpc" && ${MACHINE_CPUARCH} != "arm" && \
Index: sys/modules/xenhvm/Makefile
===================================================================
--- sys/modules/xenhvm/Makefile (revision 0)
+++ sys/modules/xenhvm/Makefile (working copy)
@@ -0,0 +1,21 @@
+# $FreeBSD$
+
+KMOD=  xenhvm
+
+DEVXENDIR=     ${.CURDIR}/../../dev/xen/
+XENDIR=        ${.CURDIR}/../../xen/
+.PATH: ${DEVXENDIR}/balloon ${DEVXENDIR}/blkfront ${DEVXENDIR}/blkback \
+       ${DEVXENDIR}/control ${DEVXENDIR}/netback ${DEVXENDIR}/netfront \
+       ${DEVXENDIR}/xenpci ${XENDIR}/ ${XENDIR}/evtchn \
+       ${XENDIR}/xenbus ${XENDIR}/xenstore
+
+SRCS=  xenhvm_mod.c    \
+       balloon.c blkfront.c blkback.c control.c netback.c netfront.c   \
+       xenpci.c evtchn.c gnttab.c features.c evtchn_dev.c              \
+       xenbus.c xenbusb.c xenbusb_front.c xenbusb_back.c               \
+       xenbus_if.c xenbus_if.h xenbusb_if.c xenbusb_if.h                       
                \
+       xenstore.c xenstore_dev.c
+MFILES=        xen/xenbus/xenbus_if.m xen/xenbus/xenbusb_if.m
+CFLAGS+=       -DXENHVM
+
+.include <bsd.kmod.mk>
Index: sys/xen/xenhvm_mod.c
===================================================================
--- sys/xen/xenhvm_mod.c        (revision 0)
+++ sys/xen/xenhvm_mod.c        (working copy)
@@ -0,0 +1,32 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD");
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/systm.h>
+
+static int
+xenhvm_modevent(module_t mod, int type, void *arg)
+{
+
+       switch (type) {
+       case MOD_LOAD:
+               if (inw(0x10) == 0x49d2) {
+                       if (bootverbose)
+                               printf("Xen detected: disabling emulated block 
and network devices\n");
+                       outw(0x10, 3);
+               }
+               return (0);
+       }
+
+       return (EOPNOTSUPP);
+}
+
+static moduledata_t xenhvm_mod = {
+       "xenhvm",
+       xenhvm_modevent,
+       0
+};
+
+DECLARE_MODULE(xenhvm, xenhvm_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
_______________________________________________
freebsd-xen@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-xen
To unsubscribe, send any mail to "freebsd-xen-unsubscr...@freebsd.org"

Reply via email to