x86/HVM: Merge HVM and PVH hypercall tables
PATCH v2 1/1 x86/HVM: Merge HVM and PVH hypercall tables
The tables are almost identical and therefore there is little reason to keep both sets.
PVH needs 3 extra hypercalls:
* mmuext_op. MMUEXT_PIN_L<x>_TABLE are required by control domain (dom0) when building guests.
* platform_op. These are only available to privileged domains. We will (eventually) have privileged HVMlite guests and therefore shouldn't limit this to PVH only.
* xenpmu_op. any guest with !has_vlapic() (i.e. PV, PVH and HVMlite) should be able to use it.
Note that until recently PVH guests used mmuext_op's MMUEXT_INVLPG_MULTI and MMUEXT_TLB_FLUSH_MULTI commands but it has been determined that using the former was incorrect and using the latter is correct for now but is not guaranteed to work in the future.
---
v2: Add MMUEXT_PIN_L<x>_TABLE handling, disallow MMUEXT_INVLPG_MULTI and
MMUEXT_TLB_FLUSH_MULTI for PVH
xen/arch/x86/hvm/hvm.c | 65 ++++++++++------------------------------------- xen/arch/x86/mm.c | 20 ++++++++++++++ 2 files changed, 34 insertions(+), 51 deletions(-)
xen/arch/x86/hvm/hvm.c +14 -51
@@ -5188,12 +5188,21 @@ static hvm_hypercall_t *const hvm_hypercall64_table[NR_hypercalls] = {HYPERCALL (sysctl),HYPERCALL (domctl ),HYPERCALL (tmem_op ), +HYPERCALL (platform_op ), +HYPERCALL (mmuext_op ), + HYPERCALL(xenpmu_op), [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation };#define COMPAT_CALL (x) \ [ __HYPERVISOR_ ## x ] = (hvm_hypercall_t *) compat_ ## x +extern int compat_mmuext_op (XEN_GUEST_HANDLE_PARAM (void ) cmp_uops, +unsigned int count, +XEN_GUEST_HANDLE_PARAM (uint) pdone, +unsigned int foreigndom); +extern int compat_platform_op (XEN_GUEST_HANDLE_PARAM (void ) u_xenpf_op); +static hvm_hypercall_t *const hvm_hypercall32_table[NR_hypercalls] = { [ __HYPERVISOR_memory_op ] = (hvm_hypercall_t *)hvm_memory_op_compat32, [ __HYPERVISOR_grant_table_op ] = (hvm_hypercall_t *)hvm_grant_table_op_compat32,
@@ -5209,48 +5218,8 @@ static hvm_hypercall_t *const hvm_hypercall32_table[NR_hypercalls] = {HYPERCALL (sysctl),HYPERCALL (domctl),HYPERCALL (tmem_op), - [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation -}; - -static hvm_hypercall_t *const pvh_hypercall64_table[NR_hypercalls] = { -HYPERCALL (platform_op), -HYPERCALL (memory_op), -HYPERCALL (xen_version), -HYPERCALL (console_io), - [ __HYPERVISOR_grant_table_op ] = (hvm_hypercall_t *)hvm_grant_table_op, -HYPERCALL (vcpu_op), -HYPERCALL (mmuext_op), -HYPERCALL (xsm_op), -HYPERCALL (sched_op), -HYPERCALL (event_channel_op), - [ __HYPERVISOR_physdev_op ] = (hvm_hypercall_t *)hvm_physdev_op, -HYPERCALL (hvm_op), -HYPERCALL (sysctl), -HYPERCALL (domctl), -HYPERCALL (xenpmu_op), - [ __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 (platform_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 };
@@ -5284,9 +5253,7 @@ int hvm_do_hypercall(struct cpu_user_regs *regs)if ( (eax &0x80000000 ) &&is_viridian_domain (currd) )return viridian_hypercall (regs); -if ( (eax >= NR_hypercalls) || - !(is_pvh_domain (currd) ? pvh_hypercall32_table[eax] - : hvm_hypercall32_table[eax]) ) +if ( (eax >= NR_hypercalls) || !hvm_hypercall32_table[eax] ) { regs->eax = -ENOSYS ;return HVM_HCALL_completed;
@@ -5320,9 +5287,8 @@ int hvm_do_hypercall(struct cpu_user_regs *regs)#endif curr->arch.hvm_vcpu.hcall_64bit =1 ; - regs->rax = (is_pvh_domain (currd) - ? pvh_hypercall64_table - : hvm_hypercall64_table)[eax](rdi, rsi, rdx, r10, r8, r9); + regs->rax = hvm_hypercall64_table[eax](rdi, rsi, rdx, r10, r8, r9); + curr->arch.hvm_vcpu.hcall_64bit =0 ;#ifndef NDEBUG
@@ -5366,10 +5332,7 @@ int hvm_do_hypercall(struct cpu_user_regs *regs) }#endif - regs->_eax = (is_pvh_vcpu (curr) - ? pvh_hypercall32_table - : hvm_hypercall32_table)[eax](ebx, ecx, edx, - esi, edi, ebp); + regs->_eax = hvm_hypercall32_table[eax](ebx, ecx, edx, esi, edi, ebp);#ifndef NDEBUG if ( !curr->arch.hvm_vcpu.hcall_preempted )
xen/arch/x86/mm.c +20 -0
@@ -3019,6 +3019,25 @@ long do_mmuext_op(break ; } +if (has_hvm_container_domain (d) ) + { +switch ( op.cmd ) + { +case MMUEXT_PIN_L1_TABLE : +case MMUEXT_PIN_L2_TABLE : +case MMUEXT_PIN_L3_TABLE : +case MMUEXT_PIN_L4_TABLE : +if (is_control_domain (d) ) +break ; +/* fallthrough */ +default : +MEM_LOG ("Invalid extended pt command %#x" , op.cmd); + okay =0 ; + rc = -ENOSYS ; + goto done; + } + } + okay =1 ; switch ( op.cmd )
@@ -3448,6 +3467,7 @@ long do_mmuext_op(break ; } + done:if (unlikely (!okay) && !rc ) rc = -EINVAL ;if (unlikely (rc) )
Signature · 1 line
1.7.1
Quoted 12 lines · Boris Ostrovsky
The tables are almost identical and therefore there is little reason to keep both sets.
PVH needs 3 extra hypercalls:
*mmuext_op. MMUEXT_PIN_L<x>_TABLE are required by control domain (dom0) when building guests.
*platform_op. These are only available to privileged domains. We will (eventually) have privileged HVMlite guests and therefore shouldn't limit this to PVH only.
*xenpmu_op. any guest with !has_vlapic() (i.e. PV, PVH and HVMlite) should be able to use it.
Quoted 6 lines
Note that until recently PVH guests used mmuext_op's
MMUEXT_INVLPG_MULTIandMMUEXT_TLB_FLUSH_MULTIcommands but it has been determined that using the former was incorrect and using the latter is correct for now but is not guaranteed to work in the future.Signed-off-by Boris Ostrovsky <[email protected]>
Since I raised the big 'oh what if' - I would like to mention that Boris has show me the light and it is OK.
Quoted 166 lines
---
v2: Add MMUEXT_PIN_L<x>_TABLE handling, disallow
MMUEXT_INVLPG_MULTIand
MMUEXT_TLB_FLUSH_MULTIfor PVHxen/arch/x86/hvm/hvm.c | 65 ++++++++++------------------------------------- xen/arch/x86/mm.c | 20 ++++++++++++++ 2 files changed, 34 insertions(+), 51 deletions(-)xen/arch/x86/hvm/hvm.c +14
-51@@ -5188,12 +5188,21 @@ static hvm_hypercall_t *const hvm_hypercall64_table[NR_hypercalls] = {HYPERCALL (sysctl),HYPERCALL (domctl ),HYPERCALL (tmem_op ), +HYPERCALL (platform_op ), +HYPERCALL (mmuext_op ), + HYPERCALL(xenpmu_op), [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation };#define COMPAT_CALL (x) \ [ __HYPERVISOR_ ## x ] = (hvm_hypercall_t *) compat_ ## x +extern int compat_mmuext_op (XEN_GUEST_HANDLE_PARAM (void ) cmp_uops, +unsigned int count, +XEN_GUEST_HANDLE_PARAM (uint) pdone, +unsigned int foreigndom); +extern int compat_platform_op (XEN_GUEST_HANDLE_PARAM (void ) u_xenpf_op); +static hvm_hypercall_t *const hvm_hypercall32_table[NR_hypercalls] = { [ __HYPERVISOR_memory_op ] = (hvm_hypercall_t *)hvm_memory_op_compat32, [ __HYPERVISOR_grant_table_op ] = (hvm_hypercall_t *)hvm_grant_table_op_compat32,@@ -5209,48 +5218,8 @@ static hvm_hypercall_t *const hvm_hypercall32_table[NR_hypercalls] = {HYPERCALL (sysctl),HYPERCALL (domctl),HYPERCALL (tmem_op), - [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation -}; - -static hvm_hypercall_t *const pvh_hypercall64_table[NR_hypercalls] = { -HYPERCALL (platform_op), -HYPERCALL (memory_op), -HYPERCALL (xen_version), -HYPERCALL (console_io), - [ __HYPERVISOR_grant_table_op ] = (hvm_hypercall_t *)hvm_grant_table_op, -HYPERCALL (vcpu_op), -HYPERCALL (mmuext_op), -HYPERCALL (xsm_op), -HYPERCALL (sched_op), -HYPERCALL (event_channel_op), - [ __HYPERVISOR_physdev_op ] = (hvm_hypercall_t *)hvm_physdev_op, -HYPERCALL (hvm_op), -HYPERCALL (sysctl), -HYPERCALL (domctl), -HYPERCALL (xenpmu_op), - [ __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 (platform_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 };@@ -5284,9 +5253,7 @@ int hvm_do_hypercall(struct cpu_user_regs *regs)if ( (eax &0x80000000 ) &&is_viridian_domain (currd) )return viridian_hypercall (regs); -if ( (eax >= NR_hypercalls) || - !(is_pvh_domain (currd) ? pvh_hypercall32_table[eax] - : hvm_hypercall32_table[eax]) ) +if ( (eax >= NR_hypercalls) || !hvm_hypercall32_table[eax] ) { regs->eax = -ENOSYS ;return HVM_HCALL_completed;@@ -5320,9 +5287,8 @@ int hvm_do_hypercall(struct cpu_user_regs *regs)#endif curr->arch.hvm_vcpu.hcall_64bit =1 ; - regs->rax = (is_pvh_domain (currd) - ? pvh_hypercall64_table - : hvm_hypercall64_table)[eax](rdi, rsi, rdx, r10, r8, r9); + regs->rax = hvm_hypercall64_table[eax](rdi, rsi, rdx, r10, r8, r9); + curr->arch.hvm_vcpu.hcall_64bit =0 ;#ifndef NDEBUG @@ -5366,10 +5332,7 @@ int hvm_do_hypercall(struct cpu_user_regs *regs) }#endif - regs->_eax = (is_pvh_vcpu (curr) - ? pvh_hypercall32_table - : hvm_hypercall32_table)[eax](ebx, ecx, edx, - esi, edi, ebp); + regs->_eax = hvm_hypercall32_table[eax](ebx, ecx, edx, esi, edi, ebp);#ifndef NDEBUG if ( !curr->arch.hvm_vcpu.hcall_preempted )xen/arch/x86/mm.c +20
-0@@ -3019,6 +3019,25 @@ long do_mmuext_op(break ; } +if (has_hvm_container_domain (d) ) + { +switch ( op.cmd ) + { +case MMUEXT_PIN_L1_TABLE : +case MMUEXT_PIN_L2_TABLE : +case MMUEXT_PIN_L3_TABLE : +case MMUEXT_PIN_L4_TABLE : +if (is_control_domain (d) ) +break ; +/* fallthrough */ +default : +MEM_LOG ("Invalid extended pt command %#x" , op.cmd); + okay =0 ; + rc = -ENOSYS ; + goto done; + } + } + okay =1 ; switch ( op.cmd )@@ -3448,6 +3467,7 @@ long do_mmuext_op(break ; } + done:if (unlikely (!okay) && !rc ) rc = -EINVAL ;if (unlikely (rc) )Signature · 7 lines
1.7.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 16.12.15 at 17:34, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +3
-0@@ -5188,12 +5188,21 @@ static hvm_hypercall_t *const hvm_hypercall64_table[NR_hypercalls] = {HYPERCALL (sysctl),HYPERCALL (domctl),HYPERCALL (tmem_op), +HYPERCALL (platform_op), +HYPERCALL (mmuext_op), + HYPERCALL(xenpmu_op), [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation
xen/arch/x86/hvm/hvm.c static hvm_hypercall_t *const hvm_hypercall64_table[NR_hypercalls] = { · line 5204
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +5
-0};#define COMPAT_CALL (x) \ [ __HYPERVISOR_ ## x ] = (hvm_hypercall_t *) compat_ ## x +extern int compat_mmuext_op (XEN_GUEST_HANDLE_PARAM (void ) cmp_uops, +unsigned int count, +XEN_GUEST_HANDLE_PARAM (uint) pdone, +unsigned int foreigndom); +extern int compat_platform_op (XEN_GUEST_HANDLE_PARAM (void ) u_xenpf_op);
While I realize that you only move the compat_mmuext_op() declaration up, neither of the two belongs here. I have no idea why I approved of you adding that declaration in this file in an earlier change. Declarations have to be in a header included by the producer and all consumers (and there are already a number of compat_ ones in the headers iirc).
Quoted 4 lines
xen/arch/x86/mm.c +0
-0@@ -3019,6 +3019,25 @@ long do_mmuext_op(break ;
xen/arch/x86/mm.c long do_mmuext_op( · line 3029
Quoted 10 lines
xen/arch/x86/mm.c +8
-0} +if (has_hvm_container_domain (d) ) + { +switch ( op.cmd ) + { +case MMUEXT_PIN_L1_TABLE : +case MMUEXT_PIN_L2_TABLE : +case MMUEXT_PIN_L3_TABLE : +case MMUEXT_PIN_L4_TABLE :
If for nothing else then for consistency this should also include the unpin counterpart.
xen/arch/x86/mm.c long do_mmuext_op( · line 3035
Quoted 6 lines
xen/arch/x86/mm.c +6
-0+if (is_control_domain (d) ) +break ; +/* fallthrough */ +default : +MEM_LOG ("Invalid extended pt command %#x" , op.cmd); + okay =0 ;
This is unnecessary due to ...
Quoted 9 lines
xen/arch/x86/mm.c +5
-0+ rc = -ENOSYS ; + goto done; + } + } + okay =1 ; switch ( op.cmd )
xen/arch/x86/mm.c long do_mmuext_op( · line 3472
Quoted 6 lines
xen/arch/x86/mm.c +1
-0@@ -3448,6 +3467,7 @@ long do_mmuext_op(break ; } + done:if (unlikely (!okay) && !rc ) rc = -EINVAL ;
... the conditional here.
Also I'd prefer if you used -EOPNOTSUPP instead of -ENOSYS.
Jan