[libvirt] [PATCH 27/36] cputest: Fix comparison in checkCPUIDFeature in cpu-cpuid.py

Jiri Denemark posted 36 patches 6 years, 10 months ago
[libvirt] [PATCH 27/36] cputest: Fix comparison in checkCPUIDFeature in cpu-cpuid.py
Posted by Jiri Denemark 6 years, 10 months ago
leaf["eax"] & eax > 0 check works correctly only if there's at most 1
bit set in eax. Luckily that's been always the case, but fixing this
could save us from future surprises.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 tests/cputestdata/cpu-cpuid.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tests/cputestdata/cpu-cpuid.py b/tests/cputestdata/cpu-cpuid.py
index 866c8047cd..0a2710689d 100755
--- a/tests/cputestdata/cpu-cpuid.py
+++ b/tests/cputestdata/cpu-cpuid.py
@@ -15,12 +15,12 @@ def checkFeature(cpuid, feature):
 
     if in_eax not in cpuid or in_ecx not in cpuid[in_eax]:
         return False
-    else:
-        leaf = cpuid[in_eax][in_ecx]
-        return ((eax > 0 and leaf["eax"] & eax > 0) or
-                (ebx > 0 and leaf["ebx"] & ebx > 0) or
-                (ecx > 0 and leaf["ecx"] & ecx > 0) or
-                (edx > 0 and leaf["edx"] & edx > 0))
+
+    leaf = cpuid[in_eax][in_ecx]
+    return ((eax > 0 and leaf["eax"] & eax == eax) or
+            (ebx > 0 and leaf["ebx"] & ebx == ebx) or
+            (ecx > 0 and leaf["ecx"] & ecx == ecx) or
+            (edx > 0 and leaf["edx"] & edx == edx))
 
 
 def addFeature(cpuid, feature):
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 27/36] cputest: Fix comparison in checkCPUIDFeature in cpu-cpuid.py
Posted by Ján Tomko 6 years, 10 months ago
On Mon, Apr 08, 2019 at 10:42:31AM +0200, Jiri Denemark wrote:
>leaf["eax"] & eax > 0 check works correctly only if there's at most 1
>bit set in eax. Luckily that's been always the case, but fixing this
>could save us from future surprises.
>
>Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
>---
> tests/cputestdata/cpu-cpuid.py | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list