From owner-freebsd-xen@FreeBSD.ORG Fri Dec 17 12:07:47 2010 Return-Path: Delivered-To: freebsd-xen@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E57391065674 for ; Fri, 17 Dec 2010 12:07:47 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 8C58A8FC1C for ; Fri, 17 Dec 2010 12:07:47 +0000 (UTC) Received: from fledge.watson.org (fledge.watson.org [65.122.17.41]) by cyrus.watson.org (Postfix) with ESMTPS id 4365346B23 for ; Fri, 17 Dec 2010 07:07:47 -0500 (EST) Date: Fri, 17 Dec 2010 12:07:47 +0000 (GMT) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: freebsd-xen@FreeBSD.org Message-ID: User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII Cc: Subject: Patches to support (or at least make compile) Xen PV drivers on i386 HVM X-BeenThere: freebsd-xen@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion of the freebsd port to xen - implementation and usage List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Dec 2010 12:07:48 -0000 Dear all: Something I'd like us to do for 9.0 (and maybe even 8.3) is include the Xen PV drivers in our GENERIC i386 and amd64 kernels. This will improve our "just works" factor running on Xen HVM by avoiding a mandatory kernel recompile to get access to PV drivers, in turn better supporting users who use freebsd-update, etc. However, today we're only in a position to really think about this on amd64, as currently options XENHVM and device xenpci are not supported on i386. I've attached some *untested* patches that appear to get them compiling properly, and might even work. However, I'm not set up to test Xen i386 under HVM currently. If there are people who are able to do some testing, that would be great -- it wouldn't surprise me if it sort of works but specific things don't. I don't know what those specific things might be. :-) More generally: there are distressing inconsistencies between the i386 and amd64 Xen code in our tree. Some is a natural outcome of supporting full PV on i386 and not amd64, but many are just arbitrarily different file layouts, etc. I think a lot of those can be reduced to our benefit, but the first step is trying to rectify functional inconsistencies. Robert N M Watson Computer Laboratory University of Cambridge Index: conf/options.i386 =================================================================== --- conf/options.i386 (revision 216496) +++ conf/options.i386 (working copy) @@ -118,3 +118,4 @@ NATIVE opt_global.h XEN opt_global.h +XENHVM opt_global.h Index: dev/xen/netfront/netfront.c =================================================================== --- dev/xen/netfront/netfront.c (revision 216496) +++ dev/xen/netfront/netfront.c (working copy) @@ -77,6 +77,7 @@ #include #include +#include #include #include #include Index: dev/xen/blkfront/blkfront.c =================================================================== --- dev/xen/blkfront/blkfront.c (revision 216496) +++ dev/xen/blkfront/blkfront.c (working copy) @@ -51,6 +51,7 @@ #include #include +#include #include #include Index: dev/xen/balloon/balloon.c =================================================================== --- dev/xen/balloon/balloon.c (revision 216496) +++ dev/xen/balloon/balloon.c (working copy) @@ -41,8 +41,8 @@ #include #include +#include #include -#include #include #include Index: dev/xen/xenpci/evtchn.c =================================================================== --- dev/xen/xenpci/evtchn.c (revision 216496) +++ dev/xen/xenpci/evtchn.c (working copy) @@ -51,13 +51,19 @@ #include +#if defined(__i386__) +#define __ffs(word) ffs(word) +#elif defined(__amd64__) static inline unsigned long __ffs(unsigned long word) { __asm__("bsfq %1,%0" :"=r" (word) - :"rm" (word)); + :"rm" (word)); /* XXXRW: why no "cc"? */ return word; } +#else +#error "evtchn: unsupported architecture" +#endif #define is_valid_evtchn(x) ((x) != 0) #define evtchn_from_irq(x) (irq_evtchn[irq].evtchn) Index: i386/include/pcpu.h =================================================================== --- i386/include/pcpu.h (revision 216496) +++ i386/include/pcpu.h (working copy) @@ -44,14 +44,17 @@ * other processors" */ -#ifdef XEN +#if defined(XEN) || defined(XENHVM) #ifndef NR_VIRQS #define NR_VIRQS 24 #endif #ifndef NR_IPIS #define NR_IPIS 2 #endif +#endif +#if defined(XEN) + /* These are peridically updated in shared_info, and then copied here. */ struct shadow_time_info { uint64_t tsc_timestamp; /* TSC at last update of time vals. */ @@ -72,8 +75,18 @@ int pc_callfunc_irq; \ int pc_virq_to_irq[NR_VIRQS]; \ int pc_ipi_to_irq[NR_IPIS] -#else + +#elif defined(XENHVM) + +#define PCPU_XEN_FIELDS \ + ; \ + unsigned int pc_last_processed_l1i; \ + unsigned int pc_last_processed_l2i + +#else /* !XEN && !XENHVM */ + #define PCPU_XEN_FIELDS + #endif #define PCPU_MD_FIELDS \ Index: i386/include/pmap.h =================================================================== --- i386/include/pmap.h (revision 216496) +++ i386/include/pmap.h (working copy) @@ -208,7 +208,7 @@ */ #define vtophys(va) pmap_kextract((vm_offset_t)(va)) -#ifdef XEN +#if defined(XEN) #include #include #include @@ -316,7 +316,9 @@ } return (pa); } +#endif +#if !defined(XEN) #define PT_UPDATES_FLUSH() #endif Index: i386/include/xen/xen-os.h =================================================================== --- i386/include/xen/xen-os.h (revision 216496) +++ i386/include/xen/xen-os.h (working copy) @@ -12,7 +12,7 @@ #define CONFIG_X86_PAE #endif -#if defined(XEN) && !defined(__XEN_INTERFACE_VERSION__) +#if !defined(__XEN_INTERFACE_VERSION__) /* * Can update to a more recent version when we implement * the hypercall page @@ -95,6 +95,8 @@ /* some function prototypes */ void trap_init(void); +#ifndef XENHVM + /* * STI/CLI equivalents. These basically set and clear the virtual * event_enable flag in teh shared_info structure. Note that when @@ -164,6 +166,7 @@ #define spin_lock_irqsave mtx_lock_irqsave #define spin_unlock_irqrestore mtx_unlock_irqrestore +#endif #ifdef SMP #define smp_mb() mb() Index: i386/include/xen/hypercall.h =================================================================== --- i386/include/xen/hypercall.h (revision 216496) +++ i386/include/xen/hypercall.h (working copy) @@ -234,9 +234,14 @@ return _hypercall2(int, memory_op, cmd, arg); } +#if defined(XEN) int HYPERVISOR_multicall(multicall_entry_t *, int); static inline int _HYPERVISOR_multicall( +#else /* XENHVM */ +static inline int +HYPERVISOR_multicall( +#endif void *call_list, int nr_calls) { return _hypercall2(int, multicall, call_list, nr_calls); Index: i386/include/xen/xenvar.h =================================================================== --- i386/include/xen/xenvar.h (revision 216496) +++ i386/include/xen/xenvar.h (working copy) @@ -28,6 +28,11 @@ #ifndef XENVAR_H_ #define XENVAR_H_ + +#include + +#if defined(XEN) + #define XBOOTUP 0x1 #define XPMAP 0x2 extern int xendebug_flags; @@ -36,7 +41,6 @@ #else #define XENPRINTF printf #endif -#include extern xen_pfn_t *xen_phys_machine; extern xen_pfn_t *xen_pfn_to_mfn_frame_list[16]; @@ -101,4 +105,11 @@ void xen_destroy_contiguous_region(void * addr, int npages); +#elif defined(XENHVM) + +#define PFNTOMFN(pa) (pa) +#define MFNTOPFN(ma) (ma) + +#endif /* !XEN && !XENHVM */ + #endif Index: i386/include/xen/xenpmap.h =================================================================== --- i386/include/xen/xenpmap.h (revision 216496) +++ i386/include/xen/xenpmap.h (working copy) @@ -35,6 +35,8 @@ #ifndef _XEN_XENPMAP_H_ #define _XEN_XENPMAP_H_ + +#if defined(XEN) void _xen_queue_pt_update(vm_paddr_t, vm_paddr_t, char *, int); void xen_pt_switch(vm_paddr_t); void xen_set_ldt(vm_paddr_t, unsigned long); @@ -230,5 +232,15 @@ return xen_phys_machine[pfn] != INVALID_P2M_ENTRY; } +#elif defined(XENHVM) +#define set_phys_to_machine(pfn, mfn) ((void)0) +#define phys_to_machine_mapping_valid(pfn) (TRUE) + +#if !defined(PAE) +#define vtomach(va) pmap_kextract((vm_offset_t) (va)) +#endif + +#endif /* !XEN && !XENHVM */ + #endif /* _XEN_XENPMAP_H_ */