32-bit domU PVH support
v5 cover 32-bit domU PVH support
32-bit PVH-classic support
Changes in v5:
* Added patch 2 that prevents a 32-bit PVH guest from turning off PAE
Changes in v4:
* Add xenpmu_op hypercall to pvh_hypercall32_table[] (patch 3)
* Adjust 'is_pvh_domain(currd)' test to match a similar test further in the routine (patch 3)
Changes in v3:
* Swapped patches 1 and 2
* Added is_pvh_32bit_domain() macro
* Dropped a few unnecessary tests for 32b mode
* Added error for unsupported modes
* Added changes to switch_native() similar to those in switch_compat()
* Fully declared compat_mmuext_op() in hvm.c
Boris Ostrovsky (5):
x86/pvh: Set 32b PVH guest mode in XEN_DOMCTL_set_address_size x86/pvh: Do not allow 32-bit PVH guests to clear CR4's PAE bit x86/compat: Test both PV and PVH guests for compat mode x86/pvh: Handle hypercalls for 32b PVH guests libxc/x86/pvh: Allow creation of 32b PVH guests
tools/libxc/xc_dom_x86.c | 32 +++++++++--------- xen/arch/x86/domain.c | 33 +++++++++++-------- xen/arch/x86/domctl.c | 5 +-- xen/arch/x86/hvm/hvm.c | 76 ++++++++++++++++++++++++++++++++++++------- xen/arch/x86/hvm/vmx/vmcs.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 19 +++++++++++ xen/include/asm-x86/domain.h | 1 + xen/include/asm-x86/hvm/hvm.h | 2 ++ 8 files changed, 125 insertions(+), 45 deletions(-)
Signature · 1 line
1.8.1.4
PATCH v5 1/5 x86/pvh: Set 32b PVH guest mode in XEN_DOMCTL_set_address_size
--- xen/arch/x86/domain.c | 27 ++++++++++++++++----------- xen/arch/x86/hvm/hvm.c | 24 +++++++++++++++++++++++- xen/arch/x86/hvm/vmx/vmcs.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 19 +++++++++++++++++++ xen/include/asm-x86/hvm/hvm.h | 2 ++ 5 files changed, 61 insertions(+), 13 deletions(-)
xen/arch/x86/domain.c +16 -11
@@ -366,7 +366,11 @@ int switch_native(struct domain *d)for_each_vcpu ( d, v ) {free_compat_arg_xlat (v); -release_compat_l4 (v); + +if ( !is_pvh_domain (d) ) +release_compat_l4 (v); +else +hvm_set_mode (v,8 ); }return 0 ;
@@ -377,25 +381,26 @@ int switch_compat(struct domain *d)struct vcpu *v;int rc; -if (is_pvh_domain (d) ) - { -printk (XENLOG_G_INFO -"Xen currently does not support 32bit PVH guests\n" ); -return -EINVAL ; - } -if ( !may_switch_mode (d) )return -EACCES ;if (is_pv_32bit_domain (d) )return 0 ; - d->arch.is_32bit_pv = d->arch.has_32bit_shinfo =1 ; + d->arch.has_32bit_shinfo =1 ; +if (is_pv_domain (d) ) + d->arch.is_32bit_pv =1 ;for_each_vcpu ( d, v ) { rc =setup_compat_arg_xlat (v);if ( !rc ) - rc =setup_compat_l4 (v); + { +if ( !is_pvh_domain (d) ) + rc =setup_compat_l4 (v); +else + rc =hvm_set_mode (v,4 ); + } +if ( rc ) goto undo_and_fail; }
@@ -410,7 +415,7 @@ int switch_compat(struct domain *d) {free_compat_arg_xlat (v); -if ( !pagetable_is_null (v->arch.guest_table) ) +if ( !is_pvh_domain (d) && !pagetable_is_null (v->arch.guest_table) )release_compat_l4 (v); }
xen/arch/x86/hvm/hvm.c +23 -1
@@ -2424,7 +2424,6 @@ int hvm_vcpu_initialise(struct vcpu *v)if (is_pvh_domain (d) ) { - v->arch.hvm_vcpu.hcall_64bit =1 ;/* PVH 32bitfixme. */ /* This is for hvm_long_mode_enabled(v). */ v->arch.hvm_vcpu.guest_efer =EFER_LMA |EFER_LME ;return 0 ;
@@ -6825,6 +6824,29 @@ bool_t altp2m_vcpu_emulate_ve(struct vcpu *v)return 0 ; } +int hvm_set_mode (struct vcpu *v,int mode) +{ + +switch ( mode ) + { +case 4 : + v->arch.hvm_vcpu.guest_efer &= ~(EFER_LMA |EFER_LME ); +break ; +case 8 : + v->arch.hvm_vcpu.guest_efer |= (EFER_LMA |EFER_LME ); +break ; +default : +return -EOPNOTSUPP ; + } + +hvm_update_guest_efer (v); + +if ( hvm_funcs.set_mode ) +return hvm_funcs.set_mode (v, mode); + +return 0 ; +} +/* * Local variables: * mode: C
xen/arch/x86/hvm/vmx/vmcs.c +1 -1
@@ -1160,7 +1160,7 @@ static int construct_vmcs(struct vcpu *v)__vmwrite (GUEST_FS_AR_BYTES ,0xc093 );__vmwrite (GUEST_GS_AR_BYTES ,0xc093 );if (is_pvh_domain (d) ) -/* CS.L == 1, exec, read/write, accessed. PVH 32bitfixme. */ +/* CS.L == 1, exec, read/write, accessed. */ __vmwrite (GUEST_CS_AR_BYTES ,0xa09b );else __vmwrite (GUEST_CS_AR_BYTES ,0xc09b );/* exec/read, accessed */
xen/arch/x86/hvm/vmx/vmx.c +19 -0
@@ -1886,6 +1886,24 @@ static bool_t vmx_vcpu_emulate_ve(struct vcpu *v)return rc; } +static int vmx_set_mode (struct vcpu *v,int mode) +{ +unsigned long attr; + +if ( !is_pvh_vcpu (v) ) +return 0 ; + +ASSERT ((mode ==4 ) || (mode ==8 )); + + attr = (mode ==4 ) ?0xc09b :0xa09b ; + +vmx_vmcs_enter (v); +__vmwrite (GUEST_CS_AR_BYTES , attr); +vmx_vmcs_exit (v); + +return 0 ; +} +static struct hvm_function_table __initdata vmx_function_table = { .name ="VMX" , .cpu_up_prepare = vmx_cpu_up_prepare,
@@ -1945,6 +1963,7 @@ static struct hvm_function_table __initdata vmx_function_table = { .hypervisor_cpuid_leaf = vmx_hypervisor_cpuid_leaf, .enable_msr_exit_interception = vmx_enable_msr_exit_interception, .is_singlestep_supported = vmx_is_singlestep_supported, + .set_mode = vmx_set_mode, .altp2m_vcpu_update_p2m = vmx_vcpu_update_eptp, .altp2m_vcpu_update_vmfunc_ve = vmx_vcpu_update_vmfunc_ve, .altp2m_vcpu_emulate_ve = vmx_vcpu_emulate_ve,
xen/include/asm-x86/hvm/hvm.h +2 -0
@@ -206,6 +206,7 @@ struct hvm_function_table {void (*enable_msr_exit_interception)(struct domain *d);bool_t (*is_singlestep_supported)(void); +int (*set_mode)(struct vcpu *v,int mode);/* Alternate p2m */ void (*altp2m_vcpu_update_p2m)(struct vcpu *v);
@@ -246,6 +247,7 @@ void hvm_set_guest_tsc_fixed(struct vcpu *v, u64 guest_tsc, u64 at_tsc);u64 hvm_get_guest_tsc_fixed (struct vcpu *v,u64 at_tsc);#define hvm_get_guest_tsc (v) hvm_get_guest_tsc_fixed(v, 0) +int hvm_set_mode (struct vcpu *v,int mode);void hvm_init_guest_time (struct domain *d);void hvm_set_guest_time (struct vcpu *v,u64 guest_time);u64 hvm_get_guest_time_fixed (struct vcpu *v,u64 at_tsc);
Signature · 1 line
1.8.1.4
PATCH v5 2/5 x86/pvh: Do not allow 32-bit PVH guests to clear CR4's PAE bit
In reply to Boris Ostrovsky.. since we only support 32-bit PV(H) guests in PAE mode.
--- xen/arch/x86/hvm/hvm.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/hvm.c +12 -4
@@ -3524,11 +3524,19 @@ int hvm_set_cr4(unsigned long value, bool_t may_defer) goto gpf; } -if ( !(value &X86_CR4_PAE ) &&hvm_long_mode_enabled (v) ) +if ( !(value &X86_CR4_PAE ) ) { -HVM_DBG_LOG (DBG_LEVEL_1 ,"Guest cleared CR4.PAE while " -"EFER.LMA is set" ); - goto gpf; +if (hvm_long_mode_enabled (v) ) + { +HVM_DBG_LOG (DBG_LEVEL_1 ,"Guest cleared CR4.PAE while " +"EFER.LMA is set" ); + goto gpf; + } +if (is_pvh_vcpu (v) ) + { +HVM_DBG_LOG (DBG_LEVEL_1 ,"32-bit PVH guest cleared CR4.PAE" ); + goto gpf; + } } old_cr = v->arch.hvm_vcpu.guest_cr[4 ];
Signature · 1 line
1.8.1.4
PATCH v5 3/5 x86/compat: Test both PV and PVH guests for compat mode
In reply to Boris OstrovskyAdd is_pvh_32bit_domain() macro and use it alongside is_pv_32bit_domain() where necessary.
Since PVH guests cannot change execution mode, has_32bit_shinfo is a good indicator of whether the guest is PVH and 32-bit.
--- xen/arch/x86/domain.c | 6 +++--- xen/arch/x86/domctl.c | 5 +++-- xen/include/asm-x86/domain.h | 1 + 3 files changed, 7 insertions(+), 5 deletions(-)
xen/arch/x86/domain.c +3 -3
@@ -358,7 +358,7 @@ int switch_native(struct domain *d)if ( !may_switch_mode (d) )return -EACCES ; -if ( !is_pv_32bit_domain (d) ) +if ( !is_pv_32bit_domain (d) && !is_pvh_32bit_domain (d) )return 0 ; d->arch.is_32bit_pv = d->arch.has_32bit_shinfo =0 ;
@@ -383,7 +383,7 @@ int switch_compat(struct domain *d)if ( !may_switch_mode (d) )return -EACCES ; -if (is_pv_32bit_domain (d) ) +if (is_pv_32bit_domain (d) ||is_pvh_32bit_domain (d) )return 0 ; d->arch.has_32bit_shinfo =1 ;
@@ -777,7 +777,7 @@ int arch_set_info_guest(/* The context is a compat-mode one if the target domain is compat-mode; * we expect the tools to DTRT even in compat-mode callers. */ - compat =is_pv_32bit_domain (d); + compat =is_pv_32bit_domain (d) ||is_pvh_32bit_domain (d);#define c (fld) (compat ? (c.cmp->fld) : (c.nat->fld)) flags =c (flags);
xen/arch/x86/domctl.c +3 -2
@@ -349,7 +349,8 @@ long arch_do_domctl(case XEN_DOMCTL_get_address_size: domctl->u.address_size.size = -is_pv_32bit_domain (d) ?32 :BITS_PER_LONG ; + (is_pv_32bit_domain (d) ||is_pvh_32bit_domain (d)) ? +32 :BITS_PER_LONG ; copyback =1 ;break ;
@@ -1203,7 +1204,7 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c) {unsigned int i;const struct domain *d = v->domain; -bool_t compat =is_pv_32bit_domain (d); +bool_t compat =is_pv_32bit_domain (d) ||is_pvh_32bit_domain (d);#define c (fld) (!compat ? (c.nat->fld) : (c.cmp->fld))if ( !is_pv_domain (d) )
xen/include/asm-x86/domain.h +1 -0
@@ -14,6 +14,7 @@#define has_32bit_shinfo (d) ((d)->arch.has_32bit_shinfo)#define is_pv_32bit_domain (d) ((d)->arch.is_32bit_pv)#define is_pv_32bit_vcpu (v) (is_pv_32bit_domain((v)->domain)) +#define is_pvh_32bit_domain (d) (is_pvh_domain(d) && has_32bit_shinfo(d))#define is_hvm_pv_evtchn_domain (d) (has_hvm_container_domain(d) && \ d->arch.hvm_domain.irq.callback_via_type == HVMIRQ_callback_vector)
Signature · 1 line
1.8.1.4
PATCH v5 4/5 x86/pvh: Handle hypercalls for 32b PVH guests
In reply to Boris Ostrovsky--- xen/arch/x86/hvm/hvm.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/hvm.c +30 -6
@@ -5113,7 +5113,6 @@ static hvm_hypercall_t *const hvm_hypercall32_table[NR_hypercalls] = { [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation }; -/* PVH 32bitfixme. */ static hvm_hypercall_t *const pvh_hypercall64_table[NR_hypercalls] = {HYPERCALL (platform_op),HYPERCALL (memory_op),
@@ -5133,6 +5132,30 @@ static hvm_hypercall_t *const pvh_hypercall64_table[NR_hypercalls] = { [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation }; +extern int compat_mmuext_op (XEN_GUEST_HANDLE_PARAM (void ) cmp_uops, +unsigned int count, +XEN_GUEST_HANDLE_PARAM (uint) pdone, +unsigned int foreigndom); +static hvm_hypercall_t *const pvh_hypercall32_table[NR_hypercalls] = { +HYPERCALL (platform_op), +COMPAT_CALL (memory_op), +HYPERCALL (xen_version), +HYPERCALL (console_io), + [ __HYPERVISOR_grant_table_op ] = + (hvm_hypercall_t *)hvm_grant_table_op_compat32, +COMPAT_CALL (vcpu_op), +COMPAT_CALL (mmuext_op), +HYPERCALL (xsm_op), +COMPAT_CALL (sched_op), +HYPERCALL (event_channel_op), + [ __HYPERVISOR_physdev_op ] = (hvm_hypercall_t *)hvm_physdev_op_compat32, +HYPERCALL (hvm_op), +HYPERCALL (sysctl), +HYPERCALL (domctl), +HYPERCALL (xenpmu_op), + [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation +}; +extern const uint8_t hypercall_args_table[], compat_hypercall_args_table[];int hvm_do_hypercall (struct cpu_user_regs *regs)
@@ -5163,8 +5186,8 @@ int hvm_do_hypercall(struct cpu_user_regs *regs)return viridian_hypercall (regs);if ( (eax >= NR_hypercalls) || - (is_pvh_domain (currd) ? !pvh_hypercall64_table[eax] - : !hvm_hypercall32_table[eax]) ) + !(is_pvh_domain (currd) ? pvh_hypercall32_table[eax] + : hvm_hypercall32_table[eax]) ) { regs->eax = -ENOSYS ;return HVM_HCALL_completed;
@@ -5219,8 +5242,6 @@ int hvm_do_hypercall(struct cpu_user_regs *regs) }#endif } -else if (unlikely (is_pvh_domain (currd)) ) - regs->_eax = -ENOSYS ;/* PVH 32bitfixme. */ else {unsigned int ebx = regs->_ebx;
@@ -5246,7 +5267,10 @@ int hvm_do_hypercall(struct cpu_user_regs *regs) }#endif - regs->_eax = hvm_hypercall32_table[eax](ebx, ecx, edx, esi, edi, ebp); + regs->_eax = (is_pvh_vcpu (curr) + ? pvh_hypercall32_table + : hvm_hypercall32_table)[eax](ebx, ecx, edx, + esi, edi, ebp);#ifndef NDEBUG if ( !curr->arch.hvm_vcpu.hcall_preempted )
Signature · 1 line
1.8.1.4
PATCH v5 5/5 libxc/x86/pvh: Allow creation of 32b PVH guests
In reply to Boris Ostrovsky--- tools/libxc/xc_dom_x86.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)
tools/libxc/xc_dom_x86.c +15 -17
@@ -300,7 +300,8 @@ static int setup_pgtables_x86_32_pae(struct xc_dom_image *dom) pgpfn = (addr - dom->parms.virt_base) >>PAGE_SHIFT_X86 ; l1tab[l1off] =pfn_to_paddr (xc_dom_p2m_guest (dom, pgpfn)) |L1_PROT ; -if ( (addr >= dom->pgtables_seg.vstart) && +if ( (!dom->pvh_enabled) && + (addr >= dom->pgtables_seg.vstart) && (addr < dom->pgtables_seg.vend) ) l1tab[l1off] &= ~_PAGE_RW;/* page tables are r/o */
@@ -590,22 +591,9 @@ static int vcpu_x86_32(struct xc_dom_image *dom, void *ptr)DOMPRINTF_CALLED (dom->xch); -if ( dom->pvh_enabled ) - { -xc_dom_panic (dom->xch,XC_INTERNAL_ERROR , -"%s: PVH not supported for 32bit guests." , __FUNCTION__); -return -1 ; - } -/* clear everything */ memset (ctxt,0 ,sizeof (*ctxt)); - ctxt->user_regs.ds =FLAT_KERNEL_DS_X86_32 ; - ctxt->user_regs.es =FLAT_KERNEL_DS_X86_32 ; - ctxt->user_regs.fs =FLAT_KERNEL_DS_X86_32 ; - ctxt->user_regs.gs =FLAT_KERNEL_DS_X86_32 ; - ctxt->user_regs.ss =FLAT_KERNEL_SS_X86_32 ; - ctxt->user_regs.cs =FLAT_KERNEL_CS_X86_32 ; ctxt->user_regs.eip = dom->parms.virt_entry; ctxt->user_regs.esp = dom->parms.virt_base + (dom->bootstack_pfn +1 ) *PAGE_SIZE_X86 ;
@@ -613,9 +601,6 @@ static int vcpu_x86_32(struct xc_dom_image *dom, void *ptr) dom->parms.virt_base + (dom->start_info_pfn) *PAGE_SIZE_X86 ; ctxt->user_regs.eflags =1 <<9 ;/* Interrupt Enable */ - ctxt->kernel_ss = ctxt->user_regs.ss; - ctxt->kernel_sp = ctxt->user_regs.esp; - ctxt->flags = VGCF_in_kernel_X86_32 | VGCF_online_X86_32;if ( dom->parms.pae ==2 /* extended_cr3 */ || dom->parms.pae ==3 /* bimodal */ )
@@ -626,6 +611,19 @@ static int vcpu_x86_32(struct xc_dom_image *dom, void *ptr)DOMPRINTF ("%s: cr3: pfn 0x%" PRIpfn" mfn 0x%" PRIpfn"" , __FUNCTION__, dom->pgtables_seg.pfn, cr3_pfn); +if ( dom->pvh_enabled ) +return 0 ; + + ctxt->user_regs.ds =FLAT_KERNEL_DS_X86_32 ; + ctxt->user_regs.es =FLAT_KERNEL_DS_X86_32 ; + ctxt->user_regs.fs =FLAT_KERNEL_DS_X86_32 ; + ctxt->user_regs.gs =FLAT_KERNEL_DS_X86_32 ; + ctxt->user_regs.ss =FLAT_KERNEL_SS_X86_32 ; + ctxt->user_regs.cs =FLAT_KERNEL_CS_X86_32 ; + + ctxt->kernel_ss = ctxt->user_regs.ss; + ctxt->kernel_sp = ctxt->user_regs.esp; +return 0 ; }
Signature · 1 line
1.8.1.4