[PATCH] tests/qtest/test-x86-cpuid-compat: Check for machines before using them

Thomas Huth posted 1 patch 2 years, 4 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20211222153923.1000420-1-thuth@redhat.com
Maintainers: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Thomas Huth <thuth@redhat.com>
tests/qtest/test-x86-cpuid-compat.c | 85 ++++++++++++++++-------------
1 file changed, 48 insertions(+), 37 deletions(-)
[PATCH] tests/qtest/test-x86-cpuid-compat: Check for machines before using them
Posted by Thomas Huth 2 years, 4 months ago
The user might have disabled the pc-i440fx machine type (or it's older
versions, like done in downstream RHEL) in the QEMU binary, so let's
better check whether the machine types are available before using them.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/test-x86-cpuid-compat.c | 85 ++++++++++++++++-------------
 1 file changed, 48 insertions(+), 37 deletions(-)

diff --git a/tests/qtest/test-x86-cpuid-compat.c b/tests/qtest/test-x86-cpuid-compat.c
index f28848e06e..39138db774 100644
--- a/tests/qtest/test-x86-cpuid-compat.c
+++ b/tests/qtest/test-x86-cpuid-compat.c
@@ -302,54 +302,65 @@ int main(int argc, char **argv)
 
     /* Check compatibility of old machine-types that didn't
      * auto-increase level/xlevel/xlevel2: */
-
-    add_cpuid_test("x86/cpuid/auto-level/pc-2.7",
-                   "-machine pc-i440fx-2.7 -cpu 486,arat=on,avx512vbmi=on,xsaveopt=on",
-                   "level", 1);
-    add_cpuid_test("x86/cpuid/auto-xlevel/pc-2.7",
-                   "-machine pc-i440fx-2.7 -cpu 486,3dnow=on,sse4a=on,invtsc=on,npt=on,svm=on",
-                   "xlevel", 0);
-    add_cpuid_test("x86/cpuid/auto-xlevel2/pc-2.7",
-                   "-machine pc-i440fx-2.7 -cpu 486,xstore=on",
-                   "xlevel2", 0);
+    if (qtest_has_machine("pc-i440fx-2.7")) {
+        add_cpuid_test("x86/cpuid/auto-level/pc-2.7",
+                       "-machine pc-i440fx-2.7 -cpu 486,arat=on,avx512vbmi=on,xsaveopt=on",
+                       "level", 1);
+        add_cpuid_test("x86/cpuid/auto-xlevel/pc-2.7",
+                       "-machine pc-i440fx-2.7 -cpu 486,3dnow=on,sse4a=on,invtsc=on,npt=on,svm=on",
+                       "xlevel", 0);
+        add_cpuid_test("x86/cpuid/auto-xlevel2/pc-2.7",
+                       "-machine pc-i440fx-2.7 -cpu 486,xstore=on",
+                       "xlevel2", 0);
+    }
     /*
      * QEMU 1.4.0 had auto-level enabled for CPUID[7], already,
      * and the compat code that sets default level shouldn't
      * disable the auto-level=7 code:
      */
-    add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-1.4/off",
-                   "-machine pc-i440fx-1.4 -cpu Nehalem",
-                   "level", 2);
-    add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-1.5/on",
-                   "-machine pc-i440fx-1.4 -cpu Nehalem,smap=on",
-                   "level", 7);
-    add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.3/off",
-                   "-machine pc-i440fx-2.3 -cpu Penryn",
-                   "level", 4);
-    add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.3/on",
-                   "-machine pc-i440fx-2.3 -cpu Penryn,erms=on",
-                   "level", 7);
-    add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/off",
-                   "-machine pc-i440fx-2.9 -cpu Conroe",
-                   "level", 10);
-    add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/on",
-                   "-machine pc-i440fx-2.9 -cpu Conroe,erms=on",
-                   "level", 10);
+    if (qtest_has_machine("pc-i440fx-1.4")) {
+        add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-1.4/off",
+                       "-machine pc-i440fx-1.4 -cpu Nehalem",
+                       "level", 2);
+        add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-1.5/on",
+                       "-machine pc-i440fx-1.4 -cpu Nehalem,smap=on",
+                       "level", 7);
+    }
+    if (qtest_has_machine("pc-i440fx-2.3")) {
+        add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.3/off",
+                       "-machine pc-i440fx-2.3 -cpu Penryn",
+                       "level", 4);
+        add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.3/on",
+                       "-machine pc-i440fx-2.3 -cpu Penryn,erms=on",
+                       "level", 7);
+    }
+    if (qtest_has_machine("pc-i440fx-2.9")) {
+        add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/off",
+                       "-machine pc-i440fx-2.9 -cpu Conroe",
+                       "level", 10);
+        add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/on",
+                       "-machine pc-i440fx-2.9 -cpu Conroe,erms=on",
+                       "level", 10);
+    }
 
     /*
      * xlevel doesn't have any feature that triggers auto-level
      * code on old machine-types.  Just check that the compat code
      * is working correctly:
      */
-    add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.3",
-                   "-machine pc-i440fx-2.3 -cpu SandyBridge",
-                   "xlevel", 0x8000000a);
-    add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-off",
-                   "-machine pc-i440fx-2.4 -cpu SandyBridge,",
-                   "xlevel", 0x80000008);
-    add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-on",
-                   "-machine pc-i440fx-2.4 -cpu SandyBridge,svm=on,npt=on",
-                   "xlevel", 0x80000008);
+    if (qtest_has_machine("pc-i440fx-2.3")) {
+        add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.3",
+                       "-machine pc-i440fx-2.3 -cpu SandyBridge",
+                       "xlevel", 0x8000000a);
+    }
+    if (qtest_has_machine("pc-i440fx-2.4")) {
+        add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-off",
+                       "-machine pc-i440fx-2.4 -cpu SandyBridge,",
+                       "xlevel", 0x80000008);
+        add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-on",
+                       "-machine pc-i440fx-2.4 -cpu SandyBridge,svm=on,npt=on",
+                       "xlevel", 0x80000008);
+    }
 
     /* Test feature parsing */
     add_feature_test("x86/cpuid/features/plus",
-- 
2.27.0


Re: [PATCH] tests/qtest/test-x86-cpuid-compat: Check for machines before using them
Posted by Igor Mammedov 2 years, 4 months ago
On Wed, 22 Dec 2021 16:39:23 +0100
Thomas Huth <thuth@redhat.com> wrote:

> The user might have disabled the pc-i440fx machine type (or it's older
> versions, like done in downstream RHEL) in the QEMU binary, so let's
> better check whether the machine types are available before using them.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
Looks good to me, so

Reviewed-by: Igor Mammedov <imammedo@redhat.com>


the only concern is that when deprecated machine is removed,
this code will happily hide test block which should be removed.

> ---
>  tests/qtest/test-x86-cpuid-compat.c | 85 ++++++++++++++++-------------
>  1 file changed, 48 insertions(+), 37 deletions(-)
> 
> diff --git a/tests/qtest/test-x86-cpuid-compat.c b/tests/qtest/test-x86-cpuid-compat.c
> index f28848e06e..39138db774 100644
> --- a/tests/qtest/test-x86-cpuid-compat.c
> +++ b/tests/qtest/test-x86-cpuid-compat.c
> @@ -302,54 +302,65 @@ int main(int argc, char **argv)
>  
>      /* Check compatibility of old machine-types that didn't
>       * auto-increase level/xlevel/xlevel2: */
> -
> -    add_cpuid_test("x86/cpuid/auto-level/pc-2.7",
> -                   "-machine pc-i440fx-2.7 -cpu 486,arat=on,avx512vbmi=on,xsaveopt=on",
> -                   "level", 1);
> -    add_cpuid_test("x86/cpuid/auto-xlevel/pc-2.7",
> -                   "-machine pc-i440fx-2.7 -cpu 486,3dnow=on,sse4a=on,invtsc=on,npt=on,svm=on",
> -                   "xlevel", 0);
> -    add_cpuid_test("x86/cpuid/auto-xlevel2/pc-2.7",
> -                   "-machine pc-i440fx-2.7 -cpu 486,xstore=on",
> -                   "xlevel2", 0);
> +    if (qtest_has_machine("pc-i440fx-2.7")) {
> +        add_cpuid_test("x86/cpuid/auto-level/pc-2.7",
> +                       "-machine pc-i440fx-2.7 -cpu 486,arat=on,avx512vbmi=on,xsaveopt=on",
> +                       "level", 1);
> +        add_cpuid_test("x86/cpuid/auto-xlevel/pc-2.7",
> +                       "-machine pc-i440fx-2.7 -cpu 486,3dnow=on,sse4a=on,invtsc=on,npt=on,svm=on",
> +                       "xlevel", 0);
> +        add_cpuid_test("x86/cpuid/auto-xlevel2/pc-2.7",
> +                       "-machine pc-i440fx-2.7 -cpu 486,xstore=on",
> +                       "xlevel2", 0);
> +    }
>      /*
>       * QEMU 1.4.0 had auto-level enabled for CPUID[7], already,
>       * and the compat code that sets default level shouldn't
>       * disable the auto-level=7 code:
>       */
> -    add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-1.4/off",
> -                   "-machine pc-i440fx-1.4 -cpu Nehalem",
> -                   "level", 2);
> -    add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-1.5/on",
> -                   "-machine pc-i440fx-1.4 -cpu Nehalem,smap=on",
> -                   "level", 7);
> -    add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.3/off",
> -                   "-machine pc-i440fx-2.3 -cpu Penryn",
> -                   "level", 4);
> -    add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.3/on",
> -                   "-machine pc-i440fx-2.3 -cpu Penryn,erms=on",
> -                   "level", 7);
> -    add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/off",
> -                   "-machine pc-i440fx-2.9 -cpu Conroe",
> -                   "level", 10);
> -    add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/on",
> -                   "-machine pc-i440fx-2.9 -cpu Conroe,erms=on",
> -                   "level", 10);
> +    if (qtest_has_machine("pc-i440fx-1.4")) {
> +        add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-1.4/off",
> +                       "-machine pc-i440fx-1.4 -cpu Nehalem",
> +                       "level", 2);
> +        add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-1.5/on",
> +                       "-machine pc-i440fx-1.4 -cpu Nehalem,smap=on",
> +                       "level", 7);
> +    }
> +    if (qtest_has_machine("pc-i440fx-2.3")) {
> +        add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.3/off",
> +                       "-machine pc-i440fx-2.3 -cpu Penryn",
> +                       "level", 4);
> +        add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.3/on",
> +                       "-machine pc-i440fx-2.3 -cpu Penryn,erms=on",
> +                       "level", 7);
> +    }
> +    if (qtest_has_machine("pc-i440fx-2.9")) {
> +        add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/off",
> +                       "-machine pc-i440fx-2.9 -cpu Conroe",
> +                       "level", 10);
> +        add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/on",
> +                       "-machine pc-i440fx-2.9 -cpu Conroe,erms=on",
> +                       "level", 10);
> +    }
>  
>      /*
>       * xlevel doesn't have any feature that triggers auto-level
>       * code on old machine-types.  Just check that the compat code
>       * is working correctly:
>       */
> -    add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.3",
> -                   "-machine pc-i440fx-2.3 -cpu SandyBridge",
> -                   "xlevel", 0x8000000a);
> -    add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-off",
> -                   "-machine pc-i440fx-2.4 -cpu SandyBridge,",
> -                   "xlevel", 0x80000008);
> -    add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-on",
> -                   "-machine pc-i440fx-2.4 -cpu SandyBridge,svm=on,npt=on",
> -                   "xlevel", 0x80000008);
> +    if (qtest_has_machine("pc-i440fx-2.3")) {
> +        add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.3",
> +                       "-machine pc-i440fx-2.3 -cpu SandyBridge",
> +                       "xlevel", 0x8000000a);
> +    }
> +    if (qtest_has_machine("pc-i440fx-2.4")) {
> +        add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-off",
> +                       "-machine pc-i440fx-2.4 -cpu SandyBridge,",
> +                       "xlevel", 0x80000008);
> +        add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-on",
> +                       "-machine pc-i440fx-2.4 -cpu SandyBridge,svm=on,npt=on",
> +                       "xlevel", 0x80000008);
> +    }
>  
>      /* Test feature parsing */
>      add_feature_test("x86/cpuid/features/plus",


Re: [PATCH] tests/qtest/test-x86-cpuid-compat: Check for machines before using them
Posted by Thomas Huth 2 years, 4 months ago
On 27/12/2021 11.01, Igor Mammedov wrote:
> On Wed, 22 Dec 2021 16:39:23 +0100
> Thomas Huth <thuth@redhat.com> wrote:
> 
>> The user might have disabled the pc-i440fx machine type (or it's older
>> versions, like done in downstream RHEL) in the QEMU binary, so let's
>> better check whether the machine types are available before using them.
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
> Looks good to me, so
> 
> Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> 
> 
> the only concern is that when deprecated machine is removed,
> this code will happily hide test block which should be removed.

Yes, but ideally, the person who removes depreacted machines should "grep" 
throught the sources for the machines that should be removed anyway 
(otherwise you might miss the spots where they are mentioned in comments 
anyway, like in hw/i386/acpi-build.c for example).

By the way, currently there are no x86 machines marked as deprecated ... 
should we maybe mark the pc-i440fx-1.x machines as deprecated now, since 
they are very old already?

  Thomas