From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
Dario Faggioli <dfaggioli@suse.com>,
Juergen Gross <jgross@suse.com>,
George Dunlap <gwd@xenproject.org>,
Oleksii Kurochko <oleksii.kurochko@gmail.com>
Subject: Re: [PATCH for-4.22?] domctl: correct return value of XEN_DOMCTL_[gs]etvcpuaffinity
Date: Tue, 16 Jun 2026 19:12:08 +0200 [thread overview]
Message-ID: <ajGD6B4kHhCC9wql@macbook.local> (raw)
In-Reply-To: <8b7daaa3-418e-4ec7-90a6-775e0a964b76@suse.com>
On Mon, Jun 15, 2026 at 02:00:39PM +0200, Jan Beulich wrote:
> 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: 6e4ecc6d5884 ("sched: DOMCTL_*vcpuaffinity works with hard and soft affinity")
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- a/xen/common/sched/core.c
> +++ b/xen/common/sched/core.c
> @@ -1705,6 +1705,7 @@ int vcpu_affinity_domctl(struct domain *
> {
> cpumask_var_t new_affinity, old_affinity;
> cpumask_t *online = cpupool_domain_master_cpumask(v->domain);
> + int hret = 0;
>
> /*
> * We want to be able to restore hard affinity if we are trying
> @@ -1726,8 +1727,6 @@ int vcpu_affinity_domctl(struct domain *
> 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.
> @@ -1746,7 +1745,7 @@ int vcpu_affinity_domctl(struct domain *
> * 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 )
> {
> @@ -1777,6 +1776,8 @@ int vcpu_affinity_domctl(struct domain *
> ret = cpumask_to_xenctl_bitmap(&vcpuaff->cpumap_soft, new_affinity);
> }
>
> + ret = hret ?: ret;
Here you seem to have a preference to keep the error from the first
caller (possibly XEN_VCPUAFFINITY_HARD if set), but below...
> +
> setvcpuaffinity_out:
> free_cpumask_var(new_affinity);
> free_cpumask_var(old_affinity);
> @@ -1788,7 +1789,7 @@ int vcpu_affinity_domctl(struct domain *
> unit->cpu_hard_affinity);
> if ( vcpuaff->flags & XEN_VCPUAFFINITY_SOFT )
> ret = cpumask_to_xenctl_bitmap(&vcpuaff->cpumap_soft,
> - unit->cpu_soft_affinity);
> + unit->cpu_soft_affinity) ?: ret;
...you overwrite it with a possible error returned from the last
cpumask_to_xenctl_bitmap() call. Don't you want to do the same, and
return the first error if possible? IOW: store the error from the
first call into hret and use the elvis operator to set ret after both
calls.
Thanks, Roger.
prev parent reply other threads:[~2026-06-16 17:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 12:00 [PATCH for-4.22?] domctl: correct return value of XEN_DOMCTL_[gs]etvcpuaffinity Jan Beulich
2026-06-16 17:12 ` Roger Pau Monné [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ajGD6B4kHhCC9wql@macbook.local \
--to=roger.pau@citrix.com \
--cc=dfaggioli@suse.com \
--cc=gwd@xenproject.org \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=oleksii.kurochko@gmail.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.