From patchwork Thu Apr 3 23:58:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 878136 Delivered-To: patch@linaro.org Received: by 2002:a5d:6dae:0:b0:38f:210b:807b with SMTP id u14csp3532587wrs; Thu, 3 Apr 2025 17:05:40 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX68MwDomV+pwBsTOWIDOW2GAqnK5lJc0BYvklv9fsP+55vicg2FQYZRnH2/PrbY0+cgcFq/Q==@linaro.org X-Google-Smtp-Source: AGHT+IGhtWuZfYURm9rUW1/j3VWVtK3Hm3PbSwnMpibWLRFe2fKbqzikI+l23kbtjS1Yax9jcGMc X-Received: by 2002:a05:620a:4089:b0:7c5:5768:40ac with SMTP id af79cd13be357-7c774d4bb03mr160164385a.30.1743725140113; Thu, 03 Apr 2025 17:05:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1743725140; cv=none; d=google.com; s=arc-20240605; b=IGeo3vRwDo5kOw9heTceIZKO37cZsYkxueMBefkG+GVDZtI/zwbXJaNcO5Hkp3hPWG z+LPQlzZph8wJHuFTQnPoL1Dn8QRs4uD8o31zoYpcHbxVIjTiV41hVZxrpvlWMNfLgHC VG3xxiqMr75PR0QwMY0sUTp3I9vkfPFzzkaVzoMUDdRQ7L9igmcpta9jCEFn+rxXOrcB S2aRszWbwqqA6Qg/zaPVl0KDM1t7kwnAaNoIwYCue0wlkfYs7RedZ/W84Wd9UDFiOveP 8bRW5y0VWqj2xIQrGxel3Anas2dq6nyv2nbB8RhB3aNLmjJEB3yINPZ05oKAlZC3Fo2w oEww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pEQ4caRuUm17bqEdIOfMLiQw9DDP+11LU+Cj2r4W6Vc=; fh=cGDjR9+NH75RtMqDHQPhCvgcQemKyI3acX9LAGXbf+c=; b=lgpfJz/HyQ/mb0Qmqo6YgOt0NQIvzaj+Slfr8h7+n97wjg1yESnAYKM3ltj2QPSAaa 0rwSCRHP3ff7Uy6JGAaxyRH5c10oPggw3773hlbZzuzWT367L7+2NBy17fKsV9ftHFm0 ts1jFPjrsiHO9vw71dzZhgitKf89UhVwgUdeEQDSfhgYYNt2EsLGt2weEfV1Zt3cze6R OD0rNOQX+gU2YEwBXNEPAHf917Qh09df1P6sf1W+Wb3R9foazdrkF6HW+mIZaSPHTub4 8XgSXWobgVC/iQXiz+d6jwrJtYpAfEoAtHyKhr5FcXXQVD/K/VNOv38IB/M1fsTEZNqn XySg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DiDhqPnU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4791b05e607si21286841cf.13.2025.04.03.17.05.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Apr 2025 17:05:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DiDhqPnU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u0UVq-0002S7-Kb; Thu, 03 Apr 2025 20:02:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u0UVd-0001sT-4q for qemu-devel@nongnu.org; Thu, 03 Apr 2025 20:02:13 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u0UVX-0003GA-Bb for qemu-devel@nongnu.org; Thu, 03 Apr 2025 20:02:06 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-39c0e0bc733so1226243f8f.1 for ; Thu, 03 Apr 2025 17:02:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1743724920; x=1744329720; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pEQ4caRuUm17bqEdIOfMLiQw9DDP+11LU+Cj2r4W6Vc=; b=DiDhqPnUaC4SRbYNlQmpQg9VqleterL4nzs2cFNnINdG9TROxwQguuoQFsFnL7DFOi +5Bs1Hw7JhhBhXXoOdIeJjgitntj/SRkDLJAqJUL6AEu+txd5tZtjpjOtkqfPhhQNf1j GrCUHnue/X4Df67wMjoAtlJL4pQL9DNPTPglBfbfO2xYfhE2+uTszB1rsOVX6g0JUwa5 Gw4Zx0j4TcxSj5sh5VoLcA8OoB6GOu2p/PILA+uVfIAN+0wSgXfAmvlAQgyi5vh9Fq4Q 4WZXMPSrutGrJpa/GTKbZSeM04yUllTKuVUHWZ6qxLDzJ4I4L/77O2jWK7bgeIm3YTjX PpGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743724920; x=1744329720; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pEQ4caRuUm17bqEdIOfMLiQw9DDP+11LU+Cj2r4W6Vc=; b=QQD/0QgDuMJNvBhNpCWPYaD0l2RR2GIuTn1rSenvm+mqoh8uDkpqrhuYy3HUBr2T55 3qAfxlUhWNLMtvgMkGS7Bz3xmHS77rS8JyZTpfxh7jUi3J8nOnarDJW/19qFbMXfExwU bZ9RzMKxAohiGPTk289lif6Z7vu0oapInsKvaH5BeYuccCJ1FzaPdyLy0vlfbFCAk8bR fgCloUzVq8RiszqDqoelOViVOafnfenugRb++El6uLacbD+ZqTP1rl2CsAaw7fi8plYs mQRid6xkIzKYhpwQIn+Vg3//if1GJW0F0WHNvzenRDBB96V2n62C4xHFKeOC11aRNFUS EBaw== X-Gm-Message-State: AOJu0YwCI9LSixap2QBHrCnDC5aLl2j/LM6S/nM7yLGPtUbCkl48DK7w a2e2ovopiWxtJHemFJc+hm+a2H1vexyXKVi9Cxf6+BYVg83OwP81uoJQo+WovtXHKTeHr7dZQEV J X-Gm-Gg: ASbGncuK2XW+oWZynYlxeGCGA2FyLmcNeTV07NGpICy0azbJenpXiBCXpUlPoQIyb4x zxH7rBgLWq6ezj57SjYsXdm/BVOIT9CZ7yzJh1BrjBke5RnZSbySUbk1vq+YyAimXG3efuD2+n9 cDbJoBH+WG+doUH286RoXlwYUKPdKfa2muENSAHAUNoUPQSAm8m1n1xVnXzg8y/dlqd6KxE8AH8 yIfJuN3U3vUv6diqqwmsmG/ZByFdSHU9zChOL65ajhwXLF7LPXp+zVM6loUUFp4XM08/1Z6VhUm RqCNhGdY3zBjINYa/Als7BDMLZNwMPrIeCNSEL4XyMh1FBuPuIxmulQU6GU2rlDF6ilJdoEs5bt gjY/vePsZkYPlyhYGJq4= X-Received: by 2002:a05:6000:1ac5:b0:390:de33:b0ef with SMTP id ffacd0b85a97d-39cba93c429mr785050f8f.30.1743724920555; Thu, 03 Apr 2025 17:02:00 -0700 (PDT) Received: from localhost.localdomain (184.170.88.92.rev.sfr.net. [92.88.170.184]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ec163107csm35041975e9.3.2025.04.03.17.01.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 03 Apr 2025 17:02:00 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Richard Henderson , Markus Armbruster Subject: [RFC PATCH-for-10.1 33/39] hw/core/machine: Allow dynamic registration of valid CPU types Date: Fri, 4 Apr 2025 01:58:15 +0200 Message-ID: <20250403235821.9909-34-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250403235821.9909-1-philmd@linaro.org> References: <20250403235821.9909-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=philmd@linaro.org; helo=mail-wr1-x42c.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, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Add MachineClass::valid_cpu_types_list, a dynamic list of strings. CPU types can be registered with machine_class_add_valid_cpu_type(). Suggested-by: Pierrick Bouvier Signed-off-by: Philippe Mathieu-Daudé --- include/hw/boards.h | 8 ++++++++ hw/core/machine.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/hw/boards.h b/include/hw/boards.h index b1bbf3c34d4..92a13b0dc32 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -57,6 +57,13 @@ void machine_set_cache_topo_level(MachineState *ms, CacheLevelAndType cache, bool machine_check_smp_cache(const MachineState *ms, Error **errp); void machine_memory_devices_init(MachineState *ms, hwaddr base, uint64_t size); +/** + * machine_class_add_valid_cpu_type: Add type to list of valid CPUs + * @mc: Machine class + * @type: CPU type to allow (should be a subtype of TYPE_CPU) + */ +void machine_class_add_valid_cpu_type(MachineClass *mc, const char *type); + /** * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices * @mc: Machine class @@ -307,6 +314,7 @@ struct MachineClass { bool ignore_memory_transaction_failures; int numa_mem_align_shift; const char * const *valid_cpu_types; + strList *valid_cpu_types_list; strList *allowed_dynamic_sysbus_devices; bool auto_enable_numa_with_memhp; bool auto_enable_numa_with_memdev; diff --git a/hw/core/machine.c b/hw/core/machine.c index f52a4f2273b..5993c6e38d5 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1538,6 +1538,11 @@ const char *machine_class_default_cpu_type(MachineClass *mc) return mc->default_cpu_type; } +void machine_class_add_valid_cpu_type(MachineClass *mc, const char *type) +{ + QAPI_LIST_PREPEND(mc->valid_cpu_types_list, g_strdup(type)); +} + static bool is_cpu_type_supported(const MachineState *machine, Error **errp) { MachineClass *mc = MACHINE_GET_CLASS(machine); @@ -1581,6 +1586,29 @@ static bool is_cpu_type_supported(const MachineState *machine, Error **errp) return false; } } + if (mc->valid_cpu_types_list) { + bool valid = false; + unsigned count = 0; + strList *wl; + + for (wl = mc->valid_cpu_types_list; !valid && wl; wl = wl->next) { + valid |= !!object_class_dynamic_cast(oc, wl->value); + count++; + } + + if (!valid) { + g_autofree char *requested = cpu_model_from_type(machine->cpu_type); + error_setg(errp, "Invalid CPU model: %s", requested); + error_append_hint(errp, "The valid models are: "); + for (wl = mc->valid_cpu_types_list; wl; wl = wl->next) { + g_autofree char *model = cpu_model_from_type(wl->value); + error_append_hint(errp, "%s%s", model, --count ? ", " : ""); + } + error_append_hint(errp, "\n"); + + return false; + } + } /* Check if CPU type is deprecated and warn if so */ cc = CPU_CLASS(oc);