Xen/hypercall: Update vcpu_op to take an unsigned vcpuid
PATCH 1/1 Xen/hypercall: Update vcpu_op to take an unsigned vcpuid
This has no guest-visible change, but makes the Hypervisor side bounds checking more simple.
---
There are no functional changes as a result of this patch, but I have an RFC improvement to suggest.
The bounds check against MAX_VIRT_CPUS is spurious now that PVH domains can use vcpu_op hypercalls. It is fine as MAX_VIRT_CPUS (8K) is far higher than current 128 limit for HVM guests, but there is nothing conceptually preventing an HVM domain from having more than 8k CPUs (x2apic allows for 2^32 unique ids).
I propose dropping the MAX_VIRT_CPU bounds check completely, and relying on d->max_vcpus to be within the approprate bounds. This will result in a guest visible change insofar that some of their -EINVAL errors will turn into -ENOENT, which is why this is suggestion is RFC.
--- xen/arch/arm/domain.c | 2 +- xen/arch/x86/hvm/hvm.c | 4 ++-- xen/common/compat/domain.c | 6 +++--- xen/common/domain.c | 6 +++--- xen/include/asm-arm/hypercall.h | 2 +- xen/include/public/vcpu.h | 2 +- xen/include/xen/hypercall.h | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-)
xen/arch/arm/domain.c +1 -1
@@ -777,7 +777,7 @@ void arch_dump_domain_info(struct domain *d) } -long do_arm_vcpu_op (int cmd,int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) +long do_arm_vcpu_op (int cmd,unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) {switch ( cmd ) {
xen/arch/x86/hvm/hvm.c +2 -2
@@ -4659,7 +4659,7 @@ static long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) }static long hvm_vcpu_op ( -int cmd,int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) +int cmd,unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) {long rc;
@@ -4718,7 +4718,7 @@ static long hvm_memory_op_compat32(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) }static long hvm_vcpu_op_compat32 ( -int cmd,int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) +int cmd,unsigned vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) {long rc;
xen/common/compat/domain.c +3 -3
@@ -23,13 +23,13 @@ CHECK_SIZE_(struct, vcpu_info); CHECK_vcpu_register_vcpu_info;#undef xen_vcpu_register_vcpu_info -int compat_vcpu_op (int cmd,int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) +int compat_vcpu_op (int cmd,unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) {struct domain *d = current->domain;struct vcpu *v;int rc =0 ; -if ( (vcpuid <0 ) || (vcpuid >=MAX_VIRT_CPUS ) ) +if ( vcpuid >=MAX_VIRT_CPUS )return -EINVAL ;if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) ==NULL )
@@ -59,7 +59,7 @@ int compat_vcpu_op(int cmd, int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)domain_unlock (d);if ( rc == -ERESTART ) - rc =hypercall_create_continuation (__HYPERVISOR_vcpu_op,"iih" , + rc =hypercall_create_continuation (__HYPERVISOR_vcpu_op,"iuh" , cmd, vcpuid, arg);xfree (cmp_ctxt);
xen/common/domain.c +3 -3
@@ -1139,14 +1139,14 @@ void unmap_vcpu_info(struct vcpu *v)put_page_and_type (mfn_to_page (mfn)); } -long do_vcpu_op (int cmd,int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) +long do_vcpu_op (int cmd,unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) {struct domain *d = current->domain;struct vcpu *v;struct vcpu_guest_context *ctxt;long rc =0 ; -if ( (vcpuid <0 ) || (vcpuid >=MAX_VIRT_CPUS ) ) +if ( vcpuid >=MAX_VIRT_CPUS )return -EINVAL ;if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) ==NULL )
@@ -1174,7 +1174,7 @@ long do_vcpu_op(int cmd, int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)free_vcpu_guest_context (ctxt);if ( rc == -ERESTART ) - rc =hypercall_create_continuation (__HYPERVISOR_vcpu_op,"iih" , + rc =hypercall_create_continuation (__HYPERVISOR_vcpu_op,"iuh" , cmd, vcpuid, arg);break ;
xen/include/asm-arm/hypercall.h +1 -1
@@ -4,7 +4,7 @@#include <public/domctl.h> /* for arch_do_domctl */ int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg); -long do_arm_vcpu_op (int cmd,int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg); +long do_arm_vcpu_op (int cmd,unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg);long subarch_do_domctl (struct xen_domctl *domctl,struct domain *d,XEN_GUEST_HANDLE_PARAM (xen_domctl_t) u_domctl);
xen/include/public/vcpu.h +1 -1
@@ -31,7 +31,7 @@/* * Prototype for this hypercall is: -* int vcpu_op(int cmd, int vcpuid, void *extra_args) +* long vcpu_op(int cmd, unsigned int vcpuid, void *extra_args) * @cmd == VCPUOP_??? (VCPU operation). * @vcpuid == VCPU to operate on. * @extra_args == Operation-specific extra arguments (NULL if none).
xen/include/xen/hypercall.h +2 -2
@@ -109,7 +109,7 @@ do_vm_assist(extern long do_vcpu_op (int cmd, -int vcpuid, +unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg);struct vcpu ;
@@ -160,7 +160,7 @@ compat_grant_table_op(extern int compat_vcpu_op (int cmd, -int vcpuid, +unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg); extern int
Signature · 1 line
1.7.10.4
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 16.01.15 at 13:03, <[email protected]> wrote:
This has no guest-visible change, but makes the Hypervisor side bounds checking more simple.
Signed-off-by Andrew Cooper <[email protected]>
Quoted 9 lines
There are no functional changes as a result of this patch, but I have an RFC improvement to suggest.
The bounds check against
MAX_VIRT_CPUSis spurious now that PVH domains can usevcpu_ophypercalls. It is fine asMAX_VIRT_CPUS(8K) is far higher than current 128 limit for HVM guests, but there is nothing conceptually preventing
an HVM domain from having more than 8k CPUs (x2apic allows for 2^32 unique ids).
Not exactly, due to the need to allow for clustered mode, but still a few hundred k.
Quoted 4 lines
I propose dropping the
MAX_VIRT_CPUbounds check completely, and relying ond->max_vcpusto be within the approprate bounds. This will result in a guest visible change insofar that some of their-EINVALerrors will turn into-ENOENT, which is why this is suggestion is RFC.
I don't think changes in error code values is problematic in any way, except in cases where for specific ones specific actions are expected to be taken by the guest. So - go for it.
Jan
Quoted 10 lines · Andrew Cooper
This has no guest-visible change, but makes the Hypervisor side bounds checking more simple.
Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>CC Ian Campbell <[email protected]>CC Stefano Stabellini <[email protected]>CC Tim Deegan <[email protected]>
For the tiny arm part:
Quoted 168 lines
There are no functional changes as a result of this patch, but I have an RFC improvement to suggest.
The bounds check against
MAX_VIRT_CPUSis spurious now that PVH domains can usevcpu_ophypercalls. It is fine asMAX_VIRT_CPUS(8K) is far higher than current 128 limit for HVM guests, but there is nothing conceptually preventing an HVM domain from having more than 8k CPUs (x2apic allows for 2^32 unique ids).I propose dropping the
MAX_VIRT_CPUbounds check completely, and relying ond->max_vcpusto be within the approprate bounds. This will result in a guest visible change insofar that some of their-EINVALerrors will turn into(quoted diff) +0
-2-ENOENT, which is why this is suggestion is RFC. --- xen/arch/arm/domain.c | 2 +- xen/arch/x86/hvm/hvm.c | 4 ++-- xen/common/compat/domain.c | 6 +++--- xen/common/domain.c | 6 +++--- xen/include/asm-arm/hypercall.h | 2 +- xen/include/public/vcpu.h | 2 +- xen/include/xen/hypercall.h | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-)xen/arch/arm/domain.c +1
-1@@ -777,7 +777,7 @@ void arch_dump_domain_info(struct domain *d) } -long do_arm_vcpu_op (int cmd,int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) +long do_arm_vcpu_op (int cmd,unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) {switch ( cmd ) {xen/arch/x86/hvm/hvm.c +2
-2@@ -4659,7 +4659,7 @@ static long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) }static long hvm_vcpu_op ( -int cmd,int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) +int cmd,unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) {long rc;@@ -4718,7 +4718,7 @@ static long hvm_memory_op_compat32(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) }static long hvm_vcpu_op_compat32 ( -int cmd,int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) +int cmd,unsigned vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) {long rc;xen/common/compat/domain.c +3
-3@@ -23,13 +23,13 @@ CHECK_SIZE_(struct, vcpu_info); CHECK_vcpu_register_vcpu_info;#undef xen_vcpu_register_vcpu_info -int compat_vcpu_op (int cmd,int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) +int compat_vcpu_op (int cmd,unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) {struct domain *d = current->domain;struct vcpu *v;int rc =0 ; -if ( (vcpuid <0 ) || (vcpuid >=MAX_VIRT_CPUS ) ) +if ( vcpuid >=MAX_VIRT_CPUS )return -EINVAL ;if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) ==NULL )@@ -59,7 +59,7 @@ int compat_vcpu_op(int cmd, int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)domain_unlock (d);if ( rc == -ERESTART ) - rc =hypercall_create_continuation (__HYPERVISOR_vcpu_op,"iih" , + rc =hypercall_create_continuation (__HYPERVISOR_vcpu_op,"iuh" , cmd, vcpuid, arg);xfree (cmp_ctxt);xen/common/domain.c +3
-3@@ -1139,14 +1139,14 @@ void unmap_vcpu_info(struct vcpu *v)put_page_and_type (mfn_to_page (mfn)); } -long do_vcpu_op (int cmd,int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) +long do_vcpu_op (int cmd,unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg) {struct domain *d = current->domain;struct vcpu *v;struct vcpu_guest_context *ctxt;long rc =0 ; -if ( (vcpuid <0 ) || (vcpuid >=MAX_VIRT_CPUS ) ) +if ( vcpuid >=MAX_VIRT_CPUS )return -EINVAL ;if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) ==NULL )@@ -1174,7 +1174,7 @@ long do_vcpu_op(int cmd, int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)free_vcpu_guest_context (ctxt);if ( rc == -ERESTART ) - rc =hypercall_create_continuation (__HYPERVISOR_vcpu_op,"iih" , + rc =hypercall_create_continuation (__HYPERVISOR_vcpu_op,"iuh" , cmd, vcpuid, arg);break ;xen/include/asm-arm/hypercall.h +1
-1@@ -4,7 +4,7 @@#include <public/domctl.h> /* for arch_do_domctl */ int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg); -long do_arm_vcpu_op (int cmd,int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg); +long do_arm_vcpu_op (int cmd,unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg);long subarch_do_domctl (struct xen_domctl *domctl,struct domain *d,XEN_GUEST_HANDLE_PARAM (xen_domctl_t) u_domctl);xen/include/public/vcpu.h +1
-1@@ -31,7 +31,7 @@/* * Prototype for this hypercall is: -* int vcpu_op(int cmd, int vcpuid, void *extra_args) +* long vcpu_op(int cmd, unsigned int vcpuid, void *extra_args) * @cmd == VCPUOP_??? (VCPU operation). * @vcpuid == VCPU to operate on. * @extra_args == Operation-specific extra arguments (NULL if none). xen/include/xen/hypercall.h +2
-2@@ -109,7 +109,7 @@ do_vm_assist(extern long do_vcpu_op (int cmd, -int vcpuid, +unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg);struct vcpu ;@@ -160,7 +160,7 @@ compat_grant_table_op(extern int compat_vcpu_op (int cmd, -int vcpuid, +unsigned int vcpuid,XEN_GUEST_HANDLE_PARAM (void ) arg); extern intSignature · 1 line
1.7.10.4