From nobody Thu Nov 28 08:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1694165452; cv=none; d=zohomail.com; s=zohoarc; b=TuQDHT/5bUHFOIWp7gjZMdVwg0oUn+sa0DA3Ugs4kECthY9VcPKuQmrxIh+Jor40Nf/+vT28lJUC/s8IG/DWaY0AQ3HrbYBwnw7jt2iaNkwy3fo4sHg0xjY6f6tv+N3b0B+ri92uiMfJz4x6yIQ98Q0DN/uFJQ3/44MLpEwaDAY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694165452; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=G/TX6SDiw/RA6WCqGD3fMIlR8OZXenhAqc/m5lfuEqA=; b=UnNPn6vYxRkotBg1n5kqOLdvuu5L8iP8dkD0ogtPN6HbS0OQLk5NUmpl/xtPMe8cmO8gMFIJULfhALhRxeydq5ekPxli0XpGGRc3eMklAxX+3TIJ2v+v9rZxOEPJKvYFd80Gr5tSRSzjg6X2YBJtzrFxD+XHgc/riiHV7/nVzkU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694165452594872.7612605502608; Fri, 8 Sep 2023 02:30:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeXoi-0000tJ-V5; Fri, 08 Sep 2023 05:30:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeXob-0000s1-9F for qemu-devel@nongnu.org; Fri, 08 Sep 2023 05:30:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeXoO-00062e-AE for qemu-devel@nongnu.org; Fri, 08 Sep 2023 05:30:13 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-407-nUNjcnU6MP2Qm6At-LNB5g-1; Fri, 08 Sep 2023 05:29:54 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8E683101CA82; Fri, 8 Sep 2023 09:29:53 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.28.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F4E540C2070; Fri, 8 Sep 2023 09:29:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694165399; 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; bh=G/TX6SDiw/RA6WCqGD3fMIlR8OZXenhAqc/m5lfuEqA=; b=bL/FTP3Q4leZ07F/LTWHrIGOf2hdHScbwfc28sSyllTlfHXT8BO+S3bmtYkUtMk+8rnvLB JCnmcHIAq9oJXofzn2XJ9JYDvSDvwBHcXrq9WCxo3pO9PsF6FzKwJsOtpd41gf5DbvGvf/ 2xtwyFOuaN0jot38fqXcBM3S5hSil9I= X-MC-Unique: nUNjcnU6MP2Qm6At-LNB5g-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Markus Armbruster , Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Kevin Wolf , Peter Maydell Subject: [PATCH] hw: forbid DEFINE_PROP_ARRAY for user creatable devices Date: Fri, 8 Sep 2023 10:29:51 +0100 Message-ID: <20230908092951.2683721-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1694165454492100005 The DEFINE_PROP_ARRAY macro is a clever trick for defining array properties. It initially creates a property "len-$FOO". When that property is set, then it creates a sequence "$FOO[NN]" for NN in the range 0 to "len-$FOO". The intended usage for this was to simplify code for internal devices, however, it crept into use for user creatable devices when the 'rocker' network device used it. This relied on the user specifying the len property first on the -device comand line, and the args being processed in-order. The latter was broken[1] when -device was converted from QemuOpts to QDict[2], as ordering of loading properties was no longer guaranteed to match user specified ordering. This change poisons the setter for "len-$FOO" such that it raises an error when used with a user creatable device. This allows DEFINE_PROP_ARRAY to remain exclusively for internal devices, since code can ensure properties are set in the correct ordering. [1] https://gitlab.com/qemu-project/qemu/-/issues/1090 [2] f3558b1b763683bb877f7dd5b282469cdadc65c3 Signed-off-by: Daniel P. Berrang=C3=A9 --- hw/core/qdev-properties.c | 6 ++++++ include/hw/qdev-properties.h | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 357b8761b5..2d295411ef 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -584,6 +584,12 @@ static void set_prop_arraylen(Object *obj, Visitor *v,= const char *name, void *eltptr; const char *arrayname; int i; + DeviceClass *devc =3D DEVICE_CLASS(object_get_class(obj)); + + if (devc->user_creatable) { + error_setg(errp, "array property not permitted for user creatable = devices"); + return; + } =20 if (*alenptr) { error_setg(errp, "array size property %s may not be set more than = once", diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index e1df08876c..19042e6cd9 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -127,6 +127,13 @@ extern const PropertyInfo qdev_prop_link; * @_arrayprop: PropertyInfo defining what property the array elements have * @_arraytype: C type of the array elements * + * Note: this macro is forbidden to use with user creatable devices + * as its behaviour relies on the precise ordering with which + * properties are set. Ordering is not guaranteed for our public + * facing interfaces (-device CLI / device_add QMP) for creating + * devices. Any attempt to use this on a user creatable device + * will trigger an error at runtime. + * * Define device properties for a variable-length array _name. A * static property "len-arrayname" is defined. When the device creator * sets this property to the desired length of array, further dynamic --=20 2.41.0