From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA0DFC433EF for ; Thu, 23 Sep 2021 10:52:34 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9AD05610C9 for ; Thu, 23 Sep 2021 10:52:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9AD05610C9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=anisinha.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.193681.345015 (Exim 4.92) (envelope-from ) id 1mTML4-0000fr-VC; Thu, 23 Sep 2021 10:52:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 193681.345015; Thu, 23 Sep 2021 10:52:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mTML4-0000fk-SF; Thu, 23 Sep 2021 10:52:26 +0000 Received: by outflank-mailman (input) for mailman id 193681; Thu, 23 Sep 2021 10:51:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mTMK4-0000Eq-KF for xen-devel@lists.xenproject.org; Thu, 23 Sep 2021 10:51:24 +0000 Received: from mail-pl1-x634.google.com (unknown [2607:f8b0:4864:20::634]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 11461a33-4c5f-4c4b-b0b0-1094f814d6d0; Thu, 23 Sep 2021 10:51:23 +0000 (UTC) Received: by mail-pl1-x634.google.com with SMTP id y1so3720435plk.10 for ; Thu, 23 Sep 2021 03:51:23 -0700 (PDT) Received: from anisinha-lenovo ([115.96.156.170]) by smtp.googlemail.com with ESMTPSA id e13sm5257765pfi.210.2021.09.23.03.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 03:51:21 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 11461a33-4c5f-4c4b-b0b0-1094f814d6d0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anisinha-ca.20210112.gappssmtp.com; s=20210112; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=4fJXlclBbnkVQPBywtqy0QsfK3GLzEGhebPQ86PZ4yM=; b=UwDv30mJvlcUbc5vsqv5ShtJ3oE0rdWz5cuSzKVT1VMx7oOAhptBwIZn+62mHKdIda CcTYo+EH+KpGcDyZdaNnrJToFa4sWqSUcsxSlx9OQMQwM6QNX2Bww7OSG0RQXXbD3De5 /pWCE/0WJrdF+Yon0++dBCaOxfyz5xkXytI1DQ+bx6EBoEMTn9XJoS68bJ+H7GOwtgB8 qoSCK6s0PZy1TP/XYoD8RYoHjlNP3fM2zc0dTANnUrIbLemr+exTR/fR3LouYTH11512 q0A2gT3vXM5gNC++K3kAcqiW6ZU/MP54Ed6BdACd1DXgZye8fizrfC83ybMpvRifxhXA lPMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=4fJXlclBbnkVQPBywtqy0QsfK3GLzEGhebPQ86PZ4yM=; b=VXIpjNXwcQ4dC8pW25Ecqfz+r5N47avqQvSKRZwqj+8qRBdQYGKcgfs4WpxqrQFOR1 nb6pAux0UA7DBrH8Y8ysGR1GLDgRNrQ8zw/3FMtLgp+TiFT7HjXBgf3VgQ3FoV9Ywps1 Ddez/dtmi2FxiI1QmHiyEQWGkPvzHqnGK2iUDjfBTDhUWylwhFfLAckeMrTd0ZvBsKoE yOst9ZZAwLM3r7YgrzBh/w2LDhpNIaHqxtj/DHYaFyeWrzb4GAbIWqrHyJ/WIF3yB2k8 J5GrpbDNQIEAQSbj8EyZfVceu1EBbOvQuzqcqK5RnVkq7Pitql+fY6iYZmaUPxoBwoni sufg== X-Gm-Message-State: AOAM5339eKGXUUwHByCHSTAfQJWFRVtz2hKmpSuVD4m6mRZefRAfHDqr u1ZVUwN1iEuRNnvHFmmCLtutVg== X-Google-Smtp-Source: ABdhPJzia+90/vmutfv9+OVhfiSOiEAHqZONBLVWc1gCXXoo34eh7DSYhO2/LLO7Y/O8VFiKodZgxw== X-Received: by 2002:a17:90b:4d8f:: with SMTP id oj15mr4553491pjb.13.1632394282429; Thu, 23 Sep 2021 03:51:22 -0700 (PDT) From: Ani Sinha X-Google-Original-From: Ani Sinha Date: Thu, 23 Sep 2021 16:21:11 +0530 (IST) X-X-Sender: anisinha@anisinha-lenovo To: Damien Hedde cc: qemu-devel@nongnu.org, Alistair Francis , =?ISO-8859-15?Q?Marc-Andr=E9_Lureau?= , Paolo Bonzini , Eduardo Habkost , Marcel Apfelbaum , =?ISO-8859-15?Q?Daniel_P=2E_Berrang=E9?= , "Michael S. Tsirkin" , Igor Mammedov , Ani Sinha , Gerd Hoffmann , Eric Auger , Stefano Stabellini , Anthony Perard , Paul Durrant , Peter Xu , David Hildenbrand , "Dr. David Alan Gilbert" , Markus Armbruster , Eric Blake , qemu-riscv@nongnu.org, xen-devel@lists.xenproject.org, mark.burton@greensocs.com, mirela.grujic@greensocs.com, edgari@xilinx.com, Peter Maydell Subject: Re: [RFC PATCH v2 07/16] hw/core/machine: add machine_class_is_dynamic_sysbus_dev_allowed In-Reply-To: <20210922161405.140018-8-damien.hedde@greensocs.com> Message-ID: References: <20210922161405.140018-1-damien.hedde@greensocs.com> <20210922161405.140018-8-damien.hedde@greensocs.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Wed, 22 Sep 2021, Damien Hedde wrote: > 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 check if a sysbus device type is > allowed to be dynamically created by the machine during the device > creation time. > > Also make device_is_dynamic_sysbus() use the new function. > > Signed-off-by: Damien Hedde > --- > > In the context of our series, we need to be able to do the check at > device creation time to allow doing it depending on the current > MACHINE_INIT phase. > --- > include/hw/boards.h | 17 +++++++++++++++++ > hw/core/machine.c | 15 ++++++++++++--- > 2 files changed, 29 insertions(+), 3 deletions(-) > > diff --git a/include/hw/boards.h b/include/hw/boards.h > index 463a5514f9..934443c1cd 100644 > --- a/include/hw/boards.h > +++ b/include/hw/boards.h > @@ -51,6 +51,23 @@ void machine_set_cpu_numa_node(MachineState *machine, > */ > void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type); > > +/** > + * machine_class_is_dynamic_sysbus_dev_allowed: 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 is a subtype of a type which is in the list, it is > + * allowed too. > + */ > +bool machine_class_is_dynamic_sysbus_dev_allowed(MachineClass *mc, > + const char *type); > + How about renaming this to device_type_is_allowed_dynamic_sysbus() ? > /** > * 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 9125c9aad0..1a18912dc8 100644 > --- a/hw/core/machine.c > +++ b/hw/core/machine.c > @@ -545,18 +545,27 @@ void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type) > > bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev) > { > - bool allowed = false; > - strList *wl; > Object *obj = OBJECT(dev); > > if (!object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE)) { > return false; > } > > + return machine_class_is_dynamic_sysbus_dev_allowed(mc, > + object_get_typename(obj)); > +} > + > +bool machine_class_is_dynamic_sysbus_dev_allowed(MachineClass *mc, > + const char *type) > +{ > + bool allowed = false; > + strList *wl; > + ObjectClass *klass = object_class_by_name(type); > + > for (wl = mc->allowed_dynamic_sysbus_devices; > !allowed && wl; > wl = wl->next) { > - allowed |= !!object_dynamic_cast(obj, wl->value); > + allowed |= !!object_class_dynamic_cast(klass, wl->value); > } > > return allowed; > -- > 2.33.0 > >