Skip to contentSkip to conversation

address remaining rule 13.1 violations; mark clean

PATCH In review Jan Beulich 5 participants 16 messages Sep 3 – Sep 30

lore
Share & tools
lore
#0 lore raw

cover address remaining rule 13.1 violations; mark clean

"Initializer lists shall not contain persistent side effects"

1: x86/pagewalk: avoid ACCESS_ONCE() in compound literals 2: Arm/guestcopy: avoid use of "current" in compound literals 3: sched/core: avoid use of "current" in initializer lists 4: automation/Eclair: tag rule 13.1 as clean

Jan

#1 lore raw

PATCH 1/4 x86/pagewalk: avoid ACCESS_ONCE() in compound literals

Compound literals are also covered by Misra C:2012 rule 13.1 ("Initializer lists shall not contain persistent side effects"), and (sadly?) that rule also applies to lists with just a single element, or more generally with just a single side effect. Use intermediate variables to overcome this as well as ACCESS_ONCE()'s restriction to be usable on scalar types only.

No functional change intended.

Fixes 0345b835dc97 ("x86/pagewalk: Read guest PTEs with ACCESS_ONCE()")
xen/arch/x86/mm/guest_walk.c +12 -4
@@ -129,7 +129,9 @@ guest_walk_tables(const struct vcpu *v,
             guest_l4_table_offset(va) * sizeof(gw->l4e);
     if ( !hvmemul_read_cache(v, l4gpa, &gw->l4e, sizeof(gw->l4e)) )
     {
-        gw->l4e = (guest_l4e_t){ ACCESS_ONCE(l4p[guest_l4_table_offset(va)].l4) };
+        guest_intpte_t l4e = ACCESS_ONCE(l4p[guest_l4_table_offset(va)].l4);
+
+        gw->l4e = (guest_l4e_t){ l4e };
         hvmemul_write_cache(v, l4gpa, &gw->l4e, sizeof(gw->l4e));
     }
     gflags = guest_l4e_get_flags(gw->l4e);
@@ -164,7 +166,9 @@ guest_walk_tables(const struct vcpu *v,
             guest_l3_table_offset(va) * sizeof(gw->l3e);
     if ( !hvmemul_read_cache(v, l3gpa, &gw->l3e, sizeof(gw->l3e)) )
     {
-        gw->l3e = (guest_l3e_t){ ACCESS_ONCE(l3p[guest_l3_table_offset(va)].l3) };
+        guest_intpte_t l3e = ACCESS_ONCE(l3p[guest_l3_table_offset(va)].l3);
+
+        gw->l3e = (guest_l3e_t){ l3e };
         hvmemul_write_cache(v, l3gpa, &gw->l3e, sizeof(gw->l3e));
     }
     gflags = guest_l3e_get_flags(gw->l3e);
@@ -264,7 +268,9 @@ guest_walk_tables(const struct vcpu *v,
     l2gpa += guest_l2_table_offset(va) * sizeof(gw->l2e);
     if ( !hvmemul_read_cache(v, l2gpa, &gw->l2e, sizeof(gw->l2e)) )
     {
-        gw->l2e = (guest_l2e_t){ ACCESS_ONCE(l2p[guest_l2_table_offset(va)].l2) };
+        guest_intpte_t l2e = ACCESS_ONCE(l2p[guest_l2_table_offset(va)].l2);
+
+        gw->l2e = (guest_l2e_t){ l2e };
         hvmemul_write_cache(v, l2gpa, &gw->l2e, sizeof(gw->l2e));
     }
 
@@ -353,7 +359,9 @@ guest_walk_tables(const struct vcpu *v,
             guest_l1_table_offset(va) * sizeof(gw->l1e);
     if ( !hvmemul_read_cache(v, l1gpa, &gw->l1e, sizeof(gw->l1e)) )
     {
-        gw->l1e = (guest_l1e_t){ ACCESS_ONCE(l1p[guest_l1_table_offset(va)].l1) };
+        guest_intpte_t l1e = ACCESS_ONCE(l1p[guest_l1_table_offset(va)].l1);
+
+        gw->l1e = (guest_l1e_t){ l1e };
         hvmemul_write_cache(v, l1gpa, &gw->l1e, sizeof(gw->l1e));
     }
 
#2 lore raw

Re: [PATCH 1/4] x86/pagewalk: avoid ACCESS_ONCE() in compound literals

Quoted 15 lines · Jan Beulich

Compound literals are also covered by Misra C:2012 rule 13.1 ("Initializer lists shall not contain persistent side effects"), and (sadly?) that rule also applies to lists with just a single element, or more generally with just a single side effect. Use intermediate variables to overcome this as well as ACCESS_ONCE()'s restriction to be usable on scalar types only.

No functional change intended.

Fixes 0345b835dc97 ("x86/pagewalk: Read guest PTEs with ACCESS_ONCE()")

xen/arch/x86/mm/guest_walk.c guest_walk_tables(const struct vcpu *v, · line 134

Quoted 7 lines
xen/arch/x86/mm/guest_walk.c +3 -1
@@ -129,7 +129,9 @@ guest_walk_tables(const struct vcpu *v,
             guest_l4_table_offset(va) * sizeof(gw->l4e);
     if ( !hvmemul_read_cache(v, l4gpa, &gw->l4e, sizeof(gw->l4e)) )
     {
-        gw->l4e = (guest_l4e_t){ ACCESS_ONCE(l4p[guest_l4_table_offset(va)].l4) };
+        guest_intpte_t l4e = ACCESS_ONCE(l4p[guest_l4_table_offset(va)].l4);
+
+        gw->l4e = (guest_l4e_t){ l4e };

Did you consider using the l4e_from_intpte() and similar helpers here and below?

Thanks, Roger.

#3 lore raw

Re: [PATCH 1/4] x86/pagewalk: avoid ACCESS_ONCE() in compound literals

Quoted 13 lines · Roger Pau Monné
Quoted 12 lines · Jan Beulich

Compound literals are also covered by Misra C:2012 rule 13.1 ("Initializer lists shall not contain persistent side effects"), and (sadly?) that rule also applies to lists with just a single element, or more generally with just a single side effect. Use intermediate variables to overcome this as well as ACCESS_ONCE()'s restriction to be usable on scalar types only.

No functional change intended.

Fixes 0345b835dc97 ("x86/pagewalk: Read guest PTEs with ACCESS_ONCE()")
Quoted 13 lines

xen/arch/x86/mm/guest_walk.c guest_walk_tables(const struct vcpu *v, · line 134

Quoted 10 lines
xen/arch/x86/mm/guest_walk.c +3 -1
@@ -129,7 +129,9 @@ guest_walk_tables(const struct vcpu *v,
             guest_l4_table_offset(va) * sizeof(gw->l4e);
     if ( !hvmemul_read_cache(v, l4gpa, &gw->l4e, sizeof(gw->l4e)) )
     {
-        gw->l4e = (guest_l4e_t){ ACCESS_ONCE(l4p[guest_l4_table_offset(va)].l4) };
+        guest_intpte_t l4e = ACCESS_ONCE(l4p[guest_l4_table_offset(va)].l4);
+
+        gw->l4e = (guest_l4e_t){ l4e };

Did you consider using the l4e_from_intpte() and similar helpers here and below?

No, I didn't, as they aren't applicable to guest_l<N>e_t. guest_intpte_t aliases intpte_t only for GUEST_PAGING_LEVELS > 2.

Jan

#4 lore raw

Re: [PATCH 1/4] x86/pagewalk: avoid ACCESS_ONCE() in compound literals

Quoted 28 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monné
Quoted 12 lines · Jan Beulich

Compound literals are also covered by Misra C:2012 rule 13.1 ("Initializer lists shall not contain persistent side effects"), and (sadly?) that rule also applies to lists with just a single element, or more generally with just a single side effect. Use intermediate variables to overcome this as well as ACCESS_ONCE()'s restriction to be usable on scalar types only.

No functional change intended.

Fixes 0345b835dc97 ("x86/pagewalk: Read guest PTEs with ACCESS_ONCE()")
Quoted 13 lines

xen/arch/x86/mm/guest_walk.c guest_walk_tables(const struct vcpu *v, · line 134

Quoted 10 lines
xen/arch/x86/mm/guest_walk.c +3 -1
@@ -129,7 +129,9 @@ guest_walk_tables(const struct vcpu *v,
             guest_l4_table_offset(va) * sizeof(gw->l4e);
     if ( !hvmemul_read_cache(v, l4gpa, &gw->l4e, sizeof(gw->l4e)) )
     {
-        gw->l4e = (guest_l4e_t){ ACCESS_ONCE(l4p[guest_l4_table_offset(va)].l4) };
+        guest_intpte_t l4e = ACCESS_ONCE(l4p[guest_l4_table_offset(va)].l4);
+
+        gw->l4e = (guest_l4e_t){ l4e };

Did you consider using the l4e_from_intpte() and similar helpers here and below?

Quoted 2 lines

No, I didn't, as they aren't applicable to guest_l<N>e_t. guest_intpte_t aliases intpte_t only for GUEST_PAGING_LEVELS > 2.

Right, as otherwise it's a 32bit PTE.

Thanks, Roger.

#5 lore raw

PATCH 2/4 Arm/guestcopy: avoid use of "current" in compound literals

In reply to Jan Beulich

Compound literals are also covered by Misra C:2012 rule 13.1 ("Initializer lists shall not contain persistent side effects"), and (sadly?) that rule also applies to lists with just a single element, or more generally with just a single side effect. Use intermediate variables to overcome this.

No functional change intended.

---
This is assumed to go on top of "Arm/guestcopy: deviate copy_guest() uses just like their x86 counterparts", conflicting contextually but not functionally.

xen/arch/arm/guestcopy.c +12 -4
@@ -109,29 +109,37 @@ static unsigned long copy_guest(void *bu
 
 unsigned long raw_copy_to_guest(void *to, const void *from, unsigned int len)
 {
+    struct vcpu *curr = current;
+
     return copy_guest((void *)from, /* COPY_to_guest doesn't modify */
-                      (vaddr_t)to, len, GVA_INFO(current),
+                      (vaddr_t)to, len, GVA_INFO(curr),
                       COPY_to_guest | COPY_linear);
 }
 
 unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from,
                                              unsigned int len)
 {
+    struct vcpu *curr = current;
+
     return copy_guest((void *)from, /* COPY_to_guest doesn't modify */
-                      (vaddr_t)to, len, GVA_INFO(current),
+                      (vaddr_t)to, len, GVA_INFO(curr),
                       COPY_to_guest | COPY_flush_dcache | COPY_linear);
 }
 
 unsigned long raw_clear_guest(void *to, unsigned int len)
 {
-    return copy_guest(NULL, (vaddr_t)to, len, GVA_INFO(current),
+    struct vcpu *curr = current;
+
+    return copy_guest(NULL, (vaddr_t)to, len, GVA_INFO(curr),
                       COPY_to_guest | COPY_linear);
 }
 
 unsigned long raw_copy_from_guest(void *to, const void __user *from,
                                   unsigned int len)
 {
-    return copy_guest(to, (vaddr_t)from, len, GVA_INFO(current),
+    struct vcpu *curr = current;
+
+    return copy_guest(to, (vaddr_t)from, len, GVA_INFO(curr),
                       COPY_from_guest | COPY_linear);
 }
 
Reviewed-by on v1 2/4
#6 lore raw

Re: [PATCH 2/4] Arm/guestcopy: avoid use of "current" in compound literals

Quoted 9 lines · Jan Beulich

Compound literals are also covered by Misra C:2012 rule 13.1 ("Initializer lists shall not contain persistent side effects"), and (sadly?) that rule also applies to lists with just a single element, or more generally with just a single side effect. Use intermediate variables to overcome this.

No functional change intended.

~Michal

#7 lore raw

PATCH 3/4 sched/core: avoid use of "current" in initializer lists

In reply to Jan Beulich

TRACE_TIME() uses an initializer list and hence is covered by Misra C:2012 rule 13.1 ("Initializer lists shall not contain persistent side effects"). Use intermediate variables to address this.

In vcpu_yield() take the opportunity to rename the existing variable which better would have been used already before.

In do_sched_op() extend the scope of and rename an existing variable. Also drop a pointless (and slightly malformed, style-wise) cast there, and adjust to other one to by style conformant.

No functional change intended.

---
Note that the violations presently are reported only for Arm. Similar issues would exist on x86 in Clang builds, afaict.

xen/common/sched/core.c +15 -14
@@ -1531,20 +1531,20 @@ static long do_poll(const struct sched_p
 /* Voluntarily yield the processor for this allocation. */
 long vcpu_yield(void)
 {
-    struct vcpu * v=current;
+    struct vcpu *curr = current;
     spinlock_t *lock;
 
     rcu_read_lock(&sched_res_rculock);
 
-    lock = unit_schedule_lock_irq(v->sched_unit);
-    sched_yield(vcpu_scheduler(v), v->sched_unit);
-    unit_schedule_unlock_irq(lock, v->sched_unit);
+    lock = unit_schedule_lock_irq(curr->sched_unit);
+    sched_yield(vcpu_scheduler(curr), curr->sched_unit);
+    unit_schedule_unlock_irq(lock, curr->sched_unit);
 
     rcu_read_unlock(&sched_res_rculock);
 
     SCHED_STAT_CRANK(vcpu_yield);
 
-    TRACE_TIME(TRC_SCHED_YIELD, current->domain->domain_id, current->vcpu_id);
+    TRACE_TIME(TRC_SCHED_YIELD, curr->domain->domain_id, curr->vcpu_id);
     raise_softirq(SCHEDULE_SOFTIRQ);
     return 0;
 }
@@ -1914,6 +1914,8 @@ typedef long ret_t;
 
 ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
+    const struct vcpu *curr = current;
+    struct domain *currd = curr->domain;
     ret_t ret = 0;
 
     switch ( cmd )
@@ -1938,9 +1940,9 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
         if ( copy_from_guest(&sched_shutdown, arg, 1) )
             break;
 
-        TRACE_TIME(TRC_SCHED_SHUTDOWN, current->domain->domain_id,
-                   current->vcpu_id, sched_shutdown.reason);
-        ret = domain_shutdown(current->domain, (u8)sched_shutdown.reason);
+        TRACE_TIME(TRC_SCHED_SHUTDOWN, currd->domain_id, curr->vcpu_id,
+                   sched_shutdown.reason);
+        ret = domain_shutdown(currd, sched_shutdown.reason);
 
         break;
     }
@@ -1948,19 +1950,18 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
     case SCHEDOP_shutdown_code:
     {
         struct sched_shutdown sched_shutdown;
-        struct domain *d = current->domain;
 
         ret = -EFAULT;
         if ( copy_from_guest(&sched_shutdown, arg, 1) )
             break;
 
-        TRACE_TIME(TRC_SCHED_SHUTDOWN_CODE, d->domain_id, current->vcpu_id,
+        TRACE_TIME(TRC_SCHED_SHUTDOWN_CODE, currd->domain_id, curr->vcpu_id,
                    sched_shutdown.reason);
 
-        spin_lock(&d->shutdown_lock);
-        if ( d->shutdown_code == SHUTDOWN_CODE_INVALID )
-            d->shutdown_code = (u8)sched_shutdown.reason;
-        spin_unlock(&d->shutdown_lock);
+        spin_lock(&currd->shutdown_lock);
+        if ( currd->shutdown_code == SHUTDOWN_CODE_INVALID )
+            currd->shutdown_code = (uint8_t)sched_shutdown.reason;
+        spin_unlock(&currd->shutdown_lock);
 
         ret = 0;
         break;
#8 lore raw

Re: [PATCH 3/4] sched/core: avoid use of "current" in initializer lists

Quoted 84 lines · Jan Beulich

TRACE_TIME() uses an initializer list and hence is covered by Misra C:2012 rule 13.1 ("Initializer lists shall not contain persistent side effects"). Use intermediate variables to address this.

In vcpu_yield() take the opportunity to rename the existing variable which better would have been used already before.

In do_sched_op() extend the scope of and rename an existing variable. Also drop a pointless (and slightly malformed, style-wise) cast there, and adjust to other one to by style conformant.

No functional change intended.

---
Note that the violations presently are reported only for Arm. Similar issues would exist on x86 in Clang builds, afaict.

xen/common/sched/core.c +11 -11
@@ -1531,20 +1531,20 @@ static long do_poll(const struct sched_p
  /* Voluntarily yield the processor for this allocation. */
  long vcpu_yield(void)
  {
-    struct vcpu * v=current;
+    struct vcpu *curr = current;
      spinlock_t *lock;
 
      rcu_read_lock(&sched_res_rculock);
 
-    lock = unit_schedule_lock_irq(v->sched_unit);
-    sched_yield(vcpu_scheduler(v), v->sched_unit);
-    unit_schedule_unlock_irq(lock, v->sched_unit);
+    lock = unit_schedule_lock_irq(curr->sched_unit);
+    sched_yield(vcpu_scheduler(curr), curr->sched_unit);
+    unit_schedule_unlock_irq(lock, curr->sched_unit);
 
      rcu_read_unlock(&sched_res_rculock);
 
      SCHED_STAT_CRANK(vcpu_yield);
 
-    TRACE_TIME(TRC_SCHED_YIELD, current->domain->domain_id, current->vcpu_id);
+    TRACE_TIME(TRC_SCHED_YIELD, curr->domain->domain_id, curr->vcpu_id);
      raise_softirq(SCHEDULE_SOFTIRQ);
      return 0;
  }
@@ -1914,6 +1914,8 @@ typedef long ret_t;
 
  ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
  {
+    const struct vcpu *curr = current;
+    struct domain *currd = curr->domain;
      ret_t ret = 0;
 
      switch ( cmd )
@@ -1938,9 +1940,9 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
          if ( copy_from_guest(&sched_shutdown, arg, 1) )
              break;
 
-        TRACE_TIME(TRC_SCHED_SHUTDOWN, current->domain->domain_id,
-                   current->vcpu_id, sched_shutdown.reason);
-        ret = domain_shutdown(current->domain, (u8)sched_shutdown.reason);
+        TRACE_TIME(TRC_SCHED_SHUTDOWN, currd->domain_id, curr->vcpu_id,
+                   sched_shutdown.reason);
+        ret = domain_shutdown(currd, sched_shutdown.reason);
 
          break;
      }
@@ -1948,19 +1950,18 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
      case SCHEDOP_shutdown_code:
      {
          struct sched_shutdown sched_shutdown;
-        struct domain *d = current->domain;
 
          ret = -EFAULT;
          if ( copy_from_guest(&sched_shutdown, arg, 1) )
              break;
 
-        TRACE_TIME(TRC_SCHED_SHUTDOWN_CODE, d->domain_id, current->vcpu_id,
+        TRACE_TIME(TRC_SCHED_SHUTDOWN_CODE, currd->domain_id, curr->vcpu_id,
                     sched_shutdown.reason);
 
-        spin_lock(&d->shutdown_lock);

xen/common/sched/core.c ret_t do_sched_op(int cmd, XEN_GUEST_HAN · line 1967

Quoted 10 lines
xen/common/sched/core.c +4 -3
-        if ( d->shutdown_code == SHUTDOWN_CODE_INVALID )
-            d->shutdown_code = (u8)sched_shutdown.reason;
-        spin_unlock(&d->shutdown_lock);
+        spin_lock(&currd->shutdown_lock);
+        if ( currd->shutdown_code == SHUTDOWN_CODE_INVALID )
+            currd->shutdown_code = (uint8_t)sched_shutdown.reason;
+        spin_unlock(&currd->shutdown_lock);
 
          ret = 0;
          break;

What about the use of current in SCHEDOP_watchdog and SCHEDOP_pin_override handling?

Juergen

#9 lore raw

Re: [PATCH 3/4] sched/core: avoid use of "current" in initializer lists

Quoted 46 lines · Jürgen Groß
Quoted 45 lines · Jan Beulich
xen/common/sched/core.c +10 -9
@@ -1914,6 +1914,8 @@ typedef long ret_t;
 
  ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
  {
+    const struct vcpu *curr = current;
+    struct domain *currd = curr->domain;
      ret_t ret = 0;
 
      switch ( cmd )
@@ -1938,9 +1940,9 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
          if ( copy_from_guest(&sched_shutdown, arg, 1) )
              break;
 
-        TRACE_TIME(TRC_SCHED_SHUTDOWN, current->domain->domain_id,
-                   current->vcpu_id, sched_shutdown.reason);
-        ret = domain_shutdown(current->domain, (u8)sched_shutdown.reason);
+        TRACE_TIME(TRC_SCHED_SHUTDOWN, currd->domain_id, curr->vcpu_id,
+                   sched_shutdown.reason);
+        ret = domain_shutdown(currd, sched_shutdown.reason);
 
          break;
      }
@@ -1948,19 +1950,18 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
      case SCHEDOP_shutdown_code:
      {
          struct sched_shutdown sched_shutdown;
-        struct domain *d = current->domain;
 
          ret = -EFAULT;
          if ( copy_from_guest(&sched_shutdown, arg, 1) )
              break;
 
-        TRACE_TIME(TRC_SCHED_SHUTDOWN_CODE, d->domain_id, current->vcpu_id,
+        TRACE_TIME(TRC_SCHED_SHUTDOWN_CODE, currd->domain_id, curr->vcpu_id,
                     sched_shutdown.reason);
 
-        spin_lock(&d->shutdown_lock);
-        if ( d->shutdown_code == SHUTDOWN_CODE_INVALID )
-            d->shutdown_code = (u8)sched_shutdown.reason;
-        spin_unlock(&d->shutdown_lock);
+        spin_lock(&currd->shutdown_lock);
+        if ( currd->shutdown_code == SHUTDOWN_CODE_INVALID )
+            currd->shutdown_code = (uint8_t)sched_shutdown.reason;
+        spin_unlock(&currd->shutdown_lock);
 
Quoted 5 lines

xen/common/sched/core.c ret_t do_sched_op(int cmd, XEN_GUEST_HAN · line 1967

Quoted 2 lines
xen/common/sched/core.c +0 -0
          ret = 0;
          break;

What about the use of current in SCHEDOP_watchdog and SCHEDOP_pin_override handling?

I can change those too if that's wanted, also the one in SCHEDOP_remote_shutdown handling then.

Jan

#10 lore raw

Re: [PATCH 3/4] sched/core: avoid use of "current" in initializer lists

Quoted 47 lines · Jan Beulich
Quoted 46 lines · Jürgen Groß
Quoted 45 lines · Jan Beulich
xen/common/sched/core.c +10 -9
@@ -1914,6 +1914,8 @@ typedef long ret_t;
 
   ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
   {
+    const struct vcpu *curr = current;
+    struct domain *currd = curr->domain;
       ret_t ret = 0;
 
       switch ( cmd )
@@ -1938,9 +1940,9 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
           if ( copy_from_guest(&sched_shutdown, arg, 1) )
               break;
 
-        TRACE_TIME(TRC_SCHED_SHUTDOWN, current->domain->domain_id,
-                   current->vcpu_id, sched_shutdown.reason);
-        ret = domain_shutdown(current->domain, (u8)sched_shutdown.reason);
+        TRACE_TIME(TRC_SCHED_SHUTDOWN, currd->domain_id, curr->vcpu_id,
+                   sched_shutdown.reason);
+        ret = domain_shutdown(currd, sched_shutdown.reason);
 
           break;
       }
@@ -1948,19 +1950,18 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
       case SCHEDOP_shutdown_code:
       {
           struct sched_shutdown sched_shutdown;
-        struct domain *d = current->domain;
 
           ret = -EFAULT;
           if ( copy_from_guest(&sched_shutdown, arg, 1) )
               break;
 
-        TRACE_TIME(TRC_SCHED_SHUTDOWN_CODE, d->domain_id, current->vcpu_id,
+        TRACE_TIME(TRC_SCHED_SHUTDOWN_CODE, currd->domain_id, curr->vcpu_id,
                      sched_shutdown.reason);
 
-        spin_lock(&d->shutdown_lock);
-        if ( d->shutdown_code == SHUTDOWN_CODE_INVALID )
-            d->shutdown_code = (u8)sched_shutdown.reason;
-        spin_unlock(&d->shutdown_lock);
+        spin_lock(&currd->shutdown_lock);
+        if ( currd->shutdown_code == SHUTDOWN_CODE_INVALID )
+            currd->shutdown_code = (uint8_t)sched_shutdown.reason;
+        spin_unlock(&currd->shutdown_lock);
 
Quoted 8 lines
Quoted 5 lines

xen/common/sched/core.c ret_t do_sched_op(int cmd, XEN_GUEST_HAN · line 1967

Quoted 2 lines
xen/common/sched/core.c +0 -0
           ret = 0;
           break;

What about the use of current in SCHEDOP_watchdog and SCHEDOP_pin_override handling?

I can change those too if that's wanted, also the one in SCHEDOP_remote_shutdown handling then.

I'd prefer that.

Juergen

#11 lore raw

PATCH 3/4 sched/core: avoid use of "current" in initializer lists

In reply to Jan Beulich

TRACE_TIME() uses an initializer list and hence is covered by Misra C:2012 rule 13.1 ("Initializer lists shall not contain persistent side effects"). Use intermediate variables to address this.

In vcpu_yield() take the opportunity to rename the existing variable which better would have been used already before.

In do_sched_op() extend the scope of and rename an existing variable. Use both variables throughout the function. Also drop a pointless (and slightly malformed, style-wise) cast there, and adjust to other one to by style conformant.

No functional change intended.

---
Note that the violations presently are reported only for Arm. Similar issues would exist on x86 in Clang builds, afaict.
---
v1.1: Also replace further (unrelated) uses of current in do_sched_op().

xen/common/sched/core.c +19 -19
@@ -1531,20 +1531,20 @@ static long do_poll(const struct sched_p
 /* Voluntarily yield the processor for this allocation. */
 long vcpu_yield(void)
 {
-    struct vcpu * v=current;
+    struct vcpu *curr = current;
     spinlock_t *lock;
 
     rcu_read_lock(&sched_res_rculock);
 
-    lock = unit_schedule_lock_irq(v->sched_unit);
-    sched_yield(vcpu_scheduler(v), v->sched_unit);
-    unit_schedule_unlock_irq(lock, v->sched_unit);
+    lock = unit_schedule_lock_irq(curr->sched_unit);
+    sched_yield(vcpu_scheduler(curr), curr->sched_unit);
+    unit_schedule_unlock_irq(lock, curr->sched_unit);
 
     rcu_read_unlock(&sched_res_rculock);
 
     SCHED_STAT_CRANK(vcpu_yield);
 
-    TRACE_TIME(TRC_SCHED_YIELD, current->domain->domain_id, current->vcpu_id);
+    TRACE_TIME(TRC_SCHED_YIELD, curr->domain->domain_id, curr->vcpu_id);
     raise_softirq(SCHEDULE_SOFTIRQ);
     return 0;
 }
@@ -1914,6 +1914,8 @@ typedef long ret_t;
 
 ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
+    struct vcpu *curr = current;
+    struct domain *currd = curr->domain;
     ret_t ret = 0;
 
     switch ( cmd )
@@ -1938,9 +1940,9 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
         if ( copy_from_guest(&sched_shutdown, arg, 1) )
             break;
 
-        TRACE_TIME(TRC_SCHED_SHUTDOWN, current->domain->domain_id,
-                   current->vcpu_id, sched_shutdown.reason);
-        ret = domain_shutdown(current->domain, (u8)sched_shutdown.reason);
+        TRACE_TIME(TRC_SCHED_SHUTDOWN, currd->domain_id, curr->vcpu_id,
+                   sched_shutdown.reason);
+        ret = domain_shutdown(currd, sched_shutdown.reason);
 
         break;
     }
@@ -1948,19 +1950,18 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
     case SCHEDOP_shutdown_code:
     {
         struct sched_shutdown sched_shutdown;
-        struct domain *d = current->domain;
 
         ret = -EFAULT;
         if ( copy_from_guest(&sched_shutdown, arg, 1) )
             break;
 
-        TRACE_TIME(TRC_SCHED_SHUTDOWN_CODE, d->domain_id, current->vcpu_id,
+        TRACE_TIME(TRC_SCHED_SHUTDOWN_CODE, currd->domain_id, curr->vcpu_id,
                    sched_shutdown.reason);
 
-        spin_lock(&d->shutdown_lock);
-        if ( d->shutdown_code == SHUTDOWN_CODE_INVALID )
-            d->shutdown_code = (u8)sched_shutdown.reason;
-        spin_unlock(&d->shutdown_lock);
+        spin_lock(&currd->shutdown_lock);
+        if ( currd->shutdown_code == SHUTDOWN_CODE_INVALID )
+            currd->shutdown_code = (uint8_t)sched_shutdown.reason;
+        spin_unlock(&currd->shutdown_lock);
 
         ret = 0;
         break;
@@ -1993,7 +1994,7 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
         if ( d == NULL )
             break;
 
-        ret = xsm_schedop_shutdown(XSM_DM_PRIV, current->domain, d);
+        ret = xsm_schedop_shutdown(XSM_DM_PRIV, currd, d);
         if ( likely(!ret) )
             domain_shutdown(d, sched_remote_shutdown.reason);
 
@@ -2010,8 +2011,7 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
         if ( copy_from_guest(&sched_watchdog, arg, 1) )
             break;
 
-        ret = domain_watchdog(
-            current->domain, sched_watchdog.id, sched_watchdog.timeout);
+        ret = domain_watchdog(currd, sched_watchdog.id, sched_watchdog.timeout);
         break;
     }
 
@@ -2021,7 +2021,7 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
         unsigned int cpu;
 
         ret = -EPERM;
-        if ( !is_hardware_domain(current->domain) )
+        if ( !is_hardware_domain(currd) )
             break;
 
         ret = -EFAULT;
@@ -2033,7 +2033,7 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HAN
            break;
 
         cpu = sched_pin_override.pcpu < 0 ? NR_CPUS : sched_pin_override.pcpu;
-        ret = vcpu_temporary_affinity(current, cpu, VCPU_AFFINITY_OVERRIDE);
+        ret = vcpu_temporary_affinity(curr, cpu, VCPU_AFFINITY_OVERRIDE);
 
         break;
     }
Reviewed-by on v1 3/4
#12 lore raw

Re: [PATCH v1.1 3/4] sched/core: avoid use of "current" in initializer lists

Quoted 7 lines · Jan Beulich

TRACE_TIME() uses an initializer list and hence is covered by Misra C:2012 rule 13.1 ("Initializer lists shall not contain persistent side effects"). Use intermediate variables to address this.

In vcpu_yield() take the opportunity to rename the existing variable which better would have been used already before.

Quoted 8 lines

In do_sched_op() extend the scope of and rename an existing variable. Use both variables throughout the function. Also drop a pointless (and slightly malformed, style-wise) cast there, and adjust to other one to by style conformant.

No functional change intended.

Juergen

#13 lore raw

Re: [PATCH v1.1 3/4] sched/core: avoid use of "current" in initializer lists

Quoted 13 lines · Jürgen Groß
Quoted 12 lines · Jan Beulich

TRACE_TIME() uses an initializer list and hence is covered by Misra C:2012 rule 13.1 ("Initializer lists shall not contain persistent side effects"). Use intermediate variables to address this.

In vcpu_yield() take the opportunity to rename the existing variable which better would have been used already before.

In do_sched_op() extend the scope of and rename an existing variable. Use both variables throughout the function. Also drop a pointless (and slightly malformed, style-wise) cast there, and adjust to other one to by style conformant.

Quoted 5 lines
Quoted 3 lines

No functional change intended.

Turns out I applied this to a stale v1 I had sitting around, and then committed that. I've now reverted the bad commit, putting in the intended one on top.

Jan

#14 lore raw

PATCH 4/4 automation/Eclair: tag rule 13.1 as clean

In reply to Jan Beulich

Remaining violations were addressed.

automation/eclair_analysis/ECLAIR/tagging.ecl +1 -0
@@ -66,6 +66,7 @@ MC3A2.R11.7||
 MC3A2.R11.9||
 MC3A2.R12.2||
 MC3A2.R12.5||
+MC3A2.R13.1||
 MC3A2.R13.2||
 MC3A2.R13.6||
 MC3A2.R14.1||
Reviewed-by on v1 4/4
#15 lore raw

Re: [PATCH 4/4] automation/Eclair: tag rule 13.1 as clean

Quoted 4 lines · Jan Beulich

Remaining violations were addressed.

Supposing of course all previous patches are ready to go in

Quoted 10 lines
automation/eclair_analysis/ECLAIR/tagging.ecl +1 -0
@@ -66,6 +66,7 @@ MC3A2.R11.7||
 MC3A2.R11.9||
 MC3A2.R12.2||
 MC3A2.R12.5||
+MC3A2.R13.1||
 MC3A2.R13.2||
 MC3A2.R13.6||
 MC3A2.R14.1||
Signature · 4 lines
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253