diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2010-05-13 10:16:44 +0100 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2010-05-13 10:16:44 +0100 |
commit | 336bb18eb60997cd58fff2ecb5dbba697704c97a (patch) | |
tree | bbabe1b3aec5f634a5a9a85bf42f1e6b7284f4a0 | |
parent | cd220b119a61f774e832a43cc0c04c1144f8c590 (diff) | |
download | xen-336bb18eb60997cd58fff2ecb5dbba697704c97a.tar.gz xen-336bb18eb60997cd58fff2ecb5dbba697704c97a.tar.bz2 xen-336bb18eb60997cd58fff2ecb5dbba697704c97a.zip |
domctl: Fix cpumap/cpumask conversion functions to return an error code.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
xen-unstable changeset: 21350:e50afc6ecc48
xen-unstable date: Wed May 12 08:42:30 2010 +0100
-rw-r--r-- | xen/arch/x86/platform_hypercall.c | 7 | ||||
-rw-r--r-- | xen/common/domctl.c | 31 | ||||
-rw-r--r-- | xen/common/trace.c | 2 | ||||
-rw-r--r-- | xen/include/xen/cpumask.h | 4 |
4 files changed, 24 insertions, 20 deletions
diff --git a/xen/arch/x86/platform_hypercall.c b/xen/arch/x86/platform_hypercall.c index dc2214930a..e7f3283c15 100644 --- a/xen/arch/x86/platform_hypercall.c +++ b/xen/arch/x86/platform_hypercall.c @@ -340,7 +340,8 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xen_platform_op_t) u_xenpf_op) 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 ) @@ -355,7 +356,9 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xen_platform_op_t) u_xenpf_op) } 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 --git a/xen/common/domctl.c b/xen/common/domctl.c index f87d91c06b..8819f2b449 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -30,37 +30,35 @@ static DEFINE_SPINLOCK(domctl_lock); 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)); @@ -68,12 +66,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) @@ -574,15 +575,15 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domctl_t) u_domctl) 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 --git a/xen/common/trace.c b/xen/common/trace.c index 48c8d273e9..c4264f0d79 100644 --- a/xen/common/trace.c +++ b/xen/common/trace.c @@ -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 --git a/xen/include/xen/cpumask.h b/xen/include/xen/cpumask.h index a0b3e15374..5ab202be7b 100644 --- a/xen/include/xen/cpumask.h +++ b/xen/include/xen/cpumask.h @@ -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 */ |