Skip to contentSkip to conversation

arm: Coverity 1469342 correct find_*_bit() functions use

PATCH Superseded Artem Mygaiev 2 participants 5 messages May 24, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: Coverity 1469342 correct find_*_bit() functions use

vgic_vcpu_pending_irq() uses find_next_bit() library function with single 'unsigned long' variable, while it is designed to work with memory regions. Nothing wrong is happening since 'offset' is set to 0 (other values could lead to memory corruption), but it would be more correct to use the find_first_bit() function instead.

Coverity Scan issue 1469342

xen/arch/arm/gic-vgic.c +1 -1
index d831b35525..fd63906e9b 100644
@@ -362,7 +362,7 @@ int vgic_vcpu_pending_irq(struct vcpu *v)
     ASSERT(v == current);
 
     mask_priority = gic_hw_ops->read_vmcr_priority();
-    active_priority = find_next_bit(&apr, 32, 0);
+    active_priority = find_first_bit(&apr, 32);
 
     spin_lock_irqsave(&v->arch.vgic.lock, flags);
 

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

#1 lore raw

Hi Artem,

Thank you for the report.

Quoted 1 line · Artem Mygaiev

vgic_vcpu_pending_irq() uses find_next_bit() library function with single 'unsigned long' variable, while it is designed to work with memory regions. Nothing wrong is happening since 'offset' is set to 0 (other values could lead to memory corruption), but it would be more correct to use the find_first_bit() function instead.

I don't understand the commit message. It is fine to use other offset than 0 in find_next_bit as long as it is smaller than 32. There would be no corruption happening.

Furthermore, find_first_bit(&apr, 32, 0) and find_next_bit(&apr, 32) are equivalent because the former is just a macro using the latter (see include/asm-arm/arm64/bitops.h).

So as it is the patch is not solving anything. However, I think this is just a false positive. Coverity should be able to guess that it will not go past the array (BITOP_WORD will turned into 0).

Quoted 2 lines

Coverity Scan issue 1469342

For future reference, please use the tag: "Coverity-ID: 1469342".

Quoted 8 lines
xen/arch/arm/gic-vgic.c +0 -0
index d831b35525..fd63906e9b 100644

xen/arch/arm/gic-vgic.c int vgic_vcpu_pending_irq(struct vcpu *v) · line 368

Quoted 8 lines
xen/arch/arm/gic-vgic.c +1 -1
@@ -362,7 +362,7 @@ int vgic_vcpu_pending_irq(struct vcpu *v)
      ASSERT(v == current);
 
      mask_priority = gic_hw_ops->read_vmcr_priority();
-    active_priority = find_next_bit(&apr, 32, 0);
+    active_priority = find_first_bit(&apr, 32);
 
      spin_lock_irqsave(&v->arch.vgic.lock, flags);
 

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

Hi Julien

Quoted 4 lines · Julien Grall

Hi Artem,

Thank you for the report.

Quoted 9 lines
Quoted 1 line · Artem Mygaiev

vgic_vcpu_pending_irq() uses find_next_bit() library function with single 'unsigned long' variable, while it is designed to work with memory regions. Nothing wrong is happening since 'offset' is set to 0 (other values could lead to memory corruption), but it would be more correct to use the find_first_bit() function instead.

I don't understand the commit message. It is fine to use other offset than 0 in find_next_bit as long as it is smaller than 32. There would be no corruption happening.

Furthermore, find_first_bit(&apr, 32, 0) and find_next_bit(&apr, 32) are equivalent because the former is just a macro using the latter (see include/asm-arm/arm64/bitops.h).

So as it is the patch is not solving anything. However, I think this is just a false positive. Coverity should be able to guess that it will not go past the array (BITOP_WORD will turned into 0).

Absolutely agree with you. Probably my message was not clear enough - with this particular patch I am not trying to fix a memory corruption, there is no memory corruption in the code now. It is just the use of functions: find_first_bit() is a better fit since the vgic_vcpu_pending_irq() function does not need to go over memory region and checks only one 32-bit variable. I have mentioned Coverity issue here because this was a false positive detected after today's test run.

Quoted 5 lines
Quoted 2 lines

Coverity Scan issue 1469342

For future reference, please use the tag: "Coverity-ID: 1469342".

Thanks, will do.

Quoted 10 lines
Quoted 10 lines
xen/arch/arm/gic-vgic.c +0 -0
index d831b35525..fd63906e9b 100644
@@ -362,7 +362,7 @@ int vgic_vcpu_pending_irq(struct vcpu *v)
       ASSERT(v == current);
 
Quoted 9 lines

xen/arch/arm/gic-vgic.c int vgic_vcpu_pending_irq(struct vcpu *v) · line 368

Quoted 6 lines
xen/arch/arm/gic-vgic.c +1 -1
       mask_priority = gic_hw_ops->read_vmcr_priority();
-    active_priority = find_next_bit(&apr, 32, 0);
+    active_priority = find_first_bit(&apr, 32);
 
       spin_lock_irqsave(&v->arch.vgic.lock, flags);
 

Cheers,

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

#3 lore raw
Quoted 1 line · Artem Mygaiev

Hi Julien

Hi Artem,

Quoted 9 lines · Julien Grall
Quoted 7 lines

Hi Artem,

Thank you for the report.

Quoted 1 line · Artem Mygaiev

vgic_vcpu_pending_irq() uses find_next_bit() library function with single 'unsigned long' variable, while it is designed to work with memory regions. Nothing wrong is happening since 'offset' is set to 0 (other values could lead to memory corruption), but it would be more correct to use the find_first_bit() function instead.

Quoted 7 lines
Quoted 6 lines

I don't understand the commit message. It is fine to use other offset than 0 in find_next_bit as long as it is smaller than 32. There would be no corruption happening.

Furthermore, find_first_bit(&apr, 32, 0) and find_next_bit(&apr, 32) are equivalent because the former is just a macro using the latter (see include/asm-arm/arm64/bitops.h).

So as it is the patch is not solving anything. However, I think this is just a false positive. Coverity should be able to guess that it will not go past the array (BITOP_WORD will turned into 0).

Absolutely agree with you. Probably my message was not clear enough - with this particular patch I am not trying to fix a memory corruption, there is no memory corruption in the code now. It is just the use of functions: find_first_bit() is a better fit since the vgic_vcpu_pending_irq() function does not need to go over memory region and checks only one 32-bit variable. I have mentioned Coverity issue here because this was a false positive detected after today's test run.

Feel free to resend this patch as a clean-up. I always found the use of find_next_bit confusing over find_first_bit.

However, I don't think coverity should be mention in the commit message or title. This is making thing very confusing as, IHMO, this is a false positive. We tend to only mention coverity when this is either going to silent coverity or fix the defect.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

Hi,

Quoted 20 lines · Julien Grall
Quoted 1 line · Artem Mygaiev

Hi Julien

Hi Artem,

Quoted 13 lines · Julien Grall
Quoted 11 lines

Hi Artem,

Thank you for the report.

Quoted 1 line · Artem Mygaiev

vgic_vcpu_pending_irq() uses find_next_bit() library function with single 'unsigned long' variable, while it is designed to work with memory regions. Nothing wrong is happening since 'offset' is set to 0 (other values could lead to memory corruption), but it would be more correct to use the find_first_bit() function instead.

I don't understand the commit message. It is fine to use other offset than 0 in find_next_bit as long as it is smaller than 32. There would be no corruption happening.

Furthermore, find_first_bit(&apr, 32, 0) and find_next_bit(&apr, 32) are equivalent because the former is just a macro using the latter (see include/asm-arm/arm64/bitops.h).

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

So as it is the patch is not solving anything. However, I think this is just a false positive. Coverity should be able to guess that it will not go past the array (BITOP_WORD will turned into 0).

Absolutely agree with you. Probably my message was not clear enough - with this particular patch I am not trying to fix a memory corruption, there is no memory corruption in the code now. It is just the use of functions: find_first_bit() is a better fit since the vgic_vcpu_pending_irq() function does not need to go over memory region and checks only one 32-bit variable. I have mentioned Coverity issue here because this was a false positive detected after today's test run.

Feel free to resend this patch as a clean-up. I always found the use of find_next_bit confusing over find_first_bit.

However, I don't think coverity should be mention in the commit message or title. This is making thing very confusing as, IHMO, this is a false positive. We tend to only mention coverity when this is either going to silent coverity or fix the defect.

Ok, I'll adjust the subject & commit message, and re-send. JFYI, I've marked this one as False Positive in Coverity; there were three more suspects produced in today's run, but nothing really worth attention.

Quoted 2 lines

Cheers,

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