domctl: correct return value of XEN_DOMCTL_[gs]etvcpuaffinity

cpumask_to_xenctl_bitmap() may return errors. Clearing the error indicator
of an earlier such call by a (successful) later call is misleading the
caller. For "set", keep setting soft affinity if the hard affinity copy-
back fails; only accumulate respective errors.

While fiddling with return values, also drop a redundant clearing of
"ret". This eliminates a Misra C:2012 rule 2.2 ("There shall be no dead
code") violation.

Fixes: 6e4ecc6d58 ("sched: DOMCTL_*vcpuaffinity works with hard and soft affinity")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
master commit: 6a21252a74
master date: 2026-06-18 10:02:34 +0200
This commit is contained in:
Jan Beulich committed 2026-06-30 15:00:49 +02:00
1 parent f8a6e2f4ad
commit 6ad6771900
1 file changed
+10 -12
+10 -12
View File
@@ -1675,7 +1675,7 @@ int vcpu_affinity_domctl(struct domain *d, uint32_t cmd,
{
struct vcpu *v;
const struct sched_unit *unit;
int ret = 0;
int ret = 0, hret = 0;
if ( vcpuaff->vcpu >= d->max_vcpus )
return -EINVAL;
@@ -1713,19 +1713,17 @@ int vcpu_affinity_domctl(struct domain *d, uint32_t cmd,
if ( vcpuaff->flags & XEN_VCPUAFFINITY_FORCE )
vcpu_temporary_affinity(v, NR_CPUS, VCPU_AFFINITY_OVERRIDE);
ret = 0;
/*
* We both set a new affinity and report back to the caller what
* the scheduler will be effectively using.
*/
if ( vcpuaff->flags & XEN_VCPUAFFINITY_HARD )
{
ret = xenctl_bitmap_to_bitmap(cpumask_bits(new_affinity),
&vcpuaff->cpumap_hard, nr_cpu_ids);
if ( !ret )
ret = vcpu_set_hard_affinity(v, new_affinity);
if ( ret )
hret = xenctl_bitmap_to_bitmap(cpumask_bits(new_affinity),
&vcpuaff->cpumap_hard, nr_cpu_ids);
if ( !hret )
hret = vcpu_set_hard_affinity(v, new_affinity);
if ( hret )
goto setvcpuaffinity_out;
/*
@@ -1733,7 +1731,7 @@ int vcpu_affinity_domctl(struct domain *d, uint32_t cmd,
* cpupool's online mask and the new hard affinity.
*/
cpumask_and(new_affinity, online, unit->cpu_hard_affinity);
ret = cpumask_to_xenctl_bitmap(&vcpuaff->cpumap_hard, new_affinity);
hret = cpumask_to_xenctl_bitmap(&vcpuaff->cpumap_hard, new_affinity);
}
if ( vcpuaff->flags & XEN_VCPUAFFINITY_SOFT )
{
@@ -1770,14 +1768,14 @@ int vcpu_affinity_domctl(struct domain *d, uint32_t cmd,
else
{
if ( vcpuaff->flags & XEN_VCPUAFFINITY_HARD )
ret = cpumask_to_xenctl_bitmap(&vcpuaff->cpumap_hard,
unit->cpu_hard_affinity);
hret = cpumask_to_xenctl_bitmap(&vcpuaff->cpumap_hard,
unit->cpu_hard_affinity);
if ( vcpuaff->flags & XEN_VCPUAFFINITY_SOFT )
ret = cpumask_to_xenctl_bitmap(&vcpuaff->cpumap_soft,
unit->cpu_soft_affinity);
}
return ret;
return hret ?: ret;
}
bool alloc_affinity_masks(struct affinity_masks *affinity)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.