* [PATCH v2 0/2] target/i386: make error message for -cpu host more informative
@ 2026-11-18 6:02 Andrew Nguyen
2026-11-18 6:02 ` [PATCH v2 1/2] " Andrew Nguyen
2026-11-18 6:02 ` [PATCH v2 2/2] target/i386: check hardware acceleration with -cpu host and scalable error Andrew Nguyen
0 siblings, 2 replies; 3+ messages in thread
From: Andrew Nguyen @ 2026-11-18 6:02 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Zhao Liu, Peter Maydell, Andrew Nguyen
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.
Signed-off-by: Andrew Nguyen <xmphyr@gmail.com>
---
I originally was going to make hwaccel_names() a macro, but that felt wrong.
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.
Just now realizing that the cover letter should largely be left unchanged between revisions.
However, I don't know where to put additional comments otherwise...
---
Changes in v1:
- cpu.c:10229: added WHPX to the error message when "-cpu host" doesn't include an accelerator
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
---
Andrew Nguyen (2):
target/i386: make error message for -cpu host more informative
target/i386: check hardware acceleration with -cpu host and scalable error
include/system/hw_accel.h | 10 ++++++++++
target/i386/cpu.c | 7 +++++--
2 files changed, 15 insertions(+), 2 deletions(-)
---
base-commit: e9fa1f66f0d47c74b6766e1b8b87ad7c2a9394d5
change-id: 20261115-4836-cpu-host-error-1e85b17e0f1d
Best regards,
--
Andrew Nguyen <xmphyr@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2 1/2] target/i386: make error message for -cpu host more informative
2026-11-18 6:02 [PATCH v2 0/2] target/i386: make error message for -cpu host more informative Andrew Nguyen
@ 2026-11-18 6:02 ` Andrew Nguyen
2026-11-18 6:02 ` [PATCH v2 2/2] target/i386: check hardware acceleration with -cpu host and scalable error Andrew Nguyen
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Nguyen @ 2026-11-18 6:02 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Zhao Liu, Peter Maydell, Andrew Nguyen
Included the mention of WHPX when the option -cpu host doesn't have
an accelerator option.
Signed-off-by: Andrew Nguyen <xmphyr@gmail.com>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4836
---
target/i386/cpu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index eab0d5a4d4..7dd5535f80 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -10229,7 +10229,8 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
if (xcc->host_cpuid_required && !accel_uses_host_cpuid()) {
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 KVM,
+ HVF or WHPX", name);
goto out;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2 2/2] target/i386: check hardware acceleration with -cpu host and scalable error
2026-11-18 6:02 [PATCH v2 0/2] target/i386: make error message for -cpu host more informative Andrew Nguyen
2026-11-18 6:02 ` [PATCH v2 1/2] " Andrew Nguyen
@ 2026-11-18 6:02 ` Andrew Nguyen
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Nguyen @ 2026-11-18 6:02 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Zhao Liu, Peter Maydell, Andrew Nguyen
Added an additional check with -cpu host: that a hardware accelerator is
enabled. The error message for when a hardware accelerator isn't used
gives a list of supported hardware accelerators. This list is made more
scalable in the form of a separate function that is substantially easier
to find and append later down the line.
Signed-off-by: Andrew Nguyen <xmphyr@gmail.com>
---
include/system/hw_accel.h | 10 ++++++++++
target/i386/cpu.c | 8 +++++---
2 files changed, 15 insertions(+), 3 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 7dd5535f80..375a4453e4 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"
@@ -10227,10 +10228,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, "The '%s' CPU type can only be used with KVM,
- HVF or WHPX", name);
+ error_setg(&local_err, "The '%s' CPU type can only be used with "
+ "hardware accelerators %s.", name, hwaccel_names());
goto out;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-18 6:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 6:02 [PATCH v2 0/2] target/i386: make error message for -cpu host more informative Andrew Nguyen
2026-11-18 6:02 ` [PATCH v2 1/2] " Andrew Nguyen
2026-11-18 6:02 ` [PATCH v2 2/2] target/i386: check hardware acceleration with -cpu host and scalable error Andrew Nguyen
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.