qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] Limit type names to alphanumerical and some few special characters
@ 2023-11-17 11:44 Thomas Huth
  2023-11-17 11:44 ` [PATCH v3 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl" Thomas Huth
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Thomas Huth @ 2023-11-17 11:44 UTC (permalink / raw)
  To: qemu-devel, Daniel P. Berrangé, Markus Armbruster
  Cc: Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Philippe Mathieu-Daudé,
	Francisco Iglesias, Eduardo Habkost, Thomas Huth

QOM names currently don't have any enforced naming rules. This
can be problematic, e.g. when they are used on the command line
for the "-device" option (where the comma is used to separate
properties). To avoid that such problematic type names come in
again, let's restrict the set of acceptable characters during the
type registration.

First four patches are clean-ups related to comma and colons
in type names, and the final patch introduces the check for
valid names.

v3:
- Added Reviewed-bys to the first four patches
- Changed last patch to use strspn() as suggested by Daniel

v2:
- Include Markus' patches in the series
- Add patches to clean up colons in type names
- Add the check to type_register_internal() instead of type_new()
  so that we can disallow colons, too
- Only allow '+' in legacy names

Markus Armbruster (2):
  docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl"
  hw: Replace anti-social QOM type names (again)

Thomas Huth (3):
  memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type
    name
  tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the
    name
  qom/object: Limit type names to alphanumerical and some few special
    characters

 docs/system/arm/xlnx-versal-virt.rst     |  4 +--
 include/exec/memory.h                    |  2 +-
 include/hw/misc/xlnx-versal-cframe-reg.h |  2 +-
 include/hw/misc/xlnx-versal-cfu.h        |  6 ++--
 include/hw/misc/xlnx-versal-crl.h        |  2 +-
 include/hw/nvram/xlnx-efuse.h            |  2 +-
 include/hw/nvram/xlnx-versal-efuse.h     |  4 +--
 include/hw/nvram/xlnx-zynqmp-efuse.h     |  2 +-
 qom/object.c                             | 41 ++++++++++++++++++++++++
 tests/unit/test-io-task.c                |  2 +-
 10 files changed, 54 insertions(+), 13 deletions(-)

-- 
2.42.0



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl"
  2023-11-17 11:44 [PATCH v3 0/5] Limit type names to alphanumerical and some few special characters Thomas Huth
@ 2023-11-17 11:44 ` Thomas Huth
  2023-11-21  3:10   ` Alistair Francis
  2023-11-17 11:44 ` [PATCH v3 2/5] hw: Replace anti-social QOM type names (again) Thomas Huth
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Thomas Huth @ 2023-11-17 11:44 UTC (permalink / raw)
  To: qemu-devel, Daniel P. Berrangé, Markus Armbruster
  Cc: Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Philippe Mathieu-Daudé,
	Francisco Iglesias, Eduardo Habkost, Thomas Huth

From: Markus Armbruster <armbru@redhat.com>

Fixes: b65b4b7ae3c8 (xlnx-bbram: hw/nvram: Use dot in device type name)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[thuth: Use longhand syntax to avoid problems with the "." in the name]
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 docs/system/arm/xlnx-versal-virt.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/system/arm/xlnx-versal-virt.rst b/docs/system/arm/xlnx-versal-virt.rst
index d2d1b26692..9a4b2ff55f 100644
--- a/docs/system/arm/xlnx-versal-virt.rst
+++ b/docs/system/arm/xlnx-versal-virt.rst
@@ -194,7 +194,7 @@ To use a different index value, N, from default of 0, add:
 
 .. code-block:: bash
 
-  -global xlnx,bbram-ctrl.drive-index=N
+  -global driver=xlnx.bbram-ctrl,property=drive-index,value=N
 
 eFUSE File Backend
 """"""""""""""""""
-- 
2.42.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 2/5] hw: Replace anti-social QOM type names (again)
  2023-11-17 11:44 [PATCH v3 0/5] Limit type names to alphanumerical and some few special characters Thomas Huth
  2023-11-17 11:44 ` [PATCH v3 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl" Thomas Huth
@ 2023-11-17 11:44 ` Thomas Huth
  2023-11-21  3:11   ` Alistair Francis
  2023-11-17 11:44 ` [PATCH v3 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name Thomas Huth
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Thomas Huth @ 2023-11-17 11:44 UTC (permalink / raw)
  To: qemu-devel, Daniel P. Berrangé, Markus Armbruster
  Cc: Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Philippe Mathieu-Daudé,
	Francisco Iglesias, Eduardo Habkost, Thomas Huth

From: Markus Armbruster <armbru@redhat.com>

QOM type names containing ',' result in awful UI.  We got rid of them
in v6.0.0 (commit e178113ff64 hw: Replace anti-social QOM type names).
A few have crept back since:

    xlnx,cframe-reg
    xlnx,efuse
    xlnx,pmc-efuse-cache
    xlnx,versal-cfu-apb
    xlnx,versal-cfu-fdro
    xlnx,versal-cfu-sfr
    xlnx,versal-crl
    xlnx,versal-efuse
    xlnx,zynqmp-efuse

These are all device types.  They can't be plugged with -device /
device_add, except for "xlnx,efuse" (I'm not sure that one is
intentional).

They *can* be used with -device / device_add to request help.
Usability is poor, though: you have to double the comma, like this:

    $ qemu-system-aarch64 -device xlnx,,pmc-efuse-cache,help

They can also be used with -global, where you must *not* double the
comma:

    $ qemu-system-aarch64 -global xlnx,efuse.drive-index=2

Trap for the unwary.

"xlnx,efuse", "xlnx,versal-efuse", "xlnx,pmc-efuse-cache",
"xlnx-zynqmp-efuse" are from v6.2.0, "xlnx,versal-crl" is from v7.1.0,
and the remainder are new.

Rename them all to "xlnx-FOO", like commit e178113ff64 did.

Reported-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Francisco Iglesias <francisco.iglesias@amd.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 docs/system/arm/xlnx-versal-virt.rst     | 2 +-
 include/hw/misc/xlnx-versal-cframe-reg.h | 2 +-
 include/hw/misc/xlnx-versal-cfu.h        | 6 +++---
 include/hw/misc/xlnx-versal-crl.h        | 2 +-
 include/hw/nvram/xlnx-efuse.h            | 2 +-
 include/hw/nvram/xlnx-versal-efuse.h     | 4 ++--
 include/hw/nvram/xlnx-zynqmp-efuse.h     | 2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/docs/system/arm/xlnx-versal-virt.rst b/docs/system/arm/xlnx-versal-virt.rst
index 9a4b2ff55f..0bafc76469 100644
--- a/docs/system/arm/xlnx-versal-virt.rst
+++ b/docs/system/arm/xlnx-versal-virt.rst
@@ -212,7 +212,7 @@ To use a different index value, N, from default of 1, add:
 
 .. code-block:: bash
 
-  -global xlnx,efuse.drive-index=N
+  -global xlnx-efuse.drive-index=N
 
 .. warning::
   In actual physical Versal, BBRAM and eFUSE contain sensitive data.
diff --git a/include/hw/misc/xlnx-versal-cframe-reg.h b/include/hw/misc/xlnx-versal-cframe-reg.h
index a14fbd7fe4..f403b00e31 100644
--- a/include/hw/misc/xlnx-versal-cframe-reg.h
+++ b/include/hw/misc/xlnx-versal-cframe-reg.h
@@ -23,7 +23,7 @@
 #include "hw/misc/xlnx-versal-cfu.h"
 #include "qemu/fifo32.h"
 
-#define TYPE_XLNX_VERSAL_CFRAME_REG "xlnx,cframe-reg"
+#define TYPE_XLNX_VERSAL_CFRAME_REG "xlnx-cframe-reg"
 OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFrameReg, XLNX_VERSAL_CFRAME_REG)
 
 #define TYPE_XLNX_VERSAL_CFRAME_BCAST_REG "xlnx.cframe-bcast-reg"
diff --git a/include/hw/misc/xlnx-versal-cfu.h b/include/hw/misc/xlnx-versal-cfu.h
index 86fb841053..8c581c0797 100644
--- a/include/hw/misc/xlnx-versal-cfu.h
+++ b/include/hw/misc/xlnx-versal-cfu.h
@@ -22,13 +22,13 @@
 #include "hw/misc/xlnx-cfi-if.h"
 #include "qemu/fifo32.h"
 
-#define TYPE_XLNX_VERSAL_CFU_APB "xlnx,versal-cfu-apb"
+#define TYPE_XLNX_VERSAL_CFU_APB "xlnx-versal-cfu-apb"
 OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUAPB, XLNX_VERSAL_CFU_APB)
 
-#define TYPE_XLNX_VERSAL_CFU_FDRO "xlnx,versal-cfu-fdro"
+#define TYPE_XLNX_VERSAL_CFU_FDRO "xlnx-versal-cfu-fdro"
 OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUFDRO, XLNX_VERSAL_CFU_FDRO)
 
-#define TYPE_XLNX_VERSAL_CFU_SFR "xlnx,versal-cfu-sfr"
+#define TYPE_XLNX_VERSAL_CFU_SFR "xlnx-versal-cfu-sfr"
 OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUSFR, XLNX_VERSAL_CFU_SFR)
 
 REG32(CFU_ISR, 0x0)
diff --git a/include/hw/misc/xlnx-versal-crl.h b/include/hw/misc/xlnx-versal-crl.h
index 2857f4169a..dfb8dff197 100644
--- a/include/hw/misc/xlnx-versal-crl.h
+++ b/include/hw/misc/xlnx-versal-crl.h
@@ -13,7 +13,7 @@
 #include "hw/register.h"
 #include "target/arm/cpu.h"
 
-#define TYPE_XLNX_VERSAL_CRL "xlnx,versal-crl"
+#define TYPE_XLNX_VERSAL_CRL "xlnx-versal-crl"
 OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCRL, XLNX_VERSAL_CRL)
 
 REG32(ERR_CTRL, 0x0)
diff --git a/include/hw/nvram/xlnx-efuse.h b/include/hw/nvram/xlnx-efuse.h
index 58414e468b..cff7924106 100644
--- a/include/hw/nvram/xlnx-efuse.h
+++ b/include/hw/nvram/xlnx-efuse.h
@@ -30,7 +30,7 @@
 #include "sysemu/block-backend.h"
 #include "hw/qdev-core.h"
 
-#define TYPE_XLNX_EFUSE "xlnx,efuse"
+#define TYPE_XLNX_EFUSE "xlnx-efuse"
 OBJECT_DECLARE_SIMPLE_TYPE(XlnxEFuse, XLNX_EFUSE);
 
 struct XlnxEFuse {
diff --git a/include/hw/nvram/xlnx-versal-efuse.h b/include/hw/nvram/xlnx-versal-efuse.h
index a873dc5cb0..86e2261b9a 100644
--- a/include/hw/nvram/xlnx-versal-efuse.h
+++ b/include/hw/nvram/xlnx-versal-efuse.h
@@ -29,8 +29,8 @@
 
 #define XLNX_VERSAL_EFUSE_CTRL_R_MAX ((0x100 / 4) + 1)
 
-#define TYPE_XLNX_VERSAL_EFUSE_CTRL  "xlnx,versal-efuse"
-#define TYPE_XLNX_VERSAL_EFUSE_CACHE "xlnx,pmc-efuse-cache"
+#define TYPE_XLNX_VERSAL_EFUSE_CTRL  "xlnx-versal-efuse"
+#define TYPE_XLNX_VERSAL_EFUSE_CACHE "xlnx-pmc-efuse-cache"
 
 OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalEFuseCtrl, XLNX_VERSAL_EFUSE_CTRL);
 OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalEFuseCache, XLNX_VERSAL_EFUSE_CACHE);
diff --git a/include/hw/nvram/xlnx-zynqmp-efuse.h b/include/hw/nvram/xlnx-zynqmp-efuse.h
index 6b051ec4f1..f5beacc2e6 100644
--- a/include/hw/nvram/xlnx-zynqmp-efuse.h
+++ b/include/hw/nvram/xlnx-zynqmp-efuse.h
@@ -29,7 +29,7 @@
 
 #define XLNX_ZYNQMP_EFUSE_R_MAX ((0x10fc / 4) + 1)
 
-#define TYPE_XLNX_ZYNQMP_EFUSE "xlnx,zynqmp-efuse"
+#define TYPE_XLNX_ZYNQMP_EFUSE "xlnx-zynqmp-efuse"
 OBJECT_DECLARE_SIMPLE_TYPE(XlnxZynqMPEFuse, XLNX_ZYNQMP_EFUSE);
 
 struct XlnxZynqMPEFuse {
-- 
2.42.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name
  2023-11-17 11:44 [PATCH v3 0/5] Limit type names to alphanumerical and some few special characters Thomas Huth
  2023-11-17 11:44 ` [PATCH v3 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl" Thomas Huth
  2023-11-17 11:44 ` [PATCH v3 2/5] hw: Replace anti-social QOM type names (again) Thomas Huth
@ 2023-11-17 11:44 ` Thomas Huth
  2023-11-21  3:13   ` Alistair Francis
  2023-11-17 11:44 ` [PATCH v3 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name Thomas Huth
  2023-11-17 11:44 ` [PATCH v3 5/5] qom/object: Limit type names to alphanumerical and some few special characters Thomas Huth
  4 siblings, 1 reply; 13+ messages in thread
From: Thomas Huth @ 2023-11-17 11:44 UTC (permalink / raw)
  To: qemu-devel, Daniel P. Berrangé, Markus Armbruster
  Cc: Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Philippe Mathieu-Daudé,
	Francisco Iglesias, Eduardo Habkost, Thomas Huth

Type names should not contain special characters like ":". Let's
remove the whole prefix here since it does not really seem to be
helpful to have such a prefix here. The type name is only used
internally for an interface type, so the renaming should not affect
the user interface or migration.

Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 include/exec/memory.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 831f7c996d..f172e82ac9 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -43,7 +43,7 @@ typedef struct IOMMUMemoryRegionClass IOMMUMemoryRegionClass;
 DECLARE_OBJ_CHECKERS(IOMMUMemoryRegion, IOMMUMemoryRegionClass,
                      IOMMU_MEMORY_REGION, TYPE_IOMMU_MEMORY_REGION)
 
-#define TYPE_RAM_DISCARD_MANAGER "qemu:ram-discard-manager"
+#define TYPE_RAM_DISCARD_MANAGER "ram-discard-manager"
 typedef struct RamDiscardManagerClass RamDiscardManagerClass;
 typedef struct RamDiscardManager RamDiscardManager;
 DECLARE_OBJ_CHECKERS(RamDiscardManager, RamDiscardManagerClass,
-- 
2.42.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name
  2023-11-17 11:44 [PATCH v3 0/5] Limit type names to alphanumerical and some few special characters Thomas Huth
                   ` (2 preceding siblings ...)
  2023-11-17 11:44 ` [PATCH v3 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name Thomas Huth
@ 2023-11-17 11:44 ` Thomas Huth
  2023-11-21  3:13   ` Alistair Francis
  2023-11-17 11:44 ` [PATCH v3 5/5] qom/object: Limit type names to alphanumerical and some few special characters Thomas Huth
  4 siblings, 1 reply; 13+ messages in thread
From: Thomas Huth @ 2023-11-17 11:44 UTC (permalink / raw)
  To: qemu-devel, Daniel P. Berrangé, Markus Armbruster
  Cc: Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Philippe Mathieu-Daudé,
	Francisco Iglesias, Eduardo Habkost, Thomas Huth

Type names should not contain special characters like ":" (so that
they are easier to use with QAPI and other parts). We are going to
forbid such names in an upcoming patch. Thus let's replace the ":"
here with a "-".

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/unit/test-io-task.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/unit/test-io-task.c b/tests/unit/test-io-task.c
index 953a50ae66..115dba8970 100644
--- a/tests/unit/test-io-task.c
+++ b/tests/unit/test-io-task.c
@@ -25,7 +25,7 @@
 #include "qapi/error.h"
 #include "qemu/module.h"
 
-#define TYPE_DUMMY "qemu:dummy"
+#define TYPE_DUMMY "qemu-dummy"
 
 typedef struct DummyObject DummyObject;
 typedef struct DummyObjectClass DummyObjectClass;
-- 
2.42.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 5/5] qom/object: Limit type names to alphanumerical and some few special characters
  2023-11-17 11:44 [PATCH v3 0/5] Limit type names to alphanumerical and some few special characters Thomas Huth
                   ` (3 preceding siblings ...)
  2023-11-17 11:44 ` [PATCH v3 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name Thomas Huth
@ 2023-11-17 11:44 ` Thomas Huth
  2023-11-17 12:25   ` Philippe Mathieu-Daudé
  2023-11-21  3:15   ` Alistair Francis
  4 siblings, 2 replies; 13+ messages in thread
From: Thomas Huth @ 2023-11-17 11:44 UTC (permalink / raw)
  To: qemu-devel, Daniel P. Berrangé, Markus Armbruster
  Cc: Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Philippe Mathieu-Daudé,
	Francisco Iglesias, Eduardo Habkost, Thomas Huth

QOM names currently don't have any enforced naming rules. This
can be problematic, e.g. when they are used on the command line
for the "-device" option (where the comma is used to separate
properties). To avoid that such problematic type names come in
again, let's restrict the set of acceptable characters during the
type registration.

Ideally, we'd apply here the same rules as for QAPI, i.e. all type
names should begin with a letter, and contain only ASCII letters,
digits, hyphen, and underscore. However, we already have so many
pre-existing types like:

    486-x86_64-cpu
    cfi.pflash01
    power5+_v2.1-spapr-cpu-core
    virt-2.6-machine
    pc-i440fx-3.0-machine

... so that we have to allow "." and "+" for now, too. While the
dot is used in a lot of places, the "+" can fortunately be limited
to two classes of legacy names ("power" and "Sun-UltraSparc" CPUs).

We also cannot enforce the rule that names must start with a letter
yet, since there are lot of types that start with a digit. Still,
at least limiting the first characters to the alphanumerical range
should be way better than nothing.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 qom/object.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/qom/object.c b/qom/object.c
index 95c0dc8285..654e1afaf2 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -138,9 +138,50 @@ static TypeImpl *type_new(const TypeInfo *info)
     return ti;
 }
 
+static bool type_name_is_valid(const char *name)
+{
+    const int slen = strlen(name);
+    int plen;
+
+    g_assert(slen > 1);
+
+    /*
+     * Ideally, the name should start with a letter - however, we've got
+     * too many names starting with a digit already, so allow digits here,
+     * too (except '0' which is not used yet)
+     */
+    if (!g_ascii_isalnum(name[0]) || name[0] == '0') {
+        return false;
+    }
+
+    plen = strspn(name, "abcdefghijklmnopqrstuvwxyz"
+                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+                        "0123456789-_.");
+
+    /* Allow some legacy names with '+' in it for compatibility reasons */
+    if (name[plen] == '+') {
+        if (plen == 6 && g_str_has_prefix(name, "power")) {
+            /* Allow "power5+" and "power7+" CPU names*/
+            return true;
+        }
+        if (plen >= 17 && g_str_has_prefix(name, "Sun-UltraSparc-I")) {
+            /* Allow "Sun-UltraSparc-IV+" and "Sun-UltraSparc-IIIi+" */
+            return true;
+        }
+    }
+
+    return plen == slen;
+}
+
 static TypeImpl *type_register_internal(const TypeInfo *info)
 {
     TypeImpl *ti;
+
+    if (!type_name_is_valid(info->name)) {
+        fprintf(stderr, "Registering '%s' with illegal type name\n", info->name);
+        abort();
+    }
+
     ti = type_new(info);
 
     type_table_add(ti);
-- 
2.42.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 5/5] qom/object: Limit type names to alphanumerical and some few special characters
  2023-11-17 11:44 ` [PATCH v3 5/5] qom/object: Limit type names to alphanumerical and some few special characters Thomas Huth
@ 2023-11-17 12:25   ` Philippe Mathieu-Daudé
  2023-11-17 13:48     ` Thomas Huth
  2023-11-21  3:15   ` Alistair Francis
  1 sibling, 1 reply; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-11-17 12:25 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel, Daniel P. Berrangé,
	Markus Armbruster
  Cc: Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Francisco Iglesias, Eduardo Habkost

On 17/11/23 12:44, Thomas Huth wrote:
> QOM names currently don't have any enforced naming rules. This
> can be problematic, e.g. when they are used on the command line
> for the "-device" option (where the comma is used to separate
> properties). To avoid that such problematic type names come in
> again, let's restrict the set of acceptable characters during the
> type registration.
> 
> Ideally, we'd apply here the same rules as for QAPI, i.e. all type
> names should begin with a letter, and contain only ASCII letters,
> digits, hyphen, and underscore. However, we already have so many
> pre-existing types like:
> 
>      486-x86_64-cpu
>      cfi.pflash01
>      power5+_v2.1-spapr-cpu-core
>      virt-2.6-machine
>      pc-i440fx-3.0-machine
> 
> ... so that we have to allow "." and "+" for now, too. While the
> dot is used in a lot of places, the "+" can fortunately be limited
> to two classes of legacy names ("power" and "Sun-UltraSparc" CPUs).
> 
> We also cannot enforce the rule that names must start with a letter
> yet, since there are lot of types that start with a digit. Still,
> at least limiting the first characters to the alphanumerical range
> should be way better than nothing.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   qom/object.c | 41 +++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 41 insertions(+)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 95c0dc8285..654e1afaf2 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -138,9 +138,50 @@ static TypeImpl *type_new(const TypeInfo *info)
>       return ti;
>   }
>   
> +static bool type_name_is_valid(const char *name)
> +{
> +    const int slen = strlen(name);
> +    int plen;
> +
> +    g_assert(slen > 1);
> +
> +    /*
> +     * Ideally, the name should start with a letter - however, we've got
> +     * too many names starting with a digit already, so allow digits here,
> +     * too (except '0' which is not used yet)
> +     */
> +    if (!g_ascii_isalnum(name[0]) || name[0] == '0') {
> +        return false;
> +    }
> +
> +    plen = strspn(name, "abcdefghijklmnopqrstuvwxyz"
> +                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
> +                        "0123456789-_.");
> +
> +    /* Allow some legacy names with '+' in it for compatibility reasons */
> +    if (name[plen] == '+') {
> +        if (plen == 6 && g_str_has_prefix(name, "power")) {
> +            /* Allow "power5+" and "power7+" CPU names*/
> +            return true;
> +        }
> +        if (plen >= 17 && g_str_has_prefix(name, "Sun-UltraSparc-I")) {
> +            /* Allow "Sun-UltraSparc-IV+" and "Sun-UltraSparc-IIIi+" */
> +            return true;
> +        }
> +    }
> +
> +    return plen == slen;
> +}
> +
>   static TypeImpl *type_register_internal(const TypeInfo *info)
>   {
>       TypeImpl *ti;
> +
> +    if (!type_name_is_valid(info->name)) {
> +        fprintf(stderr, "Registering '%s' with illegal type name\n", info->name);

Shouldn't we use error_report() instead of fprintf()? Regardless,

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

> +        abort();
> +    }
> +
>       ti = type_new(info);
>   
>       type_table_add(ti);



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 5/5] qom/object: Limit type names to alphanumerical and some few special characters
  2023-11-17 12:25   ` Philippe Mathieu-Daudé
@ 2023-11-17 13:48     ` Thomas Huth
  0 siblings, 0 replies; 13+ messages in thread
From: Thomas Huth @ 2023-11-17 13:48 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, Daniel P. Berrangé,
	Markus Armbruster
  Cc: Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Francisco Iglesias, Eduardo Habkost

On 17/11/2023 13.25, Philippe Mathieu-Daudé wrote:
> On 17/11/23 12:44, Thomas Huth wrote:
>> QOM names currently don't have any enforced naming rules. This
>> can be problematic, e.g. when they are used on the command line
>> for the "-device" option (where the comma is used to separate
>> properties). To avoid that such problematic type names come in
>> again, let's restrict the set of acceptable characters during the
>> type registration.
>>
>> Ideally, we'd apply here the same rules as for QAPI, i.e. all type
>> names should begin with a letter, and contain only ASCII letters,
>> digits, hyphen, and underscore. However, we already have so many
>> pre-existing types like:
>>
>>      486-x86_64-cpu
>>      cfi.pflash01
>>      power5+_v2.1-spapr-cpu-core
>>      virt-2.6-machine
>>      pc-i440fx-3.0-machine
>>
>> ... so that we have to allow "." and "+" for now, too. While the
>> dot is used in a lot of places, the "+" can fortunately be limited
>> to two classes of legacy names ("power" and "Sun-UltraSparc" CPUs).
>>
>> We also cannot enforce the rule that names must start with a letter
>> yet, since there are lot of types that start with a digit. Still,
>> at least limiting the first characters to the alphanumerical range
>> should be way better than nothing.
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>   qom/object.c | 41 +++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 41 insertions(+)
>>
>> diff --git a/qom/object.c b/qom/object.c
>> index 95c0dc8285..654e1afaf2 100644
>> --- a/qom/object.c
>> +++ b/qom/object.c
>> @@ -138,9 +138,50 @@ static TypeImpl *type_new(const TypeInfo *info)
>>       return ti;
>>   }
>> +static bool type_name_is_valid(const char *name)
>> +{
>> +    const int slen = strlen(name);
>> +    int plen;
>> +
>> +    g_assert(slen > 1);
>> +
>> +    /*
>> +     * Ideally, the name should start with a letter - however, we've got
>> +     * too many names starting with a digit already, so allow digits here,
>> +     * too (except '0' which is not used yet)
>> +     */
>> +    if (!g_ascii_isalnum(name[0]) || name[0] == '0') {
>> +        return false;
>> +    }
>> +
>> +    plen = strspn(name, "abcdefghijklmnopqrstuvwxyz"
>> +                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>> +                        "0123456789-_.");
>> +
>> +    /* Allow some legacy names with '+' in it for compatibility reasons */
>> +    if (name[plen] == '+') {
>> +        if (plen == 6 && g_str_has_prefix(name, "power")) {
>> +            /* Allow "power5+" and "power7+" CPU names*/
>> +            return true;
>> +        }
>> +        if (plen >= 17 && g_str_has_prefix(name, "Sun-UltraSparc-I")) {
>> +            /* Allow "Sun-UltraSparc-IV+" and "Sun-UltraSparc-IIIi+" */
>> +            return true;
>> +        }
>> +    }
>> +
>> +    return plen == slen;
>> +}
>> +
>>   static TypeImpl *type_register_internal(const TypeInfo *info)
>>   {
>>       TypeImpl *ti;
>> +
>> +    if (!type_name_is_valid(info->name)) {
>> +        fprintf(stderr, "Registering '%s' with illegal type name\n", 
>> info->name);
> 
> Shouldn't we use error_report() instead of fprintf()? Regardless,

It doesn't work here yet - the type registration happens so early that we 
cannot use error_report() here yet.

> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Thanks!

  Thomas




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl"
  2023-11-17 11:44 ` [PATCH v3 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl" Thomas Huth
@ 2023-11-21  3:10   ` Alistair Francis
  0 siblings, 0 replies; 13+ messages in thread
From: Alistair Francis @ 2023-11-21  3:10 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel, Daniel P. Berrangé, Markus Armbruster,
	Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Philippe Mathieu-Daudé,
	Francisco Iglesias, Eduardo Habkost

On Fri, Nov 17, 2023 at 9:47 PM Thomas Huth <thuth@redhat.com> wrote:
>
> From: Markus Armbruster <armbru@redhat.com>
>
> Fixes: b65b4b7ae3c8 (xlnx-bbram: hw/nvram: Use dot in device type name)
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> [thuth: Use longhand syntax to avoid problems with the "." in the name]
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Acked-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  docs/system/arm/xlnx-versal-virt.rst | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/docs/system/arm/xlnx-versal-virt.rst b/docs/system/arm/xlnx-versal-virt.rst
> index d2d1b26692..9a4b2ff55f 100644
> --- a/docs/system/arm/xlnx-versal-virt.rst
> +++ b/docs/system/arm/xlnx-versal-virt.rst
> @@ -194,7 +194,7 @@ To use a different index value, N, from default of 0, add:
>
>  .. code-block:: bash
>
> -  -global xlnx,bbram-ctrl.drive-index=N
> +  -global driver=xlnx.bbram-ctrl,property=drive-index,value=N
>
>  eFUSE File Backend
>  """"""""""""""""""
> --
> 2.42.0
>
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 2/5] hw: Replace anti-social QOM type names (again)
  2023-11-17 11:44 ` [PATCH v3 2/5] hw: Replace anti-social QOM type names (again) Thomas Huth
@ 2023-11-21  3:11   ` Alistair Francis
  0 siblings, 0 replies; 13+ messages in thread
From: Alistair Francis @ 2023-11-21  3:11 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel, Daniel P. Berrangé, Markus Armbruster,
	Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Philippe Mathieu-Daudé,
	Francisco Iglesias, Eduardo Habkost

On Fri, Nov 17, 2023 at 9:47 PM Thomas Huth <thuth@redhat.com> wrote:
>
> From: Markus Armbruster <armbru@redhat.com>
>
> QOM type names containing ',' result in awful UI.  We got rid of them
> in v6.0.0 (commit e178113ff64 hw: Replace anti-social QOM type names).
> A few have crept back since:
>
>     xlnx,cframe-reg
>     xlnx,efuse
>     xlnx,pmc-efuse-cache
>     xlnx,versal-cfu-apb
>     xlnx,versal-cfu-fdro
>     xlnx,versal-cfu-sfr
>     xlnx,versal-crl
>     xlnx,versal-efuse
>     xlnx,zynqmp-efuse
>
> These are all device types.  They can't be plugged with -device /
> device_add, except for "xlnx,efuse" (I'm not sure that one is
> intentional).
>
> They *can* be used with -device / device_add to request help.
> Usability is poor, though: you have to double the comma, like this:
>
>     $ qemu-system-aarch64 -device xlnx,,pmc-efuse-cache,help
>
> They can also be used with -global, where you must *not* double the
> comma:
>
>     $ qemu-system-aarch64 -global xlnx,efuse.drive-index=2
>
> Trap for the unwary.
>
> "xlnx,efuse", "xlnx,versal-efuse", "xlnx,pmc-efuse-cache",
> "xlnx-zynqmp-efuse" are from v6.2.0, "xlnx,versal-crl" is from v7.1.0,
> and the remainder are new.
>
> Rename them all to "xlnx-FOO", like commit e178113ff64 did.
>
> Reported-by: Thomas Huth <thuth@redhat.com>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Reviewed-by: Francisco Iglesias <francisco.iglesias@amd.com>
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  docs/system/arm/xlnx-versal-virt.rst     | 2 +-
>  include/hw/misc/xlnx-versal-cframe-reg.h | 2 +-
>  include/hw/misc/xlnx-versal-cfu.h        | 6 +++---
>  include/hw/misc/xlnx-versal-crl.h        | 2 +-
>  include/hw/nvram/xlnx-efuse.h            | 2 +-
>  include/hw/nvram/xlnx-versal-efuse.h     | 4 ++--
>  include/hw/nvram/xlnx-zynqmp-efuse.h     | 2 +-
>  7 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/docs/system/arm/xlnx-versal-virt.rst b/docs/system/arm/xlnx-versal-virt.rst
> index 9a4b2ff55f..0bafc76469 100644
> --- a/docs/system/arm/xlnx-versal-virt.rst
> +++ b/docs/system/arm/xlnx-versal-virt.rst
> @@ -212,7 +212,7 @@ To use a different index value, N, from default of 1, add:
>
>  .. code-block:: bash
>
> -  -global xlnx,efuse.drive-index=N
> +  -global xlnx-efuse.drive-index=N
>
>  .. warning::
>    In actual physical Versal, BBRAM and eFUSE contain sensitive data.
> diff --git a/include/hw/misc/xlnx-versal-cframe-reg.h b/include/hw/misc/xlnx-versal-cframe-reg.h
> index a14fbd7fe4..f403b00e31 100644
> --- a/include/hw/misc/xlnx-versal-cframe-reg.h
> +++ b/include/hw/misc/xlnx-versal-cframe-reg.h
> @@ -23,7 +23,7 @@
>  #include "hw/misc/xlnx-versal-cfu.h"
>  #include "qemu/fifo32.h"
>
> -#define TYPE_XLNX_VERSAL_CFRAME_REG "xlnx,cframe-reg"
> +#define TYPE_XLNX_VERSAL_CFRAME_REG "xlnx-cframe-reg"
>  OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFrameReg, XLNX_VERSAL_CFRAME_REG)
>
>  #define TYPE_XLNX_VERSAL_CFRAME_BCAST_REG "xlnx.cframe-bcast-reg"
> diff --git a/include/hw/misc/xlnx-versal-cfu.h b/include/hw/misc/xlnx-versal-cfu.h
> index 86fb841053..8c581c0797 100644
> --- a/include/hw/misc/xlnx-versal-cfu.h
> +++ b/include/hw/misc/xlnx-versal-cfu.h
> @@ -22,13 +22,13 @@
>  #include "hw/misc/xlnx-cfi-if.h"
>  #include "qemu/fifo32.h"
>
> -#define TYPE_XLNX_VERSAL_CFU_APB "xlnx,versal-cfu-apb"
> +#define TYPE_XLNX_VERSAL_CFU_APB "xlnx-versal-cfu-apb"
>  OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUAPB, XLNX_VERSAL_CFU_APB)
>
> -#define TYPE_XLNX_VERSAL_CFU_FDRO "xlnx,versal-cfu-fdro"
> +#define TYPE_XLNX_VERSAL_CFU_FDRO "xlnx-versal-cfu-fdro"
>  OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUFDRO, XLNX_VERSAL_CFU_FDRO)
>
> -#define TYPE_XLNX_VERSAL_CFU_SFR "xlnx,versal-cfu-sfr"
> +#define TYPE_XLNX_VERSAL_CFU_SFR "xlnx-versal-cfu-sfr"
>  OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCFUSFR, XLNX_VERSAL_CFU_SFR)
>
>  REG32(CFU_ISR, 0x0)
> diff --git a/include/hw/misc/xlnx-versal-crl.h b/include/hw/misc/xlnx-versal-crl.h
> index 2857f4169a..dfb8dff197 100644
> --- a/include/hw/misc/xlnx-versal-crl.h
> +++ b/include/hw/misc/xlnx-versal-crl.h
> @@ -13,7 +13,7 @@
>  #include "hw/register.h"
>  #include "target/arm/cpu.h"
>
> -#define TYPE_XLNX_VERSAL_CRL "xlnx,versal-crl"
> +#define TYPE_XLNX_VERSAL_CRL "xlnx-versal-crl"
>  OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalCRL, XLNX_VERSAL_CRL)
>
>  REG32(ERR_CTRL, 0x0)
> diff --git a/include/hw/nvram/xlnx-efuse.h b/include/hw/nvram/xlnx-efuse.h
> index 58414e468b..cff7924106 100644
> --- a/include/hw/nvram/xlnx-efuse.h
> +++ b/include/hw/nvram/xlnx-efuse.h
> @@ -30,7 +30,7 @@
>  #include "sysemu/block-backend.h"
>  #include "hw/qdev-core.h"
>
> -#define TYPE_XLNX_EFUSE "xlnx,efuse"
> +#define TYPE_XLNX_EFUSE "xlnx-efuse"
>  OBJECT_DECLARE_SIMPLE_TYPE(XlnxEFuse, XLNX_EFUSE);
>
>  struct XlnxEFuse {
> diff --git a/include/hw/nvram/xlnx-versal-efuse.h b/include/hw/nvram/xlnx-versal-efuse.h
> index a873dc5cb0..86e2261b9a 100644
> --- a/include/hw/nvram/xlnx-versal-efuse.h
> +++ b/include/hw/nvram/xlnx-versal-efuse.h
> @@ -29,8 +29,8 @@
>
>  #define XLNX_VERSAL_EFUSE_CTRL_R_MAX ((0x100 / 4) + 1)
>
> -#define TYPE_XLNX_VERSAL_EFUSE_CTRL  "xlnx,versal-efuse"
> -#define TYPE_XLNX_VERSAL_EFUSE_CACHE "xlnx,pmc-efuse-cache"
> +#define TYPE_XLNX_VERSAL_EFUSE_CTRL  "xlnx-versal-efuse"
> +#define TYPE_XLNX_VERSAL_EFUSE_CACHE "xlnx-pmc-efuse-cache"
>
>  OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalEFuseCtrl, XLNX_VERSAL_EFUSE_CTRL);
>  OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalEFuseCache, XLNX_VERSAL_EFUSE_CACHE);
> diff --git a/include/hw/nvram/xlnx-zynqmp-efuse.h b/include/hw/nvram/xlnx-zynqmp-efuse.h
> index 6b051ec4f1..f5beacc2e6 100644
> --- a/include/hw/nvram/xlnx-zynqmp-efuse.h
> +++ b/include/hw/nvram/xlnx-zynqmp-efuse.h
> @@ -29,7 +29,7 @@
>
>  #define XLNX_ZYNQMP_EFUSE_R_MAX ((0x10fc / 4) + 1)
>
> -#define TYPE_XLNX_ZYNQMP_EFUSE "xlnx,zynqmp-efuse"
> +#define TYPE_XLNX_ZYNQMP_EFUSE "xlnx-zynqmp-efuse"
>  OBJECT_DECLARE_SIMPLE_TYPE(XlnxZynqMPEFuse, XLNX_ZYNQMP_EFUSE);
>
>  struct XlnxZynqMPEFuse {
> --
> 2.42.0
>
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name
  2023-11-17 11:44 ` [PATCH v3 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name Thomas Huth
@ 2023-11-21  3:13   ` Alistair Francis
  0 siblings, 0 replies; 13+ messages in thread
From: Alistair Francis @ 2023-11-21  3:13 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel, Daniel P. Berrangé, Markus Armbruster,
	Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Philippe Mathieu-Daudé,
	Francisco Iglesias, Eduardo Habkost

On Fri, Nov 17, 2023 at 9:46 PM Thomas Huth <thuth@redhat.com> wrote:
>
> Type names should not contain special characters like ":". Let's
> remove the whole prefix here since it does not really seem to be
> helpful to have such a prefix here. The type name is only used
> internally for an interface type, so the renaming should not affect
> the user interface or migration.
>
> Reviewed-by: David Hildenbrand <david@redhat.com>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  include/exec/memory.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 831f7c996d..f172e82ac9 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -43,7 +43,7 @@ typedef struct IOMMUMemoryRegionClass IOMMUMemoryRegionClass;
>  DECLARE_OBJ_CHECKERS(IOMMUMemoryRegion, IOMMUMemoryRegionClass,
>                       IOMMU_MEMORY_REGION, TYPE_IOMMU_MEMORY_REGION)
>
> -#define TYPE_RAM_DISCARD_MANAGER "qemu:ram-discard-manager"
> +#define TYPE_RAM_DISCARD_MANAGER "ram-discard-manager"
>  typedef struct RamDiscardManagerClass RamDiscardManagerClass;
>  typedef struct RamDiscardManager RamDiscardManager;
>  DECLARE_OBJ_CHECKERS(RamDiscardManager, RamDiscardManagerClass,
> --
> 2.42.0
>
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name
  2023-11-17 11:44 ` [PATCH v3 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name Thomas Huth
@ 2023-11-21  3:13   ` Alistair Francis
  0 siblings, 0 replies; 13+ messages in thread
From: Alistair Francis @ 2023-11-21  3:13 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel, Daniel P. Berrangé, Markus Armbruster,
	Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Philippe Mathieu-Daudé,
	Francisco Iglesias, Eduardo Habkost

On Fri, Nov 17, 2023 at 11:08 PM Thomas Huth <thuth@redhat.com> wrote:
>
> Type names should not contain special characters like ":" (so that
> they are easier to use with QAPI and other parts). We are going to
> forbid such names in an upcoming patch. Thus let's replace the ":"
> here with a "-".
>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  tests/unit/test-io-task.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tests/unit/test-io-task.c b/tests/unit/test-io-task.c
> index 953a50ae66..115dba8970 100644
> --- a/tests/unit/test-io-task.c
> +++ b/tests/unit/test-io-task.c
> @@ -25,7 +25,7 @@
>  #include "qapi/error.h"
>  #include "qemu/module.h"
>
> -#define TYPE_DUMMY "qemu:dummy"
> +#define TYPE_DUMMY "qemu-dummy"
>
>  typedef struct DummyObject DummyObject;
>  typedef struct DummyObjectClass DummyObjectClass;
> --
> 2.42.0
>
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 5/5] qom/object: Limit type names to alphanumerical and some few special characters
  2023-11-17 11:44 ` [PATCH v3 5/5] qom/object: Limit type names to alphanumerical and some few special characters Thomas Huth
  2023-11-17 12:25   ` Philippe Mathieu-Daudé
@ 2023-11-21  3:15   ` Alistair Francis
  1 sibling, 0 replies; 13+ messages in thread
From: Alistair Francis @ 2023-11-21  3:15 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel, Daniel P. Berrangé, Markus Armbruster,
	Alistair Francis, Edgar E. Iglesias, Peter Maydell, Paolo Bonzini,
	Peter Xu, David Hildenbrand, Philippe Mathieu-Daudé,
	Francisco Iglesias, Eduardo Habkost

On Fri, Nov 17, 2023 at 9:46 PM Thomas Huth <thuth@redhat.com> wrote:
>
> QOM names currently don't have any enforced naming rules. This
> can be problematic, e.g. when they are used on the command line
> for the "-device" option (where the comma is used to separate
> properties). To avoid that such problematic type names come in
> again, let's restrict the set of acceptable characters during the
> type registration.
>
> Ideally, we'd apply here the same rules as for QAPI, i.e. all type
> names should begin with a letter, and contain only ASCII letters,
> digits, hyphen, and underscore. However, we already have so many
> pre-existing types like:
>
>     486-x86_64-cpu
>     cfi.pflash01
>     power5+_v2.1-spapr-cpu-core
>     virt-2.6-machine
>     pc-i440fx-3.0-machine
>
> ... so that we have to allow "." and "+" for now, too. While the
> dot is used in a lot of places, the "+" can fortunately be limited
> to two classes of legacy names ("power" and "Sun-UltraSparc" CPUs).
>
> We also cannot enforce the rule that names must start with a letter
> yet, since there are lot of types that start with a digit. Still,
> at least limiting the first characters to the alphanumerical range
> should be way better than nothing.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  qom/object.c | 41 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 41 insertions(+)
>
> diff --git a/qom/object.c b/qom/object.c
> index 95c0dc8285..654e1afaf2 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -138,9 +138,50 @@ static TypeImpl *type_new(const TypeInfo *info)
>      return ti;
>  }
>
> +static bool type_name_is_valid(const char *name)
> +{
> +    const int slen = strlen(name);
> +    int plen;
> +
> +    g_assert(slen > 1);
> +
> +    /*
> +     * Ideally, the name should start with a letter - however, we've got
> +     * too many names starting with a digit already, so allow digits here,
> +     * too (except '0' which is not used yet)
> +     */
> +    if (!g_ascii_isalnum(name[0]) || name[0] == '0') {
> +        return false;
> +    }
> +
> +    plen = strspn(name, "abcdefghijklmnopqrstuvwxyz"
> +                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
> +                        "0123456789-_.");
> +
> +    /* Allow some legacy names with '+' in it for compatibility reasons */
> +    if (name[plen] == '+') {
> +        if (plen == 6 && g_str_has_prefix(name, "power")) {
> +            /* Allow "power5+" and "power7+" CPU names*/
> +            return true;
> +        }
> +        if (plen >= 17 && g_str_has_prefix(name, "Sun-UltraSparc-I")) {
> +            /* Allow "Sun-UltraSparc-IV+" and "Sun-UltraSparc-IIIi+" */
> +            return true;
> +        }
> +    }
> +
> +    return plen == slen;
> +}
> +
>  static TypeImpl *type_register_internal(const TypeInfo *info)
>  {
>      TypeImpl *ti;
> +
> +    if (!type_name_is_valid(info->name)) {
> +        fprintf(stderr, "Registering '%s' with illegal type name\n", info->name);
> +        abort();
> +    }
> +
>      ti = type_new(info);
>
>      type_table_add(ti);
> --
> 2.42.0
>
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-11-21  3:16 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-17 11:44 [PATCH v3 0/5] Limit type names to alphanumerical and some few special characters Thomas Huth
2023-11-17 11:44 ` [PATCH v3 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl" Thomas Huth
2023-11-21  3:10   ` Alistair Francis
2023-11-17 11:44 ` [PATCH v3 2/5] hw: Replace anti-social QOM type names (again) Thomas Huth
2023-11-21  3:11   ` Alistair Francis
2023-11-17 11:44 ` [PATCH v3 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name Thomas Huth
2023-11-21  3:13   ` Alistair Francis
2023-11-17 11:44 ` [PATCH v3 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name Thomas Huth
2023-11-21  3:13   ` Alistair Francis
2023-11-17 11:44 ` [PATCH v3 5/5] qom/object: Limit type names to alphanumerical and some few special characters Thomas Huth
2023-11-17 12:25   ` Philippe Mathieu-Daudé
2023-11-17 13:48     ` Thomas Huth
2023-11-21  3:15   ` Alistair Francis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).