cpumask <=> xenctl_cpumap: allocate CPU masks and byte maps dynamically
PATCH 12/12 cpumask <=> xenctl_cpumap: allocate CPU masks and byte maps dynamically
Generally there was a NR_CPUS-bits wide array in these functions and another (through a cpumask_t) on their callers' stacks, which may get a little large for big NR_CPUS. As the functions can fail anyway, do the allocation in there.
For the x86/MCA case this require a little code restructuring: By using different CPU mask accessors it was possible to avoid allocating a mask in the broadcast case. Also, this was the only user that failed to check the return value of the conversion function (which could have led to undefined behvior).
Also constify the input parameters of the two functions.
xen/arch/x86/cpu/mcheck/mce.c +26 -17
@@ -1531,25 +1531,28 @@ long do_mca(XEN_GUEST_HANDLE(xen_mc_t) ucase XEN_MC_inject_v2: { -cpumask_t cpumap; +const cpumask_t *cpumap; +cpumask_var_t cmv;if (nr_mce_banks ==0 )return x86_mcerr ("do_mca #MC" , -ENODEV );if ( op->u.mc_inject_v2.flags &XEN_MC_INJECT_CPU_BROADCAST ) -cpumask_copy (&cpumap, &cpu_online_map); + cpumap = &cpu_online_map;else { -int gcw; - -xenctl_cpumap_to_cpumask (&cpumap, - &op->u.mc_inject_v2.cpumap); - gcw =cpumask_weight (&cpumap); -cpumask_and (&cpumap, &cpu_online_map, &cpumap); - -if (cpumask_empty (&cpumap) ) -return x86_mcerr ("No online CPU passed\n" , -EINVAL ); -else if ( gcw !=cpumask_weight (&cpumap) ) + ret =xenctl_cpumap_to_cpumask (&cmv, + &op->u.mc_inject_v2.cpumap); +if ( ret ) +break ; + cpumap = cmv; +if ( !cpumask_intersects (cpumap, &cpu_online_map) ) + { +free_cpumask_var (cmv); + ret =x86_mcerr ("No online CPU passed\n" , -EINVAL ); +break ; + } +if ( !cpumask_subset (cpumap, &cpu_online_map) )dprintk (XENLOG_INFO ,"Not all required CPUs are online\n" ); }
@@ -1558,19 +1561,25 @@ long do_mca(XEN_GUEST_HANDLE(xen_mc_t) u {case XEN_MC_INJECT_TYPE_MCE :if ( mce_broadcast && - !cpumask_equal (&cpumap, &cpu_online_map) ) + !cpumask_equal (cpumap, &cpu_online_map) )printk ("Not trigger MCE on all CPUs, may HANG!\n" ); -on_selected_cpus (&cpumap, x86_mc_mceinject,NULL ,1 ); +on_selected_cpus (cpumap, x86_mc_mceinject,NULL ,1 );break ;case XEN_MC_INJECT_TYPE_CMCI :if ( !cmci_support ) -return x86_mcerr ( + ret =x86_mcerr ("No CMCI supported in platform\n" , -EINVAL ); -on_selected_cpus (&cpumap, x86_cmci_inject,NULL ,1 ); +else +on_selected_cpus (cpumap, x86_cmci_inject,NULL ,1 );break ;default : -return x86_mcerr ("Wrong mca type\n" , -EINVAL ); + ret =x86_mcerr ("Wrong mca type\n" , -EINVAL ); +break ; } + +if (cpumap != &cpu_online_map) +free_cpumask_var (cmv); +break ; }
xen/arch/x86/platform_hypercall.c +12 -8
@@ -346,7 +346,7 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xeuint32_t cpu;uint64_t idletime, now =NOW ();struct xenctl_cpumap ctlmap; -cpumask_t cpumap; +cpumask_var_t cpumap;XEN_GUEST_HANDLE (uint8) cpumap_bitmap;XEN_GUEST_HANDLE (uint64) idletimes;
@@ -366,22 +366,26 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe goto out;guest_from_compat_handle (idletimes, op->u.getidletime.idletime); - for_each_cpu_mask ( cpu, cpumap ) + for_each_cpu_mask ( cpu, *cpumap ) {if ( idle_vcpu[cpu] ==NULL ) -cpu_clear (cpu, cpumap); +cpumask_clear_cpu (cpu, cpumap); idletime =get_cpu_idle_time (cpu); - ret = -EFAULT ;if (copy_to_guest_offset (idletimes, cpu, &idletime,1 ) ) - goto out; + { + ret = -EFAULT ; +break ; + } } op->u.getidletime.now = now; -if ( (ret =cpumask_to_xenctl_cpumap (&ctlmap, &cpumap)) !=0 ) - goto out; +if ( ret ==0 ) + ret =cpumask_to_xenctl_cpumap (&ctlmap, cpumap); +free_cpumask_var (cpumap); - ret =copy_to_guest (u_xenpf_op, op,1 ) ? -EFAULT :0 ; +if ( ret ==0 &©_to_guest (u_xenpf_op, op,1 ) ) + ret = -EFAULT ; }break ;
xen/common/domctl.c +34 -15
99 lines not on this page · raw message
xen/common/trace.c +10 -1
@@ -378,7 +378,16 @@ int tb_control(xen_sysctl_tbuf_op_t *tbc tbc->size = t_info_pages *PAGE_SIZE ;break ;case XEN_SYSCTL_TBUFOP_set_cpu_mask: - rc =xenctl_cpumap_to_cpumask (&tb_cpu_mask, &tbc->cpu_mask); + { +cpumask_var_t mask; + + rc =xenctl_cpumap_to_cpumask (&mask, &tbc->cpu_mask); +if ( !rc ) + { +cpumask_copy (&tb_cpu_mask, mask); +free_cpumask_var (mask); + } + }break ;case XEN_SYSCTL_TBUFOP_set_evt_mask: tb_event_mask = tbc->evt_mask;
xen/include/xen/cpumask.h +2 -4
@@ -544,9 +544,7 @@ extern cpumask_t cpu_present_map;/* Copy to/from cpumap provided by control tools. */ struct xenctl_cpumap ; -int cpumask_to_xenctl_cpumap ( -struct xenctl_cpumap *enctl_cpumap,cpumask_t *cpumask); -int xenctl_cpumap_to_cpumask ( -cpumask_t *cpumask,struct xenctl_cpumap *enctl_cpumap); +int cpumask_to_xenctl_cpumap (struct xenctl_cpumap *,const cpumask_t *); +int xenctl_cpumap_to_cpumask (cpumask_var_t *,const struct xenctl_cpumap *);#endif /* __XEN_CPUMASK_H */
cpumask <=> xenctl_cpumap: allocate CPU masks and byte maps dynamically
Generally there was a NR_CPUS-bits wide array in these functions and another (through a cpumask_t) on their callers' stacks, which may get a little large for big NR_CPUS. As the functions can fail anyway, do the allocation in there.
For the x86/MCA case this require a little code restructuring: By using different CPU mask accessors it was possible to avoid allocating a mask in the broadcast case. Also, this was the only user that failed to check the return value of the conversion function (which could have led to undefined behvior).
Also constify the input parameters of the two functions.
xen/arch/x86/cpu/mcheck/mce.c +26 -17
70 lines not on this page · raw message
xen/arch/x86/platform_hypercall.c +12 -8
@@ -346,7 +346,7 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xeuint32_t cpu;uint64_t idletime, now =NOW ();struct xenctl_cpumap ctlmap; -cpumask_t cpumap; +cpumask_var_t cpumap;XEN_GUEST_HANDLE (uint8) cpumap_bitmap;XEN_GUEST_HANDLE (uint64) idletimes;
@@ -366,22 +366,26 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe goto out;guest_from_compat_handle (idletimes, op->u.getidletime.idletime); - for_each_cpu_mask ( cpu, cpumap ) + for_each_cpu_mask ( cpu, *cpumap ) {if ( idle_vcpu[cpu] ==NULL ) -cpu_clear (cpu, cpumap); +cpumask_clear_cpu (cpu, cpumap); idletime =get_cpu_idle_time (cpu); - ret = -EFAULT ;if (copy_to_guest_offset (idletimes, cpu, &idletime,1 ) ) - goto out; + { + ret = -EFAULT ; +break ; + } } op->u.getidletime.now = now; -if ( (ret =cpumask_to_xenctl_cpumap (&ctlmap, &cpumap)) !=0 ) - goto out; +if ( ret ==0 ) + ret =cpumask_to_xenctl_cpumap (&ctlmap, cpumap); +free_cpumask_var (cpumap); - ret =copy_to_guest (u_xenpf_op, op,1 ) ? -EFAULT :0 ; +if ( ret ==0 &©_to_guest (u_xenpf_op, op,1 ) ) + ret = -EFAULT ; }break ;
xen/common/domctl.c +34 -15
99 lines not on this page · raw message
xen/common/trace.c +10 -1
@@ -378,7 +378,16 @@ int tb_control(xen_sysctl_tbuf_op_t *tbc tbc->size = t_info_pages *PAGE_SIZE ;break ;case XEN_SYSCTL_TBUFOP_set_cpu_mask: - rc =xenctl_cpumap_to_cpumask (&tb_cpu_mask, &tbc->cpu_mask); + { +cpumask_var_t mask; + + rc =xenctl_cpumap_to_cpumask (&mask, &tbc->cpu_mask); +if ( !rc ) + { +cpumask_copy (&tb_cpu_mask, mask); +free_cpumask_var (mask); + } + }break ;case XEN_SYSCTL_TBUFOP_set_evt_mask: tb_event_mask = tbc->evt_mask;
xen/include/xen/cpumask.h +2 -4
@@ -544,9 +544,7 @@ extern cpumask_t cpu_present_map;/* Copy to/from cpumap provided by control tools. */ struct xenctl_cpumap ; -int cpumask_to_xenctl_cpumap ( -struct xenctl_cpumap *enctl_cpumap,cpumask_t *cpumask); -int xenctl_cpumap_to_cpumask ( -cpumask_t *cpumask,struct xenctl_cpumap *enctl_cpumap); +int cpumask_to_xenctl_cpumap (struct xenctl_cpumap *,const cpumask_t *); +int xenctl_cpumap_to_cpumask (cpumask_var_t *,const struct xenctl_cpumap *);#endif /* __XEN_CPUMASK_H */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel