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 9E152606A31A for ; Wed, 2 Dec 2026 04:59:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0vnWh7di Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xYcRT-0000Gl-Ni; Tue, 01 Dec 2026 23:59:43 -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 1xYcRS-0000Gb-P4 for qemu-devel@nongnu.org; Tue, 01 Dec 2026 23:59:42 -0500 Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xYcRQ-0002b2-Rv for qemu-devel@nongnu.org; Tue, 01 Dec 2026 23:59:42 -0500 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-4d113bb814eso3886435fac.0 for ; Tue, 01 Dec 2026 20:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796187579; x=1796792379; darn=nongnu.org; h=cc:to:message-id:content-transfer-encoding:content-type :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=yeRhOtTrNcA/iYln2qzxOVNZAHFA5m0yhoWo0NnPSxI=; b=0vnWh7dit/3V3V+o+Jhr/Q4cb+sH5tBtxWKi7hBE4PKpVxJwEIxOKizU2seTYG3lvk +0+Jw9XF0TB6AwAkBDbxkPohorupJE8gj0wVJ8+5NoAF0l45SZc/jGKMHhp2bpAkFfEU SrcQ8RV+RZ8jy8XDZHnYEf1e0iVkBtjAk9swS2ndvRit+mht04XAg0Gwpch9Lfk8acBi GJHKoCalbNl3/n6zdG1cu9cbT/pd24nkL631BWiU6Nx9TnKFVLxQ15dnaRsf2kYt9XO0 +BEBqtLdzRfqTfGtGidTmBThM2FjSgRFUQoc3ew7XCXV2SpzFzPRiRagg49Zfu+poy4z 8nPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796187579; x=1796792379; h=cc:to:message-id:content-transfer-encoding:content-type :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=yeRhOtTrNcA/iYln2qzxOVNZAHFA5m0yhoWo0NnPSxI=; b=XCm7vbO11fFShM5JeiriMtRIZseVugXDaSapj0OwxBRIHpdgOLVhRS5S0iDt04pINA Jnsry6nx6p2gRqkhL2nI1tebWCVWZf9MGPpyuRcZZHJXaGeORy1sn2kSgxmjPEBWNYez b8UieO8bm5A0BWJEzIz3q0tCcl0Okmp2q4UG5UjfOLM+mJILsem4s0Q4UBDpKVfQLbsl 77Ep+uR+VGJ0QumDjlH+PARIbRaitHaxjI9Xik67vBFTcWWSHEH3zo+LZ0R0m5brGodg yBregjW8lLTDlSuQBr2l86NiUn5VYwu/02V9w6ZvWR3fNzCUEffNkKASQ19aAr+OIvrK BIcQ== X-Gm-Message-State: APuU4Z9DxhNV8e7fkT2ObNyTttDpdZCqvJq/7pga1MZZcXm2bAE3n6FK RF8tEI6uSx2diRIeze05QoVHOLPtm8Ev8+7M4DvYbouVXppTmft2Juo/ X-Gm-Gg: AZFdTZdnPEuwJHf+6tgRjrEmRotYUQO6eQaAFJd/wXTuzGOXL58geF+IYUqF8rCzRpn BV/I/FriGNfnEL64sE0x0kBj8NwNv8orvy2e4SBUmiuzEJAyC6Ci8esVScRRhlVWD89bE7PRXhg 2FQNpD72wEtx16MD5QcZ66FoxK45LNoS8V9WGKNkn61ibYMW/eS0VpsN4f3MigMbasNaHOLT1Fj vmxsn0EMCZI3b3glurrrUCTbnv3bABCCXAQu7g6tyd/F+DGfKlC0zBiIvGyeid4O2EsTihof3Av fjPnvLNkhMDK/WmXD6lqlv3Yf6AsHRR6NYe0YGVGVOq82MG8cskUbRxyyAIqKBZUBt6WZPYLGKT dLV5x9FWmyZgI1nL1lNEio+fhgVzDJVGZdlDrkOyjOmIptkXPFoN93f5UHKFjV9vfkiomzDBtuJ EDZm7Tny5z5HDHwF5EShBjbzy1DCVyEQZWNgUgE8JAHIYyoLkl8veOd84LSXwJRxQscXAM/CYst 3gl02o+sf/soWHrcEElCxuOn/JprZ0+K1VoM1zgDvYOF61glwPA70zNjGSggif8Ul3VVXPysOmS QHctBR//1VBUt8+LXA/GWg== X-Received: by 2002:a05:6871:3409:b0:49e:45d6:4a99 with SMTP id 586e51a60fabf-4bc8434519bmr24886396fac.19.1796187579153; Tue, 01 Dec 2026 20:59:39 -0800 (PST) Received: from [127.0.1.1] ([70.125.236.3]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4bc5b07d57csm33445756fac.1.2026.12.01.20.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 20:59:38 -0800 (PST) From: Andrew Nguyen Date: Tue, 01 Dec 2026 22:58:34 -0600 Subject: [PATCH v3] target/i386: make error message for -cpu host more informative X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261201-4836-cpu-host-error-v3-1-e8ebdbadc4e7@gmail.com> X-B4-Tracking: v=1; b=H4sIAHmlD2sC/33NQQ6CMBCF4auQrh3TKVDRlfcwLlo6hSZiSYuNh nB3CysWxuX/kvlmZpGCo8guxcwCJRedf+YoDwVre/XsCJzJzQQXEhFrqJpSQju+oPdxAgrBB0B qao0n4hYNy5djIOvem3q75+5dnHz4bE8Srut/LyEgWGM56Vpq1ahrNyj3OLZ+YKuXxN5ofhsCO GjFhday4uZs9sayLF8VEFWD+gAAAA== To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Zhao Liu , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Andrew Nguyen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796187577; l=4119; i=xmphyr@gmail.com; s=20261115; h=from:subject:message-id; bh=Qunib5i50VkXrin0HISuSMPUyvLv7XAAGbDPZxcavzs=; b=YqZAiZbAhg4ZCfU54AqN+Vd2z+Cy0V6y04MJl2uXLDFDeo25pWsNKVk8yhvFjB76Dyxb6fycm CPbH8VzCuTWA49YrcZYZP34hzZ62UdkIbFJ1FOfP+N06YnzxylGnHBE X-Developer-Key: i=xmphyr@gmail.com; a=ed25519; pk=NNmtCKBlfBcUb+tQiMXr0u4Z3W1r0gSDovSDVTzPWXE= Received-SPF: pass client-ip=2001:4860:4864:20::2f; envelope-from=xmphyr@gmail.com; helo=mail-oa1-x2f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-20.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_PASS,SPF_PASS, USER_AGENT_GIT 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 "-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()); goto out; } --- base-commit: 3c061218fcf37a98c944ecb88cff56f94f5c0a43 change-id: 20261115-4836-cpu-host-error-1e85b17e0f1d Best regards, -- Andrew Nguyen