Local APIC support for VMX domain
PATCH 1/1 Local APIC support for VMX domain
This patch provide local APIC support for vmx guest.
A configure option is also added to disable it, which is off by default.
Signed-off-by Jiang Yunhong <[email protected]>
Signed-off-by Li Xin <[email protected]>
Signed-off-by Eddie Dong <[email protected]>
Signed-off-by Jun Nakajima <[email protected]>
tools/libxc/xc_vmx_build.c +6 -4
@@ -279,6 +279,7 @@vcpu_guest_context_t *ctxt, unsigned long shared_info_frame, unsigned int control_evtchn, + unsigned int lapic, unsigned int vcpus, unsigned int store_evtchn, unsigned long *store_mfn)
@@ -554,7 +555,7 @@ ctxt->user_regs.eax =0 ; ctxt->user_regs.esp =0 ; ctxt->user_regs.ebx =0 ;/* startup_32 expects this to be 0 to signal boot cpu */ - ctxt->user_regs.ecx =0 ; + ctxt->user_regs.ecx = lapic; ctxt->user_regs.esi =0 ; ctxt->user_regs.edi =0 ; ctxt->user_regs.ebp =0 ;
@@ -597,6 +598,7 @@int memsize, const char *image_name, unsigned int control_evtchn, + unsigned int lapic, unsigned int vcpus, unsigned int store_evtchn, unsigned long *store_mfn)
@@ -651,9 +653,9 @@ goto error_out; } -if (setup_guest (xc_handle, domid, memsize, image, image_size, - nr_pages, ctxt, op.u.getdomaininfo.shared_info_frame, - control_evtchn, vcpus, store_evtchn, store_mfn) <0 ) +if (setup_guest (xc_handle, domid, memsize, image, image_size, nr_pages, + ctxt, op.u.getdomaininfo.shared_info_frame, control_evtchn, + lapic, vcpus, store_evtchn, store_mfn) <0 ) {ERROR ("Error constructing guest OS" ); goto error_out;
tools/libxc/xenguest.h +1 -0
@@ -56,6 +56,7 @@int memsize, const char *image_name, unsigned int control_evtchn, + unsigned int lapic, unsigned int vcpus, unsigned int store_evtchn, unsigned long *store_mfn);
tools/python/xen/lowlevel/xc/xc.c +6 -5
@@ -438,19 +438,20 @@char *image;int control_evtchn, store_evtchn;int vcpus =1 ; +int lapic =0 ;int memsize;unsigned long store_mfn =0 ;static char *kwd_list[] = {"dom" ,"control_evtchn" ,"store_evtchn" , -"memsize" ,"image" ,"vcpus" ,NULL }; - -if ( !PyArg_ParseTupleAndKeywords (args, kwds,"iiiisi" , kwd_list, +"memsize" ,"image" ,"lapic" ,"vcpus" ,NULL }; + +if ( !PyArg_ParseTupleAndKeywords (args, kwds,"iiiisii" , kwd_list, &dom, &control_evtchn, &store_evtchn, - &memsize, &image, &vcpus) ) + &memsize, &image, &lapic, &vcpus) )return NULL ;if (xc_vmx_build (xc->xc_handle, dom, memsize, image, control_evtchn, - vcpus, store_evtchn, &store_mfn) !=0 ) + lapic, vcpus, store_evtchn, &store_mfn) !=0 )return PyErr_SetFromErrno (xc_error);return Py_BuildValue ("{s:i}" ,"store_mfn" , store_mfn);
tools/python/xen/xend/image.py +6 -0
@@ -203,6 +203,10 @@ self.dmargs += self.configVNC(imageConfig) + self.lapic = 0 + lapic = sxp.child_value(imageConfig, 'lapic') + if not lapic is None: + self.lapic = int(lapic) def buildDomain(self): # Create an event channel
@@ -217,6 +221,7 @@ log.debug("control_evtchn = %d", self.device_channel) log.debug("store_evtchn = %d", store_evtchn) log.debug("memsize = %d", self.vm.getMemoryTarget() / 1024) + log.debug("lapic = %d", self.lapic) log.debug("vcpus = %d", self.vm.getVCpuCount()) return xc.vmx_build(dom = self.vm.getDomid(),
@@ -224,6 +229,7 @@ control_evtchn = self.device_channel, store_evtchn = store_evtchn, memsize = self.vm.getMemoryTarget() / 1024, + lapic = self.lapic, vcpus = self.vm.getVCpuCount())
tools/python/xen/xm/create.py +7 -7
@@ -158,6 +158,10 @@ fn=set_int, default=None, use="CPU to run the domain on.") +gopts.var('lapic', val='LAPIC', + fn=set_int, default=0, + use="Disable or enable local APIC of VMX domain.") + gopts.var('vcpus', val='VCPUS', fn=set_int, default=1, use="# of Virtual CPUS in domain.")
@@ -315,10 +319,6 @@ gopts.var('nfs_root', val="PATH", fn=set_value, default=None, use="Set the path of the root NFS directory.") - -gopts.var('memmap', val='FILE', - fn=set_value, default='', - use="Path to memap SXP file.") gopts.var('device_model', val='FILE', fn=set_value, default='',
@@ -542,9 +542,9 @@ def configure_vmx(opts, config_image, vals): """Create the config for VMX devices. """ - args = [ 'memmap', 'device_model', 'vcpus', 'cdrom', - 'boot', 'fda', 'fdb', 'localtime', 'serial', 'macaddr', 'stdvga', - 'isa', 'nographic', 'vnc', 'vncviewer', 'sdl', 'display', 'ne2000'] + args = [ 'device_model', 'vcpus', 'cdrom', 'boot', 'fda', 'fdb', + 'localtime', 'serial', 'macaddr', 'stdvga', 'isa', 'nographic', + 'vnc', 'vncviewer', 'sdl', 'display', 'ne2000', 'lapic'] for a in args: if (vals.__dict__[a]): config_image.append([a, vals.__dict__[a]])
xen/arch/x86/apic.c +4 -0
@@ -815,6 +815,10 @@return result; } +unsigned int get_apic_bus_scale (void ) +{ +return bus_scale; +}static unsigned int calibration_result;
xen/arch/x86/dm/i8259.c +11 -4
@@ -32,8 +32,8 @@#include <public/io/ioreq.h> #include <asm/vmx.h> #include <public/io/vmx_vpic.h> -#include <public/io/vmx_vlapic.h> #include <asm/current.h> +#include <asm/vmx_vlapic.h> /* set irq level. If an edge is detected, then the IRR is set to 1 */ static inline void pic_set_irq1 (PicState *s,int irq,int level)
@@ -135,7 +135,6 @@ { s->pics[1 ].irr |= (uint8_t )(irqs >>8 ); s->pics[0 ].irr |= (uint8_t ) irqs; -/* TODO for alt_irq_func */ pic_update_irq (s); }
@@ -505,14 +504,22 @@ {int intno;struct vmx_virpic *s = &v->domain->arch.vmx_platform.vmx_pic; - +struct vmx_platform *plat = &v->domain->arch.vmx_platform; + +if ( !vlapic_accept_pic_intr (v) ) +return -1 ; + +if ( !plat->interrupt_request ) +return -1 ; +/* read the irq from the PIC */ intno =pic_read_irq (s); *type =VLAPIC_DELIV_MODE_EXT ; + plat->interrupt_request =0 ;return intno; } -int is_pit_irq (struct vcpu *v,int irq) +int is_pit_irq (struct vcpu *v,int irq,int type) {int pit_vec = v->domain->arch.vmx_platform.vmx_pic.pics[0 ].irq_base;
xen/arch/x86/vmx.c +24 -1
@@ -65,6 +65,11 @@if ( v == v->domain->vcpu[0 ] ) { + v->domain->arch.vmx_platform.lapic_enable = + v->arch.guest_context.user_regs.ecx; + v->arch.guest_context.user_regs.ecx =0 ; +VMX_DBG_LOG (DBG_LEVEL_VLAPIC ,"lapic enable is %d.\n" , + v->domain->arch.vmx_platform.lapic_enable);/* * Required to do this once per domain * XXX todo: add a seperate function to do these.
@@ -96,6 +101,10 @@destroy_vmcs (&v->arch.arch_vmx);free_monitor_pagetable (v);rem_ac_timer (&v->domain->arch.vmx_platform.vmx_pit.pit_timer); +if (vmx_apic_support (v->domain) ) { +rem_ac_timer ( &(VLAPIC (v)->vlapic_timer) ); +xfree (VLAPIC (v) ); + } }#ifdef __x86_64__
@@ -442,7 +451,9 @@/* Use 1:1 page table to identify MMIO address space */ if (mmio_space (gpa) ){ -if (gpa >=0xFEE00000 ) {/* workaround for local APIC */ +struct vcpu *v = current; +/* No support for APIC */ +if (!vmx_apic_support (v->domain) && gpa >=0xFEC00000 ) {u32 inst_len;__vmread (VM_EXIT_INSTRUCTION_LEN , &(inst_len));__update_guest_eip (inst_len);
@@ -487,6 +498,7 @@ {unsigned int eax, ebx, ecx, edx;unsigned long eip; +struct vcpu *v = current;__vmread (GUEST_RIP , &eip);
@@ -500,6 +512,9 @@cpuid (input, &eax, &ebx, &ecx, &edx);if (input ==1 ) { +if (vmx_apic_support (v->domain) && + !vlapic_global_enabled ((VLAPIC (v))) ) +clear_bit (X86_FEATURE_APIC , &edx);#ifdef __i386__clear_bit (X86_FEATURE_PSE , &edx);clear_bit (X86_FEATURE_PAE , &edx);
@@ -1441,6 +1456,7 @@static inline void vmx_do_msr_read (struct cpu_user_regs *regs) {u64 msr_content =0 ; +struct vcpu *v = current; VMX_DBG_LOG(DBG_LEVEL_1, "vmx_do_msr_read: ecx=%lx, eax=%lx, edx=%lx", (unsigned long)regs->ecx, (unsigned long)regs->eax,
@@ -1455,6 +1471,9 @@case MSR_IA32_SYSENTER_EIP :__vmread (GUEST_SYSENTER_EIP , &msr_content);break ; +case MSR_IA32_APICBASE : + msr_content =VLAPIC (v) ?VLAPIC (v)->apic_base_msr :0 ; +break ;default :if (long_mode_do_msr_read (regs))return ;
@@ -1474,6 +1493,7 @@static inline void vmx_do_msr_write (struct cpu_user_regs *regs) {u64 msr_content; +struct vcpu *v = current; VMX_DBG_LOG(DBG_LEVEL_1, "vmx_do_msr_write: ecx=%lx, eax=%lx, edx=%lx", (unsigned long)regs->ecx, (unsigned long)regs->eax,
@@ -1490,6 +1510,9 @@break ;case MSR_IA32_SYSENTER_EIP :__vmwrite (GUEST_SYSENTER_EIP , msr_content); +break ; +case MSR_IA32_APICBASE : +vlapic_msr_set (VLAPIC (v), msr_content);break ;default :long_mode_do_msr_write (regs);
xen/arch/x86/vmx_intercept.c +118 -0
130 lines not on this page · raw message
xen/arch/x86/vmx_io.c +47 -71
168 lines not on this page · raw message
xen/arch/x86/vmx_vmcs.c +7 -0
@@ -252,6 +252,10 @@pic_init (&platform->vmx_pic, pic_irq_request, &platform->interrupt_request);register_pic_io_hook (); + +if (vmx_apic_support (d) ) { +spin_lock_init (&d->arch.vmx_platform.round_robin_lock); + } }static void vmx_set_host_env (struct vcpu *v)
@@ -312,6 +316,9 @@ error |=__vmwrite (CR4_READ_SHADOW , cr4);vmx_stts (); + +if (vmx_apic_support (v->domain)) +vlapic_init (v);vmx_set_host_env (v);
xen/include/asm-x86/vmx_intercept.h +21 -11
@@ -14,6 +14,16 @@#define VMX_MMIO 1typedef int (*intercept_action_t )(ioreq_t *); +typedef unsigned long (*vmx_mmio_read_t )(struct vcpu *v, +unsigned long addr, +unsigned long length); + +typedef unsigned long (*vmx_mmio_write_t )(struct vcpu *v, +unsigned long addr, +unsigned long length, +unsigned long val); + +typedef int (*vmx_mmio_check_t )(struct vcpu *v,unsigned long addr);struct io_handler {int type;
@@ -27,6 +37,16 @@struct io_handler hdl_list[MAX_IO_HANDLER ]; }; +struct vmx_mmio_handler { +vmx_mmio_check_t check_handler; +vmx_mmio_read_t read_handler; +vmx_mmio_write_t write_handler; +}; + +#define VMX_MMIO_HANDLER_NR 1 + +extern struct vmx_mmio_handler vmx_mmio_handers[VMX_MMIO_HANDLER_NR ]; +/* global io interception point in HV */ extern int vmx_io_intercept (ioreq_t *p,int type); extern int register_io_handler(unsigned long addr, unsigned long size,
@@ -37,10 +57,7 @@return vmx_io_intercept (p,VMX_PORTIO ); } -static inline int vmx_mmio_intercept (ioreq_t *p) -{ -return vmx_io_intercept (p,VMX_MMIO ); -} +int vmx_mmio_intercept (ioreq_t *p); static inline int register_portio_handler(unsigned long addr, unsigned long size,
@@ -49,11 +66,4 @@ return register_io_handler(addr, size, action, VMX_PORTIO); } -static inline int register_mmio_handler (unsigned long addr, -unsigned long size, -intercept_action_t action) -{ -return register_io_handler (addr, size, action,VMX_MMIO ); -} -#endif /* _VMX_INTERCEPT_H */
xen/include/asm-x86/vmx_platform.h +3 -0
@@ -80,10 +80,13 @@struct vmx_platform {unsigned long shared_page_va;unsigned int nr_vcpu; +unsigned int lapic_enable;struct vmx_virpit vmx_pit;struct vmx_io_handler vmx_io_handler;struct vmx_virpic vmx_pic; +unsigned char round_info[256 ]; +spinlock_t round_robin_lock;int interrupt_request; };
xen/include/asm-x86/vmx_vmcs.h +12 -7
@@ -22,6 +22,7 @@#include <asm/config.h> #include <asm/vmx_cpu.h> #include <asm/vmx_platform.h> +#include <asm/vmx_vlapic.h> #include <public/vmx_assist.h> extern int start_vmx (void );
@@ -96,6 +97,7 @@struct msr_state msr_content;struct mmio_op mmio_op;/* MMIO */ void *io_bitmap_a, *io_bitmap_b; +struct vlapic *vlapic;u64 tsc_offset; };
@@ -272,18 +274,21 @@#define VMX_DEBUG 1#if VMX_DEBUG -#define DBG_LEVEL_0 (1 << 0) -#define DBG_LEVEL_1 (1 << 1) -#define DBG_LEVEL_2 (1 << 2) -#define DBG_LEVEL_3 (1 << 3) -#define DBG_LEVEL_IO (1 << 4) -#define DBG_LEVEL_VMMU (1 << 5) +#define DBG_LEVEL_0 (1 << 0) +#define DBG_LEVEL_1 (1 << 1) +#define DBG_LEVEL_2 (1 << 2) +#define DBG_LEVEL_3 (1 << 3) +#define DBG_LEVEL_IO (1 << 4) +#define DBG_LEVEL_VMMU (1 << 5) +#define DBG_LEVEL_VLAPIC (1 << 6) +#define DBG_LEVEL_VLAPIC_TIMER (1 << 7) +#define DBG_LEVEL_VLAPIC_INTERRUPT (1 << 7)extern unsigned int opt_vmx_debug_level; #define VMX_DBG_LOG(level, _f, _a...) \ if ((level) & opt_vmx_debug_level) \ printk("[VMX:%d.%d] " _f "\n", \ - current->domain->domain_id, current->vcpu_id, ## _a) + current->domain->domain_id, current->vcpu_id, ## _a)#else #define VMX_DBG_LOG(level, _f, _a...)#endif
xen/include/public/io/ioreq.h +7 -6
@@ -29,11 +29,11 @@#define STATE_IORESP_READY 3#define STATE_IORESP_HOOK 4 -#define IOREQ_TYPE_PIO 0/* pio */ -#define IOREQ_TYPE_COPY 1/* mmio ops */ -#define IOREQ_TYPE_AND 2 -#define IOREQ_TYPE_OR 3 -#define IOREQ_TYPE_XOR 4 +#define IOREQ_TYPE_PIO 0/* pio */ +#define IOREQ_TYPE_COPY 1/* mmio ops */ +#define IOREQ_TYPE_AND 2 +#define IOREQ_TYPE_OR 3 +#define IOREQ_TYPE_XOR 4/* * VMExit dispatcher should cooperate with instruction decoder to
@@ -55,9 +55,10 @@uint8_t type;/* I/O type */ } ioreq_t; -#define MAX_VECTOR 256 +#define MAX_VECTOR 256#define BITS_PER_BYTE 8#define INTR_LEN (MAX_VECTOR/(BITS_PER_BYTE * sizeof(uint64_t))) +#define INTR_LEN_32 (MAX_VECTOR/(BITS_PER_BYTE * sizeof(uint32_t))) typedef struct { uint16_t pic_elcr;
xen/include/public/io/vmx_vpic.h +1 -1
@@ -76,7 +76,7 @@uint32_t pic_intack_read (struct vmx_virpic *s);void register_pic_io_hook (void );int cpu_get_pic_interrupt (struct vcpu *v,int *type); -int is_pit_irq (struct vcpu *v,int irq); +int is_pit_irq (struct vcpu *v,int irq,int type);void do_pic_irqs (struct vmx_virpic *s,uint16_t irqs);void do_pic_irqs_clear (struct vmx_virpic *s,uint16_t irqs);
xen/arch/x86/vmx_vlapic.c new file +997 -0
997 lines not on this page · raw message
xen/include/asm-x86/vmx_vlapic.h new file +245 -0
245 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel