qom-next queue, first batch: fixed-width visitors
Hello Anthony,
To get moving with the merge of qom-next into qemu.git, now that the Makefile PULL is in, please pull a first small batch, grouping patches directly related to fixed-width visitors.
Outlook:
A second batch would include the QBus refactoring - still cherry-picking, reordering and re-testing.
I'm preparing a two-patch realize series that could get appended to the second. Still open are the static property movements and their prerequisites.
CPU-related patches are split off into their own pull.
Jan, this does not include the big file movement but the largest part of the qdev-properties.c changes and in particular the ones that affect PCI. I suggest that you rebase on this one and me/Paolo the remaining parts on yours.
The following changes since commit fa79c914efd35cb60e0bc18512c03690c48b13e2:
Merge remote-tracking branch 'bonzini/nested-makefiles-3' into staging (2012-06-07 17:21:40 +0800)
are available in the git repository at:
git://repo.or.cz/qemu/afaerber.git qom-next-1
Andreas Färber (1):
target-i386: Use uint32 visitor for [x]level properties
Michael Roth (6):
qapi: Add Visitor interfaces for uint*_t and int*_t
qapi: Unit tests for visitor-based serialization
qapi: String visitor, use %f representation for floats
qapi: Add String visitor coverage to serialization unit tests
qdev: Use int32_t container for devfn property
qdev: Switch property accessors to fixed-width visitor interfaces
Paolo Bonzini (1):
qdev: Remove PropertyInfo range checking
hw/mc146818rtc.c | 7 - hw/pci.c | 2 +- hw/pci.h | 2 +- hw/qdev-addr.c | 4 +- hw/qdev-properties.c | 205 ++++------ hw/qdev.h | 4 +- qapi/qapi-visit-core.c | 139 +++++++ qapi/qapi-visit-core.h | 16 + qapi/string-output-visitor.c | 2 +- target-i386/cpu.c | 42 +-- tests/Makefile | 4 +- tests/test-string-output-visitor.c | 2 +- tests/test-visitor-serialization.c | 784 ++++++++++++++++++++++++++++++++++++ 13 files changed, 1041 insertions(+), 172 deletions(-) create mode 100644 tests/test-visitor-serialization.c
PATCH 1/8 qapi: Add Visitor interfaces for uint*_t and int*_t
From: Michael Roth <[email protected]>
This adds visitor interfaces for fixed-width integers types. Implementing these in visitors is optional, otherwise we fall back to visit_type_int() (int64_t) with some additional bounds checking to avoid integer overflows for cases where the value fetched exceeds the bounds of our target C type.
--- hw/mc146818rtc.c | 7 --- qapi/qapi-visit-core.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++ qapi/qapi-visit-core.h | 16 ++++++ 3 files changed, 155 insertions(+), 7 deletions(-)
hw/mc146818rtc.c +0 -7
@@ -599,13 +599,6 @@ static const MemoryRegionOps cmos_ops = { .old_portio = cmos_portio }; -// FIXME add int32 visitor -static void visit_type_int32 (Visitor *v,int *value,const char *name,Error **errp) -{ -int64_t val = *value; -visit_type_int (v, &val, name, errp); -} -static void rtc_get_date (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp) {
qapi/qapi-visit-core.c +139 -0
145 lines not on this page · raw message
qapi/qapi-visit-core.h +16 -0
@@ -52,6 +52,14 @@ struct Visitorvoid (*start_handle)(Visitor *v,void **obj,const char *kind,const char *name,Error **errp);void (*end_handle)(Visitor *v,Error **errp); +void (*type_uint8)(Visitor *v,uint8_t *obj,const char *name,Error **errp); +void (*type_uint16)(Visitor *v,uint16_t *obj,const char *name,Error **errp); +void (*type_uint32)(Visitor *v,uint32_t *obj,const char *name,Error **errp); +void (*type_uint64)(Visitor *v,uint64_t *obj,const char *name,Error **errp); +void (*type_int8)(Visitor *v,int8_t *obj,const char *name,Error **errp); +void (*type_int16)(Visitor *v,int16_t *obj,const char *name,Error **errp); +void (*type_int32)(Visitor *v,int32_t *obj,const char *name,Error **errp); +void (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp); }; void visit_start_handle(Visitor *v, void **obj, const char *kind,
@@ -69,6 +77,14 @@ void visit_end_optional(Visitor *v, Error **errp);void visit_type_enum (Visitor *v,int *obj,const char *strings[],const char *kind,const char *name,Error **errp);void visit_type_int (Visitor *v,int64_t *obj,const char *name,Error **errp); +void visit_type_uint8 (Visitor *v,uint8_t *obj,const char *name,Error **errp); +void visit_type_uint16 (Visitor *v,uint16_t *obj,const char *name,Error **errp); +void visit_type_uint32 (Visitor *v,uint32_t *obj,const char *name,Error **errp); +void visit_type_uint64 (Visitor *v,uint64_t *obj,const char *name,Error **errp); +void visit_type_int8 (Visitor *v,int8_t *obj,const char *name,Error **errp); +void visit_type_int16 (Visitor *v,int16_t *obj,const char *name,Error **errp); +void visit_type_int32 (Visitor *v,int32_t *obj,const char *name,Error **errp); +void visit_type_int64 (Visitor *v,int64_t *obj,const char *name,Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp);
Signature · 1 line
1.7.7
Re: [Qemu-devel] [PATCH 1/8] qapi: Add Visitor interfaces for uint*_t and int*_t
Quoted 32 lines · Andreas Färber
From: Michael Roth <[email protected]>
This adds visitor interfaces for fixed-width integers types. Implementing these in visitors is optional, otherwise we fall back to
visit_type_int()(int64_t) with some additional bounds checking to avoid integer overflows for cases where the value fetched exceeds the bounds of our target C type.qapi/qapi-visit-core.h +9
-0@@ -52,6 +52,14 @@ struct Visitorvoid (*start_handle)(Visitor *v,void **obj,const char *kind,const char *name,Error **errp);void (*end_handle)(Visitor *v,Error **errp); +void (*type_uint8)(Visitor *v,uint8_t *obj,const char *name,Error **errp); +void (*type_uint16)(Visitor *v,uint16_t *obj,const char *name,Error **errp); +void (*type_uint32)(Visitor *v,uint32_t *obj,const char *name,Error **errp); +void (*type_uint64)(Visitor *v,uint64_t *obj,const char *name,Error **errp); +void (*type_int8)(Visitor *v,int8_t *obj,const char *name,Error **errp); +void (*type_int16)(Visitor *v,int16_t *obj,const char *name,Error **errp); +void (*type_int32)(Visitor *v,int32_t *obj,const char *name,Error **errp); +void (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp); }; void visit_start_handle(Visitor *v, void **obj, const char *kind,@@ -69,6 +77,14 @@ void visit_end_optional(Visitor *v, Error **errp);void visit_type_enum (Visitor *v,int *obj,const char *strings[],const char *kind,const char *name,Error **errp);void visit_type_int (Visitor *v,int64_t *obj,const char *name,Error **errp); +void visit_type_uint8 (Visitor *v,uint8_t *obj,const char *name,Error **errp);
qapi/qapi-visit-core.h void visit_end_optional(Visitor *v, Error **errp); · line 90
Quoted 10 lines
qapi/qapi-visit-core.h +7
-0+void visit_type_uint16 (Visitor *v,uint16_t *obj,const char *name,Error **errp); +void visit_type_uint32 (Visitor *v,uint32_t *obj,const char *name,Error **errp); +void visit_type_uint64 (Visitor *v,uint64_t *obj,const char *name,Error **errp); +void visit_type_int8 (Visitor *v,int8_t *obj,const char *name,Error **errp); +void visit_type_int16 (Visitor *v,int16_t *obj,const char *name,Error **errp); +void visit_type_int32 (Visitor *v,int32_t *obj,const char *name,Error **errp); +void visit_type_int64 (Visitor *v,int64_t *obj,const char *name,Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp);
Shouldn't "scripts/qapi.py" be extended accordingly? (The c_type function.)
Thanks,
Laszlo
Re: [Qemu-devel] [PATCH 1/8] qapi: Add Visitor interfaces for uint*_t and int*_t
Am 09.06.2012 17:03, schrieb Laszlo Ersek:
Quoted 37 lines · Andreas Färber
Quoted 36 lines
From: Michael Roth <[email protected]>
This adds visitor interfaces for fixed-width integers types. Implementing these in visitors is optional, otherwise we fall back to
visit_type_int()(int64_t) with some additional bounds checking to avoid integer overflows for cases where the value fetched exceeds the bounds of our target C type.qapi/qapi-visit-core.h +13
-0@@ -52,6 +52,14 @@ struct Visitorvoid (*start_handle)(Visitor *v,void **obj,const char *kind,const char *name,Error **errp);void (*end_handle)(Visitor *v,Error **errp); +void (*type_uint8)(Visitor *v,uint8_t *obj,const char *name,Error **errp); +void (*type_uint16)(Visitor *v,uint16_t *obj,const char *name,Error **errp); +void (*type_uint32)(Visitor *v,uint32_t *obj,const char *name,Error **errp); +void (*type_uint64)(Visitor *v,uint64_t *obj,const char *name,Error **errp); +void (*type_int8)(Visitor *v,int8_t *obj,const char *name,Error **errp); +void (*type_int16)(Visitor *v,int16_t *obj,const char *name,Error **errp); +void (*type_int32)(Visitor *v,int32_t *obj,const char *name,Error **errp); +void (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp); }; void visit_start_handle(Visitor *v, void **obj, const char *kind,@@ -69,6 +77,14 @@ void visit_end_optional(Visitor *v, Error **errp);void visit_type_enum (Visitor *v,int *obj,const char *strings[],const char *kind,const char *name,Error **errp);void visit_type_int (Visitor *v,int64_t *obj,const char *name,Error **errp); +void visit_type_uint8 (Visitor *v,uint8_t *obj,const char *name,Error **errp); +void visit_type_uint16 (Visitor *v,uint16_t *obj,const char *name,Error **errp); +void visit_type_uint32 (Visitor *v,uint32_t *obj,const char *name,Error **errp); +void visit_type_uint64 (Visitor *v,uint64_t *obj,const char *name,Error **errp); +void visit_type_int8 (Visitor *v,int8_t *obj,const char *name,Error **errp);
Quoted 8 lines
qapi/qapi-visit-core.h void visit_end_optional(Visitor *v, Error **errp); · line 90
Quoted 6 lines
qapi/qapi-visit-core.h +3
-0+void visit_type_int16 (Visitor *v,int16_t *obj,const char *name,Error **errp); +void visit_type_int32 (Visitor *v,int32_t *obj,const char *name,Error **errp); +void visit_type_int64 (Visitor *v,int64_t *obj,const char *name,Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp);Shouldn't "
scripts/qapi.py" be extended accordingly? (Thec_typefunction.)
What does that affect?
Is it a blocker for this PULL or an improvement for a follow-up?
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 1/8] qapi: Add Visitor interfaces for uint*_t and int*_t
Quoted 47 lines · Andreas Färber
Am 09.06.2012 17:03, schrieb Laszlo Ersek:
Quoted 37 lines · Andreas Färber
Quoted 36 lines
From: Michael Roth <[email protected]>
This adds visitor interfaces for fixed-width integers types. Implementing these in visitors is optional, otherwise we fall back to
visit_type_int()(int64_t) with some additional bounds checking to avoid integer overflows for cases where the value fetched exceeds the bounds of our target C type.qapi/qapi-visit-core.h +13
-0@@ -52,6 +52,14 @@ struct Visitorvoid (*start_handle)(Visitor *v,void **obj,const char *kind,const char *name,Error **errp);void (*end_handle)(Visitor *v,Error **errp); +void (*type_uint8)(Visitor *v,uint8_t *obj,const char *name,Error **errp); +void (*type_uint16)(Visitor *v,uint16_t *obj,const char *name,Error **errp); +void (*type_uint32)(Visitor *v,uint32_t *obj,const char *name,Error **errp); +void (*type_uint64)(Visitor *v,uint64_t *obj,const char *name,Error **errp); +void (*type_int8)(Visitor *v,int8_t *obj,const char *name,Error **errp); +void (*type_int16)(Visitor *v,int16_t *obj,const char *name,Error **errp); +void (*type_int32)(Visitor *v,int32_t *obj,const char *name,Error **errp); +void (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp); }; void visit_start_handle(Visitor *v, void **obj, const char *kind,@@ -69,6 +77,14 @@ void visit_end_optional(Visitor *v, Error **errp);void visit_type_enum (Visitor *v,int *obj,const char *strings[],const char *kind,const char *name,Error **errp);void visit_type_int (Visitor *v,int64_t *obj,const char *name,Error **errp); +void visit_type_uint8 (Visitor *v,uint8_t *obj,const char *name,Error **errp); +void visit_type_uint16 (Visitor *v,uint16_t *obj,const char *name,Error **errp); +void visit_type_uint32 (Visitor *v,uint32_t *obj,const char *name,Error **errp); +void visit_type_uint64 (Visitor *v,uint64_t *obj,const char *name,Error **errp); +void visit_type_int8 (Visitor *v,int8_t *obj,const char *name,Error **errp);Quoted 8 lines
qapi/qapi-visit-core.h void visit_end_optional(Visitor *v, Error **errp); · line 90
Quoted 6 lines
qapi/qapi-visit-core.h +3
-0+void visit_type_int16 (Visitor *v,int16_t *obj,const char *name,Error **errp); +void visit_type_int32 (Visitor *v,int32_t *obj,const char *name,Error **errp); +void visit_type_int64 (Visitor *v,int64_t *obj,const char *name,Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp);Shouldn't "
scripts/qapi.py" be extended accordingly? (Thec_typefunction.)
Quoted 2 lines
What does that affect?
Is it a blocker for this PULL or an improvement for a follow-up?
The latter. As long as nothing actually uses these types there's no problem.
Laszlo
Re: [Qemu-devel] [PATCH 1/8] qapi: Add Visitor interfaces for uint*_t and int*_t
Quoted 48 lines · Laszlo Ersek
Quoted 47 lines · Andreas Färber
Am 09.06.2012 17:03, schrieb Laszlo Ersek:
Quoted 45 lines · Andreas Färber
Quoted 32 lines
From: Michael Roth <[email protected]>
This adds visitor interfaces for fixed-width integers types. Implementing these in visitors is optional, otherwise we fall back to
visit_type_int()(int64_t) with some additional bounds checking to avoid integer overflows for cases where the value fetched exceeds the bounds of our target C type.qapi/qapi-visit-core.h +9
-0@@ -52,6 +52,14 @@ struct Visitorvoid (*start_handle)(Visitor *v,void **obj,const char *kind,const char *name,Error **errp);void (*end_handle)(Visitor *v,Error **errp); +void (*type_uint8)(Visitor *v,uint8_t *obj,const char *name,Error **errp); +void (*type_uint16)(Visitor *v,uint16_t *obj,const char *name,Error **errp); +void (*type_uint32)(Visitor *v,uint32_t *obj,const char *name,Error **errp); +void (*type_uint64)(Visitor *v,uint64_t *obj,const char *name,Error **errp); +void (*type_int8)(Visitor *v,int8_t *obj,const char *name,Error **errp); +void (*type_int16)(Visitor *v,int16_t *obj,const char *name,Error **errp); +void (*type_int32)(Visitor *v,int32_t *obj,const char *name,Error **errp); +void (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp); }; void visit_start_handle(Visitor *v, void **obj, const char *kind,@@ -69,6 +77,14 @@ void visit_end_optional(Visitor *v, Error **errp);void visit_type_enum (Visitor *v,int *obj,const char *strings[],const char *kind,const char *name,Error **errp);void visit_type_int (Visitor *v,int64_t *obj,const char *name,Error **errp); +void visit_type_uint8 (Visitor *v,uint8_t *obj,const char *name,Error **errp);qapi/qapi-visit-core.h void visit_end_optional(Visitor *v, Error **errp); · line 90
Quoted 10 lines
qapi/qapi-visit-core.h +7
-0+void visit_type_uint16 (Visitor *v,uint16_t *obj,const char *name,Error **errp); +void visit_type_uint32 (Visitor *v,uint32_t *obj,const char *name,Error **errp); +void visit_type_uint64 (Visitor *v,uint64_t *obj,const char *name,Error **errp); +void visit_type_int8 (Visitor *v,int8_t *obj,const char *name,Error **errp); +void visit_type_int16 (Visitor *v,int16_t *obj,const char *name,Error **errp); +void visit_type_int32 (Visitor *v,int32_t *obj,const char *name,Error **errp); +void visit_type_int64 (Visitor *v,int64_t *obj,const char *name,Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp);Shouldn't "
scripts/qapi.py" be extended accordingly? (Thec_typefunction.)
Quoted 4 lines
Quoted 2 lines
What does that affect?
Is it a blocker for this PULL or an improvement for a follow-up?The latter. As long as nothing actually uses these types there's no problem.
To clarify: as long as nobody uses these types in a QAPI schema it's fine.
The current users don't rely on schema-generated fixed-width types so we're okay as far as the pull.
There's an extension to c_type() to support fixed-width types floating around in the QIDL series, but a standalone patch at some point would be warranted as well.
Quoted 3 lines
Laszlo
PATCH 2/8 qapi: Unit tests for visitor-based serialization
In reply to Andreas FärberFrom: Michael Roth <[email protected]>
Currently we test our visitors individually, and seperately for input vs. output. This is useful for validating internal representations against the native C types and vice-versa, and other visitor-specific testing, but it doesn't cover the potential use-case of using visitor pairs for serialization/deserialization very well, and makes it hard to easily extend the coverage for different C types / boundary conditions.
To cover that we add a set of unit tests that takes a number of native C values, passes them into an output visitor, extracts the values with an input visitor, then compares the result to the original.
Plugging in new visitors to the test harness only requires a user to implement the SerializeOps interface and add it to a list.
--- tests/Makefile | 4 +- tests/test-visitor-serialization.c | 744 ++++++++++++++++++++++++++++++++++++ 2 files changed, 747 insertions(+), 1 deletions(-) create mode 100644 tests/test-visitor-serialization.c
tests/Makefile +3 -1
@@ -13,6 +13,7 @@ check-unit-y += tests/test-qmp-commands$(EXESUF) check-unit-y += tests/test-string-input-visitor$(EXESUF) check-unit-y += tests/test-string-output-visitor$(EXESUF) check-unit-y += tests/test-coroutine$(EXESUF) +check-unit-y += tests/test-visitor-serialization$(EXESUF) check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
@@ -31,7 +32,7 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \ tests/test-coroutine.o tests/test-string-output-visitor.o \ tests/test-string-input-visitor.o tests/test-qmp-output-visitor.o \ tests/test-qmp-input-visitor.o tests/test-qmp-input-strict.o \ - tests/test-qmp-commands.o + tests/test-qmp-commands.o tests/test-visitor-serialization.o test-qapi-obj-y = $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) test-qapi-obj-y += tests/test-qapi-visit.o tests/test-qapi-types.o
@@ -64,6 +65,7 @@ tests/test-qmp-output-visitor$(EXESUF): tests/test-qmp-output-visitor.o $(test-q tests/test-qmp-input-visitor$(EXESUF): tests/test-qmp-input-visitor.o $(test-qapi-obj-y) tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o $(test-qapi-obj-y) tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marshal.o $(test-qapi-obj-y) +tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) tests/rtc-test$(EXESUF): tests/rtc-test.o $(trace-obj-y) tests/m48t59-test$(EXESUF): tests/m48t59-test.o $(trace-obj-y)
tests/test-visitor-serialization.c new file +744 -0
744 lines not on this page · raw message
Signature · 1 line
1.7.7
PATCH 3/8 qapi: String visitor, use %f representation for floats
In reply to Andreas FärberFrom: Michael Roth <[email protected]>
Currently string-output-visitor formats floats as %g, which is nice in that trailing 0's are automatically truncated, but otherwise this causes some issues:
- it uses 6 significant figures instead of 6 decimal places, which means something like 155777.5 (which even has an exact floating point representation) will be rounded to 155778 when converted to a string.
- output will be presented in scientific notation when the normalized form requires a 10^x multiplier. Not a huge deal, but arguably less readable for command-line arguments.
- due to using scientific notation for numbers requiring more than 6 significant figures, instead of hard-defined decimal places, it fails a lot of the test-visitor-serialization unit tests for floats.
Instead, let's just use %f, which is what the QJSON and the QMP visitors use.
--- qapi/string-output-visitor.c | 2 +- tests/test-string-output-visitor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
qapi/string-output-visitor.c +1 -1
@@ -52,7 +52,7 @@ static void print_type_number(Visitor *v, double *obj, const char *name, Error **errp) {StringOutputVisitor *sov =DO_UPCAST (StringOutputVisitor, visitor, v); -string_output_set (sov,g_strdup_printf ("%g" , *obj)); +string_output_set (sov,g_strdup_printf ("%f" , *obj)); }char *string_output_get_string (StringOutputVisitor *sov)
tests/test-string-output-visitor.c +1 -1
@@ -84,7 +84,7 @@ static void test_visitor_out_number(TestOutputVisitorData *data, str =string_output_get_string (data->sov);g_assert (str !=NULL ); - g_assert_cmpstr(str, ==, "3.14"); + g_assert_cmpstr(str, ==, "3.140000");g_free (str); }
Signature · 1 line
1.7.7
PATCH 4/8 qapi: Add String visitor coverage to serialization unit tests
In reply to Andreas FärberFrom: Michael Roth <[email protected]>
--- tests/test-visitor-serialization.c | 40 ++++++++++++++++++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 deletions(-)
tests/test-visitor-serialization.c +40 -0
@@ -19,6 +19,8 @@#include "qemu-objects.h" #include "qapi/qmp-input-visitor.h" #include "qapi/qmp-output-visitor.h" +#include "qapi/string-input-visitor.h" +#include "qapi/string-output-visitor.h" typedef struct PrimitiveType { union {
@@ -666,6 +668,37 @@ static void qmp_cleanup(void *datap)qmp_input_visitor_cleanup (d->qiv); } +typedef struct StringSerializeData { +StringOutputVisitor *sov; +StringInputVisitor *siv; +}StringSerializeData ; + +static void string_serialize (void *native_in,void **datap, +VisitorFunc visit,Error **errp) +{ +StringSerializeData *d =g_malloc0 (sizeof (*d)); + + d->sov =string_output_visitor_new (); +visit (string_output_get_visitor (d->sov), &native_in, errp); + *datap = d; +} + +static void string_deserialize (void **native_out,void *datap, +VisitorFunc visit,Error **errp) +{ +StringSerializeData *d = datap; + + d->siv =string_input_visitor_new (string_output_get_string (d->sov)); +visit (string_input_get_visitor (d->siv), native_out, errp); +} + +static void string_cleanup (void *datap) +{ +StringSerializeData *d = datap; +string_output_visitor_cleanup (d->sov); +string_input_visitor_cleanup (d->siv); +} +/* visitor registration, test harness */ /* note: to function interchangeably as a serialization mechanism your
@@ -680,6 +713,13 @@ static const SerializeOps visitors[] = { .cleanup = qmp_cleanup, .caps =VCAP_PRIMITIVES |VCAP_STRUCTURES |VCAP_LISTS }, + { + .type = "String", + .serialize = string_serialize, + .deserialize = string_deserialize, + .cleanup = string_cleanup, + .caps =VCAP_PRIMITIVES + }, { NULL } };
Signature · 1 line
1.7.7
PATCH 5/8 qdev: Use int32_t container for devfn property
In reply to Andreas FärberFrom: Michael Roth <[email protected]>
Valid range for devfn is -1 to 255 (-1 for automatic assignment). We do not currently validate this due to devfn being stored as a uint32_t. This can lead to segfaults and other strange behavior.
We could technically just cast it to int32_t to implement the checking, but this will not work for visitor-based setting where we may do additional bounds-checking based on target container type, which is int32_t for this case.
--- hw/pci.c | 2 +- hw/pci.h | 2 +- hw/qdev-properties.c | 11 ++++------- hw/qdev.h | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-)
hw/pci.c +1 -1
@@ -1537,7 +1537,7 @@ PCIDevice *pci_create_multifunction(PCIBus *bus, int devfn, bool multifunction,DeviceState *dev; dev =qdev_create (&bus->qbus, name); -qdev_prop_set_uint32 (dev,"addr" , devfn); +qdev_prop_set_int32 (dev,"addr" , devfn);qdev_prop_set_bit (dev,"multifunction" , multifunction);return PCI_DEVICE (dev); }
hw/pci.h +1 -1
@@ -197,7 +197,7 @@ struct PCIDevice {/* the following fields are read only */ PCIBus *bus; -uint32_t devfn; +int32_t devfn;char name[64 ];PCIIORegion io_regions[PCI_NUM_REGIONS ];
hw/qdev-properties.c +4 -7
@@ -824,7 +824,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque, {DeviceState *dev =DEVICE (obj);Property *prop = opaque; -uint32_t *ptr =qdev_get_prop_ptr (dev, prop); +int32_t *ptr =qdev_get_prop_ptr (dev, prop);unsigned int slot, fn, n;Error *local_err =NULL ;char *str;
@@ -860,7 +860,7 @@ invalid:static int print_pci_devfn (DeviceState *dev,Property *prop,char *dest,size_t len) { -uint32_t *ptr =qdev_get_prop_ptr (dev, prop); +int32_t *ptr =qdev_get_prop_ptr (dev, prop);if (*ptr ==-1 ) {return snprintf (dest, len,"<unset>" );
@@ -875,11 +875,8 @@ PropertyInfo qdev_prop_pci_devfn = { .print = print_pci_devfn, .get = get_int32, .set = set_pci_devfn, -/* FIXME: this should be -1...255, but the address is stored -* into an uint32_t rather than int32_t. -*/ - .min = 0, - .max = 0xFFFFFFFFULL, + .min = -1, + .max = 255, };/* --- blocksize --- */
hw/qdev.h +1 -1
@@ -267,7 +267,7 @@ extern PropertyInfo qdev_prop_blocksize;#define DEFINE_PROP_HEX64 (_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)#define DEFINE_PROP_PCI_DEVFN (_n, _s, _f, _d) \ - DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t) + DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)#define DEFINE_PROP_PTR (_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
Signature · 1 line
1.7.7
PATCH 6/8 qdev: Switch property accessors to fixed-width visitor interfaces
In reply to Andreas FärberFrom: Michael Roth <[email protected]>
This introduces {get,set}_uint{8,16,32,64}() functions for the respective qdev types.
TADDR and VLAN are switched to explicit int64, BLOCKSIZE to uint16.
--- hw/qdev-addr.c | 4 +- hw/qdev-properties.c | 150 +++++++++++++++++++++++++++++-------------------- 2 files changed, 91 insertions(+), 63 deletions(-)
hw/qdev-addr.c +2 -2
@@ -27,7 +27,7 @@ static void get_taddr(Object *obj, Visitor *v, void *opaque,int64_t value; value = *ptr; -visit_type_int (v, &value, name, errp); +visit_type_int64 (v, &value, name, errp); } static void set_taddr(Object *obj, Visitor *v, void *opaque,
@@ -44,7 +44,7 @@ static void set_taddr(Object *obj, Visitor *v, void *opaque,return ; } -visit_type_int (v, &value, name, &local_err); +visit_type_int64 (v, &value, name, &local_err);if (local_err) {error_propagate (errp, local_err);return ;
hw/qdev-properties.c +89 -61
342 lines not on this page · raw message
Signature · 1 line
1.7.7
PATCH 7/8 qdev: Remove PropertyInfo range checking
In reply to Andreas FärberFrom: Paolo Bonzini <[email protected]>
Range checking in PropertyInfo is now used only for pci_devfn properties and some error reporting. Remove all code that implements it in the various property types, and the now unused fields.
--- hw/qdev-properties.c | 106 ++++++++++++------------------------------------- hw/qdev.h | 2 - 2 files changed, 26 insertions(+), 82 deletions(-)
hw/qdev-properties.c +26 -80
@@ -91,34 +91,20 @@ static void set_uint8(Object *obj, Visitor *v, void *opaque, {DeviceState *dev =DEVICE (obj);Property *prop = opaque; -uint8_t value, *ptr =qdev_get_prop_ptr (dev, prop); -Error *local_err =NULL ; +uint8_t *ptr =qdev_get_prop_ptr (dev, prop);if (dev->state !=DEV_STATE_CREATED ) {error_set (errp,QERR_PERMISSION_DENIED );return ; } -visit_type_uint8 (v, &value, name, &local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; - } -if (value >= prop->info->min && value <= prop->info->max) { - *ptr = value; - }else { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE , - dev->id?:"" , name, (int64_t )value, prop->info->min, - prop->info->max); - } +visit_type_uint8 (v, ptr, name, errp); }PropertyInfo qdev_prop_uint8 = { .name ="uint8" , .get = get_uint8, .set = set_uint8, - .min =0 , - .max =255 , };/* --- 8bit hex value --- */
@@ -153,8 +139,6 @@ PropertyInfo qdev_prop_hex8 = { .print = print_hex8, .get = get_uint8, .set = set_uint8, - .min = 0, - .max = 255, };/* --- 16bit integer --- */
@@ -174,34 +158,20 @@ static void set_uint16(Object *obj, Visitor *v, void *opaque, {DeviceState *dev =DEVICE (obj);Property *prop = opaque; -uint16_t value, *ptr =qdev_get_prop_ptr (dev, prop); -Error *local_err =NULL ; +uint16_t *ptr =qdev_get_prop_ptr (dev, prop);if (dev->state !=DEV_STATE_CREATED ) {error_set (errp,QERR_PERMISSION_DENIED );return ; } -visit_type_uint16 (v, &value, name, &local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; - } -if (value >= prop->info->min && value <= prop->info->max) { - *ptr = value; - }else { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE , - dev->id?:"" , name, (int64_t )value, prop->info->min, - prop->info->max); - } +visit_type_uint16 (v, ptr, name, errp); }PropertyInfo qdev_prop_uint16 = { .name ="uint16" , .get = get_uint16, .set = set_uint16, - .min =0 , - .max =65535 , };/* --- 32bit integer --- */
@@ -211,10 +181,9 @@ static void get_uint32(Object *obj, Visitor *v, void *opaque, {DeviceState *dev =DEVICE (obj);Property *prop = opaque; -uint32_t value, *ptr =qdev_get_prop_ptr (dev, prop); +uint32_t *ptr =qdev_get_prop_ptr (dev, prop); - value = *ptr; -visit_type_uint32 (v, &value, name, errp); +visit_type_uint32 (v, ptr, name, errp); } static void set_uint32(Object *obj, Visitor *v, void *opaque,
@@ -222,26 +191,14 @@ static void set_uint32(Object *obj, Visitor *v, void *opaque, {DeviceState *dev =DEVICE (obj);Property *prop = opaque; -uint32_t value, *ptr =qdev_get_prop_ptr (dev, prop); -Error *local_err =NULL ; +uint32_t *ptr =qdev_get_prop_ptr (dev, prop);if (dev->state !=DEV_STATE_CREATED ) {error_set (errp,QERR_PERMISSION_DENIED );return ; } -visit_type_uint32 (v, &value, name, &local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; - } -if (value >= prop->info->min && value <= prop->info->max) { - *ptr = value; - }else { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE , - dev->id?:"" , name, (int64_t )value, prop->info->min, - prop->info->max); - } +visit_type_uint32 (v, ptr, name, errp); } static void get_int32(Object *obj, Visitor *v, void *opaque,
@@ -259,42 +216,26 @@ static void set_int32(Object *obj, Visitor *v, void *opaque, {DeviceState *dev =DEVICE (obj);Property *prop = opaque; -int32_t value, *ptr =qdev_get_prop_ptr (dev, prop); -Error *local_err =NULL ; +int32_t *ptr =qdev_get_prop_ptr (dev, prop);if (dev->state !=DEV_STATE_CREATED ) {error_set (errp,QERR_PERMISSION_DENIED );return ; } -visit_type_int32 (v, &value, name, &local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; - } -if (value >= prop->info->min && value <= prop->info->max) { - *ptr = value; - }else { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE , - dev->id?:"" , name, (int64_t )value, prop->info->min, - prop->info->max); - } +visit_type_int32 (v, ptr, name, errp); }PropertyInfo qdev_prop_uint32 = { .name ="uint32" , .get = get_uint32, .set = set_uint32, - .min =0 , - .max =0xFFFFFFFFULL , };PropertyInfo qdev_prop_int32 = { .name ="int32" , .get = get_int32, .set = set_int32, - .min =-0x80000000LL , - .max =0x7FFFFFFFLL , };/* --- 32bit hex value --- */
@@ -329,8 +270,6 @@ PropertyInfo qdev_prop_hex32 = { .print = print_hex32, .get = get_uint32, .set = set_uint32, - .min = 0, - .max = 0xFFFFFFFFULL, };/* --- 64bit integer --- */
@@ -853,7 +792,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque, {DeviceState *dev =DEVICE (obj);Property *prop = opaque; -int32_t *ptr =qdev_get_prop_ptr (dev, prop); +int32_t value, *ptr =qdev_get_prop_ptr (dev, prop);unsigned int slot, fn, n;Error *local_err =NULL ;char *str;
@@ -866,7 +805,17 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,visit_type_str (v, &str, name, &local_err);if (local_err) {error_free (local_err); -return set_int32 (obj, v, opaque, name, errp); + local_err =NULL ; +visit_type_int32 (v, &value, name, &local_err); +if (local_err) { +error_propagate (errp, local_err); + }else if (value <-1 || value >255 ) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE , name ? name :"null" , +"pci_devfn" ); + }else { + *ptr = value; + } +return ; }if (sscanf (str,"%x.%x%n" , &slot, &fn, &n) !=2 ) {
@@ -904,8 +853,6 @@ PropertyInfo qdev_prop_pci_devfn = { .print = print_pci_devfn, .get = get_int32, .set = set_pci_devfn, - .min = -1, - .max = 255, };/* --- blocksize --- */
@@ -917,6 +864,8 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque,Property *prop = opaque;uint16_t value, *ptr =qdev_get_prop_ptr (dev, prop);Error *local_err =NULL ; +const int64_t min =512 ; +const int64_t max =32768 ;if (dev->state !=DEV_STATE_CREATED ) {error_set (errp,QERR_PERMISSION_DENIED );
@@ -928,10 +877,9 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque,error_propagate (errp, local_err);return ; } -if (value < prop->info->min || value > prop->info->max) { +if (value < min || value > max) {error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE , - dev->id?:"" , name, (int64_t )value, prop->info->min, - prop->info->max); + dev->id?:"" , name, (int64_t )value, min, max);return ; }
@@ -949,8 +897,6 @@ PropertyInfo qdev_prop_blocksize = { .name = "blocksize", .get = get_uint16, .set = set_blocksize, - .min = 512, - .max = 65024, };/* --- public helpers --- */
hw/qdev.h +0 -2
@@ -122,8 +122,6 @@ struct PropertyInfo {const char *name;const char *legacy_name;const char **enum_table; -int64_t min; -int64_t max;int (*parse)(DeviceState *dev,Property *prop,const char *str);int (*print)(DeviceState *dev,Property *prop,char *dest,size_t len);ObjectPropertyAccessor *get;
Signature · 1 line
1.7.7
PATCH 8/8 target-i386: Use uint32 visitor for [x]level properties
In reply to Andreas FärberThis simplifies the code and resolves TODOs.
--- target-i386/cpu.c | 42 ++++-------------------------------------- 1 files changed, 4 insertions(+), 38 deletions(-)
target-i386/cpu.c +4 -38
@@ -723,66 +723,32 @@ static void x86_cpuid_get_level(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { X86CPU *cpu = X86_CPU(obj); -int64_t value; - value = cpu->env.cpuid_level; -/* TODO Use visit_type_uint32() once available */ -visit_type_int (v, &value, name, errp); +visit_type_uint32 (v, &cpu->env.cpuid_level, name, errp); }static void x86_cpuid_set_level (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp) {X86CPU *cpu =X86_CPU (obj); -const int64_t min =0 ; -const int64_t max =UINT32_MAX ; -int64_t value; - -/* TODO Use visit_type_uint32() once available */ -visit_type_int (v, &value, name, errp); -if (error_is_set (errp)) { -return ; - } -if (value < min || value > max) { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE ,"" , - name ? name :"null" , value, min, max); -return ; - } - cpu->env.cpuid_level = value; +visit_type_uint32 (v, &cpu->env.cpuid_level, name, errp); }static void x86_cpuid_get_xlevel (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp) {X86CPU *cpu =X86_CPU (obj); -int64_t value; - value = cpu->env.cpuid_xlevel; -/* TODO Use visit_type_uint32() once available */ -visit_type_int (v, &value, name, errp); +visit_type_uint32 (v, &cpu->env.cpuid_xlevel, name, errp); }static void x86_cpuid_set_xlevel (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp) {X86CPU *cpu =X86_CPU (obj); -const int64_t min =0 ; -const int64_t max =UINT32_MAX ; -int64_t value; - -/* TODO Use visit_type_uint32() once available */ -visit_type_int (v, &value, name, errp); -if (error_is_set (errp)) { -return ; - } -if (value < min || value > max) { -error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE ,"" , - name ? name :"null" , value, min, max); -return ; - } - cpu->env.cpuid_xlevel = value; +visit_type_uint32 (v, &cpu->env.cpuid_xlevel, name, errp); }static char *x86_cpuid_get_vendor (Object *obj,Error **errp)
Signature · 1 line
1.7.7
Am 08.06.2012 17:35, schrieb Andreas Färber:
Quoted 10 lines
Hello Anthony,
To get moving with the merge of qom-next into qemu.git, now that the
MakefilePULL is in, please pull a first small batch, grouping patches directly related to fixed-width visitors.Outlook:
A second batch would include the QBus refactoring - still cherry-picking, reordering and re-testing.
Preview is ready:
http://repo.or.cz/w/qemu/afaerber.git/shortlog/refs/heads/qom-next-2
exec.c | 4 +- hw/acpi_piix4.c | 10 +- hw/arm_l2x0.c | 2 +- hw/i2c.c | 30 +++-- hw/ide/internal.h | 3 + hw/ide/qdev.c | 31 +++-- hw/intel-hda.c | 37 +++-- hw/intel-hda.h | 3 + hw/isa-bus.c | 23 +++- hw/isa.h | 3 + hw/lsi53c895a.c | 5 +- hw/m48t59.c | 40 +++--- hw/pc_piix.c | 7 +- hw/pci-hotplug.c | 6 +- hw/pci.c | 51 +++++--- hw/pci_bridge.c | 2 +- hw/pci_internals.h | 3 +- hw/qdev-monitor.c | 101 ++++++++------- hw/qdev-properties.c | 65 +++------ hw/qdev.c | 300 +++++++++++++++++++++++++++-------------- hw/qdev.h | 65 +++++---- hw/s390-virtio-bus.c | 37 +++--- hw/s390-virtio-bus.h | 4 + hw/scsi-bus.c | 58 +++++--- hw/scsi.h | 3 + hw/spapr_pci.c | 7 +- hw/spapr_vio.c | 47 ++++--- hw/spapr_vio.h | 3 + hw/spapr_vty.c | 6 +- hw/ssi.c | 29 +++-- hw/sysbus.c | 45 ++++++- hw/sysbus.h | 3 + hw/usb.h | 3 + hw/usb/bus.c | 45 ++++--- hw/usb/desc.c | 5 +- hw/usb/dev-smartcard-reader.c | 25 +++-- hw/virtio-scsi.c | 6 +- hw/virtio-serial-bus.c | 36 ++++-- include/qemu/object.h | 47 ++++++- qom/object.c | 158 +++++++++++++++------ savevm.c | 12 +- 41 files changed, 868 insertions(+), 502 deletions(-)
Quoted 54 lines
I'm preparing a two-patch realize series that could get appended to the second. Still open are the static property movements and their prerequisites.
CPU-related patches are split off into their own pull.
Cc Anthony Liguori <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Michael Roth <[email protected]>Cc Laszlo Ersek <[email protected]>Cc Luiz Capitulino <[email protected]>Jan, this does not include the big file movement but the largest part of the
qdev-properties.cchanges and in particular the ones that affect PCI. I suggest that you rebase on this one and me/Paolo the remaining parts on yours.Cc Jan Kiszka <[email protected]>The following changes since commit
fa79c914efd35cb60e0bc18512c03690c48b13e2:Merge remote-tracking branch 'bonzini/nested-makefiles-3' into staging (2012-06-07 17:21:40 +0800)
are available in the git repository at:
git://repo.or.cz/qemu/afaerber.gitqom-next-1Andreas Färber (1):
target-i386: Use uint32 visitor for [x]level propertiesMichael Roth (6):
qapi: Add Visitor interfaces for uint*_t and int*_t
qapi: Unit tests for visitor-based serialization
qapi: String visitor, use %f representation for floats
qapi: Add String visitor coverage to serialization unit tests
qdev: Useint32_tcontainer for devfn property
qdev: Switch property accessors to fixed-width visitor interfacesPaolo Bonzini (1):
qdev: Remove PropertyInfo range checkinghw/mc146818rtc.c | 7 - hw/pci.c | 2 +- hw/pci.h | 2 +- hw/qdev-addr.c | 4 +- hw/qdev-properties.c | 205 ++++------ hw/qdev.h | 4 +- qapi/qapi-visit-core.c | 139 +++++++ qapi/qapi-visit-core.h | 16 + qapi/string-output-visitor.c | 2 +- target-i386/cpu.c | 42 +-- tests/Makefile | 4 +- tests/test-string-output-visitor.c | 2 +- tests/test-visitor-serialization.c | 784 ++++++++++++++++++++++++++++++++++++ 13 files changed, 1041 insertions(+), 172 deletions(-) create mode 100644 tests/test-visitor-serialization.c
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Quoted 5 lines · On Fri, 8 Jun 2012 17:35:05 +0200 Andreas Färber <[email protected]> wrote:
Hello Anthony,
To get moving with the merge of qom-next into qemu.git, now that the
MakefilePULL is in, please pull a first small batch, grouping patches directly related to fixed-width visitors.
FWIW, the fixed-width visitors looked good to me last time I glanced at its series.
Quoted 8 lines · Andreas Färber
Hello Anthony,
To get moving with the merge of qom-next into qemu.git, now that the
MakefilePULL is in, please pull a first small batch, grouping patches directly related to fixed-width visitors.Outlook:
Quoted 7 lines
A second batch would include the QBus refactoring - still cherry-picking, reordering and re-testing.
I'm preparing a two-patch realize series that could get appended to the second. Still open are the static property movements and their prerequisites.
CPU-related patches are split off into their own pull.
Pulled. Thanks.
Regards,
Anthony Liguori
Quoted 52 lines
Cc Anthony Liguori<[email protected]>Cc Paolo Bonzini<[email protected]>Cc Michael Roth<[email protected]>Cc Laszlo Ersek<[email protected]>Cc Luiz Capitulino<[email protected]>Jan, this does not include the big file movement but the largest part of the
qdev-properties.cchanges and in particular the ones that affect PCI. I suggest that you rebase on this one and me/Paolo the remaining parts on yours.Cc Jan Kiszka<[email protected]>The following changes since commit
fa79c914efd35cb60e0bc18512c03690c48b13e2:Merge remote-tracking branch 'bonzini/nested-makefiles-3' into staging (2012-06-07 17:21:40 +0800)are available in the git repository at:
git://repo.or.cz/qemu/afaerber.gitqom-next-1Andreas Färber (1):
target-i386: Use uint32 visitor for [x]level propertiesMichael Roth (6):
qapi: Add Visitor interfaces for uint*_t and int*_t
qapi: Unit tests for visitor-based serialization
qapi: String visitor, use %f representation for floats
qapi: Add String visitor coverage to serialization unit tests
qdev: Useint32_tcontainer for devfn property
qdev: Switch property accessors to fixed-width visitor interfacesPaolo Bonzini (1):
qdev: Remove PropertyInfo range checkinghw/mc146818rtc.c | 7 - hw/pci.c | 2 +- hw/pci.h | 2 +- hw/qdev-addr.c | 4 +- hw/qdev-properties.c | 205 ++++------ hw/qdev.h | 4 +- qapi/qapi-visit-core.c | 139 +++++++ qapi/qapi-visit-core.h | 16 + qapi/string-output-visitor.c | 2 +- target-i386/cpu.c | 42 +-- tests/Makefile | 4 +- tests/test-string-output-visitor.c | 2 +- tests/test-visitor-serialization.c | 784 ++++++++++++++++++++++++++++++++++++ 13 files changed, 1041 insertions(+), 172 deletions(-)create mode 100644
tests/test-visitor-serialization.c