Skip to contentSkip to conversation

Xen/hypercall: Update vcpu_op to take an unsigned vcpuid

PATCH In review Andrew Cooper 3 participants 3 messages Jan 16, 2015

lore
Share & tools
lore
#0 lore raw

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.

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]>

---

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
index 7221bc8..cfc7ab4 100644
@@ -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
index 8b06bfd..e096094 100644
@@ -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
index b4be3b3..510843d 100644
@@ -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
index 336e9ea..e02823e 100644
@@ -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
index 94a92d4..a0c5a31 100644
@@ -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
index e888daf..898b89f 100644
@@ -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
index 8c55779..eda8a36 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
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.

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_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).

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_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.

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

Acked-by on v1 1/1
#2 lore raw
In reply to Andrew Cooper
Quoted 10 lines · Andrew Cooper

This has no guest-visible change, but makes the Hypervisor side bounds checking more simple.

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_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

(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
index 7221bc8..cfc7ab4 100644
@@ -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
index 8b06bfd..e096094 100644
@@ -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
index b4be3b3..510843d 100644
@@ -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
index 336e9ea..e02823e 100644
@@ -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
index 94a92d4..a0c5a31 100644
@@ -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
index e888daf..898b89f 100644
@@ -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
index 8c55779..eda8a36 100644
@@ -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