* [PATCH v2 0/5] Limit type names to alphanumerical and some few special characters
@ 2023-11-16 13:14 Thomas Huth
2023-11-16 13:14 ` [PATCH v2 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-16 13:14 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
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.
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.41.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl"
2023-11-16 13:14 [PATCH v2 0/5] Limit type names to alphanumerical and some few special characters Thomas Huth
@ 2023-11-16 13:14 ` Thomas Huth
2023-11-16 13:40 ` Peter Maydell
2023-11-16 13:14 ` [PATCH v2 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-16 13:14 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
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]
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.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 2/5] hw: Replace anti-social QOM type names (again)
2023-11-16 13:14 [PATCH v2 0/5] Limit type names to alphanumerical and some few special characters Thomas Huth
2023-11-16 13:14 ` [PATCH v2 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl" Thomas Huth
@ 2023-11-16 13:14 ` Thomas Huth
2023-11-16 13:14 ` [PATCH v2 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name Thomas Huth
` (2 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Thomas Huth @ 2023-11-16 13:14 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
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.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name
2023-11-16 13:14 [PATCH v2 0/5] Limit type names to alphanumerical and some few special characters Thomas Huth
2023-11-16 13:14 ` [PATCH v2 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl" Thomas Huth
2023-11-16 13:14 ` [PATCH v2 2/5] hw: Replace anti-social QOM type names (again) Thomas Huth
@ 2023-11-16 13:14 ` Thomas Huth
2023-11-16 13:24 ` David Hildenbrand
2023-11-16 15:45 ` Philippe Mathieu-Daudé
2023-11-16 13:14 ` [PATCH v2 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name Thomas Huth
2023-11-16 13:14 ` [PATCH v2 5/5] qom/object: Limit type names to alphanumerical and some few special characters Thomas Huth
4 siblings, 2 replies; 13+ messages in thread
From: Thomas Huth @ 2023-11-16 13:14 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
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, so the renaming should not affect
the user interface or migration.
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.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name
2023-11-16 13:14 [PATCH v2 0/5] Limit type names to alphanumerical and some few special characters Thomas Huth
` (2 preceding siblings ...)
2023-11-16 13:14 ` [PATCH v2 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name Thomas Huth
@ 2023-11-16 13:14 ` Thomas Huth
2023-11-16 13:25 ` Daniel P. Berrangé
2023-11-16 15:45 ` Philippe Mathieu-Daudé
2023-11-16 13:14 ` [PATCH v2 5/5] qom/object: Limit type names to alphanumerical and some few special characters Thomas Huth
4 siblings, 2 replies; 13+ messages in thread
From: Thomas Huth @ 2023-11-16 13:14 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
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 "-".
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.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 5/5] qom/object: Limit type names to alphanumerical and some few special characters
2023-11-16 13:14 [PATCH v2 0/5] Limit type names to alphanumerical and some few special characters Thomas Huth
` (3 preceding siblings ...)
2023-11-16 13:14 ` [PATCH v2 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name Thomas Huth
@ 2023-11-16 13:14 ` Thomas Huth
2023-11-16 13:24 ` Daniel P. Berrangé
4 siblings, 1 reply; 13+ messages in thread
From: Thomas Huth @ 2023-11-16 13:14 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
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..571ef68950 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);
+
+ 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;
+ }
+
+ for (int i = 1; i < slen; i++) {
+ if (name[i] != '-' && name[i] != '_' && name[i] != '.' &&
+ !g_ascii_isalnum(name[i])) {
+ if (name[i] == '+') {
+ if (i == 6 && !strncmp(name, "power", 5)) {
+ /* It's a legacy name like "power5+" */
+ continue;
+ }
+ if (i >= 17 && !strncmp(name, "Sun-UltraSparc", 14)) {
+ /* It's a legacy name like "Sun-UltraSparc-IV+" */
+ continue;
+ }
+ }
+ return false;
+ }
+ }
+
+ return true;
+}
+
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.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 5/5] qom/object: Limit type names to alphanumerical and some few special characters
2023-11-16 13:14 ` [PATCH v2 5/5] qom/object: Limit type names to alphanumerical and some few special characters Thomas Huth
@ 2023-11-16 13:24 ` Daniel P. Berrangé
2023-11-16 17:54 ` Thomas Huth
0 siblings, 1 reply; 13+ messages in thread
From: Daniel P. Berrangé @ 2023-11-16 13:24 UTC (permalink / raw)
To: Thomas Huth
Cc: qemu-devel, Markus Armbruster, Alistair Francis,
Edgar E. Iglesias, Peter Maydell, Paolo Bonzini, Peter Xu,
David Hildenbrand, Philippe Mathieu-Daudé,
Francisco Iglesias, Eduardo Habkost
On Thu, Nov 16, 2023 at 02:14:54PM +0100, 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..571ef68950 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);
> +
> + 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;
> + }
> +
> + for (int i = 1; i < slen; i++) {
> + if (name[i] != '-' && name[i] != '_' && name[i] != '.' &&
> + !g_ascii_isalnum(name[i])) {
> + if (name[i] == '+') {
> + if (i == 6 && !strncmp(name, "power", 5)) {
> + /* It's a legacy name like "power5+" */
> + continue;
> + }
> + if (i >= 17 && !strncmp(name, "Sun-UltraSparc", 14)) {
> + /* It's a legacy name like "Sun-UltraSparc-IV+" */
> + continue;
> + }
> + }
> + return false;
> + }
> + }
Replace this big loop with strspn, which has an asm optimized impl
in glibc
ALPHA_LC "abcdefghijklmnopqrstuvwxyz"
ALPHA_UC "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
OTHER "0123456789-_."
return (strspn(name, ALPHA_UC ALPHA_LC OTHER) == slen) ||
(g_str_has_prefix(name, "power") && slen > 6 && name[6] == '+') ||
(g_str_has_prefix(name, "Sun-UltraSparc") && slen > 17 && name[17] == '+');
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name
2023-11-16 13:14 ` [PATCH v2 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name Thomas Huth
@ 2023-11-16 13:24 ` David Hildenbrand
2023-11-16 15:45 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 13+ messages in thread
From: David Hildenbrand @ 2023-11-16 13:24 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, Philippe Mathieu-Daudé, Francisco Iglesias,
Eduardo Habkost
On 16.11.23 14:14, Thomas Huth 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, so the renaming should not affect
> the user interface or migration.
>
> 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,
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name
2023-11-16 13:14 ` [PATCH v2 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name Thomas Huth
@ 2023-11-16 13:25 ` Daniel P. Berrangé
2023-11-16 15:45 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 13+ messages in thread
From: Daniel P. Berrangé @ 2023-11-16 13:25 UTC (permalink / raw)
To: Thomas Huth
Cc: qemu-devel, Markus Armbruster, Alistair Francis,
Edgar E. Iglesias, Peter Maydell, Paolo Bonzini, Peter Xu,
David Hildenbrand, Philippe Mathieu-Daudé,
Francisco Iglesias, Eduardo Habkost
On Thu, Nov 16, 2023 at 02:14:53PM +0100, Thomas Huth 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 "-".
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> tests/unit/test-io-task.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl"
2023-11-16 13:14 ` [PATCH v2 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl" Thomas Huth
@ 2023-11-16 13:40 ` Peter Maydell
0 siblings, 0 replies; 13+ messages in thread
From: Peter Maydell @ 2023-11-16 13:40 UTC (permalink / raw)
To: Thomas Huth
Cc: qemu-devel, Daniel P. Berrangé, Markus Armbruster,
Alistair Francis, Edgar E. Iglesias, Paolo Bonzini, Peter Xu,
David Hildenbrand, Philippe Mathieu-Daudé,
Francisco Iglesias, Eduardo Habkost
On Thu, 16 Nov 2023 at 13:15, 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]
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name
2023-11-16 13:14 ` [PATCH v2 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name Thomas Huth
2023-11-16 13:24 ` David Hildenbrand
@ 2023-11-16 15:45 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-11-16 15:45 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 16/11/23 14:14, Thomas Huth 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, so the renaming should not affect
> the user interface or migration.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> include/exec/memory.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name
2023-11-16 13:14 ` [PATCH v2 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name Thomas Huth
2023-11-16 13:25 ` Daniel P. Berrangé
@ 2023-11-16 15:45 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-11-16 15:45 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 16/11/23 14:14, Thomas Huth 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 "-".
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> tests/unit/test-io-task.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 5/5] qom/object: Limit type names to alphanumerical and some few special characters
2023-11-16 13:24 ` Daniel P. Berrangé
@ 2023-11-16 17:54 ` Thomas Huth
0 siblings, 0 replies; 13+ messages in thread
From: Thomas Huth @ 2023-11-16 17:54 UTC (permalink / raw)
To: Daniel P. Berrangé
Cc: qemu-devel, Markus Armbruster, Alistair Francis,
Edgar E. Iglesias, Peter Maydell, Paolo Bonzini, Peter Xu,
David Hildenbrand, Philippe Mathieu-Daudé,
Francisco Iglesias, Eduardo Habkost
On 16/11/2023 14.24, Daniel P. Berrangé wrote:
> On Thu, Nov 16, 2023 at 02:14:54PM +0100, 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..571ef68950 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);
>> +
>> + 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;
>> + }
>> +
>> + for (int i = 1; i < slen; i++) {
>> + if (name[i] != '-' && name[i] != '_' && name[i] != '.' &&
>> + !g_ascii_isalnum(name[i])) {
>> + if (name[i] == '+') {
>> + if (i == 6 && !strncmp(name, "power", 5)) {
>> + /* It's a legacy name like "power5+" */
>> + continue;
>> + }
>> + if (i >= 17 && !strncmp(name, "Sun-UltraSparc", 14)) {
>> + /* It's a legacy name like "Sun-UltraSparc-IV+" */
>> + continue;
>> + }
>> + }
>> + return false;
>> + }
>> + }
>
> Replace this big loop with strspn, which has an asm optimized impl
> in glibc
>
> ALPHA_LC "abcdefghijklmnopqrstuvwxyz"
> ALPHA_UC "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
> OTHER "0123456789-_."
>
> return (strspn(name, ALPHA_UC ALPHA_LC OTHER) == slen) ||
> (g_str_has_prefix(name, "power") && slen > 6 && name[6] == '+') ||
> (g_str_has_prefix(name, "Sun-UltraSparc") && slen > 17 && name[17] == '+');
It's quite hard to believe that a function that has to check each and every
character in a string of acceptable characters is faster than a function
that uses something like g_ascii_asalnum which can check range of characters
in one go...
So I gave it a try, wrote two test programs, one with my implementation and
one with yours, and looped on the function 1000000000 times. And indeed, for
short strings (less than 30 characters), my function is about three times
faster than the one with strspn() (mine takes ~ 13 seconds, the strspn() one
takes ~ 39 seconds).
Interestingly, for larger strings (more than 140 characters), the strspn()
impementation starts to perform better. They indeed must have an
optimization that kicks in for larger strings.
Now while my implementation seems to be a little bit faster for the strings
that we are using in QEMU, we certainly don't have 1000000000 different
types in QEMU, but rather only 1300 or so, so the performance shouldn't
really matter that much here. And I have to admit that your code is indeed
more compact to read, so I'll give it a try.
Thomas
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-11-16 17:55 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-16 13:14 [PATCH v2 0/5] Limit type names to alphanumerical and some few special characters Thomas Huth
2023-11-16 13:14 ` [PATCH v2 1/5] docs/system/arm: Fix for rename of type "xlnx.bbram-ctrl" Thomas Huth
2023-11-16 13:40 ` Peter Maydell
2023-11-16 13:14 ` [PATCH v2 2/5] hw: Replace anti-social QOM type names (again) Thomas Huth
2023-11-16 13:14 ` [PATCH v2 3/5] memory: Remove "qemu:" prefix from the "qemu:ram-discard-manager" type name Thomas Huth
2023-11-16 13:24 ` David Hildenbrand
2023-11-16 15:45 ` Philippe Mathieu-Daudé
2023-11-16 13:14 ` [PATCH v2 4/5] tests/unit/test-io-task: Rename "qemu:dummy" to avoid colon in the name Thomas Huth
2023-11-16 13:25 ` Daniel P. Berrangé
2023-11-16 15:45 ` Philippe Mathieu-Daudé
2023-11-16 13:14 ` [PATCH v2 5/5] qom/object: Limit type names to alphanumerical and some few special characters Thomas Huth
2023-11-16 13:24 ` Daniel P. Berrangé
2023-11-16 17:54 ` Thomas Huth
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).