* [PATCH v3] target/i386: make error message for -cpu host more informative
@ 2026-12-02 4:58 Andrew Nguyen
2026-12-02 8:57 ` Daniel P. Berrangé
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Nguyen @ 2026-12-02 4:58 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Zhao Liu, Peter Maydell,
Philippe Mathieu-Daudé, Andrew Nguyen
"-cpu host" by itself is not permitted; an accelerator must be
provided as well. Not only did the original code for this not even
check if an accelerator was not being used, but it also did not list
the accelerators for some host OSs, notably WHPX for Windows.
This change adds a check for a hardware accelerator and adds WHPX and
NVMM to the list in the error message when no accelerator is provided.
This change also moves the list to be returned by a function in an
easier-to-find spot to make appending more hardware accelerators in
the future easier.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4836
Signed-off-by: Andrew Nguyen <xmphyr@gmail.com>
---
This is a resolution for issue #4836:
https://gitlab.com/qemu-project/qemu/-/work_items/4836. "-cpu host" by
itself is not permitted; an accelerator must be specified as well. For
Linux, it is KVM. macOS is HVF and Windows is WHPX.
Previously, QEMU would only tell the user to use either KVM or HVF, essentially excluding
Windows users.
---
I originally was going to make hwaccel_names() a macro, but that felt
wrong. I did also consider making hwaccel_names() a bullet list with the
cooresponding OS in parentheses, but
return "- kvm (Linux)\n"
"- hvf (Mac)\n"
...looks pretty ugly. And the reason why I stuck with listing the
accelerators by name is because it provides clarity. After all, the
reporter of the issue was struggling with WHPX not being mentioned by
name.
I am considering putting the hwaccel_enabled() call in
accel_uses_host_cpuid(), but I'm not totally sure what that function is for
at the higher level. My assumption is whether or not QEMU is able to get
the CPU's capabilities.
---
Changes in v3:
- Coalesced commits and improved commit message
- Link to v2: https://lore.kernel.org/qemu-devel/20261118-4836-cpu-host-error-v2-0-ba02bb640d9d@gmail.com
Changes in v2:
- cpu.c: added a check for hardware acceleration
- cpu.c: replaced the explicit list of hardware accelerators
- hw_accel.h: created function hwaccel_names() to return the list of hw accerlator names
- Link to v1: https://lore.kernel.org/qemu-devel/20261115-4836-cpu-host-error-v1-1-fdf0eb56ba8a@gmail.com
Changes in v1:
- cpu.c:10229: added WHPX to the error message when "-cpu host" doesn't include an accelerator
---
include/system/hw_accel.h | 10 ++++++++++
target/i386/cpu.c | 7 +++++--
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/include/system/hw_accel.h b/include/system/hw_accel.h
index f0c10b6d80..04608073f7 100644
--- a/include/system/hw_accel.h
+++ b/include/system/hw_accel.h
@@ -54,4 +54,14 @@ static inline bool hwaccel_enabled(void)
|| whpx_enabled();
}
+/**
+ * hwaccel_names:
+ *
+ * Returns: String of supported hardware accelerators.
+ */
+static inline const char *hwaccel_names(void)
+{
+ return "kvm, hvf, whpx, or nvmm";
+}
+
#endif /* QEMU_HW_ACCEL_H */
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 40974bee26..6808559fdd 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -25,6 +25,7 @@
#include "cpu.h"
#include "tcg/helper-tcg.h"
#include "exec/translation-block.h"
+#include "system/hw_accel.h"
#include "system/hvf.h"
#include "system/mshv.h"
#include "system/whpx.h"
@@ -10226,9 +10227,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
return;
}
- if (xcc->host_cpuid_required && !accel_uses_host_cpuid()) {
+ if (xcc->host_cpuid_required && (!accel_uses_host_cpuid() ||
+ !hwaccel_enabled())) {
g_autofree char *name = x86_cpu_class_get_model_name(xcc);
- error_setg(&local_err, "CPU model '%s' requires KVM or HVF", name);
+ error_setg(&local_err, "The '%s' CPU type can only be used with "
+ "hardware accelerators %s", name, hwaccel_names());
goto out;
}
---
base-commit: 3c061218fcf37a98c944ecb88cff56f94f5c0a43
change-id: 20261115-4836-cpu-host-error-1e85b17e0f1d
Best regards,
--
Andrew Nguyen <xmphyr@gmail.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v3] target/i386: make error message for -cpu host more informative
2026-12-02 4:58 [PATCH v3] target/i386: make error message for -cpu host more informative Andrew Nguyen
@ 2026-12-02 8:57 ` Daniel P. Berrangé
0 siblings, 0 replies; 2+ messages in thread
From: Daniel P. Berrangé @ 2026-12-02 8:57 UTC (permalink / raw)
To: Andrew Nguyen
Cc: qemu-devel, Paolo Bonzini, Zhao Liu, Peter Maydell,
Philippe Mathieu-Daudé
On Tue, Dec 01, 2026 at 10:58:34PM -0600, Andrew Nguyen wrote:
> "-cpu host" by itself is not permitted; an accelerator must be
> provided as well. Not only did the original code for this not even
> check if an accelerator was not being used, but it also did not list
> the accelerators for some host OSs, notably WHPX for Windows.
>
> This change adds a check for a hardware accelerator and adds WHPX and
> NVMM to the list in the error message when no accelerator is provided.
> This change also moves the list to be returned by a function in an
> easier-to-find spot to make appending more hardware accelerators in
> the future easier.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4836
>
> Signed-off-by: Andrew Nguyen <xmphyr@gmail.com>
> ---
> This is a resolution for issue #4836:
> https://gitlab.com/qemu-project/qemu/-/work_items/4836. "-cpu host" by
> itself is not permitted; an accelerator must be specified as well. For
> Linux, it is KVM. macOS is HVF and Windows is WHPX.
>
> Previously, QEMU would only tell the user to use either KVM or HVF, essentially excluding
> Windows users.
> ---
> I originally was going to make hwaccel_names() a macro, but that felt
> wrong. I did also consider making hwaccel_names() a bullet list with the
> cooresponding OS in parentheses, but
>
> return "- kvm (Linux)\n"
> "- hvf (Mac)\n"
>
> ...looks pretty ugly. And the reason why I stuck with listing the
> accelerators by name is because it provides clarity. After all, the
> reporter of the issue was struggling with WHPX not being mentioned by
> name.
>
> I am considering putting the hwaccel_enabled() call in
> accel_uses_host_cpuid(), but I'm not totally sure what that function is for
> at the higher level. My assumption is whether or not QEMU is able to get
> the CPU's capabilities.
> ---
> Changes in v3:
> - Coalesced commits and improved commit message
> - Link to v2: https://lore.kernel.org/qemu-devel/20261118-4836-cpu-host-error-v2-0-ba02bb640d9d@gmail.com
>
> Changes in v2:
> - cpu.c: added a check for hardware acceleration
> - cpu.c: replaced the explicit list of hardware accelerators
> - hw_accel.h: created function hwaccel_names() to return the list of hw accerlator names
> - Link to v1: https://lore.kernel.org/qemu-devel/20261115-4836-cpu-host-error-v1-1-fdf0eb56ba8a@gmail.com
>
> Changes in v1:
> - cpu.c:10229: added WHPX to the error message when "-cpu host" doesn't include an accelerator
> ---
> include/system/hw_accel.h | 10 ++++++++++
> target/i386/cpu.c | 7 +++++--
> 2 files changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/include/system/hw_accel.h b/include/system/hw_accel.h
> index f0c10b6d80..04608073f7 100644
> --- a/include/system/hw_accel.h
> +++ b/include/system/hw_accel.h
> @@ -54,4 +54,14 @@ static inline bool hwaccel_enabled(void)
> || whpx_enabled();
> }
>
> +/**
> + * hwaccel_names:
> + *
> + * Returns: String of supported hardware accelerators.
> + */
> +static inline const char *hwaccel_names(void)
> +{
> + return "kvm, hvf, whpx, or nvmm";
> +}
> +
> #endif /* QEMU_HW_ACCEL_H */
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 40974bee26..6808559fdd 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -25,6 +25,7 @@
> #include "cpu.h"
> #include "tcg/helper-tcg.h"
> #include "exec/translation-block.h"
> +#include "system/hw_accel.h"
> #include "system/hvf.h"
> #include "system/mshv.h"
> #include "system/whpx.h"
> @@ -10226,9 +10227,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
> return;
> }
>
> - if (xcc->host_cpuid_required && !accel_uses_host_cpuid()) {
> + if (xcc->host_cpuid_required && (!accel_uses_host_cpuid() ||
> + !hwaccel_enabled())) {
> g_autofree char *name = x86_cpu_class_get_model_name(xcc);
> - error_setg(&local_err, "CPU model '%s' requires KVM or HVF", name);
> + error_setg(&local_err, "The '%s' CPU type can only be used with "
> + "hardware accelerators %s", name, hwaccel_names());
This results in us telling the user to enable a bunch of accelerators
that are not available on either their architecture and/or their OS.
The existing erorr message had that problem, and this change just
makes it more obvious. Check the CONFIG_xxx variables to determine
what hardware accelerator is available on the platform.
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 8:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 4:58 [PATCH v3] target/i386: make error message for -cpu host more informative Andrew Nguyen
2026-12-02 8:57 ` Daniel P. Berrangé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.