All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Nguyen <xmphyr@gmail.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Zhao Liu <zhao1.liu@intel.com>,
	 Peter Maydell <peter.maydell@linaro.org>,
	Andrew Nguyen <xmphyr@gmail.com>
Subject: [PATCH v2 2/2] target/i386: check hardware acceleration with -cpu host and scalable error
Date: Wed, 18 Nov 2026 00:02:53 -0600	[thread overview]
Message-ID: <20261118-4836-cpu-host-error-v2-2-ba02bb640d9d@gmail.com> (raw)
In-Reply-To: <20261118-4836-cpu-host-error-v2-0-ba02bb640d9d@gmail.com>

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



      parent reply	other threads:[~2026-11-18  6:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118-4836-cpu-host-error-v2-2-ba02bb640d9d@gmail.com \
    --to=xmphyr@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=zhao1.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.