All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/11] user-mode: Prune build dependencies (part 3)
@ 2020-09-30 16:49 Philippe Mathieu-Daudé
  2020-09-30 16:49 ` [PATCH v3 01/11] qapi: Restrict query-uuid command to block code Philippe Mathieu-Daudé
                   ` (11 more replies)
  0 siblings, 12 replies; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-30 16:49 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, Michael Roth, Eduardo Habkost, Markus Armbruster,
	Paolo Bonzini, Max Reitz, Richard Henderson

This is the third part of a series reducing user-mode
dependencies. By stripping out unused code, the build
and testing time is reduced (as is space used by objects).

Part 3:
- Extract code not related to user-mode from hw/core/qdev-properties.c
- Reduce user-mode QAPI generated files

Since v2:
- Fixed UuidInfo placed in incorrect json
- Rebased on Meson
- Include X86CPUFeatureWord unmerged from part 2

Since v1:
- Addressed Richard and Paolo review comments

Patches missing review: QAPI ones :)
- #1  'qapi: Restrict query-uuid command to block code'
- #11 'qapi: Restrict code generated for user-mode'

Green CI: https://gitlab.com/philmd/qemu/-/pipelines/196505787

v2: https://www.mail-archive.com/qemu-devel@nongnu.org/msg688879.html
v1: https://www.mail-archive.com/qemu-devel@nongnu.org/msg688486.html

Philippe Mathieu-Daudé (11):
  qapi: Restrict query-uuid command to block code
  hw/core/qdev-properties: Use qemu_strtol() in set_mac() handler
  hw/core/qdev-properties: Use qemu_strtoul() in set_pci_host_devaddr()
  hw/core/qdev-properties: Fix code style
  hw/core/qdev-properties: Export enum-related functions
  hw/core/qdev-properties: Export qdev_prop_enum
  hw/core/qdev-properties: Export some integer-related functions
  hw/core/qdev-properties: Extract system-mode specific properties
  hw/core: Add qdev stub for user-mode
  target/i386: Restrict X86CPUFeatureWord to X86 targets
  qapi: Restrict code generated for user-mode

 qapi/block.json                  |  30 ++
 qapi/machine-target.json         |  45 ++
 qapi/machine.json                |  72 ---
 hw/core/qdev-prop-internal.h     |  30 ++
 include/hw/qdev-properties.h     |   1 +
 block/iscsi.c                    |   2 +-
 hw/core/qdev-properties-system.c | 687 ++++++++++++++++++++++++++++-
 hw/core/qdev-properties.c        | 735 ++-----------------------------
 stubs/qdev-system.c              |  24 +
 stubs/uuid.c                     |   2 +-
 target/i386/cpu.c                |   2 +-
 target/i386/feature-stub.c       |  23 +
 qapi/meson.build                 |  51 ++-
 stubs/meson.build                |   5 +-
 target/i386/meson.build          |   1 +
 15 files changed, 915 insertions(+), 795 deletions(-)
 create mode 100644 hw/core/qdev-prop-internal.h
 create mode 100644 stubs/qdev-system.c
 create mode 100644 target/i386/feature-stub.c

-- 
2.26.2



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

* [PATCH v3 01/11] qapi: Restrict query-uuid command to block code
  2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
@ 2020-09-30 16:49 ` Philippe Mathieu-Daudé
  2020-10-01  5:04   ` Markus Armbruster
  2020-09-30 16:49 ` [PATCH v3 02/11] hw/core/qdev-properties: Use qemu_strtol() in set_mac() handler Philippe Mathieu-Daudé
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-30 16:49 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, Michael Roth, Eduardo Habkost, Markus Armbruster,
	Paolo Bonzini, Max Reitz, Richard Henderson

In commit f68c01470b we restricted the query-uuid command to
machine code, but it is incorrect, as it is also used by the
tools.  Therefore move this command again, but to block.json,
which is shared by machine code and tools.

Fixes: f68c01470b ("qapi: Restrict query-uuid command to machine code")
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 qapi/block.json   | 30 ++++++++++++++++++++++++++++++
 qapi/machine.json | 30 ------------------------------
 block/iscsi.c     |  2 +-
 stubs/uuid.c      |  2 +-
 stubs/meson.build |  4 +++-
 5 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/qapi/block.json b/qapi/block.json
index a009f7d3a2..4ae1716b56 100644
--- a/qapi/block.json
+++ b/qapi/block.json
@@ -11,6 +11,36 @@
 # == Additional block stuff (VM related)
 ##
 
+##
+# @UuidInfo:
+#
+# Guest UUID information (Universally Unique Identifier).
+#
+# @UUID: the UUID of the guest
+#
+# Since: 0.14.0
+#
+# Notes: If no UUID was specified for the guest, a null UUID is returned.
+##
+{ 'struct': 'UuidInfo', 'data': {'UUID': 'str'} }
+
+##
+# @query-uuid:
+#
+# Query the guest UUID information.
+#
+# Returns: The @UuidInfo for the guest
+#
+# Since: 0.14.0
+#
+# Example:
+#
+# -> { "execute": "query-uuid" }
+# <- { "return": { "UUID": "550e8400-e29b-41d4-a716-446655440000" } }
+#
+##
+{ 'command': 'query-uuid', 'returns': 'UuidInfo', 'allow-preconfig': true }
+
 ##
 # @BiosAtaTranslation:
 #
diff --git a/qapi/machine.json b/qapi/machine.json
index 756dacb06f..72f014bb5b 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -402,36 +402,6 @@
 ##
 { 'command': 'query-target', 'returns': 'TargetInfo' }
 
-##
-# @UuidInfo:
-#
-# Guest UUID information (Universally Unique Identifier).
-#
-# @UUID: the UUID of the guest
-#
-# Since: 0.14.0
-#
-# Notes: If no UUID was specified for the guest, a null UUID is returned.
-##
-{ 'struct': 'UuidInfo', 'data': {'UUID': 'str'} }
-
-##
-# @query-uuid:
-#
-# Query the guest UUID information.
-#
-# Returns: The @UuidInfo for the guest
-#
-# Since: 0.14.0
-#
-# Example:
-#
-# -> { "execute": "query-uuid" }
-# <- { "return": { "UUID": "550e8400-e29b-41d4-a716-446655440000" } }
-#
-##
-{ 'command': 'query-uuid', 'returns': 'UuidInfo', 'allow-preconfig': true }
-
 ##
 # @GuidInfo:
 #
diff --git a/block/iscsi.c b/block/iscsi.c
index e30a7e3606..1effea25ed 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -42,7 +42,7 @@
 #include "qemu/uuid.h"
 #include "sysemu/replay.h"
 #include "qapi/error.h"
-#include "qapi/qapi-commands-machine.h"
+#include "qapi/qapi-commands-block.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
 #include "crypto/secret.h"
diff --git a/stubs/uuid.c b/stubs/uuid.c
index e5112eb3f6..d6bfb442e0 100644
--- a/stubs/uuid.c
+++ b/stubs/uuid.c
@@ -1,5 +1,5 @@
 #include "qemu/osdep.h"
-#include "qapi/qapi-commands-machine.h"
+#include "qapi/qapi-commands-block.h"
 #include "qemu/uuid.h"
 
 UuidInfo *qmp_query_uuid(Error **errp)
diff --git a/stubs/meson.build b/stubs/meson.build
index e0b322bc28..2e231590e1 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -39,7 +39,9 @@ stub_ss.add(files('target-get-monitor-def.c'))
 stub_ss.add(files('target-monitor-defs.c'))
 stub_ss.add(files('tpm.c'))
 stub_ss.add(files('trace-control.c'))
-stub_ss.add(files('uuid.c'))
+if have_block
+  stub_ss.add(files('uuid.c'))
+endif
 stub_ss.add(files('vmgenid.c'))
 stub_ss.add(files('vmstate.c'))
 stub_ss.add(files('vm-stop.c'))
-- 
2.26.2



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

* [PATCH v3 02/11] hw/core/qdev-properties: Use qemu_strtol() in set_mac() handler
  2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
  2020-09-30 16:49 ` [PATCH v3 01/11] qapi: Restrict query-uuid command to block code Philippe Mathieu-Daudé
@ 2020-09-30 16:49 ` Philippe Mathieu-Daudé
  2020-09-30 16:49 ` [PATCH v3 03/11] hw/core/qdev-properties: Use qemu_strtoul() in set_pci_host_devaddr() Philippe Mathieu-Daudé
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-30 16:49 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, Michael Roth, Eduardo Habkost, Markus Armbruster,
	Richard Henderson, Paolo Bonzini, Max Reitz, Richard Henderson

The MACAddr structure contains an array of uint8_t. Previously
if a value was out of the [0..255] range, it was silently casted
and no input validation was done.
Replace strtol() by qemu_strtol() -- so checkpatch.pl won't
complain if we move this code later -- and return EINVAL if the
input is invalid.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/core/qdev-properties.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 343c824da0..080ba319a1 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1,4 +1,5 @@
 #include "qemu/osdep.h"
+#include "qemu/cutils.h"
 #include "net/net.h"
 #include "hw/qdev-properties.h"
 #include "qapi/error.h"
@@ -524,7 +525,8 @@ static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque,
     Property *prop = opaque;
     MACAddr *mac = qdev_get_prop_ptr(dev, prop);
     int i, pos;
-    char *str, *p;
+    char *str;
+    const char *p;
 
     if (dev->realized) {
         qdev_prop_set_after_realize(dev, name, errp);
@@ -536,6 +538,8 @@ static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque,
     }
 
     for (i = 0, pos = 0; i < 6; i++, pos += 3) {
+        long val;
+
         if (!qemu_isxdigit(str[pos])) {
             goto inval;
         }
@@ -551,7 +555,10 @@ static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque,
                 goto inval;
             }
         }
-        mac->a[i] = strtol(str+pos, &p, 16);
+        if (qemu_strtol(str + pos, &p, 16, &val) < 0 || val > 0xff) {
+            goto inval;
+        }
+        mac->a[i] = val;
     }
     g_free(str);
     return;
-- 
2.26.2



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

* [PATCH v3 03/11] hw/core/qdev-properties: Use qemu_strtoul() in set_pci_host_devaddr()
  2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
  2020-09-30 16:49 ` [PATCH v3 01/11] qapi: Restrict query-uuid command to block code Philippe Mathieu-Daudé
  2020-09-30 16:49 ` [PATCH v3 02/11] hw/core/qdev-properties: Use qemu_strtol() in set_mac() handler Philippe Mathieu-Daudé
@ 2020-09-30 16:49 ` Philippe Mathieu-Daudé
  2020-09-30 16:49 ` [PATCH v3 04/11] hw/core/qdev-properties: Fix code style Philippe Mathieu-Daudé
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-30 16:49 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, Michael Roth, Eduardo Habkost, Markus Armbruster,
	Richard Henderson, Paolo Bonzini, Max Reitz, Richard Henderson

Replace strtoul() by qemu_strtoul() so checkpatch.pl won't complain
if we move this code later.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/core/qdev-properties.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 080ba319a1..a1190a5db9 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -951,7 +951,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
     Property *prop = opaque;
     PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
     char *str, *p;
-    char *e;
+    const char *e;
     unsigned long val;
     unsigned long dom = 0, bus = 0;
     unsigned int slot = 0, func = 0;
@@ -966,23 +966,23 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
     }
 
     p = str;
-    val = strtoul(p, &e, 16);
-    if (e == p || *e != ':') {
+    if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0xffff || e == p) {
+        goto inval;
+    }
+    if (*e != ':') {
         goto inval;
     }
     bus = val;
 
-    p = e + 1;
-    val = strtoul(p, &e, 16);
-    if (e == p) {
+    p = (char *)e + 1;
+    if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e == p) {
         goto inval;
     }
     if (*e == ':') {
         dom = bus;
         bus = val;
-        p = e + 1;
-        val = strtoul(p, &e, 16);
-        if (e == p) {
+        p = (char *)e + 1;
+        if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e == p) {
             goto inval;
         }
     }
@@ -991,14 +991,13 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
     if (*e != '.') {
         goto inval;
     }
-    p = e + 1;
-    val = strtoul(p, &e, 10);
-    if (e == p) {
+    p = (char *)e + 1;
+    if (qemu_strtoul(p, &e, 10, &val) < 0 || val > 7 || e == p) {
         goto inval;
     }
     func = val;
 
-    if (dom > 0xffff || bus > 0xff || slot > 0x1f || func > 7) {
+    if (bus > 0xff) {
         goto inval;
     }
 
-- 
2.26.2



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

* [PATCH v3 04/11] hw/core/qdev-properties: Fix code style
  2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2020-09-30 16:49 ` [PATCH v3 03/11] hw/core/qdev-properties: Use qemu_strtoul() in set_pci_host_devaddr() Philippe Mathieu-Daudé
@ 2020-09-30 16:49 ` Philippe Mathieu-Daudé
  2020-09-30 16:49 ` [PATCH v3 05/11] hw/core/qdev-properties: Export enum-related functions Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-30 16:49 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, Michael Roth, Eduardo Habkost, Markus Armbruster,
	Richard Henderson, Paolo Bonzini, Max Reitz, Richard Henderson

We will soon move this code, fix its style to avoid checkpatch.pl
to complain.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/core/qdev-properties.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index a1190a5db9..071fd5864a 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -543,15 +543,15 @@ static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque,
         if (!qemu_isxdigit(str[pos])) {
             goto inval;
         }
-        if (!qemu_isxdigit(str[pos+1])) {
+        if (!qemu_isxdigit(str[pos + 1])) {
             goto inval;
         }
         if (i == 5) {
-            if (str[pos+2] != '\0') {
+            if (str[pos + 2] != '\0') {
                 goto inval;
             }
         } else {
-            if (str[pos+2] != ':' && str[pos+2] != '-') {
+            if (str[pos + 2] != ':' && str[pos + 2] != '-') {
                 goto inval;
             }
         }
@@ -898,8 +898,8 @@ static void set_blocksize(Object *obj, Visitor *v, const char *name,
     /* We rely on power-of-2 blocksizes for bitmasks */
     if ((value & (value - 1)) != 0) {
         error_setg(errp,
-                  "Property %s.%s doesn't take value '%" PRId64 "', it's not a power of 2",
-                  dev->id ?: "", name, (int64_t)value);
+                  "Property %s.%s doesn't take value '%" PRId64 "', "
+                  "it's not a power of 2", dev->id ?: "", name, (int64_t)value);
         return;
     }
 
-- 
2.26.2



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

* [PATCH v3 05/11] hw/core/qdev-properties: Export enum-related functions
  2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2020-09-30 16:49 ` [PATCH v3 04/11] hw/core/qdev-properties: Fix code style Philippe Mathieu-Daudé
@ 2020-09-30 16:49 ` Philippe Mathieu-Daudé
  2020-09-30 16:49 ` [PATCH v3 06/11] hw/core/qdev-properties: Export qdev_prop_enum Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-30 16:49 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, Michael Roth, Eduardo Habkost, Markus Armbruster,
	Richard Henderson, Paolo Bonzini, Max Reitz, Richard Henderson

We are going to split this file and reuse these static functions.
Add the local "qdev-prop-internal.h" header declaring them.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/core/qdev-prop-internal.h | 19 ++++++++++++
 hw/core/qdev-properties.c    | 58 +++++++++++++++++++-----------------
 2 files changed, 49 insertions(+), 28 deletions(-)
 create mode 100644 hw/core/qdev-prop-internal.h

diff --git a/hw/core/qdev-prop-internal.h b/hw/core/qdev-prop-internal.h
new file mode 100644
index 0000000000..2a8c9a306a
--- /dev/null
+++ b/hw/core/qdev-prop-internal.h
@@ -0,0 +1,19 @@
+/*
+ * qdev property parsing
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef HW_CORE_QDEV_PROP_INTERNAL_H
+#define HW_CORE_QDEV_PROP_INTERNAL_H
+
+void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name,
+                            void *opaque, Error **errp);
+void qdev_propinfo_set_enum(Object *obj, Visitor *v, const char *name,
+                            void *opaque, Error **errp);
+
+void qdev_propinfo_set_default_value_enum(ObjectProperty *op,
+                                          const Property *prop);
+
+#endif
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 071fd5864a..76417d0936 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -18,6 +18,7 @@
 #include "qemu/uuid.h"
 #include "qemu/units.h"
 #include "qemu/cutils.h"
+#include "qdev-prop-internal.h"
 
 void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
                                   Error **errp)
@@ -53,8 +54,8 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
     return ptr;
 }
 
-static void get_enum(Object *obj, Visitor *v, const char *name, void *opaque,
-                     Error **errp)
+void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name,
+                            void *opaque, Error **errp)
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
@@ -63,8 +64,8 @@ static void get_enum(Object *obj, Visitor *v, const char *name, void *opaque,
     visit_type_enum(v, prop->name, ptr, prop->info->enum_table, errp);
 }
 
-static void set_enum(Object *obj, Visitor *v, const char *name, void *opaque,
-                     Error **errp)
+void qdev_propinfo_set_enum(Object *obj, Visitor *v, const char *name,
+                            void *opaque, Error **errp)
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
@@ -78,7 +79,8 @@ static void set_enum(Object *obj, Visitor *v, const char *name, void *opaque,
     visit_type_enum(v, prop->name, ptr, prop->info->enum_table, errp);
 }
 
-static void set_default_value_enum(ObjectProperty *op, const Property *prop)
+void qdev_propinfo_set_default_value_enum(ObjectProperty *op,
+                                          const Property *prop)
 {
     object_property_set_default_str(op,
         qapi_enum_lookup(prop->info->enum_table, prop->defval.i));
@@ -669,9 +671,9 @@ const PropertyInfo qdev_prop_on_off_auto = {
     .name = "OnOffAuto",
     .description = "on/off/auto",
     .enum_table = &OnOffAuto_lookup,
-    .get = get_enum,
-    .set = set_enum,
-    .set_default_value = set_default_value_enum,
+    .get = qdev_propinfo_get_enum,
+    .set = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
 };
 
 /* --- lost tick policy --- */
@@ -681,9 +683,9 @@ QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) != sizeof(int));
 const PropertyInfo qdev_prop_losttickpolicy = {
     .name  = "LostTickPolicy",
     .enum_table  = &LostTickPolicy_lookup,
-    .get   = get_enum,
-    .set   = set_enum,
-    .set_default_value = set_default_value_enum,
+    .get   = qdev_propinfo_get_enum,
+    .set   = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
 };
 
 /* --- Block device error handling policy --- */
@@ -695,9 +697,9 @@ const PropertyInfo qdev_prop_blockdev_on_error = {
     .description = "Error handling policy, "
                    "report/ignore/enospc/stop/auto",
     .enum_table = &BlockdevOnError_lookup,
-    .get = get_enum,
-    .set = set_enum,
-    .set_default_value = set_default_value_enum,
+    .get = qdev_propinfo_get_enum,
+    .set = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
 };
 
 /* --- BIOS CHS translation */
@@ -709,9 +711,9 @@ const PropertyInfo qdev_prop_bios_chs_trans = {
     .description = "Logical CHS translation algorithm, "
                    "auto/none/lba/large/rechs",
     .enum_table = &BiosAtaTranslation_lookup,
-    .get = get_enum,
-    .set = set_enum,
-    .set_default_value = set_default_value_enum,
+    .get = qdev_propinfo_get_enum,
+    .set = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
 };
 
 /* --- FDC default drive types */
@@ -721,9 +723,9 @@ const PropertyInfo qdev_prop_fdc_drive_type = {
     .description = "FDC drive type, "
                    "144/288/120/none/auto",
     .enum_table = &FloppyDriveType_lookup,
-    .get = get_enum,
-    .set = set_enum,
-    .set_default_value = set_default_value_enum,
+    .get = qdev_propinfo_get_enum,
+    .set = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
 };
 
 /* --- MultiFDCompression --- */
@@ -733,9 +735,9 @@ const PropertyInfo qdev_prop_multifd_compression = {
     .description = "multifd_compression values, "
                    "none/zlib/zstd",
     .enum_table = &MultiFDCompression_lookup,
-    .get = get_enum,
-    .set = set_enum,
-    .set_default_value = set_default_value_enum,
+    .get = qdev_propinfo_get_enum,
+    .set = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
 };
 
 /* --- pci address --- */
@@ -1416,9 +1418,9 @@ const PropertyInfo qdev_prop_off_auto_pcibar = {
     .name = "OffAutoPCIBAR",
     .description = "off/auto/bar0/bar1/bar2/bar3/bar4/bar5",
     .enum_table = &OffAutoPCIBAR_lookup,
-    .get = get_enum,
-    .set = set_enum,
-    .set_default_value = set_default_value_enum,
+    .get = qdev_propinfo_get_enum,
+    .set = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
 };
 
 /* --- PCIELinkSpeed 2_5/5/8/16 -- */
@@ -1495,7 +1497,7 @@ const PropertyInfo qdev_prop_pcie_link_speed = {
     .enum_table = &PCIELinkSpeed_lookup,
     .get = get_prop_pcielinkspeed,
     .set = set_prop_pcielinkspeed,
-    .set_default_value = set_default_value_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
 };
 
 /* --- PCIELinkWidth 1/2/4/8/12/16/32 -- */
@@ -1590,5 +1592,5 @@ const PropertyInfo qdev_prop_pcie_link_width = {
     .enum_table = &PCIELinkWidth_lookup,
     .get = get_prop_pcielinkwidth,
     .set = set_prop_pcielinkwidth,
-    .set_default_value = set_default_value_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
 };
-- 
2.26.2



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

* [PATCH v3 06/11] hw/core/qdev-properties: Export qdev_prop_enum
  2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2020-09-30 16:49 ` [PATCH v3 05/11] hw/core/qdev-properties: Export enum-related functions Philippe Mathieu-Daudé
@ 2020-09-30 16:49 ` Philippe Mathieu-Daudé
  2020-09-30 16:49 ` [PATCH v3 07/11] hw/core/qdev-properties: Export some integer-related functions Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-30 16:49 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, Michael Roth, Eduardo Habkost, Markus Armbruster,
	Richard Henderson, Paolo Bonzini, Max Reitz, Richard Henderson

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/hw/qdev-properties.h | 1 +
 hw/core/qdev-properties.c    | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 528310bb22..4437450065 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -8,6 +8,7 @@
 extern const PropertyInfo qdev_prop_bit;
 extern const PropertyInfo qdev_prop_bit64;
 extern const PropertyInfo qdev_prop_bool;
+extern const PropertyInfo qdev_prop_enum;
 extern const PropertyInfo qdev_prop_uint8;
 extern const PropertyInfo qdev_prop_uint16;
 extern const PropertyInfo qdev_prop_uint32;
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 76417d0936..31dfe441e2 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -86,6 +86,13 @@ void qdev_propinfo_set_default_value_enum(ObjectProperty *op,
         qapi_enum_lookup(prop->info->enum_table, prop->defval.i));
 }
 
+const PropertyInfo qdev_prop_enum = {
+    .name  = "enum",
+    .get   = qdev_propinfo_get_enum,
+    .set   = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
+};
+
 /* Bit */
 
 static uint32_t qdev_get_prop_mask(Property *prop)
-- 
2.26.2



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

* [PATCH v3 07/11] hw/core/qdev-properties: Export some integer-related functions
  2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2020-09-30 16:49 ` [PATCH v3 06/11] hw/core/qdev-properties: Export qdev_prop_enum Philippe Mathieu-Daudé
@ 2020-09-30 16:49 ` Philippe Mathieu-Daudé
  2020-09-30 16:49 ` [PATCH v3 08/11] hw/core/qdev-properties: Extract system-mode specific properties Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-30 16:49 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, Michael Roth, Eduardo Habkost, Markus Armbruster,
	Richard Henderson, Paolo Bonzini, Max Reitz, Richard Henderson

We are going to split this file and reuse these static functions.
Declare them in the local "qdev-prop-internal.h" header.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v3:
Also export qdev_propinfo_get_size32 introduced in commits
914e74cda9 ("qdev-properties: add size32 property type") and
031ffd9a61 ("qdev-properties: add getter for size32 and blocksize").
---
 hw/core/qdev-prop-internal.h | 11 +++++++++
 hw/core/qdev-properties.c    | 46 +++++++++++++++++++-----------------
 2 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/hw/core/qdev-prop-internal.h b/hw/core/qdev-prop-internal.h
index 2a8c9a306a..9cf5cc1d51 100644
--- a/hw/core/qdev-prop-internal.h
+++ b/hw/core/qdev-prop-internal.h
@@ -15,5 +15,16 @@ void qdev_propinfo_set_enum(Object *obj, Visitor *v, const char *name,
 
 void qdev_propinfo_set_default_value_enum(ObjectProperty *op,
                                           const Property *prop);
+void qdev_propinfo_set_default_value_int(ObjectProperty *op,
+                                         const Property *prop);
+void qdev_propinfo_set_default_value_uint(ObjectProperty *op,
+                                          const Property *prop);
+
+void qdev_propinfo_get_uint16(Object *obj, Visitor *v, const char *name,
+                              void *opaque, Error **errp);
+void qdev_propinfo_get_int32(Object *obj, Visitor *v, const char *name,
+                             void *opaque, Error **errp);
+void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name,
+                              void *opaque, Error **errp);
 
 #endif
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 31dfe441e2..37e309077a 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -271,12 +271,14 @@ static void set_uint8(Object *obj, Visitor *v, const char *name, void *opaque,
     visit_type_uint8(v, name, ptr, errp);
 }
 
-static void set_default_value_int(ObjectProperty *op, const Property *prop)
+void qdev_propinfo_set_default_value_int(ObjectProperty *op,
+                                         const Property *prop)
 {
     object_property_set_default_int(op, prop->defval.i);
 }
 
-static void set_default_value_uint(ObjectProperty *op, const Property *prop)
+void qdev_propinfo_set_default_value_uint(ObjectProperty *op,
+                                          const Property *prop)
 {
     object_property_set_default_uint(op, prop->defval.u);
 }
@@ -285,13 +287,13 @@ const PropertyInfo qdev_prop_uint8 = {
     .name  = "uint8",
     .get   = get_uint8,
     .set   = set_uint8,
-    .set_default_value = set_default_value_uint,
+    .set_default_value = qdev_propinfo_set_default_value_uint,
 };
 
 /* --- 16bit integer --- */
 
-static void get_uint16(Object *obj, Visitor *v, const char *name,
-                       void *opaque, Error **errp)
+void qdev_propinfo_get_uint16(Object *obj, Visitor *v, const char *name,
+                              void *opaque, Error **errp)
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
@@ -317,9 +319,9 @@ static void set_uint16(Object *obj, Visitor *v, const char *name,
 
 const PropertyInfo qdev_prop_uint16 = {
     .name  = "uint16",
-    .get   = get_uint16,
+    .get   = qdev_propinfo_get_uint16,
     .set   = set_uint16,
-    .set_default_value = set_default_value_uint,
+    .set_default_value = qdev_propinfo_set_default_value_uint,
 };
 
 /* --- 32bit integer --- */
@@ -349,8 +351,8 @@ static void set_uint32(Object *obj, Visitor *v, const char *name,
     visit_type_uint32(v, name, ptr, errp);
 }
 
-static void get_int32(Object *obj, Visitor *v, const char *name, void *opaque,
-                      Error **errp)
+void qdev_propinfo_get_int32(Object *obj, Visitor *v, const char *name,
+                             void *opaque, Error **errp)
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
@@ -378,14 +380,14 @@ const PropertyInfo qdev_prop_uint32 = {
     .name  = "uint32",
     .get   = get_uint32,
     .set   = set_uint32,
-    .set_default_value = set_default_value_uint,
+    .set_default_value = qdev_propinfo_set_default_value_uint,
 };
 
 const PropertyInfo qdev_prop_int32 = {
     .name  = "int32",
-    .get   = get_int32,
+    .get   = qdev_propinfo_get_int32,
     .set   = set_int32,
-    .set_default_value = set_default_value_int,
+    .set_default_value = qdev_propinfo_set_default_value_int,
 };
 
 /* --- 64bit integer --- */
@@ -444,14 +446,14 @@ const PropertyInfo qdev_prop_uint64 = {
     .name  = "uint64",
     .get   = get_uint64,
     .set   = set_uint64,
-    .set_default_value = set_default_value_uint,
+    .set_default_value = qdev_propinfo_set_default_value_uint,
 };
 
 const PropertyInfo qdev_prop_int64 = {
     .name  = "int64",
     .get   = get_int64,
     .set   = set_int64,
-    .set_default_value = set_default_value_int,
+    .set_default_value = qdev_propinfo_set_default_value_int,
 };
 
 /* --- string --- */
@@ -820,8 +822,8 @@ const PropertyInfo qdev_prop_pci_devfn = {
 
 /* --- 32bit unsigned int 'size' type --- */
 
-static void get_size32(Object *obj, Visitor *v, const char *name, void *opaque,
-                       Error **errp)
+void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name,
+                              void *opaque, Error **errp)
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
@@ -861,9 +863,9 @@ static void set_size32(Object *obj, Visitor *v, const char *name, void *opaque,
 
 const PropertyInfo qdev_prop_size32 = {
     .name  = "size",
-    .get = get_size32,
+    .get = qdev_propinfo_get_size32,
     .set = set_size32,
-    .set_default_value = set_default_value_uint,
+    .set_default_value = qdev_propinfo_set_default_value_uint,
 };
 
 /* --- blocksize --- */
@@ -919,9 +921,9 @@ const PropertyInfo qdev_prop_blocksize = {
     .name  = "size",
     .description = "A power of two between " MIN_BLOCK_SIZE_STR
                    " and " MAX_BLOCK_SIZE_STR,
-    .get   = get_size32,
+    .get   = qdev_propinfo_get_size32,
     .set   = set_blocksize,
-    .set_default_value = set_default_value_uint,
+    .set_default_value = qdev_propinfo_set_default_value_uint,
 };
 
 /* --- pci host address --- */
@@ -1190,7 +1192,7 @@ const PropertyInfo qdev_prop_arraylen = {
     .name = "uint32",
     .get = get_uint32,
     .set = set_prop_arraylen,
-    .set_default_value = set_default_value_uint,
+    .set_default_value = qdev_propinfo_set_default_value_uint,
 };
 
 /* --- public helpers --- */
@@ -1401,7 +1403,7 @@ const PropertyInfo qdev_prop_size = {
     .name  = "size",
     .get = get_size,
     .set = set_size,
-    .set_default_value = set_default_value_uint,
+    .set_default_value = qdev_propinfo_set_default_value_uint,
 };
 
 /* --- object link property --- */
-- 
2.26.2



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

* [PATCH v3 08/11] hw/core/qdev-properties: Extract system-mode specific properties
  2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2020-09-30 16:49 ` [PATCH v3 07/11] hw/core/qdev-properties: Export some integer-related functions Philippe Mathieu-Daudé
@ 2020-09-30 16:49 ` Philippe Mathieu-Daudé
  2020-09-30 16:49 ` [PATCH v3 09/11] hw/core: Add qdev stub for user-mode Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-30 16:49 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, Michael Roth, Eduardo Habkost, Markus Armbruster,
	Richard Henderson, Paolo Bonzini, Max Reitz, Richard Henderson

Move properties specific to machines into a separate file.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v3: Also move Reserved Region introduced in commit f78069253c
    ("qdev: Introduce DEFINE_PROP_RESERVED_REGION").
---
 hw/core/qdev-properties-system.c | 687 ++++++++++++++++++++++++++++++-
 hw/core/qdev-properties.c        | 674 ------------------------------
 2 files changed, 679 insertions(+), 682 deletions(-)

diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index b29daf4fb5..49bdd12581 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -11,19 +11,25 @@
  */
 
 #include "qemu/osdep.h"
-#include "audio/audio.h"
-#include "net/net.h"
 #include "hw/qdev-properties.h"
 #include "qapi/error.h"
+#include "qapi/visitor.h"
+#include "qapi/qapi-types-block.h"
+#include "qapi/qapi-types-machine.h"
+#include "qapi/qapi-types-migration.h"
 #include "qapi/qmp/qerror.h"
+#include "qemu/ctype.h"
+#include "qemu/cutils.h"
+#include "qemu/units.h"
+#include "qemu/error-report.h"
+#include "qdev-prop-internal.h"
+
+#include "audio/audio.h"
+#include "chardev/char-fe.h"
 #include "sysemu/block-backend.h"
 #include "sysemu/blockdev.h"
-#include "hw/block/block.h"
-#include "net/hub.h"
-#include "qapi/visitor.h"
-#include "chardev/char-fe.h"
-#include "sysemu/iothread.h"
-#include "sysemu/tpm_backend.h"
+#include "net/net.h"
+#include "hw/pci/pci.h"
 
 static bool check_prop_still_unset(DeviceState *dev, const char *name,
                                    const void *old_val, const char *new_val,
@@ -280,6 +286,96 @@ const PropertyInfo qdev_prop_chr = {
     .release = release_chr,
 };
 
+/* --- mac address --- */
+
+/*
+ * accepted syntax versions:
+ *   01:02:03:04:05:06
+ *   01-02-03-04-05-06
+ */
+static void get_mac(Object *obj, Visitor *v, const char *name, void *opaque,
+                    Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    MACAddr *mac = qdev_get_prop_ptr(dev, prop);
+    char buffer[2 * 6 + 5 + 1];
+    char *p = buffer;
+
+    snprintf(buffer, sizeof(buffer), "%02x:%02x:%02x:%02x:%02x:%02x",
+             mac->a[0], mac->a[1], mac->a[2],
+             mac->a[3], mac->a[4], mac->a[5]);
+
+    visit_type_str(v, name, &p, errp);
+}
+
+static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque,
+                    Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    MACAddr *mac = qdev_get_prop_ptr(dev, prop);
+    int i, pos;
+    char *str;
+    const char *p;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    if (!visit_type_str(v, name, &str, errp)) {
+        return;
+    }
+
+    for (i = 0, pos = 0; i < 6; i++, pos += 3) {
+        long val;
+
+        if (!qemu_isxdigit(str[pos])) {
+            goto inval;
+        }
+        if (!qemu_isxdigit(str[pos + 1])) {
+            goto inval;
+        }
+        if (i == 5) {
+            if (str[pos + 2] != '\0') {
+                goto inval;
+            }
+        } else {
+            if (str[pos + 2] != ':' && str[pos + 2] != '-') {
+                goto inval;
+            }
+        }
+        if (qemu_strtol(str + pos, &p, 16, &val) < 0 || val > 0xff) {
+            goto inval;
+        }
+        mac->a[i] = val;
+    }
+    g_free(str);
+    return;
+
+inval:
+    error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    g_free(str);
+}
+
+const PropertyInfo qdev_prop_macaddr = {
+    .name  = "str",
+    .description = "Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56",
+    .get   = get_mac,
+    .set   = set_mac,
+};
+
+void qdev_prop_set_macaddr(DeviceState *dev, const char *name,
+                           const uint8_t *value)
+{
+    char str[2 * 6 + 5 + 1];
+    snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
+             value[0], value[1], value[2], value[3], value[4], value[5]);
+
+    object_property_set_str(OBJECT(dev), name, str, &error_abort);
+}
+
 /* --- netdev device --- */
 static void get_netdev(Object *obj, Visitor *v, const char *name,
                        void *opaque, Error **errp)
@@ -465,3 +561,578 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
     }
     nd->instantiated = 1;
 }
+
+/* --- lost tick policy --- */
+
+QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) != sizeof(int));
+
+const PropertyInfo qdev_prop_losttickpolicy = {
+    .name  = "LostTickPolicy",
+    .enum_table  = &LostTickPolicy_lookup,
+    .get   = qdev_propinfo_get_enum,
+    .set   = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
+};
+
+/* --- blocksize --- */
+
+/* lower limit is sector size */
+#define MIN_BLOCK_SIZE          512
+#define MIN_BLOCK_SIZE_STR      "512 B"
+/*
+ * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses, and
+ * matches qcow2 cluster size limit
+ */
+#define MAX_BLOCK_SIZE          (2 * MiB)
+#define MAX_BLOCK_SIZE_STR      "2 MiB"
+
+static void set_blocksize(Object *obj, Visitor *v, const char *name,
+                          void *opaque, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
+    uint64_t value;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    if (!visit_type_size(v, name, &value, errp)) {
+        return;
+    }
+    /* value of 0 means "unset" */
+    if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) {
+        error_setg(errp,
+                   "Property %s.%s doesn't take value %" PRIu64
+                   " (minimum: " MIN_BLOCK_SIZE_STR
+                   ", maximum: " MAX_BLOCK_SIZE_STR ")",
+                   dev->id ? : "", name, value);
+        return;
+    }
+
+    /* We rely on power-of-2 blocksizes for bitmasks */
+    if ((value & (value - 1)) != 0) {
+        error_setg(errp,
+                  "Property %s.%s doesn't take value '%" PRId64 "', "
+                  "it's not a power of 2", dev->id ?: "", name, (int64_t)value);
+        return;
+    }
+
+    *ptr = value;
+}
+
+const PropertyInfo qdev_prop_blocksize = {
+    .name  = "size",
+    .description = "A power of two between " MIN_BLOCK_SIZE_STR
+                   " and " MAX_BLOCK_SIZE_STR,
+    .get   = qdev_propinfo_get_size32,
+    .set   = set_blocksize,
+    .set_default_value = qdev_propinfo_set_default_value_uint,
+};
+
+/* --- Block device error handling policy --- */
+
+QEMU_BUILD_BUG_ON(sizeof(BlockdevOnError) != sizeof(int));
+
+const PropertyInfo qdev_prop_blockdev_on_error = {
+    .name = "BlockdevOnError",
+    .description = "Error handling policy, "
+                   "report/ignore/enospc/stop/auto",
+    .enum_table = &BlockdevOnError_lookup,
+    .get = qdev_propinfo_get_enum,
+    .set = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
+};
+
+/* --- BIOS CHS translation */
+
+QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation) != sizeof(int));
+
+const PropertyInfo qdev_prop_bios_chs_trans = {
+    .name = "BiosAtaTranslation",
+    .description = "Logical CHS translation algorithm, "
+                   "auto/none/lba/large/rechs",
+    .enum_table = &BiosAtaTranslation_lookup,
+    .get = qdev_propinfo_get_enum,
+    .set = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
+};
+
+/* --- FDC default drive types */
+
+const PropertyInfo qdev_prop_fdc_drive_type = {
+    .name = "FdcDriveType",
+    .description = "FDC drive type, "
+                   "144/288/120/none/auto",
+    .enum_table = &FloppyDriveType_lookup,
+    .get = qdev_propinfo_get_enum,
+    .set = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
+};
+
+/* --- MultiFDCompression --- */
+
+const PropertyInfo qdev_prop_multifd_compression = {
+    .name = "MultiFDCompression",
+    .description = "multifd_compression values, "
+                   "none/zlib/zstd",
+    .enum_table = &MultiFDCompression_lookup,
+    .get = qdev_propinfo_get_enum,
+    .set = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
+};
+
+/* --- Reserved Region --- */
+
+/*
+ * Accepted syntax:
+ *   <low address>:<high address>:<type>
+ *   where low/high addresses are uint64_t in hexadecimal
+ *   and type is a non-negative decimal integer
+ */
+static void get_reserved_region(Object *obj, Visitor *v, const char *name,
+                                void *opaque, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    ReservedRegion *rr = qdev_get_prop_ptr(dev, prop);
+    char buffer[64];
+    char *p = buffer;
+    int rc;
+
+    rc = snprintf(buffer, sizeof(buffer), "0x%"PRIx64":0x%"PRIx64":%u",
+                  rr->low, rr->high, rr->type);
+    assert(rc < sizeof(buffer));
+
+    visit_type_str(v, name, &p, errp);
+}
+
+static void set_reserved_region(Object *obj, Visitor *v, const char *name,
+                                void *opaque, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    ReservedRegion *rr = qdev_get_prop_ptr(dev, prop);
+    Error *local_err = NULL;
+    const char *endptr;
+    char *str;
+    int ret;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    visit_type_str(v, name, &str, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    ret = qemu_strtou64(str, &endptr, 16, &rr->low);
+    if (ret) {
+        error_setg(errp, "start address of '%s'"
+                   " must be a hexadecimal integer", name);
+        goto out;
+    }
+    if (*endptr != ':') {
+        goto separator_error;
+    }
+
+    ret = qemu_strtou64(endptr + 1, &endptr, 16, &rr->high);
+    if (ret) {
+        error_setg(errp, "end address of '%s'"
+                   " must be a hexadecimal integer", name);
+        goto out;
+    }
+    if (*endptr != ':') {
+        goto separator_error;
+    }
+
+    ret = qemu_strtoui(endptr + 1, &endptr, 10, &rr->type);
+    if (ret) {
+        error_setg(errp, "type of '%s'"
+                   " must be a non-negative decimal integer", name);
+    }
+    goto out;
+
+separator_error:
+    error_setg(errp, "reserved region fields must be separated with ':'");
+out:
+    g_free(str);
+    return;
+}
+
+const PropertyInfo qdev_prop_reserved_region = {
+    .name  = "reserved_region",
+    .description = "Reserved Region, example: 0xFEE00000:0xFEEFFFFF:0",
+    .get   = get_reserved_region,
+    .set   = set_reserved_region,
+};
+
+/* --- pci address --- */
+
+/*
+ * bus-local address, i.e. "$slot" or "$slot.$fn"
+ */
+static void set_pci_devfn(Object *obj, Visitor *v, const char *name,
+                          void *opaque, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    int32_t value, *ptr = qdev_get_prop_ptr(dev, prop);
+    unsigned int slot, fn, n;
+    char *str;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    if (!visit_type_str(v, name, &str, NULL)) {
+        if (!visit_type_int32(v, name, &value, errp)) {
+            return;
+        }
+        if (value < -1 || value > 255) {
+            error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+                       name ? name : "null", "pci_devfn");
+            return;
+        }
+        *ptr = value;
+        return;
+    }
+
+    if (sscanf(str, "%x.%x%n", &slot, &fn, &n) != 2) {
+        fn = 0;
+        if (sscanf(str, "%x%n", &slot, &n) != 1) {
+            goto invalid;
+        }
+    }
+    if (str[n] != '\0' || fn > 7 || slot > 31) {
+        goto invalid;
+    }
+    *ptr = slot << 3 | fn;
+    g_free(str);
+    return;
+
+invalid:
+    error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    g_free(str);
+}
+
+static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest,
+                           size_t len)
+{
+    int32_t *ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (*ptr == -1) {
+        return snprintf(dest, len, "<unset>");
+    } else {
+        return snprintf(dest, len, "%02x.%x", *ptr >> 3, *ptr & 7);
+    }
+}
+
+const PropertyInfo qdev_prop_pci_devfn = {
+    .name  = "int32",
+    .description = "Slot and optional function number, example: 06.0 or 06",
+    .print = print_pci_devfn,
+    .get   = qdev_propinfo_get_int32,
+    .set   = set_pci_devfn,
+    .set_default_value = qdev_propinfo_set_default_value_int,
+};
+
+/* --- pci host address --- */
+
+static void get_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
+                                 void *opaque, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
+    char buffer[] = "ffff:ff:ff.f";
+    char *p = buffer;
+    int rc = 0;
+
+    /*
+     * Catch "invalid" device reference from vfio-pci and allow the
+     * default buffer representing the non-existent device to be used.
+     */
+    if (~addr->domain || ~addr->bus || ~addr->slot || ~addr->function) {
+        rc = snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%0d",
+                      addr->domain, addr->bus, addr->slot, addr->function);
+        assert(rc == sizeof(buffer) - 1);
+    }
+
+    visit_type_str(v, name, &p, errp);
+}
+
+/*
+ * Parse [<domain>:]<bus>:<slot>.<func>
+ *   if <domain> is not supplied, it's assumed to be 0.
+ */
+static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
+                                 void *opaque, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
+    char *str, *p;
+    const char *e;
+    unsigned long val;
+    unsigned long dom = 0, bus = 0;
+    unsigned int slot = 0, func = 0;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    if (!visit_type_str(v, name, &str, errp)) {
+        return;
+    }
+
+    p = str;
+    if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0xffff || e == p) {
+        goto inval;
+    }
+    if (*e != ':') {
+        goto inval;
+    }
+    bus = val;
+
+    p = (char *)e + 1;
+    if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e == p) {
+        goto inval;
+    }
+    if (*e == ':') {
+        dom = bus;
+        bus = val;
+        p = (char *)e + 1;
+        if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e == p) {
+            goto inval;
+        }
+    }
+    slot = val;
+
+    if (*e != '.') {
+        goto inval;
+    }
+    p = (char *)e + 1;
+    if (qemu_strtoul(p, &e, 10, &val) < 0 || val > 7 || e == p) {
+        goto inval;
+    }
+    func = val;
+
+    if (bus > 0xff) {
+        goto inval;
+    }
+
+    if (*e) {
+        goto inval;
+    }
+
+    addr->domain = dom;
+    addr->bus = bus;
+    addr->slot = slot;
+    addr->function = func;
+
+    g_free(str);
+    return;
+
+inval:
+    error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    g_free(str);
+}
+
+const PropertyInfo qdev_prop_pci_host_devaddr = {
+    .name = "str",
+    .description = "Address (bus/device/function) of "
+                   "the host device, example: 04:10.0",
+    .get = get_pci_host_devaddr,
+    .set = set_pci_host_devaddr,
+};
+
+/* --- OffAutoPCIBAR off/auto/bar0/bar1/bar2/bar3/bar4/bar5 --- */
+
+const PropertyInfo qdev_prop_off_auto_pcibar = {
+    .name = "OffAutoPCIBAR",
+    .description = "off/auto/bar0/bar1/bar2/bar3/bar4/bar5",
+    .enum_table = &OffAutoPCIBAR_lookup,
+    .get = qdev_propinfo_get_enum,
+    .set = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
+};
+
+/* --- PCIELinkSpeed 2_5/5/8/16 -- */
+
+static void get_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
+                                   void *opaque, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    PCIExpLinkSpeed *p = qdev_get_prop_ptr(dev, prop);
+    int speed;
+
+    switch (*p) {
+    case QEMU_PCI_EXP_LNK_2_5GT:
+        speed = PCIE_LINK_SPEED_2_5;
+        break;
+    case QEMU_PCI_EXP_LNK_5GT:
+        speed = PCIE_LINK_SPEED_5;
+        break;
+    case QEMU_PCI_EXP_LNK_8GT:
+        speed = PCIE_LINK_SPEED_8;
+        break;
+    case QEMU_PCI_EXP_LNK_16GT:
+        speed = PCIE_LINK_SPEED_16;
+        break;
+    default:
+        /* Unreachable */
+        abort();
+    }
+
+    visit_type_enum(v, prop->name, &speed, prop->info->enum_table, errp);
+}
+
+static void set_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
+                                   void *opaque, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    PCIExpLinkSpeed *p = qdev_get_prop_ptr(dev, prop);
+    int speed;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    if (!visit_type_enum(v, prop->name, &speed, prop->info->enum_table,
+                         errp)) {
+        return;
+    }
+
+    switch (speed) {
+    case PCIE_LINK_SPEED_2_5:
+        *p = QEMU_PCI_EXP_LNK_2_5GT;
+        break;
+    case PCIE_LINK_SPEED_5:
+        *p = QEMU_PCI_EXP_LNK_5GT;
+        break;
+    case PCIE_LINK_SPEED_8:
+        *p = QEMU_PCI_EXP_LNK_8GT;
+        break;
+    case PCIE_LINK_SPEED_16:
+        *p = QEMU_PCI_EXP_LNK_16GT;
+        break;
+    default:
+        /* Unreachable */
+        abort();
+    }
+}
+
+const PropertyInfo qdev_prop_pcie_link_speed = {
+    .name = "PCIELinkSpeed",
+    .description = "2_5/5/8/16",
+    .enum_table = &PCIELinkSpeed_lookup,
+    .get = get_prop_pcielinkspeed,
+    .set = set_prop_pcielinkspeed,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
+};
+
+/* --- PCIELinkWidth 1/2/4/8/12/16/32 -- */
+
+static void get_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
+                                   void *opaque, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    PCIExpLinkWidth *p = qdev_get_prop_ptr(dev, prop);
+    int width;
+
+    switch (*p) {
+    case QEMU_PCI_EXP_LNK_X1:
+        width = PCIE_LINK_WIDTH_1;
+        break;
+    case QEMU_PCI_EXP_LNK_X2:
+        width = PCIE_LINK_WIDTH_2;
+        break;
+    case QEMU_PCI_EXP_LNK_X4:
+        width = PCIE_LINK_WIDTH_4;
+        break;
+    case QEMU_PCI_EXP_LNK_X8:
+        width = PCIE_LINK_WIDTH_8;
+        break;
+    case QEMU_PCI_EXP_LNK_X12:
+        width = PCIE_LINK_WIDTH_12;
+        break;
+    case QEMU_PCI_EXP_LNK_X16:
+        width = PCIE_LINK_WIDTH_16;
+        break;
+    case QEMU_PCI_EXP_LNK_X32:
+        width = PCIE_LINK_WIDTH_32;
+        break;
+    default:
+        /* Unreachable */
+        abort();
+    }
+
+    visit_type_enum(v, prop->name, &width, prop->info->enum_table, errp);
+}
+
+static void set_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
+                                   void *opaque, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    PCIExpLinkWidth *p = qdev_get_prop_ptr(dev, prop);
+    int width;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    if (!visit_type_enum(v, prop->name, &width, prop->info->enum_table,
+                         errp)) {
+        return;
+    }
+
+    switch (width) {
+    case PCIE_LINK_WIDTH_1:
+        *p = QEMU_PCI_EXP_LNK_X1;
+        break;
+    case PCIE_LINK_WIDTH_2:
+        *p = QEMU_PCI_EXP_LNK_X2;
+        break;
+    case PCIE_LINK_WIDTH_4:
+        *p = QEMU_PCI_EXP_LNK_X4;
+        break;
+    case PCIE_LINK_WIDTH_8:
+        *p = QEMU_PCI_EXP_LNK_X8;
+        break;
+    case PCIE_LINK_WIDTH_12:
+        *p = QEMU_PCI_EXP_LNK_X12;
+        break;
+    case PCIE_LINK_WIDTH_16:
+        *p = QEMU_PCI_EXP_LNK_X16;
+        break;
+    case PCIE_LINK_WIDTH_32:
+        *p = QEMU_PCI_EXP_LNK_X32;
+        break;
+    default:
+        /* Unreachable */
+        abort();
+    }
+}
+
+const PropertyInfo qdev_prop_pcie_link_width = {
+    .name = "PCIELinkWidth",
+    .description = "1/2/4/8/12/16/32",
+    .enum_table = &PCIELinkWidth_lookup,
+    .get = get_prop_pcielinkwidth,
+    .set = set_prop_pcielinkwidth,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
+};
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 37e309077a..509cbf155d 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1,20 +1,11 @@
 #include "qemu/osdep.h"
-#include "qemu/cutils.h"
-#include "net/net.h"
 #include "hw/qdev-properties.h"
 #include "qapi/error.h"
-#include "hw/pci/pci.h"
-#include "qapi/qapi-types-block.h"
-#include "qapi/qapi-types-machine.h"
 #include "qapi/qapi-types-misc.h"
 #include "qapi/qmp/qerror.h"
 #include "qemu/ctype.h"
 #include "qemu/error-report.h"
-#include "qapi/qapi-types-migration.h"
-#include "hw/block/block.h"
-#include "net/hub.h"
 #include "qapi/visitor.h"
-#include "chardev/char.h"
 #include "qemu/uuid.h"
 #include "qemu/units.h"
 #include "qemu/cutils.h"
@@ -506,174 +497,6 @@ const PropertyInfo qdev_prop_string = {
     .set   = set_string,
 };
 
-/* --- mac address --- */
-
-/*
- * accepted syntax versions:
- *   01:02:03:04:05:06
- *   01-02-03-04-05-06
- */
-static void get_mac(Object *obj, Visitor *v, const char *name, void *opaque,
-                    Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    MACAddr *mac = qdev_get_prop_ptr(dev, prop);
-    char buffer[2 * 6 + 5 + 1];
-    char *p = buffer;
-
-    snprintf(buffer, sizeof(buffer), "%02x:%02x:%02x:%02x:%02x:%02x",
-             mac->a[0], mac->a[1], mac->a[2],
-             mac->a[3], mac->a[4], mac->a[5]);
-
-    visit_type_str(v, name, &p, errp);
-}
-
-static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque,
-                    Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    MACAddr *mac = qdev_get_prop_ptr(dev, prop);
-    int i, pos;
-    char *str;
-    const char *p;
-
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
-    if (!visit_type_str(v, name, &str, errp)) {
-        return;
-    }
-
-    for (i = 0, pos = 0; i < 6; i++, pos += 3) {
-        long val;
-
-        if (!qemu_isxdigit(str[pos])) {
-            goto inval;
-        }
-        if (!qemu_isxdigit(str[pos + 1])) {
-            goto inval;
-        }
-        if (i == 5) {
-            if (str[pos + 2] != '\0') {
-                goto inval;
-            }
-        } else {
-            if (str[pos + 2] != ':' && str[pos + 2] != '-') {
-                goto inval;
-            }
-        }
-        if (qemu_strtol(str + pos, &p, 16, &val) < 0 || val > 0xff) {
-            goto inval;
-        }
-        mac->a[i] = val;
-    }
-    g_free(str);
-    return;
-
-inval:
-    error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
-    g_free(str);
-}
-
-const PropertyInfo qdev_prop_macaddr = {
-    .name  = "str",
-    .description = "Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56",
-    .get   = get_mac,
-    .set   = set_mac,
-};
-
-/* --- Reserved Region --- */
-
-/*
- * Accepted syntax:
- *   <low address>:<high address>:<type>
- *   where low/high addresses are uint64_t in hexadecimal
- *   and type is a non-negative decimal integer
- */
-static void get_reserved_region(Object *obj, Visitor *v, const char *name,
-                                void *opaque, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    ReservedRegion *rr = qdev_get_prop_ptr(dev, prop);
-    char buffer[64];
-    char *p = buffer;
-    int rc;
-
-    rc = snprintf(buffer, sizeof(buffer), "0x%"PRIx64":0x%"PRIx64":%u",
-                  rr->low, rr->high, rr->type);
-    assert(rc < sizeof(buffer));
-
-    visit_type_str(v, name, &p, errp);
-}
-
-static void set_reserved_region(Object *obj, Visitor *v, const char *name,
-                                void *opaque, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    ReservedRegion *rr = qdev_get_prop_ptr(dev, prop);
-    Error *local_err = NULL;
-    const char *endptr;
-    char *str;
-    int ret;
-
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
-    visit_type_str(v, name, &str, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        return;
-    }
-
-    ret = qemu_strtou64(str, &endptr, 16, &rr->low);
-    if (ret) {
-        error_setg(errp, "start address of '%s'"
-                   " must be a hexadecimal integer", name);
-        goto out;
-    }
-    if (*endptr != ':') {
-        goto separator_error;
-    }
-
-    ret = qemu_strtou64(endptr + 1, &endptr, 16, &rr->high);
-    if (ret) {
-        error_setg(errp, "end address of '%s'"
-                   " must be a hexadecimal integer", name);
-        goto out;
-    }
-    if (*endptr != ':') {
-        goto separator_error;
-    }
-
-    ret = qemu_strtoui(endptr + 1, &endptr, 10, &rr->type);
-    if (ret) {
-        error_setg(errp, "type of '%s'"
-                   " must be a non-negative decimal integer", name);
-    }
-    goto out;
-
-separator_error:
-    error_setg(errp, "reserved region fields must be separated with ':'");
-out:
-    g_free(str);
-    return;
-}
-
-const PropertyInfo qdev_prop_reserved_region = {
-    .name  = "reserved_region",
-    .description = "Reserved Region, example: 0xFEE00000:0xFEEFFFFF:0",
-    .get   = get_reserved_region,
-    .set   = set_reserved_region,
-};
-
 /* --- on/off/auto --- */
 
 const PropertyInfo qdev_prop_on_off_auto = {
@@ -685,141 +508,6 @@ const PropertyInfo qdev_prop_on_off_auto = {
     .set_default_value = qdev_propinfo_set_default_value_enum,
 };
 
-/* --- lost tick policy --- */
-
-QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) != sizeof(int));
-
-const PropertyInfo qdev_prop_losttickpolicy = {
-    .name  = "LostTickPolicy",
-    .enum_table  = &LostTickPolicy_lookup,
-    .get   = qdev_propinfo_get_enum,
-    .set   = qdev_propinfo_set_enum,
-    .set_default_value = qdev_propinfo_set_default_value_enum,
-};
-
-/* --- Block device error handling policy --- */
-
-QEMU_BUILD_BUG_ON(sizeof(BlockdevOnError) != sizeof(int));
-
-const PropertyInfo qdev_prop_blockdev_on_error = {
-    .name = "BlockdevOnError",
-    .description = "Error handling policy, "
-                   "report/ignore/enospc/stop/auto",
-    .enum_table = &BlockdevOnError_lookup,
-    .get = qdev_propinfo_get_enum,
-    .set = qdev_propinfo_set_enum,
-    .set_default_value = qdev_propinfo_set_default_value_enum,
-};
-
-/* --- BIOS CHS translation */
-
-QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation) != sizeof(int));
-
-const PropertyInfo qdev_prop_bios_chs_trans = {
-    .name = "BiosAtaTranslation",
-    .description = "Logical CHS translation algorithm, "
-                   "auto/none/lba/large/rechs",
-    .enum_table = &BiosAtaTranslation_lookup,
-    .get = qdev_propinfo_get_enum,
-    .set = qdev_propinfo_set_enum,
-    .set_default_value = qdev_propinfo_set_default_value_enum,
-};
-
-/* --- FDC default drive types */
-
-const PropertyInfo qdev_prop_fdc_drive_type = {
-    .name = "FdcDriveType",
-    .description = "FDC drive type, "
-                   "144/288/120/none/auto",
-    .enum_table = &FloppyDriveType_lookup,
-    .get = qdev_propinfo_get_enum,
-    .set = qdev_propinfo_set_enum,
-    .set_default_value = qdev_propinfo_set_default_value_enum,
-};
-
-/* --- MultiFDCompression --- */
-
-const PropertyInfo qdev_prop_multifd_compression = {
-    .name = "MultiFDCompression",
-    .description = "multifd_compression values, "
-                   "none/zlib/zstd",
-    .enum_table = &MultiFDCompression_lookup,
-    .get = qdev_propinfo_get_enum,
-    .set = qdev_propinfo_set_enum,
-    .set_default_value = qdev_propinfo_set_default_value_enum,
-};
-
-/* --- pci address --- */
-
-/*
- * bus-local address, i.e. "$slot" or "$slot.$fn"
- */
-static void set_pci_devfn(Object *obj, Visitor *v, const char *name,
-                          void *opaque, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    int32_t value, *ptr = qdev_get_prop_ptr(dev, prop);
-    unsigned int slot, fn, n;
-    char *str;
-
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
-    if (!visit_type_str(v, name, &str, NULL)) {
-        if (!visit_type_int32(v, name, &value, errp)) {
-            return;
-        }
-        if (value < -1 || value > 255) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
-                       name ? name : "null", "pci_devfn");
-            return;
-        }
-        *ptr = value;
-        return;
-    }
-
-    if (sscanf(str, "%x.%x%n", &slot, &fn, &n) != 2) {
-        fn = 0;
-        if (sscanf(str, "%x%n", &slot, &n) != 1) {
-            goto invalid;
-        }
-    }
-    if (str[n] != '\0' || fn > 7 || slot > 31) {
-        goto invalid;
-    }
-    *ptr = slot << 3 | fn;
-    g_free(str);
-    return;
-
-invalid:
-    error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
-    g_free(str);
-}
-
-static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest,
-                           size_t len)
-{
-    int32_t *ptr = qdev_get_prop_ptr(dev, prop);
-
-    if (*ptr == -1) {
-        return snprintf(dest, len, "<unset>");
-    } else {
-        return snprintf(dest, len, "%02x.%x", *ptr >> 3, *ptr & 7);
-    }
-}
-
-const PropertyInfo qdev_prop_pci_devfn = {
-    .name  = "int32",
-    .description = "Slot and optional function number, example: 06.0 or 06",
-    .print = print_pci_devfn,
-    .get   = get_int32,
-    .set   = set_pci_devfn,
-    .set_default_value = set_default_value_int,
-};
-
 /* --- 32bit unsigned int 'size' type --- */
 
 void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name,
@@ -868,175 +556,6 @@ const PropertyInfo qdev_prop_size32 = {
     .set_default_value = qdev_propinfo_set_default_value_uint,
 };
 
-/* --- blocksize --- */
-
-/* lower limit is sector size */
-#define MIN_BLOCK_SIZE          512
-#define MIN_BLOCK_SIZE_STR      "512 B"
-/*
- * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses, and
- * matches qcow2 cluster size limit
- */
-#define MAX_BLOCK_SIZE          (2 * MiB)
-#define MAX_BLOCK_SIZE_STR      "2 MiB"
-
-static void set_blocksize(Object *obj, Visitor *v, const char *name,
-                          void *opaque, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
-    uint64_t value;
-
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
-    if (!visit_type_size(v, name, &value, errp)) {
-        return;
-    }
-    /* value of 0 means "unset" */
-    if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) {
-        error_setg(errp,
-                   "Property %s.%s doesn't take value %" PRIu64
-                   " (minimum: " MIN_BLOCK_SIZE_STR
-                   ", maximum: " MAX_BLOCK_SIZE_STR ")",
-                   dev->id ? : "", name, value);
-        return;
-    }
-
-    /* We rely on power-of-2 blocksizes for bitmasks */
-    if ((value & (value - 1)) != 0) {
-        error_setg(errp,
-                  "Property %s.%s doesn't take value '%" PRId64 "', "
-                  "it's not a power of 2", dev->id ?: "", name, (int64_t)value);
-        return;
-    }
-
-    *ptr = value;
-}
-
-const PropertyInfo qdev_prop_blocksize = {
-    .name  = "size",
-    .description = "A power of two between " MIN_BLOCK_SIZE_STR
-                   " and " MAX_BLOCK_SIZE_STR,
-    .get   = qdev_propinfo_get_size32,
-    .set   = set_blocksize,
-    .set_default_value = qdev_propinfo_set_default_value_uint,
-};
-
-/* --- pci host address --- */
-
-static void get_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
-                                 void *opaque, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
-    char buffer[] = "ffff:ff:ff.f";
-    char *p = buffer;
-    int rc = 0;
-
-    /*
-     * Catch "invalid" device reference from vfio-pci and allow the
-     * default buffer representing the non-existent device to be used.
-     */
-    if (~addr->domain || ~addr->bus || ~addr->slot || ~addr->function) {
-        rc = snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%0d",
-                      addr->domain, addr->bus, addr->slot, addr->function);
-        assert(rc == sizeof(buffer) - 1);
-    }
-
-    visit_type_str(v, name, &p, errp);
-}
-
-/*
- * Parse [<domain>:]<bus>:<slot>.<func>
- *   if <domain> is not supplied, it's assumed to be 0.
- */
-static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
-                                 void *opaque, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
-    char *str, *p;
-    const char *e;
-    unsigned long val;
-    unsigned long dom = 0, bus = 0;
-    unsigned int slot = 0, func = 0;
-
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
-    if (!visit_type_str(v, name, &str, errp)) {
-        return;
-    }
-
-    p = str;
-    if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0xffff || e == p) {
-        goto inval;
-    }
-    if (*e != ':') {
-        goto inval;
-    }
-    bus = val;
-
-    p = (char *)e + 1;
-    if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e == p) {
-        goto inval;
-    }
-    if (*e == ':') {
-        dom = bus;
-        bus = val;
-        p = (char *)e + 1;
-        if (qemu_strtoul(p, &e, 16, &val) < 0 || val > 0x1f || e == p) {
-            goto inval;
-        }
-    }
-    slot = val;
-
-    if (*e != '.') {
-        goto inval;
-    }
-    p = (char *)e + 1;
-    if (qemu_strtoul(p, &e, 10, &val) < 0 || val > 7 || e == p) {
-        goto inval;
-    }
-    func = val;
-
-    if (bus > 0xff) {
-        goto inval;
-    }
-
-    if (*e) {
-        goto inval;
-    }
-
-    addr->domain = dom;
-    addr->bus = bus;
-    addr->slot = slot;
-    addr->function = func;
-
-    g_free(str);
-    return;
-
-inval:
-    error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
-    g_free(str);
-}
-
-const PropertyInfo qdev_prop_pci_host_devaddr = {
-    .name = "str",
-    .description = "Address (bus/device/function) of "
-                   "the host device, example: 04:10.0",
-    .get = get_pci_host_devaddr,
-    .set = set_pci_host_devaddr,
-};
-
 /* --- UUID --- */
 
 static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
@@ -1286,16 +805,6 @@ void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value)
     object_property_set_str(OBJECT(dev), name, value, &error_abort);
 }
 
-void qdev_prop_set_macaddr(DeviceState *dev, const char *name,
-                           const uint8_t *value)
-{
-    char str[2 * 6 + 5 + 1];
-    snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
-             value[0], value[1], value[2], value[3], value[4], value[5]);
-
-    object_property_set_str(OBJECT(dev), name, str, &error_abort);
-}
-
 void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
 {
     Property *prop;
@@ -1420,186 +929,3 @@ const PropertyInfo qdev_prop_link = {
     .name = "link",
     .create = create_link_property,
 };
-
-/* --- OffAutoPCIBAR off/auto/bar0/bar1/bar2/bar3/bar4/bar5 --- */
-
-const PropertyInfo qdev_prop_off_auto_pcibar = {
-    .name = "OffAutoPCIBAR",
-    .description = "off/auto/bar0/bar1/bar2/bar3/bar4/bar5",
-    .enum_table = &OffAutoPCIBAR_lookup,
-    .get = qdev_propinfo_get_enum,
-    .set = qdev_propinfo_set_enum,
-    .set_default_value = qdev_propinfo_set_default_value_enum,
-};
-
-/* --- PCIELinkSpeed 2_5/5/8/16 -- */
-
-static void get_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
-                                   void *opaque, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    PCIExpLinkSpeed *p = qdev_get_prop_ptr(dev, prop);
-    int speed;
-
-    switch (*p) {
-    case QEMU_PCI_EXP_LNK_2_5GT:
-        speed = PCIE_LINK_SPEED_2_5;
-        break;
-    case QEMU_PCI_EXP_LNK_5GT:
-        speed = PCIE_LINK_SPEED_5;
-        break;
-    case QEMU_PCI_EXP_LNK_8GT:
-        speed = PCIE_LINK_SPEED_8;
-        break;
-    case QEMU_PCI_EXP_LNK_16GT:
-        speed = PCIE_LINK_SPEED_16;
-        break;
-    default:
-        /* Unreachable */
-        abort();
-    }
-
-    visit_type_enum(v, prop->name, &speed, prop->info->enum_table, errp);
-}
-
-static void set_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
-                                   void *opaque, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    PCIExpLinkSpeed *p = qdev_get_prop_ptr(dev, prop);
-    int speed;
-
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
-    if (!visit_type_enum(v, prop->name, &speed, prop->info->enum_table,
-                         errp)) {
-        return;
-    }
-
-    switch (speed) {
-    case PCIE_LINK_SPEED_2_5:
-        *p = QEMU_PCI_EXP_LNK_2_5GT;
-        break;
-    case PCIE_LINK_SPEED_5:
-        *p = QEMU_PCI_EXP_LNK_5GT;
-        break;
-    case PCIE_LINK_SPEED_8:
-        *p = QEMU_PCI_EXP_LNK_8GT;
-        break;
-    case PCIE_LINK_SPEED_16:
-        *p = QEMU_PCI_EXP_LNK_16GT;
-        break;
-    default:
-        /* Unreachable */
-        abort();
-    }
-}
-
-const PropertyInfo qdev_prop_pcie_link_speed = {
-    .name = "PCIELinkSpeed",
-    .description = "2_5/5/8/16",
-    .enum_table = &PCIELinkSpeed_lookup,
-    .get = get_prop_pcielinkspeed,
-    .set = set_prop_pcielinkspeed,
-    .set_default_value = qdev_propinfo_set_default_value_enum,
-};
-
-/* --- PCIELinkWidth 1/2/4/8/12/16/32 -- */
-
-static void get_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
-                                   void *opaque, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    PCIExpLinkWidth *p = qdev_get_prop_ptr(dev, prop);
-    int width;
-
-    switch (*p) {
-    case QEMU_PCI_EXP_LNK_X1:
-        width = PCIE_LINK_WIDTH_1;
-        break;
-    case QEMU_PCI_EXP_LNK_X2:
-        width = PCIE_LINK_WIDTH_2;
-        break;
-    case QEMU_PCI_EXP_LNK_X4:
-        width = PCIE_LINK_WIDTH_4;
-        break;
-    case QEMU_PCI_EXP_LNK_X8:
-        width = PCIE_LINK_WIDTH_8;
-        break;
-    case QEMU_PCI_EXP_LNK_X12:
-        width = PCIE_LINK_WIDTH_12;
-        break;
-    case QEMU_PCI_EXP_LNK_X16:
-        width = PCIE_LINK_WIDTH_16;
-        break;
-    case QEMU_PCI_EXP_LNK_X32:
-        width = PCIE_LINK_WIDTH_32;
-        break;
-    default:
-        /* Unreachable */
-        abort();
-    }
-
-    visit_type_enum(v, prop->name, &width, prop->info->enum_table, errp);
-}
-
-static void set_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
-                                   void *opaque, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    PCIExpLinkWidth *p = qdev_get_prop_ptr(dev, prop);
-    int width;
-
-    if (dev->realized) {
-        qdev_prop_set_after_realize(dev, name, errp);
-        return;
-    }
-
-    if (!visit_type_enum(v, prop->name, &width, prop->info->enum_table,
-                         errp)) {
-        return;
-    }
-
-    switch (width) {
-    case PCIE_LINK_WIDTH_1:
-        *p = QEMU_PCI_EXP_LNK_X1;
-        break;
-    case PCIE_LINK_WIDTH_2:
-        *p = QEMU_PCI_EXP_LNK_X2;
-        break;
-    case PCIE_LINK_WIDTH_4:
-        *p = QEMU_PCI_EXP_LNK_X4;
-        break;
-    case PCIE_LINK_WIDTH_8:
-        *p = QEMU_PCI_EXP_LNK_X8;
-        break;
-    case PCIE_LINK_WIDTH_12:
-        *p = QEMU_PCI_EXP_LNK_X12;
-        break;
-    case PCIE_LINK_WIDTH_16:
-        *p = QEMU_PCI_EXP_LNK_X16;
-        break;
-    case PCIE_LINK_WIDTH_32:
-        *p = QEMU_PCI_EXP_LNK_X32;
-        break;
-    default:
-        /* Unreachable */
-        abort();
-    }
-}
-
-const PropertyInfo qdev_prop_pcie_link_width = {
-    .name = "PCIELinkWidth",
-    .description = "1/2/4/8/12/16/32",
-    .enum_table = &PCIELinkWidth_lookup,
-    .get = get_prop_pcielinkwidth,
-    .set = set_prop_pcielinkwidth,
-    .set_default_value = qdev_propinfo_set_default_value_enum,
-};
-- 
2.26.2



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

* [PATCH v3 09/11] hw/core: Add qdev stub for user-mode
  2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2020-09-30 16:49 ` [PATCH v3 08/11] hw/core/qdev-properties: Extract system-mode specific properties Philippe Mathieu-Daudé
@ 2020-09-30 16:49 ` Philippe Mathieu-Daudé
  2020-09-30 16:49 ` [PATCH v3 10/11] target/i386: Restrict X86CPUFeatureWord to X86 targets Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-30 16:49 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, Michael Roth, Eduardo Habkost, Markus Armbruster,
	Richard Henderson, Paolo Bonzini, Max Reitz, Richard Henderson

While user-mode does not use peripherals (devices), it uses a
CPU which is a device.
In the next commit we will reduce the QAPI generated code for
user-mode. Since qdev.c calls qapi_event_send_device_deleted()
in device_finalize, let's add a stub for it.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v3: Meson rebase
---
 stubs/qdev-system.c | 24 ++++++++++++++++++++++++
 stubs/meson.build   |  1 +
 2 files changed, 25 insertions(+)
 create mode 100644 stubs/qdev-system.c

diff --git a/stubs/qdev-system.c b/stubs/qdev-system.c
new file mode 100644
index 0000000000..2b4b54f621
--- /dev/null
+++ b/stubs/qdev-system.c
@@ -0,0 +1,24 @@
+/*
+ * QAPI qdev stubs
+ *
+ * Copyright (c) 2020 Red Hat, Inc.
+ *
+ * Author:
+ *   Philippe Mathieu-Daudé <philmd@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/qapi-events-qdev.h"
+
+void qapi_event_send_device_deleted(bool has_device,
+                                    const char *device, const char *path)
+{
+    /*
+     * Called in user-mode in fork() when a CPUState is qdev::finalize()'d.
+     * Simply ignore the QAPI event there.
+     */
+}
diff --git a/stubs/meson.build b/stubs/meson.build
index 2e231590e1..71d42c34d6 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -25,6 +25,7 @@ stub_ss.add(files('monitor.c'))
 stub_ss.add(files('monitor-core.c'))
 stub_ss.add(files('pci-bus.c'))
 stub_ss.add(files('pci-host-piix.c'))
+stub_ss.add(files('qdev-system.c'))
 stub_ss.add(files('qemu-timer-notify-cb.c'))
 stub_ss.add(files('qmp_memory_device.c'))
 stub_ss.add(files('qtest.c'))
-- 
2.26.2



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

* [PATCH v3 10/11] target/i386: Restrict X86CPUFeatureWord to X86 targets
  2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
                   ` (8 preceding siblings ...)
  2020-09-30 16:49 ` [PATCH v3 09/11] hw/core: Add qdev stub for user-mode Philippe Mathieu-Daudé
@ 2020-09-30 16:49 ` Philippe Mathieu-Daudé
  2020-09-30 17:18   ` Eduardo Habkost
  2020-09-30 16:49 ` [PATCH v3 11/11] qapi: Restrict code generated for user-mode Philippe Mathieu-Daudé
  2020-09-30 17:15 ` [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Eduardo Habkost
  11 siblings, 1 reply; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-30 16:49 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, Michael Roth, Eduardo Habkost, Markus Armbruster,
	Richard Henderson, Paolo Bonzini, Max Reitz, Richard Henderson

Only qemu-system-FOO and qemu-storage-daemon provide QMP
monitors, therefore such declarations and definitions are
irrelevant for user-mode emulation.

Restricting the x86-specific commands to machine-target.json
pulls less QAPI-generated code into user-mode.

Add a stub to satisfy linking in user-mode:

  /usr/bin/ld: libqemu-i386-linux-user.fa.p/target_i386_cpu.c.o: in function `x86_cpu_get_feature_words':
  target/i386/cpu.c:4643: undefined reference to `visit_type_X86CPUFeatureWordInfoList'
  collect2: error: ld returned 1 exit status
  make: *** [Makefile.ninja:1125: qemu-i386] Error 1

Acked-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v3: Reworded + Meson rebase
---
 qapi/machine-target.json   | 45 ++++++++++++++++++++++++++++++++++++++
 qapi/machine.json          | 42 -----------------------------------
 target/i386/cpu.c          |  2 +-
 target/i386/feature-stub.c | 23 +++++++++++++++++++
 target/i386/meson.build    |  1 +
 5 files changed, 70 insertions(+), 43 deletions(-)
 create mode 100644 target/i386/feature-stub.c

diff --git a/qapi/machine-target.json b/qapi/machine-target.json
index 698850cc78..b4d769a53b 100644
--- a/qapi/machine-target.json
+++ b/qapi/machine-target.json
@@ -4,6 +4,51 @@
 # This work is licensed under the terms of the GNU GPL, version 2 or later.
 # See the COPYING file in the top-level directory.
 
+##
+# @X86CPURegister32:
+#
+# A X86 32-bit register
+#
+# Since: 1.5
+##
+{ 'enum': 'X86CPURegister32',
+  'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ],
+  'if': 'defined(TARGET_I386)' }
+
+##
+# @X86CPUFeatureWordInfo:
+#
+# Information about a X86 CPU feature word
+#
+# @cpuid-input-eax: Input EAX value for CPUID instruction for that feature word
+#
+# @cpuid-input-ecx: Input ECX value for CPUID instruction for that
+#                   feature word
+#
+# @cpuid-register: Output register containing the feature bits
+#
+# @features: value of output register, containing the feature bits
+#
+# Since: 1.5
+##
+{ 'struct': 'X86CPUFeatureWordInfo',
+  'data': { 'cpuid-input-eax': 'int',
+            '*cpuid-input-ecx': 'int',
+            'cpuid-register': 'X86CPURegister32',
+            'features': 'int' },
+  'if': 'defined(TARGET_I386)' }
+
+##
+# @DummyForceArrays:
+#
+# Not used by QMP; hack to let us use X86CPUFeatureWordInfoList internally
+#
+# Since: 2.5
+##
+{ 'struct': 'DummyForceArrays',
+  'data': { 'unused': ['X86CPUFeatureWordInfo'] },
+  'if': 'defined(TARGET_I386)' }
+
 ##
 # @CpuModelInfo:
 #
diff --git a/qapi/machine.json b/qapi/machine.json
index 72f014bb5b..cb878acdac 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -544,48 +544,6 @@
    'dst': 'uint16',
    'val': 'uint8' }}
 
-##
-# @X86CPURegister32:
-#
-# A X86 32-bit register
-#
-# Since: 1.5
-##
-{ 'enum': 'X86CPURegister32',
-  'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ] }
-
-##
-# @X86CPUFeatureWordInfo:
-#
-# Information about a X86 CPU feature word
-#
-# @cpuid-input-eax: Input EAX value for CPUID instruction for that feature word
-#
-# @cpuid-input-ecx: Input ECX value for CPUID instruction for that
-#                   feature word
-#
-# @cpuid-register: Output register containing the feature bits
-#
-# @features: value of output register, containing the feature bits
-#
-# Since: 1.5
-##
-{ 'struct': 'X86CPUFeatureWordInfo',
-  'data': { 'cpuid-input-eax': 'int',
-            '*cpuid-input-ecx': 'int',
-            'cpuid-register': 'X86CPURegister32',
-            'features': 'int' } }
-
-##
-# @DummyForceArrays:
-#
-# Not used by QMP; hack to let us use X86CPUFeatureWordInfoList internally
-#
-# Since: 2.5
-##
-{ 'struct': 'DummyForceArrays',
-  'data': { 'unused': ['X86CPUFeatureWordInfo'] } }
-
 ##
 # @NumaCpuOptions:
 #
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 3ffd877dd5..d45fa217cc 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -38,7 +38,7 @@
 #include "qemu/option.h"
 #include "qemu/config-file.h"
 #include "qapi/error.h"
-#include "qapi/qapi-visit-machine.h"
+#include "qapi/qapi-visit-machine-target.h"
 #include "qapi/qapi-visit-run-state.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qerror.h"
diff --git a/target/i386/feature-stub.c b/target/i386/feature-stub.c
new file mode 100644
index 0000000000..787c3c7fa1
--- /dev/null
+++ b/target/i386/feature-stub.c
@@ -0,0 +1,23 @@
+/*
+ * QAPI x86 CPU features stub
+ *
+ * Copyright (c) 2020 Red Hat, Inc.
+ *
+ * Author:
+ *   Philippe Mathieu-Daudé <philmd@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qapi/qapi-visit-machine-target.h"
+
+bool visit_type_X86CPUFeatureWordInfoList(Visitor *v, const char *name,
+                                          X86CPUFeatureWordInfoList **obj,
+                                          Error **errp)
+{
+    g_assert_not_reached();
+}
diff --git a/target/i386/meson.build b/target/i386/meson.build
index e0b71ade56..0c5d9e6caf 100644
--- a/target/i386/meson.build
+++ b/target/i386/meson.build
@@ -5,6 +5,7 @@ i386_ss.add(files(
   'helper.c',
   'xsave_helper.c',
 ))
+i386_ss.add(when: 'CONFIG_SOFTMMU', if_false: files('feature-stub.c'))
 i386_ss.add(when: 'CONFIG_TCG', if_true: files(
   'bpt_helper.c',
   'cc_helper.c',
-- 
2.26.2



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

* [PATCH v3 11/11] qapi: Restrict code generated for user-mode
  2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
                   ` (9 preceding siblings ...)
  2020-09-30 16:49 ` [PATCH v3 10/11] target/i386: Restrict X86CPUFeatureWord to X86 targets Philippe Mathieu-Daudé
@ 2020-09-30 16:49 ` Philippe Mathieu-Daudé
  2020-10-01  5:09   ` Markus Armbruster
  2020-09-30 17:15 ` [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Eduardo Habkost
  11 siblings, 1 reply; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-09-30 16:49 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, Michael Roth, Eduardo Habkost, Markus Armbruster,
	Richard Henderson, Paolo Bonzini, Max Reitz, Richard Henderson

A lot of QAPI generated code is never used by user-mode.

Split out qapi_system_modules and qapi_system_or_tools_modules
from the qapi_all_modules array. We now have 3 groups:
- always used
- use by system-mode or tools (usually by the block layer)
- only used by system-mode

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
Resetting due to Meson update:
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 qapi/meson.build | 51 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 15 deletions(-)

diff --git a/qapi/meson.build b/qapi/meson.build
index 7c4a89a882..ba9677ba97 100644
--- a/qapi/meson.build
+++ b/qapi/meson.build
@@ -14,39 +14,60 @@ util_ss.add(files(
 ))
 
 qapi_all_modules = [
+  'common',
+  'introspect',
+  'misc',
+]
+
+qapi_system_modules = [
   'acpi',
   'audio',
+  'dump',
+  'machine-target',
+  'machine',
+  'migration',
+  'misc-target',
+  'net',
+  'pci',
+  'qdev',
+  'rdma',
+  'rocker',
+  'tpm',
+  'trace',
+]
+
+# system or tools
+qapi_block_modules = [
   'authz',
   'block-core',
   'block',
   'char',
-  'common',
   'control',
   'crypto',
-  'dump',
   'error',
-  'introspect',
   'job',
-  'machine',
-  'machine-target',
-  'migration',
-  'misc',
-  'misc-target',
-  'net',
   'pragma',
-  'qdev',
-  'pci',
   'qom',
-  'rdma',
-  'rocker',
   'run-state',
   'sockets',
-  'tpm',
-  'trace',
   'transaction',
   'ui',
 ]
 
+if have_system
+  qapi_all_modules += qapi_system_modules
+elif have_user
+  # Temporary kludge because X86CPUFeatureWordInfo is not
+  # restricted to system-mode. This should be removed (along
+  # with target/i386/feature-stub.c) once target/i386/cpu.c
+  # has been cleaned.
+  qapi_all_modules += ['machine-target']
+endif
+
+if have_block
+  qapi_all_modules += qapi_block_modules
+endif
+
 qapi_storage_daemon_modules = [
   'block-core',
   'char',
-- 
2.26.2



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

* Re: [PATCH v3 00/11] user-mode: Prune build dependencies (part 3)
  2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
                   ` (10 preceding siblings ...)
  2020-09-30 16:49 ` [PATCH v3 11/11] qapi: Restrict code generated for user-mode Philippe Mathieu-Daudé
@ 2020-09-30 17:15 ` Eduardo Habkost
  2020-09-30 17:24   ` Paolo Bonzini
  11 siblings, 1 reply; 24+ messages in thread
From: Eduardo Habkost @ 2020-09-30 17:15 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Markus Armbruster, Peter Lieven,
	qemu-devel, Laurent Vivier, Paolo Bonzini, Max Reitz,
	Michael Roth, Richard Henderson

On Wed, Sep 30, 2020 at 06:49:38PM +0200, Philippe Mathieu-Daudé wrote:
> This is the third part of a series reducing user-mode
> dependencies. By stripping out unused code, the build
> and testing time is reduced (as is space used by objects).

I'm queueing patches 2-9 on machine-next.  Thanks!

Markus, Eric: I can merge the QAPI patches (1, 11) if I get an
Acked-by.

I'll send separate comments on patch 10.

> 
> Part 3:
> - Extract code not related to user-mode from hw/core/qdev-properties.c
> - Reduce user-mode QAPI generated files
> 
> Since v2:
> - Fixed UuidInfo placed in incorrect json
> - Rebased on Meson
> - Include X86CPUFeatureWord unmerged from part 2
> 
> Since v1:
> - Addressed Richard and Paolo review comments
> 
> Patches missing review: QAPI ones :)
> - #1  'qapi: Restrict query-uuid command to block code'
> - #11 'qapi: Restrict code generated for user-mode'
> 
> Green CI: https://gitlab.com/philmd/qemu/-/pipelines/196505787
> 
> v2: https://www.mail-archive.com/qemu-devel@nongnu.org/msg688879.html
> v1: https://www.mail-archive.com/qemu-devel@nongnu.org/msg688486.html
> 
> Philippe Mathieu-Daudé (11):
>   qapi: Restrict query-uuid command to block code
>   hw/core/qdev-properties: Use qemu_strtol() in set_mac() handler
>   hw/core/qdev-properties: Use qemu_strtoul() in set_pci_host_devaddr()
>   hw/core/qdev-properties: Fix code style
>   hw/core/qdev-properties: Export enum-related functions
>   hw/core/qdev-properties: Export qdev_prop_enum
>   hw/core/qdev-properties: Export some integer-related functions
>   hw/core/qdev-properties: Extract system-mode specific properties
>   hw/core: Add qdev stub for user-mode
>   target/i386: Restrict X86CPUFeatureWord to X86 targets
>   qapi: Restrict code generated for user-mode
> 
>  qapi/block.json                  |  30 ++
>  qapi/machine-target.json         |  45 ++
>  qapi/machine.json                |  72 ---
>  hw/core/qdev-prop-internal.h     |  30 ++
>  include/hw/qdev-properties.h     |   1 +
>  block/iscsi.c                    |   2 +-
>  hw/core/qdev-properties-system.c | 687 ++++++++++++++++++++++++++++-
>  hw/core/qdev-properties.c        | 735 ++-----------------------------
>  stubs/qdev-system.c              |  24 +
>  stubs/uuid.c                     |   2 +-
>  target/i386/cpu.c                |   2 +-
>  target/i386/feature-stub.c       |  23 +
>  qapi/meson.build                 |  51 ++-
>  stubs/meson.build                |   5 +-
>  target/i386/meson.build          |   1 +
>  15 files changed, 915 insertions(+), 795 deletions(-)
>  create mode 100644 hw/core/qdev-prop-internal.h
>  create mode 100644 stubs/qdev-system.c
>  create mode 100644 target/i386/feature-stub.c
> 
> -- 
> 2.26.2
> 

-- 
Eduardo



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

* Re: [PATCH v3 10/11] target/i386: Restrict X86CPUFeatureWord to X86 targets
  2020-09-30 16:49 ` [PATCH v3 10/11] target/i386: Restrict X86CPUFeatureWord to X86 targets Philippe Mathieu-Daudé
@ 2020-09-30 17:18   ` Eduardo Habkost
  0 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2020-09-30 17:18 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Michael Roth, qemu-block, Markus Armbruster, Peter Lieven,
	qemu-devel, Laurent Vivier, Max Reitz, Ronnie Sahlberg,
	Paolo Bonzini, Richard Henderson, Richard Henderson

On Wed, Sep 30, 2020 at 06:49:48PM +0200, Philippe Mathieu-Daudé wrote:
> Only qemu-system-FOO and qemu-storage-daemon provide QMP
> monitors, therefore such declarations and definitions are
> irrelevant for user-mode emulation.
> 
> Restricting the x86-specific commands to machine-target.json
> pulls less QAPI-generated code into user-mode.
> 
> Add a stub to satisfy linking in user-mode:
> 
>   /usr/bin/ld: libqemu-i386-linux-user.fa.p/target_i386_cpu.c.o: in function `x86_cpu_get_feature_words':
>   target/i386/cpu.c:4643: undefined reference to `visit_type_X86CPUFeatureWordInfoList'
>   collect2: error: ld returned 1 exit status
>   make: *** [Makefile.ninja:1125: qemu-i386] Error 1
> 

If you don't want the QAPI definitions in user mode, there's no
reason to register the properties in user mode.  Wrapping #ifdef
around "feature-words" and "filtered-features" registration would
be simpler than adding a stub.

> Acked-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> v3: Reworded + Meson rebase
> ---
>  qapi/machine-target.json   | 45 ++++++++++++++++++++++++++++++++++++++
>  qapi/machine.json          | 42 -----------------------------------
>  target/i386/cpu.c          |  2 +-
>  target/i386/feature-stub.c | 23 +++++++++++++++++++
>  target/i386/meson.build    |  1 +
>  5 files changed, 70 insertions(+), 43 deletions(-)
>  create mode 100644 target/i386/feature-stub.c
> 
> diff --git a/qapi/machine-target.json b/qapi/machine-target.json
> index 698850cc78..b4d769a53b 100644
> --- a/qapi/machine-target.json
> +++ b/qapi/machine-target.json
> @@ -4,6 +4,51 @@
>  # This work is licensed under the terms of the GNU GPL, version 2 or later.
>  # See the COPYING file in the top-level directory.
>  
> +##
> +# @X86CPURegister32:
> +#
> +# A X86 32-bit register
> +#
> +# Since: 1.5
> +##
> +{ 'enum': 'X86CPURegister32',
> +  'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ],
> +  'if': 'defined(TARGET_I386)' }
> +
> +##
> +# @X86CPUFeatureWordInfo:
> +#
> +# Information about a X86 CPU feature word
> +#
> +# @cpuid-input-eax: Input EAX value for CPUID instruction for that feature word
> +#
> +# @cpuid-input-ecx: Input ECX value for CPUID instruction for that
> +#                   feature word
> +#
> +# @cpuid-register: Output register containing the feature bits
> +#
> +# @features: value of output register, containing the feature bits
> +#
> +# Since: 1.5
> +##
> +{ 'struct': 'X86CPUFeatureWordInfo',
> +  'data': { 'cpuid-input-eax': 'int',
> +            '*cpuid-input-ecx': 'int',
> +            'cpuid-register': 'X86CPURegister32',
> +            'features': 'int' },
> +  'if': 'defined(TARGET_I386)' }
> +
> +##
> +# @DummyForceArrays:
> +#
> +# Not used by QMP; hack to let us use X86CPUFeatureWordInfoList internally
> +#
> +# Since: 2.5
> +##
> +{ 'struct': 'DummyForceArrays',
> +  'data': { 'unused': ['X86CPUFeatureWordInfo'] },
> +  'if': 'defined(TARGET_I386)' }
> +
>  ##
>  # @CpuModelInfo:
>  #
> diff --git a/qapi/machine.json b/qapi/machine.json
> index 72f014bb5b..cb878acdac 100644
> --- a/qapi/machine.json
> +++ b/qapi/machine.json
> @@ -544,48 +544,6 @@
>     'dst': 'uint16',
>     'val': 'uint8' }}
>  
> -##
> -# @X86CPURegister32:
> -#
> -# A X86 32-bit register
> -#
> -# Since: 1.5
> -##
> -{ 'enum': 'X86CPURegister32',
> -  'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ] }
> -
> -##
> -# @X86CPUFeatureWordInfo:
> -#
> -# Information about a X86 CPU feature word
> -#
> -# @cpuid-input-eax: Input EAX value for CPUID instruction for that feature word
> -#
> -# @cpuid-input-ecx: Input ECX value for CPUID instruction for that
> -#                   feature word
> -#
> -# @cpuid-register: Output register containing the feature bits
> -#
> -# @features: value of output register, containing the feature bits
> -#
> -# Since: 1.5
> -##
> -{ 'struct': 'X86CPUFeatureWordInfo',
> -  'data': { 'cpuid-input-eax': 'int',
> -            '*cpuid-input-ecx': 'int',
> -            'cpuid-register': 'X86CPURegister32',
> -            'features': 'int' } }
> -
> -##
> -# @DummyForceArrays:
> -#
> -# Not used by QMP; hack to let us use X86CPUFeatureWordInfoList internally
> -#
> -# Since: 2.5
> -##
> -{ 'struct': 'DummyForceArrays',
> -  'data': { 'unused': ['X86CPUFeatureWordInfo'] } }
> -
>  ##
>  # @NumaCpuOptions:
>  #
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 3ffd877dd5..d45fa217cc 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -38,7 +38,7 @@
>  #include "qemu/option.h"
>  #include "qemu/config-file.h"
>  #include "qapi/error.h"
> -#include "qapi/qapi-visit-machine.h"
> +#include "qapi/qapi-visit-machine-target.h"
>  #include "qapi/qapi-visit-run-state.h"
>  #include "qapi/qmp/qdict.h"
>  #include "qapi/qmp/qerror.h"
> diff --git a/target/i386/feature-stub.c b/target/i386/feature-stub.c
> new file mode 100644
> index 0000000000..787c3c7fa1
> --- /dev/null
> +++ b/target/i386/feature-stub.c
> @@ -0,0 +1,23 @@
> +/*
> + * QAPI x86 CPU features stub
> + *
> + * Copyright (c) 2020 Red Hat, Inc.
> + *
> + * Author:
> + *   Philippe Mathieu-Daudé <philmd@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qapi/error.h"
> +#include "qapi/qapi-visit-machine-target.h"
> +
> +bool visit_type_X86CPUFeatureWordInfoList(Visitor *v, const char *name,
> +                                          X86CPUFeatureWordInfoList **obj,
> +                                          Error **errp)
> +{
> +    g_assert_not_reached();
> +}
> diff --git a/target/i386/meson.build b/target/i386/meson.build
> index e0b71ade56..0c5d9e6caf 100644
> --- a/target/i386/meson.build
> +++ b/target/i386/meson.build
> @@ -5,6 +5,7 @@ i386_ss.add(files(
>    'helper.c',
>    'xsave_helper.c',
>  ))
> +i386_ss.add(when: 'CONFIG_SOFTMMU', if_false: files('feature-stub.c'))
>  i386_ss.add(when: 'CONFIG_TCG', if_true: files(
>    'bpt_helper.c',
>    'cc_helper.c',
> -- 
> 2.26.2
> 
> 

-- 
Eduardo



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

* Re: [PATCH v3 00/11] user-mode: Prune build dependencies (part 3)
  2020-09-30 17:15 ` [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Eduardo Habkost
@ 2020-09-30 17:24   ` Paolo Bonzini
  2020-09-30 17:27     ` Eduardo Habkost
  2020-09-30 18:56     ` Alex Bennée
  0 siblings, 2 replies; 24+ messages in thread
From: Paolo Bonzini @ 2020-09-30 17:24 UTC (permalink / raw)
  To: Eduardo Habkost, Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Markus Armbruster, Peter Lieven,
	qemu-devel, Laurent Vivier, Max Reitz, Michael Roth,
	Richard Henderson

On 30/09/20 19:15, Eduardo Habkost wrote:
> On Wed, Sep 30, 2020 at 06:49:38PM +0200, Philippe Mathieu-Daudé wrote:
>> This is the third part of a series reducing user-mode
>> dependencies. By stripping out unused code, the build
>> and testing time is reduced (as is space used by objects).
> I'm queueing patches 2-9 on machine-next.  Thanks!
> 
> Markus, Eric: I can merge the QAPI patches (1, 11) if I get an
> Acked-by.
> 
> I'll send separate comments on patch 10.
> 

1-8 is fine, but I think 9-11 is too much complication (especially not
really future-proof) for the benefit.

Paolo



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

* Re: [PATCH v3 00/11] user-mode: Prune build dependencies (part 3)
  2020-09-30 17:24   ` Paolo Bonzini
@ 2020-09-30 17:27     ` Eduardo Habkost
  2020-10-01 12:56       ` Philippe Mathieu-Daudé
  2020-09-30 18:56     ` Alex Bennée
  1 sibling, 1 reply; 24+ messages in thread
From: Eduardo Habkost @ 2020-09-30 17:27 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Kevin Wolf, Daniel P. Berrangé,
	qemu-block, Philippe Mathieu-Daudé,
	Peter Lieven, qemu-devel, Laurent Vivier, Ronnie Sahlberg,
	Max Reitz, Michael Roth, Markus Armbruster, Richard Henderson

On Wed, Sep 30, 2020 at 07:24:24PM +0200, Paolo Bonzini wrote:
> On 30/09/20 19:15, Eduardo Habkost wrote:
> > On Wed, Sep 30, 2020 at 06:49:38PM +0200, Philippe Mathieu-Daudé wrote:
> >> This is the third part of a series reducing user-mode
> >> dependencies. By stripping out unused code, the build
> >> and testing time is reduced (as is space used by objects).
> > I'm queueing patches 2-9 on machine-next.  Thanks!
> > 
> > Markus, Eric: I can merge the QAPI patches (1, 11) if I get an
> > Acked-by.
> > 
> > I'll send separate comments on patch 10.
> > 
> 
> 1-8 is fine, but I think 9-11 is too much complication (especially not
> really future-proof) for the benefit.

I'll dequeue patch 9 while this is discussed.

-- 
Eduardo



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

* Re: [PATCH v3 00/11] user-mode: Prune build dependencies (part 3)
  2020-09-30 17:24   ` Paolo Bonzini
  2020-09-30 17:27     ` Eduardo Habkost
@ 2020-09-30 18:56     ` Alex Bennée
  2020-09-30 19:05       ` Paolo Bonzini
  1 sibling, 1 reply; 24+ messages in thread
From: Alex Bennée @ 2020-09-30 18:56 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Eduardo Habkost, qemu-block, qemu-devel, Peter Lieven,
	Markus Armbruster, Laurent Vivier, Ronnie Sahlberg, Max Reitz,
	Philippe Mathieu-Daudé,
	Michael Roth, Richard Henderson


Paolo Bonzini <pbonzini@redhat.com> writes:

> On 30/09/20 19:15, Eduardo Habkost wrote:
>> On Wed, Sep 30, 2020 at 06:49:38PM +0200, Philippe Mathieu-Daudé wrote:
>>> This is the third part of a series reducing user-mode
>>> dependencies. By stripping out unused code, the build
>>> and testing time is reduced (as is space used by objects).
>> I'm queueing patches 2-9 on machine-next.  Thanks!
>> 
>> Markus, Eric: I can merge the QAPI patches (1, 11) if I get an
>> Acked-by.
>> 
>> I'll send separate comments on patch 10.
>> 
>
> 1-8 is fine, but I think 9-11 is too much complication (especially not
> really future-proof) for the benefit.

Isn't qdev considered an internal API for our object and device lifetime
handling (which should be shared) versus QAPI which only exists for
system emulation and tool integration? That is of course assuming
libvirt is never going to want to know about linux-user emulation?

>
> Paolo


-- 
Alex Bennée


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

* Re: [PATCH v3 00/11] user-mode: Prune build dependencies (part 3)
  2020-09-30 18:56     ` Alex Bennée
@ 2020-09-30 19:05       ` Paolo Bonzini
  0 siblings, 0 replies; 24+ messages in thread
From: Paolo Bonzini @ 2020-09-30 19:05 UTC (permalink / raw)
  To: Alex Bennée
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Eduardo Habkost, qemu-block, qemu-devel, Peter Lieven,
	Markus Armbruster, Laurent Vivier, Ronnie Sahlberg, Max Reitz,
	Philippe Mathieu-Daudé,
	Michael Roth, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 709 bytes --]

Il mer 30 set 2020, 20:57 Alex Bennée <alex.bennee@linaro.org> ha scritto:

> > 1-8 is fine, but I think 9-11 is too much complication (especially not
> > really future-proof) for the benefit.
>
> Isn't qdev considered an internal API for our object and device lifetime
> handling (which should be shared) versus QAPI which only exists for
> system emulation and tool integration?
>

qdev is nothing more than a bunch of QOM classes, and QAPI is an integral
part of QOM (though properties, which are used when setting up CPUs in user
more emulation)

Therefore, even though most of the QAPI schema is specific to system
emulation and tools, a small part is used by common code.

Paolo

>

[-- Attachment #2: Type: text/html, Size: 1298 bytes --]

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

* Re: [PATCH v3 01/11] qapi: Restrict query-uuid command to block code
  2020-09-30 16:49 ` [PATCH v3 01/11] qapi: Restrict query-uuid command to block code Philippe Mathieu-Daudé
@ 2020-10-01  5:04   ` Markus Armbruster
  2020-10-01 10:22     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 24+ messages in thread
From: Markus Armbruster @ 2020-10-01  5:04 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Michael Roth, qemu-block, Richard Henderson, Peter Lieven,
	qemu-devel, Laurent Vivier, Ronnie Sahlberg, Paolo Bonzini,
	Max Reitz, Eduardo Habkost

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> In commit f68c01470b we restricted the query-uuid command to
> machine code, but it is incorrect, as it is also used by the
> tools.  Therefore move this command again, but to block.json,
> which is shared by machine code and tools.
>
> Fixes: f68c01470b ("qapi: Restrict query-uuid command to machine code")
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

UUIDs are not really a block-specific thing.

QMP query-uuid and HMP info uuid are about the VM, like query-name.
That's why they used to be next to query-name in misc.json.

There's one additional use in block/iscsi.c's get_initiator_name().  I
figure that's what pulls it into tools via qemu-img.

Which other QAPI modules are shared by all the executables that use it?

What about reverting the commit?  How bad would that be for user mode?



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

* Re: [PATCH v3 11/11] qapi: Restrict code generated for user-mode
  2020-09-30 16:49 ` [PATCH v3 11/11] qapi: Restrict code generated for user-mode Philippe Mathieu-Daudé
@ 2020-10-01  5:09   ` Markus Armbruster
  2020-10-01 10:23     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 24+ messages in thread
From: Markus Armbruster @ 2020-10-01  5:09 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Michael Roth, qemu-block, Richard Henderson, Richard Henderson,
	Peter Lieven, qemu-devel, Laurent Vivier, Ronnie Sahlberg,
	Paolo Bonzini, Max Reitz, Eduardo Habkost

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> A lot of QAPI generated code is never used by user-mode.
>
> Split out qapi_system_modules and qapi_system_or_tools_modules
> from the qapi_all_modules array. We now have 3 groups:
> - always used
> - use by system-mode or tools (usually by the block layer)
> - only used by system-mode
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> Resetting due to Meson update:
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  qapi/meson.build | 51 ++++++++++++++++++++++++++++++++++--------------
>  1 file changed, 36 insertions(+), 15 deletions(-)
>
> diff --git a/qapi/meson.build b/qapi/meson.build
> index 7c4a89a882..ba9677ba97 100644
> --- a/qapi/meson.build
> +++ b/qapi/meson.build
> @@ -14,39 +14,60 @@ util_ss.add(files(
>  ))
>  
>  qapi_all_modules = [
> +  'common',
> +  'introspect',
> +  'misc',
> +]
> +
> +qapi_system_modules = [
>    'acpi',
>    'audio',
> +  'dump',
> +  'machine-target',
> +  'machine',
> +  'migration',
> +  'misc-target',
> +  'net',
> +  'pci',
> +  'qdev',
> +  'rdma',
> +  'rocker',
> +  'tpm',
> +  'trace',
> +]
> +
> +# system or tools
> +qapi_block_modules = [
>    'authz',
>    'block-core',
>    'block',
>    'char',
> -  'common',
>    'control',
>    'crypto',
> -  'dump',
>    'error',
> -  'introspect',
>    'job',
> -  'machine',
> -  'machine-target',
> -  'migration',
> -  'misc',
> -  'misc-target',
> -  'net',
>    'pragma',
> -  'qdev',
> -  'pci',
>    'qom',
> -  'rdma',
> -  'rocker',
>    'run-state',
>    'sockets',
> -  'tpm',
> -  'trace',
>    'transaction',
>    'ui',
>  ]

Most of these aren't "block modules".  Name the thing
qapi_system_or_tools_modules?

> +if have_system
> +  qapi_all_modules += qapi_system_modules
> +elif have_user
> +  # Temporary kludge because X86CPUFeatureWordInfo is not
> +  # restricted to system-mode. This should be removed (along
> +  # with target/i386/feature-stub.c) once target/i386/cpu.c
> +  # has been cleaned.
> +  qapi_all_modules += ['machine-target']
> +endif
> +
> +if have_block

Aha, precedence for using "block" as an abbreviation of "system or
tools".  I find that confusing.

> +  qapi_all_modules += qapi_block_modules
> +endif
> +
>  qapi_storage_daemon_modules = [
>    'block-core',
>    'char',



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

* Re: [PATCH v3 01/11] qapi: Restrict query-uuid command to block code
  2020-10-01  5:04   ` Markus Armbruster
@ 2020-10-01 10:22     ` Philippe Mathieu-Daudé
  2020-10-01 12:24       ` Markus Armbruster
  0 siblings, 1 reply; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-01 10:22 UTC (permalink / raw)
  To: Markus Armbruster, Paolo Bonzini, Igor Mammedov
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Michael Roth, qemu-block, Richard Henderson, Peter Lieven,
	qemu-devel, Laurent Vivier, Ronnie Sahlberg, Max Reitz,
	Eduardo Habkost

+Igor

On 10/1/20 7:04 AM, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
> 
>> In commit f68c01470b we restricted the query-uuid command to
>> machine code, but it is incorrect, as it is also used by the
>> tools.  Therefore move this command again, but to block.json,
>> which is shared by machine code and tools.
>>
>> Fixes: f68c01470b ("qapi: Restrict query-uuid command to machine code")
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> 
> UUIDs are not really a block-specific thing.

This is the discussion we had in v1 with Igor...

UuidInfo is a iSCSI-specific "thing", the original commit
is f9dadc9855 ("iSCSI: add configuration variables for iSCSI")
then Paolo introduced 'UuidInfo' in commit 5accc8408f
("scsi: prefer UUID to VM name for the initiator name") but
is misnamed?

> 
> QMP query-uuid and HMP info uuid are about the VM, like query-name.
> That's why they used to be next to query-name in misc.json.

This is GuidInfo, not UuidInfo...

GuidInfo is correctly in machine.json.

> 
> There's one additional use in block/iscsi.c's get_initiator_name().  I
> figure that's what pulls it into tools via qemu-img.

Yes.

> 
> Which other QAPI modules are shared by all the executables that use it?

None?

> 
> What about reverting the commit?  How bad would that be for user mode?
> 

The problem is not user-mode, is linking tools.



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

* Re: [PATCH v3 11/11] qapi: Restrict code generated for user-mode
  2020-10-01  5:09   ` Markus Armbruster
@ 2020-10-01 10:23     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-01 10:23 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Michael Roth, qemu-block, Richard Henderson, Richard Henderson,
	Peter Lieven, qemu-devel, Laurent Vivier, Ronnie Sahlberg,
	Paolo Bonzini, Max Reitz, Eduardo Habkost

On 10/1/20 7:09 AM, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
> 
>> A lot of QAPI generated code is never used by user-mode.
>>
>> Split out qapi_system_modules and qapi_system_or_tools_modules
>> from the qapi_all_modules array. We now have 3 groups:
>> - always used
>> - use by system-mode or tools (usually by the block layer)
>> - only used by system-mode
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>> Resetting due to Meson update:
>> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>  qapi/meson.build | 51 ++++++++++++++++++++++++++++++++++--------------
>>  1 file changed, 36 insertions(+), 15 deletions(-)
>>
>> diff --git a/qapi/meson.build b/qapi/meson.build
>> index 7c4a89a882..ba9677ba97 100644
>> --- a/qapi/meson.build
>> +++ b/qapi/meson.build
>> @@ -14,39 +14,60 @@ util_ss.add(files(
>>  ))
>>  
>>  qapi_all_modules = [
>> +  'common',
>> +  'introspect',
>> +  'misc',
>> +]
>> +
>> +qapi_system_modules = [
>>    'acpi',
>>    'audio',
>> +  'dump',
>> +  'machine-target',
>> +  'machine',
>> +  'migration',
>> +  'misc-target',
>> +  'net',
>> +  'pci',
>> +  'qdev',
>> +  'rdma',
>> +  'rocker',
>> +  'tpm',
>> +  'trace',
>> +]
>> +
>> +# system or tools
>> +qapi_block_modules = [
>>    'authz',
>>    'block-core',
>>    'block',
>>    'char',
>> -  'common',
>>    'control',
>>    'crypto',
>> -  'dump',
>>    'error',
>> -  'introspect',
>>    'job',
>> -  'machine',
>> -  'machine-target',
>> -  'migration',
>> -  'misc',
>> -  'misc-target',
>> -  'net',
>>    'pragma',
>> -  'qdev',
>> -  'pci',
>>    'qom',
>> -  'rdma',
>> -  'rocker',
>>    'run-state',
>>    'sockets',
>> -  'tpm',
>> -  'trace',
>>    'transaction',
>>    'ui',
>>  ]
> 
> Most of these aren't "block modules".  Name the thing
> qapi_system_or_tools_modules?

This is why I used first, then realized this is defined
as:
  have_block = have_system or have_tools

> 
>> +if have_system
>> +  qapi_all_modules += qapi_system_modules
>> +elif have_user
>> +  # Temporary kludge because X86CPUFeatureWordInfo is not
>> +  # restricted to system-mode. This should be removed (along
>> +  # with target/i386/feature-stub.c) once target/i386/cpu.c
>> +  # has been cleaned.
>> +  qapi_all_modules += ['machine-target']
>> +endif
>> +
>> +if have_block
> 
> Aha, precedence for using "block" as an abbreviation of "system or
> tools".  I find that confusing.

I'll use qapi_system_or_tools_modules back, it is clearer, thanks.

> 
>> +  qapi_all_modules += qapi_block_modules
>> +endif
>> +
>>  qapi_storage_daemon_modules = [
>>    'block-core',
>>    'char',
> 



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

* Re: [PATCH v3 01/11] qapi: Restrict query-uuid command to block code
  2020-10-01 10:22     ` Philippe Mathieu-Daudé
@ 2020-10-01 12:24       ` Markus Armbruster
  0 siblings, 0 replies; 24+ messages in thread
From: Markus Armbruster @ 2020-10-01 12:24 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Laurent Vivier, Daniel P. Berrangé,
	Eduardo Habkost, qemu-block, Peter Lieven, Michael Roth,
	qemu-devel, Ronnie Sahlberg, Igor Mammedov, Paolo Bonzini,
	Max Reitz, Richard Henderson

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> +Igor
>
> On 10/1/20 7:04 AM, Markus Armbruster wrote:
>> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
>> 
>>> In commit f68c01470b we restricted the query-uuid command to
>>> machine code, but it is incorrect, as it is also used by the
>>> tools.  Therefore move this command again, but to block.json,
>>> which is shared by machine code and tools.
>>>
>>> Fixes: f68c01470b ("qapi: Restrict query-uuid command to machine code")
>>>
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> 
>> UUIDs are not really a block-specific thing.
>
> This is the discussion we had in v1 with Igor...
>
> UuidInfo is a iSCSI-specific "thing", the original commit
> is f9dadc9855 ("iSCSI: add configuration variables for iSCSI")
> then Paolo introduced 'UuidInfo' in commit 5accc8408f
> ("scsi: prefer UUID to VM name for the initiator name") but
> is misnamed?

UuidInfo is also used by query-uuid and info uuid.  query-uuid returns
whatever was set with option -uuid.  Option's help text calls it
"machine UUID".

>> QMP query-uuid and HMP info uuid are about the VM, like query-name.
>> That's why they used to be next to query-name in misc.json.
>
> This is GuidInfo, not UuidInfo...
>
> GuidInfo is correctly in machine.json.

GuidInfo is used by query-vm-generation-id and info vm-generation-id.
query-vm-generation-id returns the value of property "guid" of the
vmgenid device.

I don't know why we have both.

>> There's one additional use in block/iscsi.c's get_initiator_name().  I
>> figure that's what pulls it into tools via qemu-img.
>
> Yes.
>
>> 
>> Which other QAPI modules are shared by all the executables that use it?
>
> None?

I'd expect at least all the modules block.json includes:
block-core.json, common.json, crypto.json, job.json, sockets.json.

>> What about reverting the commit?  How bad would that be for user mode?
>> 
>
> The problem is not user-mode, is linking tools.

Which modules are linked now?



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

* Re: [PATCH v3 00/11] user-mode: Prune build dependencies (part 3)
  2020-09-30 17:27     ` Eduardo Habkost
@ 2020-10-01 12:56       ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 24+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-01 12:56 UTC (permalink / raw)
  To: Eduardo Habkost, Paolo Bonzini
  Cc: Kevin Wolf, Daniel P. Berrangé,
	Ronnie Sahlberg, qemu-block, Markus Armbruster, Peter Lieven,
	qemu-devel, Laurent Vivier, Max Reitz, Michael Roth,
	Richard Henderson

On 9/30/20 7:27 PM, Eduardo Habkost wrote:
> On Wed, Sep 30, 2020 at 07:24:24PM +0200, Paolo Bonzini wrote:
>> On 30/09/20 19:15, Eduardo Habkost wrote:
>>> On Wed, Sep 30, 2020 at 06:49:38PM +0200, Philippe Mathieu-Daudé wrote:
>>>> This is the third part of a series reducing user-mode
>>>> dependencies. By stripping out unused code, the build
>>>> and testing time is reduced (as is space used by objects).
>>> I'm queueing patches 2-9 on machine-next.  Thanks!
>>>
>>> Markus, Eric: I can merge the QAPI patches (1, 11) if I get an
>>> Acked-by.
>>>
>>> I'll send separate comments on patch 10.
>>>
>>
>> 1-8 is fine, but I think 9-11 is too much complication (especially not
>> really future-proof) for the benefit.
> 
> I'll dequeue patch 9 while this is discussed.
Please also dequeue 1 :(

Markus hasn't sent negative comments on 2-8 so these should be OK.



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

end of thread, other threads:[~2020-10-01 12:57 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 16:49 [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Philippe Mathieu-Daudé
2020-09-30 16:49 ` [PATCH v3 01/11] qapi: Restrict query-uuid command to block code Philippe Mathieu-Daudé
2020-10-01  5:04   ` Markus Armbruster
2020-10-01 10:22     ` Philippe Mathieu-Daudé
2020-10-01 12:24       ` Markus Armbruster
2020-09-30 16:49 ` [PATCH v3 02/11] hw/core/qdev-properties: Use qemu_strtol() in set_mac() handler Philippe Mathieu-Daudé
2020-09-30 16:49 ` [PATCH v3 03/11] hw/core/qdev-properties: Use qemu_strtoul() in set_pci_host_devaddr() Philippe Mathieu-Daudé
2020-09-30 16:49 ` [PATCH v3 04/11] hw/core/qdev-properties: Fix code style Philippe Mathieu-Daudé
2020-09-30 16:49 ` [PATCH v3 05/11] hw/core/qdev-properties: Export enum-related functions Philippe Mathieu-Daudé
2020-09-30 16:49 ` [PATCH v3 06/11] hw/core/qdev-properties: Export qdev_prop_enum Philippe Mathieu-Daudé
2020-09-30 16:49 ` [PATCH v3 07/11] hw/core/qdev-properties: Export some integer-related functions Philippe Mathieu-Daudé
2020-09-30 16:49 ` [PATCH v3 08/11] hw/core/qdev-properties: Extract system-mode specific properties Philippe Mathieu-Daudé
2020-09-30 16:49 ` [PATCH v3 09/11] hw/core: Add qdev stub for user-mode Philippe Mathieu-Daudé
2020-09-30 16:49 ` [PATCH v3 10/11] target/i386: Restrict X86CPUFeatureWord to X86 targets Philippe Mathieu-Daudé
2020-09-30 17:18   ` Eduardo Habkost
2020-09-30 16:49 ` [PATCH v3 11/11] qapi: Restrict code generated for user-mode Philippe Mathieu-Daudé
2020-10-01  5:09   ` Markus Armbruster
2020-10-01 10:23     ` Philippe Mathieu-Daudé
2020-09-30 17:15 ` [PATCH v3 00/11] user-mode: Prune build dependencies (part 3) Eduardo Habkost
2020-09-30 17:24   ` Paolo Bonzini
2020-09-30 17:27     ` Eduardo Habkost
2020-10-01 12:56       ` Philippe Mathieu-Daudé
2020-09-30 18:56     ` Alex Bennée
2020-09-30 19:05       ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.