# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1273650150 -3600
# Node ID e50afc6ecc4833f07fce3cd57a5a8bae6ea41125
# Parent d77a88f938c635c3ccfedaa00f946e4d9ed26098
domctl: Fix cpumap/cpumask conversion functions to return an error code.
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
xen/arch/x86/platform_hypercall.c | 7 +++++--
xen/common/cpupool.c | 10 ++++------
xen/common/domctl.c | 31 ++++++++++++++++---------------
xen/common/trace.c | 2 +-
xen/include/xen/cpumask.h | 4 ++--
5 files changed, 28 insertions(+), 26 deletions(-)
diff -r d77a88f938c6 -r e50afc6ecc48 xen/arch/x86/platform_hypercall.c
--- a/xen/arch/x86/platform_hypercall.c Tue May 11 14:05:28 2010 +0100
+++ b/xen/arch/x86/platform_hypercall.c Wed May 12 08:42:30 2010 +0100
@@ -344,7 +344,8 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
guest_from_compat_handle(cpumap_bitmap,
op->u.getidletime.cpumap_bitmap);
ctlmap.bitmap.p = cpumap_bitmap.p; /* handle -> handle_64 conversion */
- xenctl_cpumap_to_cpumask(&cpumap, &ctlmap);
+ if ( (ret = xenctl_cpumap_to_cpumask(&cpumap, &ctlmap)) != 0 )
+ goto out;
guest_from_compat_handle(idletimes, op->u.getidletime.idletime);
for_each_cpu_mask ( cpu, cpumap )
@@ -359,7 +360,9 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
}
op->u.getidletime.now = now;
- cpumask_to_xenctl_cpumap(&ctlmap, &cpumap);
+ if ( (ret = cpumask_to_xenctl_cpumap(&ctlmap, &cpumap)) != 0 )
+ goto out;
+
ret = copy_to_guest(u_xenpf_op, op, 1) ? -EFAULT : 0;
}
break;
diff -r d77a88f938c6 -r e50afc6ecc48 xen/common/cpupool.c
--- a/xen/common/cpupool.c Tue May 11 14:05:28 2010 +0100
+++ b/xen/common/cpupool.c Wed May 12 08:42:30 2010 +0100
@@ -446,8 +446,7 @@ int cpupool_do_sysctl(struct xen_sysctl_
op->cpupool_id = c->cpupool_id;
op->sched_id = c->sched.sched_id;
op->n_dom = c->n_dom;
- cpumask_to_xenctl_cpumap(&(op->cpumap), &(c->cpu_valid));
- ret = 0;
+ ret = cpumask_to_xenctl_cpumap(&(op->cpumap), &(c->cpu_valid));
}
break;
@@ -546,15 +545,14 @@ addcpu_out:
case XEN_SYSCTL_CPUPOOL_OP_FREEINFO:
{
- cpumask_to_xenctl_cpumap(&(op->cpumap),
- &cpupool_free_cpus);
- ret = 0;
+ ret = cpumask_to_xenctl_cpumap(
+ &op->cpumap, &cpupool_free_cpus);
}
break;
default:
ret = -ENOSYS;
-
+ break;
}
spin_unlock(&cpupool_ctl_lock);
diff -r d77a88f938c6 -r e50afc6ecc48 xen/common/domctl.c
--- a/xen/common/domctl.c Tue May 11 14:05:28 2010 +0100
+++ b/xen/common/domctl.c Wed May 12 08:42:30 2010 +0100
@@ -31,37 +31,35 @@ extern long arch_do_domctl(
extern long arch_do_domctl(
struct xen_domctl *op, XEN_GUEST_HANDLE(xen_domctl_t) u_domctl);
-void cpumask_to_xenctl_cpumap(
+int cpumask_to_xenctl_cpumap(
struct xenctl_cpumap *xenctl_cpumap, cpumask_t *cpumask)
{
unsigned int guest_bytes, copy_bytes, i;
uint8_t zero = 0;
uint8_t bytemap[(NR_CPUS + 7) / 8];
- if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
- return;
-
guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
copy_bytes = min_t(unsigned int, guest_bytes, sizeof(bytemap));
bitmap_long_to_byte(bytemap, cpus_addr(*cpumask), NR_CPUS);
if ( copy_bytes != 0 )
- copy_to_guest(xenctl_cpumap->bitmap, bytemap, copy_bytes);
+ if ( copy_to_guest(xenctl_cpumap->bitmap, bytemap, copy_bytes) )
+ return -EFAULT;
for ( i = copy_bytes; i < guest_bytes; i++ )
- copy_to_guest_offset(xenctl_cpumap->bitmap, i, &zero, 1);
+ if ( copy_to_guest_offset(xenctl_cpumap->bitmap, i, &zero, 1) )
+ return -EFAULT;
+
+ return 0;
}
-void xenctl_cpumap_to_cpumask(
+int xenctl_cpumap_to_cpumask(
cpumask_t *cpumask, struct xenctl_cpumap *xenctl_cpumap)
{
unsigned int guest_bytes, copy_bytes;
uint8_t bytemap[(NR_CPUS + 7) / 8];
- if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
- return;
-
guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
copy_bytes = min_t(unsigned int, guest_bytes, sizeof(bytemap));
@@ -69,12 +67,15 @@ void xenctl_cpumap_to_cpumask(
if ( copy_bytes != 0 )
{
- copy_from_guest(bytemap, xenctl_cpumap->bitmap, copy_bytes);
+ if ( copy_from_guest(bytemap, xenctl_cpumap->bitmap, copy_bytes) )
+ return -EFAULT;
if ( (xenctl_cpumap->nr_cpus & 7) && (guest_bytes <= sizeof(bytemap)) )
bytemap[guest_bytes-1] &= ~(0xff << (xenctl_cpumap->nr_cpus & 7));
}
bitmap_byte_to_long(cpus_addr(*cpumask), bytemap, NR_CPUS);
+
+ return 0;
}
static inline int is_free_domid(domid_t dom)
@@ -579,15 +580,15 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domc
if ( op->cmd == XEN_DOMCTL_setvcpuaffinity )
{
- xenctl_cpumap_to_cpumask(
+ ret = xenctl_cpumap_to_cpumask(
&new_affinity, &op->u.vcpuaffinity.cpumap);
- ret = vcpu_set_affinity(v, &new_affinity);
+ if ( !ret )
+ ret = vcpu_set_affinity(v, &new_affinity);
}
else
{
- cpumask_to_xenctl_cpumap(
+ ret = cpumask_to_xenctl_cpumap(
&op->u.vcpuaffinity.cpumap, &v->cpu_affinity);
- ret = 0;
}
vcpuaffinity_out:
diff -r d77a88f938c6 -r e50afc6ecc48 xen/common/trace.c
--- a/xen/common/trace.c Tue May 11 14:05:28 2010 +0100
+++ b/xen/common/trace.c Wed May 12 08:42:30 2010 +0100
@@ -343,7 +343,7 @@ int tb_control(xen_sysctl_tbuf_op_t *tbc
tbc->size = T_INFO_PAGES * PAGE_SIZE;
break;
case XEN_SYSCTL_TBUFOP_set_cpu_mask:
- xenctl_cpumap_to_cpumask(&tb_cpu_mask, &tbc->cpu_mask);
+ rc = xenctl_cpumap_to_cpumask(&tb_cpu_mask, &tbc->cpu_mask);
break;
case XEN_SYSCTL_TBUFOP_set_evt_mask:
tb_event_mask = tbc->evt_mask;
diff -r d77a88f938c6 -r e50afc6ecc48 xen/include/xen/cpumask.h
--- a/xen/include/xen/cpumask.h Tue May 11 14:05:28 2010 +0100
+++ b/xen/include/xen/cpumask.h Wed May 12 08:42:30 2010 +0100
@@ -424,9 +424,9 @@ extern cpumask_t cpu_present_map;
/* Copy to/from cpumap provided by control tools. */
struct xenctl_cpumap;
-void cpumask_to_xenctl_cpumap(
+int cpumask_to_xenctl_cpumap(
struct xenctl_cpumap *enctl_cpumap, cpumask_t *cpumask);
-void xenctl_cpumap_to_cpumask(
+int xenctl_cpumap_to_cpumask(
cpumask_t *cpumask, struct xenctl_cpumap *enctl_cpumap);
#endif /* __XEN_CPUMASK_H */
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|