I appreciate the both of you for the feedback.

As Philippe has suggested, I will add hwaccel_enabled() as a condition in
order to check for KVM, HVF, or WHPX.

To Peter, instead of explicitly printing the list of accelerators, maybe I
should add a macro of a string that's something like "KVM, HVF, or WHPX"?
This would be in include/system/hw_accel.h.

As a sidenote, this is my first patch. When I receive feedback, should I
reply first with my plan and get feedback on that before sending a revision?

---
Thanks,
Andrew Nguyen

On Mon, Nov 16, 2026 at 8:10 AM Philippe Mathieu-Daudé <
[email protected]> wrote:

> Hi Andrew,
>
> On 16/11/26 10:38, Peter Maydell wrote:
> > On Mon, 16 Nov 2026 at 03:38, Andrew Nguyen <[email protected]> wrote:
> >>
> >> Included the mention of WHPX when the option -cpu host doesn't have
> >> an accelerator option.
> >>
> >> Signed-off-by: Andrew Nguyen <[email protected]>
> >>
> >> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4836
> >> ---
> >> 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. This patch adds WHPX to the error message. A similar
> patch was made seven
> >> months ago in target/arm/cpu.c:1861.
> >>
> >> Signed-off-by: Andrew Nguyen <[email protected]>
> >> ---
> >> Changes:
> >> - cpu.c:10229: added WHPX to the error message when "-cpu host" doesn't
> include an accelerator
> >> ---
> >>   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;
> >>       }
> >
> > The code isn't checking "is this KVM, HVF or WHPX", though.
> > accel_uses_host_cpuid() is checking "not TCG" (also "not qtest" but as
> > that's a test facility we don't need to mention it here). Listing
> > an explicit set of accelerators means it gets out of date whenever
> > a new one is added (as has already happened here once when the
> > WHPX accelerator was added and the message not updated).
>
> See commit f7fa2b88084c22299b347cea8fd9fadb0b136b22 for an example
> of the hwaccel_enabled() method.
>

Reply via email to