From nobody Mon Feb 9 10:29:14 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