[PATCH v5 47/69] target/arm: Use generic hwaccel_enabled() to check 'host' cpu type

Philippe Mathieu-Daudé posted 69 patches 5 months, 2 weeks ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>, Phil Dennis-Jordan <phil@philjordan.eu>, Mads Ynddal <mads@ynddal.dk>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Anthony PERARD <anthony@xenproject.org>, Paul Durrant <paul@xen.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Dr. David Alan Gilbert" <dave@treblig.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Reinoud Zandijk <reinoud@netbsd.org>, Sunil Muthuswamy <sunilmut@microsoft.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Alexander Graf <agraf@csgraf.de>
There is a newer version of this series
[PATCH v5 47/69] target/arm: Use generic hwaccel_enabled() to check 'host' cpu type
Posted by Philippe Mathieu-Daudé 5 months, 2 weeks ago
We should be able to use the 'host' CPU with any hardware accelerator.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/arm-qmp-cmds.c | 5 +++--
 target/arm/cpu.c          | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/target/arm/arm-qmp-cmds.c b/target/arm/arm-qmp-cmds.c
index cefd2352638..ee5eb1bac9f 100644
--- a/target/arm/arm-qmp-cmds.c
+++ b/target/arm/arm-qmp-cmds.c
@@ -30,6 +30,7 @@
 #include "qapi/qapi-commands-misc-arm.h"
 #include "qobject/qdict.h"
 #include "qom/qom-qobject.h"
+#include "system/hw_accel.h"
 #include "cpu.h"
 
 static GICCapability *gic_cap_new(int version)
@@ -116,8 +117,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
         return NULL;
     }
 
-    if (!kvm_enabled() && !strcmp(model->name, "host")) {
-        error_setg(errp, "The CPU type '%s' requires KVM", model->name);
+    if (!hwaccel_enabled() && !strcmp(model->name, "host")) {
+        error_setg(errp, "The CPU type 'host' requires hardware accelerator");
         return NULL;
     }
 
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index ebac86f70d3..e37376dbd2d 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1978,8 +1978,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
      * this is the first point where we can report it.
      */
     if (cpu->host_cpu_probe_failed) {
-        if (!kvm_enabled() && !hvf_enabled()) {
-            error_setg(errp, "The 'host' CPU type can only be used with KVM or HVF");
+        if (!hwaccel_enabled()) {
+            error_setg(errp, "The 'host' CPU type can only be used with "
+                             "hardware accelator such KVM/HVF");
         } else {
             error_setg(errp, "Failed to retrieve host CPU features");
         }
-- 
2.49.0


Re: [PATCH v5 47/69] target/arm: Use generic hwaccel_enabled() to check 'host' cpu type
Posted by Philippe Mathieu-Daudé 5 months, 2 weeks ago
On 3/7/25 12:55, Philippe Mathieu-Daudé wrote:
> We should be able to use the 'host' CPU with any hardware accelerator.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   target/arm/arm-qmp-cmds.c | 5 +++--
>   target/arm/cpu.c          | 5 +++--
>   2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/target/arm/arm-qmp-cmds.c b/target/arm/arm-qmp-cmds.c
> index cefd2352638..ee5eb1bac9f 100644
> --- a/target/arm/arm-qmp-cmds.c
> +++ b/target/arm/arm-qmp-cmds.c
> @@ -30,6 +30,7 @@
>   #include "qapi/qapi-commands-misc-arm.h"
>   #include "qobject/qdict.h"
>   #include "qom/qom-qobject.h"
> +#include "system/hw_accel.h"
>   #include "cpu.h"
>   
>   static GICCapability *gic_cap_new(int version)
> @@ -116,8 +117,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
>           return NULL;
>       }
>   
> -    if (!kvm_enabled() && !strcmp(model->name, "host")) {
> -        error_setg(errp, "The CPU type '%s' requires KVM", model->name);
> +    if (!hwaccel_enabled() && !strcmp(model->name, "host")) {
> +        error_setg(errp, "The CPU type 'host' requires hardware accelerator");
>           return NULL;
>       }

Consider the following hunk squashed:

-- >8 --
diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c
index eb8ddebffbf..bdd37cafecd 100644
--- a/tests/qtest/arm-cpu-features.c
+++ b/tests/qtest/arm-cpu-features.c
@@ -456,7 +456,8 @@ static void test_query_cpu_model_expansion(const 
void *data)
                   "ARM CPU type", NULL);
      assert_error(qts, "max", "Parameter 'model.props.not-a-prop' is 
unexpected",
                   "{ 'not-a-prop': false }");
-    assert_error(qts, "host", "The CPU type 'host' requires KVM", NULL);
+    assert_error(qts, "host",
+                 "The CPU type 'host' requires hardware accelerator", 
NULL);

      /* Test expected feature presence/absence for some cpu types */
      assert_has_feature_enabled(qts, "cortex-a15", "pmu");
---

Re: [PATCH v5 47/69] target/arm: Use generic hwaccel_enabled() to check 'host' cpu type
Posted by Peter Maydell 5 months, 2 weeks ago
On Thu, 3 Jul 2025 at 14:45, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> On 3/7/25 12:55, Philippe Mathieu-Daudé wrote:
> > We should be able to use the 'host' CPU with any hardware accelerator.
> >
> > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> > Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> > ---
> >   target/arm/arm-qmp-cmds.c | 5 +++--
> >   target/arm/cpu.c          | 5 +++--
> >   2 files changed, 6 insertions(+), 4 deletions(-)
> >
> > diff --git a/target/arm/arm-qmp-cmds.c b/target/arm/arm-qmp-cmds.c
> > index cefd2352638..ee5eb1bac9f 100644
> > --- a/target/arm/arm-qmp-cmds.c
> > +++ b/target/arm/arm-qmp-cmds.c
> > @@ -30,6 +30,7 @@
> >   #include "qapi/qapi-commands-misc-arm.h"
> >   #include "qobject/qdict.h"
> >   #include "qom/qom-qobject.h"
> > +#include "system/hw_accel.h"
> >   #include "cpu.h"
> >
> >   static GICCapability *gic_cap_new(int version)
> > @@ -116,8 +117,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
> >           return NULL;
> >       }
> >
> > -    if (!kvm_enabled() && !strcmp(model->name, "host")) {
> > -        error_setg(errp, "The CPU type '%s' requires KVM", model->name);
> > +    if (!hwaccel_enabled() && !strcmp(model->name, "host")) {
> > +        error_setg(errp, "The CPU type 'host' requires hardware accelerator");
> >           return NULL;
> >       }
>
> Consider the following hunk squashed:
>
> -- >8 --
> diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c
> index eb8ddebffbf..bdd37cafecd 100644
> --- a/tests/qtest/arm-cpu-features.c
> +++ b/tests/qtest/arm-cpu-features.c
> @@ -456,7 +456,8 @@ static void test_query_cpu_model_expansion(const
> void *data)
>                    "ARM CPU type", NULL);
>       assert_error(qts, "max", "Parameter 'model.props.not-a-prop' is
> unexpected",
>                    "{ 'not-a-prop': false }");
> -    assert_error(qts, "host", "The CPU type 'host' requires KVM", NULL);
> +    assert_error(qts, "host",
> +                 "The CPU type 'host' requires hardware accelerator",
> NULL);

Grammar nit: either "a hardware accelerator" or "hardware acceleration".

-- PMM
Re: [PATCH v5 47/69] target/arm: Use generic hwaccel_enabled() to check 'host' cpu type
Posted by Philippe Mathieu-Daudé 5 months, 2 weeks ago
On 3/7/25 15:46, Peter Maydell wrote:
> On Thu, 3 Jul 2025 at 14:45, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>>
>> On 3/7/25 12:55, Philippe Mathieu-Daudé wrote:
>>> We should be able to use the 'host' CPU with any hardware accelerator.
>>>
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>>> ---
>>>    target/arm/arm-qmp-cmds.c | 5 +++--
>>>    target/arm/cpu.c          | 5 +++--
>>>    2 files changed, 6 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/target/arm/arm-qmp-cmds.c b/target/arm/arm-qmp-cmds.c
>>> index cefd2352638..ee5eb1bac9f 100644
>>> --- a/target/arm/arm-qmp-cmds.c
>>> +++ b/target/arm/arm-qmp-cmds.c
>>> @@ -30,6 +30,7 @@
>>>    #include "qapi/qapi-commands-misc-arm.h"
>>>    #include "qobject/qdict.h"
>>>    #include "qom/qom-qobject.h"
>>> +#include "system/hw_accel.h"
>>>    #include "cpu.h"
>>>
>>>    static GICCapability *gic_cap_new(int version)
>>> @@ -116,8 +117,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
>>>            return NULL;
>>>        }
>>>
>>> -    if (!kvm_enabled() && !strcmp(model->name, "host")) {
>>> -        error_setg(errp, "The CPU type '%s' requires KVM", model->name);
>>> +    if (!hwaccel_enabled() && !strcmp(model->name, "host")) {
>>> +        error_setg(errp, "The CPU type 'host' requires hardware accelerator");
>>>            return NULL;
>>>        }
>>
>> Consider the following hunk squashed:
>>
>> -- >8 --
>> diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c
>> index eb8ddebffbf..bdd37cafecd 100644
>> --- a/tests/qtest/arm-cpu-features.c
>> +++ b/tests/qtest/arm-cpu-features.c
>> @@ -456,7 +456,8 @@ static void test_query_cpu_model_expansion(const
>> void *data)
>>                     "ARM CPU type", NULL);
>>        assert_error(qts, "max", "Parameter 'model.props.not-a-prop' is
>> unexpected",
>>                     "{ 'not-a-prop': false }");
>> -    assert_error(qts, "host", "The CPU type 'host' requires KVM", NULL);
>> +    assert_error(qts, "host",
>> +                 "The CPU type 'host' requires hardware accelerator",
>> NULL);
> 
> Grammar nit: either "a hardware accelerator" or "hardware acceleration".

Fixed, thanks :)