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

[xen master] domain: use unsigned loop induction variable in complete_domain_destroy()



commit 505b2afae44caa9df189957c6e298017b2ef7988
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Thu Mar 5 09:28:27 2026 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Mar 5 09:28:27 2026 +0100

    domain: use unsigned loop induction variable in complete_domain_destroy()
    
    Using plain (signed) int variables as array indexes can be unhelpful on at
    least x86, where the compiler may see the need to insert sign-extension
    insns (strictly speaking it should be able to avoid that when the loop
    continuation condition says >= 0, but that's not generally the case even
    with gcc15).
    
    Observed effects with gcc15 (will of course vary with compiler version and
    level of optimization):
    - on x86, one less preserved register in use, yet due to sub-optimal
      choice of register variables still a small code size increase (%r12
      isn't a good choice when it's used for base-without-index addressing, as
      it requires a SIB byte which other registers wouldn't require),
    - on Arm64 code size decreases, albeit that's eaten up by padding which is
      being inserted ahead of a few labels,
    - on Arm32 code size increases for a reason I didn't fully understand (my
      ability to read Arm assembly is still somewhat limited).
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Acked-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
 xen/common/domain.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index e06174fca7..d24be268ae 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1475,7 +1475,7 @@ static void cf_check complete_domain_destroy(struct 
rcu_head *head)
 {
     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,11 @@ static void cf_check complete_domain_destroy(struct 
rcu_head *head)
      */
     sync_local_execstate();
 
-    for ( i = d->max_vcpus - 1; i >= 0; i-- )
+    /*
+     * Iterating downwards is a requirement here, as e.g. sched_destroy_vcpu()
+     * relies on this.
+     */
+    for ( i = d->max_vcpus; i-- > 0; )
     {
         if ( (v = d->vcpu[i]) == NULL )
             continue;
@@ -1511,7 +1515,7 @@ static void cf_check complete_domain_destroy(struct 
rcu_head *head)
     xfree(d->vm_event_share);
 #endif
 
-    for ( i = d->max_vcpus - 1; i >= 0; i-- )
+    for ( i = d->max_vcpus; i-- > 0; )
         if ( (v = d->vcpu[i]) != NULL )
             vcpu_destroy(v);
 
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

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