[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH for-4.22?] domctl: correct return value of XEN_DOMCTL_[gs]etvcpuaffinity


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 16 Jun 2026 19:12:08 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SqboQVx8R1d3+2wOicZCmfr9fGWBqILClvWS6jNMVxc=; b=T+jxy38yzY5VeRwLYc0Bf24pkdOFZ79/oyzrMApW3imQrk6yglw37iXDxbjMm52usd8yUPS/RegUqswdRB+ofAinJV7lhpibBfXANWX6D8AZ1K/Mo9IMRKKXRq46ihhU52D+48Ce/qkI6shOMbn5+7N/cirR5VyVgsRnc7PxEh0Jz2dkkFUu5QK8LaNXb48lMFbzgepbC1GlA0NfOCo6t97cYyLPuSQbwk8SWLhB02vMsdiGe6vZ7yurUgR6trdPsXYloA6FnPjQZF7mIOHco6NjQ+45Cu5h0Ed9IaB9z18eWTD9E9gTITSMwMcEl6s2xUmNn2KspB5Hf9XmBLavgw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nHBI6/9Xr9MRIiTBF2qHQ/4Hzp8VSnrcgbGLTkUEzNftMgBJhlcS7UlmEeCju6rDAKUsbwAg0hmJF/hW0bD8TrO7bJW7Ui3/9ZA8ZdEkhtclsQXc10YsFE0RZcHLGlwGi+4eQWKDaTJEIIDJqdvURqRGpnNXvil0tRCElck1JqB8eI7mrf2OChkmeqb/VRiHrdz33hFF31OqJWb40whtJGEUed4Yj2vkcerWEBq7A1+CD769Qmch1HEIkQXQIfBrCK5z3hijP1TGkkGr+GZC+FPDU1dm2ptywW/cHbyi+0h3MgvRxF3yYfQPyNUpJHtBvMEj5cHjsfpdDRYX05BSHw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Dario Faggioli <dfaggioli@xxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, George Dunlap <gwd@xxxxxxxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
  • Delivery-date: Tue, 16 Jun 2026 17:12:36 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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@xxxxxxxx>
> 
> --- 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.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.