Skip to contentSkip to conversation

xen: credit: change an ASSERT on nr_runnable so that it makes sense.

PATCH In review Dario Faggioli 5 participants 6 messages Apr 13, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: credit: change an ASSERT on nr_runnable so that it makes sense.

Since the counter is unsigned, it's pointless/bogous to check for if to be above zero.

Check that it is at least one before it's decremented, instead.

Spotted by Coverity.

---
Cc: George Dunlap <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Julien Grall <[email protected]>
---
Julien,

This is very low risk, and I'd call it a bugfix in the sense that it quiesces coverity.

Dario

---
 xen/common/sched_credit.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched_credit.c +1 -1
index 93658dc..efdf6bf 100644
@@ -275,8 +275,8 @@ static inline void
 dec_nr_runnable(unsigned int cpu)
 {
     ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock));
+    ASSERT(CSCHED_PCPU(cpu)->nr_runnable >= 1);
     CSCHED_PCPU(cpu)->nr_runnable--;
-    ASSERT(CSCHED_PCPU(cpu)->nr_runnable >= 0);
 }
 
 static inline void

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw

Hi Dario,

Quoted 6 lines · Dario Faggioli

Since the counter is unsigned, it's pointless/bogous to check for if to be above zero.

Check that it is at least one before it's decremented, instead.

Spotted by Coverity.

Do you have the Coverity-ID? :)

Quoted 10 lines

---
Cc: George Dunlap <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Julien Grall <[email protected]>
---
Julien,

Quoted 2 lines

This is very low risk, and I'd call it a bugfix in the sense that it quiesces coverity.

Quoted 12 lines

Dario

---
 xen/common/sched_credit.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched_credit.c +0 -0
index 93658dc..efdf6bf 100644

xen/common/sched_credit.c static inline void · line 282

Quoted 9 lines
xen/common/sched_credit.c +1 -1
@@ -275,8 +275,8 @@ static inline void
 dec_nr_runnable(unsigned int cpu)
 {
     ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock));
+    ASSERT(CSCHED_PCPU(cpu)->nr_runnable >= 1);
     CSCHED_PCPU(cpu)->nr_runnable--;
-    ASSERT(CSCHED_PCPU(cpu)->nr_runnable >= 0);
 }
 
 static inline void

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw
Quoted 12 lines · Julien Grall

Hi Dario,

Quoted 6 lines · Dario Faggioli

Since the counter is unsigned, it's pointless/bogous to check for if to be above zero.

Check that it is at least one before it's decremented, instead.

Spotted by Coverity.

Do you have the Coverity-ID? :)

Not really. It is XenServer's internal instance.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
In reply to Julien Grall
Quoted 12 lines · Julien Grall

Hi Dario,

Quoted 6 lines · Dario Faggioli

Since the counter is unsigned, it's pointless/bogous to check for if to be above zero.

Check that it is at least one before it's decremented, instead.

Spotted by Coverity.

Do you have the Coverity-ID? :)

This comes from the Citrix internal instance, so the ID wouldn't make any sense.

I don't know if the XenProject instance has also caught it. I guess it's likely, but I don't have access, so I can't check.

Adding the above line is what Andrew suggested doing (saying he does it
himself) when things like this happens, to better reflect the reality.

Let me know if I should do anything different (of feel free to add or change anything related to this upon commit).

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
Quoted 9 lines · Dario Faggioli
Quoted 8 lines · Julien Grall

Hi Dario,

Quoted 5 lines · Dario Faggioli

Since the counter is unsigned, it's pointless/bogous to check for if to be above zero.

Check that it is at least one before it's decremented, instead.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Spotted by Coverity.

Do you have the Coverity-ID? :)

This comes from the Citrix internal instance, so the ID wouldn't make any sense.

I don't know if the XenProject instance has also caught it. I guess it's likely, but I don't have access, so I can't check.

OSSTest is currently failing at the Coverity jobs, probably because of firewall issues uploading the analysis results.

I expect it would have noticed, had an upload succeeded recently.

On the subject of access, we really should open it up now. The fact that anyone can clone Xen and run Coverity themselves means there is no point in keeping the main one private.

Quoted 3 lines

Adding the above line is what Andrew suggested doing (saying he does it
himself) when things like this happens, to better reflect the reality.

It is the least bad way I've found of expressing the difference.

Quoted 6 lines

Let me know if I should do anything different (of feel free to add or change anything related to this upon commit).

Regards,
Dario

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#5 lore raw
In reply to Dario Faggioli
Quoted 9 lines · Dario Faggioli

Since the counter is unsigned, it's pointless/bogous to check for if to be above zero.

Check that it is at least one before it's decremented, instead.

Spotted by Coverity.

And queued

Quoted 21 lines

---
Cc: George Dunlap <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Julien Grall <[email protected]>
---
Julien,

This is very low risk, and I'd call it a bugfix in the sense that it quiesces coverity.

Dario

---
 xen/common/sched_credit.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched_credit.c +0 -0
index 93658dc..efdf6bf 100644

xen/common/sched_credit.c static inline void · line 282

Quoted 9 lines
xen/common/sched_credit.c +1 -1
@@ -275,8 +275,8 @@ static inline void
 dec_nr_runnable(unsigned int cpu)
 {
     ASSERT(spin_is_locked(per_cpu(schedule_data, cpu).schedule_lock));
+    ASSERT(CSCHED_PCPU(cpu)->nr_runnable >= 1);
     CSCHED_PCPU(cpu)->nr_runnable--;
-    ASSERT(CSCHED_PCPU(cpu)->nr_runnable >= 0);
 }
 
 static inline void

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel