From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B75D606A68E for ; Wed, 2 Dec 2026 08:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Y0InNIKf Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xYg9f-0006J2-GP; Wed, 02 Dec 2026 03:57:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xYg9X-0006IK-08 for qemu-devel@nongnu.org; Wed, 02 Dec 2026 03:57:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xYg9T-0007fk-N7 for qemu-devel@nongnu.org; Wed, 02 Dec 2026 03:57:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796201842; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=zqlAr335WDWZiWLk1q0/pNRVt0QDyHdh9ccfP6K6wOY=; b=Y0InNIKf9pj7mMT2dPhNpf+3SrnTAYMU0GA1D9nczaf7CnyaqTP6LRTJrGJF+17fZhOkAJ tDt6pe98JmJ971L9LTND6+IcnQ+2NMxbwzeGipJrhvsbpv8cCd3q2nEwFUmdE8RIH02fUS evGKvuB11mfTHTtTAf6h8yvT4G56wQo= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687--BsPWU5ANFCdpb15MpVn6Q-1; Wed, 2 Dec 2026 08:57:19 +0000 X-MC-Unique: -BsPWU5ANFCdpb15MpVn6Q-1 X-Mimecast-MFC-AGG-ID: -BsPWU5ANFCdpb15MpVn6Q_1796201838 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1AB2E180AEF8; Wed, 2 Dec 2026 08:57:18 +0000 (UTC) Received: from redhat.com (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 71DF37D8; Wed, 2 Dec 2026 08:57:16 +0000 (UTC) Date: Wed, 2 Dec 2026 08:57:13 +0000 From: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= To: Andrew Nguyen Cc: qemu-devel@nongnu.org, Paolo Bonzini , Zhao Liu , Peter Maydell , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= Subject: Re: [PATCH v3] target/i386: make error message for -cpu host more informative Message-ID: References: <20261201-4836-cpu-host-error-v3-1-e8ebdbadc4e7@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20261201-4836-cpu-host-error-v3-1-e8ebdbadc4e7@gmail.com> User-Agent: Mutt/2.4.3 (2026-10-09) X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-22.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_PASS,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 > --- > 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 :|