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

Re: [PATCH] domain: use unsigned loop induction variable in complete_domain_destroy()


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Wed, 4 Mar 2026 18:36:55 +0100
  • 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=tYj4Aq4H/z18cpo/OR/vwiWEXB53aTYcBr5skHnHH2g=; b=cCGCZIDC9hCq5/uQcOHGd94PIUlE9wS9sfKGpIOJd5qvOtqdbCuxLGOwy2ce91ySukKQZFKf4AIWS0Vs63jis2NWudhQ25LWLvOAIjy3SlqJFZxuGPUl1PRYlHWbUJIiiDOuScMwJzJFcPww3cfkZZ2MYPATlnlgGDmBcHBUITbm+FOy2YQwnpXuii/GthUfA/5B7aNvmmyd7LQE62fnQEQW3QX76CMGXzRHijNAOp9HysGgiC4a3x+Ik/sI+tuoqMOYGbG75lB0PJwHggIfv+qeZRgjEqEFXL1TNvoOEBlT7OtxbPTMXPHDpPNekYRZJLX79LtRJaFvhDMy7o3q2Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=L3kf0YcMg7PPQ1M4XhDPFfUO7xubTg+qUIzhFOFYiYfS6S92cnkjMET69eSnq7tZAIDYJ1ie1dyE9Cy3gxsasWkqmGhKZXW71TtUmFSLLjveXWGzd4S3PFcDZvDM39i0VsDpxhsiNvFmAlem2QwQbrLkSxfV6e5OrRlNlIfc+0JzyynJ8lglk9dURJ/MTgkPXOpnoFSd4aZxY9d7sXLnN55OXfFB7vQSd6RwQloqrsaoTRKv0zsKKPnLbm/rAWrG0kYktg02SzM+x6PDJ9r3/7rVRRX9ch8QNESv0H6mY6wTe/OHadmC1NIFZQN7WCDrzHZr1rtYdqaNgNNlSBV1DA==
  • 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>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Wed, 04 Mar 2026 17:37:13 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Wed, Mar 04, 2026 at 04:48:07PM +0100, Jan Beulich wrote:
> On 04.03.2026 16:38, Roger Pau Monné wrote:
> > On Thu, Feb 26, 2026 at 10:01:45AM +0100, Jan Beulich wrote:
> >> --- a/xen/common/domain.c
> >> +++ b/xen/common/domain.c
> >> @@ -1475,7 +1475,7 @@ static void cf_check complete_domain_des
> >>  {
> >>      struct domain *d = container_of(head, struct domain, rcu);
> >>      struct vcpu *v;
> >> -    int i;
> >> +    unsigned int i;
> >>  
> >>      /*
> >>       * Flush all state for the vCPU previously having run on the current 
> >> CPU.
> >> @@ -1485,7 +1485,7 @@ static void cf_check complete_domain_des
> >>       */
> >>      sync_local_execstate();
> >>  
> >> -    for ( i = d->max_vcpus - 1; i >= 0; i-- )
> >> +    for ( i = d->max_vcpus; i-- > 0; )
> > 
> > Is there any reason we need to do those loops backwards?
> > 
> > I would rather do:
> > 
> > for ( i = 0; i < d->max_vcpus; i++ )
> > 
> > ?
> 
> I think it's better to keep like this. The latter of the loops would better
> clear d->vcpu[i] (to not leave a dangling pointer), and there may be code
> which assumes that for ordinary domains d->vcpu[] is populated contiguously.
> Hardly any code should touch the vCPU-s of a domain destructed this far, but
> still better safe than sorry, I guess.

Yes, you are right.  sched_destroy_vcpu() relies on this specific
top-down calling.

Since you are adjusting the code anyway, it might be worth writing
down that some functions (like sched_destroy_vcpu()) expect to be
called with a top-down order of vCPUs.

For the change itself:

Acked-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

Thanks, Roger.



 


Rackspace

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