x86: split struct vcpu
PATCH 2/6 x86: split struct vcpu
This is accomplished by splitting the guest_context member, which by itself is larger than a page on x86-64. Quite a number of fields of this structure is completely meaningless for HVM guests, and thus a new struct pv_vcpu gets introduced, which is being overlaid with struct hvm_vcpu in struct arch_vcpu. The one member that is mostly responsible for the large size is trap_ctxt, which now gets allocated separately (unless fitting on the same page as struct arch_vcpu, as is currently the case for x86-32), and only for non-hvm, non-idle domains.
This change pointed out a latent problem in arch_set_info_guest(), which is permitted to be called on already initialized vCPU-s, but so far copied the new state into struct arch_vcpu without (in this case) actually going through all the necessary accounting/validation steps. The logic gets changed so that the pieces that bypass accounting will at least be verified to be no different from the currently active bits, and the whole change will fail in case they are. The logic does *not* get adjusted here to do full error recovery, that is, partially modified state continues to not get unrolled in case of failure.
xen/arch/x86/acpi/suspend.c +7 -7
@@ -87,14 +87,14 @@ void restore_rest_processor_state(void)/* Maybe load the debug registers. */ BUG_ON (is_hvm_vcpu (curr)); -if ( !is_idle_vcpu (curr) && curr->arch.guest_context.debugreg[7 ] ) +if ( !is_idle_vcpu (curr) && curr->arch.debugreg[7 ] ) { -write_debugreg (0 , curr->arch.guest_context.debugreg[0 ]); -write_debugreg (1 , curr->arch.guest_context.debugreg[1 ]); -write_debugreg (2 , curr->arch.guest_context.debugreg[2 ]); -write_debugreg (3 , curr->arch.guest_context.debugreg[3 ]); -write_debugreg (6 , curr->arch.guest_context.debugreg[6 ]); -write_debugreg (7 , curr->arch.guest_context.debugreg[7 ]); +write_debugreg (0 , curr->arch.debugreg[0 ]); +write_debugreg (1 , curr->arch.debugreg[1 ]); +write_debugreg (2 , curr->arch.debugreg[2 ]); +write_debugreg (3 , curr->arch.debugreg[3 ]); +write_debugreg (6 , curr->arch.debugreg[6 ]); +write_debugreg (7 , curr->arch.debugreg[7 ]); }/* Reload FPU state on next FPU use. */
xen/arch/x86/domain.c +225 -102
577 lines not on this page · raw message
xen/arch/x86/domain_build.c +9 -9
@@ -731,8 +731,8 @@ int __init construct_dom0(if (is_pv_32on64_domain (d) ) { - v->arch.guest_context.failsafe_callback_cs =FLAT_COMPAT_KERNEL_CS ; - v->arch.guest_context.event_callback_cs =FLAT_COMPAT_KERNEL_CS ; + v->arch.pv_vcpu.failsafe_callback_cs =FLAT_COMPAT_KERNEL_CS ; + v->arch.pv_vcpu.event_callback_cs =FLAT_COMPAT_KERNEL_CS ; }/* WARNING: The new domain must have its 'processor' field filled in! */
@@ -1160,7 +1160,7 @@ int __init construct_dom0(* ESI = start_info * [EAX,EBX,ECX,EDX,EDI,EBP are zero] */ - regs = &v->arch.guest_context.user_regs; + regs = &v->arch.user_regs; regs->ds = regs->es = regs->fs = regs->gs = !is_pv_32on64_domain (d) ?FLAT_KERNEL_DS :FLAT_COMPAT_KERNEL_DS ; regs->ss = (!is_pv_32on64_domain(d) ?
@@ -1178,12 +1178,12 @@ int __init construct_dom0(if ( supervisor_mode_kernel ) { - v->arch.guest_context.kernel_ss &= ~3 ; - v->arch.guest_context.user_regs.ss &= ~3 ; - v->arch.guest_context.user_regs.es &= ~3 ; - v->arch.guest_context.user_regs.ds &= ~3 ; - v->arch.guest_context.user_regs.fs &= ~3 ; - v->arch.guest_context.user_regs.gs &= ~3 ; + v->arch.pv_vcpu.kernel_ss &= ~3 ; + v->arch.user_regs.ss &= ~3 ; + v->arch.user_regs.es &= ~3 ; + v->arch.user_regs.ds &= ~3 ; + v->arch.user_regs.fs &= ~3 ; + v->arch.user_regs.gs &= ~3 ;printk ("Dom0 runs in ring 0 (supervisor mode)\n" );if ( !test_bit (XENFEAT_supervisor_mode_kernel, parms.f_supported) )
xen/arch/x86/domctl.c +70 -17
126 lines not on this page · raw message
xen/arch/x86/hvm/hvm.c +61 -66
196 lines not on this page · raw message
xen/arch/x86/hvm/svm/svm.c +13 -13
@@ -117,12 +117,12 @@ static void svm_save_dr(struct vcpu *v) v->arch.hvm_vcpu.flag_dr_dirty =0 ;vmcb_set_dr_intercepts (vmcb, ~0u ); - v->arch.guest_context.debugreg[0 ] =read_debugreg (0 ); - v->arch.guest_context.debugreg[1 ] =read_debugreg (1 ); - v->arch.guest_context.debugreg[2 ] =read_debugreg (2 ); - v->arch.guest_context.debugreg[3 ] =read_debugreg (3 ); - v->arch.guest_context.debugreg[6 ] =vmcb_get_dr6 (vmcb); - v->arch.guest_context.debugreg[7 ] =vmcb_get_dr7 (vmcb); + v->arch.debugreg[0 ] =read_debugreg (0 ); + v->arch.debugreg[1 ] =read_debugreg (1 ); + v->arch.debugreg[2 ] =read_debugreg (2 ); + v->arch.debugreg[3 ] =read_debugreg (3 ); + v->arch.debugreg[6 ] =vmcb_get_dr6 (vmcb); + v->arch.debugreg[7 ] =vmcb_get_dr7 (vmcb); }static void __restore_debug_registers (struct vcpu *v)
@@ -135,12 +135,12 @@ static void __restore_debug_registers(st v->arch.hvm_vcpu.flag_dr_dirty =1 ;vmcb_set_dr_intercepts (vmcb,0 ); -write_debugreg (0 , v->arch.guest_context.debugreg[0 ]); -write_debugreg (1 , v->arch.guest_context.debugreg[1 ]); -write_debugreg (2 , v->arch.guest_context.debugreg[2 ]); -write_debugreg (3 , v->arch.guest_context.debugreg[3 ]); -vmcb_set_dr6 (vmcb, v->arch.guest_context.debugreg[6 ]); -vmcb_set_dr7 (vmcb, v->arch.guest_context.debugreg[7 ]); +write_debugreg (0 , v->arch.debugreg[0 ]); +write_debugreg (1 , v->arch.debugreg[1 ]); +write_debugreg (2 , v->arch.debugreg[2 ]); +write_debugreg (3 , v->arch.debugreg[3 ]); +vmcb_set_dr6 (vmcb, v->arch.debugreg[6 ]); +vmcb_set_dr7 (vmcb, v->arch.debugreg[7 ]); }/*
@@ -151,7 +151,7 @@ static void __restore_debug_registers(st*/ static void svm_restore_dr (struct vcpu *v) { -if (unlikely (v->arch.guest_context.debugreg[7 ] &DR7_ACTIVE_MASK ) ) +if (unlikely (v->arch.debugreg[7 ] &DR7_ACTIVE_MASK ) )__restore_debug_registers (v); }
xen/arch/x86/hvm/vmx/vmcs.c +1 -1
@@ -1128,7 +1128,7 @@ static void vmx_dump_sel2(char *name, uivoid vmcs_dump_vcpu (struct vcpu *v) { -struct cpu_user_regs *regs = &v->arch.guest_context.user_regs; +struct cpu_user_regs *regs = &v->arch.user_regs;unsigned long long x;if ( v == current )
xen/arch/x86/hvm/vmx/vmx.c +15 -15
@@ -132,7 +132,7 @@ static int vmx_vcpu_initialise(struct vc/* %eax == 1 signals full real-mode support to the guest loader. */ if ( v->vcpu_id ==0 ) - v->arch.guest_context.user_regs.eax =1 ; + v->arch.user_regs.eax =1 ;return 0 ; }
@@ -400,13 +400,13 @@ static void vmx_save_dr(struct vcpu *v) v->arch.hvm_vmx.exec_control |=CPU_BASED_MOV_DR_EXITING ;vmx_update_cpu_exec_control (v); - v->arch.guest_context.debugreg[0 ] =read_debugreg (0 ); - v->arch.guest_context.debugreg[1 ] =read_debugreg (1 ); - v->arch.guest_context.debugreg[2 ] =read_debugreg (2 ); - v->arch.guest_context.debugreg[3 ] =read_debugreg (3 ); - v->arch.guest_context.debugreg[6 ] =read_debugreg (6 ); + v->arch.debugreg[0 ] =read_debugreg (0 ); + v->arch.debugreg[1 ] =read_debugreg (1 ); + v->arch.debugreg[2 ] =read_debugreg (2 ); + v->arch.debugreg[3 ] =read_debugreg (3 ); + v->arch.debugreg[6 ] =read_debugreg (6 );/* DR7 must be saved as it is used by vmx_restore_dr(). */ - v->arch.guest_context.debugreg[7 ] =__vmread (GUEST_DR7 ); + v->arch.debugreg[7 ] =__vmread (GUEST_DR7 ); }static void __restore_debug_registers (struct vcpu *v)
@@ -416,11 +416,11 @@ static void __restore_debug_registers(st v->arch.hvm_vcpu.flag_dr_dirty =1 ; -write_debugreg (0 , v->arch.guest_context.debugreg[0 ]); -write_debugreg (1 , v->arch.guest_context.debugreg[1 ]); -write_debugreg (2 , v->arch.guest_context.debugreg[2 ]); -write_debugreg (3 , v->arch.guest_context.debugreg[3 ]); -write_debugreg (6 , v->arch.guest_context.debugreg[6 ]); +write_debugreg (0 , v->arch.debugreg[0 ]); +write_debugreg (1 , v->arch.debugreg[1 ]); +write_debugreg (2 , v->arch.debugreg[2 ]); +write_debugreg (3 , v->arch.debugreg[3 ]); +write_debugreg (6 , v->arch.debugreg[6 ]);/* DR7 is loaded from the VMCS. */ }
@@ -433,7 +433,7 @@ static void __restore_debug_registers(ststatic void vmx_restore_dr (struct vcpu *v) {/* NB. __vmread() is not usable here, so we cannot read from the VMCS. */ -if (unlikely (v->arch.guest_context.debugreg[7 ] &DR7_ACTIVE_MASK ) ) +if (unlikely (v->arch.debugreg[7 ] &DR7_ACTIVE_MASK ) )__restore_debug_registers (v); }
@@ -1352,7 +1352,7 @@ static void vmx_set_info_guest(struct vcvmx_vmcs_enter (v); -__vmwrite (GUEST_DR7 , v->arch.guest_context.debugreg[7 ]); +__vmwrite (GUEST_DR7 , v->arch.debugreg[7 ]);/* * If the interruptibility-state field indicates blocking by STI,
@@ -1364,7 +1364,7 @@ static void vmx_set_info_guest(struct vc*/ intr_shadow =__vmread (GUEST_INTERRUPTIBILITY_INFO );if ( v->domain->debugger_attached && - (v->arch.guest_context.user_regs.eflags &X86_EFLAGS_TF ) && + (v->arch.user_regs.eflags &X86_EFLAGS_TF ) && (intr_shadow &VMX_INTR_SHADOW_STI ) ) { intr_shadow &= ~VMX_INTR_SHADOW_STI ;
xen/arch/x86/i387.c +4 -4
@@ -110,7 +110,7 @@ void save_init_fpu(struct vcpu *v)ASSERT (!is_idle_vcpu (v)); cr0 =read_cr0 (); - fpu_ctxt = v->arch.guest_context.fpu_ctxt.x; + fpu_ctxt = v->arch.fpu_ctxt;/* This can happen, if a paravirtualised guest OS has set its CR0.TS. */ if ( cr0 &X86_CR0_TS )
@@ -176,7 +176,7 @@ void save_init_fpu(struct vcpu *v)static void restore_fpu (struct vcpu *v) { -char *fpu_ctxt = v->arch.guest_context.fpu_ctxt.x; +const char *fpu_ctxt = v->arch.fpu_ctxt;/* * FXRSTOR can fault if passed a corrupted data block. We handle this
@@ -208,7 +208,7 @@ static void restore_fpu(struct vcpu *v) _ASM_EXTABLE(1b, 2b) : : "m" (*fpu_ctxt), - "i" (sizeof(v->arch.guest_context.fpu_ctxt)/4) + "i" (sizeof(v->arch.xsave_area->fpu_sse)/4)#ifdef __x86_64__ ,"cdaSDb" (fpu_ctxt)#endif
@@ -216,7 +216,7 @@ static void restore_fpu(struct vcpu *v) }else { - asmvolatile ("frstor %0" : :"m" (v->arch.guest_context.fpu_ctxt) ); + asmvolatile ("frstor %0" : :"m" (*fpu_ctxt) ); } }
xen/arch/x86/mm.c +9 -9
@@ -646,7 +646,7 @@ int map_ldt_shadow_page(unsigned int offstruct domain *d = v->domain;unsigned long gmfn, mfn;l1_pgentry_t l1e, nl1e; -unsigned long gva = v->arch.guest_context.ldt_base + (off <<PAGE_SHIFT ); +unsigned long gva = v->arch.pv_vcpu.ldt_base + (off <<PAGE_SHIFT );int okay;BUG_ON (unlikely (in_irq ()));
@@ -3220,13 +3220,13 @@ int do_mmuext_op( okay =0 ;MEM_LOG ("Bad args to SET_LDT: ptr=%lx, ents=%lx" , ptr, ents); } -else if ( (curr->arch.guest_context.ldt_ents != ents) || - (curr->arch.guest_context.ldt_base != ptr) ) +else if ( (curr->arch.pv_vcpu.ldt_ents != ents) || + (curr->arch.pv_vcpu.ldt_base != ptr) ) {invalidate_shadow_ldt (curr,0 );flush_tlb_local (); - curr->arch.guest_context.ldt_base = ptr; - curr->arch.guest_context.ldt_ents = ents; + curr->arch.pv_vcpu.ldt_base = ptr; + curr->arch.pv_vcpu.ldt_ents = ents;load_LDT (curr);if ( ents !=0 ) (void )map_ldt_shadow_page (0 );
@@ -4416,13 +4416,13 @@ void destroy_gdt(struct vcpu *v)int i;unsigned long pfn; - v->arch.guest_context.gdt_ents =0 ; + v->arch.pv_vcpu.gdt_ents =0 ;for ( i =0 ; i <FIRST_RESERVED_GDT_PAGE ; i++ ) {if ( (pfn =l1e_get_pfn (v->arch.perdomain_ptes[i])) !=0 )put_page_and_type (mfn_to_page (pfn));l1e_write (&v->arch.perdomain_ptes[i],l1e_empty ()); - v->arch.guest_context.gdt_frames[i] =0 ; + v->arch.pv_vcpu.gdt_frames[i] =0 ; } }
@@ -4452,10 +4452,10 @@ long set_gdt(struct vcpu *v,destroy_gdt (v);/* Install the new GDT. */ - v->arch.guest_context.gdt_ents = entries; + v->arch.pv_vcpu.gdt_ents = entries;for ( i =0 ; i < nr_pages; i++ ) { - v->arch.guest_context.gdt_frames[i] = frames[i]; + v->arch.pv_vcpu.gdt_frames[i] = frames[i];l1e_write (&v->arch.perdomain_ptes[i],l1e_from_pfn (frames[i], __PAGE_HYPERVISOR)); }
xen/arch/x86/traps.c +59 -59
350 lines not on this page · raw message
xen/arch/x86/x86_32/asm-offsets.c +7 -11
@@ -55,19 +55,15 @@ void __dummy__(void) OFFSET(VCPU_vcpu_info, struct vcpu, vcpu_info); OFFSET(VCPU_trap_bounce, struct vcpu, arch.trap_bounce); OFFSET(VCPU_thread_flags, struct vcpu, arch.flags); - OFFSET(VCPU_event_sel, struct vcpu, - arch.guest_context.event_callback_cs); - OFFSET(VCPU_event_addr, struct vcpu, - arch.guest_context.event_callback_eip); + OFFSET(VCPU_event_sel, struct vcpu, arch.pv_vcpu.event_callback_cs); + OFFSET(VCPU_event_addr, struct vcpu, arch.pv_vcpu.event_callback_eip); OFFSET(VCPU_failsafe_sel, struct vcpu, - arch.guest_context.failsafe_callback_cs); + arch.pv_vcpu.failsafe_callback_cs); OFFSET(VCPU_failsafe_addr, struct vcpu, - arch.guest_context.failsafe_callback_eip); - OFFSET(VCPU_kernel_ss, struct vcpu, - arch.guest_context.kernel_ss); - OFFSET(VCPU_kernel_sp, struct vcpu, - arch.guest_context.kernel_sp); - OFFSET(VCPU_guest_context_flags, struct vcpu, arch.guest_context.flags); + arch.pv_vcpu.failsafe_callback_eip); + OFFSET(VCPU_kernel_ss, struct vcpu, arch.pv_vcpu.kernel_ss); + OFFSET(VCPU_kernel_sp, struct vcpu, arch.pv_vcpu.kernel_sp); + OFFSET(VCPU_guest_context_flags, struct vcpu, arch.vgc_flags); OFFSET(VCPU_nmi_pending, struct vcpu, nmi_pending); OFFSET(VCPU_mce_pending, struct vcpu, mce_pending); OFFSET(VCPU_nmi_old_mask, struct vcpu, nmi_state.old_mask);
xen/arch/x86/x86_32/mm.c +2 -2
@@ -252,8 +252,8 @@ long do_stack_switch(unsigned long ss, ufixup_guest_stack_selector (current->domain, ss); - current->arch.guest_context.kernel_ss = ss; - current->arch.guest_context.kernel_sp = esp; + current->arch.pv_vcpu.kernel_ss = ss; + current->arch.pv_vcpu.kernel_sp = esp; t->ss1 = ss; t->esp1 = esp;
xen/arch/x86/x86_32/seg_fixup.c +9 -9
@@ -175,13 +175,13 @@ static int get_baselimit(u16 seg, unsignif ( ldt ) { table = (uint32_t *)LDT_VIRT_START (curr); -if ( idx >= curr->arch.guest_context.ldt_ents ) +if ( idx >= curr->arch.pv_vcpu.ldt_ents ) goto fail; }else /* gdt */ { table = (uint32_t *)GDT_VIRT_START (curr); -if ( idx >= curr->arch.guest_context.gdt_ents ) +if ( idx >= curr->arch.pv_vcpu.gdt_ents ) goto fail; }
@@ -241,20 +241,20 @@ static int fixup_seg(u16 seg, unsigned lif ( ldt ) { table = (uint32_t *)LDT_VIRT_START (curr); -if ( idx >= curr->arch.guest_context.ldt_ents ) +if ( idx >= curr->arch.pv_vcpu.ldt_ents ) { -dprintk (XENLOG_DEBUG ,"Segment %04x out of LDT range (%ld)\n" , - seg, curr->arch.guest_context.ldt_ents); +dprintk (XENLOG_DEBUG ,"Segment %04x out of LDT range (%u)\n" , + seg, curr->arch.pv_vcpu.ldt_ents); goto fail; } }else /* gdt */ { table = (uint32_t *)GDT_VIRT_START (curr); -if ( idx >= curr->arch.guest_context.gdt_ents ) +if ( idx >= curr->arch.pv_vcpu.gdt_ents ) { -dprintk (XENLOG_DEBUG ,"Segment %04x out of GDT range (%ld)\n" , - seg, curr->arch.guest_context.gdt_ents); +dprintk (XENLOG_DEBUG ,"Segment %04x out of GDT range (%u)\n" , + seg, curr->arch.pv_vcpu.gdt_ents); goto fail; } }
@@ -545,7 +545,7 @@ int gpf_emulate_4gb(struct cpu_user_regs/* If requested, give a callback on otherwise unused vector 15. */ if (VM_ASSIST (curr->domain, VMASST_TYPE_4gb_segments_notify) ) { -struct trap_info *ti = &curr->arch.guest_context.trap_ctxt[15 ]; +struct trap_info *ti = &curr->arch.pv_vcpu.trap_ctxt[15 ];struct trap_bounce *tb = &curr->arch.trap_bounce; tb->flags =TBF_EXCEPTION |TBF_EXCEPTION_ERRCODE ;
xen/arch/x86/x86_32/traps.c +10 -10
@@ -141,12 +141,12 @@ void vcpu_show_registers(const struct vcif (is_hvm_vcpu (v) )return ; - crs[0 ] = v->arch.guest_context.ctrlreg[0 ]; + crs[0 ] = v->arch.pv_vcpu.ctrlreg[0 ]; crs[2 ] = v->vcpu_info->arch.cr2; crs[3 ] =pagetable_get_paddr (v->arch.guest_table); - crs[4 ] = v->arch.guest_context.ctrlreg[4 ]; + crs[4 ] = v->arch.pv_vcpu.ctrlreg[4 ]; -_show_registers (&v->arch.guest_context.user_regs, crs, CTXT_pv_guest, v); +_show_registers (&v->arch.user_regs, crs, CTXT_pv_guest, v); }void show_page_walk (unsigned long addr)
@@ -372,7 +372,7 @@ void __devinit subarch_percpu_traps_initvoid init_int80_direct_trap (struct vcpu *v) { -struct trap_info *ti = &v->arch.guest_context.trap_ctxt[0x80 ]; +struct trap_info *ti = &v->arch.pv_vcpu.trap_ctxt[0x80 ];/* * We can't virtualise interrupt gates, as there's no way to get
@@ -419,19 +419,19 @@ static long register_guest_callback(struswitch ( reg->type ) {case CALLBACKTYPE_event: - v->arch.guest_context.event_callback_cs = reg->address.cs; - v->arch.guest_context.event_callback_eip = reg->address.eip; + v->arch.pv_vcpu.event_callback_cs = reg->address.cs; + v->arch.pv_vcpu.event_callback_eip = reg->address.eip;break ;case CALLBACKTYPE_failsafe: - v->arch.guest_context.failsafe_callback_cs = reg->address.cs; - v->arch.guest_context.failsafe_callback_eip = reg->address.eip; + v->arch.pv_vcpu.failsafe_callback_cs = reg->address.cs; + v->arch.pv_vcpu.failsafe_callback_eip = reg->address.eip;if ( reg->flags & CALLBACKF_mask_events )set_bit (_VGCF_failsafe_disables_events, - &v->arch.guest_context.flags); + &v->arch.vgc_flags);else clear_bit (_VGCF_failsafe_disables_events, - &v->arch.guest_context.flags); + &v->arch.vgc_flags);break ;#ifdef CONFIG_X86_SUPERVISOR_MODE_KERNEL
xen/arch/x86/x86_64/asm-offsets.c +14 -14
@@ -68,16 +68,14 @@ void __dummy__(void) OFFSET(VCPU_trap_bounce, struct vcpu, arch.trap_bounce); OFFSET(VCPU_int80_bounce, struct vcpu, arch.int80_bounce); OFFSET(VCPU_thread_flags, struct vcpu, arch.flags); - OFFSET(VCPU_event_addr, struct vcpu, - arch.guest_context.event_callback_eip); - OFFSET(VCPU_event_sel, struct vcpu, - arch.guest_context.event_callback_cs); + OFFSET(VCPU_event_addr, struct vcpu, arch.pv_vcpu.event_callback_eip); + OFFSET(VCPU_event_sel, struct vcpu, arch.pv_vcpu.event_callback_cs); OFFSET(VCPU_failsafe_addr, struct vcpu, - arch.guest_context.failsafe_callback_eip); + arch.pv_vcpu.failsafe_callback_eip); OFFSET(VCPU_failsafe_sel, struct vcpu, - arch.guest_context.failsafe_callback_cs); + arch.pv_vcpu.failsafe_callback_cs); OFFSET(VCPU_syscall_addr, struct vcpu, - arch.guest_context.syscall_callback_eip); + arch.pv_vcpu.syscall_callback_eip); OFFSET(VCPU_syscall32_addr, struct vcpu, arch.syscall32_callback_eip); OFFSET(VCPU_syscall32_sel, struct vcpu, arch.syscall32_callback_cs); OFFSET(VCPU_syscall32_disables_events, struct vcpu,
@@ -86,13 +84,10 @@ void __dummy__(void) OFFSET(VCPU_sysenter_sel, struct vcpu, arch.sysenter_callback_cs); OFFSET(VCPU_sysenter_disables_events, struct vcpu, arch.sysenter_disables_events); - OFFSET(VCPU_gp_fault_addr, struct vcpu, - arch.guest_context.trap_ctxt[TRAP_gp_fault].address); - OFFSET(VCPU_gp_fault_sel, struct vcpu, - arch.guest_context.trap_ctxt[TRAP_gp_fault].cs); - OFFSET(VCPU_kernel_sp, struct vcpu, arch.guest_context.kernel_sp); - OFFSET(VCPU_kernel_ss, struct vcpu, arch.guest_context.kernel_ss); - OFFSET(VCPU_guest_context_flags, struct vcpu, arch.guest_context.flags); + OFFSET(VCPU_trap_ctxt, struct vcpu, arch.pv_vcpu.trap_ctxt); + OFFSET(VCPU_kernel_sp, struct vcpu, arch.pv_vcpu.kernel_sp); + OFFSET(VCPU_kernel_ss, struct vcpu, arch.pv_vcpu.kernel_ss); + OFFSET(VCPU_guest_context_flags, struct vcpu, arch.vgc_flags); OFFSET(VCPU_nmi_pending, struct vcpu, nmi_pending); OFFSET(VCPU_mce_pending, struct vcpu, mce_pending); OFFSET(VCPU_nmi_old_mask, struct vcpu, nmi_state.old_mask);
@@ -139,6 +134,11 @@ void __dummy__(void)DEFINE (CPUINFO_sizeof,sizeof (struct cpu_info ));BLANK (); + OFFSET(TRAPINFO_eip, struct trap_info, address); + OFFSET(TRAPINFO_cs, struct trap_info, cs); +DEFINE (TRAPINFO_sizeof,sizeof (struct trap_info )); +BLANK (); + OFFSET(TRAPBOUNCE_error_code, struct trap_bounce, error_code); OFFSET(TRAPBOUNCE_flags, struct trap_bounce, flags); OFFSET(TRAPBOUNCE_cs, struct trap_bounce, cs);
xen/arch/x86/x86_64/compat/entry.S +6 -4
@@ -222,18 +222,20 @@ ENTRY(compat_syscall) movb %cl,TRAPBOUNCE_flags(%rdx) call compat_create_bounce_frame jmp compat_test_all_events -2: movl $TRAP_gp_fault,UREGS_entry_vector(%rsp) +2: movq VCPU_trap_ctxt(%rbx),%rsi + movl $TRAP_gp_fault,UREGS_entry_vector(%rsp) subl $2,UREGS_rip(%rsp) - movq VCPU_gp_fault_addr(%rbx),%rax - movzwl VCPU_gp_fault_sel(%rbx),%esi + movl TRAP_gp_fault * TRAPINFO_sizeof + TRAPINFO_eip(%rsi),%eax + movzwl TRAP_gp_fault * TRAPINFO_sizeof + TRAPINFO_cs(%rsi),%esi movb $(TBF_EXCEPTION|TBF_EXCEPTION_ERRCODE|TBF_INTERRUPT),%cl movl $0,TRAPBOUNCE_error_code(%rdx) jmp 1b ENTRY(compat_sysenter) + movq VCPU_trap_ctxt(%rbx),%rcx cmpl $TRAP_gp_fault,UREGS_entry_vector(%rsp) movzwl VCPU_sysenter_sel(%rbx),%eax - movzwl VCPU_gp_fault_sel(%rbx),%ecx + movzwl TRAP_gp_fault * TRAPINFO_sizeof + TRAPINFO_cs(%rcx),%ecx cmovel %ecx,%eax testl $~3,%eax movl $FLAT_COMPAT_USER_SS,UREGS_ss(%rsp)
xen/arch/x86/x86_64/compat/traps.c +10 -10
@@ -97,7 +97,7 @@ unsigned int compat_iret(void)* mode frames). */ const struct trap_info *ti; -u32 x, ksp = v->arch.guest_context.kernel_sp -40 ; +u32 x, ksp = v->arch.pv_vcpu.kernel_sp -40 ;unsigned int i;int rc =0 ;
@@ -122,9 +122,9 @@ unsigned int compat_iret(void)if ( rc ) goto exit_and_crash; regs->_esp = ksp; - regs->ss = v->arch.guest_context.kernel_ss; + regs->ss = v->arch.pv_vcpu.kernel_ss; - ti = &v->arch.guest_context.trap_ctxt[13 ]; + ti = &v->arch.pv_vcpu.trap_ctxt[TRAP_gp_fault];if (TI_GET_IF (ti) ) eflags &= ~X86_EFLAGS_IF ; regs->_eflags &= ~(X86_EFLAGS_VM|X86_EFLAGS_RF|
@@ -174,19 +174,19 @@ static long compat_register_guest_callbaswitch ( reg->type ) {case CALLBACKTYPE_event: - v->arch.guest_context.event_callback_cs = reg->address.cs; - v->arch.guest_context.event_callback_eip = reg->address.eip; + v->arch.pv_vcpu.event_callback_cs = reg->address.cs; + v->arch.pv_vcpu.event_callback_eip = reg->address.eip;break ;case CALLBACKTYPE_failsafe: - v->arch.guest_context.failsafe_callback_cs = reg->address.cs; - v->arch.guest_context.failsafe_callback_eip = reg->address.eip; + v->arch.pv_vcpu.failsafe_callback_cs = reg->address.cs; + v->arch.pv_vcpu.failsafe_callback_eip = reg->address.eip;if ( reg->flags & CALLBACKF_mask_events )set_bit (_VGCF_failsafe_disables_events, - &v->arch.guest_context.flags); + &v->arch.vgc_flags);else clear_bit (_VGCF_failsafe_disables_events, - &v->arch.guest_context.flags); + &v->arch.vgc_flags);break ;case CALLBACKTYPE_syscall32:
@@ -311,7 +311,7 @@ DEFINE_XEN_GUEST_HANDLE(trap_info_compatint compat_set_trap_table (XEN_GUEST_HANDLE (trap_info_compat_t) traps) {struct compat_trap_info cur; -struct trap_info *dst = current->arch.guest_context.trap_ctxt; +struct trap_info *dst = current->arch.pv_vcpu.trap_ctxt;long rc =0 ;/* If no table is presented then clear the entire virtual IDT. */
xen/arch/x86/x86_64/entry.S +3 -2
@@ -286,8 +286,9 @@ sysenter_eflags_saved: jnz compat_sysenter call create_bounce_frame jmp test_all_events -2: movl %eax,TRAPBOUNCE_error_code(%rdx) - movq VCPU_gp_fault_addr(%rbx),%rax +2: movq VCPU_trap_ctxt(%rbx),%rcx + movl %eax,TRAPBOUNCE_error_code(%rdx) + movq TRAP_gp_fault * TRAPINFO_sizeof + TRAPINFO_eip(%rcx),%rax movb $(TBF_EXCEPTION|TBF_EXCEPTION_ERRCODE|TBF_INTERRUPT),%cl movl $TRAP_gp_fault,UREGS_entry_vector(%rsp) jmp 1b
xen/arch/x86/x86_64/mm.c +5 -5
@@ -1100,8 +1100,8 @@ long subarch_memory_op(int op, XEN_GUESTlong do_stack_switch (unsigned long ss,unsigned long esp) {fixup_guest_stack_selector (current->domain, ss); - current->arch.guest_context.kernel_ss = ss; - current->arch.guest_context.kernel_sp = esp; + current->arch.pv_vcpu.kernel_ss = ss; + current->arch.pv_vcpu.kernel_sp = esp;return 0 ; }
@@ -1116,21 +1116,21 @@ long do_set_segment_base(unsigned int whif (wrmsr_safe (MSR_FS_BASE , base) ) ret = -EFAULT ;else - v->arch.guest_context.fs_base = base; + v->arch.pv_vcpu.fs_base = base;break ;case SEGBASE_GS_USER :if (wrmsr_safe (MSR_SHADOW_GS_BASE , base) ) ret = -EFAULT ;else - v->arch.guest_context.gs_base_user = base; + v->arch.pv_vcpu.gs_base_user = base;break ;case SEGBASE_GS_KERNEL :if (wrmsr_safe (MSR_GS_BASE , base) ) ret = -EFAULT ;else - v->arch.guest_context.gs_base_kernel = base; + v->arch.pv_vcpu.gs_base_kernel = base;break ;case SEGBASE_GS_USER_SEL :
xen/arch/x86/x86_64/traps.c +11 -11
@@ -146,19 +146,19 @@ void show_registers(struct cpu_user_regsvoid vcpu_show_registers (const struct vcpu *v) { -const struct cpu_user_regs *regs = &v->arch.guest_context.user_regs; +const struct cpu_user_regs *regs = &v->arch.user_regs;unsigned long crs[8 ];/* No need to handle HVM for now. */ if (is_hvm_vcpu (v) )return ; - crs[0 ] = v->arch.guest_context.ctrlreg[0 ]; + crs[0 ] = v->arch.pv_vcpu.ctrlreg[0 ]; crs[2 ] =arch_get_cr2 (v); crs[3 ] =pagetable_get_paddr (guest_kernel_mode (v, regs) ? v->arch.guest_table : v->arch.guest_table_user); - crs[4 ] = v->arch.guest_context.ctrlreg[4 ]; + crs[4 ] = v->arch.pv_vcpu.ctrlreg[4 ];_show_registers (regs, crs, CTXT_pv_guest, v); }
@@ -421,7 +421,7 @@ void __devinit subarch_percpu_traps_initvoid init_int80_direct_trap (struct vcpu *v) { -struct trap_info *ti = &v->arch.guest_context.trap_ctxt[0x80 ]; +struct trap_info *ti = &v->arch.pv_vcpu.trap_ctxt[0x80 ];struct trap_bounce *tb = &v->arch.int80_bounce; tb->flags =TBF_EXCEPTION ;
@@ -443,27 +443,27 @@ static long register_guest_callback(struswitch ( reg->type ) {case CALLBACKTYPE_event: - v->arch.guest_context.event_callback_eip = reg->address; + v->arch.pv_vcpu.event_callback_eip = reg->address;break ;case CALLBACKTYPE_failsafe: - v->arch.guest_context.failsafe_callback_eip = reg->address; + v->arch.pv_vcpu.failsafe_callback_eip = reg->address;if ( reg->flags & CALLBACKF_mask_events )set_bit (_VGCF_failsafe_disables_events, - &v->arch.guest_context.flags); + &v->arch.vgc_flags);else clear_bit (_VGCF_failsafe_disables_events, - &v->arch.guest_context.flags); + &v->arch.vgc_flags);break ;case CALLBACKTYPE_syscall: - v->arch.guest_context.syscall_callback_eip = reg->address; + v->arch.pv_vcpu.syscall_callback_eip = reg->address;if ( reg->flags & CALLBACKF_mask_events )set_bit (_VGCF_syscall_disables_events, - &v->arch.guest_context.flags); + &v->arch.vgc_flags);else clear_bit (_VGCF_syscall_disables_events, - &v->arch.guest_context.flags); + &v->arch.vgc_flags);break ;case CALLBACKTYPE_syscall32:
xen/include/asm-x86/domain.h +50 -6
82 lines not on this page · raw message
xen/include/asm-x86/ldt.h +1 -1
@@ -9,7 +9,7 @@ static inline void load_LDT(struct vcpustruct desc_struct *desc;unsigned long ents; -if ( (ents = v->arch.guest_context.ldt_ents) ==0 ) +if ( (ents = v->arch.pv_vcpu.ldt_ents) ==0 ) { __asm__ __volatile__ ("lldt %%ax" : :"a" (0 ) ); }
xen/include/asm-x86/regs.h +1 -1
@@ -19,6 +19,6 @@ (diff ==0 ); \ }) -#define return_reg (v) ((v)->arch.guest_context.user_regs.eax) +#define return_reg (v) ((v)->arch.user_regs.eax)#endif /* __X86_REGS_H__ */
xen/include/xlat.lst +0 -1
@@ -10,7 +10,6 @@ ? vcpu_time_info xen.h ! cpu_user_regs arch-x86/xen-@[email protected] ! trap_info arch-x86/xen.h -! vcpu_guest_context arch-x86/xen.h ? cpu_offline_action arch-x86/xen-mca.h ? mc arch-x86/xen-mca.h ? mcinfo_bank arch-x86/xen-mca.h
This is accomplished by splitting the guest_context member, which by itself is larger than a page on x86-64. Quite a number of fields of this structure is completely meaningless for HVM guests, and thus a new struct pv_vcpu gets introduced, which is being overlaid with struct hvm_vcpu in struct arch_vcpu. The one member that is mostly responsible for the large size is trap_ctxt, which now gets allocated separately (unless fitting on the same page as struct arch_vcpu, as is currently the case for x86-32), and only for non-hvm, non-idle domains.
This change pointed out a latent problem in arch_set_info_guest(), which is permitted to be called on already initialized vCPU-s, but so far copied the new state into struct arch_vcpu without (in this case) actually going through all the necessary accounting/validation steps. The logic gets changed so that the pieces that bypass accounting will at least be verified to be no different from the currently active bits, and the whole change will fail in case they are. The logic does *not* get adjusted here to do full error recovery, that is, partially modified state continues to not get unrolled in case of failure.
xen/arch/x86/acpi/suspend.c +7 -7
@@ -87,14 +87,14 @@ void restore_rest_processor_state(void)/* Maybe load the debug registers. */ BUG_ON (is_hvm_vcpu (curr)); -if ( !is_idle_vcpu (curr) && curr->arch.guest_context.debugreg[7 ] ) +if ( !is_idle_vcpu (curr) && curr->arch.debugreg[7 ] ) { -write_debugreg (0 , curr->arch.guest_context.debugreg[0 ]); -write_debugreg (1 , curr->arch.guest_context.debugreg[1 ]); -write_debugreg (2 , curr->arch.guest_context.debugreg[2 ]); -write_debugreg (3 , curr->arch.guest_context.debugreg[3 ]); -write_debugreg (6 , curr->arch.guest_context.debugreg[6 ]); -write_debugreg (7 , curr->arch.guest_context.debugreg[7 ]); +write_debugreg (0 , curr->arch.debugreg[0 ]); +write_debugreg (1 , curr->arch.debugreg[1 ]); +write_debugreg (2 , curr->arch.debugreg[2 ]); +write_debugreg (3 , curr->arch.debugreg[3 ]); +write_debugreg (6 , curr->arch.debugreg[6 ]); +write_debugreg (7 , curr->arch.debugreg[7 ]); }/* Reload FPU state on next FPU use. */
xen/arch/x86/domain.c +225 -102
577 lines not on this page · raw message
xen/arch/x86/domain_build.c +9 -9
@@ -731,8 +731,8 @@ int __init construct_dom0(if (is_pv_32on64_domain (d) ) { - v->arch.guest_context.failsafe_callback_cs =FLAT_COMPAT_KERNEL_CS ; - v->arch.guest_context.event_callback_cs =FLAT_COMPAT_KERNEL_CS ; + v->arch.pv_vcpu.failsafe_callback_cs =FLAT_COMPAT_KERNEL_CS ; + v->arch.pv_vcpu.event_callback_cs =FLAT_COMPAT_KERNEL_CS ; }/* WARNING: The new domain must have its 'processor' field filled in! */
@@ -1160,7 +1160,7 @@ int __init construct_dom0(* ESI = start_info * [EAX,EBX,ECX,EDX,EDI,EBP are zero] */ - regs = &v->arch.guest_context.user_regs; + regs = &v->arch.user_regs; regs->ds = regs->es = regs->fs = regs->gs = !is_pv_32on64_domain (d) ?FLAT_KERNEL_DS :FLAT_COMPAT_KERNEL_DS ; regs->ss = (!is_pv_32on64_domain(d) ?
@@ -1178,12 +1178,12 @@ int __init construct_dom0(if ( supervisor_mode_kernel ) { - v->arch.guest_context.kernel_ss &= ~3 ; - v->arch.guest_context.user_regs.ss &= ~3 ; - v->arch.guest_context.user_regs.es &= ~3 ; - v->arch.guest_context.user_regs.ds &= ~3 ; - v->arch.guest_context.user_regs.fs &= ~3 ; - v->arch.guest_context.user_regs.gs &= ~3 ; + v->arch.pv_vcpu.kernel_ss &= ~3 ; + v->arch.user_regs.ss &= ~3 ; + v->arch.user_regs.es &= ~3 ; + v->arch.user_regs.ds &= ~3 ; + v->arch.user_regs.fs &= ~3 ; + v->arch.user_regs.gs &= ~3 ;printk ("Dom0 runs in ring 0 (supervisor mode)\n" );if ( !test_bit (XENFEAT_supervisor_mode_kernel, parms.f_supported) )
xen/arch/x86/domctl.c +70 -17
126 lines not on this page · raw message
xen/arch/x86/hvm/hvm.c +61 -66
196 lines not on this page · raw message
xen/arch/x86/hvm/svm/svm.c +13 -13
@@ -117,12 +117,12 @@ static void svm_save_dr(struct vcpu *v) v->arch.hvm_vcpu.flag_dr_dirty =0 ;vmcb_set_dr_intercepts (vmcb, ~0u ); - v->arch.guest_context.debugreg[0 ] =read_debugreg (0 ); - v->arch.guest_context.debugreg[1 ] =read_debugreg (1 ); - v->arch.guest_context.debugreg[2 ] =read_debugreg (2 ); - v->arch.guest_context.debugreg[3 ] =read_debugreg (3 ); - v->arch.guest_context.debugreg[6 ] =vmcb_get_dr6 (vmcb); - v->arch.guest_context.debugreg[7 ] =vmcb_get_dr7 (vmcb); + v->arch.debugreg[0 ] =read_debugreg (0 ); + v->arch.debugreg[1 ] =read_debugreg (1 ); + v->arch.debugreg[2 ] =read_debugreg (2 ); + v->arch.debugreg[3 ] =read_debugreg (3 ); + v->arch.debugreg[6 ] =vmcb_get_dr6 (vmcb); + v->arch.debugreg[7 ] =vmcb_get_dr7 (vmcb); }static void __restore_debug_registers (struct vcpu *v)
@@ -135,12 +135,12 @@ static void __restore_debug_registers(st v->arch.hvm_vcpu.flag_dr_dirty =1 ;vmcb_set_dr_intercepts (vmcb,0 ); -write_debugreg (0 , v->arch.guest_context.debugreg[0 ]); -write_debugreg (1 , v->arch.guest_context.debugreg[1 ]); -write_debugreg (2 , v->arch.guest_context.debugreg[2 ]); -write_debugreg (3 , v->arch.guest_context.debugreg[3 ]); -vmcb_set_dr6 (vmcb, v->arch.guest_context.debugreg[6 ]); -vmcb_set_dr7 (vmcb, v->arch.guest_context.debugreg[7 ]); +write_debugreg (0 , v->arch.debugreg[0 ]); +write_debugreg (1 , v->arch.debugreg[1 ]); +write_debugreg (2 , v->arch.debugreg[2 ]); +write_debugreg (3 , v->arch.debugreg[3 ]); +vmcb_set_dr6 (vmcb, v->arch.debugreg[6 ]); +vmcb_set_dr7 (vmcb, v->arch.debugreg[7 ]); }/*
@@ -151,7 +151,7 @@ static void __restore_debug_registers(st*/ static void svm_restore_dr (struct vcpu *v) { -if (unlikely (v->arch.guest_context.debugreg[7 ] &DR7_ACTIVE_MASK ) ) +if (unlikely (v->arch.debugreg[7 ] &DR7_ACTIVE_MASK ) )__restore_debug_registers (v); }
xen/arch/x86/hvm/vmx/vmcs.c +1 -1
@@ -1128,7 +1128,7 @@ static void vmx_dump_sel2(char *name, uivoid vmcs_dump_vcpu (struct vcpu *v) { -struct cpu_user_regs *regs = &v->arch.guest_context.user_regs; +struct cpu_user_regs *regs = &v->arch.user_regs;unsigned long long x;if ( v == current )
xen/arch/x86/hvm/vmx/vmx.c +15 -15
@@ -132,7 +132,7 @@ static int vmx_vcpu_initialise(struct vc/* %eax == 1 signals full real-mode support to the guest loader. */ if ( v->vcpu_id ==0 ) - v->arch.guest_context.user_regs.eax =1 ; + v->arch.user_regs.eax =1 ;return 0 ; }
@@ -400,13 +400,13 @@ static void vmx_save_dr(struct vcpu *v) v->arch.hvm_vmx.exec_control |=CPU_BASED_MOV_DR_EXITING ;vmx_update_cpu_exec_control (v); - v->arch.guest_context.debugreg[0 ] =read_debugreg (0 );
Lines of this file are not shown. View the raw message.
xen/arch/x86/i387.c +4 -4
Lines of this file are not shown. View the raw message.
xen/arch/x86/mm.c +9 -9
Lines of this file are not shown. View the raw message.
xen/arch/x86/traps.c +59 -59
118 lines not on this page · raw message
xen/arch/x86/x86_32/asm-offsets.c +7 -11
Lines of this file are not shown. View the raw message.
xen/arch/x86/x86_32/mm.c +2 -2
Lines of this file are not shown. View the raw message.
xen/arch/x86/x86_32/seg_fixup.c +9 -9
Lines of this file are not shown. View the raw message.
xen/arch/x86/x86_32/traps.c +10 -10
Lines of this file are not shown. View the raw message.
xen/arch/x86/x86_64/asm-offsets.c +14 -14
Lines of this file are not shown. View the raw message.
xen/arch/x86/x86_64/compat/entry.S +6 -4
Lines of this file are not shown. View the raw message.
xen/arch/x86/x86_64/compat/traps.c +10 -10
Lines of this file are not shown. View the raw message.
xen/arch/x86/x86_64/entry.S +3 -2
Lines of this file are not shown. View the raw message.
xen/arch/x86/x86_64/mm.c +5 -5
Lines of this file are not shown. View the raw message.
xen/arch/x86/x86_64/traps.c +11 -11
Lines of this file are not shown. View the raw message.
xen/include/asm-x86/domain.h +50 -6
56 lines not on this page · raw message
xen/include/asm-x86/ldt.h +1 -1
Lines of this file are not shown. View the raw message.
xen/include/asm-x86/regs.h +1 -1
Lines of this file are not shown. View the raw message.
xen/include/xlat.lst +0 -1
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Part of the diff is not shown here. View the raw message.