From nobody Sun Feb 8 23:41:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635792190; cv=none; d=zohomail.com; s=zohoarc; b=m64As7y65zMl8aE/1feOmlmYn3YrUJxdO7oSFlIgv0EUhl7l/3x/enWf5sFpx9uZywYYpT06TDvlZy5vDjAoid0HFSGv40TiTzkEiVdhCMc8nDbJBrXeWvf78gd7gbehFRLz00rArKaU8sdZ7YBe2N829A50412ywhJSoxYu6z0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635792190; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=SNHZNzBP1nSDzMaqDz3IAOQ774k1f3QsulMN2SnaIMo=; b=CWgowQO3gVhp/mU458cWXdETaCL74t7xvVyQQdScL+RpsGui0EyDsxirpl5XvYT03uZe8t2ShEJfdymFUYx4QFZVXpaXAbAftqN0qUnsVLEnPraYvW/EUXawYsp5foD1g+XgySiiKjcTdAY2MKbzVFSEUwR6VvYD6ZeVnIMHAFk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1635792190973452.1483820092284; Mon, 1 Nov 2021 11:43:10 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-368-GPpoDayLM2yr9v4Ugb9znw-1; Mon, 01 Nov 2021 14:43:07 -0400 Received: by mail-wr1-f71.google.com with SMTP id c4-20020a056000184400b0016e0cc310b3so6543546wri.3 for ; Mon, 01 Nov 2021 11:43:07 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id w15sm5760475wrk.77.2021.11.01.11.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:43:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635792189; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SNHZNzBP1nSDzMaqDz3IAOQ774k1f3QsulMN2SnaIMo=; b=cDrHqgxB9nhoG4Cac84ItsZjgVpKUoVMWQzDsYEBFnXPhezMATrGByEqtp4HfxUk3fV2bt 0A/+N/zL5H5cGUKK3kIMiN4wA+kII5QtMXiaUz/ovHLZK4wl7HdSzCDzGToLv4kRX/nm0x /HD8PZyXxm4qePS05Sz1/Cx2bW/3vbA= X-MC-Unique: GPpoDayLM2yr9v4Ugb9znw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SNHZNzBP1nSDzMaqDz3IAOQ774k1f3QsulMN2SnaIMo=; b=7ZJi1j/FUzZp7VRdIbQCak5AgA65uTN+OUsqYmBgqgXQzKwfzdRS7MD4xRq8wXmk/Y Nu0cz1r8Wttc4KJLAa2Fx/2TmpV3AygID2tzg4c54Qqe4WF+nwiqg+720K7sXfTUisGH nWKi4gDIYROvRBUqMdtEfUrkPfeeMGKELXtdyX/fM9ZXW4qtyNYdRnr0J+dufwaXsV+f tz50ZQrqZwzvzTIDeDRosAunYGtrrgV0dx0B9llBIZse5+wFJ67n4XEP51ceII2ZDMgR eQEBoK9paXTroxjEOp23Z97roGd4qqw/fADopnRSpY2a0NyCGFqf0P3xloghFLWVPKqs L8Ag== X-Gm-Message-State: AOAM531aRN7MY6Z0W42Lcb8y6C66UE/qhXCsgZjHLC6CIEJ9D+w2/wGz BTg2pGkz9YF2kuHyyVWYotOJSa3xDEKO8s8WXneSLe7CjAD/yDgq7WBbZgnFFn7YqUFmmrcxpin aF3HG6UrcGREUhg== X-Received: by 2002:adf:ce0e:: with SMTP id p14mr18701250wrn.423.1635792186054; Mon, 01 Nov 2021 11:43:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwK0A4GsLFI09HL8uK4Dy9tYyGhnRz4MQ34BHU2niGUY0C7pJB23Whiez8jzowsMPR17s0s6A== X-Received: by 2002:adf:ce0e:: with SMTP id p14mr18701194wrn.423.1635792185774; Mon, 01 Nov 2021 11:43:05 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Marcel Apfelbaum Subject: [PULL 01/10] machine: Move gpio code to hw/core/gpio.c Date: Mon, 1 Nov 2021 19:42:50 +0100 Message-Id: <20211101184259.2859090-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211101184259.2859090-1-philmd@redhat.com> References: <20211101184259.2859090-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635792192391100001 From: Eduardo Habkost Only softmmu code uses gpio, so move gpio code from qdev.c to gpio.c and compile it only on softmmu mode. Signed-off-by: Eduardo Habkost Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20190425200051.19906-2-ehabkost@redhat.com> Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/core/gpio.c | 197 ++++++++++++++++++++++++++++++++++++++++++++ hw/core/qdev.c | 174 -------------------------------------- hw/core/meson.build | 1 + 3 files changed, 198 insertions(+), 174 deletions(-) create mode 100644 hw/core/gpio.c diff --git a/hw/core/gpio.c b/hw/core/gpio.c new file mode 100644 index 00000000000..8e6b4f5edf3 --- /dev/null +++ b/hw/core/gpio.c @@ -0,0 +1,197 @@ +/* + * qdev GPIO helpers + * + * Copyright (c) 2009 CodeSourcery + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/qdev-core.h" +#include "hw/irq.h" +#include "qapi/error.h" + +static NamedGPIOList *qdev_get_named_gpio_list(DeviceState *dev, + const char *name) +{ + NamedGPIOList *ngl; + + QLIST_FOREACH(ngl, &dev->gpios, node) { + /* NULL is a valid and matchable name. */ + if (g_strcmp0(name, ngl->name) =3D=3D 0) { + return ngl; + } + } + + ngl =3D g_malloc0(sizeof(*ngl)); + ngl->name =3D g_strdup(name); + QLIST_INSERT_HEAD(&dev->gpios, ngl, node); + return ngl; +} + +void qdev_init_gpio_in_named_with_opaque(DeviceState *dev, + qemu_irq_handler handler, + void *opaque, + const char *name, int n) +{ + int i; + NamedGPIOList *gpio_list =3D qdev_get_named_gpio_list(dev, name); + + assert(gpio_list->num_out =3D=3D 0 || !name); + gpio_list->in =3D qemu_extend_irqs(gpio_list->in, gpio_list->num_in, h= andler, + opaque, n); + + if (!name) { + name =3D "unnamed-gpio-in"; + } + for (i =3D gpio_list->num_in; i < gpio_list->num_in + n; i++) { + gchar *propname =3D g_strdup_printf("%s[%u]", name, i); + + object_property_add_child(OBJECT(dev), propname, + OBJECT(gpio_list->in[i])); + g_free(propname); + } + + gpio_list->num_in +=3D n; +} + +void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n) +{ + qdev_init_gpio_in_named(dev, handler, NULL, n); +} + +void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins, + const char *name, int n) +{ + int i; + NamedGPIOList *gpio_list =3D qdev_get_named_gpio_list(dev, name); + + assert(gpio_list->num_in =3D=3D 0 || !name); + + if (!name) { + name =3D "unnamed-gpio-out"; + } + memset(pins, 0, sizeof(*pins) * n); + for (i =3D 0; i < n; ++i) { + gchar *propname =3D g_strdup_printf("%s[%u]", name, + gpio_list->num_out + i); + + object_property_add_link(OBJECT(dev), propname, TYPE_IRQ, + (Object **)&pins[i], + object_property_allow_set_link, + OBJ_PROP_LINK_STRONG); + g_free(propname); + } + gpio_list->num_out +=3D n; +} + +void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n) +{ + qdev_init_gpio_out_named(dev, pins, NULL, n); +} + +qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n) +{ + NamedGPIOList *gpio_list =3D qdev_get_named_gpio_list(dev, name); + + assert(n >=3D 0 && n < gpio_list->num_in); + return gpio_list->in[n]; +} + +qemu_irq qdev_get_gpio_in(DeviceState *dev, int n) +{ + return qdev_get_gpio_in_named(dev, NULL, n); +} + +void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n, + qemu_irq pin) +{ + char *propname =3D g_strdup_printf("%s[%d]", + name ? name : "unnamed-gpio-out", n); + if (pin && !OBJECT(pin)->parent) { + /* We need a name for object_property_set_link to work */ + object_property_add_child(container_get(qdev_get_machine(), + "/unattached"), + "non-qdev-gpio[*]", OBJECT(pin)); + } + object_property_set_link(OBJECT(dev), propname, OBJECT(pin), &error_ab= ort); + g_free(propname); +} + +qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, i= nt n) +{ + g_autofree char *propname =3D g_strdup_printf("%s[%d]", + name ? name : "unnamed-gpio-out", n); + + qemu_irq ret =3D (qemu_irq)object_property_get_link(OBJECT(dev), propn= ame, + NULL); + + return ret; +} + +/* disconnect a GPIO output, returning the disconnected input (if any) */ + +static qemu_irq qdev_disconnect_gpio_out_named(DeviceState *dev, + const char *name, int n) +{ + char *propname =3D g_strdup_printf("%s[%d]", + name ? name : "unnamed-gpio-out", n); + + qemu_irq ret =3D (qemu_irq)object_property_get_link(OBJECT(dev), propn= ame, + NULL); + if (ret) { + object_property_set_link(OBJECT(dev), propname, NULL, NULL); + } + g_free(propname); + return ret; +} + +qemu_irq qdev_intercept_gpio_out(DeviceState *dev, qemu_irq icpt, + const char *name, int n) +{ + qemu_irq disconnected =3D qdev_disconnect_gpio_out_named(dev, name, n); + qdev_connect_gpio_out_named(dev, name, n, icpt); + return disconnected; +} + +void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin) +{ + qdev_connect_gpio_out_named(dev, NULL, n, pin); +} + +void qdev_pass_gpios(DeviceState *dev, DeviceState *container, + const char *name) +{ + int i; + NamedGPIOList *ngl =3D qdev_get_named_gpio_list(dev, name); + + for (i =3D 0; i < ngl->num_in; i++) { + const char *nm =3D ngl->name ? ngl->name : "unnamed-gpio-in"; + char *propname =3D g_strdup_printf("%s[%d]", nm, i); + + object_property_add_alias(OBJECT(container), propname, + OBJECT(dev), propname); + g_free(propname); + } + for (i =3D 0; i < ngl->num_out; i++) { + const char *nm =3D ngl->name ? ngl->name : "unnamed-gpio-out"; + char *propname =3D g_strdup_printf("%s[%d]", nm, i); + + object_property_add_alias(OBJECT(container), propname, + OBJECT(dev), propname); + g_free(propname); + } + QLIST_REMOVE(ngl, node); + QLIST_INSERT_HEAD(&container->gpios, ngl, node); +} diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 7f06403752d..1e38f997245 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -436,180 +436,6 @@ BusState *qdev_get_parent_bus(DeviceState *dev) return dev->parent_bus; } =20 -static NamedGPIOList *qdev_get_named_gpio_list(DeviceState *dev, - const char *name) -{ - NamedGPIOList *ngl; - - QLIST_FOREACH(ngl, &dev->gpios, node) { - /* NULL is a valid and matchable name. */ - if (g_strcmp0(name, ngl->name) =3D=3D 0) { - return ngl; - } - } - - ngl =3D g_malloc0(sizeof(*ngl)); - ngl->name =3D g_strdup(name); - QLIST_INSERT_HEAD(&dev->gpios, ngl, node); - return ngl; -} - -void qdev_init_gpio_in_named_with_opaque(DeviceState *dev, - qemu_irq_handler handler, - void *opaque, - const char *name, int n) -{ - int i; - NamedGPIOList *gpio_list =3D qdev_get_named_gpio_list(dev, name); - - assert(gpio_list->num_out =3D=3D 0 || !name); - gpio_list->in =3D qemu_extend_irqs(gpio_list->in, gpio_list->num_in, h= andler, - opaque, n); - - if (!name) { - name =3D "unnamed-gpio-in"; - } - for (i =3D gpio_list->num_in; i < gpio_list->num_in + n; i++) { - gchar *propname =3D g_strdup_printf("%s[%u]", name, i); - - object_property_add_child(OBJECT(dev), propname, - OBJECT(gpio_list->in[i])); - g_free(propname); - } - - gpio_list->num_in +=3D n; -} - -void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n) -{ - qdev_init_gpio_in_named(dev, handler, NULL, n); -} - -void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins, - const char *name, int n) -{ - int i; - NamedGPIOList *gpio_list =3D qdev_get_named_gpio_list(dev, name); - - assert(gpio_list->num_in =3D=3D 0 || !name); - - if (!name) { - name =3D "unnamed-gpio-out"; - } - memset(pins, 0, sizeof(*pins) * n); - for (i =3D 0; i < n; ++i) { - gchar *propname =3D g_strdup_printf("%s[%u]", name, - gpio_list->num_out + i); - - object_property_add_link(OBJECT(dev), propname, TYPE_IRQ, - (Object **)&pins[i], - object_property_allow_set_link, - OBJ_PROP_LINK_STRONG); - g_free(propname); - } - gpio_list->num_out +=3D n; -} - -void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n) -{ - qdev_init_gpio_out_named(dev, pins, NULL, n); -} - -qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n) -{ - NamedGPIOList *gpio_list =3D qdev_get_named_gpio_list(dev, name); - - assert(n >=3D 0 && n < gpio_list->num_in); - return gpio_list->in[n]; -} - -qemu_irq qdev_get_gpio_in(DeviceState *dev, int n) -{ - return qdev_get_gpio_in_named(dev, NULL, n); -} - -void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n, - qemu_irq pin) -{ - char *propname =3D g_strdup_printf("%s[%d]", - name ? name : "unnamed-gpio-out", n); - if (pin && !OBJECT(pin)->parent) { - /* We need a name for object_property_set_link to work */ - object_property_add_child(container_get(qdev_get_machine(), - "/unattached"), - "non-qdev-gpio[*]", OBJECT(pin)); - } - object_property_set_link(OBJECT(dev), propname, OBJECT(pin), &error_ab= ort); - g_free(propname); -} - -qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, i= nt n) -{ - g_autofree char *propname =3D g_strdup_printf("%s[%d]", - name ? name : "unnamed-gpio-out", n); - - qemu_irq ret =3D (qemu_irq)object_property_get_link(OBJECT(dev), propn= ame, - NULL); - - return ret; -} - -/* disconnect a GPIO output, returning the disconnected input (if any) */ - -static qemu_irq qdev_disconnect_gpio_out_named(DeviceState *dev, - const char *name, int n) -{ - char *propname =3D g_strdup_printf("%s[%d]", - name ? name : "unnamed-gpio-out", n); - - qemu_irq ret =3D (qemu_irq)object_property_get_link(OBJECT(dev), propn= ame, - NULL); - if (ret) { - object_property_set_link(OBJECT(dev), propname, NULL, NULL); - } - g_free(propname); - return ret; -} - -qemu_irq qdev_intercept_gpio_out(DeviceState *dev, qemu_irq icpt, - const char *name, int n) -{ - qemu_irq disconnected =3D qdev_disconnect_gpio_out_named(dev, name, n); - qdev_connect_gpio_out_named(dev, name, n, icpt); - return disconnected; -} - -void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin) -{ - qdev_connect_gpio_out_named(dev, NULL, n, pin); -} - -void qdev_pass_gpios(DeviceState *dev, DeviceState *container, - const char *name) -{ - int i; - NamedGPIOList *ngl =3D qdev_get_named_gpio_list(dev, name); - - for (i =3D 0; i < ngl->num_in; i++) { - const char *nm =3D ngl->name ? ngl->name : "unnamed-gpio-in"; - char *propname =3D g_strdup_printf("%s[%d]", nm, i); - - object_property_add_alias(OBJECT(container), propname, - OBJECT(dev), propname); - g_free(propname); - } - for (i =3D 0; i < ngl->num_out; i++) { - const char *nm =3D ngl->name ? ngl->name : "unnamed-gpio-out"; - char *propname =3D g_strdup_printf("%s[%d]", nm, i); - - object_property_add_alias(OBJECT(container), propname, - OBJECT(dev), propname); - g_free(propname); - } - QLIST_REMOVE(ngl, node); - QLIST_INSERT_HEAD(&container->gpios, ngl, node); -} - BusState *qdev_get_child_bus(DeviceState *dev, const char *name) { BusState *bus; diff --git a/hw/core/meson.build b/hw/core/meson.build index 18f44fb7c24..86f26f0a60f 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -27,6 +27,7 @@ softmmu_ss.add(files( 'cpu-sysemu.c', 'fw-path-provider.c', + 'gpio.c', 'loader.c', 'machine-hmp-cmds.c', 'machine.c', --=20 2.31.1 From nobody Sun Feb 8 23:41:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635792194; cv=none; d=zohomail.com; s=zohoarc; b=iZQHJ7XHraX2SchAV0jwYemheGD/j573IDhQtwJjMPoX7r5tnlHBuToGrK5DAwbTySinkO500v21bRDQsTnTkCI9DFMfkg5VwvxCt7z8V3rPJBVkWD7xFEag4/FkT3qaXzYXUVnw09Ppvcf1c+PxzOM+AyzmRWKYxqIZPrErdLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635792194; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=5VbMOmYh/1NBtZLn877qT4k9nsfbY/WlKvNxb1iUJ0s=; b=DHzDIdQdMXVgq9sNSVLWO+gQbtfrksHOJ8a5NvFfRmdk45vXrWZjqZhDl/iUdbu/JMXPh11CQhPqIw6+zAeM8ruvFOcaeHgJuqu4VNW8layzisOLgiD/yMjgTRgDvm3YmAkfi0yBNifWNzzhS8AZfXt1jcLBljVGA3X+1ij1njY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1635792194489589.0103704893353; Mon, 1 Nov 2021 11:43:14 -0700 (PDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-2VYoBHl_Nv6N9ZIm9JgYRA-1; Mon, 01 Nov 2021 14:43:12 -0400 Received: by mail-wr1-f69.google.com with SMTP id k8-20020a5d5248000000b001763e7c9ce5so5415473wrc.22 for ; Mon, 01 Nov 2021 11:43:11 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id h16sm8743605wrm.27.2021.11.01.11.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635792193; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5VbMOmYh/1NBtZLn877qT4k9nsfbY/WlKvNxb1iUJ0s=; b=hrx6rZPg9hSx7pwBoJPBl2qzS7FEtr4RVDFF9PwEqMXDB77RHKrmtXELeQVTwia5mezd5W 4e8eT2ym0rZWJ+sH3KMgdQ0x6ZOx4o0ihOqfbmE6wF+AlfWhjUJyhujmc0UIjIMN20PYcp y52PleAAVqczGLDR0leEhmcsYedvTgc= X-MC-Unique: 2VYoBHl_Nv6N9ZIm9JgYRA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5VbMOmYh/1NBtZLn877qT4k9nsfbY/WlKvNxb1iUJ0s=; b=S0FWE/tu6sf2J+gagnyzNHeB23NSFC+sRrg7BAAF8n8iaP9VuyLQVqcTshSl7sOPeT RxxdGeouxwMeVb7HW4TZcKICggkKnAx3gkq8z82rTitbHvup0+EofH5esQU+iPLDPelh Wtn6Mpp0PL+rLw5aZ7B7362jD4pcGuEgkJfV3faZ0acebz7DtuRBCouOl3NvwM2F2kAx 35x8qVA+aoo5YKOTFXxwWB3foE1L71vFzT//0cxxCgCe73cbEhPNYJ/ETHfEuROeMcw+ wWf2dXd27bjN19uLCU5m5rm4cZ9Kra0e+PcKxdY3mRJaEWd0LGfuqO1SZFchXN9j6V6q rdQg== X-Gm-Message-State: AOAM5301LoQbAaOUnywMlJfk9YL0tHXBWdHjqg1vNpiysKlBqaWnaeXs k6Q6vWQpxvjQ7EJppm8BfmSze3Pl61pCY5v068RM8RWTPdMHPWFWThFlRowR6JrDb9uXhyAt7Sf Bt08cLn5EdgRtLA== X-Received: by 2002:a05:600c:3b0d:: with SMTP id m13mr797451wms.100.1635792190900; Mon, 01 Nov 2021 11:43:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxNJ6ipODIMr/C3zQvWlQZFuNSVPzituzyug8uOvpGydQDViExmEM75BseAm9ArkxcaCRd+g== X-Received: by 2002:a05:600c:3b0d:: with SMTP id m13mr797426wms.100.1635792190707; Mon, 01 Nov 2021 11:43:10 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Marcel Apfelbaum , Yanan Wang Subject: [PULL 02/10] hw/core: Restrict sysemu specific files Date: Mon, 1 Nov 2021 19:42:51 +0100 Message-Id: <20211101184259.2859090-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211101184259.2859090-1-philmd@redhat.com> References: <20211101184259.2859090-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635792196723100001 All these files don't make sense for tools and user emulation, restrict them to system emulation. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Yanan Wang Tested-by: Yanan Wang Acked-by: Eduardo Habkost Message-Id: <20211028150521.1973821-2-philmd@redhat.com> --- hw/core/meson.build | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/hw/core/meson.build b/hw/core/meson.build index 86f26f0a60f..6af4c5c5cbc 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -14,15 +14,15 @@ ) =20 common_ss.add(files('cpu-common.c')) -common_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) -common_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: files('generic-loade= r.c')) -common_ss.add(when: ['CONFIG_GUEST_LOADER', fdt], if_true: files('guest-lo= ader.c')) -common_ss.add(when: 'CONFIG_OR_IRQ', if_true: files('or-irq.c')) -common_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('platform-bus.c'= )) -common_ss.add(when: 'CONFIG_PTIMER', if_true: files('ptimer.c')) -common_ss.add(when: 'CONFIG_REGISTER', if_true: files('register.c')) -common_ss.add(when: 'CONFIG_SPLIT_IRQ', if_true: files('split-irq.c')) -common_ss.add(when: 'CONFIG_XILINX_AXI', if_true: files('stream.c')) +softmmu_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) +softmmu_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: files('generic-load= er.c')) +softmmu_ss.add(when: ['CONFIG_GUEST_LOADER', fdt], if_true: files('guest-l= oader.c')) +softmmu_ss.add(when: 'CONFIG_OR_IRQ', if_true: files('or-irq.c')) +softmmu_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('platform-bus.c= ')) +softmmu_ss.add(when: 'CONFIG_PTIMER', if_true: files('ptimer.c')) +softmmu_ss.add(when: 'CONFIG_REGISTER', if_true: files('register.c')) +softmmu_ss.add(when: 'CONFIG_SPLIT_IRQ', if_true: files('split-irq.c')) +softmmu_ss.add(when: 'CONFIG_XILINX_AXI', if_true: files('stream.c')) =20 softmmu_ss.add(files( 'cpu-sysemu.c', --=20 2.31.1 From nobody Sun Feb 8 23:41:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635792199; cv=none; d=zohomail.com; s=zohoarc; b=jRqdhqz9flFx6zeauCUh+pH85cak0ChCQtwm3e0ZQG8aMzIrJv13BFE4omSM1Kqj3xDHsIy9RyqkoiKFsCbzZtqZG0Jq8yn3I5ZdYnX+mnKksyQB5VlV82278p4LtuNJHpIGfx7Wp4ZiEaKdTIt1HtTI+fN2cs2HRDqdtTT4Ip0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635792199; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=IhijWbgKLTtnsiOPXsxu08OvEiKOisd4DyugRUJL+wM=; b=c/92VMW+qOT07nHBEWqntPHT6QYg3Z3w3AbhqEaoKRwW7MG5UO9H8YkX9p5zGcu8KPBJWKn1xeoa8tca3AVmRAJgMt0yg4YIjLVDHDE9VHEzy86gmRfSHnRSnooKUJMZ4c+/GhrTviPmj+aR4LrGFX8u9JBsXLuggmkWGydqxvA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1635792199456892.9610153013708; Mon, 1 Nov 2021 11:43:19 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-192-hysmqsRZO5uu-Zl0kacbYA-1; Mon, 01 Nov 2021 14:43:17 -0400 Received: by mail-wr1-f70.google.com with SMTP id z5-20020a5d6405000000b00182083d7d2aso2096663wru.13 for ; Mon, 01 Nov 2021 11:43:17 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id l124sm304374wml.8.2021.11.01.11.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635792198; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IhijWbgKLTtnsiOPXsxu08OvEiKOisd4DyugRUJL+wM=; b=LiEtPUIT/VHaeR71/PRdu8X2dhiWyQqqjysNBaoWJYu1i5ko3GWwBq+hINSEQq4lysgQCt 3fG2ta3UW1UUPMbPooQWZCIB3VFQf3gvAvj6mUoU/ARkdYIfbiV0TwRNSw1XzyXtrmh5KC wsd/thCj8t5O+oIk7MgRxwso/t13O3A= X-MC-Unique: hysmqsRZO5uu-Zl0kacbYA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IhijWbgKLTtnsiOPXsxu08OvEiKOisd4DyugRUJL+wM=; b=srCcDLsHm2I4ODkNJkKBVxCtKueC+ElYeA/tYim7QkzGvqQ+GajsvxxYoZqmtbghRC w3Zm4bEapUYqyx8NFiTg7yiXdGvqAP8jy6yVnp/hzwt38KTfvfOK9NSYuOQBmTyMAFXA dB5uLl1Jn9MYqfY+shdix+GDM0CsKu9bDa9QqBXEzudXgUmRu9yd0nY5eLXl1heMPKWr xMh8IU5Oe7AWmf4KQaKjwkDU+MTJjWZ3041gF8GH+b3GmP6JkC3ez6CDwUKT+JqKlr9U pComZYBjbbBRm+AJLvYVdYi+ARB7Eknf4fDMVuStPZtbvk70x1PPTvu+HaW9mgNA5RLc E6ag== X-Gm-Message-State: AOAM532qNZlBh6QiJmRsl/iQBIKZDFtszqK9xM4H7NuMSdmbWGe9frle pkWSDNbXRPtqjiOa2n/Cekv9eb8Kk3rJEY1+3/PuPqsPUpY35q43zjlMfixrX0aPRinPG+GSSNs cojSIxObcuGITrw== X-Received: by 2002:a5d:69c5:: with SMTP id s5mr36834177wrw.283.1635792196199; Mon, 01 Nov 2021 11:43:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfnLqbxMIwErwRSz3QcOyUFEpGwdo7C00sF7zicqDvDsgPuicCaBl0IzZM7tQ3NZN+0CiKtw== X-Received: by 2002:a5d:69c5:: with SMTP id s5mr36834164wrw.283.1635792196085; Mon, 01 Nov 2021 11:43:16 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Marcel Apfelbaum , Yanan Wang Subject: [PULL 03/10] hw/core: Declare meson source set Date: Mon, 1 Nov 2021 19:42:52 +0100 Message-Id: <20211101184259.2859090-4-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211101184259.2859090-1-philmd@redhat.com> References: <20211101184259.2859090-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635792201559100002 As we want to be able to conditionally add files to the hw/core file list, use a source set. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Yanan Wang Tested-by: Yanan Wang Acked-by: Eduardo Habkost Message-Id: <20211028150521.1973821-3-philmd@redhat.com> --- meson.build | 4 +++- hw/core/meson.build | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index b0927283976..85f1e43dfe6 100644 --- a/meson.build +++ b/meson.build @@ -2365,6 +2365,7 @@ chardev_ss =3D ss.source_set() common_ss =3D ss.source_set() crypto_ss =3D ss.source_set() +hwcore_ss =3D ss.source_set() io_ss =3D ss.source_set() linux_user_ss =3D ss.source_set() qmp_ss =3D ss.source_set() @@ -2806,7 +2807,8 @@ =20 chardev =3D declare_dependency(link_whole: libchardev) =20 -libhwcore =3D static_library('hwcore', sources: hwcore_files + genh, +hwcore_ss =3D hwcore_ss.apply(config_host, strict: false) +libhwcore =3D static_library('hwcore', sources: hwcore_ss.sources() + genh, name_suffix: 'fa', build_by_default: false) hwcore =3D declare_dependency(link_whole: libhwcore) diff --git a/hw/core/meson.build b/hw/core/meson.build index 6af4c5c5cbc..cc1ebb8e0f4 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -1,5 +1,5 @@ # core qdev-related obj files, also used by *-user and unit tests -hwcore_files =3D files( +hwcore_ss.add(files( 'bus.c', 'hotplug.c', 'qdev-properties.c', @@ -11,7 +11,7 @@ 'irq.c', 'clock.c', 'qdev-clock.c', -) +)) =20 common_ss.add(files('cpu-common.c')) softmmu_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) --=20 2.31.1 From nobody Sun Feb 8 23:41:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635792204; cv=none; d=zohomail.com; s=zohoarc; b=Cv4z6iZjdq+i9yTAsj9naTuFjBXg1Pr6GTjR+3eyarfqmE7ziPgTT55xw+D6I8CA/JPjWz4TzPCdcfCB02odbl0NGmmQkf1icWSVg60svHQU0Kk6hgbQ1IoEPBldIBLTrVG7S19GwfLr63OoISXz6mpbSUbNJo8YO9J/lk8rHg0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635792204; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=zP0Zzar9NcpirKydIFsBcmX/ZgtzRAXafWTr0rzZA9Y=; b=XjWk2QAgcNlUg1xR7uTSqOqTSej6Z6flScUxzUDwzE5oSmcOazGb6cmfttIW4efs70F5NdpNcWc8h6NwxcMcdfRcNK983tgq+5CEz58nO9T5SfsnrrGwUuUswUPaYTdmjKG+OzbTqVVu8ntI8njDHsrv6kPPwDYd4uI2kIv//xw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1635792204289653.353470086683; Mon, 1 Nov 2021 11:43:24 -0700 (PDT) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-429-gnsfIvJBNbmpmp8AcuAbCg-1; Mon, 01 Nov 2021 14:43:22 -0400 Received: by mail-wm1-f69.google.com with SMTP id k5-20020a7bc3050000b02901e081f69d80so6324878wmj.8 for ; Mon, 01 Nov 2021 11:43:22 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id u20sm338753wmq.3.2021.11.01.11.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:43:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635792203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zP0Zzar9NcpirKydIFsBcmX/ZgtzRAXafWTr0rzZA9Y=; b=P6OpwXt3c79ScGH5qWd8G6ZHRGJ7WJqIWkkjx9OYXMskW3TvTuh6ALBxy29kcRG7cyc/UB hnz3rHPtZbqdfnRug5fDmpJM4OZvvvtiiDrr5qPXPK7Or0yDdOad65J1bVRk3LqcgLAY+9 i/TpNO5WSz/Sn/igHEp73FLKDNTXFYY= X-MC-Unique: gnsfIvJBNbmpmp8AcuAbCg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zP0Zzar9NcpirKydIFsBcmX/ZgtzRAXafWTr0rzZA9Y=; b=yhpDVjRFwHn/wea2Em6MvMPkrsovm+bRincUm8GdHsc1hMUk+1fYUDadPHYqtPLDux 59S/1ahl4YKYxHkmdgMTL6H4F3M4I50legs7Zok6xTBAbtRtx6/g0ZGl+Iv//Rdb6EG1 ybC9FcY4l7om1s0xJfwQCoSKhMC719at2t6y819gPOALcSd89KOB5x8I8tRODgtVLYNT +UwC+qf0gTCnyl7kPHOuSdtceRe7HE/bLGIbsRgOurxnCaqhLrwxNvBEnpEoalEwN685 Qb8PXvocrtV+iRgL8s3eWwbUNy6PQ8DqcmOooWyTRrW3KWjAaqgN0OFYaMVpSgHsEUpM KXCg== X-Gm-Message-State: AOAM532GwLd+U3o9Z+T5GTwgDyNsOeOPI56rlVLop/5G56uaA1MRGs9d iraf7579G679O9kBBm1cfDa/yDYbifYC4R9y5MdqfTbvggSSRLU48nquZOaljZdaI7Z7ddZDCA3 1ctvF2hf2abYzEQ== X-Received: by 2002:a05:600c:2f01:: with SMTP id r1mr740622wmn.153.1635792200952; Mon, 01 Nov 2021 11:43:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysnc/rIs757lBgpRlW4l367oMuNqH+BKNG0J3j46i7dg3+kfgCTM3Q/LXgHkwQFSCs2dCtPA== X-Received: by 2002:a05:600c:2f01:: with SMTP id r1mr740601wmn.153.1635792200765; Mon, 01 Nov 2021 11:43:20 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Marcel Apfelbaum , Yanan Wang Subject: [PULL 04/10] hw/core: Extract hotplug-related functions to qdev-hotplug.c Date: Mon, 1 Nov 2021 19:42:53 +0100 Message-Id: <20211101184259.2859090-5-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211101184259.2859090-1-philmd@redhat.com> References: <20211101184259.2859090-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635792205806100001 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Yanan Wang Acked-by: Eduardo Habkost Message-Id: <20211028150521.1973821-4-philmd@redhat.com> --- hw/core/qdev-hotplug.c | 73 ++++++++++++++++++++++++++++++++++++++++++ hw/core/qdev.c | 60 ---------------------------------- hw/core/meson.build | 1 + 3 files changed, 74 insertions(+), 60 deletions(-) create mode 100644 hw/core/qdev-hotplug.c diff --git a/hw/core/qdev-hotplug.c b/hw/core/qdev-hotplug.c new file mode 100644 index 00000000000..d495d0e9c70 --- /dev/null +++ b/hw/core/qdev-hotplug.c @@ -0,0 +1,73 @@ +/* + * QDev Hotplug handlers + * + * Copyright (c) Red Hat + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/qdev-core.h" +#include "hw/boards.h" + +HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev) +{ + MachineState *machine; + MachineClass *mc; + Object *m_obj =3D qdev_get_machine(); + + if (object_dynamic_cast(m_obj, TYPE_MACHINE)) { + machine =3D MACHINE(m_obj); + mc =3D MACHINE_GET_CLASS(machine); + if (mc->get_hotplug_handler) { + return mc->get_hotplug_handler(machine, dev); + } + } + + return NULL; +} + +bool qdev_hotplug_allowed(DeviceState *dev, Error **errp) +{ + MachineState *machine; + MachineClass *mc; + Object *m_obj =3D qdev_get_machine(); + + if (object_dynamic_cast(m_obj, TYPE_MACHINE)) { + machine =3D MACHINE(m_obj); + mc =3D MACHINE_GET_CLASS(machine); + if (mc->hotplug_allowed) { + return mc->hotplug_allowed(machine, dev, errp); + } + } + + return true; +} + +HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev) +{ + if (dev->parent_bus) { + return dev->parent_bus->hotplug_handler; + } + return NULL; +} + +HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev) +{ + HotplugHandler *hotplug_ctrl =3D qdev_get_machine_hotplug_handler(dev); + + if (hotplug_ctrl =3D=3D NULL && dev->parent_bus) { + hotplug_ctrl =3D qdev_get_bus_hotplug_handler(dev); + } + return hotplug_ctrl; +} + +/* can be used as ->unplug() callback for the simple cases */ +void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + qdev_unrealize(dev); +} diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 1e38f997245..84f3019440f 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -33,7 +33,6 @@ #include "qapi/visitor.h" #include "qemu/error-report.h" #include "qemu/option.h" -#include "hw/hotplug.h" #include "hw/irq.h" #include "hw/qdev-properties.h" #include "hw/boards.h" @@ -238,58 +237,6 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int= alias_id, dev->alias_required_for_version =3D required_for_version; } =20 -HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev) -{ - MachineState *machine; - MachineClass *mc; - Object *m_obj =3D qdev_get_machine(); - - if (object_dynamic_cast(m_obj, TYPE_MACHINE)) { - machine =3D MACHINE(m_obj); - mc =3D MACHINE_GET_CLASS(machine); - if (mc->get_hotplug_handler) { - return mc->get_hotplug_handler(machine, dev); - } - } - - return NULL; -} - -bool qdev_hotplug_allowed(DeviceState *dev, Error **errp) -{ - MachineState *machine; - MachineClass *mc; - Object *m_obj =3D qdev_get_machine(); - - if (object_dynamic_cast(m_obj, TYPE_MACHINE)) { - machine =3D MACHINE(m_obj); - mc =3D MACHINE_GET_CLASS(machine); - if (mc->hotplug_allowed) { - return mc->hotplug_allowed(machine, dev, errp); - } - } - - return true; -} - -HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev) -{ - if (dev->parent_bus) { - return dev->parent_bus->hotplug_handler; - } - return NULL; -} - -HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev) -{ - HotplugHandler *hotplug_ctrl =3D qdev_get_machine_hotplug_handler(dev); - - if (hotplug_ctrl =3D=3D NULL && dev->parent_bus) { - hotplug_ctrl =3D qdev_get_bus_hotplug_handler(dev); - } - return hotplug_ctrl; -} - static int qdev_prereset(DeviceState *dev, void *opaque) { trace_qdev_reset_tree(dev, object_get_typename(OBJECT(dev))); @@ -371,13 +318,6 @@ static void device_reset_child_foreach(Object *obj, Re= settableChildCallback cb, } } =20 -/* can be used as ->unplug() callback for the simple cases */ -void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, - DeviceState *dev, Error **errp) -{ - qdev_unrealize(dev); -} - bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp) { assert(!dev->realized && !dev->parent_bus); diff --git a/hw/core/meson.build b/hw/core/meson.build index cc1ebb8e0f4..c9fe6441d92 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -11,6 +11,7 @@ 'irq.c', 'clock.c', 'qdev-clock.c', + 'qdev-hotplug.c', )) =20 common_ss.add(files('cpu-common.c')) --=20 2.31.1 From nobody Sun Feb 8 23:41:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635792209; cv=none; d=zohomail.com; s=zohoarc; b=ghkjQAcQAajleSgwgmpCaNd458L8eOZT8s6PBMeB5csliFfw6L75SXuGU/BCTSvLGjO/4icTjXZYcRagMUEKxG10VxF0ptJ6t6pCxExDsQprpFHWdsIsrM25ydTqMHqajtTaJVjb79hbPjqmQbQSm0RFVQNf54HLaTLch1w+gbw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635792209; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=OwFvWOuJyssO0Z6DL9B2iJO2pVnuKxsynrvNM6xKjqs=; b=PmuUMZwLPr38G1jJPf/9TIW86IpuvquLZFrQWB7RqnZUAC4eSMqe+D7c4st+P+Ui4+xbkcy8N0j+OsJAfdOFvx3UJUV/FKR2ynMOoD4TVOMLo10XT/L/x0IzZ7YH5gtgkoe822esHwuz6z19FzCgfgOfa/++FDLL15Gg8dqntD0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1635792209681791.1548675667599; Mon, 1 Nov 2021 11:43:29 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-18-bOW3nr9HP-KzOBJZCjGCcA-1; Mon, 01 Nov 2021 14:43:27 -0400 Received: by mail-wm1-f70.google.com with SMTP id l187-20020a1c25c4000000b0030da46b76daso42844wml.9 for ; Mon, 01 Nov 2021 11:43:27 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id c15sm14428464wrs.19.2021.11.01.11.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635792208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OwFvWOuJyssO0Z6DL9B2iJO2pVnuKxsynrvNM6xKjqs=; b=dgd+GwNKSG9taVr7N2znWSxu3MVbVDguonErZnPDPdyhYUL8IdyoQrJkMAqdTfaXPBF1Jl oDPgrujthaQ/yNyNvZMzmlbSyLvWtUfrXPZqdbV2oEBx3GdWvL887VtHfmZV3x6mK9/HUs IpSYb4/kkCPa9PdTVB0M3vGZDFrsZB0= X-MC-Unique: bOW3nr9HP-KzOBJZCjGCcA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OwFvWOuJyssO0Z6DL9B2iJO2pVnuKxsynrvNM6xKjqs=; b=M+iQ3dP9898baFX4/GC+f+x1IUK5N1MRKAbW4DLgxgRz8AeNODrkIFXSRykIT5gmOs RHWphDdazgQA6Jvv1+n5AsQsy6OhC7Ky3cRGNl1pmdqXUgbB9qK26ua25kC8yYI6XEmN j4yWBX9GHfnvT65lJGjZ9cPckQuY0U35qv8YauDsehBbaXyb0rz9zg2whBFPgZWuLOHD eBvSQBvYSqB6AU0/rHd0+cY0ThI/pJQuKF8506fglqaic//1Hsxv/mVLehVELGMY4X5N rA03FX3Z3kY8dHEVJ6i9RvJKuKDn4WgjOCHGd8d69t/5rmRQqM+Z8N2D4iTJbah1nz6h xthw== X-Gm-Message-State: AOAM530lJraP89gO2wFft614nTysfO2BgQ+FJ1cUs/Km1XqFg83r7XWQ Ywzo9+Kp8RJ+oBFdjvHPcp2ezgwAwuoydPmguPHNuHHxjYkfZH+6yAays4xp0uqjwbv3vTvtRXX mrMXmpv7X/h226A== X-Received: by 2002:a5d:4e0b:: with SMTP id p11mr36822759wrt.88.1635792206512; Mon, 01 Nov 2021 11:43:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqaJuWFOc17DJo3kuVwUakNDeYQZXBzO2XBCIsQJunrj/QbH+w59C4EBPssg5T74gYfhFJRQ== X-Received: by 2002:a5d:4e0b:: with SMTP id p11mr36822733wrt.88.1635792206360; Mon, 01 Nov 2021 11:43:26 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Marcel Apfelbaum , Yanan Wang Subject: [PULL 05/10] hw/core: Restrict hotplug to system emulation Date: Mon, 1 Nov 2021 19:42:54 +0100 Message-Id: <20211101184259.2859090-6-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211101184259.2859090-1-philmd@redhat.com> References: <20211101184259.2859090-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635792210219100001 Restrict hotplug to system emulation, add stubs for the other uses. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Yanan Wang Acked-by: Eduardo Habkost Message-Id: <20211028150521.1973821-5-philmd@redhat.com> --- hw/core/hotplug-stubs.c | 34 ++++++++++++++++++++++++++++++++++ hw/core/meson.build | 12 ++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 hw/core/hotplug-stubs.c diff --git a/hw/core/hotplug-stubs.c b/hw/core/hotplug-stubs.c new file mode 100644 index 00000000000..7aadaa29bd5 --- /dev/null +++ b/hw/core/hotplug-stubs.c @@ -0,0 +1,34 @@ +/* + * Hotplug handler stubs + * + * Copyright (c) Red Hat + * + * Authors: + * Philippe Mathieu-Daud=C3=A9 , + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "hw/qdev-core.h" + +HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev) +{ + return NULL; +} + +void hotplug_handler_pre_plug(HotplugHandler *plug_handler, + DeviceState *plugged_dev, + Error **errp) +{ + g_assert_not_reached(); +} + +void hotplug_handler_plug(HotplugHandler *plug_handler, + DeviceState *plugged_dev, + Error **errp) +{ + g_assert_not_reached(); +} diff --git a/hw/core/meson.build b/hw/core/meson.build index c9fe6441d92..7ec7bb93d5f 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -1,7 +1,6 @@ # core qdev-related obj files, also used by *-user and unit tests hwcore_ss.add(files( 'bus.c', - 'hotplug.c', 'qdev-properties.c', 'qdev.c', 'reset.c', @@ -11,8 +10,17 @@ 'irq.c', 'clock.c', 'qdev-clock.c', - 'qdev-hotplug.c', )) +if have_system + hwcore_ss.add(files( + 'hotplug.c', + 'qdev-hotplug.c', + )) +else + hwcore_ss.add(files( + 'hotplug-stubs.c', + )) +endif =20 common_ss.add(files('cpu-common.c')) softmmu_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) --=20 2.31.1 From nobody Sun Feb 8 23:42:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635792215; cv=none; d=zohomail.com; s=zohoarc; b=ES+yPIszADcz20cNGTk6SA+qWt4u4fMCroUnjGFuoYVkClyAwKJzoGhM1GyISNY6NmzrBGD9YmRNmJMd/hC/FMYniVwLGBNkZft542qJjbQ25QDvJTeLQKl3NSNQZ2q64gfVIMaZDYhwBDaAu2cZMVpRC8PCj3Y88+7mubKROXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635792215; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=euU/R1theKjT6dJ6MZK+iqP5pd5vFwd810oB/EoUuBg=; b=aB43JbnP+fWae+LUATFH+p41qsCMwyChAwi1xH7QngLHt6KftbmdvDkO9ONmQvy1EeBsQx73hSWLJfdzVVxzIMlLkfUtPM1rLRRzawquS0NM9EU9zUGgZ87YI5GDEUeiJskog7VhAxxvz4brsXSLWqw5YOShnDmsDtMwJuMiebM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 163579221533873.60590395886663; Mon, 1 Nov 2021 11:43:35 -0700 (PDT) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-31-x8nyla7xP5mCwpBMBM6vdg-1; Mon, 01 Nov 2021 14:43:33 -0400 Received: by mail-wm1-f72.google.com with SMTP id j193-20020a1c23ca000000b003306ae8bfb7so125672wmj.7 for ; Mon, 01 Nov 2021 11:43:32 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id l26sm314952wms.15.2021.11.01.11.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:43:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635792214; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=euU/R1theKjT6dJ6MZK+iqP5pd5vFwd810oB/EoUuBg=; b=hAJNNmcDfNsC6gbrsWHXm9J9wPYBqsiolgzNyyv9Gj13a0Xx3hbWJYYyYFDv0W2XyfIHDc oQmgF0TJ13WEEC8ZP1hG6xxph3GcjnhtlFYjT66SzBD5LVgJfv6UuAPxIDkOuvdZz5+LU2 u1fKL2bc78hGHZFm2vqAGiU/t4yhSPs= X-MC-Unique: x8nyla7xP5mCwpBMBM6vdg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=euU/R1theKjT6dJ6MZK+iqP5pd5vFwd810oB/EoUuBg=; b=PMJbHsiXCz2+6fA2RQpg2iAI36zAMxrXac3Xwho5l7CP4WEgvHhgmlrB433muQMBU8 BtbA2GnL0SJF/yS5IcoKpSD52gnrnNFzZ2AuIEwA6/K0zln6H5DvJ9j5ps+frAcfKsFO nNuyqwdR+jbBLR3TQQKMgvwKIqk8Z5QpXDw+XYT6M4pRT/AUTHD85MCd9sAI8H4XFQSP Gfn1/ljDOzNwR355oJ6x1hQ268t8KnvL9WJ/9ecBqZv7jEtbhf0eGjjNA//PJsCaUX9E fkt8ZVM1J/TiHEQou0a/LjgbnaGPe5hUZiQQzkwaGrEk6yMV4HZCUeEQUlBR4meyawi8 tzCA== X-Gm-Message-State: AOAM530c47YOJ6mDOmKKd7M//NcT4H17cyTeIt6E1ekkaWaCRKwZdpgA TF7Asv3YBjy6xXdFgBfRAQVP1qmlae4Qncfqe0D9fNWarHNCtQ0vTJDctJJ5m6x2pIZ2jo8ObCQ iOou4oTJNu0YBtw== X-Received: by 2002:adf:a2d4:: with SMTP id t20mr39931975wra.229.1635792211681; Mon, 01 Nov 2021 11:43:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyihhNw49t6ufRSX37zJzPNx+61qvWWf5NiBkpCdEF2U+kq6KT8EYdGjy/XfP9xFwBcJxpynQ== X-Received: by 2002:adf:a2d4:: with SMTP id t20mr39931925wra.229.1635792211298; Mon, 01 Nov 2021 11:43:31 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Marcel Apfelbaum , Yanan Wang , Andrew Jones Subject: [PULL 06/10] hw/core/machine: Split out the smp parsing code Date: Mon, 1 Nov 2021 19:42:55 +0100 Message-Id: <20211101184259.2859090-7-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211101184259.2859090-1-philmd@redhat.com> References: <20211101184259.2859090-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635792216889100001 From: Yanan Wang We are going to introduce an unit test for the parser smp_parse() in hw/core/machine.c, but now machine.c is only built in softmmu. In order to solve the build dependency on the smp parsing code and avoid building unrelated stuff for the unit tests, move the tested code from machine.c into a separate file, i.e., machine-smp.c and build it in common field. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20211026034659.22040-2-wangyanan55@huawei.com> Acked-by: Eduardo Habkost Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/boards.h | 1 + hw/core/machine-smp.c | 181 ++++++++++++++++++++++++++++++++++++++++++ hw/core/machine.c | 159 ------------------------------------- MAINTAINERS | 1 + hw/core/meson.build | 1 + 5 files changed, 184 insertions(+), 159 deletions(-) create mode 100644 hw/core/machine-smp.c diff --git a/include/hw/boards.h b/include/hw/boards.h index 5adbcbb99b1..e36fc7d8615 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -34,6 +34,7 @@ HotpluggableCPUList *machine_query_hotpluggable_cpus(Mach= ineState *machine); void machine_set_cpu_numa_node(MachineState *machine, const CpuInstanceProperties *props, Error **errp); +void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp); =20 /** * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devic= es diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c new file mode 100644 index 00000000000..116a0cbbfab --- /dev/null +++ b/hw/core/machine-smp.c @@ -0,0 +1,181 @@ +/* + * QEMU Machine core (related to -smp parsing) + * + * Copyright (c) 2021 Huawei Technologies Co., Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/boards.h" +#include "qapi/error.h" + +/* + * Report information of a machine's supported CPU topology hierarchy. + * Topology members will be ordered from the largest to the smallest + * in the string. + */ +static char *cpu_hierarchy_to_string(MachineState *ms) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + GString *s =3D g_string_new(NULL); + + g_string_append_printf(s, "sockets (%u)", ms->smp.sockets); + + if (mc->smp_props.dies_supported) { + g_string_append_printf(s, " * dies (%u)", ms->smp.dies); + } + + g_string_append_printf(s, " * cores (%u)", ms->smp.cores); + g_string_append_printf(s, " * threads (%u)", ms->smp.threads); + + return g_string_free(s, false); +} + +/* + * smp_parse - Generic function used to parse the given SMP configuration + * + * Any missing parameter in "cpus/maxcpus/sockets/cores/threads" will be + * automatically computed based on the provided ones. + * + * In the calculation of omitted sockets/cores/threads: we prefer sockets + * over cores over threads before 6.2, while preferring cores over sockets + * over threads since 6.2. + * + * In the calculation of cpus/maxcpus: When both maxcpus and cpus are omit= ted, + * maxcpus will be computed from the given parameters and cpus will be set + * equal to maxcpus. When only one of maxcpus and cpus is given then the + * omitted one will be set to its given counterpart's value. Both maxcpus = and + * cpus may be specified, but maxcpus must be equal to or greater than cpu= s. + * + * For compatibility, apart from the parameters that will be computed, new= ly + * introduced topology members which are likely to be target specific shou= ld + * be directly set as 1 if they are omitted (e.g. dies for PC since 4.1). + */ +void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + unsigned cpus =3D config->has_cpus ? config->cpus : 0; + unsigned sockets =3D config->has_sockets ? config->sockets : 0; + unsigned dies =3D config->has_dies ? config->dies : 0; + unsigned cores =3D config->has_cores ? config->cores : 0; + unsigned threads =3D config->has_threads ? config->threads : 0; + unsigned maxcpus =3D config->has_maxcpus ? config->maxcpus : 0; + + /* + * Specified CPU topology parameters must be greater than zero, + * explicit configuration like "cpus=3D0" is not allowed. + */ + if ((config->has_cpus && config->cpus =3D=3D 0) || + (config->has_sockets && config->sockets =3D=3D 0) || + (config->has_dies && config->dies =3D=3D 0) || + (config->has_cores && config->cores =3D=3D 0) || + (config->has_threads && config->threads =3D=3D 0) || + (config->has_maxcpus && config->maxcpus =3D=3D 0)) { + warn_report("Deprecated CPU topology (considered invalid): " + "CPU topology parameters must be greater than zero"); + } + + /* + * If not supported by the machine, a topology parameter must be + * omitted or specified equal to 1. + */ + if (!mc->smp_props.dies_supported && dies > 1) { + error_setg(errp, "dies not supported by this machine's CPU topolog= y"); + return; + } + + dies =3D dies > 0 ? dies : 1; + + /* compute missing values based on the provided ones */ + if (cpus =3D=3D 0 && maxcpus =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + cores =3D cores > 0 ? cores : 1; + threads =3D threads > 0 ? threads : 1; + } else { + maxcpus =3D maxcpus > 0 ? maxcpus : cpus; + + if (mc->smp_props.prefer_sockets) { + /* prefer sockets over cores before 6.2 */ + if (sockets =3D=3D 0) { + cores =3D cores > 0 ? cores : 1; + threads =3D threads > 0 ? threads : 1; + sockets =3D maxcpus / (dies * cores * threads); + } else if (cores =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + cores =3D maxcpus / (sockets * dies * threads); + } + } else { + /* prefer cores over sockets since 6.2 */ + if (cores =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + threads =3D threads > 0 ? threads : 1; + cores =3D maxcpus / (sockets * dies * threads); + } else if (sockets =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + sockets =3D maxcpus / (dies * cores * threads); + } + } + + /* try to calculate omitted threads at last */ + if (threads =3D=3D 0) { + threads =3D maxcpus / (sockets * dies * cores); + } + } + + maxcpus =3D maxcpus > 0 ? maxcpus : sockets * dies * cores * threads; + cpus =3D cpus > 0 ? cpus : maxcpus; + + ms->smp.cpus =3D cpus; + ms->smp.sockets =3D sockets; + ms->smp.dies =3D dies; + ms->smp.cores =3D cores; + ms->smp.threads =3D threads; + ms->smp.max_cpus =3D maxcpus; + + /* sanity-check of the computed topology */ + if (sockets * dies * cores * threads !=3D maxcpus) { + g_autofree char *topo_msg =3D cpu_hierarchy_to_string(ms); + error_setg(errp, "Invalid CPU topology: " + "product of the hierarchy must match maxcpus: " + "%s !=3D maxcpus (%u)", + topo_msg, maxcpus); + return; + } + + if (maxcpus < cpus) { + g_autofree char *topo_msg =3D cpu_hierarchy_to_string(ms); + error_setg(errp, "Invalid CPU topology: " + "maxcpus must be equal to or greater than smp: " + "%s =3D=3D maxcpus (%u) < smp_cpus (%u)", + topo_msg, maxcpus, cpus); + return; + } + + if (ms->smp.cpus < mc->min_cpus) { + error_setg(errp, "Invalid SMP CPUs %d. The min CPUs " + "supported by machine '%s' is %d", + ms->smp.cpus, + mc->name, mc->min_cpus); + return; + } + + if (ms->smp.max_cpus > mc->max_cpus) { + error_setg(errp, "Invalid SMP CPUs %d. The max CPUs " + "supported by machine '%s' is %d", + ms->smp.max_cpus, + mc->name, mc->max_cpus); + return; + } +} diff --git a/hw/core/machine.c b/hw/core/machine.c index b8d95eec32d..dc15f5f9e5c 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -749,165 +749,6 @@ void machine_set_cpu_numa_node(MachineState *machine, } } =20 -/* - * Report information of a machine's supported CPU topology hierarchy. - * Topology members will be ordered from the largest to the smallest - * in the string. - */ -static char *cpu_hierarchy_to_string(MachineState *ms) -{ - MachineClass *mc =3D MACHINE_GET_CLASS(ms); - GString *s =3D g_string_new(NULL); - - g_string_append_printf(s, "sockets (%u)", ms->smp.sockets); - - if (mc->smp_props.dies_supported) { - g_string_append_printf(s, " * dies (%u)", ms->smp.dies); - } - - g_string_append_printf(s, " * cores (%u)", ms->smp.cores); - g_string_append_printf(s, " * threads (%u)", ms->smp.threads); - - return g_string_free(s, false); -} - -/* - * smp_parse - Generic function used to parse the given SMP configuration - * - * Any missing parameter in "cpus/maxcpus/sockets/cores/threads" will be - * automatically computed based on the provided ones. - * - * In the calculation of omitted sockets/cores/threads: we prefer sockets - * over cores over threads before 6.2, while preferring cores over sockets - * over threads since 6.2. - * - * In the calculation of cpus/maxcpus: When both maxcpus and cpus are omit= ted, - * maxcpus will be computed from the given parameters and cpus will be set - * equal to maxcpus. When only one of maxcpus and cpus is given then the - * omitted one will be set to its given counterpart's value. Both maxcpus = and - * cpus may be specified, but maxcpus must be equal to or greater than cpu= s. - * - * For compatibility, apart from the parameters that will be computed, new= ly - * introduced topology members which are likely to be target specific shou= ld - * be directly set as 1 if they are omitted (e.g. dies for PC since 4.1). - */ -static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **= errp) -{ - MachineClass *mc =3D MACHINE_GET_CLASS(ms); - unsigned cpus =3D config->has_cpus ? config->cpus : 0; - unsigned sockets =3D config->has_sockets ? config->sockets : 0; - unsigned dies =3D config->has_dies ? config->dies : 0; - unsigned cores =3D config->has_cores ? config->cores : 0; - unsigned threads =3D config->has_threads ? config->threads : 0; - unsigned maxcpus =3D config->has_maxcpus ? config->maxcpus : 0; - - /* - * Specified CPU topology parameters must be greater than zero, - * explicit configuration like "cpus=3D0" is not allowed. - */ - if ((config->has_cpus && config->cpus =3D=3D 0) || - (config->has_sockets && config->sockets =3D=3D 0) || - (config->has_dies && config->dies =3D=3D 0) || - (config->has_cores && config->cores =3D=3D 0) || - (config->has_threads && config->threads =3D=3D 0) || - (config->has_maxcpus && config->maxcpus =3D=3D 0)) { - warn_report("Deprecated CPU topology (considered invalid): " - "CPU topology parameters must be greater than zero"); - } - - /* - * If not supported by the machine, a topology parameter must be - * omitted or specified equal to 1. - */ - if (!mc->smp_props.dies_supported && dies > 1) { - error_setg(errp, "dies not supported by this machine's CPU topolog= y"); - return; - } - - dies =3D dies > 0 ? dies : 1; - - /* compute missing values based on the provided ones */ - if (cpus =3D=3D 0 && maxcpus =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - } else { - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - - if (mc->smp_props.prefer_sockets) { - /* prefer sockets over cores before 6.2 */ - if (sockets =3D=3D 0) { - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - sockets =3D maxcpus / (dies * cores * threads); - } else if (cores =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - cores =3D maxcpus / (sockets * dies * threads); - } - } else { - /* prefer cores over sockets since 6.2 */ - if (cores =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - threads =3D threads > 0 ? threads : 1; - cores =3D maxcpus / (sockets * dies * threads); - } else if (sockets =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - sockets =3D maxcpus / (dies * cores * threads); - } - } - - /* try to calculate omitted threads at last */ - if (threads =3D=3D 0) { - threads =3D maxcpus / (sockets * dies * cores); - } - } - - maxcpus =3D maxcpus > 0 ? maxcpus : sockets * dies * cores * threads; - cpus =3D cpus > 0 ? cpus : maxcpus; - - ms->smp.cpus =3D cpus; - ms->smp.sockets =3D sockets; - ms->smp.dies =3D dies; - ms->smp.cores =3D cores; - ms->smp.threads =3D threads; - ms->smp.max_cpus =3D maxcpus; - - /* sanity-check of the computed topology */ - if (sockets * dies * cores * threads !=3D maxcpus) { - g_autofree char *topo_msg =3D cpu_hierarchy_to_string(ms); - error_setg(errp, "Invalid CPU topology: " - "product of the hierarchy must match maxcpus: " - "%s !=3D maxcpus (%u)", - topo_msg, maxcpus); - return; - } - - if (maxcpus < cpus) { - g_autofree char *topo_msg =3D cpu_hierarchy_to_string(ms); - error_setg(errp, "Invalid CPU topology: " - "maxcpus must be equal to or greater than smp: " - "%s =3D=3D maxcpus (%u) < smp_cpus (%u)", - topo_msg, maxcpus, cpus); - return; - } - - if (ms->smp.cpus < mc->min_cpus) { - error_setg(errp, "Invalid SMP CPUs %d. The min CPUs " - "supported by machine '%s' is %d", - ms->smp.cpus, - mc->name, mc->min_cpus); - return; - } - - if (ms->smp.max_cpus > mc->max_cpus) { - error_setg(errp, "Invalid SMP CPUs %d. The max CPUs " - "supported by machine '%s' is %d", - ms->smp.max_cpus, - mc->name, mc->max_cpus); - return; - } -} - static void machine_get_smp(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { diff --git a/MAINTAINERS b/MAINTAINERS index 894dc431052..80ec27d76ae 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1623,6 +1623,7 @@ F: cpu.c F: hw/core/cpu.c F: hw/core/machine-qmp-cmds.c F: hw/core/machine.c +F: hw/core/machine-smp.c F: hw/core/null-machine.c F: hw/core/numa.c F: hw/cpu/cluster.c diff --git a/hw/core/meson.build b/hw/core/meson.build index 7ec7bb93d5f..0f884d6fd4d 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -23,6 +23,7 @@ endif =20 common_ss.add(files('cpu-common.c')) +common_ss.add(files('machine-smp.c')) softmmu_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) softmmu_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: files('generic-load= er.c')) softmmu_ss.add(when: ['CONFIG_GUEST_LOADER', fdt], if_true: files('guest-l= oader.c')) --=20 2.31.1 From nobody Sun Feb 8 23:42:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635792220; cv=none; d=zohomail.com; s=zohoarc; b=fCjOKwKQoTNNpmxqkgPNBXIYrDmQ2BiYC1n9pHIC+DfoJw05GoD4wRElPRn+KPmfcAqVC1d5ACS3FkNpR8N6L+Q3hJUevm7NoCXyGT5rlcq61bP5JQOcpkgZVyrz79q3v2HCYOKgv6nyngjhJWFgsBpli+5QWwk+t2/e11/a3x8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635792220; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=/h0darTf513WPkfexGnPhY2VjdovSQxyXVgcl2pMqi8=; b=bw4qOcvBAZ5WriHPRmIrNEMo2IvL8C7vxQ4GxA2xmZqTAPn8wrw6PXIQG8p5OPiA/aKErrlDbZjKxjxULY+c0yd7QBku3yyOHKeliKFV1Akz82ss8TRBnHoxaWpFSZPfKyOv1h14Qf8fgi3I/eIAvVGdS4EEJBtSx3Q/u5tMOsI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1635792220469625.6026532648086; Mon, 1 Nov 2021 11:43:40 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-596-V-s91zLfPvSKoB6ao5kYYw-1; Mon, 01 Nov 2021 14:43:38 -0400 Received: by mail-wm1-f70.google.com with SMTP id m1-20020a1ca301000000b003231d5b3c4cso50420wme.5 for ; Mon, 01 Nov 2021 11:43:37 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id 10sm345396wme.27.2021.11.01.11.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635792219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/h0darTf513WPkfexGnPhY2VjdovSQxyXVgcl2pMqi8=; b=UgP61SIvLWjAmdLyqs3Zfh7fly9IfsnJZI27oWaSHL0voA4D1Spfj0Oc+U+Yo923BD37x5 g3ysFK47gPPB5PsH3tx5nP4ycWQay3XE6+A7EIxgoNJ89Owm9gGcg3oVZnVXFa9c7X5eG1 nulc9OVI59NGI030+nX2HGYcDsEtTpU= X-MC-Unique: V-s91zLfPvSKoB6ao5kYYw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/h0darTf513WPkfexGnPhY2VjdovSQxyXVgcl2pMqi8=; b=TTJu2NDv41x0iGbb2OCjoZiaBlvhGepbbeyf72znIfvlIgB2vAWH0AS3FPybSAOAlr hzn0Z7Sf/MDVbd6SB2rNOmcVCUks8TqfPJ7CNT5mtugzwHMPVaSH3DM0F2QEmm/508fG 08FFj2fQLUSwFPrf3ie/cAdIbVpFK38Dmw+7xfueGIcCR0hakWbtSr0NepAFaZgek5jC R41NRKiedOxPgmtDG1UyDdjW7CODVPX/xkx3Yh0ZPBCQosYO9ftyi0DrHeAgTIhY8od+ kovz/D7PqB71BVtZRUsKQbe2S9CXZiF4khilytr590KeyYmTNGtMnJu77kTT/UKnKGnU /kqg== X-Gm-Message-State: AOAM532OHk9c3AB309uymnf84fEmSLQdtkpdPZYYToOqNt6ELpvnLDCm S0EhEVFzpIvy6mqQIP6u/CVtf7Rm7a5brQYxTKwtBEOPOyqARmQjt+TguSbgpoO38BcqD1A5X0o MrrCm++Cybf7XQg== X-Received: by 2002:a05:600c:1d06:: with SMTP id l6mr716026wms.97.1635792216402; Mon, 01 Nov 2021 11:43:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztdU5aHWPvsJkmmBuSl7DVTF1SEzIfJiA035/X8zBrReugZT3oLcZkXpv17/DxDraPnR0+JA== X-Received: by 2002:a05:600c:1d06:: with SMTP id l6mr715981wms.97.1635792216067; Mon, 01 Nov 2021 11:43:36 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Marcel Apfelbaum , Yanan Wang , Andrew Jones Subject: [PULL 07/10] tests/unit: Add an unit test for smp parsing Date: Mon, 1 Nov 2021 19:42:56 +0100 Message-Id: <20211101184259.2859090-8-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211101184259.2859090-1-philmd@redhat.com> References: <20211101184259.2859090-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635792221348100001 From: Yanan Wang Now that we have a generic parser smp_parse(), let's add an unit test for the code. All possible valid/invalid SMP configurations that the user can specify are covered. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones Tested-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20211026034659.22040-3-wangyanan55@huawei.com> Acked-by: Eduardo Habkost Message-Id: [PMD: Squashed format string fixup from Yanan Wang] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- tests/unit/test-smp-parse.c | 594 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + tests/unit/meson.build | 1 + 3 files changed, 596 insertions(+) create mode 100644 tests/unit/test-smp-parse.c diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c new file mode 100644 index 00000000000..cbe0c990494 --- /dev/null +++ b/tests/unit/test-smp-parse.c @@ -0,0 +1,594 @@ +/* + * SMP parsing unit-tests + * + * Copyright (c) 2021 Huawei Technologies Co., Ltd + * + * Authors: + * Yanan Wang + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or l= ater. + * See the COPYING.LIB file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qom/object.h" +#include "qemu/module.h" +#include "qapi/error.h" + +#include "hw/boards.h" + +#define T true +#define F false + +#define MIN_CPUS 1 /* set the min CPUs supported by the machine as 1 */ +#define MAX_CPUS 512 /* set the max CPUs supported by the machine as 512 */ + +/* + * Used to define the generic 3-level CPU topology hierarchy + * -sockets/cores/threads + */ +#define SMP_CONFIG_GENERIC(ha, a, hb, b, hc, c, hd, d, he, e) \ + { \ + .has_cpus =3D ha, .cpus =3D a, \ + .has_sockets =3D hb, .sockets =3D b, \ + .has_cores =3D hc, .cores =3D c, \ + .has_threads =3D hd, .threads =3D d, \ + .has_maxcpus =3D he, .maxcpus =3D e, \ + } + +#define CPU_TOPOLOGY_GENERIC(a, b, c, d, e) \ + { \ + .cpus =3D a, \ + .sockets =3D b, \ + .cores =3D c, \ + .threads =3D d, \ + .max_cpus =3D e, \ + } + +/* + * Currently a 4-level topology hierarchy is supported on PC machines + * -sockets/dies/cores/threads + */ +#define SMP_CONFIG_WITH_DIES(ha, a, hb, b, hc, c, hd, d, he, e, hf, f) \ + { \ + .has_cpus =3D ha, .cpus =3D a, \ + .has_sockets =3D hb, .sockets =3D b, \ + .has_dies =3D hc, .dies =3D c, \ + .has_cores =3D hd, .cores =3D d, \ + .has_threads =3D he, .threads =3D e, \ + .has_maxcpus =3D hf, .maxcpus =3D f, \ + } + +/** + * @config - the given SMP configuration + * @expect_prefer_sockets - the expected parsing result for the + * valid configuration, when sockets are preferred over cores + * @expect_prefer_cores - the expected parsing result for the + * valid configuration, when cores are preferred over sockets + * @expect_error - the expected error report when the given + * configuration is invalid + */ +typedef struct SMPTestData { + SMPConfiguration config; + CpuTopology expect_prefer_sockets; + CpuTopology expect_prefer_cores; + const char *expect_error; +} SMPTestData; + +/* Type info of the tested machine */ +static const TypeInfo smp_machine_info =3D { + .name =3D TYPE_MACHINE, + .parent =3D TYPE_OBJECT, + .class_size =3D sizeof(MachineClass), + .instance_size =3D sizeof(MachineState), +}; + +/* + * List all the possible valid sub-collections of the generic 5 + * topology parameters (i.e. cpus/maxcpus/sockets/cores/threads), + * then test the automatic calculation algorithm of the missing + * values in the parser. + */ +static struct SMPTestData data_generic_valid[] =3D { + { + /* config: no configuration provided + * expect: cpus=3D1,sockets=3D1,cores=3D1,threads=3D1,maxcpus=3D1 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, F, 0, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(1, 1, 1, 1, 1), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(1, 1, 1, 1, 1), + }, { + /* config: -smp 8 + * prefer_sockets: cpus=3D8,sockets=3D8,cores=3D1,threads=3D1,maxc= pus=3D8 + * prefer_cores: cpus=3D8,sockets=3D1,cores=3D8,threads=3D1,maxcpu= s=3D8 */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, F, 0, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 8, 1, 1, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 1, 8, 1, 8), + }, { + /* config: -smp sockets=3D2 + * expect: cpus=3D2,sockets=3D2,cores=3D1,threads=3D1,maxcpus=3D2 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, F, 0, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(2, 2, 1, 1, 2), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(2, 2, 1, 1, 2), + }, { + /* config: -smp cores=3D4 + * expect: cpus=3D4,sockets=3D1,cores=3D4,threads=3D1,maxcpus=3D4 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, T, 4, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(4, 1, 4, 1, 4), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(4, 1, 4, 1, 4), + }, { + /* config: -smp threads=3D2 + * expect: cpus=3D2,sockets=3D1,cores=3D1,threads=3D2,maxcpus=3D2 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, F, 0, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(2, 1, 1, 2, 2), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(2, 1, 1, 2, 2), + }, { + /* config: -smp maxcpus=3D16 + * prefer_sockets: cpus=3D16,sockets=3D16,cores=3D1,threads=3D1,ma= xcpus=3D16 + * prefer_cores: cpus=3D16,sockets=3D1,cores=3D16,threads=3D1,maxc= pus=3D16 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, F, 0, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 16, 1, 1, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 1, 16, 1, 16), + }, { + /* config: -smp 8,sockets=3D2 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D1,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, F, 0, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + }, { + /* config: -smp 8,cores=3D4 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D1,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, T, 4, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + }, { + /* config: -smp 8,threads=3D2 + * prefer_sockets: cpus=3D8,sockets=3D4,cores=3D1,threads=3D2,maxc= pus=3D8 + * prefer_cores: cpus=3D8,sockets=3D1,cores=3D4,threads=3D2,maxcpu= s=3D8 */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, F, 0, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 4, 1, 2, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 1, 4, 2, 8), + }, { + /* config: -smp 8,maxcpus=3D16 + * prefer_sockets: cpus=3D8,sockets=3D16,cores=3D1,threads=3D1,max= cpus=3D16 + * prefer_cores: cpus=3D8,sockets=3D1,cores=3D16,threads=3D1,maxcp= us=3D16 */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, F, 0, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 16, 1, 1, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 1, 16, 1, 16), + }, { + /* config: -smp sockets=3D2,cores=3D4 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D1,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, T, 4, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + }, { + /* config: -smp sockets=3D2,threads=3D2 + * expect: cpus=3D4,sockets=3D2,cores=3D1,threads=3D2,maxcpus=3D4 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, F, 0, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(4, 2, 1, 2, 4), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(4, 2, 1, 2, 4), + }, { + /* config: -smp sockets=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,cores=3D8,threads=3D1,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, F, 0, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 2, 8, 1, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 2, 8, 1, 16), + }, { + /* config: -smp cores=3D4,threads=3D2 + * expect: cpus=3D8,sockets=3D1,cores=3D4,threads=3D2,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, T, 4, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 1, 4, 2, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 1, 4, 2, 8), + }, { + /* config: -smp cores=3D4,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D4,cores=3D4,threads=3D1,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, T, 4, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 4, 4, 1, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 4, 4, 1, 16), + }, { + /* config: -smp threads=3D2,maxcpus=3D16 + * prefer_sockets: cpus=3D16,sockets=3D8,cores=3D1,threads=3D2,max= cpus=3D16 + * prefer_cores: cpus=3D16,sockets=3D1,cores=3D8,threads=3D2,maxcp= us=3D16 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, F, 0, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 8, 1, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 1, 8, 2, 16), + }, { + /* config: -smp 8,sockets=3D2,cores=3D4 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D1,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, T, 4, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + }, { + /* config: -smp 8,sockets=3D2,threads=3D2 + * expect: cpus=3D8,sockets=3D2,cores=3D2,threads=3D2,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, F, 0, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 2, 2, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 2, 2, 8), + }, { + /* config: -smp 8,sockets=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,cores=3D8,threads=3D1,maxcpus=3D16= */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, F, 0, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 8, 1, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 8, 1, 16), + }, { + /* config: -smp 8,cores=3D4,threads=3D2 + * expect: cpus=3D8,sockets=3D1,cores=3D4,threads=3D2,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, T, 4, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 1, 4, 2, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 1, 4, 2, 8), + }, { + /* config: -smp 8,cores=3D4,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D4,cores=3D4,threads=3D1,maxcpus=3D16= */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, T, 4, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 4, 4, 1, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 4, 4, 1, 16), + }, { + /* config: -smp 8,threads=3D2,maxcpus=3D16 + * prefer_sockets: cpus=3D8,sockets=3D8,cores=3D1,threads=3D2,maxc= pus=3D16 + * prefer_cores: cpus=3D8,sockets=3D1,cores=3D8,threads=3D2,maxcpu= s=3D16 */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, F, 0, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 8, 1, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 1, 8, 2, 16), + }, { + /* config: -smp sockets=3D2,cores=3D4,threads=3D2 + * expect: cpus=3D16,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, T, 4, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + }, { + /* config: -smp sockets=3D2,cores=3D4,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, T, 4, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + }, { + /* config: -smp sockets=3D2,threads=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, F, 0, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + }, { + /* config: -smp cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, T, 4, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,threads=3D1 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D1,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, T, 4, T, 1, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16= */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, T, 4, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + }, { + /* config: -smp 8,sockets=3D2,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16= */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, F, 0, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + }, { + /* config: -smp 8,cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16= */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, T, 4, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + }, { + /* config: -smp sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, T, 4, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16= */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, T, 4, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + }, +}; + +static struct SMPTestData data_generic_invalid[] =3D { + { + /* config: -smp 2,dies=3D2 */ + .config =3D SMP_CONFIG_WITH_DIES(T, 2, F, 0, T, 2, F, 0, F, 0, F, = 0), + .expect_error =3D "dies not supported by this machine's CPU topolo= gy", + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D8 */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, T, 4, T, 2, T, 8), + .expect_error =3D "Invalid CPU topology: " + "product of the hierarchy must match maxcpus: " + "sockets (2) * cores (4) * threads (2) " + "!=3D maxcpus (8)", + }, { + /* config: -smp 18,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16 = */ + .config =3D SMP_CONFIG_GENERIC(T, 18, T, 2, T, 4, T, 2, T, 16), + .expect_error =3D "Invalid CPU topology: " + "maxcpus must be equal to or greater than smp: " + "sockets (2) * cores (4) * threads (2) " + "=3D=3D maxcpus (16) < smp_cpus (18)", + }, { + /* config: -smp 1 + * should tweak the supported min CPUs to 2 for testing */ + .config =3D SMP_CONFIG_GENERIC(T, 1, F, 0, F, 0, F, 0, F, 0), + .expect_error =3D "Invalid SMP CPUs 1. The min CPUs supported " + "by machine '(null)' is 2", + }, { + /* config: -smp 512 + * should tweak the supported max CPUs to 511 for testing */ + .config =3D SMP_CONFIG_GENERIC(T, 512, F, 0, F, 0, F, 0, F, 0), + .expect_error =3D "Invalid SMP CPUs 512. The max CPUs supported " + "by machine '(null)' is 511", + }, +}; + +static struct SMPTestData data_with_dies_invalid[] =3D { + { + /* config: -smp 16,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,maxc= pus=3D16 */ + .config =3D SMP_CONFIG_WITH_DIES(T, 16, T, 2, T, 2, T, 4, T, 2, T,= 16), + .expect_error =3D "Invalid CPU topology: " + "product of the hierarchy must match maxcpus: " + "sockets (2) * dies (2) * cores (4) * threads (2) " + "!=3D maxcpus (16)", + }, { + /* config: -smp 34,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,maxc= pus=3D32 */ + .config =3D SMP_CONFIG_WITH_DIES(T, 34, T, 2, T, 2, T, 4, T, 2, T,= 32), + .expect_error =3D "Invalid CPU topology: " + "maxcpus must be equal to or greater than smp: " + "sockets (2) * dies (2) * cores (4) * threads (2) " + "=3D=3D maxcpus (32) < smp_cpus (34)", + }, +}; + +static char *smp_config_to_string(SMPConfiguration *config) +{ + return g_strdup_printf( + "(SMPConfiguration) {\n" + " .has_cpus =3D %5s, cpus =3D %" PRId64 ",\n" + " .has_sockets =3D %5s, sockets =3D %" PRId64 ",\n" + " .has_dies =3D %5s, dies =3D %" PRId64 ",\n" + " .has_cores =3D %5s, cores =3D %" PRId64 ",\n" + " .has_threads =3D %5s, threads =3D %" PRId64 ",\n" + " .has_maxcpus =3D %5s, maxcpus =3D %" PRId64 ",\n" + "}", + config->has_cpus ? "true" : "false", config->cpus, + config->has_sockets ? "true" : "false", config->sockets, + config->has_dies ? "true" : "false", config->dies, + config->has_cores ? "true" : "false", config->cores, + config->has_threads ? "true" : "false", config->threads, + config->has_maxcpus ? "true" : "false", config->maxcpus); +} + +static char *cpu_topology_to_string(CpuTopology *topo) +{ + return g_strdup_printf( + "(CpuTopology) {\n" + " .cpus =3D %u,\n" + " .sockets =3D %u,\n" + " .dies =3D %u,\n" + " .cores =3D %u,\n" + " .threads =3D %u,\n" + " .max_cpus =3D %u,\n" + "}", + topo->cpus, topo->sockets, topo->dies, + topo->cores, topo->threads, topo->max_cpus); +} + +static void check_parse(MachineState *ms, SMPConfiguration *config, + CpuTopology *expect_topo, const char *expect_err, + bool is_valid) +{ + g_autofree char *config_str =3D smp_config_to_string(config); + g_autofree char *expect_topo_str =3D cpu_topology_to_string(expect_top= o); + g_autofree char *output_topo_str =3D NULL; + Error *err =3D NULL; + + /* call the generic parser smp_parse() */ + smp_parse(ms, config, &err); + + output_topo_str =3D cpu_topology_to_string(&ms->smp); + + /* when the configuration is supposed to be valid */ + if (is_valid) { + if ((err =3D=3D NULL) && + (ms->smp.cpus =3D=3D expect_topo->cpus) && + (ms->smp.sockets =3D=3D expect_topo->sockets) && + (ms->smp.dies =3D=3D expect_topo->dies) && + (ms->smp.cores =3D=3D expect_topo->cores) && + (ms->smp.threads =3D=3D expect_topo->threads) && + (ms->smp.max_cpus =3D=3D expect_topo->max_cpus)) { + return; + } + + if (err !=3D NULL) { + g_printerr("Test smp_parse failed!\n" + "Input configuration: %s\n" + "Should be valid: yes\n" + "Expected topology: %s\n\n" + "Result is valid: no\n" + "Output error report: %s\n", + config_str, expect_topo_str, error_get_pretty(err)); + goto end; + } + + g_printerr("Test smp_parse failed!\n" + "Input configuration: %s\n" + "Should be valid: yes\n" + "Expected topology: %s\n\n" + "Result is valid: yes\n" + "Output topology: %s\n", + config_str, expect_topo_str, output_topo_str); + goto end; + } + + /* when the configuration is supposed to be invalid */ + if (err !=3D NULL) { + if (expect_err =3D=3D NULL || + g_str_equal(expect_err, error_get_pretty(err))) { + error_free(err); + return; + } + + g_printerr("Test smp_parse failed!\n" + "Input configuration: %s\n" + "Should be valid: no\n" + "Expected error report: %s\n\n" + "Result is valid: no\n" + "Output error report: %s\n", + config_str, expect_err, error_get_pretty(err)); + goto end; + } + + g_printerr("Test smp_parse failed!\n" + "Input configuration: %s\n" + "Should be valid: no\n" + "Expected error report: %s\n\n" + "Result is valid: yes\n" + "Output topology: %s\n", + config_str, expect_err, output_topo_str); + +end: + if (err !=3D NULL) { + error_free(err); + } + + abort(); +} + +static void smp_parse_test(MachineState *ms, SMPTestData *data, bool is_va= lid) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + + mc->smp_props.prefer_sockets =3D true; + check_parse(ms, &data->config, &data->expect_prefer_sockets, + data->expect_error, is_valid); + + mc->smp_props.prefer_sockets =3D false; + check_parse(ms, &data->config, &data->expect_prefer_cores, + data->expect_error, is_valid); +} + +/* The parsed results of the unsupported parameters should be 1 */ +static void unsupported_params_init(MachineClass *mc, SMPTestData *data) +{ + if (!mc->smp_props.dies_supported) { + data->expect_prefer_sockets.dies =3D 1; + data->expect_prefer_cores.dies =3D 1; + } +} + +/* Reset the related machine properties before each sub-test */ +static void smp_machine_class_init(MachineClass *mc) +{ + mc->min_cpus =3D MIN_CPUS; + mc->max_cpus =3D MAX_CPUS; + + mc->smp_props.prefer_sockets =3D true; + mc->smp_props.dies_supported =3D false; +} + +static void test_generic(void) +{ + Object *obj =3D object_new(TYPE_MACHINE); + MachineState *ms =3D MACHINE(obj); + MachineClass *mc =3D MACHINE_GET_CLASS(obj); + SMPTestData *data =3D &(SMPTestData){{ }}; + int i; + + smp_machine_class_init(mc); + + for (i =3D 0; i < ARRAY_SIZE(data_generic_valid); i++) { + *data =3D data_generic_valid[i]; + unsupported_params_init(mc, data); + + smp_parse_test(ms, data, true); + + /* Unsupported parameters can be provided with their values as 1 */ + data->config.has_dies =3D true; + data->config.dies =3D 1; + smp_parse_test(ms, data, true); + } + + /* Reset the supported min CPUs and max CPUs */ + mc->min_cpus =3D 2; + mc->max_cpus =3D 511; + + for (i =3D 0; i < ARRAY_SIZE(data_generic_invalid); i++) { + *data =3D data_generic_invalid[i]; + unsupported_params_init(mc, data); + + smp_parse_test(ms, data, false); + } + + object_unref(obj); +} + +static void test_with_dies(void) +{ + Object *obj =3D object_new(TYPE_MACHINE); + MachineState *ms =3D MACHINE(obj); + MachineClass *mc =3D MACHINE_GET_CLASS(obj); + SMPTestData *data =3D &(SMPTestData){{ }}; + unsigned int num_dies =3D 2; + int i; + + smp_machine_class_init(mc); + mc->smp_props.dies_supported =3D true; + + for (i =3D 0; i < ARRAY_SIZE(data_generic_valid); i++) { + *data =3D data_generic_valid[i]; + unsupported_params_init(mc, data); + + /* when dies parameter is omitted, it will be set as 1 */ + data->expect_prefer_sockets.dies =3D 1; + data->expect_prefer_cores.dies =3D 1; + + smp_parse_test(ms, data, true); + + /* when dies parameter is specified */ + data->config.has_dies =3D true; + data->config.dies =3D num_dies; + if (data->config.has_cpus) { + data->config.cpus *=3D num_dies; + } + if (data->config.has_maxcpus) { + data->config.maxcpus *=3D num_dies; + } + + data->expect_prefer_sockets.dies =3D num_dies; + data->expect_prefer_sockets.cpus *=3D num_dies; + data->expect_prefer_sockets.max_cpus *=3D num_dies; + data->expect_prefer_cores.dies =3D num_dies; + data->expect_prefer_cores.cpus *=3D num_dies; + data->expect_prefer_cores.max_cpus *=3D num_dies; + + smp_parse_test(ms, data, true); + } + + for (i =3D 0; i < ARRAY_SIZE(data_with_dies_invalid); i++) { + *data =3D data_with_dies_invalid[i]; + unsupported_params_init(mc, data); + + smp_parse_test(ms, data, false); + } + + object_unref(obj); +} + +int main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); + + module_call_init(MODULE_INIT_QOM); + type_register_static(&smp_machine_info); + + g_test_add_func("/test-smp-parse/generic", test_generic); + g_test_add_func("/test-smp-parse/with_dies", test_with_dies); + + g_test_run(); + + return 0; +} diff --git a/MAINTAINERS b/MAINTAINERS index 80ec27d76ae..310a9512ea1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1633,6 +1633,7 @@ F: include/hw/boards.h F: include/hw/core/cpu.h F: include/hw/cpu/cluster.h F: include/sysemu/numa.h +F: tests/unit/test-smp-parse.c T: git https://gitlab.com/ehabkost/qemu.git machine-next =20 Xtensa Machines diff --git a/tests/unit/meson.build b/tests/unit/meson.build index 5ac2d9e9431..acac3622edc 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -46,6 +46,7 @@ 'test-uuid': [], 'ptimer-test': ['ptimer-test-stubs.c', meson.project_source_root() / 'hw= /core/ptimer.c'], 'test-qapi-util': [], + 'test-smp-parse': [qom, meson.project_source_root() / 'hw/core/machine-s= mp.c'], } =20 if have_system or have_tools --=20 2.31.1 From nobody Sun Feb 8 23:42:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635792224; cv=none; d=zohomail.com; s=zohoarc; b=LhKDj4+SX9jc8sTHJlQXClV8/8vTJG7hPh8VFgwHwm2yhzousYE2xH71p0/4wyTAjUhNOBtzMHygC/b4iwljBcdgsdvPNue8FLskLfZgmpEcUVbRH6JKLU7YuAzHmnhI8v0PjE8a3nnt+FLYsKK+pJ4tFVgED9iQwxoBnVpYyXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635792224; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=0YpUHkH8QkEwzNTR61Yyssu2TGxSWXI2GUicTQR5x2E=; b=bdtMlIMVO8BLVt/HvRd0a34qEIj/4m8RFsRHfeVxJhoYEKtxtJRQI+rh2+H5ys+p7zZVj20hUrWuetCjUpmYXQjyQeYZsUaHOYfhg/i/WolRgE39WlrIgtkeXMVZAHHY2yLgx+GB6/B1Mdx8XKk0n0XNtO+R8K9wZr4YNEQHeAY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 16357922248531010.2089834258815; Mon, 1 Nov 2021 11:43:44 -0700 (PDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-515-nl8i9qaZPRKvalwILEGjqQ-1; Mon, 01 Nov 2021 14:43:42 -0400 Received: by mail-wr1-f69.google.com with SMTP id r21-20020adfa155000000b001608162e16dso6494693wrr.15 for ; Mon, 01 Nov 2021 11:43:42 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id j40sm286137wms.16.2021.11.01.11.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635792223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0YpUHkH8QkEwzNTR61Yyssu2TGxSWXI2GUicTQR5x2E=; b=dW3S/xsW3Nhpx9gJyz2xjOv/aeZPIyPLnBdq3+AY2EhEZ/NVx82qu5laWDcJWxXGdp6Q1H DJYcDPN9c0naamF7s3/6o8hvYBvYDSNe4WA1P752NkkZs2NdJN6FS1CLlY+ZG+kdJTaPHI KW7xnyqwZn2w8ehdmDyoXRXXfxjigcY= X-MC-Unique: nl8i9qaZPRKvalwILEGjqQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0YpUHkH8QkEwzNTR61Yyssu2TGxSWXI2GUicTQR5x2E=; b=yqMJr6VD+LOXMpPe3BWFKWx0tlTdP7ZCN34n24VDqKdvMHfZzhze1inbDQOUNJYi8C 1JsuYku+JVenwrSkDsp8bxJ27ZIEEmsV8TZHVpZAIguDbDK3D3Tkxez6SNnibcGbra8a pdNcq8WM1BODm/bB2BBv+Ngi+uOoVNuqKXebUUx3yPdbmwRa4YibHDBgAoIsd9LzAel0 Lfuyt9hRMbu9oWsLWQCXP3oeJ7+vRUDT8Ar+4UM6RvUL1j5R8czgamOxROrVFR8r8S6Y 08/fk73kopX9Aus5xoMcaBJhBpS8xMZljaDutE3IKMFkApYxsG2P/IG6/2KU3f4YaTWB O43A== X-Gm-Message-State: AOAM5335J3cX/ZhRYulkbCyR89xiLeBxEgbQApjGy+9Z8VOQALyFXwbt F0MzPUjlrbFBkcZbQxWh4M4F8LP9Ygv7HXquijbd73GVTdJRxBaOPjSTcBNobeX7s2Ohp5t++TR smm4KD8qKvPO7CA== X-Received: by 2002:a5d:4a46:: with SMTP id v6mr39073528wrs.262.1635792221193; Mon, 01 Nov 2021 11:43:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy96s9T2qC8MqXugO/zZLgnIT6dX4xTBLgmQxzVTNY8vxctATLUEnprd1PTV1LM4aY6TbGxnA== X-Received: by 2002:a5d:4a46:: with SMTP id v6mr39073499wrs.262.1635792220987; Mon, 01 Nov 2021 11:43:40 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Marcel Apfelbaum , Damien Hedde , Alistair Francis Subject: [PULL 08/10] machine: add device_type_is_dynamic_sysbus function Date: Mon, 1 Nov 2021 19:42:57 +0100 Message-Id: <20211101184259.2859090-9-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211101184259.2859090-1-philmd@redhat.com> References: <20211101184259.2859090-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635792226012100001 From: Damien Hedde Right now the allowance check for adding a sysbus device using -device cli option (or device_add qmp command) is done well after the device has been created. It is done during the machine init done notifier: machine_init_notify() in hw/core/machine.c This new function will allow us to do the check at the right time and issue an error if it fails. Also make device_is_dynamic_sysbus() use the new function. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Acked-by: Eduardo Habkost Message-Id: <20211029142258.484907-2-damien.hedde@greensocs.com> Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/boards.h | 15 +++++++++++++++ hw/core/machine.c | 13 ++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/hw/boards.h b/include/hw/boards.h index e36fc7d8615..602993bd5ab 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -52,6 +52,21 @@ void smp_parse(MachineState *ms, SMPConfiguration *confi= g, Error **errp); */ void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *= type); =20 +/** + * device_type_is_dynamic_sysbus: Check if type is an allowed sysbus device + * type for the machine class. + * @mc: Machine class + * @type: type to check (should be a subtype of TYPE_SYS_BUS_DEVICE) + * + * Returns: true if @type is a type in the machine's list of + * dynamically pluggable sysbus devices; otherwise false. + * + * Check if the QOM type @type is in the list of allowed sysbus device + * types (see machine_class_allowed_dynamic_sysbus_dev()). + * Note that if @type has a parent type in the list, it is allowed too. + */ +bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type); + /** * device_is_dynamic_sysbus: test whether device is a dynamic sysbus device * @mc: Machine class diff --git a/hw/core/machine.c b/hw/core/machine.c index dc15f5f9e5c..7c4004ac5a0 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -548,18 +548,25 @@ void machine_class_allow_dynamic_sysbus_dev(MachineCl= ass *mc, const char *type) =20 bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev) { - bool allowed =3D false; - strList *wl; Object *obj =3D OBJECT(dev); =20 if (!object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE)) { return false; } =20 + return device_type_is_dynamic_sysbus(mc, object_get_typename(obj)); +} + +bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type) +{ + bool allowed =3D false; + strList *wl; + ObjectClass *klass =3D object_class_by_name(type); + for (wl =3D mc->allowed_dynamic_sysbus_devices; !allowed && wl; wl =3D wl->next) { - allowed |=3D !!object_dynamic_cast(obj, wl->value); + allowed |=3D !!object_class_dynamic_cast(klass, wl->value); } =20 return allowed; --=20 2.31.1 From nobody Sun Feb 8 23:42:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635792228; cv=none; d=zohomail.com; s=zohoarc; b=hPwHj9wwo/BIgG0cCUzq+/9JVFECRPBDLA8dYKKjWYqGyjEZ9Ye5ihUjdK1oAtZx3mCn/R3Qa3a7AFKfWpuNK8ZrF4LfYWzkfy40f1jeZ/gAxpzWkKP0pcgv3kGURQgmW3gst+sSQvJ2Aj4FXaDUtmmVj8mHW9wPwk3bM9Lg7+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635792228; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=wrRJbxTfXKoNE9RhSD+9rCBC0L1fCrHGd+SeOdkp/14=; b=MlOzVdVaGKbivEmYfLEJQekGHlkl3xMHwgNo9+/eQE9IZgkxxwYCd+TKnn5Z7gNm7Bq6Wk7bMg7JqFnsduxo6vyoF5TGRQsifm7UqEeBfgztOD3RNIXgty5L1ULfxgOdamQ79yO9gIsOwHpeS/1QCcgkG3TJXhBWifND4BTuT1M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 163579222896314.932150986269335; Mon, 1 Nov 2021 11:43:48 -0700 (PDT) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-586-Kma0uXH0Me2UvzfY7CrWSw-1; Mon, 01 Nov 2021 14:43:46 -0400 Received: by mail-wm1-f69.google.com with SMTP id m1-20020a1ca301000000b003231d5b3c4cso50553wme.5 for ; Mon, 01 Nov 2021 11:43:46 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id u16sm275280wmc.21.2021.11.01.11.43.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:43:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635792228; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wrRJbxTfXKoNE9RhSD+9rCBC0L1fCrHGd+SeOdkp/14=; b=Wl6vIytR1dLYwH7oMrX8MdoM05i1HhKrwF8uh7mIjgF1X7UJ/LJnoxFHzRkGpaOU1fEP0I Pkbm/zLJhDqvTUzqHd2tnpG+UIUIIcrWklQaCOlzWg1qGK50LTNRS6TEDQWCclPd21Ovxm i8hcScd/amiC3Jed4uajZb7JltKB7l0= X-MC-Unique: Kma0uXH0Me2UvzfY7CrWSw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wrRJbxTfXKoNE9RhSD+9rCBC0L1fCrHGd+SeOdkp/14=; b=4BAQWisw29K2TFO7aVQqKA5aBbL1gvpYPNJeytmMfiPTWVWHsg+85S4/LnvjujQ0fx OHKGKq34SpBPF0f0KYv4h3qRv3/8OJuea/pXDeVUK6FnXGXJKZGSAPe3OACu+ghZJg8J 95hA4z5FOf53mvHnHkYVvejwGkgCC/yVt/PX21aNUiD07BwtP2kSye+EAw0Yg+LTOaXf mTe0wyZhBbvWYxYVLiqGaMcXo8r9fEZdLKN9hNJ5Z2sr29zbKzHeBnfbg6K1VHpEojZF LX4dm1jjnYhQ4zNSp5Fpd7iXYsIPTLdlq3vN64cywjxRRbkpZYRb60b26/lEYeoy5ozP 7Wpg== X-Gm-Message-State: AOAM530NMsm1H0zuygvxCBS+r4kJj/N0ErbAvL2A9TEg2NuSquH3WtlU qISmE+Yg6ZhImYfdD67aWsJNInUCOtjjuIvYZUbuNVizl9FQXPees6k66KNZxv27Mn4oGbZ2ioA 67DQ533EvPtKpZA== X-Received: by 2002:a5d:6a4d:: with SMTP id t13mr11122612wrw.104.1635792225735; Mon, 01 Nov 2021 11:43:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2utyBz54X2ezIzxsjFjSLvMDAbTQkGqrOuc8GVm1HB/EpzH9jSQ7tuQC1VbotVp26ooV79w== X-Received: by 2002:a5d:6a4d:: with SMTP id t13mr11122591wrw.104.1635792225597; Mon, 01 Nov 2021 11:43:45 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Marcel Apfelbaum , Damien Hedde , Alistair Francis Subject: [PULL 09/10] qdev-monitor: Check sysbus device type before creating it Date: Mon, 1 Nov 2021 19:42:58 +0100 Message-Id: <20211101184259.2859090-10-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211101184259.2859090-1-philmd@redhat.com> References: <20211101184259.2859090-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635792230486100001 From: Damien Hedde Add an early check to test if the requested sysbus device type is allowed by the current machine before creating the device. This impacts both -device cli option and device_add qmp command. Before this patch, the check was done well after the device has been created (in a machine init done notifier). We can now report the error right away. Signed-off-by: Damien Hedde Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Eduardo Habkost Message-Id: <20211029142258.484907-3-damien.hedde@greensocs.com> Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- softmmu/qdev-monitor.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 4851de51a5c..e49d9773d2d 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -42,6 +42,7 @@ #include "qemu/cutils.h" #include "hw/qdev-properties.h" #include "hw/clock.h" +#include "hw/boards.h" =20 /* * Aliases were a bad idea from the start. Let's keep them @@ -254,6 +255,16 @@ static DeviceClass *qdev_get_device_class(const char *= *driver, Error **errp) return NULL; } =20 + if (object_class_dynamic_cast(oc, TYPE_SYS_BUS_DEVICE)) { + /* sysbus devices need to be allowed by the machine */ + MachineClass *mc =3D MACHINE_CLASS(object_get_class(qdev_get_machi= ne())); + if (!device_type_is_dynamic_sysbus(mc, *driver)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "driver", + "a dynamic sysbus device type for the machine"); + return NULL; + } + } + return dc; } =20 --=20 2.31.1 From nobody Sun Feb 8 23:42:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635792235; cv=none; d=zohomail.com; s=zohoarc; b=YWoUCv44jw0OpYp6j5GNpVSVL6MAFhs/9I0u7K88+Pe5sjT8uABDjM307h/MkcYCcE8+kkXE9upVUivh5htEthwoKN0R+OgGQDFZZVf4SGi8raYf0K5QQILS9SI8TFMTlMPh7eThOL45sdl+BpbeaQCHQ+7SK22fAmq2iHNbXoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635792235; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=F/4BMq7DrQu+zCZQqgn6KN2GFLHZ2AhJb11IE3m6BvI=; b=ZJRyq1YPp+/jPjQobNoLtDb135clWUcE4a5EQOWJBZpUWpowekgAB4TrGh8Ib/ydmZoBdtTD4LyhNiZwtY4JYRSuLsN0Kry38z/ScdZ5PR+ne/n3M+BCD1iO0uGTfD3VxVA8JvF+RhqVXDBXv8pmRFTSjTOyAZ6aLpYdtGMqd40= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1635792235775142.14791456098123; Mon, 1 Nov 2021 11:43:55 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-551-a4oUN7fJNziteRAsUaKtgw-1; Mon, 01 Nov 2021 14:43:51 -0400 Received: by mail-wm1-f70.google.com with SMTP id v5-20020a1cac05000000b0032ccf04ba2cso59879wme.2 for ; Mon, 01 Nov 2021 11:43:51 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id o2sm15128956wrg.1.2021.11.01.11.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 11:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635792234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F/4BMq7DrQu+zCZQqgn6KN2GFLHZ2AhJb11IE3m6BvI=; b=MAbjKPaiFzChqtY4w4FCm639G13kOs+Fc8XXGyiM6zpBULTAxvsMpLuWrLZyGfnB25fqAr yzLvLhc7TOeGIEkY5qAnPmqVRxrnSbgwN6bwPImCU19KLhnuBZkvcIAuTAv8bSOBuCwtxh YKFex3vddUU+FkYGu8dvl2ABTAwU3ww= X-MC-Unique: a4oUN7fJNziteRAsUaKtgw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F/4BMq7DrQu+zCZQqgn6KN2GFLHZ2AhJb11IE3m6BvI=; b=fke0VjvQdMQGLB6v0WAgqyEcrOROH0vgo0FLtnKmPqJRVBaoSnZQE0AvGlv+BqTslz 4kcFhSpfiKlKvY8pDW7kyyh5OmTrcX+Jd8SSR7A0tBreNfzuTluR9qOOkm0xcKoe0NlV wnOP7wIRPz0y6ExxFHnBwNUo/wl69x+d8E9AhZIbIUjqT9CxrYONzubvqnFTeFo0+0D9 FSMVuNzqgRsCXZW1Ax8wyYnwdIV6Id4JBQsDfB8bTzip4Hcua/mI6t53OZL9L43etzrH 5FkAzRJCY2mHgv4f12loTXaQ1OEoDYZynpVqgQ6UAriomtmu2ePZBQ2/t37RDD0rPwuj WsbQ== X-Gm-Message-State: AOAM5337bVFCe+lw2KyTgYcjO+UczTH6fk0ts8TjB1SeaPE31BUSmEMf oHuocu9ZvkTmYT6CRrDpUvXA+GudhReUMe71intedl7w3EaXAMwA9D0IXFskWJraCmGGgJrCi37 /Sh62nZRnHHyhtA== X-Received: by 2002:a5d:58c5:: with SMTP id o5mr23112949wrf.15.1635792230463; Mon, 01 Nov 2021 11:43:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjHqzi3yr+pZ4o8shqMaGSGS9W7EXt8i+7Ju1NmeqJx1eY6jDwQrELoqkN+WOkPtZnlFVHbA== X-Received: by 2002:a5d:58c5:: with SMTP id o5mr23112931wrf.15.1635792230275; Mon, 01 Nov 2021 11:43:50 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Marcel Apfelbaum , Damien Hedde , Alistair Francis Subject: [PULL 10/10] machine: remove the done notifier for dynamic sysbus device type check Date: Mon, 1 Nov 2021 19:42:59 +0100 Message-Id: <20211101184259.2859090-11-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211101184259.2859090-1-philmd@redhat.com> References: <20211101184259.2859090-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635792237022100002 From: Damien Hedde Now that we check sysbus device types during device creation, we can remove the check in the machine init done notifier. This was the only thing done by this notifier, so we remove the whole sysbus_notifier structure of the MachineState. Note: This notifier was checking all /peripheral and /peripheral-anon sysbus devices. Now we only check those added by -device cli option or device_add qmp command when handling the command/option. So if there are some devices added in one of these containers manually (eg in machine C code), these will not be checked anymore. This use case does not seem to appear apart from hw/xen/xen-legacy-backend.c (it uses qdev_set_id() and in this case, not for a sysbus device, so it's ok). Signed-off-by: Damien Hedde Acked-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Eduardo Habkost Message-Id: <20211029142258.484907-4-damien.hedde@greensocs.com> Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/boards.h | 1 - hw/core/machine.c | 27 --------------------------- 2 files changed, 28 deletions(-) diff --git a/include/hw/boards.h b/include/hw/boards.h index 602993bd5ab..9c1c1901046 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -317,7 +317,6 @@ typedef struct CpuTopology { struct MachineState { /*< private >*/ Object parent_obj; - Notifier sysbus_notifier; =20 /*< public >*/ =20 diff --git a/hw/core/machine.c b/hw/core/machine.c index 7c4004ac5a0..e24e3e27dbe 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -572,18 +572,6 @@ bool device_type_is_dynamic_sysbus(MachineClass *mc, c= onst char *type) return allowed; } =20 -static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque) -{ - MachineState *machine =3D opaque; - MachineClass *mc =3D MACHINE_GET_CLASS(machine); - - if (!device_is_dynamic_sysbus(mc, DEVICE(sbdev))) { - error_report("Option '-device %s' cannot be handled by this machin= e", - object_class_get_name(object_get_class(OBJECT(sbdev))= )); - exit(1); - } -} - static char *machine_get_memdev(Object *obj, Error **errp) { MachineState *ms =3D MACHINE(obj); @@ -599,17 +587,6 @@ static void machine_set_memdev(Object *obj, const char= *value, Error **errp) ms->ram_memdev_id =3D g_strdup(value); } =20 -static void machine_init_notify(Notifier *notifier, void *data) -{ - MachineState *machine =3D MACHINE(qdev_get_machine()); - - /* - * Loop through all dynamically created sysbus devices and check if th= ey are - * all allowed. If a device is not allowed, error out. - */ - foreach_dynamic_sysbus_device(validate_sysbus_device, machine); -} - HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine) { int i; @@ -949,10 +926,6 @@ static void machine_initfn(Object *obj) "Table (HMAT)"); } =20 - /* Register notifier when init is done for sysbus sanity checks */ - ms->sysbus_notifier.notify =3D machine_init_notify; - qemu_add_machine_init_done_notifier(&ms->sysbus_notifier); - /* default to mc->default_cpus */ ms->smp.cpus =3D mc->default_cpus; ms->smp.max_cpus =3D mc->default_cpus; --=20 2.31.1