Re: [Qemu-devel] [PATCH 0/4] four zpci patches

2017-08-24 Thread Cornelia Huck
On Thu, 24 Aug 2017 13:20:12 +0800
Yi Min Zhao  wrote:

> Why can't I receive [Qemu-devel] prefixed patches?
> 
> 
> 在 2017/8/23 下午3:26, Yi Min Zhao 写道:
> > This patch set contains four small zpci patches to fixup different issues.
> > 1) fixup calculation of msix boundary
> > 2) remove zpci idx from msix message, instead we could use PCIDevice's id to
> > find zpci device in kvm_arch_fixup_msi_route()
> > 3) fixup ind_offset calculation for adapter interrupt routing entry
> > 4) introduce our own iommu_replay callback
> >
> > Yi Min Zhao (4):
> >s390x/pci: fixup trap_msix()
> >s390x/pci: remove idx from msix msg data
> >s390x/pci: fixup ind_offset of msix routing entry
> >s390x/pci: add iommu replay callback
> >
> >   hw/s390x/s390-pci-bus.c  | 24 +---
> >   hw/s390x/s390-pci-bus.h  |  2 ++
> >   hw/s390x/s390-pci-inst.c | 28 ++--
> >   target/s390x/kvm.c   | 11 ++-
> >   4 files changed, 23 insertions(+), 42 deletions(-)
> >  
> 

Well, I did not get any of your original patches, just this reply...
seem to be stuck somewhere?



Re: [Qemu-devel] [Qemu-block] [RFC PATCH 31/56] block: Make throttle byte rates and sizes unsigned in QAPI/QMP

2017-08-24 Thread Markus Armbruster
Alberto Garcia  writes:

> On Mon 07 Aug 2017 04:45:35 PM CEST, Markus Armbruster wrote:
>> Sizes and byte rates should use QAPI type 'size' (uint64_t).
>> BlockIOThrottle and BlockDeviceInfo members @bps, @bps_rd, @bps_wr,
>> @bps_max, @bps_rd_max, @bps_wr_max, @iops_size are 'int' (int64_t).
>> qmp_block_set_io_throttle() and bdrv_block_device_info() copy @bps,
>> @bps_rd, @bps_wr to / from LeakyBucket member @avg (implicit
>> conversion to / from double), @bps_max, @bps_rd_max, @bps_wr_max to /
>> from LeakyBucket member @max (implicit conversion to / from double),
>> and @iops_size to / from ThrottleConfig member op_size (implicit
>> conversion to / from uint64_t).
>>
>> Change these BlockIOThrottle and BlockDeviceInfo members to 'size'.
>>
>> block_set_io_throttle now accepts sizes and rates between 2^63 and
>> 2^64-1.  It accepts negative values as before, because that's how the
>> QObject input visitor works for backward compatibility.
>>
>> Doing the same for HMP's block_set_io_throttle deserves its own commit
>> (the next one).
>>
>> query-block and query-named-block-nodes now report sizes and rates
>> above 2^63-1 correctly instead of their (negative) two's complement.
>>
>> So does HMP's "info block".
>>
>> Signed-off-by: Markus Armbruster 
>
> This is fine because all those parameters are limited to [0, 10^15], so
> changing int64_t -> uint64_t is not a problem.
>
> I have already sent a patch that changes the fields in the data
> structure in throttle.h from double to uint64_t

I expect v2 to be based on your patch.  Might simplify the commit
message.

> Reviewed-by: Alberto Garcia 

Thanks!



Re: [Qemu-devel] [PATCH v5 3/9] s390x/pci: add stubs

2017-08-24 Thread Christian Borntraeger


On 08/23/2017 05:54 PM, Cornelia Huck wrote:
> Some non-pci code calls into zpci code. Provide some stubs for builds
> without pci.
> 
> Reviewed-by: Thomas Huth 
> Signed-off-by: Cornelia Huck 
> ---
>  hw/s390x/Makefile.objs   |  3 +-
>  hw/s390x/s390-pci-stub.c | 74 
> 
>  2 files changed, 76 insertions(+), 1 deletion(-)
>  create mode 100644 hw/s390x/s390-pci-stub.c
> 
> diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs
> index b2aade2466..7ee19d3abc 100644
> --- a/hw/s390x/Makefile.objs
> +++ b/hw/s390x/Makefile.objs
> @@ -11,7 +11,8 @@ obj-y += 3270-ccw.o
>  obj-y += virtio-ccw.o
>  obj-y += css-bridge.o
>  obj-y += ccw-device.o
> -obj-y += s390-pci-bus.o s390-pci-inst.o
> +obj-$(CONFIG_PCI) += s390-pci-bus.o s390-pci-inst.o
> +obj-$(call lnot,$(CONFIG_PCI)) += s390-pci-stub.o
>  obj-y += s390-skeys.o
>  obj-y += s390-stattrib.o
>  obj-$(CONFIG_KVM) += s390-skeys-kvm.o
> diff --git a/hw/s390x/s390-pci-stub.c b/hw/s390x/s390-pci-stub.c
> new file mode 100644
> index 00..2e7e42a2af
> --- /dev/null
> +++ b/hw/s390x/s390-pci-stub.c
> @@ -0,0 +1,74 @@
> +/* stubs for non-pci builds */
> +
> +#include "qemu/osdep.h"
> +#include "qemu-common.h"
> +#include "cpu.h"
> +#include "s390-pci-inst.h"
> +#include "s390-pci-bus.h"
> +
> +/* target/s390x/ioinst.c */
> +int chsc_sei_nt2_get_event(void *res)
> +{
> +return 1;
> +}
> +
> +int chsc_sei_nt2_have_event(void)
> +{
> +return 0;
> +}
> +
> +/* hw/s390x/sclp.c */
> +void s390_pci_sclp_configure(SCCB *sccb)
> +{
> +}
> +
> +void s390_pci_sclp_deconfigure(SCCB *sccb)
> +{
> +}

shouldnt these function set an error code in the sccb, e.g.
something like

   sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);





[Qemu-devel] [PATCH] hw/nvram/spapr_nvram: Device can not be created by the users

2017-08-24 Thread Thomas Huth
Trying to add a spapr-nvram device currently aborts QEMU like this:

$ ppc64-softmmu/qemu-system-ppc64  -device spapr-nvram
qemu-system-ppc64: hw/ppc/spapr_rtas.c:407: spapr_rtas_register:
 Assertion `!rtas_table[token].name' failed.
Aborted (core dumped)

This NVRAM device registers RTAS calls during its realize function
and thus can only be used once - and that's internally from spapr.c.
So let's mark the device with user_creatable = false to avoid that
the users can crash their QEMU this way.

Signed-off-by: Thomas Huth 
---
 hw/nvram/spapr_nvram.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
index bc355a4..4a0aec8 100644
--- a/hw/nvram/spapr_nvram.c
+++ b/hw/nvram/spapr_nvram.c
@@ -264,6 +264,8 @@ static void spapr_nvram_class_init(ObjectClass *klass, void 
*data)
 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
 dc->props = spapr_nvram_properties;
 dc->vmsd = &vmstate_spapr_nvram;
+/* Reason: Internal device only, uses spapr_rtas_register() in realize() */
+dc->user_creatable = false;
 }
 
 static const TypeInfo spapr_nvram_type_info = {
-- 
1.8.3.1




[Qemu-devel] [PATCH for-2.11] hw/nvram/spapr_nvram: Device can not be created by the users

2017-08-24 Thread Thomas Huth
Trying to add a spapr-nvram device currently aborts QEMU like this:

$ ppc64-softmmu/qemu-system-ppc64  -device spapr-nvram
qemu-system-ppc64: hw/ppc/spapr_rtas.c:407: spapr_rtas_register:
 Assertion `!rtas_table[token].name' failed.
Aborted (core dumped)

This NVRAM device registers RTAS calls during its realize function
and thus can only be used once - and that's internally from spapr.c.
So let's mark the device with user_creatable = false to avoid that
the users can crash their QEMU this way.

Signed-off-by: Thomas Huth 
---
 hw/nvram/spapr_nvram.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
index bc355a4..4a0aec8 100644
--- a/hw/nvram/spapr_nvram.c
+++ b/hw/nvram/spapr_nvram.c
@@ -264,6 +264,8 @@ static void spapr_nvram_class_init(ObjectClass *klass, void 
*data)
 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
 dc->props = spapr_nvram_properties;
 dc->vmsd = &vmstate_spapr_nvram;
+/* Reason: Internal device only, uses spapr_rtas_register() in realize() */
+dc->user_creatable = false;
 }
 
 static const TypeInfo spapr_nvram_type_info = {
-- 
1.8.3.1




Re: [Qemu-devel] [Qemu-block] [PATCH v5 08/13] tests: Rely more on global_qtest

2017-08-24 Thread Markus Armbruster
Paolo Bonzini  writes:

> On 23/08/2017 23:30, Eric Blake wrote:
>>> Well, whatever is assigning to global_qtest should be using the long form.
>> Question - what about going the other way, and switching ALL callers to
>> always use the explicit form?  I'd really like to maintain only one
>> form, but if we think maintaining the explicit form is better, then I'd
>> rather see:
>> 
>> s = qtest_init(...);
>> qmp(s, "{'execute':'foo'}");
>
> I think the short form is not problematic per se, but when e.g.
> migration is involved, then the tests are abusing it...

The long forms avoid global state.  Global state exits through the front
door; designer congratulates himself for this virtous deed.

Trouble is the long forms are, well, long, so designer creates short
ones.  Global state jumps right back through the open window.  Almost
everything uses the short forms, and with good reason.

Ritual avoidance of global state without really avoiding it has a
name in German programming jargon: "Muesli".

While undisciplined use of global state is the root of many problems, I
fail to see a problem here.  For me,

do this with QTestState A
do that with QTestState A

do something with QTestState B

do more with QTestState A

is no better than

with QTestState A
do this
do that

with QTestState B
do something

with QTestState A
do more

In a language less primitive than C, I'd write it exactly that way, and
nobody would complain.  In old, primitive C, I have to write

global_qtest = A;
do this
do that

global_qtest = B;
do something

global_qtest = A;
do more

Why's that so horrible to justify busywork on wrappers?

Creating and updating the short form wrappers has grown on me.  If I
enjoyed busywork, I would've become Vice President of Nothing in
Particular or something.

Pretty-please?  ;)



Re: [Qemu-devel] [PATCH v5 3/9] s390x/pci: add stubs

2017-08-24 Thread Christian Borntraeger


On 08/24/2017 09:38 AM, Christian Borntraeger wrote:
> 
> 
> On 08/23/2017 05:54 PM, Cornelia Huck wrote:
>> Some non-pci code calls into zpci code. Provide some stubs for builds
>> without pci.
>>
>> Reviewed-by: Thomas Huth 
>> Signed-off-by: Cornelia Huck 
>> ---
>>  hw/s390x/Makefile.objs   |  3 +-
>>  hw/s390x/s390-pci-stub.c | 74 
>> 
>>  2 files changed, 76 insertions(+), 1 deletion(-)
>>  create mode 100644 hw/s390x/s390-pci-stub.c
>>
>> diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs
>> index b2aade2466..7ee19d3abc 100644
>> --- a/hw/s390x/Makefile.objs
>> +++ b/hw/s390x/Makefile.objs
>> @@ -11,7 +11,8 @@ obj-y += 3270-ccw.o
>>  obj-y += virtio-ccw.o
>>  obj-y += css-bridge.o
>>  obj-y += ccw-device.o
>> -obj-y += s390-pci-bus.o s390-pci-inst.o
>> +obj-$(CONFIG_PCI) += s390-pci-bus.o s390-pci-inst.o
>> +obj-$(call lnot,$(CONFIG_PCI)) += s390-pci-stub.o
>>  obj-y += s390-skeys.o
>>  obj-y += s390-stattrib.o
>>  obj-$(CONFIG_KVM) += s390-skeys-kvm.o
>> diff --git a/hw/s390x/s390-pci-stub.c b/hw/s390x/s390-pci-stub.c
>> new file mode 100644
>> index 00..2e7e42a2af
>> --- /dev/null
>> +++ b/hw/s390x/s390-pci-stub.c
>> @@ -0,0 +1,74 @@
>> +/* stubs for non-pci builds */
>> +
>> +#include "qemu/osdep.h"
>> +#include "qemu-common.h"
>> +#include "cpu.h"
>> +#include "s390-pci-inst.h"
>> +#include "s390-pci-bus.h"
>> +
>> +/* target/s390x/ioinst.c */
>> +int chsc_sei_nt2_get_event(void *res)
>> +{
>> +return 1;
>> +}
>> +
>> +int chsc_sei_nt2_have_event(void)
>> +{
>> +return 0;
>> +}
>> +
>> +/* hw/s390x/sclp.c */
>> +void s390_pci_sclp_configure(SCCB *sccb)
>> +{
>> +}
>> +
>> +void s390_pci_sclp_deconfigure(SCCB *sccb)
>> +{
>> +}
> 
> shouldnt these function set an error code in the sccb, e.g.
> something like
> 
>sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
> 
> 
> 

Oh you have something like that in patch 7. Maybe move?




[Qemu-devel] [PATCH 2/3] iotests.py: add FilePath context manager

2017-08-24 Thread Stefan Hajnoczi
The scratch/ (TEST_DIR) directory is not automatically cleaned up after
test execution.  It is the responsibility of tests to remove any files
they create.

A nice way of doing this is to declare files at the beginning of the
test and automatically remove them with a context manager:

  with iotests.FilePath('test.img') as img_path:
  qemu_img(...)
  qemu_io(...)
  # img_path is guaranteed to be deleted here

Signed-off-by: Stefan Hajnoczi 
---
 tests/qemu-iotests/iotests.py | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 7233983f3c..07fa1626a0 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -160,6 +160,32 @@ class Timeout:
 def timeout(self, signum, frame):
 raise Exception(self.errmsg)
 
+
+class FilePath(object):
+'''An auto-generated filename that cleans itself up.
+
+Use this context manager to generate filenames and ensure that the file
+gets deleted::
+
+with TestFilePath('test.img') as img_path:
+qemu_img('create', img_path, '1G')
+# migration_sock_path is automatically deleted
+'''
+def __init__(self, name):
+filename = '{0}-{1}'.format(os.getpid(), name)
+self.path = os.path.join(test_dir, filename)
+
+def __enter__(self):
+return self.path
+
+def __exit__(self, exc_type, exc_val, exc_tb):
+try:
+os.remove(self.path)
+except OSError:
+pass
+return False
+
+
 class VM(qtest.QEMUQtestMachine):
 '''A QEMU VM'''
 
-- 
2.13.5




[Qemu-devel] [PATCH 1/3] qemu.py: make VM() a context manager

2017-08-24 Thread Stefan Hajnoczi
There are a number of ways to ensure that the QEMU process is shut down
when the test ends, including atexit.register(), try: finally:, or
unittest.teardown() methods.  All of these require extra code and the
programmer must remember to add vm.shutdown().

A nice solution is context managers:

  with VM(binary) as vm:
  ...
  # vm is guaranteed to be shut down here

Cc: Eduardo Habkost 
Signed-off-by: Stefan Hajnoczi 
---
 scripts/qemu.py | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/scripts/qemu.py b/scripts/qemu.py
index 880e3e8219..4d8ee10943 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -21,7 +21,14 @@ import qmp.qmp
 
 
 class QEMUMachine(object):
-'''A QEMU VM'''
+'''A QEMU VM
+
+Use this object as a context manager to ensure the QEMU process 
terminates::
+
+with VM(binary) as vm:
+...
+# vm is guaranteed to be shut down here
+'''
 
 def __init__(self, binary, args=[], wrapper=[], name=None, 
test_dir="/var/tmp",
  monitor_address=None, socket_scm_helper=None, debug=False):
@@ -40,6 +47,13 @@ class QEMUMachine(object):
 self._socket_scm_helper = socket_scm_helper
 self._debug = debug
 
+def __enter__(self):
+return self
+
+def __exit__(self, exc_type, exc_val, exc_tb):
+self.shutdown()
+return False
+
 # This can be used to add an unused monitor instance.
 def add_monitor_telnet(self, ip, port):
 args = 'tcp:%s:%d,server,nowait,telnet' % (ip, port)
-- 
2.13.5




[Qemu-devel] [PATCH 3/3] qemu-iotests: use context managers for resource cleanup in 194

2017-08-24 Thread Stefan Hajnoczi
Switch from atexit.register() to a more elegant idiom of declaring
resources in a with statement:

  with FilePath('monitor.sock') as monitor_path,
   VM() as vm:
  ...

The files and VMs will be automatically cleaned up whether the test
passes or fails.

Signed-off-by: Stefan Hajnoczi 
---
 tests/qemu-iotests/194 | 83 +-
 1 file changed, 41 insertions(+), 42 deletions(-)

diff --git a/tests/qemu-iotests/194 b/tests/qemu-iotests/194
index 8028111e21..06aea661d4 100755
--- a/tests/qemu-iotests/194
+++ b/tests/qemu-iotests/194
@@ -19,55 +19,54 @@
 #
 # Non-shared storage migration test using NBD server and drive-mirror
 
-import os
-import atexit
 import iotests
 
 iotests.verify_platform(['linux'])
 
-img_size = '1G'
-source_img_path = os.path.join(iotests.test_dir, 'source.img')
-dest_img_path = os.path.join(iotests.test_dir, 'dest.img')
-iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, source_img_path, 
img_size)
-iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, dest_img_path, img_size)
+with iotests.FilePath('source.img') as source_img_path, \
+ iotests.FilePath('dest.img') as dest_img_path, \
+ iotests.FilePath('migration.sock') as migration_sock_path, \
+ iotests.FilePath('nbd.sock') as nbd_sock_path, \
+ iotests.VM('source') as source_vm, \
+ iotests.VM('dest') as dest_vm:
 
-iotests.log('Launching VMs...')
-migration_sock_path = os.path.join(iotests.test_dir, 'migration.sock')
-nbd_sock_path = os.path.join(iotests.test_dir, 'nbd.sock')
-source_vm = iotests.VM('source').add_drive(source_img_path)
-dest_vm = (iotests.VM('dest').add_drive(dest_img_path)
- 
.add_incoming('unix:{0}'.format(migration_sock_path)))
-source_vm.launch()
-atexit.register(source_vm.shutdown)
-dest_vm.launch()
-atexit.register(dest_vm.shutdown)
+img_size = '1G'
+iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, source_img_path, 
img_size)
+iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, dest_img_path, 
img_size)
 
-iotests.log('Launching NBD server on destination...')
-iotests.log(dest_vm.qmp('nbd-server-start', addr={'type': 'unix', 'data': 
{'path': nbd_sock_path}}))
-iotests.log(dest_vm.qmp('nbd-server-add', device='drive0', writable=True))
+iotests.log('Launching VMs...')
+(source_vm.add_drive(source_img_path)
+  .launch())
+(dest_vm.add_drive(dest_img_path)
+.add_incoming('unix:{0}'.format(migration_sock_path))
+.launch())
 
-iotests.log('Starting drive-mirror on source...')
-iotests.log(source_vm.qmp(
-  'drive-mirror',
-  device='drive0',
-  target='nbd+unix:///drive0?socket={0}'.format(nbd_sock_path),
-  sync='full',
-  format='raw', # always raw, the server handles the format
-  mode='existing'))
+iotests.log('Launching NBD server on destination...')
+iotests.log(dest_vm.qmp('nbd-server-start', addr={'type': 'unix', 'data': 
{'path': nbd_sock_path}}))
+iotests.log(dest_vm.qmp('nbd-server-add', device='drive0', writable=True))
 
-iotests.log('Waiting for drive-mirror to complete...')
-iotests.log(source_vm.event_wait('BLOCK_JOB_READY'),
-filters=[iotests.filter_qmp_event])
+iotests.log('Starting drive-mirror on source...')
+iotests.log(source_vm.qmp(
+  'drive-mirror',
+  device='drive0',
+  target='nbd+unix:///drive0?socket={0}'.format(nbd_sock_path),
+  sync='full',
+  format='raw', # always raw, the server handles the format
+  mode='existing'))
 
-iotests.log('Starting migration...')
-source_vm.qmp('migrate-set-capabilities',
-  capabilities=[{'capability': 'events', 'state': True}])
-dest_vm.qmp('migrate-set-capabilities',
-capabilities=[{'capability': 'events', 'state': True}])
-iotests.log(source_vm.qmp('migrate', 
uri='unix:{0}'.format(migration_sock_path)))
+iotests.log('Waiting for drive-mirror to complete...')
+iotests.log(source_vm.event_wait('BLOCK_JOB_READY'),
+filters=[iotests.filter_qmp_event])
 
-while True:
-event = source_vm.event_wait('MIGRATION')
-iotests.log(event, filters=[iotests.filter_qmp_event])
-if event['data']['status'] in ('completed', 'failed'):
-break
+iotests.log('Starting migration...')
+source_vm.qmp('migrate-set-capabilities',
+  capabilities=[{'capability': 'events', 'state': True}])
+dest_vm.qmp('migrate-set-capabilities',
+capabilities=[{'capability': 'events', 'state': True}])
+iotests.log(source_vm.qmp('migrate', 
uri='unix:{0}'.format(migration_sock_path)))
+
+while True:
+event = source_vm.event_wait('MIGRATION')
+iotests.log(event, filters=[iotests.filter_qmp_event])
+if event['data']['status'] in ('completed', 'failed'):
+break
-- 
2.13.5




[Qemu-devel] [PATCH 0/3] iotests: clean up resources using context managers

2017-08-24 Thread Stefan Hajnoczi
This series introduces context managers for the two most commonly used
resources: files and VMs.  Context managers eliminate the need to call a
cleanup function explicitly.

Tests should declare resources upfront in a with statement.  Resources are
automatically cleaned up whether the test passes or fails:

  with FilePath('test.img') as img_path,
   VM() as vm:
  ...test...
  # img_path is deleted and vm is shut down automatically

The final patch converts 194 to use context managers instead of
atexit.register().  This makes the code shorter and easier to read.

Stefan Hajnoczi (3):
  qemu.py: make VM() a context manager
  iotests.py: add FilePath context manager
  qemu-iotests: use context managers for resource cleanup in 194

 scripts/qemu.py   | 16 -
 tests/qemu-iotests/194| 83 +--
 tests/qemu-iotests/iotests.py | 26 ++
 3 files changed, 82 insertions(+), 43 deletions(-)

-- 
2.13.5




Re: [Qemu-devel] [PATCH v5 0/9] zpci detangling

2017-08-24 Thread Christian Borntraeger
As there are only minor things left, 
whole series

Acked-by: Christian Borntraeger 


On 08/23/2017 05:54 PM, Cornelia Huck wrote:
> Hopefully should be close now...
> 
> v4->v5:
> - dropped "s390x/kvm: msi route fixup for non-pci"
> - reworked "s390x/sclp: properly guard pci-specific functions": the
>   configure/deconfigure stuff is about I/O adapters, we were missing
>   checks, and I used an incorrect return code -- please review
> - collected more r-bs
> 
> Cornelia Huck (9):
>   9pfs: fix dependencies
>   kvm: remove hard dependency on pci
>   s390x/pci: add stubs
>   s390x: chsc nt2 events are pci-only
>   s390x/pci: do not advertise pci on non-pci builds
>   s390x/ccw: create s390 phb conditionally
>   s390x/sclp: properly guard pci-specific functions
>   s390x/pci: fence off instructions for non-pci
>   s390x: refine pci dependencies
> 
>  accel/kvm/kvm-all.c   |  6 ++--
>  default-configs/s390x-softmmu.mak |  2 +-
>  fsdev/Makefile.objs   |  9 ++---
>  hw/9pfs/Makefile.objs |  2 +-
>  hw/Makefile.objs  |  2 +-
>  hw/pci/pci-stub.c | 16 -
>  hw/pci/pci.c  |  2 ++
>  hw/s390x/Makefile.objs|  3 +-
>  hw/s390x/s390-pci-bus.c   | 18 +++---
>  hw/s390x/s390-pci-bus.h   | 12 ++-
>  hw/s390x/s390-pci-stub.c  | 76 
> +++
>  hw/s390x/s390-virtio-ccw.c| 14 
>  hw/s390x/sclp.c   | 39 +---
>  include/hw/pci/pci.h  |  2 ++
>  include/hw/s390x/sclp.h   | 17 ++---
>  target/s390x/ioinst.c | 16 +
>  target/s390x/kvm.c| 58 ++
>  17 files changed, 227 insertions(+), 67 deletions(-)
>  create mode 100644 hw/s390x/s390-pci-stub.c
> 




Re: [Qemu-devel] [RFC PATCH] osdep.h: Prohibit disabling assert() in supported builds

2017-08-24 Thread Markus Armbruster
Eric Blake  writes:

> On 08/22/2017 06:19 AM, Halil Pasic wrote:
>
>> OTOH I do think this is to some degree institutionalizing a bad practice
>> (you say we do not want to do that, but IMHO refusing to build with
>> NDEBUG makes only sense if we want to alter the semantic of assert so
>> that once bad becomes acceptable). I can live with that, but I'm not
>> happy about it. Have we considered rolling our own construct which is
>> designed to exhibit the properties we desire?
>
> I've thought about it, and it may have even been discussed on the list
> perhaps (although I didn't go searching to verify).
>
>> 
>> I mean, if it's about the side effects we could create something like
>> q_assert(cond) and state that cond is evaluate exactly once (and
>> depending on what we want to have, make the actions on !cond (calling
>> abort(), producing a diagnostic message) compile time tweak-able or
>> not). I assume we could then convert each usage of assert to the safe
>> q_assert programmatically.
>
> I'd prefer that if we are going to introduce our own construct that
> always evaluates side effects, and only has a compile-time switch on
> whether to abort() or (foolishly) plow on, that we name it something
> without 'assert' in the name, so that reviewers don't have to be
> confused about remembering which variant evaluates side effects.  Maybe:
>
> q_verify(cond)
>
> is a good name, which performs the side effects of 'cond' no matter
> what, but also allows us to abort() if cond fails vs. ignore the
> failure; perhaps where we make a compile-time decision between the two
> behaviors as a configure --enable-FOO flag.
>
> Converting all existing assert() and g_assert() to q_verify() should be
> fairly simple, if we like the idea.

About as simple as expanding tabs.

CODING_STYLE demands spaces rather than tabs since 2009.  455 out of
3542 C source files have tabs.  Only a minority of them is imported from
other projects and thus exempt from CODING_STYLE.

I vote for frying bigger fish.

I also vote for using standard C when standard C is servicable.



Re: [Qemu-devel] [PATCHv4 02/03] colo-compare: Use IOThread to Check old packet regularly and Process pactkets of the primary

2017-08-24 Thread Zhang Chen



On 08/22/2017 04:46 PM, Wang yong wrote:

From: Wang Yong 

Remove the task which check old packet in the comparing thread,
then use IOthread context timer to handle it.

Process pactkets in the IOThread which arrived over the socket.
we use iothread_get_g_main_context to create a new g_main_loop in
the IOThread.then the packets from the primary and the secondary
are processed in the IOThread.

Finally remove the colo-compare thread using the IOThread instead.

Signed-off-by: Wang Yong 
Signed-off-by: Wang Guang 
---
  net/colo-compare.c | 75 --
  1 file changed, 39 insertions(+), 36 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 5fe8e3f..69cb16e 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -29,6 +29,7 @@
  #include "qemu/sockets.h"
  #include "qapi-visit.h"
  #include "net/colo.h"
+#include "sysemu/iothread.h"
  
  #define TYPE_COLO_COMPARE "colo-compare"

  #define COLO_COMPARE(obj) \
@@ -82,11 +83,10 @@ typedef struct CompareState {
  GQueue conn_list;
  /* hashtable to save connection */
  GHashTable *connection_track_table;
-/* compare thread, a thread for each NIC */
-QemuThread thread;
  
+IOThread *iothread;

  GMainContext *worker_context;
-GMainLoop *compare_loop;
+QEMUTimer *packet_check_timer;
  } CompareState;
  
  typedef struct CompareClass {

@@ -597,22 +597,40 @@ static void compare_sec_chr_in(void *opaque, const 
uint8_t *buf, int size)
   * Check old packet regularly so it can watch for any packets
   * that the secondary hasn't produced equivalents of.
   */
-static gboolean check_old_packet_regular(void *opaque)
+static void check_old_packet_regular(void *opaque)
  {
  CompareState *s = opaque;
  
  /* if have old packet we will notify checkpoint */

  colo_old_packet_check(s);
+timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+REGULAR_PACKET_CHECK_MS);
+}
+
+static void colo_compare_timer_init(CompareState *s)
+{
+AioContext *ctx = iothread_get_aio_context(s->iothread);
  
-return TRUE;

+s->packet_check_timer = aio_timer_new(ctx, QEMU_CLOCK_VIRTUAL,
+SCALE_MS, check_old_packet_regular,
+s);
+timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+REGULAR_PACKET_CHECK_MS);
  }
  
-static void *colo_compare_thread(void *opaque)

+static void colo_compare_timer_del(CompareState *s)
  {
-CompareState *s = opaque;
-GSource *timeout_source;
+if (s->packet_check_timer) {
+timer_del(s->packet_check_timer);
+timer_free(s->packet_check_timer);
+s->packet_check_timer = NULL;
+}
+ }
  
-s->worker_context = g_main_context_new();

+static void colo_compare_iothread(CompareState *s)
+{
+object_ref(OBJECT(s->iothread));
+s->worker_context = iothread_get_g_main_context(s->iothread);
  
  qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read,

   compare_pri_chr_in, NULL, NULL,
@@ -621,20 +639,7 @@ static void *colo_compare_thread(void *opaque)
   compare_sec_chr_in, NULL, NULL,
   s, s->worker_context, true);
  
-s->compare_loop = g_main_loop_new(s->worker_context, FALSE);

-
-/* To kick any packets that the secondary doesn't match */
-timeout_source = g_timeout_source_new(REGULAR_PACKET_CHECK_MS);
-g_source_set_callback(timeout_source,
-  (GSourceFunc)check_old_packet_regular, s, NULL);
-g_source_attach(timeout_source, s->worker_context);
-
-g_main_loop_run(s->compare_loop);
-
-g_source_unref(timeout_source);
-g_main_loop_unref(s->compare_loop);
-g_main_context_unref(s->worker_context);
-return NULL;
+colo_compare_timer_init(s);
  }
  
  static char *compare_get_pri_indev(Object *obj, Error **errp)

@@ -759,12 +764,10 @@ static void colo_compare_complete(UserCreatable *uc, 
Error **errp)
  {
  CompareState *s = COLO_COMPARE(uc);
  Chardev *chr;
-char thread_name[64];
-static int compare_id;
  
-if (!s->pri_indev || !s->sec_indev || !s->outdev) {

+if (!s->pri_indev || !s->sec_indev || !s->outdev || !s->iothread) {
  error_setg(errp, "colo compare needs 'primary_in' ,"
-   "'secondary_in','outdev' property set");
+   "'secondary_in','outdev','iothread' property set");


If user forgot input the iothread field, they will get the segmentation 
fault.

Please fix this bug.

Program received signal SIGSEGV, Segmentation fault.
0x5594c319 in iothread_get_aio_context (iothread=0x0) at 
iothread.c:271

271return iothread->ctx;


Thanks
Zhang Chen


  return;
  } else if (!strcmp(s->pri_indev, s->outdev) ||
 !strcmp(s->sec_indev, s->outdev) ||
@@ -799,12 +802,7 @@ static void colo_compare_c

[Qemu-devel] [PATCH 2/2] qxl: add support for chunked cursors.

2017-08-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 hw/display/qxl-render.c | 33 ++---
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/hw/display/qxl-render.c b/hw/display/qxl-render.c
index e1b3f05ecb..b2c98f90c0 100644
--- a/hw/display/qxl-render.c
+++ b/hw/display/qxl-render.c
@@ -204,7 +204,30 @@ void qxl_render_update_area_done(PCIQXLDevice *qxl, 
QXLCookie *cookie)
 g_free(cookie);
 }
 
-static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor)
+static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,
+  QXLDataChunk *chunk, uint32_t group_id)
+{
+uint32_t max_chunks = 32;
+size_t offset = 0;
+size_t bytes;
+
+for (;;) {
+bytes = MIN(size - offset, chunk->data_size);
+memcpy(dest + offset, chunk->data, bytes);
+offset += bytes;
+if (offset == size)
+return;
+chunk = qxl_phys2virt(qxl, chunk->next_chunk, group_id);
+if (!chunk)
+return;
+max_chunks--;
+if (max_chunks == 0)
+return;
+}
+}
+
+static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor,
+  uint32_t group_id)
 {
 QEMUCursor *c;
 size_t size;
@@ -215,7 +238,7 @@ static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor 
*cursor)
 switch (cursor->header.type) {
 case SPICE_CURSOR_TYPE_ALPHA:
 size = sizeof(uint32_t) * cursor->header.width * cursor->header.height;
-memcpy(c->data, cursor->chunk.data, size);
+qxl_unpack_chunks(c->data, size, qxl, &cursor->chunk, group_id);
 if (qxl->debug > 2) {
 cursor_print_ascii_art(c, "qxl/alpha");
 }
@@ -259,11 +282,7 @@ int qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt 
*ext)
 if (!cursor) {
 return 1;
 }
-if (cursor->chunk.data_size != cursor->data_size) {
-fprintf(stderr, "%s: multiple chunks\n", __FUNCTION__);
-return 1;
-}
-c = qxl_cursor(qxl, cursor);
+c = qxl_cursor(qxl, cursor, ext->group_id);
 if (c == NULL) {
 c = cursor_builtin_left_ptr();
 }
-- 
2.9.3




[Qemu-devel] [PATCH 0/2] qxl: add support for chunked cursors.

2017-08-24 Thread Gerd Hoffmann
This series adds support for unpacking qxl chunks, and uses it to
support chunked cursor images.  Windows guest drivers seem to use
that when in HiDPI mode.

Also drop (broken) support for mono cursors.

Gerd Hoffmann (2):
  qxl: drop mono cursor support
  qxl: add support for chunked cursors.

 hw/display/qxl-render.c | 42 ++
 1 file changed, 26 insertions(+), 16 deletions(-)

-- 
2.9.3




[Qemu-devel] [PATCH 1/2] qxl: drop mono cursor support

2017-08-24 Thread Gerd Hoffmann
The chunk size sanity check in qxl_render_cursor works for
SPICE_CURSOR_TYPE_ALPHA cursors only.  So support for
SPICE_CURSOR_TYPE_MONO cursors must be broken for ages without anyone
noticing.  Most likely it simply isn't used any more by guest drivers.
Drop the dead code.

Signed-off-by: Gerd Hoffmann 
---
 hw/display/qxl-render.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/hw/display/qxl-render.c b/hw/display/qxl-render.c
index 9ad9d9e0f5..e1b3f05ecb 100644
--- a/hw/display/qxl-render.c
+++ b/hw/display/qxl-render.c
@@ -207,7 +207,6 @@ void qxl_render_update_area_done(PCIQXLDevice *qxl, 
QXLCookie *cookie)
 static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor)
 {
 QEMUCursor *c;
-uint8_t *image, *mask;
 size_t size;
 
 c = cursor_alloc(cursor->header.width, cursor->header.height);
@@ -221,14 +220,6 @@ static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor 
*cursor)
 cursor_print_ascii_art(c, "qxl/alpha");
 }
 break;
-case SPICE_CURSOR_TYPE_MONO:
-mask  = cursor->chunk.data;
-image = mask + cursor_get_mono_bpl(c) * c->width;
-cursor_set_mono(c, 0xff, 0x00, image, 1, mask);
-if (qxl->debug > 2) {
-cursor_print_ascii_art(c, "qxl/mono");
-}
-break;
 default:
 fprintf(stderr, "%s: not implemented: type %d\n",
 __FUNCTION__, cursor->header.type);
-- 
2.9.3




Re: [Qemu-devel] [PATCH v2] audio: intel-hda: do not use old_mmio accesses

2017-08-24 Thread Gerd Hoffmann
On Wed, 2017-08-23 at 20:37 +0100, Matt Parker wrote:
> +    intel_hda_reg_write(d, reg, val, (1UL << (size * 8)) - 1);

Hmm?  Same as v1, forgot to commit the changes?

cheers,
  Gerd




[Qemu-devel] [PATCH for-2.11 1/6] ppc: use macros to make cpu type name from string literal

2017-08-24 Thread Igor Mammedov
Replace
  "-" TYPE_POWERPC_CPU
when composing cpu type name from cpu model string literal
and the same pattern in format strings with
 POWERPC_CPU_TYPE_SUFFIX and POWERPC_CPU_TYPE_NAME(model)
macroses like we do in x86.

Later POWERPC_CPU_TYPE_NAME() will be used to define default
cpu type per machine type and as bonus it will be consistent
and easy grep-able pattern across all other targets that I'm
plannig to treat the same way.

Signed-off-by: Igor Mammedov 
---
 target/ppc/cpu.h| 3 +++
 target/ppc/kvm_ppc.h| 2 +-
 target/ppc/cpu-models.c | 2 +-
 target/ppc/kvm.c| 2 +-
 target/ppc/translate_init.c | 6 +++---
 5 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 12f0949..0512393 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -1354,6 +1354,9 @@ int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t 
val);
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_POWERPC_CPU, cpu_model)
 
+#define POWERPC_CPU_TYPE_SUFFIX "-" TYPE_POWERPC_CPU
+#define POWERPC_CPU_TYPE_NAME(model) model POWERPC_CPU_TYPE_SUFFIX
+
 #define cpu_signal_handler cpu_ppc_signal_handler
 #define cpu_list ppc_cpu_list
 
diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h
index 6bc6fb3..bcb40f2 100644
--- a/target/ppc/kvm_ppc.h
+++ b/target/ppc/kvm_ppc.h
@@ -9,7 +9,7 @@
 #ifndef KVM_PPC_H
 #define KVM_PPC_H
 
-#define TYPE_HOST_POWERPC_CPU "host-" TYPE_POWERPC_CPU
+#define TYPE_HOST_POWERPC_CPU POWERPC_CPU_TYPE_NAME("host")
 
 #ifdef CONFIG_KVM
 
diff --git a/target/ppc/cpu-models.c b/target/ppc/cpu-models.c
index 4d3e635..8b27962 100644
--- a/target/ppc/cpu-models.c
+++ b/target/ppc/cpu-models.c
@@ -51,7 +51,7 @@
 \
 static const TypeInfo   \
 glue(POWERPC_DEF_PREFIX(_pvr, _svr, _type), _cpu_type_info) = { \
-.name   = _name "-" TYPE_POWERPC_CPU,   \
+.name   = POWERPC_CPU_TYPE_NAME(_name),   \
 .parent = stringify(_type) "-family-" TYPE_POWERPC_CPU, \
 .class_init =   \
 glue(POWERPC_DEF_PREFIX(_pvr, _svr, _type), _cpu_class_init),   \
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 8571379..8590809 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -2484,7 +2484,7 @@ static int kvm_ppc_register_host_cpu_type(void)
 char *suffix;
 
 ppc_cpu_aliases[i].model = g_strdup(object_class_get_name(oc));
-suffix = strstr(ppc_cpu_aliases[i].model, "-"TYPE_POWERPC_CPU);
+suffix = strstr(ppc_cpu_aliases[i].model, POWERPC_CPU_TYPE_SUFFIX);
 if (suffix) {
 *suffix = 0;
 }
diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c
index 43be9a8..f377cf2 100644
--- a/target/ppc/translate_init.c
+++ b/target/ppc/translate_init.c
@@ -10185,7 +10185,7 @@ static gint ppc_cpu_compare_class_name(gconstpointer a, 
gconstpointer b)
 if (strncasecmp(name, object_class_get_name(oc), strlen(name)) == 0 &&
 ppc_cpu_is_valid(pcc) &&
 strcmp(object_class_get_name(oc) + strlen(name),
-   "-" TYPE_POWERPC_CPU) == 0) {
+   POWERPC_CPU_TYPE_SUFFIX) == 0) {
 return 0;
 }
 return -1;
@@ -10327,7 +10327,7 @@ static void ppc_cpu_list_entry(gpointer data, gpointer 
user_data)
 }
 
 name = g_strndup(typename,
- strlen(typename) - strlen("-" TYPE_POWERPC_CPU));
+ strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFFIX));
 (*s->cpu_fprintf)(s->file, "PowerPC %-16s PVR %08x\n",
   name, pcc->pvr);
 for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
@@ -10388,7 +10388,7 @@ static void ppc_cpu_defs_entry(gpointer data, gpointer 
user_data)
 typename = object_class_get_name(oc);
 info = g_malloc0(sizeof(*info));
 info->name = g_strndup(typename,
-   strlen(typename) - strlen("-" TYPE_POWERPC_CPU));
+   strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFFIX));
 
 entry = g_malloc0(sizeof(*entry));
 entry->value = info;
-- 
2.7.4




[Qemu-devel] [PATCH for-2.11 0/6] ppc: cpu_model handling cleanups

2017-08-24 Thread Igor Mammedov
While removing cpu_init() tree-wide, I've stumbled uppon
PPC way of parsing cpu_model which looked way too complex
compared to other targets.

So here goes cleanups that instead of current inconsistent
way of dealing with cpu models
 - mix of case-(in)sensetive lookups and cpu model names
 - aliases pointing to another aliases
normalize cpu model names to upper-case and make aliases
point to cpu moldel names. These changes allow to simplify
cpu model handling quite a bit and make it look/behave
a bit more in line with other targets.
 
Patches are not must have for cpu_init() removal but make
it a little bit easier without need to deal with way of
conversion of cpu model to cpu type, so pls consider
merging it early once 2.11 merge window is open if
patches make any sense.

loosly (to avoid conflicts) depends on:
  https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg03364.html

repo for testing:
  https://github.com/imammedo/qemu.git ppc_cpu_model_cleanups_V1

CC: David Gibson 
CC: Alexander Graf 
CC: qemu-...@nongnu.org


Igor Mammedov (6):
  ppc: use macros to make cpu type name from string literal
  ppc: make cpu_model translation to type consistent
  ppc: make cpu alias point only to real cpu models
  ppc: replace inter-function cyclic dependency/recurssion with 2 simple
lookups
  ppc: simplify cpu model lookup by PVR
  ppc: drop caching ObjectClass from PowerPCCPUAlias

 target/ppc/cpu-models.h |   3 +-
 target/ppc/cpu.h|   3 +
 target/ppc/kvm_ppc.h|   2 +-
 hw/ppc/spapr_cpu_core.c |  30 +-
 target/ppc/cpu-models.c | 876 ++--
 target/ppc/kvm.c|   5 +-
 target/ppc/translate_init.c | 100 ++---
 7 files changed, 490 insertions(+), 529 deletions(-)

-- 
2.7.4




[Qemu-devel] [PATCH for-2.11 6/6] ppc: drop caching ObjectClass from PowerPCCPUAlias

2017-08-24 Thread Igor Mammedov
Caching there practically doesn't give any benefits
and that at slow path druring querying supported CPU list.
But it introduces non conventional path of where from
comes used CPU type name (kvm_ppc_register_host_cpu_type).

Taking in account that kvm_ppc_register_host_cpu_type()
fixes up models the aliases point to, it's sufficient to
make ppc_cpu_class_by_name() translate cpu alias to
correct cpu type name.
So drop PowerPCCPUAlias::oc field + ppc_cpu_class_by_alias()
and let ppc_cpu_class_by_name() do conversion to cpu type name,
which simplifies code a little bit saving ~20LOC and trouble
wondering why ppc_cpu_class_by_alias() is necessary.

Signed-off-by: Igor Mammedov 
---
 target/ppc/cpu-models.h |  1 -
 target/ppc/kvm.c|  1 -
 target/ppc/translate_init.c | 26 ++
 3 files changed, 2 insertions(+), 26 deletions(-)

diff --git a/target/ppc/cpu-models.h b/target/ppc/cpu-models.h
index d748c68..e9c6015 100644
--- a/target/ppc/cpu-models.h
+++ b/target/ppc/cpu-models.h
@@ -31,7 +31,6 @@
 typedef struct PowerPCCPUAlias {
 const char *alias;
 const char *model;
-ObjectClass *oc;
 } PowerPCCPUAlias;
 
 extern PowerPCCPUAlias ppc_cpu_aliases[];
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 3f21190..995c2da 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -2488,7 +2488,6 @@ static int kvm_ppc_register_host_cpu_type(void)
 if (suffix) {
 *suffix = 0;
 }
-ppc_cpu_aliases[i].oc = oc;
 break;
 }
 }
diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c
index ca9f1e3..c06f34b 100644
--- a/target/ppc/translate_init.c
+++ b/target/ppc/translate_init.c
@@ -10177,28 +10177,6 @@ PowerPCCPUClass *ppc_cpu_class_by_pvr_mask(uint32_t 
pvr)
 return pcc;
 }
 
-static ObjectClass *ppc_cpu_class_by_name(const char *name);
-
-static ObjectClass *ppc_cpu_class_by_alias(PowerPCCPUAlias *alias)
-{
-ObjectClass *invalid_class = (void*)ppc_cpu_class_by_alias;
-
-/* Cache target class lookups in the alias table */
-if (!alias->oc) {
-alias->oc = ppc_cpu_class_by_name(alias->model);
-if (!alias->oc) {
-/* Fast check for non-existing aliases */
-alias->oc = invalid_class;
-}
-}
-
-if (alias->oc == invalid_class) {
-return NULL;
-} else {
-return alias->oc;
-}
-}
-
 static ObjectClass *ppc_cpu_class_by_name(const char *name)
 {
 char *cpu_model, *typename;
@@ -10310,7 +10288,7 @@ static void ppc_cpu_list_entry(gpointer data, gpointer 
user_data)
   name, pcc->pvr);
 for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
 PowerPCCPUAlias *alias = &ppc_cpu_aliases[i];
-ObjectClass *alias_oc = ppc_cpu_class_by_alias(alias);
+ObjectClass *alias_oc = ppc_cpu_class_by_name(alias->model);
 
 if (alias_oc != oc) {
 continue;
@@ -10390,7 +10368,7 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error 
**errp)
 CpuDefinitionInfoList *entry;
 CpuDefinitionInfo *info;
 
-oc = ppc_cpu_class_by_alias(alias);
+oc = ppc_cpu_class_by_name(alias->model);
 if (oc == NULL) {
 continue;
 }
-- 
2.7.4




[Qemu-devel] [PATCH for-2.11 3/6] ppc: make cpu alias point only to real cpu models

2017-08-24 Thread Igor Mammedov
alias pointing to another alias forces lookup code to
do recurrsive translation till real cpu model is reached.

Drop this nonsence and make each alias point to cpu model
that has corresponding CPU type. It will allow to drop
recurrsion in cpu model translation code and actually
make ppc_cpu_aliases[] content use PowerPCCPUAlias
fields properly
(i.e. alias goes into .alias and model goes into .model)

While at it add TODO defines around aliases that point to
cpu models excluded by the same TODO defines.

Signed-off-by: Igor Mammedov 
---
If it were up to me, I'd remove all TODO cpu models as dead
code and make whomever wants to add them back to do so
with actual implementation.
---
 target/ppc/cpu-models.h |  2 +-
 target/ppc/cpu-models.c | 56 ++---
 2 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/target/ppc/cpu-models.h b/target/ppc/cpu-models.h
index b563c45..d748c68 100644
--- a/target/ppc/cpu-models.h
+++ b/target/ppc/cpu-models.h
@@ -24,7 +24,7 @@
 /**
  * PowerPCCPUAlias:
  * @alias: The alias name.
- * @model: The CPU model @alias refers to.
+ * @model: The CPU model @alias refers to, that directly resolves into CPU type
  *
  * A mapping entry from CPU @alias to CPU @model.
  */
diff --git a/target/ppc/cpu-models.c b/target/ppc/cpu-models.c
index 346b6b1..f917b9d 100644
--- a/target/ppc/cpu-models.c
+++ b/target/ppc/cpu-models.c
@@ -1235,6 +1235,7 @@ PowerPCCPUAlias ppc_cpu_aliases[] = {
 { "X2VP50", "X2VP20" },
 
 { "440EP", "440EPB" },
+#if defined(TODO_USER_ONLY)
 { "440GP", "440GPC" },
 { "440GR", "440GRA" },
 { "440GX", "440GXF" },
@@ -1272,36 +1273,37 @@ PowerPCCPUAlias ppc_cpu_aliases[] = {
 { "MPC875", "MPC8XX" },
 { "MPC880", "MPC8XX" },
 { "MPC885", "MPC8XX" },
+#endif
 
 /* PowerPC MPC603 microcontrollers */
 { "MPC8240", "603" },
 
-{ "MPC52XX", "MPC5200" },
+{ "MPC52XX", "MPC5200_V12" },
 { "MPC5200", "MPC5200_V12" },
 { "MPC5200B", "MPC5200B_V21" },
 
-{ "MPC82XX", "MPC8280" },
-{ "POWERQUICC-II", "MPC82XX" },
+{ "MPC82XX", "G2LEGP3" },
+{ "POWERQUICC-II", "G2LEGP3" },
 { "MPC8241", "G2HIP4" },
 { "MPC8245", "G2HIP4" },
 { "MPC8247", "G2LEGP3" },
 { "MPC8248", "G2LEGP3" },
-{ "MPC8250", "MPC8250_HIP4" },
+{ "MPC8250", "G2HIP4" },
 { "MPC8250_HIP3", "G2HIP3" },
 { "MPC8250_HIP4", "G2HIP4" },
-{ "MPC8255", "MPC8255_HIP4" },
+{ "MPC8255", "G2HIP4" },
 { "MPC8255_HIP3", "G2HIP3" },
 { "MPC8255_HIP4", "G2HIP4" },
-{ "MPC8260", "MPC8260_HIP4" },
+{ "MPC8260", "G2HIP4" },
 { "MPC8260_HIP3", "G2HIP3" },
 { "MPC8260_HIP4", "G2HIP4" },
-{ "MPC8264", "MPC8264_HIP4" },
+{ "MPC8264", "G2HIP4" },
 { "MPC8264_HIP3", "G2HIP3" },
 { "MPC8264_HIP4", "G2HIP4" },
-{ "MPC8265", "MPC8265_HIP4" },
+{ "MPC8265", "G2HIP4" },
 { "MPC8265_HIP3", "G2HIP3" },
 { "MPC8265_HIP4", "G2HIP4" },
-{ "MPC8266", "MPC8266_HIP4" },
+{ "MPC8266", "G2HIP4" },
 { "MPC8266_HIP3", "G2HIP3" },
 { "MPC8266_HIP4", "G2HIP4" },
 { "MPC8270", "G2LEGP3" },
@@ -1339,18 +1341,18 @@ PowerPCCPUAlias ppc_cpu_aliases[] = {
 { "601V", "601_V2" },
 { "VANILLA", "603" },
 { "603E", "603E_V4.1" },
-{ "STRETCH", "603E" },
+{ "STRETCH", "603E_V4.1" },
 { "VAILLANT", "603E7V" },
 { "603R", "603E7T" },
-{ "GOLDENEYE", "603R" },
+{ "GOLDENEYE", "603E7T" },
 { "604E", "604E_V2.4" },
-{ "SIROCCO", "604E" },
+{ "SIROCCO", "604E_V2.4" },
 { "MACH5", "604R" },
 { "740", "740_V3.1" },
-{ "ARTHUR", "740" },
+{ "ARTHUR", "740_V3.1" },
 { "750", "750_V3.1" },
-{ "TYPHOON", "750" },
-{ "G3",  "750" },
+{ "TYPHOON", "750_V3.1" },
+{ "G3",  "750_V3.1" },
 { "CONAN/DOYLE", "750P" },
 { "750CL", "750CL_V2.0" },
 { "750CX", "750CX_V2.2" },
@@ -1358,32 +1360,34 @@ PowerPCCPUAlias ppc_cpu_aliases[] = {
 { "750FX", "750FX_V2.3" },
 { "750GX", "750GX_V1.2" },
 { "750L", "750L_V3.2" },
-{ "LONESTAR", "750L" },
+{ "LONESTAR", "750L_V3.2" },
 { "745", "745_V2.8" },
 { "755", "755_V2.8" },
-{ "GOLDFINGER", "755" },
+{ "GOLDFINGER", "755_V2.8" },
 { "7400", "7400_V2.9" },
-{ "MAX", "7400" },
-{ "G4",  "7400" },
+{ "MAX", "7400_V2.9" },
+{ "G4",  "7400_V2.9" },
 { "7410", "7410_V1.4" },
-{ "NITRO", "7410" },
+{ "NITRO", "7410_V1.4" },
 { "7448", "7448_V2.1" },
 { "7450", "7450_V2.1" },
-{ "VGER", "7450" },
+{ "VGER", "7450_V2.1" },
 { "7441", "7441_V2.3" },
 { "7451", "7451_V2.3" },
 { "7445", "7445_V3.2" },
 { "7455", "7455_V3.2" },
-{ "APOLLO6", "7455" },
+{ "APOLLO6", "7455_V3.2" },
 { "7447", "7447_V1.1" },
 { "7457", "7457_V1.2" },
-{ "APOLLO7", "7457" },
+{ "APOLLO7", "7457_V1.2" },
 { "7447A", "7447A_V1.2" },
 { "7457A", "7457A_V1.2" },
 { "APOLLO7PM", "7457A_V1.0" },
 #if defined(TARGET_

[Qemu-devel] [PATCH for-2.11 4/6] ppc: replace inter-function cyclic dependency/recurssion with 2 simple lookups

2017-08-24 Thread Igor Mammedov
previous patches cleaned up cpu model/alias naming which
allows to simplify cpu model/alias to cpu type lookup a bit
byt removing recurssion and dependency of ppc_cpu_class_by_name() /
ppc_cpu_class_by_alias() on each other.
Besides of simplifying code it reduces it by ~15LOC.

Signed-off-by: Igor Mammedov 
---
 target/ppc/translate_init.c | 43 +--
 1 file changed, 13 insertions(+), 30 deletions(-)

diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c
index 0325226..f1a559d 100644
--- a/target/ppc/translate_init.c
+++ b/target/ppc/translate_init.c
@@ -10176,22 +10176,6 @@ PowerPCCPUClass *ppc_cpu_class_by_pvr_mask(uint32_t 
pvr)
 return pcc;
 }
 
-static gint ppc_cpu_compare_class_name(gconstpointer a, gconstpointer b)
-{
-ObjectClass *oc = (ObjectClass *)a;
-const char *name = b;
-PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
-
-if (strncasecmp(name, object_class_get_name(oc), strlen(name)) == 0 &&
-ppc_cpu_is_valid(pcc) &&
-strcmp(object_class_get_name(oc) + strlen(name),
-   POWERPC_CPU_TYPE_SUFFIX) == 0) {
-return 0;
-}
-return -1;
-}
-
-
 static ObjectClass *ppc_cpu_class_by_name(const char *name);
 
 static ObjectClass *ppc_cpu_class_by_alias(PowerPCCPUAlias *alias)
@@ -10216,8 +10200,8 @@ static ObjectClass 
*ppc_cpu_class_by_alias(PowerPCCPUAlias *alias)
 
 static ObjectClass *ppc_cpu_class_by_name(const char *name)
 {
-GSList *list, *item;
-ObjectClass *ret = NULL;
+char *cpu_model, *typename;
+ObjectClass *oc;
 const char *p;
 int i, len;
 
@@ -10238,21 +10222,20 @@ static ObjectClass *ppc_cpu_class_by_name(const char 
*name)
 }
 }
 
-list = object_class_get_list(TYPE_POWERPC_CPU, false);
-item = g_slist_find_custom(list, name, ppc_cpu_compare_class_name);
-if (item != NULL) {
-ret = OBJECT_CLASS(item->data);
+cpu_model = g_ascii_strup(name, -1);
+p = ppc_cpu_lookup_alias(cpu_model);
+if (p) {
+g_free(cpu_model);
+cpu_model = g_strdup(p);
 }
-g_slist_free(list);
 
-if (ret) {
-return ret;
-}
+typename = g_strdup_printf("%s" POWERPC_CPU_TYPE_SUFFIX, cpu_model);
+oc = object_class_by_name(typename);
+g_free(typename);
+g_free(cpu_model);
 
-for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
-if (strcasecmp(ppc_cpu_aliases[i].alias, name) == 0) {
-return ppc_cpu_class_by_alias(&ppc_cpu_aliases[i]);
-}
+if (oc && ppc_cpu_is_valid(POWERPC_CPU_CLASS(oc))) {
+return oc;
 }
 
 return NULL;
-- 
2.7.4




[Qemu-devel] [PATCH for-2.11 2/6] ppc: make cpu_model translation to type consistent

2017-08-24 Thread Igor Mammedov
PPC handles -cpu FOO rather incosistently,
i.e. it does case-insensitive matching of FOO to
a CPU type (see: ppc_cpu_compare_class_name) but
handles alias names as case-sensitive, as result:

 # qemu-system-ppc64 -M mac99 -cpu g3
 qemu-system-ppc64: unable to find CPU model ' kN�U'

 # qemu-system-ppc64 -cpu 970MP_V1.1
 qemu-system-ppc64: Unable to find sPAPR CPU Core definition

while

 # qemu-system-ppc64 -M mac99 -cpu G3
 # qemu-system-ppc64 -cpu 970MP_v1.1

start up just fine.

Considering we can't take case-insensitive matching away,
make it case-insensitive for  all alias/type/core_type
lookups.

As side effect it allows to remove duplicate core types
which are the same but use lower-case letters in name.

Signed-off-by: Igor Mammedov 
---
PS:
 consistent naming will be used by follow up patch to
 simplify cpu_model translation code and drop ~50LOC.
---
 hw/ppc/spapr_cpu_core.c |  30 +-
 target/ppc/cpu-models.c | 866 ++--
 target/ppc/kvm.c|   2 +-
 target/ppc/translate_init.c |   2 +-
 4 files changed, 450 insertions(+), 450 deletions(-)

diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index ea278ce..40936b4 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -130,8 +130,10 @@ char *spapr_get_cpu_core_type(const char *model)
 {
 char *core_type;
 gchar **model_pieces = g_strsplit(model, ",", 2);
+gchar *cpu_model = g_ascii_strup(model_pieces[0], -1);
+g_strfreev(model_pieces);
 
-core_type = g_strdup_printf("%s-%s", model_pieces[0], TYPE_SPAPR_CPU_CORE);
+core_type = g_strdup_printf("%s-" TYPE_SPAPR_CPU_CORE, cpu_model);
 
 /* Check whether it exists or whether we have to look up an alias name */
 if (!object_class_by_name(core_type)) {
@@ -139,13 +141,13 @@ char *spapr_get_cpu_core_type(const char *model)
 
 g_free(core_type);
 core_type = NULL;
-realmodel = ppc_cpu_lookup_alias(model_pieces[0]);
+realmodel = ppc_cpu_lookup_alias(cpu_model);
 if (realmodel) {
 core_type = spapr_get_cpu_core_type(realmodel);
 }
 }
+g_free(cpu_model);
 
-g_strfreev(model_pieces);
 return core_type;
 }
 
@@ -265,34 +267,32 @@ err:
 
 static const char *spapr_core_models[] = {
 /* 970 */
-"970_v2.2",
+"970_V2.2",
 
 /* 970MP variants */
-"970MP_v1.0",
-"970mp_v1.0",
-"970MP_v1.1",
-"970mp_v1.1",
+"970MP_V1.0",
+"970MP_V1.1",
 
 /* POWER5+ */
-"POWER5+_v2.1",
+"POWER5+_V2.1",
 
 /* POWER7 */
-"POWER7_v2.3",
+"POWER7_V2.3",
 
 /* POWER7+ */
-"POWER7+_v2.1",
+"POWER7+_V2.1",
 
 /* POWER8 */
-"POWER8_v2.0",
+"POWER8_V2.0",
 
 /* POWER8E */
-"POWER8E_v2.1",
+"POWER8E_V2.1",
 
 /* POWER8NVL */
-"POWER8NVL_v1.0",
+"POWER8NVL_V1.0",
 
 /* POWER9 */
-"POWER9_v1.0",
+"POWER9_V1.0",
 };
 
 static Property spapr_cpu_core_properties[] = {
diff --git a/target/ppc/cpu-models.c b/target/ppc/cpu-models.c
index 8b27962..346b6b1 100644
--- a/target/ppc/cpu-models.c
+++ b/target/ppc/cpu-models.c
@@ -101,10 +101,10 @@
 #endif
 POWERPC_DEF("IOP480",CPU_POWERPC_IOP480, IOP480,
 "IOP480 (401 microcontroller)")
-POWERPC_DEF("Cobra", CPU_POWERPC_COBRA,  401,
+POWERPC_DEF("COBRA", CPU_POWERPC_COBRA,  401,
 "IBM Processor for Network Resources")
 #if defined(TODO)
-POWERPC_DEF("Xipchip",   CPU_POWERPC_XIPCHIP,401,
+POWERPC_DEF("XIPCHIP",   CPU_POWERPC_XIPCHIP,401,
 NULL)
 #endif
 /* PowerPC 403 family*/
@@ -176,16 +176,16 @@
 "PowerPC 405 F6")
 #endif
 /* PowerPC 405 microcontrollers  */
-POWERPC_DEF("405CRa",CPU_POWERPC_405CRa, 405,
+POWERPC_DEF("405CRA",CPU_POWERPC_405CRa, 405,
 "PowerPC 405 CRa")
-POWERPC_DEF("405CRb",CPU_POWERPC_405CRb, 405,
+POWERPC_DEF("405CRB",CPU_POWERPC_405CRb, 405,
 "PowerPC 405 CRb")
-POWERPC_DEF("405CRc",CPU_POWERPC_405CRc, 405,
+POWERPC_DEF("405CRC",CPU_POWERPC_405CRc, 405,
 "PowerPC 405 CRc")
 POWERPC_DEF("405EP", CPU_POWERPC_405EP,  405,
 "PowerPC 405 EP")
 #if defined(TODO)
-POWERPC_DEF("405EXr",CPU_POWERPC_405EXr, 405,
+POWERPC_DEF("405EXR",CPU_POWERPC_405EXr, 405,
 "PowerPC 405 EXr")
 #endif
 POWERPC_DEF("405EZ", CPU_POWERPC_405EZ,  405,
@@ -194,13 +194,13 @@
 POWERPC_DEF("405FX", CPU_POWERPC_405FX,  405,
 "

[Qemu-devel] [PATCH for-2.11 5/6] ppc: simplify cpu model lookup by PVR

2017-08-24 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 target/ppc/translate_init.c | 27 +++
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c
index f1a559d..ca9f1e3 100644
--- a/target/ppc/translate_init.c
+++ b/target/ppc/translate_init.c
@@ -34,6 +34,7 @@
 #include "hw/ppc/ppc.h"
 #include "mmu-book3s-v3.h"
 #include "sysemu/qtest.h"
+#include "qemu/cutils.h"
 
 //#define PPC_DUMP_CPU
 //#define PPC_DEBUG_SPR
@@ -10203,22 +10204,16 @@ static ObjectClass *ppc_cpu_class_by_name(const char 
*name)
 char *cpu_model, *typename;
 ObjectClass *oc;
 const char *p;
-int i, len;
-
-/* Check if the given name is a PVR */
-len = strlen(name);
-if (len == 10 && name[0] == '0' && name[1] == 'x') {
-p = name + 2;
-goto check_pvr;
-} else if (len == 8) {
-p = name;
-check_pvr:
-for (i = 0; i < 8; i++) {
-if (!qemu_isxdigit(*p++))
-break;
-}
-if (i == 8) {
-return OBJECT_CLASS(ppc_cpu_class_by_pvr(strtoul(name, NULL, 16)));
+unsigned long pvr;
+
+/* Lookup by PVR if cpu_model is valid 8 digit hex number
+ * (excl: 0x prefix if present)
+ */
+if (!qemu_strtoul(name, &p, 16, &pvr)) {
+int len = p - name;
+len = (len == 10) && (name[1] == 'x') ? len - 2 : len;
+if (len == 8) {
+return OBJECT_CLASS(ppc_cpu_class_by_pvr(pvr));
 }
 }
 
-- 
2.7.4




Re: [Qemu-devel] [PATCH v5 7/9] s390x/sclp: properly guard pci-specific functions

2017-08-24 Thread Cornelia Huck
On Wed, 23 Aug 2017 18:25:05 +0200
Pierre Morel  wrote:

> On 23/08/2017 17:54, Cornelia Huck wrote:
> > If we do not provide zpci, pci reconfiguration via sclp is not available
> > either. I/O adapter configuration, however, should always be present.
> > 
> > Rename the values that refer to I/O adapter configuration (instead of only
> > pci) to make things clearer.
> > 
> > Move length checking of the sccb for I/O adapter configuration into the
> > common sclp code (out of the pci code). This also fixes an issue that
> > the pci code would refer to a field in the sccb before checking whether
> > it was actually long enough.
> > 
> > Check for the adapter type in the sccb and return unrecognized adapter
> > type if the guest tries to issue I/O adapter configure/deconfigure for
> > a type other than pci or for pci if the zpci facility is not provided.
> > 
> > Signed-off-by: Cornelia Huck 
> > ---
> >   hw/s390x/s390-pci-bus.c  | 14 ++
> >   hw/s390x/s390-pci-bus.h  |  8 
> >   hw/s390x/s390-pci-stub.c |  2 ++
> >   hw/s390x/sclp.c  | 39 ++-
> >   include/hw/s390x/sclp.h  | 17 +
> >   5 files changed, 51 insertions(+), 29 deletions(-)

> LGTM and
> I could also test the all serie on the hardware (sure is sure) :)
> with VFIO and virtio PCI... so
> 
> Reviewed-by: Pierre Morel 

Cool, thanks!



Re: [Qemu-devel] [PATCH v5 2/9] kvm: remove hard dependency on pci

2017-08-24 Thread Cornelia Huck
On Thu, 24 Aug 2017 03:13:46 +0200
Thomas Huth  wrote:

> On 23.08.2017 17:54, Cornelia Huck wrote:
> > The msi routing code in kvm calls some pci functions: provide
> > some stubs to enable builds without pci.
> > 
> > Also, to make this more obvious, guard them via a pci_available boolean
> > (which also can be reused in other places).
> > 
> > Fixes: e1d4fb2de ("kvm-irqchip: x86: add msi route notify fn")
> > Fixes: 767a554a0 ("kvm-all: Pass requester ID to MSI routing functions")
> > Reviewed-by: Pierre Morel 
> > Signed-off-by: Cornelia Huck 
> > ---
> >  accel/kvm/kvm-all.c  |  6 +++---
> >  hw/pci/pci-stub.c| 16 +++-
> >  hw/pci/pci.c |  2 ++
> >  include/hw/pci/pci.h |  2 ++
> >  4 files changed, 22 insertions(+), 4 deletions(-)

> > diff --git a/hw/pci/pci-stub.c b/hw/pci/pci-stub.c
> > index ecad664946..2d3b32c6ab 100644
> > --- a/hw/pci/pci-stub.c
> > +++ b/hw/pci/pci-stub.c
> > @@ -23,10 +23,11 @@
> >  #include "monitor/monitor.h"
> >  #include "qapi/qmp/qerror.h"
> >  #include "hw/pci/pci.h"
> > -#include "qmp-commands.h"
> >  #include "hw/pci/msi.h"
> > +#include "qmp-commands.h"  
> 
> Nit: Unnecessary movement of the #include statement.

Seems to have slipped in during the various rebases. Fixed.

> 
> If you fix that:
> 
> Reviewed-by: Thomas Huth 

Thanks!



Re: [Qemu-devel] [PATCH 0/3] iotests: clean up resources using context managers

2017-08-24 Thread Fam Zheng
On Thu, 08/24 08:21, Stefan Hajnoczi wrote:
> Tests should declare resources upfront in a with statement.  Resources are
> automatically cleaned up whether the test passes or fails:
> 
>   with FilePath('test.img') as img_path,
>VM() as vm:
>   ...test...
>   # img_path is deleted and vm is shut down automatically

Looks good but still requires test writers to learn and remember to use FilePath
and with.  These are still boilerplates.  Here goes my personal oppinion, so may
not be plausible:

- For VM() maybe add an atexit in the launch() method also makes sure the VM is
  eventually terminated.

  This means vm.shutdown() is still needed in tearDown() if there are multiple
  test methods and each of them expects a clean state, but that is probably
  still less typing (and also indenting) than the with approach, and also easy
  to remember (otherwise a test will fail).

- For scratch how about adding atexit in iotests.main to clean up everything in
  the scratch directory? The rationale is similar to above.

Fam



Re: [Qemu-devel] [PATCH 0/2] qxl: add support for chunked cursors.

2017-08-24 Thread no-reply
Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20170824081305.8445-1-kra...@redhat.com
Subject: [Qemu-devel] [PATCH 0/2] qxl: add support for chunked cursors.

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
008bbacb9b qxl: add support for chunked cursors.
1b9a2e39e8 qxl: drop mono cursor support

=== OUTPUT BEGIN ===
Checking PATCH 1/2: qxl: drop mono cursor support...
Checking PATCH 2/2: qxl: add support for chunked cursors
ERROR: braces {} are necessary for all arms of this statement
#29: FILE: hw/display/qxl-render.c:218:
+if (offset == size)
[...]

ERROR: braces {} are necessary for all arms of this statement
#32: FILE: hw/display/qxl-render.c:221:
+if (!chunk)
[...]

total: 2 errors, 0 warnings, 51 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@freelists.org

[Qemu-devel] [PATCH 10/16] qapi: Use qapi_enum_parse() in input_type_enum()

2017-08-24 Thread Markus Armbruster
Signed-off-by: Markus Armbruster 
---
 qapi/qapi-visit-core.c | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index ed6d2af..ec83ff6 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -14,6 +14,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/util.h"
 #include "qemu-common.h"
 #include "qapi/qmp/qobject.h"
 #include "qapi/qmp/qerror.h"
@@ -353,7 +354,7 @@ static void input_type_enum(Visitor *v, const char *name, 
int *obj,
 const char *const strings[], Error **errp)
 {
 Error *local_err = NULL;
-int64_t value = 0;
+int64_t value;
 char *enum_str;
 
 visit_type_str(v, name, &enum_str, &local_err);
@@ -362,14 +363,8 @@ static void input_type_enum(Visitor *v, const char *name, 
int *obj,
 return;
 }
 
-while (strings[value] != NULL) {
-if (strcmp(strings[value], enum_str) == 0) {
-break;
-}
-value++;
-}
-
-if (strings[value] == NULL) {
+value = qapi_enum_parse(strings, enum_str, -1, NULL);
+if (value < 0) {
 error_setg(errp, QERR_INVALID_PARAMETER, enum_str);
 g_free(enum_str);
 return;
-- 
2.7.5




[Qemu-devel] [PATCH 08/16] quorum: Use qapi_enum_parse() in quorum_open()

2017-08-24 Thread Markus Armbruster
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Message-Id: <20170822132255.23945-12-marcandre.lur...@redhat.com>
Reviewed-by: Markus Armbruster 
[Rebased, qemu_opt_get() factored out, commit message tweaked]
Cc: Alberto Garcia 
Reviewed-by: Alberto Garcia 
Signed-off-by: Markus Armbruster 
---
 block/quorum.c | 28 +---
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/block/quorum.c b/block/quorum.c
index d04da4f..cb66177 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -22,6 +22,7 @@
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/qlist.h"
 #include "qapi/qmp/qstring.h"
+#include "qapi/util.h"
 #include "qapi-event.h"
 #include "crypto/hash.h"
 
@@ -867,30 +868,13 @@ static QemuOptsList quorum_runtime_opts = {
 },
 };
 
-static int parse_read_pattern(const char *opt)
-{
-int i;
-
-if (!opt) {
-/* Set quorum as default */
-return QUORUM_READ_PATTERN_QUORUM;
-}
-
-for (i = 0; i < QUORUM_READ_PATTERN__MAX; i++) {
-if (!strcmp(opt, QuorumReadPattern_lookup[i])) {
-return i;
-}
-}
-
-return -EINVAL;
-}
-
 static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
 {
 BDRVQuorumState *s = bs->opaque;
 Error *local_err = NULL;
 QemuOpts *opts = NULL;
+const char *pattern_str;
 bool *opened;
 int i;
 int ret = 0;
@@ -925,7 +909,13 @@ static int quorum_open(BlockDriverState *bs, QDict 
*options, int flags,
 goto exit;
 }
 
-ret = parse_read_pattern(qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN));
+pattern_str = qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN);
+if (!pattern_str) {
+ret = QUORUM_READ_PATTERN_QUORUM;
+} else {
+ret = qapi_enum_parse(QuorumReadPattern_lookup, pattern_str,
+  -EINVAL, NULL);
+}
 if (ret < 0) {
 error_setg(&local_err, "Please set read-pattern as fifo or quorum");
 goto exit;
-- 
2.7.5




[Qemu-devel] [PATCH 12/16] qapi: Generate FOO_str() macro for QAPI enum FOO

2017-08-24 Thread Markus Armbruster
The next commit will put it to use.  May look pointless now, but we're
going to change the FOO_lookup's type, and then it'll help.

Signed-off-by: Markus Armbruster 
---
 block.c  | 1 -
 block/blkdebug.c | 1 -
 block/file-posix.c   | 1 -
 block/file-win32.c   | 1 -
 block/gluster.c  | 1 -
 block/parallels.c| 1 -
 block/qcow2.c| 1 -
 block/quorum.c   | 1 -
 blockdev.c   | 1 -
 crypto/block-luks.c  | 1 -
 docs/devel/qapi-code-gen.txt | 3 +++
 hmp.c| 1 -
 include/qapi/util.h  | 1 +
 migration/global_state.c | 1 -
 migration/migration.c| 1 -
 qapi/qapi-util.c | 8 +++-
 qapi/qapi-visit-core.c   | 1 -
 qemu-img.c   | 1 -
 qemu-nbd.c   | 1 -
 scripts/qapi-event.py| 1 +
 scripts/qapi-types.py| 4 
 scripts/qapi.py  | 3 +++
 tests/test-qapi-util.c   | 1 -
 tpm.c| 1 -
 util/keyval.c| 1 -
 25 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/block.c b/block.c
index dd0efa2..2d12131 100644
--- a/block.c
+++ b/block.c
@@ -42,7 +42,6 @@
 #include "qapi-event.h"
 #include "qemu/cutils.h"
 #include "qemu/id.h"
-#include "qapi/util.h"
 
 #ifdef CONFIG_BSD
 #include 
diff --git a/block/blkdebug.c b/block/blkdebug.c
index f1bbee9..b370fce 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -32,7 +32,6 @@
 #include "qapi/qmp/qbool.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
-#include "qapi/util.h"
 #include "sysemu/qtest.h"
 
 typedef struct BDRVBlkdebugState {
diff --git a/block/file-posix.c b/block/file-posix.c
index 97e8a92..d81eccc 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -31,7 +31,6 @@
 #include "block/thread-pool.h"
 #include "qemu/iov.h"
 #include "block/raw-aio.h"
-#include "qapi/util.h"
 #include "qapi/qmp/qstring.h"
 
 #if defined(__APPLE__) && (__MACH__)
diff --git a/block/file-win32.c b/block/file-win32.c
index 978d805..192ea81 100644
--- a/block/file-win32.c
+++ b/block/file-win32.c
@@ -31,7 +31,6 @@
 #include "block/thread-pool.h"
 #include "qemu/iov.h"
 #include "qapi/qmp/qstring.h"
-#include "qapi/util.h"
 #include 
 #include 
 
diff --git a/block/gluster.c b/block/gluster.c
index 8367e80..0614e0c 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -12,7 +12,6 @@
 #include "block/block_int.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qerror.h"
-#include "qapi/util.h"
 #include "qemu/uri.h"
 #include "qemu/error-report.h"
 #include "qemu/cutils.h"
diff --git a/block/parallels.c b/block/parallels.c
index eb92366..d812210 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -35,7 +35,6 @@
 #include "qemu/module.h"
 #include "qemu/bswap.h"
 #include "qemu/bitmap.h"
-#include "qapi/util.h"
 
 /**/
 
diff --git a/block/qcow2.c b/block/qcow2.c
index 7aaf248..41e067e 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -30,7 +30,6 @@
 #include "qemu/error-report.h"
 #include "qapi/qmp/qerror.h"
 #include "qapi/qmp/qbool.h"
-#include "qapi/util.h"
 #include "qapi/qmp/types.h"
 #include "qapi-event.h"
 #include "trace.h"
diff --git a/block/quorum.c b/block/quorum.c
index cb66177..8d1c9f6 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -22,7 +22,6 @@
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/qlist.h"
 #include "qapi/qmp/qstring.h"
-#include "qapi/util.h"
 #include "qapi-event.h"
 #include "crypto/hash.h"
 
diff --git a/blockdev.c b/blockdev.c
index 722a61e..f90bc93 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -44,7 +44,6 @@
 #include "qapi-visit.h"
 #include "qapi/qmp/qerror.h"
 #include "qapi/qobject-output-visitor.h"
-#include "qapi/util.h"
 #include "sysemu/sysemu.h"
 #include "block/block_int.h"
 #include "qmp-commands.h"
diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index c3cacdb..84d189a 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -20,7 +20,6 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "qapi/util.h"
 #include "qemu/bswap.h"
 
 #include "crypto/block-luks.h"
diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index ae05327..f04c63f 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -1275,6 +1275,9 @@ Example:
 EXAMPLE_QAPI_EVENT__MAX = 1,
 } example_QAPIEvent;
 
+#define example_QAPIEvent_str(val) \
+qapi_enum_lookup(example_QAPIEvent_lookup, (val))
+
 extern const char *const example_QAPIEvent_lookup[];
 
 #endif
diff --git a/hmp.c b/hmp.c
index 2b6e919..5d980ac 100644
--- a/hmp.c
+++ b/hmp.c
@@ -31,7 +31,6 @@
 #include "qapi/qmp/qerror.h"
 #include "qapi/string-input-visitor.h"
 #include "qapi/string-output-visitor.h"
-#include "qapi/util.h"
 #include "qapi-visit.h"
 #include "qom/object_interfaces.h"
 #include "ui/console.h"
diff --git a/include/qapi/util.h b/include

[Qemu-devel] [PATCH 00/16] qapi: Rework mapping of enum value to string

2017-08-24 Thread Markus Armbruster
The purpose of this work is to make holes in QAPI enumerations
possible.

Why holes?  Because we want to be able to suppress enumeration
constants with #if.  Holes could be avoided, e.g. by letting the
compiler assign the values.  Falls apart when the conditions are
target-specific, because then target-specific code would get different
values.

Why are holes a problem?  The tables mapping enumeration constants to
strings use a NULL sentinel.

This is PATCH 06-13 of "[PATCH v2 00/54] qapi: add #if pre-processor
conditions to generated code" reworked for reviewability.  Took a bit
of time, but it was probably less work and certainly more fun than
reviewing the old PATCH 06 and 12 (almost 300 hunks!) in sufficient
depth would have been.

* PATCH 01: New, included only so I can update qapi-code-gen.txt
  sanely in PATCH 12
* PATCH 02: New, factored out of old PATCH 12 (sort of)
* PATCH 03: Old PATCH 07 rebased, superfluous initializer dropped,
  commit message rewritten
* PATCH 04: New, to finish PATCH 03's cleanup job
* PATCH 05: Old PATCH 08 rebased, commit message rewritten
* PATCH 06: Old PATCH 09 rebased, assertion added, commit message
  rewritten
* PATCH 07: Old PATCH 10 rebased, commit message rewritten
* PATCH 08: Old PATCH 11 rebased, qemu_opt_get() factored out, commit
  message tweaked
* PATCH 09: New, factored out of old PATCH 12
* PATCH 10: New, to complete PATCH 03-09
* PATCH 11: New, to make these loops cope with holes
* PATCH 12: New, split off old PATCH 06, with macros spliced in
* PATCH 13: New, replacing parts of old PATCH 06
* PATCH 14: New, replacing parts of old PATCH 06
* PATCH 15: Old PATCH 12 basically redone
* PATCH 16: Old PATCH 13 rebased, superfluous local variable dropped,
  missing check-qom-proplist.c update added

Not included: old PATCH 12's change to make output_type_enum() fail on
"hole".  I think this is best done together with the patches that
punch holes, so it can be tested.

Old diffstat:
 68 files changed, 425 insertions(+), 396 deletions(-)
New diffstat:
 71 files changed, 410 insertions(+), 463 deletions(-)

Marc-André Lureau (7):
  tpm: Clean up driver registration & lookup
  hmp: Use qapi_enum_parse() in hmp_migrate_set_capability()
  hmp: Use qapi_enum_parse() in hmp_migrate_set_parameter()
  block: Use qemu_enum_parse() in blkdebug_debug_breakpoint()
  quorum: Use qapi_enum_parse() in quorum_open()
  qapi: Change data type of the FOO_lookup generated for enum FOO
  qapi: drop the sentinel in enum array

Markus Armbruster (9):
  qapi: Update qapi-code-gen.txt examples to match current code
  qapi: Drop superfluous qapi_enum_parse() parameter max
  tpm: Clean up model registration & lookup
  crypto: Use qapi_enum_parse() in qcrypto_block_luks_name_lookup()
  qapi: Use qapi_enum_parse() in input_type_enum()
  qapi: Avoid unnecessary use of enum lookup table's sentinel
  qapi: Generate FOO_str() macro for QAPI enum FOO
  qapi: Mechanically convert FOO_lookup[...] to FOO_str(...)
  qapi: Convert indirect uses of FOO_lookup[...] to qapi_enum_lookup()

 backends/hostmem.c  |   4 +-
 block.c |   4 +-
 block/backup.c  |   2 +-
 block/blkdebug.c|  27 ++---
 block/file-posix.c  |  20 ++--
 block/file-win32.c  |   5 +-
 block/gluster.c |  11 +-
 block/iscsi.c   |   2 +-
 block/nfs.c |   2 +-
 block/parallels.c   |  17 +--
 block/qcow2.c   |  15 +--
 block/qed.c |   2 +-
 block/quorum.c  |  27 ++---
 block/rbd.c |   2 +-
 block/sheepdog.c|   2 +-
 blockdev.c  |   8 +-
 blockjob.c  |   6 +-
 chardev/char.c  |   4 +-
 crypto/block-luks.c |  38 +++
 crypto/block.c  |   4 +-
 crypto/cipher-afalg.c   |   2 +-
 crypto/cipher-builtin.c |   8 +-
 crypto/cipher-gcrypt.c  |   4 +-
 crypto/cipher-nettle.c  |   8 +-
 crypto/hmac-gcrypt.c|   2 +-
 crypto/hmac-glib.c  |   2 +-
 crypto/hmac-nettle.c|   2 +-
 crypto/pbkdf-gcrypt.c   |   2 +-
 crypto/pbkdf-nettle.c   |   2 +-
 crypto/secret.c |   2 +-
 crypto/tlscreds.c   |   2 +-
 docs/devel/qapi-code-gen.txt|  50 ++--
 hmp.c   | 220 ++--
 hw/block/fdc.c  |   6 +-
 hw/char/escc.c  |   2 +-
 hw/core/qdev-properties.c   |  17 +--
 hw/input/virtio-input-hid.c |   4 +-
 include/hw/qdev-core.h  |   2 +-
 include/qapi/util.h |  10 +-
 include/qapi/visitor.h  |   2 +-
 include/qom/object.h|   4 +-
 include/sys

[Qemu-devel] [PATCH 04/16] tpm: Clean up model registration & lookup

2017-08-24 Thread Markus Armbruster
We have a strict separation between enum TpmModel and tpm_models[]:

* TpmModel may have any number of members.  It just happens to have one.

* tpm_register_model() uses the first empty slot in tmp_models[].

  If you register more than tpm_models[] has space,
  tpn_register_model() fails.  Its caller silently ignores the
  failure.

  Register the same TpmModel more than once has no effect other than
  wasting tpm_models[] slots: tpm_model_is_registered() is happy with
  the first one it finds.

Since we only ever register one model, and tpm_models[] has space for
just that one, this contraption even works.

Turn tpm_models[] into a straight map from enum TpmType to bool.  Much
simpler.

Cc: Stefan Berger 
Signed-off-by: Markus Armbruster 
---
 include/sysemu/tpm_backend.h |  2 +-
 tpm.c| 37 +
 2 files changed, 6 insertions(+), 33 deletions(-)

diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
index 1d21c6b..b0a9731 100644
--- a/include/sysemu/tpm_backend.h
+++ b/include/sysemu/tpm_backend.h
@@ -226,7 +226,7 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);
 TPMBackend *qemu_find_tpm(const char *id);
 
 const TPMDriverOps *tpm_get_backend_driver(const char *type);
-int tpm_register_model(enum TpmModel model);
+void tpm_register_model(enum TpmModel model);
 void tpm_register_driver(const TPMDriverOps *tdo);
 
 #endif
diff --git a/tpm.c b/tpm.c
index 6f39ec9..7635fc7 100644
--- a/tpm.c
+++ b/tpm.c
@@ -24,39 +24,12 @@
 static QLIST_HEAD(, TPMBackend) tpm_backends =
 QLIST_HEAD_INITIALIZER(tpm_backends);
 
-
-#define TPM_MAX_MODELS  1
-
 static TPMDriverOps const *be_drivers[TPM_TYPE__MAX];
+static bool tpm_models[TPM_MODEL__MAX];
 
-static enum TpmModel tpm_models[TPM_MAX_MODELS] = {
-TPM_MODEL__MAX,
-};
-
-int tpm_register_model(enum TpmModel model)
+void tpm_register_model(enum TpmModel model)
 {
-int i;
-
-for (i = 0; i < TPM_MAX_MODELS; i++) {
-if (tpm_models[i] == TPM_MODEL__MAX) {
-tpm_models[i] = model;
-return 0;
-}
-}
-error_report("Could not register TPM model");
-return 1;
-}
-
-static bool tpm_model_is_registered(enum TpmModel model)
-{
-int i;
-
-for (i = 0; i < TPM_MAX_MODELS; i++) {
-if (tpm_models[i] == model) {
-return true;
-}
-}
-return false;
+tpm_models[model] = true;
 }
 
 const TPMDriverOps *tpm_get_backend_driver(const char *type)
@@ -270,7 +243,7 @@ TPMInfoList *qmp_query_tpm(Error **errp)
 TPMInfoList *info, *head = NULL, *cur_item = NULL;
 
 QLIST_FOREACH(drv, &tpm_backends, list) {
-if (!tpm_model_is_registered(drv->fe_model)) {
+if (!tpm_models[drv->fe_model]) {
 continue;
 }
 info = g_new0(TPMInfoList, 1);
@@ -317,7 +290,7 @@ TpmModelList *qmp_query_tpm_models(Error **errp)
 TpmModelList *head = NULL, *prev = NULL, *cur_item;
 
 for (i = 0; i < TPM_MODEL__MAX; i++) {
-if (!tpm_model_is_registered(i)) {
+if (!tpm_models[i]) {
 continue;
 }
 cur_item = g_new0(TpmModelList, 1);
-- 
2.7.5




[Qemu-devel] [PATCH 11/16] qapi: Avoid unnecessary use of enum lookup table's sentinel

2017-08-24 Thread Markus Armbruster
Currently, the FOO_lookup[] generated for QAPI enum types are
terminated by a NULL sentinel.

A future patch will generate enums with "holes".  NULL-termination
will cease to work then.

To prepare for that, replace "have we reached the sentinel?"
predicates by "have we reached the FOO__MAX value?" predicates.

Signed-off-by: Markus Armbruster 
---
 monitor.c  | 4 ++--
 tests/test-qobject-input-visitor.c | 2 +-
 tests/test-string-input-visitor.c  | 2 +-
 ui/input-legacy.c  | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/monitor.c b/monitor.c
index e0f8801..b45f55d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3249,7 +3249,7 @@ void netdev_add_completion(ReadLineState *rs, int 
nb_args, const char *str)
 }
 len = strlen(str);
 readline_set_completion_index(rs, len);
-for (i = 0; NetClientDriver_lookup[i]; i++) {
+for (i = 0; i < NET_CLIENT_DRIVER__MAX; i++) {
 add_completion_option(rs, str, NetClientDriver_lookup[i]);
 }
 }
@@ -3537,7 +3537,7 @@ void watchdog_action_completion(ReadLineState *rs, int 
nb_args, const char *str)
 return;
 }
 readline_set_completion_index(rs, strlen(str));
-for (i = 0; WatchdogExpirationAction_lookup[i]; i++) {
+for (i = 0; i < WATCHDOG_EXPIRATION_ACTION__MAX; i++) {
 add_completion_option(rs, str, WatchdogExpirationAction_lookup[i]);
 }
 }
diff --git a/tests/test-qobject-input-visitor.c 
b/tests/test-qobject-input-visitor.c
index bcf0261..5bbfb65 100644
--- a/tests/test-qobject-input-visitor.c
+++ b/tests/test-qobject-input-visitor.c
@@ -382,7 +382,7 @@ static void test_visitor_in_enum(TestInputVisitorData *data,
 Visitor *v;
 EnumOne i;
 
-for (i = 0; EnumOne_lookup[i]; i++) {
+for (i = 0; i < ENUM_ONE__MAX; i++) {
 EnumOne res = -1;
 
 v = visitor_input_test_init(data, "%s", EnumOne_lookup[i]);
diff --git a/tests/test-string-input-visitor.c 
b/tests/test-string-input-visitor.c
index 79313a7..e7a7b80 100644
--- a/tests/test-string-input-visitor.c
+++ b/tests/test-string-input-visitor.c
@@ -279,7 +279,7 @@ static void test_visitor_in_enum(TestInputVisitorData *data,
 Visitor *v;
 EnumOne i;
 
-for (i = 0; EnumOne_lookup[i]; i++) {
+for (i = 0; i < ENUM_ONE__MAX; i++) {
 EnumOne res = -1;
 
 v = visitor_input_test_init(data, EnumOne_lookup[i]);
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 7159747..a5f1e82 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -61,7 +61,7 @@ int index_from_key(const char *key, size_t key_length)
 {
 int i;
 
-for (i = 0; QKeyCode_lookup[i] != NULL; i++) {
+for (i = 0; i < Q_KEY_CODE__MAX; i++) {
 if (!strncmp(key, QKeyCode_lookup[i], key_length) &&
 !QKeyCode_lookup[i][key_length]) {
 break;
-- 
2.7.5




[Qemu-devel] [PATCH 03/16] tpm: Clean up driver registration & lookup

2017-08-24 Thread Markus Armbruster
From: Marc-André Lureau 

We have a strict separation between enum TpmType and be_drivers[]:

* TpmType may have any number of members.  It just happens to have one.

* tpm_register_driver() uses the first empty slot in be_drivers[].

  If you register more than tpm_models[] has space,
  tpm_register_driver() fails.  Its caller silently ignores the
  failure.

  If you register more than one with a given TpmType,
  tpm_display_backend_drivers() will shows all of them, but
  tpm_driver_find_by_type() and tpm_get_backend_driver() will find
  only the one one that registered first.

Since we only ever register one driver, and be_drivers[] has space for
just that one, this contraption even works.

Turn be_drivers[] into a straight map from enum TpmType to driver.
Much simpler, and has a decent chance to actually work should we ever
acquire additional drivers.

While there, use qapi_enum_parse() in tpm_get_backend_driver().

Signed-off-by: Marc-André Lureau 
Message-Id: <20170822132255.23945-8-marcandre.lur...@redhat.com>
Reviewed-by: Markus Armbruster 
[Rebased, superfluous initializer dropped, commit message rewritten]
Cc: Stefan Berger 
Signed-off-by: Markus Armbruster 
---
 include/sysemu/tpm_backend.h |  2 +-
 tpm.c| 45 +---
 2 files changed, 14 insertions(+), 33 deletions(-)

diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
index b58f52d..1d21c6b 100644
--- a/include/sysemu/tpm_backend.h
+++ b/include/sysemu/tpm_backend.h
@@ -227,6 +227,6 @@ TPMBackend *qemu_find_tpm(const char *id);
 
 const TPMDriverOps *tpm_get_backend_driver(const char *type);
 int tpm_register_model(enum TpmModel model);
-int tpm_register_driver(const TPMDriverOps *tdo);
+void tpm_register_driver(const TPMDriverOps *tdo);
 
 #endif
diff --git a/tpm.c b/tpm.c
index 9a7c711..6f39ec9 100644
--- a/tpm.c
+++ b/tpm.c
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 
 #include "qapi/qmp/qerror.h"
+#include "qapi/util.h"
 #include "sysemu/tpm_backend.h"
 #include "sysemu/tpm.h"
 #include "qemu/config-file.h"
@@ -25,11 +26,8 @@ static QLIST_HEAD(, TPMBackend) tpm_backends =
 
 
 #define TPM_MAX_MODELS  1
-#define TPM_MAX_DRIVERS 1
 
-static TPMDriverOps const *be_drivers[TPM_MAX_DRIVERS] = {
-NULL,
-};
+static TPMDriverOps const *be_drivers[TPM_TYPE__MAX];
 
 static enum TpmModel tpm_models[TPM_MAX_MODELS] = {
 TPM_MODEL__MAX,
@@ -63,31 +61,18 @@ static bool tpm_model_is_registered(enum TpmModel model)
 
 const TPMDriverOps *tpm_get_backend_driver(const char *type)
 {
-int i;
+int i = qapi_enum_parse(TpmType_lookup, type, -1, NULL);
 
-for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) {
-if (!strcmp(TpmType_lookup[be_drivers[i]->type], type)) {
-return be_drivers[i];
-}
-}
-
-return NULL;
+return i >= 0 ? be_drivers[i] : NULL;
 }
 
 #ifdef CONFIG_TPM
 
-int tpm_register_driver(const TPMDriverOps *tdo)
+void tpm_register_driver(const TPMDriverOps *tdo)
 {
-int i;
+assert(!be_drivers[tdo->type]);
 
-for (i = 0; i < TPM_MAX_DRIVERS; i++) {
-if (!be_drivers[i]) {
-be_drivers[i] = tdo;
-return 0;
-}
-}
-error_report("Could not register TPM driver");
-return 1;
+be_drivers[tdo->type] = tdo;
 }
 
 /*
@@ -100,9 +85,12 @@ static void tpm_display_backend_drivers(void)
 
 fprintf(stderr, "Supported TPM types (choose only one):\n");
 
-for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) {
+for (i = 0; i < TPM_TYPE__MAX; i++) {
+if (be_drivers[i] == NULL) {
+continue;
+}
 fprintf(stderr, "%12s   %s\n",
-TpmType_lookup[be_drivers[i]->type], be_drivers[i]->desc());
+TpmType_lookup[i], be_drivers[i]->desc());
 }
 fprintf(stderr, "\n");
 }
@@ -239,14 +227,7 @@ int tpm_config_parse(QemuOptsList *opts_list, const char 
*optarg)
 
 static const TPMDriverOps *tpm_driver_find_by_type(enum TpmType type)
 {
-int i;
-
-for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) {
-if (be_drivers[i]->type == type) {
-return be_drivers[i];
-}
-}
-return NULL;
+return be_drivers[type];
 }
 
 static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv)
-- 
2.7.5




[Qemu-devel] [PATCH 07/16] block: Use qemu_enum_parse() in blkdebug_debug_breakpoint()

2017-08-24 Thread Markus Armbruster
From: Marc-André Lureau 

The error message on invalid blkdebug events changes from

qemu-system-x86_64: LOCATION: Invalid event name "VALUE"

to

qemu-system-x86_64: LOCATION: invalid parameter value: VALUE

Slight degradation, but the message is sub-par even before the patch.
When complaining about a parameter value, both parameter name and
value should be mentioned, as the value may well not be unique.  Left
for another day.

Also left is the error message's unhelpful location: it points to the
config=FILENAME rather than into that file.

Signed-off-by: Marc-André Lureau 
Message-Id: <20170822132255.23945-11-marcandre.lur...@redhat.com>
Reviewed-by: Markus Armbruster 
[Rebased, commit message rewritten]
Cc: Kevin Wolf 
Cc: Max Reitz 
Cc: qemu-bl...@nongnu.org
Signed-off-by: Markus Armbruster 
---
 block/blkdebug.c | 28 
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/block/blkdebug.c b/block/blkdebug.c
index c19ab28..f1bbee9 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -32,6 +32,7 @@
 #include "qapi/qmp/qbool.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
+#include "qapi/util.h"
 #include "sysemu/qtest.h"
 
 typedef struct BDRVBlkdebugState {
@@ -149,20 +150,6 @@ static QemuOptsList *config_groups[] = {
 NULL
 };
 
-static int get_event_by_name(const char *name, BlkdebugEvent *event)
-{
-int i;
-
-for (i = 0; i < BLKDBG__MAX; i++) {
-if (!strcmp(BlkdebugEvent_lookup[i], name)) {
-*event = i;
-return 0;
-}
-}
-
-return -1;
-}
-
 struct add_rule_data {
 BDRVBlkdebugState *s;
 int action;
@@ -173,7 +160,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error 
**errp)
 struct add_rule_data *d = opaque;
 BDRVBlkdebugState *s = d->s;
 const char* event_name;
-BlkdebugEvent event;
+int event;
 struct BlkdebugRule *rule;
 int64_t sector;
 
@@ -182,8 +169,9 @@ static int add_rule(void *opaque, QemuOpts *opts, Error 
**errp)
 if (!event_name) {
 error_setg(errp, "Missing event name for rule");
 return -1;
-} else if (get_event_by_name(event_name, &event) < 0) {
-error_setg(errp, "Invalid event name \"%s\"", event_name);
+}
+event = qapi_enum_parse(BlkdebugEvent_lookup, event_name, -1, errp);
+if (event < 0) {
 return -1;
 }
 
@@ -743,13 +731,13 @@ static int blkdebug_debug_breakpoint(BlockDriverState 
*bs, const char *event,
 {
 BDRVBlkdebugState *s = bs->opaque;
 struct BlkdebugRule *rule;
-BlkdebugEvent blkdebug_event;
+int blkdebug_event;
 
-if (get_event_by_name(event, &blkdebug_event) < 0) {
+blkdebug_event = qapi_enum_parse(BlkdebugEvent_lookup, event, -1, NULL);
+if (blkdebug_event < 0) {
 return -ENOENT;
 }
 
-
 rule = g_malloc(sizeof(*rule));
 *rule = (struct BlkdebugRule) {
 .event  = blkdebug_event,
-- 
2.7.5




[Qemu-devel] [PATCH 16/16] qapi: drop the sentinel in enum array

2017-08-24 Thread Markus Armbruster
From: Marc-André Lureau 

Now that all usages have been converted to user lookup helpers.

Signed-off-by: Marc-André Lureau 
Message-Id: <20170822132255.23945-14-marcandre.lur...@redhat.com>
[Rebased, superfluous local variable dropped, missing
check-qom-proplist.c update added]
Signed-off-by: Markus Armbruster 
---
 block/parallels.c  | 1 -
 scripts/qapi.py| 4 +---
 tests/check-qom-proplist.c | 1 -
 3 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/block/parallels.c b/block/parallels.c
index cce7336..2b6c6e5 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -72,7 +72,6 @@ static QEnumLookup prealloc_mode_lookup = {
 .array = (const char *const[]) {
 "falloc",
 "truncate",
-NULL,
 },
 .size = PRL_PREALLOC_MODE__MAX
 };
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 61be538..a0993ee 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1860,14 +1860,12 @@ const QEnumLookup %(c_name)s_lookup = {
 ''',
  index=index, value=value)
 
-max_index = c_enum_const(name, '_MAX', prefix)
 ret += mcgen('''
-[%(max_index)s] = NULL,
 },
 .size = %(max_index)s
 };
 ''',
- max_index=max_index)
+ max_index=c_enum_const(name, '_MAX', prefix))
 return ret
 
 
diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
index 07e351f..92898e1 100644
--- a/tests/check-qom-proplist.c
+++ b/tests/check-qom-proplist.c
@@ -51,7 +51,6 @@ const QEnumLookup dummy_animal_map = {
 [DUMMY_FROG] = "frog",
 [DUMMY_ALLIGATOR] = "alligator",
 [DUMMY_PLATYPUS] = "platypus",
-[DUMMY_LAST] = NULL,
 },
 .size = DUMMY_LAST
 };
-- 
2.7.5




[Qemu-devel] [PATCH 09/16] crypto: Use qapi_enum_parse() in qcrypto_block_luks_name_lookup()

2017-08-24 Thread Markus Armbruster
Cc: "Daniel P. Berrange" 
Signed-off-by: Markus Armbruster 
---
 crypto/block-luks.c | 19 +++
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index afb8543..c3cacdb 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -20,6 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/util.h"
 #include "qemu/bswap.h"
 
 #include "crypto/block-luks.h"
@@ -265,39 +266,33 @@ 
qcrypto_block_luks_cipher_alg_lookup(QCryptoCipherAlgorithm alg,
  * make that function emit a more friendly error message */
 static int qcrypto_block_luks_name_lookup(const char *name,
   const char *const *map,
-  size_t maplen,
   const char *type,
   Error **errp)
 {
-size_t i;
-for (i = 0; i < maplen; i++) {
-if (g_str_equal(map[i], name)) {
-return i;
-}
-}
+int ret = qapi_enum_parse(map, name, -1, NULL);
 
-error_setg(errp, "%s %s not supported", type, name);
-return 0;
+if (ret < 0) {
+error_setg(errp, "%s %s not supported", type, name);
+return 0;
+}
+return ret;
 }
 
 #define qcrypto_block_luks_cipher_mode_lookup(name, errp)   \
 qcrypto_block_luks_name_lookup(name,\
QCryptoCipherMode_lookup,\
-   QCRYPTO_CIPHER_MODE__MAX,\
"Cipher mode",   \
errp)
 
 #define qcrypto_block_luks_hash_name_lookup(name, errp) \
 qcrypto_block_luks_name_lookup(name,\
QCryptoHashAlgorithm_lookup, \
-   QCRYPTO_HASH_ALG__MAX,   \
"Hash algorithm",\
errp)
 
 #define qcrypto_block_luks_ivgen_name_lookup(name, errp)\
 qcrypto_block_luks_name_lookup(name,\
QCryptoIVGenAlgorithm_lookup,\
-   QCRYPTO_IVGEN_ALG__MAX,  \
"IV generator",  \
errp)
 
-- 
2.7.5




[Qemu-devel] [PATCH 14/16] qapi: Convert indirect uses of FOO_lookup[...] to qapi_enum_lookup()

2017-08-24 Thread Markus Armbruster
Signed-off-by: Markus Armbruster 
---
 hw/core/qdev-properties.c | 7 +--
 qapi/qapi-visit-core.c| 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 078fc5d..7512bd4 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -72,7 +72,9 @@ static void set_enum(Object *obj, Visitor *v, const char 
*name, void *opaque,
 
 static void set_default_value_enum(Object *obj, const Property *prop)
 {
-object_property_set_str(obj, prop->info->enum_table[prop->defval.i],
+object_property_set_str(obj,
+qapi_enum_lookup(prop->info->enum_table,
+ prop->defval.i),
 prop->name, &error_abort);
 }
 
@@ -1095,7 +1097,8 @@ void qdev_prop_set_enum(DeviceState *dev, const char 
*name, int value)
 Property *prop;
 
 prop = qdev_prop_find(dev, name);
-object_property_set_str(OBJECT(dev), prop->info->enum_table[value],
+object_property_set_str(OBJECT(dev),
+qapi_enum_lookup(prop->info->enum_table, value),
 name, &error_abort);
 }
 
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index f285879..30dc85b 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -345,7 +345,7 @@ static void output_type_enum(Visitor *v, const char *name, 
int *obj,
 return;
 }
 
-enum_str = (char *)strings[value];
+enum_str = (char *)qapi_enum_lookup(strings, value);
 visit_type_str(v, name, &enum_str, errp);
 }
 
-- 
2.7.5




[Qemu-devel] [PATCH 01/16] qapi: Update qapi-code-gen.txt examples to match current code

2017-08-24 Thread Markus Armbruster
Signed-off-by: Markus Armbruster 
---
 docs/devel/qapi-code-gen.txt | 47 +++-
 1 file changed, 38 insertions(+), 9 deletions(-)

diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index 9903ac4..ae05327 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -957,6 +957,8 @@ Example:
 
 typedef struct UserDefOneList UserDefOneList;
 
+typedef struct q_obj_my_command_arg q_obj_my_command_arg;
+
 struct UserDefOne {
 int64_t integer;
 bool has_string;
@@ -972,6 +974,10 @@ Example:
 
 void qapi_free_UserDefOneList(UserDefOneList *obj);
 
+struct q_obj_my_command_arg {
+UserDefOneList *arg1;
+};
+
 #endif
 $ cat qapi-generated/example-qapi-types.c
 [Uninteresting stuff omitted...]
@@ -1036,6 +1042,8 @@ Example:
 void visit_type_UserDefOne(Visitor *v, const char *name, UserDefOne **obj, 
Error **errp);
 void visit_type_UserDefOneList(Visitor *v, const char *name, 
UserDefOneList **obj, Error **errp);
 
+void visit_type_q_obj_my_command_arg_members(Visitor *v, 
q_obj_my_command_arg *obj, Error **errp);
+
 #endif
 $ cat qapi-generated/example-qapi-visit.c
 [Uninteresting stuff omitted...]
@@ -1104,6 +1112,9 @@ Example:
 }
 }
 
+if (!err) {
+visit_check_list(v, &err);
+}
 visit_end_list(v, (void **)obj);
 if (err && visit_is_input(v)) {
 qapi_free_UserDefOneList(*obj);
@@ -1113,6 +1124,19 @@ Example:
 error_propagate(errp, err);
 }
 
+void visit_type_q_obj_my_command_arg_members(Visitor *v, 
q_obj_my_command_arg *obj, Error **errp)
+{
+Error *err = NULL;
+
+visit_type_UserDefOneList(v, "arg1", &obj->arg1, &err);
+if (err) {
+goto out;
+}
+
+out:
+error_propagate(errp, err);
+}
+
 === scripts/qapi-commands.py ===
 
 Used to generate the marshaling/dispatch functions for the commands
@@ -1145,9 +1169,12 @@ Example:
 
 #include "example-qapi-types.h"
 #include "qapi/qmp/qdict.h"
+#include "qapi/qmp/dispatch.h"
 #include "qapi/error.h"
 
+void example_qmp_init_marshal(QmpCommandList *cmds);
 UserDefOne *qmp_my_command(UserDefOneList *arg1, Error **errp);
+void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp);
 
 #endif
 $ cat qapi-generated/example-qmp-marshal.c
@@ -1170,19 +1197,19 @@ Example:
 visit_free(v);
 }
 
-static void qmp_marshal_my_command(QDict *args, QObject **ret, Error 
**errp)
+void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp)
 {
 Error *err = NULL;
 UserDefOne *retval;
 Visitor *v;
-UserDefOneList *arg1 = NULL;
+q_obj_my_command_arg arg = {0};
 
 v = qobject_input_visitor_new(QOBJECT(args));
 visit_start_struct(v, NULL, NULL, 0, &err);
 if (err) {
 goto out;
 }
-visit_type_UserDefOneList(v, "arg1", &arg1, &err);
+visit_type_q_obj_my_command_arg_members(v, &arg, &err);
 if (!err) {
 visit_check_struct(v, &err);
 }
@@ -1191,7 +1218,7 @@ Example:
 goto out;
 }
 
-retval = qmp_my_command(arg1, &err);
+retval = qmp_my_command(arg.arg1, &err);
 if (err) {
 goto out;
 }
@@ -1203,17 +1230,18 @@ Example:
 visit_free(v);
 v = qapi_dealloc_visitor_new();
 visit_start_struct(v, NULL, NULL, 0, NULL);
-visit_type_UserDefOneList(v, "arg1", &arg1, NULL);
+visit_type_q_obj_my_command_arg_members(v, &arg, NULL);
 visit_end_struct(v, NULL);
 visit_free(v);
 }
 
-static void qmp_init_marshal(void)
+void example_qmp_init_marshal(QmpCommandList *cmds)
 {
-qmp_register_command("my-command", qmp_marshal_my_command, 
QCO_NO_OPTIONS);
-}
+QTAILQ_INIT(cmds);
 
-qapi_init(qmp_init_marshal);
+qmp_register_command(cmds, "my-command",
+ qmp_marshal_my_command, QCO_NO_OPTIONS);
+}
 
 === scripts/qapi-event.py ===
 
@@ -1258,6 +1286,7 @@ Example:
 QDict *qmp;
 Error *err = NULL;
 QMPEventFuncEmit emit;
+
 emit = qmp_event_get_func_emit();
 if (!emit) {
 return;
-- 
2.7.5




[Qemu-devel] [PATCH 02/16] qapi: Drop superfluous qapi_enum_parse() parameter max

2017-08-24 Thread Markus Armbruster
The lookup tables have a sentinel, no need to make callers pass their
size.

Fun: the header has it in the wrong position.  Good riddance.

Signed-off-by: Markus Armbruster 
---
 block.c  |  1 -
 block/file-posix.c   |  7 +++
 block/file-win32.c   |  2 +-
 block/gluster.c  |  6 ++
 block/parallels.c|  3 ++-
 block/qcow2.c|  6 ++
 blockdev.c   |  1 -
 hmp.c|  2 +-
 include/qapi/util.h  |  2 +-
 migration/global_state.c |  3 +--
 qapi/qapi-util.c |  4 ++--
 qemu-img.c   |  3 +--
 qemu-nbd.c   |  1 -
 tests/test-qapi-util.c   | 15 +--
 14 files changed, 21 insertions(+), 35 deletions(-)

diff --git a/block.c b/block.c
index 3615a68..dd0efa2 100644
--- a/block.c
+++ b/block.c
@@ -1335,7 +1335,6 @@ static int bdrv_open_common(BlockDriverState *bs, 
BlockBackend *file,
 BlockdevDetectZeroesOptions value =
 qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
 detect_zeroes,
-BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX,
 BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
 &local_err);
 if (local_err) {
diff --git a/block/file-posix.c b/block/file-posix.c
index cb3bfce..97e8a92 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -439,7 +439,7 @@ static int raw_open_common(BlockDriverState *bs, QDict 
*options,
   ? BLOCKDEV_AIO_OPTIONS_NATIVE
   : BLOCKDEV_AIO_OPTIONS_THREADS;
 aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"),
-  BLOCKDEV_AIO_OPTIONS__MAX, aio_default, &local_err);
+  aio_default, &local_err);
 if (local_err) {
 error_propagate(errp, local_err);
 ret = -EINVAL;
@@ -448,7 +448,7 @@ static int raw_open_common(BlockDriverState *bs, QDict 
*options,
 s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE);
 
 locking = qapi_enum_parse(OnOffAuto_lookup, qemu_opt_get(opts, "locking"),
-  ON_OFF_AUTO__MAX, ON_OFF_AUTO_AUTO, &local_err);
+  ON_OFF_AUTO_AUTO, &local_err);
 if (local_err) {
 error_propagate(errp, local_err);
 ret = -EINVAL;
@@ -1975,8 +1975,7 @@ static int raw_create(const char *filename, QemuOpts 
*opts, Error **errp)
 nocow = qemu_opt_get_bool(opts, BLOCK_OPT_NOCOW, false);
 buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
 prealloc = qapi_enum_parse(PreallocMode_lookup, buf,
-   PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,
-   &local_err);
+   PREALLOC_MODE_OFF, &local_err);
 g_free(buf);
 if (local_err) {
 error_propagate(errp, local_err);
diff --git a/block/file-win32.c b/block/file-win32.c
index 4706335..978d805 100644
--- a/block/file-win32.c
+++ b/block/file-win32.c
@@ -304,7 +304,7 @@ static bool get_aio_option(QemuOpts *opts, int flags, Error 
**errp)
 aio_default = (flags & BDRV_O_NATIVE_AIO) ? BLOCKDEV_AIO_OPTIONS_NATIVE
   : BLOCKDEV_AIO_OPTIONS_THREADS;
 aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"),
-  BLOCKDEV_AIO_OPTIONS__MAX, aio_default, errp);
+  aio_default, errp);
 
 switch (aio) {
 case BLOCKDEV_AIO_OPTIONS_NATIVE:
diff --git a/block/gluster.c b/block/gluster.c
index 3064a45..8367e80 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -544,8 +544,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster 
*gconf,
 if (!strcmp(ptr, "tcp")) {
 ptr = "inet";   /* accept legacy "tcp" */
 }
-type = qapi_enum_parse(SocketAddressType_lookup, ptr,
-   SOCKET_ADDRESS_TYPE__MAX, -1, NULL);
+type = qapi_enum_parse(SocketAddressType_lookup, ptr, -1, NULL);
 if (type != SOCKET_ADDRESS_TYPE_INET
 && type != SOCKET_ADDRESS_TYPE_UNIX) {
 error_setg(&local_err,
@@ -1002,8 +1001,7 @@ static int qemu_gluster_create(const char *filename,
   BDRV_SECTOR_SIZE);
 
 tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
-prealloc = qapi_enum_parse(PreallocMode_lookup, tmp,
-   PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,
+prealloc = qapi_enum_parse(PreallocMode_lookup, tmp, PREALLOC_MODE_OFF,
&local_err);
 g_free(tmp);
 if (local_err) {
diff --git a/block/parallels.c b/block/parallels.c
index e1e06d2..eb92366 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -697,7 +697,8 @@ static int parallels_open(BlockDriverState *bs, QDict 
*options, int flags,
 s->prealloc_size = MAX(s->tracks, s->prealloc_size >> BDRV_SECTOR_BITS);
 buf = qemu_opt_get_del(opts, PARALLELS

Re: [Qemu-devel] [Qemu-block] [PATCH v5 08/13] tests: Rely more on global_qtest

2017-08-24 Thread Paolo Bonzini
On 24/08/2017 09:42, Markus Armbruster wrote:
> 
> In a language less primitive than C, I'd write it exactly that way, and
> nobody would complain.  In old, primitive C, I have to write
> 
> global_qtest = A;
> do this
> do that
> 
> global_qtest = B;
> do something
> 
> global_qtest = A;
> do more
> 
> Why's that so horrible to justify busywork on wrappers?

Because cut-and-paste is a thing. :(

Paolo



[Qemu-devel] [PATCH 05/16] hmp: Use qapi_enum_parse() in hmp_migrate_set_capability()

2017-08-24 Thread Markus Armbruster
From: Marc-André Lureau 

The error message on invalid capability name changes from

Invalid parameter "NAME"

to

invalid parameter value: NAME

No worse than before.

Signed-off-by: Marc-André Lureau 
Message-Id: <20170822132255.23945-9-marcandre.lur...@redhat.com>
Reviewed-by: Markus Armbruster 
[Rebased, commit message rewritten]
Cc: "Dr. David Alan Gilbert" 
Signed-off-by: Markus Armbruster 
---
 hmp.c | 23 ++-
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/hmp.c b/hmp.c
index 03c1a78..7e0bd3d 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1527,23 +1527,20 @@ void hmp_migrate_set_capability(Monitor *mon, const 
QDict *qdict)
 bool state = qdict_get_bool(qdict, "state");
 Error *err = NULL;
 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
-int i;
+int val;
 
-for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
-if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
-caps->value = g_malloc0(sizeof(*caps->value));
-caps->value->capability = i;
-caps->value->state = state;
-caps->next = NULL;
-qmp_migrate_set_capabilities(caps, &err);
-break;
-}
+val = qapi_enum_parse(MigrationCapability_lookup, cap, -1, &err);
+if (val < 0) {
+goto end;
 }
 
-if (i == MIGRATION_CAPABILITY__MAX) {
-error_setg(&err, QERR_INVALID_PARAMETER, cap);
-}
+caps->value = g_malloc0(sizeof(*caps->value));
+caps->value->capability = val;
+caps->value->state = state;
+caps->next = NULL;
+qmp_migrate_set_capabilities(caps, &err);
 
+end:
 qapi_free_MigrationCapabilityStatusList(caps);
 
 if (err) {
-- 
2.7.5




Re: [Qemu-devel] [PATCH 0/4] four zpci patches

2017-08-24 Thread Yi Min Zhao



在 2017/8/24 下午3:13, Cornelia Huck 写道:

On Thu, 24 Aug 2017 13:20:12 +0800
Yi Min Zhao  wrote:


Why can't I receive [Qemu-devel] prefixed patches?


在 2017/8/23 下午3:26, Yi Min Zhao 写道:

This patch set contains four small zpci patches to fixup different issues.
1) fixup calculation of msix boundary
2) remove zpci idx from msix message, instead we could use PCIDevice's id to
 find zpci device in kvm_arch_fixup_msi_route()
3) fixup ind_offset calculation for adapter interrupt routing entry
4) introduce our own iommu_replay callback

Yi Min Zhao (4):
s390x/pci: fixup trap_msix()
s390x/pci: remove idx from msix msg data
s390x/pci: fixup ind_offset of msix routing entry
s390x/pci: add iommu replay callback

   hw/s390x/s390-pci-bus.c  | 24 +---
   hw/s390x/s390-pci-bus.h  |  2 ++
   hw/s390x/s390-pci-inst.c | 28 ++--
   target/s390x/kvm.c   | 11 ++-
   4 files changed, 23 insertions(+), 42 deletions(-)
  

Well, I did not get any of your original patches, just this reply...
seem to be stuck somewhere?



I sent patches to qemu-devel@nongnu.org and cc you also myself.
But what I received looks like CC ones, no [Qemu-devel] prefix.
Let me send them again. I'm not sure the reason.




Re: [Qemu-devel] Number of usable slots in PCIe Root Port / PCIe Switch Downstream Port

2017-08-24 Thread Andrea Bolognani
On Wed, 2017-08-23 at 23:16 +0300, Marcel Apfelbaum wrote:
> > Is such a configuration considered valid?
> 
> Definitely no.
> 
> > Or should
> > libvirt and the guest OS / firmware start allowing it?
> 
> I thought libvirt does not allow it anyway and yes, is a bug,
> but considered low priority.

That's correct, libvirt knows those controllers only have
a single slot and will prevent you from adding more than
one device to them. So no change needed there.

IIUC Lukáš is using QEMU directly in (some parts of)
Avocado, so I imagine emitting an error rather than
silently accepting an invalid configuration would save
him some debugging time :) But he knows not to do that
now, so I guess low priority sounds about right.

Thanks for clarifying!

-- 
Andrea Bolognani / Red Hat / Virtualization



[Qemu-devel] [PATCH 06/16] hmp: Use qapi_enum_parse() in hmp_migrate_set_parameter()

2017-08-24 Thread Markus Armbruster
From: Marc-André Lureau 

The error message on invalid parameter name changes from

Invalid parameter "NAME"

to

invalid parameter value: NAME

Slight degratation, perhaps.

Signed-off-by: Marc-André Lureau 
Message-Id: <20170822132255.23945-10-marcandre.lur...@redhat.com>
Reviewed-by: Markus Armbruster 
[Rebased, assertion added, commit message rewritten]
Cc: "Dr. David Alan Gilbert" 
Signed-off-by: Markus Armbruster 
---
 hmp.c | 138 +-
 1 file changed, 68 insertions(+), 70 deletions(-)

diff --git a/hmp.c b/hmp.c
index 7e0bd3d..2b6e919 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1556,84 +1556,82 @@ void hmp_migrate_set_parameter(Monitor *mon, const 
QDict *qdict)
 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
 uint64_t valuebw = 0;
 Error *err = NULL;
-int i, ret;
+int val, ret;
 
-for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
-if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
-switch (i) {
-case MIGRATION_PARAMETER_COMPRESS_LEVEL:
-p->has_compress_level = true;
-visit_type_int(v, param, &p->compress_level, &err);
-break;
-case MIGRATION_PARAMETER_COMPRESS_THREADS:
-p->has_compress_threads = true;
-visit_type_int(v, param, &p->compress_threads, &err);
-break;
-case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
-p->has_decompress_threads = true;
-visit_type_int(v, param, &p->decompress_threads, &err);
-break;
-case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
-p->has_cpu_throttle_initial = true;
-visit_type_int(v, param, &p->cpu_throttle_initial, &err);
-break;
-case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
-p->has_cpu_throttle_increment = true;
-visit_type_int(v, param, &p->cpu_throttle_increment, &err);
-break;
-case MIGRATION_PARAMETER_TLS_CREDS:
-p->has_tls_creds = true;
-p->tls_creds = g_new0(StrOrNull, 1);
-p->tls_creds->type = QTYPE_QSTRING;
-visit_type_str(v, param, &p->tls_creds->u.s, &err);
-break;
-case MIGRATION_PARAMETER_TLS_HOSTNAME:
-p->has_tls_hostname = true;
-p->tls_hostname = g_new0(StrOrNull, 1);
-p->tls_hostname->type = QTYPE_QSTRING;
-visit_type_str(v, param, &p->tls_hostname->u.s, &err);
-break;
-case MIGRATION_PARAMETER_MAX_BANDWIDTH:
-p->has_max_bandwidth = true;
-/*
- * Can't use visit_type_size() here, because it
- * defaults to Bytes rather than Mebibytes.
- */
-ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
-if (ret < 0 || valuebw > INT64_MAX
-|| (size_t)valuebw != valuebw) {
-error_setg(&err, "Invalid size %s", valuestr);
-break;
-}
-p->max_bandwidth = valuebw;
-break;
-case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
-p->has_downtime_limit = true;
-visit_type_int(v, param, &p->downtime_limit, &err);
-break;
-case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
-p->has_x_checkpoint_delay = true;
-visit_type_int(v, param, &p->x_checkpoint_delay, &err);
-break;
-case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
-p->has_block_incremental = true;
-visit_type_bool(v, param, &p->block_incremental, &err);
-break;
-}
+val = qapi_enum_parse(MigrationParameter_lookup, param, -1, &err);
+if (val < 0) {
+goto cleanup;
+}
 
-if (err) {
-goto cleanup;
-}
-
-qmp_migrate_set_parameters(p, &err);
+switch (val) {
+case MIGRATION_PARAMETER_COMPRESS_LEVEL:
+p->has_compress_level = true;
+visit_type_int(v, param, &p->compress_level, &err);
+break;
+case MIGRATION_PARAMETER_COMPRESS_THREADS:
+p->has_compress_threads = true;
+visit_type_int(v, param, &p->compress_threads, &err);
+break;
+case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
+p->has_decompress_threads = true;
+visit_type_int(v, param, &p->decompress_threads, &err);
+break;
+case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
+p->has_cpu_throttle_initial = true;
+visit_type_int(v, param, &p->cpu_throttle_initial, &err);
+break;
+case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
+p->has_cpu_throttle_increment = true;
+visit_type_int(v, param, &p->cpu_

[Qemu-devel] [PATCH 15/16] qapi: Change data type of the FOO_lookup generated for enum FOO

2017-08-24 Thread Markus Armbruster
From: Marc-André Lureau 

Currently, a FOO_lookup is an array of strings terminated by a NULL
sentinel.

A future patch will generate enums with "holes".  NULL-termination
will cease to work then.

To prepare for that, store the length in the FOO_lookup by wrapping it
in a struct and adding a member for the length.

The sentinel will be dropped next.

Signed-off-by: Marc-André Lureau 
Message-Id: <20170822132255.23945-13-marcandre.lur...@redhat.com>
[Basically redone]
Signed-off-by: Markus Armbruster 
---
 backends/hostmem.c |  2 +-
 block.c|  2 +-
 block/blkdebug.c   |  4 ++--
 block/file-posix.c |  8 +---
 block/gluster.c|  4 ++--
 block/parallels.c  | 14 --
 block/qcow2.c  |  4 ++--
 block/quorum.c |  2 +-
 blockdev.c |  2 +-
 crypto/block-luks.c|  8 
 crypto/secret.c|  2 +-
 crypto/tlscreds.c  |  2 +-
 hmp.c  |  6 +++---
 hw/core/qdev-properties.c  | 10 +-
 include/hw/qdev-core.h |  2 +-
 include/qapi/util.h|  9 +++--
 include/qapi/visitor.h |  2 +-
 include/qom/object.h   |  4 ++--
 migration/global_state.c   |  2 +-
 net/filter.c   |  2 +-
 qapi/qapi-util.c   | 12 ++--
 qapi/qapi-visit-core.c | 24 +---
 qemu-img.c |  2 +-
 qemu-nbd.c |  2 +-
 qom/object.c   | 16 
 scripts/qapi-visit.py  |  2 +-
 scripts/qapi.py| 13 -
 tests/check-qom-proplist.c | 15 +--
 tests/test-qapi-util.c | 10 +-
 tests/test-qobject-input-visitor.c |  2 +-
 tpm.c  |  2 +-
 31 files changed, 104 insertions(+), 87 deletions(-)

diff --git a/backends/hostmem.c b/backends/hostmem.c
index 06e8898..217cff6 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -395,7 +395,7 @@ host_memory_backend_class_init(ObjectClass *oc, void *data)
 host_memory_backend_set_host_nodes,
 NULL, NULL, &error_abort);
 object_class_property_add_enum(oc, "policy", "HostMemPolicy",
-HostMemPolicy_lookup,
+&HostMemPolicy_lookup,
 host_memory_backend_get_policy,
 host_memory_backend_set_policy, &error_abort);
 object_class_property_add_str(oc, "id", get_id, set_id, &error_abort);
diff --git a/block.c b/block.c
index 2d12131..3bd1eb8 100644
--- a/block.c
+++ b/block.c
@@ -1332,7 +1332,7 @@ static int bdrv_open_common(BlockDriverState *bs, 
BlockBackend *file,
 detect_zeroes = qemu_opt_get(opts, "detect-zeroes");
 if (detect_zeroes) {
 BlockdevDetectZeroesOptions value =
-qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
+qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup,
 detect_zeroes,
 BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
 &local_err);
diff --git a/block/blkdebug.c b/block/blkdebug.c
index b370fce..8e385ac 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -169,7 +169,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error 
**errp)
 error_setg(errp, "Missing event name for rule");
 return -1;
 }
-event = qapi_enum_parse(BlkdebugEvent_lookup, event_name, -1, errp);
+event = qapi_enum_parse(&BlkdebugEvent_lookup, event_name, -1, errp);
 if (event < 0) {
 return -1;
 }
@@ -732,7 +732,7 @@ static int blkdebug_debug_breakpoint(BlockDriverState *bs, 
const char *event,
 struct BlkdebugRule *rule;
 int blkdebug_event;
 
-blkdebug_event = qapi_enum_parse(BlkdebugEvent_lookup, event, -1, NULL);
+blkdebug_event = qapi_enum_parse(&BlkdebugEvent_lookup, event, -1, NULL);
 if (blkdebug_event < 0) {
 return -ENOENT;
 }
diff --git a/block/file-posix.c b/block/file-posix.c
index bfef91d..6acbd56 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -437,7 +437,8 @@ static int raw_open_common(BlockDriverState *bs, QDict 
*options,
 aio_default = (bdrv_flags & BDRV_O_NATIVE_AIO)
   ? BLOCKDEV_AIO_OPTIONS_NATIVE
   : BLOCKDEV_AIO_OPTIONS_THREADS;
-aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"),
+aio = qapi_enum_parse(&BlockdevAioOptions_lookup,
+  qemu_opt_get(opts, "aio"),
   aio_default, &local_err);
 if (local_err) {
 error_propagate(errp, local_err);
@@ -446,7 +447,8 @@ static int raw_open_common(BlockDriverState *bs, QDict 
*options,
 }
 s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE);
 
-locking = qapi_enum_parse(OnOffAuto_lo

[Qemu-devel] [PATCH 13/16] qapi: Mechanically convert FOO_lookup[...] to FOO_str(...)

2017-08-24 Thread Markus Armbruster
Signed-off-by: Markus Armbruster 
---
 backends/hostmem.c  |  2 +-
 block/backup.c  |  2 +-
 block/file-posix.c  |  4 +--
 block/file-win32.c  |  2 +-
 block/gluster.c |  4 +--
 block/iscsi.c   |  2 +-
 block/nfs.c |  2 +-
 block/qcow2.c   |  4 +--
 block/qed.c |  2 +-
 block/rbd.c |  2 +-
 block/sheepdog.c|  2 +-
 blockdev.c  |  4 +--
 blockjob.c  |  6 ++---
 chardev/char.c  |  4 +--
 crypto/block-luks.c | 12 -
 crypto/block.c  |  4 +--
 crypto/cipher-afalg.c   |  2 +-
 crypto/cipher-builtin.c |  8 +++---
 crypto/cipher-gcrypt.c  |  4 +--
 crypto/cipher-nettle.c  |  8 +++---
 crypto/hmac-gcrypt.c|  2 +-
 crypto/hmac-glib.c  |  2 +-
 crypto/hmac-nettle.c|  2 +-
 crypto/pbkdf-gcrypt.c   |  2 +-
 crypto/pbkdf-nettle.c   |  2 +-
 hmp.c   | 54 ++---
 hw/block/fdc.c  |  6 ++---
 hw/char/escc.c  |  2 +-
 hw/input/virtio-input-hid.c |  4 +--
 migration/colo-failover.c   |  4 +--
 migration/colo.c| 14 +-
 migration/global_state.c|  2 +-
 monitor.c   | 16 +--
 net/net.c   |  4 +--
 qapi/qmp-dispatch.c |  2 +-
 tests/test-qapi-util.c  |  2 +-
 tests/test-qobject-input-visitor.c  |  4 +--
 tests/test-qobject-output-visitor.c |  2 +-
 tests/test-string-input-visitor.c   |  2 +-
 tests/test-string-output-visitor.c  |  4 +--
 tpm.c   |  2 +-
 ui/input-legacy.c   |  4 +--
 ui/input.c  | 12 -
 ui/vnc.c|  6 ++---
 vl.c|  6 ++---
 45 files changed, 121 insertions(+), 121 deletions(-)

diff --git a/backends/hostmem.c b/backends/hostmem.c
index 4606b73..06e8898 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -304,7 +304,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, 
Error **errp)
 return;
 } else if (maxnode == 0 && backend->policy != MPOL_DEFAULT) {
 error_setg(errp, "host-nodes must be set for policy %s",
-   HostMemPolicy_lookup[backend->policy]);
+   HostMemPolicy_str(backend->policy));
 return;
 }
 
diff --git a/block/backup.c b/block/backup.c
index 504a089..517c300 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -596,7 +596,7 @@ BlockJob *backup_job_create(const char *job_id, 
BlockDriverState *bs,
 error_setg(errp,
"a sync_bitmap was provided to backup_run, "
"but received an incompatible sync_mode (%s)",
-   MirrorSyncMode_lookup[sync_mode]);
+   MirrorSyncMode_str(sync_mode));
 return NULL;
 }
 
diff --git a/block/file-posix.c b/block/file-posix.c
index d81eccc..bfef91d 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1724,7 +1724,7 @@ static int raw_regular_truncate(int fd, int64_t offset, 
PreallocMode prealloc,
 default:
 result = -ENOTSUP;
 error_setg(errp, "Unsupported preallocation mode: %s",
-   PreallocMode_lookup[prealloc]);
+   PreallocMode_str(prealloc));
 return result;
 }
 
@@ -1759,7 +1759,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t 
offset,
 
 if (prealloc != PREALLOC_MODE_OFF) {
 error_setg(errp, "Preallocation mode '%s' unsupported for this "
-   "non-regular file", PreallocMode_lookup[prealloc]);
+   "non-regular file", PreallocMode_str(prealloc));
 return -ENOTSUP;
 }
 
diff --git a/block/file-win32.c b/block/file-win32.c
index 192ea81..f2a1830 100644
--- a/block/file-win32.c
+++ b/block/file-win32.c
@@ -469,7 +469,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t 
offset,
 
 if (prealloc != PREALLOC_MODE_OFF) {
 error_setg(errp, "Unsupported preallocation mode '%s'",
-   PreallocMode_lookup[prealloc]);
+   PreallocMode_str(prealloc));
 return -ENOTSUP;
 }
 
diff --git a/block/gluster.c b/block/gluster.c
index 0614e0c..29f9427 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -1047,7 +1047,7 @@ static int qemu_gluster_create(const char *filename,
 default:
 ret = -EINVAL;
 error_setg(errp, "Unsupported preallocation mode: %s",
-   PreallocMode_lookup[prealloc]);
+   PreallocMode_str(prealloc));
 break;
   

Re: [Qemu-devel] [PATCH v5 3/9] s390x/pci: add stubs

2017-08-24 Thread Cornelia Huck
On Thu, 24 Aug 2017 09:43:48 +0200
Christian Borntraeger  wrote:

> On 08/24/2017 09:38 AM, Christian Borntraeger wrote:
> > 
> > 
> > On 08/23/2017 05:54 PM, Cornelia Huck wrote:  
> >> Some non-pci code calls into zpci code. Provide some stubs for builds
> >> without pci.
> >>
> >> Reviewed-by: Thomas Huth 
> >> Signed-off-by: Cornelia Huck 
> >> ---
> >>  hw/s390x/Makefile.objs   |  3 +-
> >>  hw/s390x/s390-pci-stub.c | 74 
> >> 
> >>  2 files changed, 76 insertions(+), 1 deletion(-)
> >>  create mode 100644 hw/s390x/s390-pci-stub.c

> >> +/* hw/s390x/sclp.c */
> >> +void s390_pci_sclp_configure(SCCB *sccb)
> >> +{
> >> +}
> >> +
> >> +void s390_pci_sclp_deconfigure(SCCB *sccb)
> >> +{
> >> +}  
> > 
> > shouldnt these function set an error code in the sccb, e.g.
> > something like
> > 
> >sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
> > 
> > 
> >   
> 
> Oh you have something like that in patch 7. Maybe move?

Does not really change anything in practice, but I can move it.



Re: [Qemu-devel] anyone seen or heard of large delays/stalls running qemu with kvm support?

2017-08-24 Thread Dr. David Alan Gilbert
* Chris Friesen (chris.frie...@windriver.com) wrote:
> 
> Hi all,
> 
> I need to apologize up front, this is going to be a long email.  Basically
> the executive summary is that we're seeing issues where a VM is apparently
> not making forward progress in the guest, while at the same time spinning in
> a busy loop on the host.  I'm looking for any pointers/suggestions on what
> might be going on or how to narrow it down.
> 
> We're using qemu-kvm-ev-2.6.0 in the context of an OpenStack compute node
> running CentOS 7.
> 
> While running a test involving a cold migration of a VM from one host to
> another (basically shutting down the guest, moving all the files over to
> another host, then starting the guest back up) we have on a couple of cases
> had a VM get into a state where it was displaying "Guest has not initialized
> the display (yet)." on the console.  Running strace or gdb on the host
> against the guest qemu process seems to allow it to make forward progress.

cc'ing in Paolo.


> Here's what I've got:
> 
> 1) The root disk seems to be fine.  The root disk for the VM is iSCSI, and
> is accessible from the host.  Starting up a new VM with the same root disk
> and mostly the same commandline works fine.  (The serial port of the new VM
> was directed to stdio and the vnc option was removed.)
> 
> 2) Investigating the apparently-hung instance it seems 2 of its 3 vCPUs are
> running a busy-loop:
> 
>PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
> 192577 root 20 0 3816972 38360 10916 R 99.9 0.0 75:15.17 CPU 1/KVM
> 192578 root -2 0 3816972 38360 10916 R 99.9 0.0 75:15.36 CPU 2/KVM
> 
> (Each of the vCPU threads is affined to a separate physical CPU.)
> 
> 
> 3) Trying to retrieve the cpu info via libvirt didn't return within 10 
> seconds:
> 
> compute-0:/home/wrsroot# start=$SECONDS; timeout 10 virsh
> qemu-monitor-command --hmp instance-006e info cpus || echo "timeout
> after $((SECONDS - start)) seconds"
> timeout after 10 seconds
> 
> 
> 4) Running gdb on 192577 shows the following backtrace:

How about getting a copy of the kernel stack for all the threads from
 /proc/(pid of qemu)/task/*/stack ?


> Thread 1 (process 192577):
> #0 0x7f8c596e4537 in ioctl () from /lib64/libc.so.6
> #1 0x7f8c70fe0234 in kvm_vcpu_ioctl ()
> #2 0x7f8c70fe02ed in kvm_cpu_exec ()
> #3 0x7f8c70fcee76 in qemu_kvm_cpu_thread_fn ()
> #4 0x7f8c599bedc5 in start_thread () from /lib64/libpthread.so.0
> #5 0x7f8c596ed76d in clone () from /lib64/libc.so.6
> 
> 5) Running gdb on 192578 gives the same backtrace.
> 
> 6) Strace shows most of the time spent in ioctl...with 39K syscalls in 30
> seconds across those two PIDs:

I've got vague memories of a recent bug report about something stuck
with the host eating CPU similarly, but I can't remember if it was
during boot or any other details.

> compute-0:/home/wrsroot# timeout 30 strace -c -q -T -p 192577 -p 192578
> % time seconds usecs/call calls errors syscall
> -- --- --- - - 
>  99.86 0.297753 9 32325 ioctl
>   0.12 0.000354 0 6730 writev
>   0.02 0.59 0 384 60 futex
>   0.00 0.00 0 10 write
>   0.00 0.00 0 2 rt_sigpending
>   0.00 0.00 0 2 2 rt_sigtimedwait
> -- --- --- - - 
> 100.00 0.298166 39453 62 total
> 
> 
> 7) Running strace is enough to allow the VM to make forward progress, here
> are kernel logs from within the guest:
> 
> [ 2540.964492] INFO: rcu_preempt self-detected stall on CPU { 0} (t=2202996
> jiffies g=-108 c=-109 q=1676)
> [ 2540.984656] Task dump for CPU 0:
> [ 2540.985911] systemd R running task 0 1 0 0x0008
> [ 2540.988028] 88003b66 84d8f1f4 88003e003d90 
> 810a8676
> [ 2540.990869]  81a44d40 88003e003da8 
> 810abed9
> [ 2540.993975] 0001 88003e003dd8 8110e1a0 
> 88003e00ec40
> [ 2540.996815] Call Trace:
> [ 2540.997995]  [] sched_show_task+0xb6/0x120
> [ 2540.58] [] dump_cpu_task+0x39/0x70
> [ 2541.001559] [] rcu_dump_cpu_stacks+0x90/0xd0
> [ 2541.002425] [] rcu_check_callbacks+0x434/0x7f0
> [ 2541.003154] [] ? tick_sched_handle.isra.13+0x60/0x60
> [ 2541.003981] [] update_process_times+0x47/0x80
> [ 2541.004755] [] tick_sched_handle.isra.13+0x25/0x60
> [ 2541.005528] [] tick_sched_timer+0x41/0x70
> [ 2541.006225] [] __hrtimer_run_queues+0xfc/0x320
> [ 2541.006976] [] hrtimer_interrupt+0xb0/0x1e0
> [ 2541.007751] [] local_apic_timer_interrupt+0x37/0x60
> [ 2541.008541] [] smp_apic_timer_interrupt+0x3f/0x60
> [ 2541.009290] [] apic_timer_interrupt+0x6d/0x80
> [ 2541.009996]  [] ? get_monotonic_boottime+0xb9/0x100
> [ 2541.010976] [] posix_get_boottime+0x11/0x20
> [ 2541.011740] [] SyS_clock_gettime+0x54/0xc0
> [ 2541.012437] [] system_call_fastpath+0x16/0x1b
> 
> [ 2602.140152] NMI watchdog: BUG: soft lockup - CPU#2 stuck for 22s!
> [systemd-udevd:232]
> [ 2602.140438] NMI watchdog: BUG: soft lockup

[Qemu-devel] [PATCH] vga: stop passing pointers to vga_draw_line* functions

2017-08-24 Thread Gerd Hoffmann
Instead pass around the address (aka offset into vga memory).
Add vga_read_* helper functions which apply vbe_size_mask to
the address, to make sure the address stays within the valid
range, simliar to the cirrus blitter fixes (commits ffaf857778
and 026aeffcb4).

Impact:  DoS for priviledged guest users.  qemu crashes with
a segfault, when hitting the guard page after vga memory
allocation, while reading vga memory for display updates.

Fixes: CVE-2017-
Cc: P J P 
Reported-by: David Buchanan 
Signed-off-by: Gerd Hoffmann 
---
 hw/display/vga-helpers.h | 202 ++-
 hw/display/vga_int.h |   1 +
 hw/display/vga.c |   5 +-
 3 files changed, 114 insertions(+), 94 deletions(-)

diff --git a/hw/display/vga-helpers.h b/hw/display/vga-helpers.h
index 94f6de2046..5a752b3f9e 100644
--- a/hw/display/vga-helpers.h
+++ b/hw/display/vga-helpers.h
@@ -95,20 +95,46 @@ static void vga_draw_glyph9(uint8_t *d, int linesize,
 } while (--h);
 }
 
+static inline uint8_t vga_read_byte(VGACommonState *vga, uint32_t addr)
+{
+return vga->vram_ptr[addr & vga->vbe_size_mask];
+}
+
+static inline uint16_t vga_read_word_le(VGACommonState *vga, uint32_t addr)
+{
+uint32_t offset = addr & vga->vbe_size_mask & ~1;
+uint16_t *ptr = (uint16_t *)(vga->vram_ptr + offset);
+return lduw_le_p(ptr);
+}
+
+static inline uint16_t vga_read_word_be(VGACommonState *vga, uint32_t addr)
+{
+uint32_t offset = addr & vga->vbe_size_mask & ~1;
+uint16_t *ptr = (uint16_t *)(vga->vram_ptr + offset);
+return lduw_be_p(ptr);
+}
+
+static inline uint32_t vga_read_dword_le(VGACommonState *vga, uint32_t addr)
+{
+uint32_t offset = addr & vga->vbe_size_mask & ~3;
+uint32_t *ptr = (uint32_t *)(vga->vram_ptr + offset);
+return ldl_le_p(ptr);
+}
+
 /*
  * 4 color mode
  */
-static void vga_draw_line2(VGACommonState *s1, uint8_t *d,
-   const uint8_t *s, int width)
+static void vga_draw_line2(VGACommonState *vga, uint8_t *d,
+   uint32_t addr, int width)
 {
 uint32_t plane_mask, *palette, data, v;
 int x;
 
-palette = s1->last_palette;
-plane_mask = mask16[s1->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
+palette = vga->last_palette;
+plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
 width >>= 3;
 for(x = 0; x < width; x++) {
-data = ((uint32_t *)s)[0];
+data = vga_read_dword_le(vga, addr);
 data &= plane_mask;
 v = expand2[GET_PLANE(data, 0)];
 v |= expand2[GET_PLANE(data, 2)] << 2;
@@ -124,7 +150,7 @@ static void vga_draw_line2(VGACommonState *s1, uint8_t *d,
 ((uint32_t *)d)[6] = palette[(v >> 4) & 0xf];
 ((uint32_t *)d)[7] = palette[(v >> 0) & 0xf];
 d += 32;
-s += 4;
+addr += 4;
 }
 }
 
@@ -134,17 +160,17 @@ static void vga_draw_line2(VGACommonState *s1, uint8_t *d,
 /*
  * 4 color mode, dup2 horizontal
  */
-static void vga_draw_line2d2(VGACommonState *s1, uint8_t *d,
- const uint8_t *s, int width)
+static void vga_draw_line2d2(VGACommonState *vga, uint8_t *d,
+ uint32_t addr, int width)
 {
 uint32_t plane_mask, *palette, data, v;
 int x;
 
-palette = s1->last_palette;
-plane_mask = mask16[s1->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
+palette = vga->last_palette;
+plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
 width >>= 3;
 for(x = 0; x < width; x++) {
-data = ((uint32_t *)s)[0];
+data = vga_read_dword_le(vga, addr);
 data &= plane_mask;
 v = expand2[GET_PLANE(data, 0)];
 v |= expand2[GET_PLANE(data, 2)] << 2;
@@ -160,24 +186,24 @@ static void vga_draw_line2d2(VGACommonState *s1, uint8_t 
*d,
 PUT_PIXEL2(d, 6, palette[(v >> 4) & 0xf]);
 PUT_PIXEL2(d, 7, palette[(v >> 0) & 0xf]);
 d += 64;
-s += 4;
+addr += 4;
 }
 }
 
 /*
  * 16 color mode
  */
-static void vga_draw_line4(VGACommonState *s1, uint8_t *d,
-   const uint8_t *s, int width)
+static void vga_draw_line4(VGACommonState *vga, uint8_t *d,
+   uint32_t addr, int width)
 {
 uint32_t plane_mask, data, v, *palette;
 int x;
 
-palette = s1->last_palette;
-plane_mask = mask16[s1->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
+palette = vga->last_palette;
+plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
 width >>= 3;
 for(x = 0; x < width; x++) {
-data = ((uint32_t *)s)[0];
+data = vga_read_dword_le(vga, addr);
 data &= plane_mask;
 v = expand4[GET_PLANE(data, 0)];
 v |= expand4[GET_PLANE(data, 1)] << 1;
@@ -192,24 +218,24 @@ static void vga_draw_line4(VGACommonState *s1, uint8_t *d,
 ((uint32_t *)d)[6] = palette[(v >> 4) & 0xf];
 ((uint32_t *)d)[7] = palette[(v >> 0) & 0xf];
 d += 32;
-s += 4;
+addr += 4;
 }
 }
 
 /*
  * 16

Re: [Qemu-devel] [PATCH for-2.11 06/27] x86: extract legacy cpu features format parser

2017-08-24 Thread Igor Mammedov
On Wed, 23 Aug 2017 14:58:39 -0300
Eduardo Habkost  wrote:

> On Wed, Aug 23, 2017 at 07:37:39PM +0200, Igor Mammedov wrote:
> > On Wed, 23 Aug 2017 13:46:38 -0300
> > Eduardo Habkost  wrote:
> >   
> > > On Wed, Aug 23, 2017 at 06:29:02PM +0200, Igor Mammedov wrote:  
> > > > On Wed, 23 Aug 2017 11:34:14 -0300
> > > > Eduardo Habkost  wrote:
> > > >   
> > > > > On Fri, Aug 18, 2017 at 12:08:38PM +0200, Igor Mammedov wrote:  
> > > > > > Move cpu_model +-feat parsing into a separate file so that it
> > > > > > could be reused later for parsing similar format of sparc target
> > > > > > 
> > > > > > Signed-off-by: Igor Mammedov 
> > > > > > ---
> > > > > > CC: Richard Henderson 
> > > > > > CC: Eduardo Habkost 
> > > > > > CC: Mark Cave-Ayland 
> > > > > > CC: Artyom Tarasenko 
> > > > > > CC: Philippe Mathieu-Daudé 
> > > > > > ---
> > > > > >  include/qom/cpu.h |   2 +
> > > > > >  default-configs/i386-bsd-user.mak |   1 +
> > > > > >  default-configs/i386-linux-user.mak   |   1 +
> > > > > >  default-configs/i386-softmmu.mak  |   1 +
> > > > > >  default-configs/x86_64-bsd-user.mak   |   1 +
> > > > > >  default-configs/x86_64-linux-user.mak |   1 +
> > > > > >  default-configs/x86_64-softmmu.mak|   1 +
> > > > > >  target/i386/cpu.c | 125 
> > > > > > +-
> > > > > >  util/Makefile.objs|   1 +
> > > > > >  util/legacy_cpu_features_parser.c | 161 
> > > > > > ++
> > > > > >  10 files changed, 171 insertions(+), 124 deletions(-)
> > > > > >  create mode 100644 util/legacy_cpu_features_parser.c
> > > > > > 
> > > > > [...]  
> > > > > > diff --git a/util/legacy_cpu_features_parser.c 
> > > > > > b/util/legacy_cpu_features_parser.c
> > > > > > new file mode 100644
> > > > > > index 000..6b352a3
> > > > > > --- /dev/null
> > > > > > +++ b/util/legacy_cpu_features_parser.c
> > > > > > @@ -0,0 +1,161 @@
> > > > > > +/* Support for legacy -cpu cpu,features CLI option with +-feat 
> > > > > > syntax,
> > > > > > + * used by x86/sparc targets
> > > > > > + *
> > > > > > + * Author: Andreas Färber 
> > > > > > + * Author: Andre Przywara 
> > > > > > + * Author: Eduardo Habkost 
> > > > > > + * Author: Igor Mammedov 
> > > > > > + * Author: Paolo Bonzini 
> > > > > > + * Author: Markus Armbruster 
> > > > > 
> > > > > IANAL, but I believe a
> > > > >   Copyright (c)  
> > > > > line is needed here.
> > > > >   
> > > > > > + *
> > > > > > + * This program is free software; you can redistribute it and/or 
> > > > > > modify
> > > > > > + * it under the terms of the GNU General Public License as 
> > > > > > published by
> > > > > > + * the Free Software Foundation; either version 2 of the License, 
> > > > > > or
> > > > > > + * (at your option) any later version.
> > > > > > +
> > > > > > + * This program is distributed in the hope that it will be useful,
> > > > > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > > > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > > > > + * GNU General Public License for more details.
> > > > > > +
> > > > > > + * You should have received a copy of the GNU General Public 
> > > > > > License along
> > > > > > + * with this program; if not, see .
> > > > > > + */
> > > > > > +
> > > > > > +#include "qemu/osdep.h"
> > > > > > +#include "qapi/error.h"
> > > > > > +#include "qemu/cutils.h"
> > > > > > +#include "qom/cpu.h"
> > > > > > +#include "qemu/error-report.h"
> > > > > > +#include "hw/qdev-properties.h"
> > > > > > +
> > > > > > +static inline void feat2prop(char *s)
> > > > > > +{
> > > > > > +while ((s = strchr(s, '_'))) {
> > > > > > +*s = '-';
> > > > > > +}
> > > > > > +}
> > > > > > +
> > > > > > +static gint compare_string(gconstpointer a, gconstpointer b)
> > > > > > +{
> > > > > > +return g_strcmp0(a, b);
> > > > > > +}
> > > > > > +
> > > > > > +static void
> > > > > > +cpu_add_feat_as_prop(const char *typename, const char *name, const 
> > > > > > char *val)
> > > > > > +{
> > > > > > +GlobalProperty *prop = g_new0(typeof(*prop), 1);
> > > > > > +prop->driver = typename;
> > > > > > +prop->property = g_strdup(name);
> > > > > > +prop->value = g_strdup(val);
> > > > > > +prop->errp = &error_fatal;
> > > > > > +qdev_prop_register_global(prop);
> > > > > > +}
> > > > > > +
> > > > > > +/* DO NOT USE WITH NEW CODE
> > > > > > + * Parse "+feature,-feature,feature=foo" CPU feature string
> > > > > > + */
> > > > > > +void cpu_legacy_parse_featurestr(const char *typename, char 
> > > > > > *features,
> > > > > > + Error **errp)
> > > > > > +{
> > > > > > +/* Compatibily hack to maintain legacy +-feat semantic,
> > > > > > + * where +-feat overwrites any feature set by
> > > > > > + * feat=on|feat even if the later is parsed after +-feat
> > > > > > + * (i.e. "-x2

[Qemu-devel] [PATCH] vga: fix display update region calculation (split screen)

2017-08-24 Thread Gerd Hoffmann
vga display update mis-calculated the region for the dirty bitmap
snapshot in case split screen mode is used.  This can trigger an
assert in cpu_physical_memory_snapshot_get_dirty().

Impact:  DoS for priviledged guest users.

Fixes: CVE-2017-
Fixes: fec5e8c92becad223df9d972770522f64aafdb72
Cc: P J P 
Reported-by: David Buchanan 
Signed-off-by: Gerd Hoffmann 
---
 hw/display/vga.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/display/vga.c b/hw/display/vga.c
index 63421f9ee8..ab33668402 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -1628,9 +1628,15 @@ static void vga_draw_graphic(VGACommonState *s, int 
full_update)
 y1 = 0;
 
 if (!full_update) {
+ram_addr_t region_start = addr1;
+ram_addr_t region_end = addr1 + line_offset * height;
 vga_sync_dirty_bitmap(s);
-snap = memory_region_snapshot_and_clear_dirty(&s->vram, addr1,
-  line_offset * height,
+if (s->line_compare < height) {
+/* split screen mode */
+region_start = 0;
+}
+snap = memory_region_snapshot_and_clear_dirty(&s->vram, region_start,
+  region_end - 
region_start,
   DIRTY_MEMORY_VGA);
 }
 
-- 
2.9.3




Re: [Qemu-devel] [PATCH v3 06/10] tests: Add NetBSD image

2017-08-24 Thread Fam Zheng
On Wed, 08/23 17:15, Kamil Rytarowski wrote:
> On 22.08.2017 06:41, Fam Zheng wrote:
> > The image is prepared following instructions as in:
> > 
> > https://wiki.qemu.org/Hosts/BSD
> > 
> > Signed-off-by: Fam Zheng 
> > Reviewed-by: Kamil Rytarowski 
> > ---
> >  tests/vm/netbsd | 45 +
> >  1 file changed, 45 insertions(+)
> >  create mode 100755 tests/vm/netbsd
> > 
> > diff --git a/tests/vm/netbsd b/tests/vm/netbsd
> > new file mode 100755
> > index 00..7d7dfe6586
> > --- /dev/null
> > +++ b/tests/vm/netbsd
> > @@ -0,0 +1,45 @@
> > +#!/usr/bin/env python
> > +#
> > +# NetBSD VM image
> > +#
> > +# Copyright (C) 2017 Red Hat Inc.
> > +#
> > +# Authors:
> > +#  Fam Zheng 
> > +#
> > +# This work is licensed under the terms of the GNU GPL, version 2.  See
> > +# the COPYING file in the top-level directory.
> > +#
> > +
> > +import os
> > +import sys
> > +import logging
> > +import subprocess
> > +import tempfile
> > +import time
> > +import basevm
> > +
> > +class NetBSDVM(basevm.BaseVM):
> > +name = "netbsd"
> > +BUILD_SCRIPT = """
> > +set -e;
> > +cd $(mktemp -d /var/tmp/qemu-test.XX);
> > +tar -xf /dev/ld1a;
> 
> I've rechecked a similar setup, and I think that there might be needed
> /dev/rld1a (initial r stands for raw device).

Sure, I'll have a test and update it.

Fam



Re: [Qemu-devel] [PATCH v3 00/10] tests: Add VM based build tests (for non-x86_64 and/or non-Linux)

2017-08-24 Thread Fam Zheng
On Tue, 08/22 16:33, Kamil Rytarowski wrote:
> I propose to rename *bsd.img.xz (like netbsd.img.xz) to
> *bsd-version-arch.img.xz, like netbsd-7.1-amd64.img.xz. This will be
> more verbose about the version and leave room for image upgrades in future.

Good idea, will update.

Fam



Re: [Qemu-devel] [PATCH v5 7/9] s390x/sclp: properly guard pci-specific functions

2017-08-24 Thread Halil Pasic


On 08/23/2017 05:54 PM, Cornelia Huck wrote:
> If we do not provide zpci, pci reconfiguration via sclp is not available
> either. I/O adapter configuration, however, should always be present.
> 
> Rename the values that refer to I/O adapter configuration (instead of only
> pci) to make things clearer.
> 
> Move length checking of the sccb for I/O adapter configuration into the
> common sclp code (out of the pci code). This also fixes an issue that
> the pci code would refer to a field in the sccb before checking whether
> it was actually long enough.
> 
> Check for the adapter type in the sccb and return unrecognized adapter
> type if the guest tries to issue I/O adapter configure/deconfigure for
> a type other than pci or for pci if the zpci facility is not provided.
> 
> Signed-off-by: Cornelia Huck 
> ---
>  hw/s390x/s390-pci-bus.c  | 14 ++
>  hw/s390x/s390-pci-bus.h  |  8 
>  hw/s390x/s390-pci-stub.c |  2 ++
>  hw/s390x/sclp.c  | 39 ++-
>  include/hw/s390x/sclp.h  | 17 +
>  5 files changed, 51 insertions(+), 29 deletions(-)
> 
> diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
> index c57f6ebae0..0a31a4ae88 100644
> --- a/hw/s390x/s390-pci-bus.c
> +++ b/hw/s390x/s390-pci-bus.c
> @@ -122,16 +122,11 @@ S390PCIBusDevice *s390_pci_find_dev_by_fid(S390pciState 
> *s, uint32_t fid)
> 
>  void s390_pci_sclp_configure(SCCB *sccb)
>  {
> -PciCfgSccb *psccb = (PciCfgSccb *)sccb;
> +IoaCfgSccb *psccb = (IoaCfgSccb *)sccb;
>  S390PCIBusDevice *pbdev = s390_pci_find_dev_by_fid(s390_get_phb(),
> 
> be32_to_cpu(psccb->aid));
>  uint16_t rc;
> 
> -if (be16_to_cpu(sccb->h.length) < 16) {
> -rc = SCLP_RC_INSUFFICIENT_SCCB_LENGTH;
> -goto out;
> -}
> -
>  if (!pbdev) {
>  DPRINTF("sclp config no dev found\n");
>  rc = SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED;
> @@ -155,16 +150,11 @@ out:
> 
>  void s390_pci_sclp_deconfigure(SCCB *sccb)
>  {
> -PciCfgSccb *psccb = (PciCfgSccb *)sccb;
> +IoaCfgSccb *psccb = (IoaCfgSccb *)sccb;
>  S390PCIBusDevice *pbdev = s390_pci_find_dev_by_fid(s390_get_phb(),
> 
> be32_to_cpu(psccb->aid));
>  uint16_t rc;
> 
> -if (be16_to_cpu(sccb->h.length) < 16) {
> -rc = SCLP_RC_INSUFFICIENT_SCCB_LENGTH;
> -goto out;
> -}
> -
>  if (!pbdev) {
>  DPRINTF("sclp deconfig no dev found\n");
>  rc = SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED;
> diff --git a/hw/s390x/s390-pci-bus.h b/hw/s390x/s390-pci-bus.h
> index 5df6292509..bd636abc28 100644
> --- a/hw/s390x/s390-pci-bus.h
> +++ b/hw/s390x/s390-pci-bus.h
> @@ -244,14 +244,6 @@ typedef struct ChscSeiNt2Res {
>  uint8_t ccdf[4016];
>  } QEMU_PACKED ChscSeiNt2Res;
> 
> -typedef struct PciCfgSccb {
> -SCCBHeader header;
> -uint8_t atype;
> -uint8_t reserved1;
> -uint16_t reserved2;
> -uint32_t aid;
> -} QEMU_PACKED PciCfgSccb;
> -
>  typedef struct S390MsixInfo {
>  bool available;
>  uint8_t table_bar;
> diff --git a/hw/s390x/s390-pci-stub.c b/hw/s390x/s390-pci-stub.c
> index cc7278a865..7a642d376c 100644
> --- a/hw/s390x/s390-pci-stub.c
> +++ b/hw/s390x/s390-pci-stub.c
> @@ -20,10 +20,12 @@ int pci_chsc_sei_nt2_have_event(void)
>  /* hw/s390x/sclp.c */
>  void s390_pci_sclp_configure(SCCB *sccb)
>  {
> +sccb->h.response_code = cpu_to_be16(SCLP_RC_ADAPTER_TYPE_NOT_RECOGNIZED);
>  }
> 
>  void s390_pci_sclp_deconfigure(SCCB *sccb)
>  {
> +sccb->h.response_code = cpu_to_be16(SCLP_RC_ADAPTER_TYPE_NOT_RECOGNIZED);
>  }
> 
>  /* target/s390x/kvm.c */
> diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
> index 9253dbbc64..7ae6a0e37a 100644
> --- a/hw/s390x/sclp.c
> +++ b/hw/s390x/sclp.c
> @@ -80,7 +80,7 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
>  prepare_cpu_entries(sclp, read_info->entries, cpu_count);
> 
>  read_info->facilities = cpu_to_be64(SCLP_HAS_CPU_INFO |
> -SCLP_HAS_PCI_RECONFIG);
> +SCLP_HAS_IOA_RECONFIG);
> 
>  /* Memory Hotplug is only supported for the ccw machine type */
>  if (mhd) {
> @@ -354,6 +354,35 @@ static void sclp_read_cpu_info(SCLPDevice *sclp, SCCB 
> *sccb)
>  sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_READ_COMPLETION);
>  }
> 
> +static void sclp_configure_io_adapter(SCLPDevice *sclp, SCCB *sccb,
> +  bool configure)

Just an idea. This could be called reconfigure instead
of configure (that's sclp_reconfigure_io_adapter) as the
facility providing both conf and deconf is called reconf.

It ain't important. Patch looks good!

Reviewed-by: Halil Pasic 




Re: [Qemu-devel] [PATCH v5 7/9] s390x/sclp: properly guard pci-specific functions

2017-08-24 Thread Cornelia Huck
On Thu, 24 Aug 2017 11:29:47 +0200
Halil Pasic  wrote:

> On 08/23/2017 05:54 PM, Cornelia Huck wrote:
> > If we do not provide zpci, pci reconfiguration via sclp is not available
> > either. I/O adapter configuration, however, should always be present.
> > 
> > Rename the values that refer to I/O adapter configuration (instead of only
> > pci) to make things clearer.
> > 
> > Move length checking of the sccb for I/O adapter configuration into the
> > common sclp code (out of the pci code). This also fixes an issue that
> > the pci code would refer to a field in the sccb before checking whether
> > it was actually long enough.
> > 
> > Check for the adapter type in the sccb and return unrecognized adapter
> > type if the guest tries to issue I/O adapter configure/deconfigure for
> > a type other than pci or for pci if the zpci facility is not provided.
> > 
> > Signed-off-by: Cornelia Huck 
> > ---
> >  hw/s390x/s390-pci-bus.c  | 14 ++
> >  hw/s390x/s390-pci-bus.h  |  8 
> >  hw/s390x/s390-pci-stub.c |  2 ++
> >  hw/s390x/sclp.c  | 39 ++-
> >  include/hw/s390x/sclp.h  | 17 +
> >  5 files changed, 51 insertions(+), 29 deletions(-)

> > diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
> > index 9253dbbc64..7ae6a0e37a 100644
> > --- a/hw/s390x/sclp.c
> > +++ b/hw/s390x/sclp.c
> > @@ -80,7 +80,7 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
> >  prepare_cpu_entries(sclp, read_info->entries, cpu_count);
> > 
> >  read_info->facilities = cpu_to_be64(SCLP_HAS_CPU_INFO |
> > -SCLP_HAS_PCI_RECONFIG);
> > +SCLP_HAS_IOA_RECONFIG);
> > 
> >  /* Memory Hotplug is only supported for the ccw machine type */
> >  if (mhd) {
> > @@ -354,6 +354,35 @@ static void sclp_read_cpu_info(SCLPDevice *sclp, SCCB 
> > *sccb)
> >  sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_READ_COMPLETION);
> >  }
> > 
> > +static void sclp_configure_io_adapter(SCLPDevice *sclp, SCCB *sccb,
> > +  bool configure)  
> 
> Just an idea. This could be called reconfigure instead
> of configure (that's sclp_reconfigure_io_adapter) as the
> facility providing both conf and deconf is called reconf.
> 
> It ain't important. Patch looks good!

So I'll just keep it as-is :)

> 
> Reviewed-by: Halil Pasic 

Thanks!



Re: [Qemu-devel] Memory use with >100 virtio devices

2017-08-24 Thread Alexey Kardashevskiy
On 21/08/17 15:50, Alexey Kardashevskiy wrote:
> On 21/08/17 14:31, David Gibson wrote:
>> On Fri, Aug 18, 2017 at 02:18:53PM +0100, Stefan Hajnoczi wrote:
>>> On Fri, Aug 18, 2017 at 03:39:20PM +1000, Alexey Kardashevskiy wrote:
 ==94451==  4 of 10 
 ==94451== max-live:314,649,600 in 150 blocks
 ==94451== tot-alloc:   314,649,600 in 150 blocks (avg size 2097664.00)
 ==94451== deaths:  none (none of these blocks were freed)
 ==94451== acc-ratios:  0.00 rd, 0.00 wr  (0 b-read, 0 b-written)
 ==94451==at 0x4895600: memalign (in
 /usr/lib/valgrind/vgpreload_exp-dhat-ppc64le-linux.so)
 ==94451==by 0x48957E7: posix_memalign (in
 /usr/lib/valgrind/vgpreload_exp-dhat-ppc64le-linux.so)
 ==94451==by 0xB744AB: qemu_try_memalign (oslib-posix.c:106)
 ==94451==by 0xA92053: qemu_try_blockalign (io.c:2493)
 ==94451==by 0xA34DDF: qcow2_do_open (qcow2.c:1365)
 ==94451==by 0xA35627: qcow2_open (qcow2.c:1526)
 ==94451==by 0x9FB94F: bdrv_open_driver (block.c:1109)
 ==94451==by 0x9FC413: bdrv_open_common (block.c:1365)
 ==94451==by 0x9FF823: bdrv_open_inherit (block.c:2542)
 ==94451==by 0x9FFC17: bdrv_open (block.c:2626)
 ==94451==by 0xA71027: blk_new_open (block-backend.c:267)
 ==94451==by 0x6D3E6B: blockdev_init (blockdev.c:588)
>>>
>>> This allocation is unnecessary.  Most qcow2 files are not encrypted so
>>> s->cluster_data does not need to be allocated upfront.
>>>
>>> I'll send a patch.
>>
>> Is that sufficient to explain the problem, I can't quickly see how big
>> that unnecessary allocation is - but would it account for the 10s of
>> gigabytes usage we're seeing here?
>>
>> I'm suspecting we accidentally have a O(n^2) or worse space complexity
>> going on here.
>>
> 
> No, it is a small fraction only. See "[PATCH] qcow2: allocate
> cluster_cache/cluster_data on demand" thread for more details.


The information was lost there so I'll continue in this thread.

I run QEMU again, with 2GB of RAM, -initrd+-kernel, pseries, 64 PCI
bridges, -S, no KVM, some virtio-block devices; I run it under "valgrind
--tool=exp-dhat" and exited via "c-a x" as soon as possible.

The summary of each run is:

50 virtio-block devices:
guest_insns:  2,728,740,444
max_live: 1,214,121,770 in 226,958 blocks
tot_alloc:1,384,726,690 in 310,930 blocks


150 virtio-block devices:
guest_insns:  17,576,279,582
max_live: 7,454,182,031 in 1,286,128 blocks
tot_alloc:7,958,747,994 in 1,469,719 blocks

250 virtio-block devices:
guest_insns:  46,100,928,249
max_live: 19,423,868,479 in 3,264,833 blocks
tot_alloc:20,262,409,839 in 3,548,220 blocks

350 virtio-block devices:
guest_insns:  88,046,403,555
max_live: 36,994,652,991 in 6,140,203 blocks
tot_alloc:38,167,153,779 in 6,523,206 blocks


Memory usage 1) grows a lot 2) grows out of proportion 3) QEMU becomes
incredibly slow.


With the hack (below) and 350 virtio-block devices, the summary is:
guest_insns:  7,873,805,573
max_live: 2,577,738,019 in 2,567,682 blocks
tot_alloc:3,750,238,807 in 2,950,685 blocks
insns per allocated byte: 2


I am also attaching 2 snapshots from the valgrind's "massif" tool, with and
without the hack.

Ideas what to tweak or what valgrind tool to try?



The hack is basically excluding virtio-pci-cfg-as from the address_spaces
list (yeah, it breaks QEMU, this is just a hint):

diff --git a/memory.c b/memory.c
index 02c95d1..118ac7f 100644
--- a/memory.c
+++ b/memory.c
@@ -2589,6 +2589,7 @@ void address_space_init(AddressSpace *as,
MemoryRegion *root, const char *name)
 as->ioeventfd_nb = 0;
 as->ioeventfds = NULL;
 QTAILQ_INIT(&as->listeners);
+if (strcmp(name, "virtio-pci-cfg-as"))
 QTAILQ_INSERT_TAIL(&address_spaces, as, address_spaces_link);
 as->name = g_strdup(name ? name : "anonymous");
 address_space_init_dispatch(as);




-- 
Alexey
 57 85,481,838,874   37,075,366,088   36,993,595,91381,770,1750
99.78% (36,993,595,913B) (heap allocation functions) malloc/new/new[], 
--alloc-fns, etc.
->95.82% (35,527,301,159B) 0x59E7392: g_realloc (in 
/lib/powerpc64le-linux-gnu/libglib-2.0.so.0.5000.2)
| ->94.64% (35,089,885,088B) 0x59E7756: g_realloc_n (in 
/lib/powerpc64le-linux-gnu/libglib-2.0.so.0.5000.2)
| | ->90.60% (33,590,452,224B) 0x3A785A: phys_map_node_reserve (exec.c:251)
| | | ->90.60% (33,590,452,224B) 0x3A7CE2: phys_page_set (exec.c:307)
| | |   ->90.60% (33,590,452,224B) 0x3AAF26: register_multipage (exec.c:1345)
| | | ->90.60% (33,590,452,224B) 0x3AB31E: mem_add (exec.c:1376)
| | |   ->90.55% (33,573,015,552B) 0x437F52: 
address_space_update_topology_pass (memory.c:855)
| | |   | ->90.55% (33,573,015,552B) 0x4382C2: 
address_space_update_topology (memory.c:889)
| | |   |   ->90.55% (33,573,015,552B) 0x438502: 
memory_region_transaction_commit (memory.c:925)
| | |   | ->54.09% (20,055,085,056B) 0x

Re: [Qemu-devel] [PATCH v5 3/9] s390x/pci: add stubs

2017-08-24 Thread Halil Pasic


On 08/24/2017 11:09 AM, Cornelia Huck wrote:
> On Thu, 24 Aug 2017 09:43:48 +0200
> Christian Borntraeger  wrote:
> 
>> On 08/24/2017 09:38 AM, Christian Borntraeger wrote:
>>>
>>>
>>> On 08/23/2017 05:54 PM, Cornelia Huck wrote:  
 Some non-pci code calls into zpci code. Provide some stubs for builds
 without pci.

 Reviewed-by: Thomas Huth 
 Signed-off-by: Cornelia Huck 
 ---
  hw/s390x/Makefile.objs   |  3 +-
  hw/s390x/s390-pci-stub.c | 74 
 
  2 files changed, 76 insertions(+), 1 deletion(-)
  create mode 100644 hw/s390x/s390-pci-stub.c
> 
 +/* hw/s390x/sclp.c */
 +void s390_pci_sclp_configure(SCCB *sccb)
 +{
 +}
 +
 +void s390_pci_sclp_deconfigure(SCCB *sccb)
 +{
 +}  
>>>
>>> shouldnt these function set an error code in the sccb, e.g.
>>> something like
>>>
>>>sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
>>>
>>>
>>>   
>>
>> Oh you have something like that in patch 7. Maybe move?
> 
> Does not really change anything in practice, but I can move it.
> 

You mean these stubs are not supposed to be reachable and are just
for making the linker happy, or? If that's the case I would prefer
having that expressed by something like assert(false) or even 
#define NOT_REACHABLE assert(false).

Otherwise patch looks good, but I did not a full review on it,
so let's try this:
Acked-by: Halil Pasic 




Re: [Qemu-devel] [PATCH QEMU] xen/pt: allow QEMU to request MSI unmasking at bind time

2017-08-24 Thread Jan Beulich
>>> On 24.08.17 at 11:47,  wrote:
> @@ -274,7 +278,7 @@ int xen_pt_msi_update(XenPCIPassthroughState *s)
>  {
>  XenPTMSI *msi = s->msi;
>  return msi_msix_update(s, msi_addr64(msi), msi->data, msi->pirq,
> -   false, 0, &msi->pirq);
> +   false, 0, &msi->pirq, false);
>  }

I don't think this is correct when the device has mask bits.

Jan




Re: [Qemu-devel] [PATCH 15/16] qapi: Change data type of the FOO_lookup generated for enum FOO

2017-08-24 Thread Markus Armbruster
Markus Armbruster  writes:

> From: Marc-André Lureau 
>
> Currently, a FOO_lookup is an array of strings terminated by a NULL
> sentinel.
>
> A future patch will generate enums with "holes".  NULL-termination
> will cease to work then.
>
> To prepare for that, store the length in the FOO_lookup by wrapping it
> in a struct and adding a member for the length.
>
> The sentinel will be dropped next.
>
> Signed-off-by: Marc-André Lureau 
> Message-Id: <20170822132255.23945-13-marcandre.lur...@redhat.com>
> [Basically redone]
> Signed-off-by: Markus Armbruster 

Fixup for Windows (thanks, Patchew!)


>From 594a6c8eb29e728e9fb960d321ca2d17f9bd9cd1 Mon Sep 17 00:00:00 2001
From: Markus Armbruster 
Date: Thu, 24 Aug 2017 11:48:46 +0200
Subject: [PATCH] fixup! qapi: Change data type of the FOO_lookup generated for
 enum FOO

---
 block/file-win32.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/file-win32.c b/block/file-win32.c
index f2a1830..639221b 100644
--- a/block/file-win32.c
+++ b/block/file-win32.c
@@ -302,7 +302,8 @@ static bool get_aio_option(QemuOpts *opts, int flags, Error 
**errp)
 
 aio_default = (flags & BDRV_O_NATIVE_AIO) ? BLOCKDEV_AIO_OPTIONS_NATIVE
   : BLOCKDEV_AIO_OPTIONS_THREADS;
-aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"),
+aio = qapi_enum_parse(&BlockdevAioOptions_lookup,
+  qemu_opt_get(opts, "aio"),
   aio_default, errp);
 
 switch (aio) {
-- 
2.7.5




Re: [Qemu-devel] [PATCH v5 3/9] s390x/pci: add stubs

2017-08-24 Thread Cornelia Huck
On Thu, 24 Aug 2017 11:50:54 +0200
Halil Pasic  wrote:

> On 08/24/2017 11:09 AM, Cornelia Huck wrote:
> > On Thu, 24 Aug 2017 09:43:48 +0200
> > Christian Borntraeger  wrote:
> >   
> >> On 08/24/2017 09:38 AM, Christian Borntraeger wrote:  
> >>>
> >>>
> >>> On 08/23/2017 05:54 PM, Cornelia Huck wrote:
>  Some non-pci code calls into zpci code. Provide some stubs for builds
>  without pci.
> 
>  Reviewed-by: Thomas Huth 
>  Signed-off-by: Cornelia Huck 
>  ---
>   hw/s390x/Makefile.objs   |  3 +-
>   hw/s390x/s390-pci-stub.c | 74 
>  
>   2 files changed, 76 insertions(+), 1 deletion(-)
>   create mode 100644 hw/s390x/s390-pci-stub.c  
> >   
>  +/* hw/s390x/sclp.c */
>  +void s390_pci_sclp_configure(SCCB *sccb)
>  +{
>  +}
>  +
>  +void s390_pci_sclp_deconfigure(SCCB *sccb)
>  +{
>  +}
> >>>
> >>> shouldnt these function set an error code in the sccb, e.g.
> >>> something like
> >>>
> >>>sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
> >>>
> >>>
> >>> 
> >>
> >> Oh you have something like that in patch 7. Maybe move?  
> > 
> > Does not really change anything in practice, but I can move it.
> >   
> 
> You mean these stubs are not supposed to be reachable and are just
> for making the linker happy, or? If that's the case I would prefer
> having that expressed by something like assert(false) or even 
> #define NOT_REACHABLE assert(false).

Without the last patch that makes virtio-pci depend on pci for s390x,
you can't compile without pci anyway ;)

> 
> Otherwise patch looks good, but I did not a full review on it,
> so let's try this:
> Acked-by: Halil Pasic 
> 

Thanks!



[Qemu-devel] [PATCH for-2.11] hw/s390x/s390-skeys: Mark the storage key devices with user_creatable = false

2017-08-24 Thread Thomas Huth
QEMU currently aborts if the user tries to create a skey device:

$ s390x-softmmu/qemu-system-s390x -nographic -device s390-skeys-qemu
qemu-system-s390x: hw/s390x/s390-skeys.c:30: s390_get_skeys_device:
 Assertion `ss' failed.
Aborted (core dumped)

The storage key devices are only meant to be instantiated one time,
internally. They can not be used by the user, so mark them with
user_creatable = false.

Signed-off-by: Thomas Huth 
---
 hw/s390x/s390-skeys-kvm.c | 4 
 hw/s390x/s390-skeys.c | 4 
 2 files changed, 8 insertions(+)

diff --git a/hw/s390x/s390-skeys-kvm.c b/hw/s390x/s390-skeys-kvm.c
index 131da56..dc54ed8 100644
--- a/hw/s390x/s390-skeys-kvm.c
+++ b/hw/s390x/s390-skeys-kvm.c
@@ -54,10 +54,14 @@ static int kvm_s390_skeys_set(S390SKeysState *ss, uint64_t 
start_gfn,
 static void kvm_s390_skeys_class_init(ObjectClass *oc, void *data)
 {
 S390SKeysClass *skeyclass = S390_SKEYS_CLASS(oc);
+DeviceClass *dc = DEVICE_CLASS(oc);
 
 skeyclass->skeys_enabled = kvm_s390_skeys_enabled;
 skeyclass->get_skeys = kvm_s390_skeys_get;
 skeyclass->set_skeys = kvm_s390_skeys_set;
+
+/* Reason: Internal device (only one skeys device for the whole memory) */
+dc->user_creatable = false;
 }
 
 static const TypeInfo kvm_s390_skeys_info = {
diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c
index c0de3b0..53ad5d3 100644
--- a/hw/s390x/s390-skeys.c
+++ b/hw/s390x/s390-skeys.c
@@ -229,10 +229,14 @@ static int qemu_s390_skeys_get(S390SKeysState *ss, 
uint64_t start_gfn,
 static void qemu_s390_skeys_class_init(ObjectClass *oc, void *data)
 {
 S390SKeysClass *skeyclass = S390_SKEYS_CLASS(oc);
+DeviceClass *dc = DEVICE_CLASS(oc);
 
 skeyclass->skeys_enabled = qemu_s390_skeys_enabled;
 skeyclass->get_skeys = qemu_s390_skeys_get;
 skeyclass->set_skeys = qemu_s390_skeys_set;
+
+/* Reason: Internal device (only one skeys device for the whole memory) */
+dc->user_creatable = false;
 }
 
 static const TypeInfo qemu_s390_skeys_info = {
-- 
1.8.3.1




Re: [Qemu-devel] [Qemu-block] [PATCH v5 08/13] tests: Rely more on global_qtest

2017-08-24 Thread Markus Armbruster
Paolo Bonzini  writes:

> On 24/08/2017 09:42, Markus Armbruster wrote:
>> 
>> In a language less primitive than C, I'd write it exactly that way, and
>> nobody would complain.  In old, primitive C, I have to write
>> 
>> global_qtest = A;
>> do this
>> do that
>> 
>> global_qtest = B;
>> do something
>> 
>> global_qtest = A;
>> do more
>> 
>> Why's that so horrible to justify busywork on wrappers?
>
> Because cut-and-paste is a thing. :(

Cut-and-paste cuts both ways (pardon the pun):

initialize with QTestState A
frobnicate with QTestState A
glomnify with QTestState A
frobnicate with QTestState A
initialize with QTestState B
boingboing with QTestState B
finalize with QTestState A
finalize with QTestState A

Uh, forgot to frobnicate after boingboing, let me fix that real quick!

initialize with QTestState A
frobnicate with QTestState A
glomnify with QTestState A
frobnicate with QTestState A
initialize with QTestState B
boingboing with QTestState B
frobnicate with QTestState A
finalize with QTestState A
finalize with QTestState A

Spot the pasto.

This hasty paste would simply work with global_qtest.  I'm not claiming
there are cases that are just the opposite.  I'm just challenging your
apparent claim that the long forms help with avoiding or catching
pastos.  Can you explain how they help more than they hurt?

A bit of global state isn't automatically bad.  *Shared* global state is
what gets us into trouble.  Can you point to examples where global_qtest
is shared in ways that aren't 100% trivial?



Re: [Qemu-devel] [PATCH QEMU] xen/pt: allow QEMU to request MSI unmasking at bind time

2017-08-24 Thread Jan Beulich
>>> On 24.08.17 at 12:06,  wrote:
> On Thu, Aug 24, 2017 at 03:54:21AM -0600, Jan Beulich wrote:
>> >>> On 24.08.17 at 11:47,  wrote:
>> > @@ -274,7 +278,7 @@ int xen_pt_msi_update(XenPCIPassthroughState *s)
>> >  {
>> >  XenPTMSI *msi = s->msi;
>> >  return msi_msix_update(s, msi_addr64(msi), msi->data, msi->pirq,
>> > -   false, 0, &msi->pirq);
>> > +   false, 0, &msi->pirq, false);
>> >  }
>> 
>> I don't think this is correct when the device has mask bits.
> 
> Right, I thought I modified this. I've already changed
> pt_irq_create_bind so that the original behavior is keep if the unmask
> bit is not set. In this case this should be 'true' in order to keep
> the previous behavior, which was correct for MSI.

Wouldn't you want to pass the state of the mask bit here,
rather than uniformly hard coding true or false?

> It also makes me wonder whether it would be better to change the name
> of the parameter to "unmask", so that false -> no change to mask, true
> -> unconditionally unmask.

I don't care much about this aspect, but perhaps the qemu
maintainers do.

Jan




[Qemu-devel] [Bug 1712027] Re: qemu: Cryptography adding encrypted disk with luks format failed

2017-08-24 Thread Huang Yong
If the alg is GCRY_CIPHER_AES256 and length of data to be encrypted is
multiple of 16 (16/32/48...),the length of encryted data is equal to the
raw data. There is no padding and the bug is triggerd.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1712027

Title:
  qemu: Cryptography adding encrypted disk with luks format failed

Status in QEMU:
  New

Bug description:
  I'm using libvirt to attach luks encrypted disk to a running VM. The
  qemu-monitor-command like the

  following:

  {"execute":"object-add","arguments":{"qom-type":"secret","id":"virtio-
  disk11-luks-
  
secret0","props":{"data":"El7jOYLCZwrij2Mue0q2tA==","keyid":"masterKey0","iv":"J2je0WJjCa89L3iKc1lceg==","format":"base64"}}

  the masterKey0 specify the secret which has been created before.

  command above return with error message "Incorrect number of padding
  bytes XXX found on decrypted

  data". This is triggered by the following code snippets in 
qemu/crypto/secret.c:
   
  if (plaintext[ciphertextlen - 1] > 16 ||
   plaintext[ciphertextlen - 1] > ciphertextlen) {
   error_setg(errp, "Incorrect number of padding bytes (%d) "
   "found on decrypted data",
   (int)plaintext[ciphertextlen - 1]); 
 …
   }

  The bug is: There is on padding in plaintext if the actual length of
  the plaintext  decrypted is

  equal to ciphertext.

  In this case, the last element in plaintext array may be one of the
  character in base64 code table

  or other.

  I would like to know why length of padding bytes cannot exceed 16 and
  whether i can remove

  judement: “plaintext[ciphertextlen - 1] > 16” so that I can eliminate
  the error above.

  Much appreciate it if doubts above is cleared up.

  libvirt/qemu version:

  # virsh version
  Compiled against library: libvirt 3.0.0
  Using library: libvirt 3.0.0
  Using API: QEMU 3.0.0
  Running hypervisor: QEMU 2.7.1

  OS: Ubuntu 12.04 LTS

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1712027/+subscriptions



[Qemu-devel] [PATCH QEMU] xen/pt: allow QEMU to request MSI unmasking at bind time

2017-08-24 Thread Roger Pau Monne
When a MSIX interrupt is bound to a guest using
xc_domain_update_msi_irq (XEN_DOMCTL_bind_pt_irq) the interrupt is
left masked by default.

This causes problems with guests that first configure interrupts and
clean the per-entry MSIX table mask bit and afterwards enable MSIX
globally. In such scenario the Xen internal msixtbl handlers would not
detect the unmasking of MSIX entries because vectors are not yet
registered since MSIX is not enabled, and vectors would be left
masked.

Introduce a new flag in the gflags field to signal Xen whether a MSIX
interrupt should be unmasked after being bound.

Signed-off-by: Roger Pau Monné 
Reported-by: Andreas Kinzler 
---
Cc: Stefano Stabellini 
Cc: Anthony Perard 
Cc: Jan Beulich 
Cc: qemu-devel@nongnu.org
---
 hw/xen/xen_pt_msi.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/hw/xen/xen_pt_msi.c b/hw/xen/xen_pt_msi.c
index ff9a79f5d2..c00ac2fd7d 100644
--- a/hw/xen/xen_pt_msi.c
+++ b/hw/xen/xen_pt_msi.c
@@ -24,6 +24,7 @@
 #define XEN_PT_GFLAGS_SHIFT_DM 9
 #define XEN_PT_GFLAGSSHIFT_DELIV_MODE 12
 #define XEN_PT_GFLAGSSHIFT_TRG_MODE   15
+#define XEN_PT_GFLAGSSHIFT_UNMASKED   16
 
 #define latch(fld) latch[PCI_MSIX_ENTRY_##fld / sizeof(uint32_t)]
 
@@ -155,7 +156,8 @@ static int msi_msix_update(XenPCIPassthroughState *s,
int pirq,
bool is_msix,
int msix_entry,
-   int *old_pirq)
+   int *old_pirq,
+   bool masked)
 {
 PCIDevice *d = &s->dev;
 uint8_t gvec = msi_vector(data);
@@ -171,6 +173,8 @@ static int msi_msix_update(XenPCIPassthroughState *s,
 table_addr = s->msix->mmio_base_addr;
 }
 
+gflags |= masked ? 0 : (1u << XEN_PT_GFLAGSSHIFT_UNMASKED);
+
 rc = xc_domain_update_msi_irq(xen_xc, xen_domid, gvec,
   pirq, gflags, table_addr);
 
@@ -274,7 +278,7 @@ int xen_pt_msi_update(XenPCIPassthroughState *s)
 {
 XenPTMSI *msi = s->msi;
 return msi_msix_update(s, msi_addr64(msi), msi->data, msi->pirq,
-   false, 0, &msi->pirq);
+   false, 0, &msi->pirq, false);
 }
 
 void xen_pt_msi_disable(XenPCIPassthroughState *s)
@@ -355,7 +359,8 @@ static int xen_pt_msix_update_one(XenPCIPassthroughState 
*s, int entry_nr,
 }
 
 rc = msi_msix_update(s, entry->addr, entry->data, pirq, true,
- entry_nr, &entry->pirq);
+ entry_nr, &entry->pirq,
+ vec_ctrl & PCI_MSIX_ENTRY_CTRL_MASKBIT);
 
 if (!rc) {
 entry->updated = false;
-- 
2.11.0 (Apple Git-81)




Re: [Qemu-devel] [Qemu-block] [PATCH v5 08/13] tests: Rely more on global_qtest

2017-08-24 Thread Paolo Bonzini
On 24/08/2017 12:09, Markus Armbruster wrote:
> Cut-and-paste cuts both ways (pardon the pun):
> 
> initialize with QTestState A
> frobnicate with QTestState A
> glomnify with QTestState A
> frobnicate with QTestState A
> initialize with QTestState B
> boingboing with QTestState B
> finalize with QTestState A
> finalize with QTestState A
> 
> Uh, forgot to frobnicate after boingboing, let me fix that real quick!
> 
> initialize with QTestState A
> frobnicate with QTestState A
> glomnify with QTestState A
> frobnicate with QTestState A
> initialize with QTestState B
> boingboing with QTestState B
> frobnicate with QTestState A
> finalize with QTestState A
> finalize with QTestState A
> 
> Spot the pasto.
>
> This hasty paste would simply work with global_qtest.  I'm not claiming
> there are cases that are just the opposite.  I'm just challenging your
> apparent claim that the long forms help with avoiding or catching
> pastos.  Can you explain how they help more than they hurt?

A pasto without global_qtest is local.

But cut-and-paste that involves _assigning_ global_qtest, even if it
doesn't have cut-and-paste mistakes, may create a mess of functions
knowing^Wbelieving they know what global_qtest is.

Assigning global_qtest means the short-form functions have effectively
dynamic binding.  In a perfect world, global_qtest would be static and
the create-and-assign-global would assert(!global_qtest).  Then >1 VM ->
don't use the short forms.

Paolo

> A bit of global state isn't automatically bad.  *Shared* global state is
> what gets us into trouble.  Can you point to examples where global_qtest
> is shared in ways that aren't 100% trivial?




Re: [Qemu-devel] AVMF & OVMF blobs in QEMU tree???

2017-08-24 Thread Gerd Hoffmann
  Hi,

> > How big?
> 
> The ArmVirtQemu firmware binary, and its matching varstore template,
> need to be padded to 64MB each, after the edk2 build process
> completes,
> before the fw binary, and a variable store created from the varstore
> template, can be passed to QEMU.
> 
> So, "pretty big".

Most of it is zeros though, so it wouldn't change on updates.
Actual content is almost 3MB (code + vars template combined).

cheers,
  Gerd




Re: [Qemu-devel] [PATCH for-2.11] hw/s390x/s390-skeys: Mark the storage key devices with user_creatable = false

2017-08-24 Thread Claudio Imbrenda
On Thu, 24 Aug 2017 12:08:48 +0200
Thomas Huth  wrote:

> QEMU currently aborts if the user tries to create a skey device:
> 
> $ s390x-softmmu/qemu-system-s390x -nographic -device s390-skeys-qemu
> qemu-system-s390x: hw/s390x/s390-skeys.c:30: s390_get_skeys_device:
>  Assertion `ss' failed.
> Aborted (core dumped)
> 
> The storage key devices are only meant to be instantiated one time,
> internally. They can not be used by the user, so mark them with
> user_creatable = false.
> 
> Signed-off-by: Thomas Huth 
> ---
>  hw/s390x/s390-skeys-kvm.c | 4 
>  hw/s390x/s390-skeys.c | 4 
>  2 files changed, 8 insertions(+)
> 
> diff --git a/hw/s390x/s390-skeys-kvm.c b/hw/s390x/s390-skeys-kvm.c
> index 131da56..dc54ed8 100644
> --- a/hw/s390x/s390-skeys-kvm.c
> +++ b/hw/s390x/s390-skeys-kvm.c
> @@ -54,10 +54,14 @@ static int kvm_s390_skeys_set(S390SKeysState *ss,
> uint64_t start_gfn, static void kvm_s390_skeys_class_init(ObjectClass
> *oc, void *data) {
>  S390SKeysClass *skeyclass = S390_SKEYS_CLASS(oc);
> +DeviceClass *dc = DEVICE_CLASS(oc);
> 
>  skeyclass->skeys_enabled = kvm_s390_skeys_enabled;
>  skeyclass->get_skeys = kvm_s390_skeys_get;
>  skeyclass->set_skeys = kvm_s390_skeys_set;
> +
> +/* Reason: Internal device (only one skeys device for the whole
> memory) */
> +dc->user_creatable = false;
>  }
> 
>  static const TypeInfo kvm_s390_skeys_info = {
> diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c
> index c0de3b0..53ad5d3 100644
> --- a/hw/s390x/s390-skeys.c
> +++ b/hw/s390x/s390-skeys.c
> @@ -229,10 +229,14 @@ static int qemu_s390_skeys_get(S390SKeysState
> *ss, uint64_t start_gfn, static void
> qemu_s390_skeys_class_init(ObjectClass *oc, void *data) {
>  S390SKeysClass *skeyclass = S390_SKEYS_CLASS(oc);
> +DeviceClass *dc = DEVICE_CLASS(oc);
> 
>  skeyclass->skeys_enabled = qemu_s390_skeys_enabled;
>  skeyclass->get_skeys = qemu_s390_skeys_get;
>  skeyclass->set_skeys = qemu_s390_skeys_set;
> +
> +/* Reason: Internal device (only one skeys device for the whole
> memory) */
> +dc->user_creatable = false;
>  }
> 
>  static const TypeInfo qemu_s390_skeys_info = {

Reviewed-by: Claudio Imbrenda 

we probably need something like this for the storage attributes
device too




[Qemu-devel] [PATCH 01/14] qdict: add qdict_put_null() helper

2017-08-24 Thread Marc-André Lureau
A step towards completeness.

Signed-off-by: Marc-André Lureau 
---
 include/qapi/qmp/qdict.h | 4 +++-
 target/i386/cpu.c| 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h
index 363e431106..6588c7f0c8 100644
--- a/include/qapi/qmp/qdict.h
+++ b/include/qapi/qmp/qdict.h
@@ -53,13 +53,15 @@ void qdict_destroy_obj(QObject *obj);
 #define qdict_put(qdict, key, obj) \
 qdict_put_obj(qdict, key, QOBJECT(obj))
 
-/* Helpers for int, bool, and string */
+/* Helpers for int, bool, null, and string */
 #define qdict_put_int(qdict, key, value) \
 qdict_put(qdict, key, qnum_from_int(value))
 #define qdict_put_bool(qdict, key, value) \
 qdict_put(qdict, key, qbool_from_bool(value))
 #define qdict_put_str(qdict, key, value) \
 qdict_put(qdict, key, qstring_from_str(value))
+#define qdict_put_null(qdict, key) \
+qdict_put(qdict, key, qnull())
 
 /* High level helpers */
 double qdict_get_double(const QDict *qdict, const char *key);
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ddc45abd70..bec2009a9c 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -2454,7 +2454,7 @@ static QDict *x86_cpu_static_props(void)
 
 d = qdict_new();
 for (i = 0; props[i]; i++) {
-qdict_put(d, props[i], qnull());
+qdict_put_null(d, props[i]);
 }
 
 for (w = 0; w < FEATURE_WORDS; w++) {
@@ -2464,7 +2464,7 @@ static QDict *x86_cpu_static_props(void)
 if (!fi->feat_names[bit]) {
 continue;
 }
-qdict_put(d, fi->feat_names[bit], qnull());
+qdict_put_null(d, fi->feat_names[bit]);
 }
 }
 
-- 
2.14.1.146.gd35faa819




[Qemu-devel] [PATCH 00/14] Generate a literal qobject for introspection

2017-08-24 Thread Marc-André Lureau
Hi,

This series is based on patches 2-5 from "[PATCH v2 00/54] qapi: add #if
pre-processor conditions to generated code". Generating a literal qobject
will allow to easily introduce #if conditionals from the original series.

Marc-André Lureau (14):
  qdict: add qdict_put_null() helper
  qlit: move qlit from check-qjson to qobject/
  qlit: use QLit prefix consistently
  qlit: remove needless type cast
  qlit: rename compare_litqobj_to_qobj
  qlit: make qlit_equal_qobject return a bool
  qlit: make qlit_equal_qobject() take const arguments
  qlit: add QLIT_QNULL and QLIT_BOOL
  qlit: replace assert(qnum_get_try_int)
  tests: add qlit tests
  qlit: improve QLit dict vs qdict comparison
  qlit: improve QLit list vs qlist comparison
  qlit: add qobject_form_qlit()
  qapi: generate a literal qobject for introspection

 scripts/qapi-introspect.py |  87 +++-
 include/qapi/qmp/qdict.h   |   4 +-
 include/qapi/qmp/qlit.h|  56 +
 monitor.c  |   2 +-
 qobject/qlit.c | 157 +
 target/i386/cpu.c  |   4 +-
 tests/check-qjson.c| 150 +++
 tests/check-qlit.c | 100 +++
 tests/test-qobject-input-visitor.c |  11 ++-
 docs/devel/qapi-code-gen.txt   |  29 ---
 qobject/Makefile.objs  |   2 +-
 tests/Makefile.include |   5 +-
 12 files changed, 429 insertions(+), 178 deletions(-)
 create mode 100644 include/qapi/qmp/qlit.h
 create mode 100644 qobject/qlit.c
 create mode 100644 tests/check-qlit.c

-- 
2.14.1.146.gd35faa819




[Qemu-devel] [PATCH 05/14] qlit: rename compare_litqobj_to_qobj

2017-08-24 Thread Marc-André Lureau
Use qlit_ prefix.

Signed-off-by: Marc-André Lureau 
---
 include/qapi/qmp/qlit.h |  2 +-
 qobject/qlit.c  |  6 +++---
 tests/check-qjson.c | 14 +++---
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h
index 1e9696988a..e299e8fab0 100644
--- a/include/qapi/qmp/qlit.h
+++ b/include/qapi/qmp/qlit.h
@@ -44,6 +44,6 @@ struct QLitDictEntry {
 #define QLIT_QLIST(val) \
 { .type = QTYPE_QLIST, .value.qlist = (val) }
 
-int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs);
+int qlit_equal_qobject(QLitObject *lhs, QObject *rhs);
 
 #endif /* QLIT_H_ */
diff --git a/qobject/qlit.c b/qobject/qlit.c
index 262d64988d..0c4101898d 100644
--- a/qobject/qlit.c
+++ b/qobject/qlit.c
@@ -38,10 +38,10 @@ static void compare_helper(QObject *obj, void *opaque)
 }
 
 helper->result =
-compare_litqobj_to_qobj(&helper->objs[helper->index++], obj);
+qlit_equal_qobject(&helper->objs[helper->index++], obj);
 }
 
-int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs)
+int qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
 {
 int64_t val;
 
@@ -63,7 +63,7 @@ int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs)
 QObject *obj = qdict_get(qobject_to_qdict(rhs),
  lhs->value.qdict[i].key);
 
-if (!compare_litqobj_to_qobj(&lhs->value.qdict[i].value, obj)) {
+if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) {
 return 0;
 }
 }
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 82b3681327..e5ca273cbc 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -1094,13 +1094,13 @@ static void simple_dict(void)
 QString *str;
 
 obj = qobject_from_json(test_cases[i].encoded, &error_abort);
-g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
 
 str = qobject_to_json(obj);
 qobject_decref(obj);
 
 obj = qobject_from_json(qstring_get_str(str), &error_abort);
-g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
 qobject_decref(obj);
 QDECREF(str);
 }
@@ -1203,13 +1203,13 @@ static void simple_list(void)
 QString *str;
 
 obj = qobject_from_json(test_cases[i].encoded, &error_abort);
-g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
 
 str = qobject_to_json(obj);
 qobject_decref(obj);
 
 obj = qobject_from_json(qstring_get_str(str), &error_abort);
-g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
 qobject_decref(obj);
 QDECREF(str);
 }
@@ -1265,13 +1265,13 @@ static void simple_whitespace(void)
 QString *str;
 
 obj = qobject_from_json(test_cases[i].encoded, &error_abort);
-g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
 
 str = qobject_to_json(obj);
 qobject_decref(obj);
 
 obj = qobject_from_json(qstring_get_str(str), &error_abort);
-g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
 
 qobject_decref(obj);
 QDECREF(str);
@@ -1295,7 +1295,7 @@ static void simple_varargs(void)
 g_assert(embedded_obj != NULL);
 
 obj = qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj);
-g_assert(compare_litqobj_to_qobj(&decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&decoded, obj) == 1);
 
 qobject_decref(obj);
 }
-- 
2.14.1.146.gd35faa819




[Qemu-devel] [PATCH 02/14] qlit: move qlit from check-qjson to qobject/

2017-08-24 Thread Marc-André Lureau
Fix code style issues while at it, to please check-patch.

Signed-off-by: Marc-André Lureau 
---
 include/qapi/qmp/qlit.h | 49 +
 qobject/qlit.c  | 89 +
 tests/check-qjson.c | 96 +
 qobject/Makefile.objs   |  2 +-
 4 files changed, 140 insertions(+), 96 deletions(-)
 create mode 100644 include/qapi/qmp/qlit.h
 create mode 100644 qobject/qlit.c

diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h
new file mode 100644
index 00..4e2e760ef1
--- /dev/null
+++ b/include/qapi/qmp/qlit.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright IBM, Corp. 2009
+ * Copyright (c) 2013, 2015, 2017 Red Hat Inc.
+ *
+ * Authors:
+ *  Anthony Liguori   
+ *  Markus Armbruster 
+ *  Marc-André Lureau 
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+#ifndef QLIT_H_
+#define QLIT_H_
+
+#include "qapi-types.h"
+#include "qobject.h"
+
+typedef struct LiteralQDictEntry LiteralQDictEntry;
+typedef struct LiteralQObject LiteralQObject;
+
+struct LiteralQObject {
+int type;
+union {
+int64_t qnum;
+const char *qstr;
+LiteralQDictEntry *qdict;
+LiteralQObject *qlist;
+} value;
+};
+
+struct LiteralQDictEntry {
+const char *key;
+LiteralQObject value;
+};
+
+#define QLIT_QNUM(val) \
+(LiteralQObject){.type = QTYPE_QNUM, .value.qnum = (val)}
+#define QLIT_QSTR(val) \
+(LiteralQObject){.type = QTYPE_QSTRING, .value.qstr = (val)}
+#define QLIT_QDICT(val) \
+(LiteralQObject){.type = QTYPE_QDICT, .value.qdict = (val)}
+#define QLIT_QLIST(val) \
+(LiteralQObject){.type = QTYPE_QLIST, .value.qlist = (val)}
+
+int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs);
+
+#endif /* QLIT_H_ */
diff --git a/qobject/qlit.c b/qobject/qlit.c
new file mode 100644
index 00..5917c3584e
--- /dev/null
+++ b/qobject/qlit.c
@@ -0,0 +1,89 @@
+/*
+ * QLit literal qobject
+ *
+ * Copyright IBM, Corp. 2009
+ * Copyright (c) 2013, 2015, 2017 Red Hat Inc.
+ *
+ * Authors:
+ *  Anthony Liguori   
+ *  Markus Armbruster 
+ *  Marc-André Lureau 
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+
+#include "qapi/qmp/qlit.h"
+#include "qapi/qmp/types.h"
+
+typedef struct QListCompareHelper {
+int index;
+LiteralQObject *objs;
+int result;
+} QListCompareHelper;
+
+static void compare_helper(QObject *obj, void *opaque)
+{
+QListCompareHelper *helper = opaque;
+
+if (helper->result == 0) {
+return;
+}
+
+if (helper->objs[helper->index].type == QTYPE_NONE) {
+helper->result = 0;
+return;
+}
+
+helper->result =
+compare_litqobj_to_qobj(&helper->objs[helper->index++], obj);
+}
+
+int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs)
+{
+int64_t val;
+
+if (!rhs || lhs->type != qobject_type(rhs)) {
+return 0;
+}
+
+switch (lhs->type) {
+case QTYPE_QNUM:
+g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val));
+return lhs->value.qnum == val;
+case QTYPE_QSTRING:
+return (strcmp(lhs->value.qstr,
+   qstring_get_str(qobject_to_qstring(rhs))) == 0);
+case QTYPE_QDICT: {
+int i;
+
+for (i = 0; lhs->value.qdict[i].key; i++) {
+QObject *obj = qdict_get(qobject_to_qdict(rhs),
+ lhs->value.qdict[i].key);
+
+if (!compare_litqobj_to_qobj(&lhs->value.qdict[i].value, obj)) {
+return 0;
+}
+}
+
+return 1;
+}
+case QTYPE_QLIST: {
+QListCompareHelper helper;
+
+helper.index = 0;
+helper.objs = lhs->value.qlist;
+helper.result = 1;
+
+qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper);
+
+return helper.result;
+}
+default:
+break;
+}
+
+return 0;
+}
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index a3a97b0d99..525f79e60b 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -16,6 +16,7 @@
 #include "qapi/error.h"
 #include "qapi/qmp/types.h"
 #include "qapi/qmp/qjson.h"
+#include "qapi/qmp/qlit.h"
 #include "qemu-common.h"
 
 static void escaped_string(void)
@@ -1059,101 +1060,6 @@ static void keyword_literal(void)
 QDECREF(null);
 }
 
-typedef struct LiteralQDictEntry LiteralQDictEntry;
-typedef struct LiteralQObject LiteralQObject;
-
-struct LiteralQObject
-{
-int type;
-union {
-int64_t qnum;
-const char *qstr;
-LiteralQDictEntry *qdict;
-LiteralQObject *qlist;
-} value;
-};
-
-struct LiteralQDictEntry
-{
-const char *key;
-LiteralQObject value;
-};
-
-#define QLIT_QNUM(val) (LiteralQObject){.type = QTYPE_QNUM, .value.qnum =

[Qemu-devel] [PATCH 07/14] qlit: make qlit_equal_qobject() take const arguments

2017-08-24 Thread Marc-André Lureau
Signed-off-by: Marc-André Lureau 
---
 include/qapi/qmp/qlit.h | 2 +-
 qobject/qlit.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h
index 2e22d0f73c..8882016199 100644
--- a/include/qapi/qmp/qlit.h
+++ b/include/qapi/qmp/qlit.h
@@ -44,6 +44,6 @@ struct QLitDictEntry {
 #define QLIT_QLIST(val) \
 { .type = QTYPE_QLIST, .value.qlist = (val) }
 
-bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs);
+bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs);
 
 #endif /* QLIT_H_ */
diff --git a/qobject/qlit.c b/qobject/qlit.c
index a2975bef3f..ae2787ef35 100644
--- a/qobject/qlit.c
+++ b/qobject/qlit.c
@@ -41,7 +41,7 @@ static void compare_helper(QObject *obj, void *opaque)
 qlit_equal_qobject(&helper->objs[helper->index++], obj);
 }
 
-bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
+bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
 {
 int64_t val;
 
-- 
2.14.1.146.gd35faa819




[Qemu-devel] [PATCH 03/14] qlit: use QLit prefix consistently

2017-08-24 Thread Marc-André Lureau
Rename from LiteralQ to QLit.

Signed-off-by: Marc-André Lureau 
---
 include/qapi/qmp/qlit.h | 24 
 qobject/qlit.c  |  4 ++--
 tests/check-qjson.c | 40 
 3 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h
index 4e2e760ef1..f36bca4554 100644
--- a/include/qapi/qmp/qlit.h
+++ b/include/qapi/qmp/qlit.h
@@ -17,33 +17,33 @@
 #include "qapi-types.h"
 #include "qobject.h"
 
-typedef struct LiteralQDictEntry LiteralQDictEntry;
-typedef struct LiteralQObject LiteralQObject;
+typedef struct QLitDictEntry QLitDictEntry;
+typedef struct QLitObject QLitObject;
 
-struct LiteralQObject {
+struct QLitObject {
 int type;
 union {
 int64_t qnum;
 const char *qstr;
-LiteralQDictEntry *qdict;
-LiteralQObject *qlist;
+QLitDictEntry *qdict;
+QLitObject *qlist;
 } value;
 };
 
-struct LiteralQDictEntry {
+struct QLitDictEntry {
 const char *key;
-LiteralQObject value;
+QLitObject value;
 };
 
 #define QLIT_QNUM(val) \
-(LiteralQObject){.type = QTYPE_QNUM, .value.qnum = (val)}
+(QLitObject){.type = QTYPE_QNUM, .value.qnum = (val)}
 #define QLIT_QSTR(val) \
-(LiteralQObject){.type = QTYPE_QSTRING, .value.qstr = (val)}
+(QLitObject){.type = QTYPE_QSTRING, .value.qstr = (val)}
 #define QLIT_QDICT(val) \
-(LiteralQObject){.type = QTYPE_QDICT, .value.qdict = (val)}
+(QLitObject){.type = QTYPE_QDICT, .value.qdict = (val)}
 #define QLIT_QLIST(val) \
-(LiteralQObject){.type = QTYPE_QLIST, .value.qlist = (val)}
+(QLitObject){.type = QTYPE_QLIST, .value.qlist = (val)}
 
-int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs);
+int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs);
 
 #endif /* QLIT_H_ */
diff --git a/qobject/qlit.c b/qobject/qlit.c
index 5917c3584e..262d64988d 100644
--- a/qobject/qlit.c
+++ b/qobject/qlit.c
@@ -20,7 +20,7 @@
 
 typedef struct QListCompareHelper {
 int index;
-LiteralQObject *objs;
+QLitObject *objs;
 int result;
 } QListCompareHelper;
 
@@ -41,7 +41,7 @@ static void compare_helper(QObject *obj, void *opaque)
 compare_litqobj_to_qobj(&helper->objs[helper->index++], obj);
 }
 
-int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs)
+int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs)
 {
 int64_t val;
 
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 525f79e60b..82b3681327 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -1065,23 +1065,23 @@ static void simple_dict(void)
 int i;
 struct {
 const char *encoded;
-LiteralQObject decoded;
+QLitObject decoded;
 } test_cases[] = {
 {
 .encoded = "{\"foo\": 42, \"bar\": \"hello world\"}",
-.decoded = QLIT_QDICT(((LiteralQDictEntry[]){
+.decoded = QLIT_QDICT(((QLitDictEntry[]){
 { "foo", QLIT_QNUM(42) },
 { "bar", QLIT_QSTR("hello world") },
 { }
 })),
 }, {
 .encoded = "{}",
-.decoded = QLIT_QDICT(((LiteralQDictEntry[]){
+.decoded = QLIT_QDICT(((QLitDictEntry[]){
 { }
 })),
 }, {
 .encoded = "{\"foo\": 43}",
-.decoded = QLIT_QDICT(((LiteralQDictEntry[]){
+.decoded = QLIT_QDICT(((QLitDictEntry[]){
 { "foo", QLIT_QNUM(43) },
 { }
 })),
@@ -1163,11 +1163,11 @@ static void simple_list(void)
 int i;
 struct {
 const char *encoded;
-LiteralQObject decoded;
+QLitObject decoded;
 } test_cases[] = {
 {
 .encoded = "[43,42]",
-.decoded = QLIT_QLIST(((LiteralQObject[]){
+.decoded = QLIT_QLIST(((QLitObject[]){
 QLIT_QNUM(43),
 QLIT_QNUM(42),
 { }
@@ -1175,21 +1175,21 @@ static void simple_list(void)
 },
 {
 .encoded = "[43]",
-.decoded = QLIT_QLIST(((LiteralQObject[]){
+.decoded = QLIT_QLIST(((QLitObject[]){
 QLIT_QNUM(43),
 { }
 })),
 },
 {
 .encoded = "[]",
-.decoded = QLIT_QLIST(((LiteralQObject[]){
+.decoded = QLIT_QLIST(((QLitObject[]){
 { }
 })),
 },
 {
 .encoded = "[{}]",
-.decoded = QLIT_QLIST(((LiteralQObject[]){
-QLIT_QDICT(((LiteralQDictEntry[]){
+.decoded = QLIT_QLIST(((QLitObject[]){
+QLIT_QDICT(((QLitDictEntry[]){
 {},
 })),
  

[Qemu-devel] [PATCH 04/14] qlit: remove needless type cast

2017-08-24 Thread Marc-André Lureau
And misc code style fix.

Signed-off-by: Marc-André Lureau 
---
 include/qapi/qmp/qlit.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h
index f36bca4554..1e9696988a 100644
--- a/include/qapi/qmp/qlit.h
+++ b/include/qapi/qmp/qlit.h
@@ -36,13 +36,13 @@ struct QLitDictEntry {
 };
 
 #define QLIT_QNUM(val) \
-(QLitObject){.type = QTYPE_QNUM, .value.qnum = (val)}
+{ .type = QTYPE_QNUM, .value.qnum = (val) }
 #define QLIT_QSTR(val) \
-(QLitObject){.type = QTYPE_QSTRING, .value.qstr = (val)}
+{ .type = QTYPE_QSTRING, .value.qstr = (val) }
 #define QLIT_QDICT(val) \
-(QLitObject){.type = QTYPE_QDICT, .value.qdict = (val)}
+{ .type = QTYPE_QDICT, .value.qdict = (val) }
 #define QLIT_QLIST(val) \
-(QLitObject){.type = QTYPE_QLIST, .value.qlist = (val)}
+{ .type = QTYPE_QLIST, .value.qlist = (val) }
 
 int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs);
 
-- 
2.14.1.146.gd35faa819




[Qemu-devel] [PATCH 08/14] qlit: add QLIT_QNULL and QLIT_BOOL

2017-08-24 Thread Marc-André Lureau
As they are going to be used in the following patches.

Signed-off-by: Marc-André Lureau 
---
 include/qapi/qmp/qlit.h | 5 +
 qobject/qlit.c  | 4 
 2 files changed, 9 insertions(+)

diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h
index 8882016199..7118fc9e32 100644
--- a/include/qapi/qmp/qlit.h
+++ b/include/qapi/qmp/qlit.h
@@ -23,6 +23,7 @@ typedef struct QLitObject QLitObject;
 struct QLitObject {
 int type;
 union {
+bool qbool;
 int64_t qnum;
 const char *qstr;
 QLitDictEntry *qdict;
@@ -35,6 +36,10 @@ struct QLitDictEntry {
 QLitObject value;
 };
 
+#define QLIT_QNULL \
+{ .type = QTYPE_QNULL }
+#define QLIT_QBOOL(val) \
+{ .type = QTYPE_QBOOL, .value.qbool = (val) }
 #define QLIT_QNUM(val) \
 { .type = QTYPE_QNUM, .value.qnum = (val) }
 #define QLIT_QSTR(val) \
diff --git a/qobject/qlit.c b/qobject/qlit.c
index ae2787ef35..07ad6b05e8 100644
--- a/qobject/qlit.c
+++ b/qobject/qlit.c
@@ -50,6 +50,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject 
*rhs)
 }
 
 switch (lhs->type) {
+case QTYPE_QBOOL:
+return lhs->value.qbool == qbool_get_bool(qobject_to_qbool(rhs));
 case QTYPE_QNUM:
 g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val));
 return lhs->value.qnum == val;
@@ -81,6 +83,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject 
*rhs)
 
 return helper.result;
 }
+case QTYPE_QNULL:
+return true;
 default:
 break;
 }
-- 
2.14.1.146.gd35faa819




[Qemu-devel] [PATCH 06/14] qlit: make qlit_equal_qobject return a bool

2017-08-24 Thread Marc-André Lureau
Make it more obvious about the expected return values.

Signed-off-by: Marc-André Lureau 
---
 include/qapi/qmp/qlit.h |  2 +-
 qobject/qlit.c  | 18 +-
 tests/check-qjson.c | 14 +++---
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h
index e299e8fab0..2e22d0f73c 100644
--- a/include/qapi/qmp/qlit.h
+++ b/include/qapi/qmp/qlit.h
@@ -44,6 +44,6 @@ struct QLitDictEntry {
 #define QLIT_QLIST(val) \
 { .type = QTYPE_QLIST, .value.qlist = (val) }
 
-int qlit_equal_qobject(QLitObject *lhs, QObject *rhs);
+bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs);
 
 #endif /* QLIT_H_ */
diff --git a/qobject/qlit.c b/qobject/qlit.c
index 0c4101898d..a2975bef3f 100644
--- a/qobject/qlit.c
+++ b/qobject/qlit.c
@@ -21,19 +21,19 @@
 typedef struct QListCompareHelper {
 int index;
 QLitObject *objs;
-int result;
+bool result;
 } QListCompareHelper;
 
 static void compare_helper(QObject *obj, void *opaque)
 {
 QListCompareHelper *helper = opaque;
 
-if (helper->result == 0) {
+if (!helper->result) {
 return;
 }
 
 if (helper->objs[helper->index].type == QTYPE_NONE) {
-helper->result = 0;
+helper->result = false;
 return;
 }
 
@@ -41,12 +41,12 @@ static void compare_helper(QObject *obj, void *opaque)
 qlit_equal_qobject(&helper->objs[helper->index++], obj);
 }
 
-int qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
+bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
 {
 int64_t val;
 
 if (!rhs || lhs->type != qobject_type(rhs)) {
-return 0;
+return false;
 }
 
 switch (lhs->type) {
@@ -64,18 +64,18 @@ int qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
  lhs->value.qdict[i].key);
 
 if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) {
-return 0;
+return false;
 }
 }
 
-return 1;
+return true;
 }
 case QTYPE_QLIST: {
 QListCompareHelper helper;
 
 helper.index = 0;
 helper.objs = lhs->value.qlist;
-helper.result = 1;
+helper.result = true;
 
 qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper);
 
@@ -85,5 +85,5 @@ int qlit_equal_qobject(QLitObject *lhs, QObject *rhs)
 break;
 }
 
-return 0;
+return false;
 }
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index e5ca273cbc..59227934ce 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -1094,13 +1094,13 @@ static void simple_dict(void)
 QString *str;
 
 obj = qobject_from_json(test_cases[i].encoded, &error_abort);
-g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
 
 str = qobject_to_json(obj);
 qobject_decref(obj);
 
 obj = qobject_from_json(qstring_get_str(str), &error_abort);
-g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
 qobject_decref(obj);
 QDECREF(str);
 }
@@ -1203,13 +1203,13 @@ static void simple_list(void)
 QString *str;
 
 obj = qobject_from_json(test_cases[i].encoded, &error_abort);
-g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
 
 str = qobject_to_json(obj);
 qobject_decref(obj);
 
 obj = qobject_from_json(qstring_get_str(str), &error_abort);
-g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
 qobject_decref(obj);
 QDECREF(str);
 }
@@ -1265,13 +1265,13 @@ static void simple_whitespace(void)
 QString *str;
 
 obj = qobject_from_json(test_cases[i].encoded, &error_abort);
-g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
 
 str = qobject_to_json(obj);
 qobject_decref(obj);
 
 obj = qobject_from_json(qstring_get_str(str), &error_abort);
-g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
 
 qobject_decref(obj);
 QDECREF(str);
@@ -1295,7 +1295,7 @@ static void simple_varargs(void)
 g_assert(embedded_obj != NULL);
 
 obj = qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj);
-g_assert(qlit_equal_qobject(&decoded, obj) == 1);
+g_assert(qlit_equal_qobject(&decoded, obj));
 
 qobject_decref(obj);
 }
-- 
2.14.1.146.gd35faa819




[Qemu-devel] [PATCH 11/14] qlit: improve QLit dict vs qdict comparison

2017-08-24 Thread Marc-André Lureau
Fail if the QLit dict doesn't match exactly the object dict.

To do so, create a copy of the original qdict, and remove the checked
elements. Verify that the dict is empty by the end of the comparison.

Signed-off-by: Marc-André Lureau 
---
 qobject/qlit.c | 42 --
 tests/check-qlit.c |  7 +++
 2 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/qobject/qlit.c b/qobject/qlit.c
index 7e4bf92862..45ae0635c0 100644
--- a/qobject/qlit.c
+++ b/qobject/qlit.c
@@ -41,6 +41,32 @@ static void compare_helper(QObject *obj, void *opaque)
 qlit_equal_qobject(&helper->objs[helper->index++], obj);
 }
 
+static bool qlit_equal_qdict(const QLitObject *lhs, const QDict *qdict)
+{
+QDict *dict = qdict_clone_shallow(qdict);
+bool success = false;
+int i;
+
+for (i = 0; lhs->value.qdict[i].key; i++) {
+QObject *obj = qdict_get(dict, lhs->value.qdict[i].key);
+
+if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) {
+goto end;
+}
+qdict_del(dict, lhs->value.qdict[i].key);
+}
+
+if (qdict_size(dict) != 0) {
+goto end;
+}
+
+success = true;
+
+end:
+QDECREF(dict);
+return success;
+}
+
 bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
 {
 int64_t val;
@@ -58,20 +84,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject 
*rhs)
 case QTYPE_QSTRING:
 return (strcmp(lhs->value.qstr,
qstring_get_str(qobject_to_qstring(rhs))) == 0);
-case QTYPE_QDICT: {
-int i;
-
-for (i = 0; lhs->value.qdict[i].key; i++) {
-QObject *obj = qdict_get(qobject_to_qdict(rhs),
- lhs->value.qdict[i].key);
-
-if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) {
-return false;
-}
-}
-
-return true;
-}
+case QTYPE_QDICT:
+return qlit_equal_qdict(lhs, qobject_to_qdict(rhs));
 case QTYPE_QLIST: {
 QListCompareHelper helper;
 
diff --git a/tests/check-qlit.c b/tests/check-qlit.c
index 47fde92a46..5d9558dfd9 100644
--- a/tests/check-qlit.c
+++ b/tests/check-qlit.c
@@ -28,6 +28,11 @@ static QLitObject qlit = QLIT_QDICT(((QLitDictEntry[]) {
 { },
 }));
 
+static QLitObject qlit_foo = QLIT_QDICT(((QLitDictEntry[]) {
+{ "foo", QLIT_QNUM(42) },
+{ },
+}));
+
 static QObject *make_qobject(void)
 {
 QDict *qdict = qdict_new();
@@ -51,6 +56,8 @@ static void qlit_equal_qobject_test(void)
 
 g_assert(qlit_equal_qobject(&qlit, qobj));
 
+g_assert(!qlit_equal_qobject(&qlit_foo, qobj));
+
 qobject_decref(qobj);
 }
 
-- 
2.14.1.146.gd35faa819




Re: [Qemu-devel] [PATCH for-2.11] hw/s390x/s390-skeys: Mark the storage key devices with user_creatable = false

2017-08-24 Thread Halil Pasic


On 08/24/2017 12:08 PM, Thomas Huth wrote:
> QEMU currently aborts if the user tries to create a skey device:
> 
> $ s390x-softmmu/qemu-system-s390x -nographic -device s390-skeys-qemu
> qemu-system-s390x: hw/s390x/s390-skeys.c:30: s390_get_skeys_device:
>  Assertion `ss' failed.
> Aborted (core dumped)
> 
> The storage key devices are only meant to be instantiated one time,
> internally. They can not be used by the user, so mark them with
> user_creatable = false.
> 
> Signed-off-by: Thomas Huth 
> ---
>  hw/s390x/s390-skeys-kvm.c | 4 
>  hw/s390x/s390-skeys.c | 4 
>  2 files changed, 8 insertions(+)
> 
> diff --git a/hw/s390x/s390-skeys-kvm.c b/hw/s390x/s390-skeys-kvm.c
> index 131da56..dc54ed8 100644
> --- a/hw/s390x/s390-skeys-kvm.c
> +++ b/hw/s390x/s390-skeys-kvm.c
> @@ -54,10 +54,14 @@ static int kvm_s390_skeys_set(S390SKeysState *ss, 
> uint64_t start_gfn,
>  static void kvm_s390_skeys_class_init(ObjectClass *oc, void *data)
>  {
>  S390SKeysClass *skeyclass = S390_SKEYS_CLASS(oc);
> +DeviceClass *dc = DEVICE_CLASS(oc);
> 
>  skeyclass->skeys_enabled = kvm_s390_skeys_enabled;
>  skeyclass->get_skeys = kvm_s390_skeys_get;
>  skeyclass->set_skeys = kvm_s390_skeys_set;
> +
> +/* Reason: Internal device (only one skeys device for the whole memory) 
> */
> +dc->user_creatable = false;
>  }
> 
>  static const TypeInfo kvm_s390_skeys_info = {
> diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c
> index c0de3b0..53ad5d3 100644
> --- a/hw/s390x/s390-skeys.c
> +++ b/hw/s390x/s390-skeys.c
> @@ -229,10 +229,14 @@ static int qemu_s390_skeys_get(S390SKeysState *ss, 
> uint64_t start_gfn,
>  static void qemu_s390_skeys_class_init(ObjectClass *oc, void *data)
>  {
>  S390SKeysClass *skeyclass = S390_SKEYS_CLASS(oc);
> +DeviceClass *dc = DEVICE_CLASS(oc);
> 
>  skeyclass->skeys_enabled = qemu_s390_skeys_enabled;
>  skeyclass->get_skeys = qemu_s390_skeys_get;
>  skeyclass->set_skeys = qemu_s390_skeys_set;
> +
> +/* Reason: Internal device (only one skeys device for the whole memory) 
> */
> +dc->user_creatable = false;
>  }
> 
>  static const TypeInfo qemu_s390_skeys_info = {
> 

Reviewed-by: Halil Pasic 




[Qemu-devel] [PATCH 09/14] qlit: replace assert(qnum_get_try_int)

2017-08-24 Thread Marc-André Lureau
qnum_get_int() will assert if underlying type isn't compatible.

Signed-off-by: Marc-André Lureau 
---
 qobject/qlit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qobject/qlit.c b/qobject/qlit.c
index 07ad6b05e8..7e4bf92862 100644
--- a/qobject/qlit.c
+++ b/qobject/qlit.c
@@ -53,7 +53,7 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject 
*rhs)
 case QTYPE_QBOOL:
 return lhs->value.qbool == qbool_get_bool(qobject_to_qbool(rhs));
 case QTYPE_QNUM:
-g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val));
+val = qnum_get_int(qobject_to_qnum(rhs));
 return lhs->value.qnum == val;
 case QTYPE_QSTRING:
 return (strcmp(lhs->value.qstr,
-- 
2.14.1.146.gd35faa819




[Qemu-devel] [PATCH 10/14] tests: add qlit tests

2017-08-24 Thread Marc-André Lureau
Signed-off-by: Marc-André Lureau 
---
 tests/check-qlit.c | 64 ++
 tests/Makefile.include |  5 +++-
 2 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 tests/check-qlit.c

diff --git a/tests/check-qlit.c b/tests/check-qlit.c
new file mode 100644
index 00..47fde92a46
--- /dev/null
+++ b/tests/check-qlit.c
@@ -0,0 +1,64 @@
+/*
+ * QLit unit-tests.
+ *
+ * Copyright (C) 2017 Red Hat Inc.
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+
+#include "qapi/qmp/qbool.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qlit.h"
+#include "qapi/qmp/qnum.h"
+#include "qapi/qmp/qstring.h"
+
+static QLitObject qlit = QLIT_QDICT(((QLitDictEntry[]) {
+{ "foo", QLIT_QNUM(42) },
+{ "bar", QLIT_QSTR("hello world") },
+{ "baz", QLIT_QNULL },
+{ "bee", QLIT_QLIST(((QLitObject[]) {
+QLIT_QNUM(43),
+QLIT_QNUM(44),
+QLIT_QBOOL(true),
+{ },
+}))},
+{ },
+}));
+
+static QObject *make_qobject(void)
+{
+QDict *qdict = qdict_new();
+QList *list = qlist_new();
+
+qdict_put_int(qdict, "foo", 42);
+qdict_put_str(qdict, "bar", "hello world");
+qdict_put_null(qdict, "baz");
+
+qlist_append_int(list, 43);
+qlist_append_int(list, 44);
+qlist_append_bool(list, true);
+qdict_put(qdict, "bee", list);
+
+return QOBJECT(qdict);
+}
+
+static void qlit_equal_qobject_test(void)
+{
+QObject *qobj = make_qobject();
+
+g_assert(qlit_equal_qobject(&qlit, qobj));
+
+qobject_decref(qobj);
+}
+
+int main(int argc, char **argv)
+{
+g_test_init(&argc, &argv, NULL);
+
+g_test_add_func("/qlit/equal_qobject", qlit_equal_qobject_test);
+
+return g_test_run();
+}
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 37c1bed683..3653c7b40a 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -43,6 +43,8 @@ check-unit-y += tests/check-qnull$(EXESUF)
 gcov-files-check-qnull-y = qobject/qnull.c
 check-unit-y += tests/check-qjson$(EXESUF)
 gcov-files-check-qjson-y = qobject/qjson.c
+check-unit-y += tests/check-qlit$(EXESUF)
+gcov-files-check-qlit-y = qobject/qlit.c
 check-unit-y += tests/test-qobject-output-visitor$(EXESUF)
 gcov-files-test-qobject-output-visitor-y = qapi/qobject-output-visitor.c
 check-unit-y += tests/test-clone-visitor$(EXESUF)
@@ -535,7 +537,7 @@ GENERATED_FILES += tests/test-qapi-types.h 
tests/test-qapi-visit.h \
 
 test-obj-y = tests/check-qnum.o tests/check-qstring.o tests/check-qdict.o \
tests/check-qlist.o tests/check-qnull.o \
-   tests/check-qjson.o \
+   tests/check-qjson.o tests/check-qlit.o \
tests/test-coroutine.o tests/test-string-output-visitor.o \
tests/test-string-input-visitor.o tests/test-qobject-output-visitor.o \
tests/test-clone-visitor.o \
@@ -569,6 +571,7 @@ tests/check-qdict$(EXESUF): tests/check-qdict.o 
$(test-util-obj-y)
 tests/check-qlist$(EXESUF): tests/check-qlist.o $(test-util-obj-y)
 tests/check-qnull$(EXESUF): tests/check-qnull.o $(test-util-obj-y)
 tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y)
+tests/check-qlit$(EXESUF): tests/check-qlit.o $(test-util-obj-y)
 tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o 
$(test-qom-obj-y)
 tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y)
 
-- 
2.14.1.146.gd35faa819




Re: [Qemu-devel] [PATCH 01/16] qapi: Update qapi-code-gen.txt examples to match current code

2017-08-24 Thread Marc-André Lureau
On Thu, Aug 24, 2017 at 10:55 AM Markus Armbruster 
wrote:

> Signed-off-by: Markus Armbruster 
>


Reviewed-by: Marc-André Lureau 

(tbh, I find it tedious and not really useful to have generated code in the
doc though)

---
>  docs/devel/qapi-code-gen.txt | 47
> +++-
>  1 file changed, 38 insertions(+), 9 deletions(-)
>
> diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
> index 9903ac4..ae05327 100644
> --- a/docs/devel/qapi-code-gen.txt
> +++ b/docs/devel/qapi-code-gen.txt
> @@ -957,6 +957,8 @@ Example:
>
>  typedef struct UserDefOneList UserDefOneList;
>
> +typedef struct q_obj_my_command_arg q_obj_my_command_arg;
> +
>  struct UserDefOne {
>  int64_t integer;
>  bool has_string;
> @@ -972,6 +974,10 @@ Example:
>
>  void qapi_free_UserDefOneList(UserDefOneList *obj);
>
> +struct q_obj_my_command_arg {
> +UserDefOneList *arg1;
> +};
> +
>  #endif
>  $ cat qapi-generated/example-qapi-types.c
>  [Uninteresting stuff omitted...]
> @@ -1036,6 +1042,8 @@ Example:
>  void visit_type_UserDefOne(Visitor *v, const char *name, UserDefOne
> **obj, Error **errp);
>  void visit_type_UserDefOneList(Visitor *v, const char *name,
> UserDefOneList **obj, Error **errp);
>
> +void visit_type_q_obj_my_command_arg_members(Visitor *v,
> q_obj_my_command_arg *obj, Error **errp);
> +
>  #endif
>  $ cat qapi-generated/example-qapi-visit.c
>  [Uninteresting stuff omitted...]
> @@ -1104,6 +1112,9 @@ Example:
>  }
>  }
>
> +if (!err) {
> +visit_check_list(v, &err);
> +}
>  visit_end_list(v, (void **)obj);
>  if (err && visit_is_input(v)) {
>  qapi_free_UserDefOneList(*obj);
> @@ -1113,6 +1124,19 @@ Example:
>  error_propagate(errp, err);
>  }
>
> +void visit_type_q_obj_my_command_arg_members(Visitor *v,
> q_obj_my_command_arg *obj, Error **errp)
> +{
> +Error *err = NULL;
> +
> +visit_type_UserDefOneList(v, "arg1", &obj->arg1, &err);
> +if (err) {
> +goto out;
> +}
> +
> +out:
> +error_propagate(errp, err);
> +}
> +
>  === scripts/qapi-commands.py ===
>
>  Used to generate the marshaling/dispatch functions for the commands
> @@ -1145,9 +1169,12 @@ Example:
>
>  #include "example-qapi-types.h"
>  #include "qapi/qmp/qdict.h"
> +#include "qapi/qmp/dispatch.h"
>  #include "qapi/error.h"
>
> +void example_qmp_init_marshal(QmpCommandList *cmds);
>  UserDefOne *qmp_my_command(UserDefOneList *arg1, Error **errp);
> +void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp);
>
>  #endif
>  $ cat qapi-generated/example-qmp-marshal.c
> @@ -1170,19 +1197,19 @@ Example:
>  visit_free(v);
>  }
>
> -static void qmp_marshal_my_command(QDict *args, QObject **ret, Error
> **errp)
> +void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp)
>  {
>  Error *err = NULL;
>  UserDefOne *retval;
>  Visitor *v;
> -UserDefOneList *arg1 = NULL;
> +q_obj_my_command_arg arg = {0};
>
>  v = qobject_input_visitor_new(QOBJECT(args));
>  visit_start_struct(v, NULL, NULL, 0, &err);
>  if (err) {
>  goto out;
>  }
> -visit_type_UserDefOneList(v, "arg1", &arg1, &err);
> +visit_type_q_obj_my_command_arg_members(v, &arg, &err);
>  if (!err) {
>  visit_check_struct(v, &err);
>  }
> @@ -1191,7 +1218,7 @@ Example:
>  goto out;
>  }
>
> -retval = qmp_my_command(arg1, &err);
> +retval = qmp_my_command(arg.arg1, &err);
>  if (err) {
>  goto out;
>  }
> @@ -1203,17 +1230,18 @@ Example:
>  visit_free(v);
>  v = qapi_dealloc_visitor_new();
>  visit_start_struct(v, NULL, NULL, 0, NULL);
> -visit_type_UserDefOneList(v, "arg1", &arg1, NULL);
> +visit_type_q_obj_my_command_arg_members(v, &arg, NULL);
>  visit_end_struct(v, NULL);
>  visit_free(v);
>  }
>
> -static void qmp_init_marshal(void)
> +void example_qmp_init_marshal(QmpCommandList *cmds)
>  {
> -qmp_register_command("my-command", qmp_marshal_my_command,
> QCO_NO_OPTIONS);
> -}
> +QTAILQ_INIT(cmds);
>
> -qapi_init(qmp_init_marshal);
> +qmp_register_command(cmds, "my-command",
> + qmp_marshal_my_command, QCO_NO_OPTIONS);
> +}
>
>  === scripts/qapi-event.py ===
>
> @@ -1258,6 +1286,7 @@ Example:
>  QDict *qmp;
>  Error *err = NULL;
>  QMPEventFuncEmit emit;
> +
>  emit = qmp_event_get_func_emit();
>  if (!emit) {
>  return;
> --
> 2.7.5
>
>
> --
Marc-André Lureau


Re: [Qemu-devel] [PATCH QEMU] xen/pt: allow QEMU to request MSI unmasking at bind time

2017-08-24 Thread Roger Pau Monne
On Thu, Aug 24, 2017 at 03:54:21AM -0600, Jan Beulich wrote:
> >>> On 24.08.17 at 11:47,  wrote:
> > @@ -274,7 +278,7 @@ int xen_pt_msi_update(XenPCIPassthroughState *s)
> >  {
> >  XenPTMSI *msi = s->msi;
> >  return msi_msix_update(s, msi_addr64(msi), msi->data, msi->pirq,
> > -   false, 0, &msi->pirq);
> > +   false, 0, &msi->pirq, false);
> >  }
> 
> I don't think this is correct when the device has mask bits.

Right, I thought I modified this. I've already changed
pt_irq_create_bind so that the original behavior is keep if the unmask
bit is not set. In this case this should be 'true' in order to keep
the previous behavior, which was correct for MSI.

It also makes me wonder whether it would be better to change the name
of the parameter to "unmask", so that false -> no change to mask, true
-> unconditionally unmask.

Thanks, Roger.



[Qemu-devel] [PATCH 12/14] qlit: improve QLit list vs qlist comparison

2017-08-24 Thread Marc-André Lureau
Check that the QLit list has the same size as the qlist, this should
ensure that we have an exact match when iterating over qlist for
comparing the elements.

Signed-off-by: Marc-André Lureau 
---
 qobject/qlit.c | 39 ++-
 tests/check-qlit.c |  3 +++
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/qobject/qlit.c b/qobject/qlit.c
index 45ae0635c0..0a60802d74 100644
--- a/qobject/qlit.c
+++ b/qobject/qlit.c
@@ -67,6 +67,28 @@ end:
 return success;
 }
 
+static bool qlit_equal_qlist(const QLitObject *lhs, const QList *qlist)
+{
+QListCompareHelper helper;
+int i;
+
+for (i = 0; lhs->value.qlist[i].type != QTYPE_NONE; i++) {
+continue;
+}
+
+if (qlist_size(qlist) != i) {
+return false;
+}
+
+helper.index = 0;
+helper.objs = lhs->value.qlist;
+helper.result = true;
+
+qlist_iter(qlist, compare_helper, &helper);
+
+return helper.result;
+}
+
 bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
 {
 int64_t val;
@@ -82,21 +104,12 @@ bool qlit_equal_qobject(const QLitObject *lhs, const 
QObject *rhs)
 val = qnum_get_int(qobject_to_qnum(rhs));
 return lhs->value.qnum == val;
 case QTYPE_QSTRING:
-return (strcmp(lhs->value.qstr,
-   qstring_get_str(qobject_to_qstring(rhs))) == 0);
+return g_str_equal(lhs->value.qstr,
+   qstring_get_str(qobject_to_qstring(rhs)));
 case QTYPE_QDICT:
 return qlit_equal_qdict(lhs, qobject_to_qdict(rhs));
-case QTYPE_QLIST: {
-QListCompareHelper helper;
-
-helper.index = 0;
-helper.objs = lhs->value.qlist;
-helper.result = true;
-
-qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper);
-
-return helper.result;
-}
+case QTYPE_QLIST:
+return qlit_equal_qlist(lhs, qobject_to_qlist(rhs));
 case QTYPE_QNULL:
 return true;
 default:
diff --git a/tests/check-qlit.c b/tests/check-qlit.c
index 5d9558dfd9..ae74bfcb83 100644
--- a/tests/check-qlit.c
+++ b/tests/check-qlit.c
@@ -58,6 +58,9 @@ static void qlit_equal_qobject_test(void)
 
 g_assert(!qlit_equal_qobject(&qlit_foo, qobj));
 
+qdict_put(qobject_to_qdict(qobj), "bee", qlist_new());
+g_assert(!qlit_equal_qobject(&qlit, qobj));
+
 qobject_decref(qobj);
 }
 
-- 
2.14.1.146.gd35faa819




[Qemu-devel] [PATCH 13/14] qlit: add qobject_form_qlit()

2017-08-24 Thread Marc-André Lureau
Signed-off-by: Marc-André Lureau 
---
 include/qapi/qmp/qlit.h |  2 ++
 qobject/qlit.c  | 37 +
 tests/check-qlit.c  | 26 ++
 3 files changed, 65 insertions(+)

diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h
index 7118fc9e32..9b6e06d02f 100644
--- a/include/qapi/qmp/qlit.h
+++ b/include/qapi/qmp/qlit.h
@@ -51,4 +51,6 @@ struct QLitDictEntry {
 
 bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs);
 
+QObject *qobject_from_qlit(const QLitObject *qlit);
+
 #endif /* QLIT_H_ */
diff --git a/qobject/qlit.c b/qobject/qlit.c
index 0a60802d74..4adc2033a9 100644
--- a/qobject/qlit.c
+++ b/qobject/qlit.c
@@ -118,3 +118,40 @@ bool qlit_equal_qobject(const QLitObject *lhs, const 
QObject *rhs)
 
 return false;
 }
+
+QObject *qobject_from_qlit(const QLitObject *qlit)
+{
+int i;
+
+switch (qlit->type) {
+case QTYPE_QNULL:
+return QOBJECT(qnull());
+case QTYPE_QNUM:
+return QOBJECT(qnum_from_int(qlit->value.qnum));
+case QTYPE_QSTRING:
+return QOBJECT(qstring_from_str(qlit->value.qstr));
+case QTYPE_QDICT: {
+QDict *qdict = qdict_new();
+for (i = 0; qlit->value.qdict[i].value.type != QTYPE_NONE; i++) {
+QLitDictEntry *e = &qlit->value.qdict[i];
+
+qdict_put_obj(qdict, e->key, qobject_from_qlit(&e->value));
+}
+return QOBJECT(qdict);
+}
+case QTYPE_QLIST: {
+QList *qlist = qlist_new();
+
+for (i = 0; qlit->value.qlist[i].type != QTYPE_NONE; i++) {
+qlist_append_obj(qlist, qobject_from_qlit(&qlit->value.qlist[i]));
+}
+return QOBJECT(qlist);
+}
+case QTYPE_QBOOL:
+return QOBJECT(qbool_from_bool(qlit->value.qbool));
+case QTYPE_NONE:
+assert(0);
+}
+
+return NULL;
+}
diff --git a/tests/check-qlit.c b/tests/check-qlit.c
index ae74bfcb83..135a399c6d 100644
--- a/tests/check-qlit.c
+++ b/tests/check-qlit.c
@@ -64,11 +64,37 @@ static void qlit_equal_qobject_test(void)
 qobject_decref(qobj);
 }
 
+static void qobject_from_qlit_test(void)
+{
+QObject *obj, *qobj = qobject_from_qlit(&qlit);
+QDict *qdict;
+QList *bee;
+
+qdict = qobject_to_qdict(qobj);
+g_assert_cmpint(qdict_get_int(qdict, "foo"), ==, 42);
+g_assert_cmpstr(qdict_get_str(qdict, "bar"), ==, "hello world");
+g_assert(qobject_type(qdict_get(qdict, "baz")) == QTYPE_QNULL);
+
+bee = qdict_get_qlist(qdict, "bee");
+obj = qlist_pop(bee);
+g_assert_cmpint(qnum_get_int(qobject_to_qnum(obj)), ==, 43);
+qobject_decref(obj);
+obj = qlist_pop(bee);
+g_assert_cmpint(qnum_get_int(qobject_to_qnum(obj)), ==, 44);
+qobject_decref(obj);
+obj = qlist_pop(bee);
+g_assert(qbool_get_bool(qobject_to_qbool(obj)));
+qobject_decref(obj);
+
+qobject_decref(qobj);
+}
+
 int main(int argc, char **argv)
 {
 g_test_init(&argc, &argv, NULL);
 
 g_test_add_func("/qlit/equal_qobject", qlit_equal_qobject_test);
+g_test_add_func("/qlit/qobject_from_qlit", qobject_from_qlit_test);
 
 return g_test_run();
 }
-- 
2.14.1.146.gd35faa819




[Qemu-devel] [PATCH 14/14] qapi: generate a literal qobject for introspection

2017-08-24 Thread Marc-André Lureau
Replace the generated json string with a literal qobject. The later is
easier to deal with, at run time as well as compile time: adding #if
conditionals will be easier than in a json string.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
---
 scripts/qapi-introspect.py | 87 ++
 monitor.c  |  2 +-
 tests/test-qobject-input-visitor.c | 11 +++--
 docs/devel/qapi-code-gen.txt   | 29 -
 4 files changed, 78 insertions(+), 51 deletions(-)

diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
index 032bcea491..a157a5f91c 100644
--- a/scripts/qapi-introspect.py
+++ b/scripts/qapi-introspect.py
@@ -12,31 +12,41 @@
 from qapi import *
 
 
-# Caveman's json.dumps() replacement (we're stuck at Python 2.4)
-# TODO try to use json.dumps() once we get unstuck
-def to_json(obj, level=0):
+def to_qlit(obj, level=0, suppress_first_indent=False):
+
+def indent(level):
+return level * 4 * ' '
+
+ret = ''
+if not suppress_first_indent:
+ret += indent(level)
 if obj is None:
-ret = 'null'
+ret += 'QLIT_QNULL'
 elif isinstance(obj, str):
-ret = '"' + obj.replace('"', r'\"') + '"'
+ret += 'QLIT_QSTR(' + to_c_string(obj) + ')'
 elif isinstance(obj, list):
-elts = [to_json(elt, level + 1)
+elts = [to_qlit(elt, level + 1)
 for elt in obj]
-ret = '[' + ', '.join(elts) + ']'
+elts.append(indent(level + 1) + "{}")
+ret += 'QLIT_QLIST(((QLitObject[]) {\n'
+ret += ',\n'.join(elts) + '\n'
+ret += indent(level) + '}))'
 elif isinstance(obj, dict):
-elts = ['"%s": %s' % (key.replace('"', r'\"'),
-  to_json(obj[key], level + 1))
-for key in sorted(obj.keys())]
-ret = '{' + ', '.join(elts) + '}'
+elts = []
+for key, value in sorted(obj.iteritems()):
+elts.append(indent(level + 1) + '{ %s, %s }' %
+(to_c_string(key), to_qlit(value, level + 1, False)))
+elts.append(indent(level + 1) + '{}')
+ret += 'QLIT_QDICT(((QLitDictEntry[]) {\n'
+ret += ',\n'.join(elts) + '\n'
+ret += indent(level) + '}))'
 else:
 assert False# not implemented
-if level == 1:
-ret = '\n' + ret
 return ret
 
 
-def to_c_string(string):
-return '"' + string.replace('\\', r'\\').replace('"', r'\"') + '"'
+def to_c_string(s):
+return '"' + s.replace('\\', r'\\').replace('"', r'\"') + '"'
 
 
 class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor):
@@ -45,39 +55,37 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor):
 self.defn = None
 self.decl = None
 self._schema = None
-self._jsons = None
+self._qlits = None
 self._used_types = None
 self._name_map = None
 
 def visit_begin(self, schema):
 self._schema = schema
-self._jsons = []
+self._qlits = []
 self._used_types = []
 self._name_map = {}
 
 def visit_end(self):
 # visit the types that are actually used
-jsons = self._jsons
-self._jsons = []
+qlits = self._qlits
+self._qlits = []
 for typ in self._used_types:
 typ.visit(self)
 # generate C
 # TODO can generate awfully long lines
-jsons.extend(self._jsons)
-name = c_name(prefix, protect=False) + 'qmp_schema_json'
+qlits.extend(self._qlits)
+name = c_name(prefix, protect=False) + 'qmp_schema_qlit'
 self.decl = mcgen('''
-extern const char %(c_name)s[];
+extern const QLitObject %(c_name)s;
 ''',
   c_name=c_name(name))
-lines = to_json(jsons).split('\n')
-c_string = '\n'.join([to_c_string(line) for line in lines])
 self.defn = mcgen('''
-const char %(c_name)s[] = %(c_string)s;
+const QLitObject %(c_name)s = %(c_string)s;
 ''',
   c_name=c_name(name),
-  c_string=c_string)
+  c_string=to_qlit(qlits))
 self._schema = None
-self._jsons = None
+self._qlits = None
 self._used_types = None
 self._name_map = None
 
@@ -111,12 +119,12 @@ const char %(c_name)s[] = %(c_string)s;
 return '[' + self._use_type(typ.element_type) + ']'
 return self._name(typ.name)
 
-def _gen_json(self, name, mtype, obj):
+def _gen_qlit(self, name, mtype, obj):
 if mtype not in ('command', 'event', 'builtin', 'array'):
 name = self._name(name)
 obj['name'] = name
 obj['meta-type'] = mtype
-self._jsons.append(obj)
+self._qlits.append(obj)
 
 def _gen_member(self, member):
 ret = {'name': member.name, 'type': self._use_type(member.type)}
@@ -132,24 +140,24 @@ const char %(c_name)s

Re: [Qemu-devel] [PATCH 12/14] qlit: improve QLit list vs qlist comparison

2017-08-24 Thread Marc-André Lureau


- Original Message -
> Check that the QLit list has the same size as the qlist, this should
> ensure that we have an exact match when iterating over qlist for
> comparing the elements.
> 
> Signed-off-by: Marc-André Lureau 
> ---
>  qobject/qlit.c | 39 ++-
>  tests/check-qlit.c |  3 +++
>  2 files changed, 29 insertions(+), 13 deletions(-)
> 
> diff --git a/qobject/qlit.c b/qobject/qlit.c
> index 45ae0635c0..0a60802d74 100644
> --- a/qobject/qlit.c
> +++ b/qobject/qlit.c
> @@ -67,6 +67,28 @@ end:
>  return success;
>  }
>  
> +static bool qlit_equal_qlist(const QLitObject *lhs, const QList *qlist)
> +{
> +QListCompareHelper helper;
> +int i;
> +
> +for (i = 0; lhs->value.qlist[i].type != QTYPE_NONE; i++) {
> +continue;
> +}
> +
> +if (qlist_size(qlist) != i) {
> +return false;
> +}
> +
> +helper.index = 0;
> +helper.objs = lhs->value.qlist;
> +helper.result = true;
> +
> +qlist_iter(qlist, compare_helper, &helper);
> +
> +return helper.result;
> +}
> +
>  bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
>  {
>  int64_t val;
> @@ -82,21 +104,12 @@ bool qlit_equal_qobject(const QLitObject *lhs, const
> QObject *rhs)
>  val = qnum_get_int(qobject_to_qnum(rhs));
>  return lhs->value.qnum == val;
>  case QTYPE_QSTRING:
> -return (strcmp(lhs->value.qstr,
> -   qstring_get_str(qobject_to_qstring(rhs))) == 0);
> +return g_str_equal(lhs->value.qstr,
> +   qstring_get_str(qobject_to_qstring(rhs)));

drop this hunk, it slipped in by mistake.

>  case QTYPE_QDICT:
>  return qlit_equal_qdict(lhs, qobject_to_qdict(rhs));
> -case QTYPE_QLIST: {
> -QListCompareHelper helper;
> -
> -helper.index = 0;
> -helper.objs = lhs->value.qlist;
> -helper.result = true;
> -
> -qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper);
> -
> -return helper.result;
> -}
> +case QTYPE_QLIST:
> +return qlit_equal_qlist(lhs, qobject_to_qlist(rhs));
>  case QTYPE_QNULL:
>  return true;
>  default:
> diff --git a/tests/check-qlit.c b/tests/check-qlit.c
> index 5d9558dfd9..ae74bfcb83 100644
> --- a/tests/check-qlit.c
> +++ b/tests/check-qlit.c
> @@ -58,6 +58,9 @@ static void qlit_equal_qobject_test(void)
>  
>  g_assert(!qlit_equal_qobject(&qlit_foo, qobj));
>  
> +qdict_put(qobject_to_qdict(qobj), "bee", qlist_new());
> +g_assert(!qlit_equal_qobject(&qlit, qobj));
> +
>  qobject_decref(qobj);
>  }
>  
> --
> 2.14.1.146.gd35faa819
> 
> 



Re: [Qemu-devel] [PATCH 04/16] tpm: Clean up model registration & lookup

2017-08-24 Thread Marc-André Lureau
Hi

On Thu, Aug 24, 2017 at 10:45 AM, Markus Armbruster  wrote:
> We have a strict separation between enum TpmModel and tpm_models[]:
>
> * TpmModel may have any number of members.  It just happens to have one.
>
> * tpm_register_model() uses the first empty slot in tmp_models[].
>
>   If you register more than tpm_models[] has space,
>   tpn_register_model() fails.  Its caller silently ignores the
>   failure.

tpm_

>
>   Register the same TpmModel more than once has no effect other than
>   wasting tpm_models[] slots: tpm_model_is_registered() is happy with
>   the first one it finds.
>
> Since we only ever register one model, and tpm_models[] has space for
> just that one, this contraption even works.
>
> Turn tpm_models[] into a straight map from enum TpmType to bool.  Much
> simpler.
>
> Cc: Stefan Berger 
> Signed-off-by: Markus Armbruster 

Reviewed-by: Marc-André Lureau 


> ---
>  include/sysemu/tpm_backend.h |  2 +-
>  tpm.c| 37 +
>  2 files changed, 6 insertions(+), 33 deletions(-)
>
> diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
> index 1d21c6b..b0a9731 100644
> --- a/include/sysemu/tpm_backend.h
> +++ b/include/sysemu/tpm_backend.h
> @@ -226,7 +226,7 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);
>  TPMBackend *qemu_find_tpm(const char *id);
>
>  const TPMDriverOps *tpm_get_backend_driver(const char *type);
> -int tpm_register_model(enum TpmModel model);
> +void tpm_register_model(enum TpmModel model);
>  void tpm_register_driver(const TPMDriverOps *tdo);
>
>  #endif
> diff --git a/tpm.c b/tpm.c
> index 6f39ec9..7635fc7 100644
> --- a/tpm.c
> +++ b/tpm.c
> @@ -24,39 +24,12 @@
>  static QLIST_HEAD(, TPMBackend) tpm_backends =
>  QLIST_HEAD_INITIALIZER(tpm_backends);
>
> -
> -#define TPM_MAX_MODELS  1
> -
>  static TPMDriverOps const *be_drivers[TPM_TYPE__MAX];
> +static bool tpm_models[TPM_MODEL__MAX];
>
> -static enum TpmModel tpm_models[TPM_MAX_MODELS] = {
> -TPM_MODEL__MAX,
> -};
> -
> -int tpm_register_model(enum TpmModel model)
> +void tpm_register_model(enum TpmModel model)
>  {
> -int i;
> -
> -for (i = 0; i < TPM_MAX_MODELS; i++) {
> -if (tpm_models[i] == TPM_MODEL__MAX) {
> -tpm_models[i] = model;
> -return 0;
> -}
> -}
> -error_report("Could not register TPM model");
> -return 1;
> -}
> -
> -static bool tpm_model_is_registered(enum TpmModel model)
> -{
> -int i;
> -
> -for (i = 0; i < TPM_MAX_MODELS; i++) {
> -if (tpm_models[i] == model) {
> -return true;
> -}
> -}
> -return false;
> +tpm_models[model] = true;

Ah, no need for an assert() here indeed (it took me a minute).

>  }
>
>  const TPMDriverOps *tpm_get_backend_driver(const char *type)
> @@ -270,7 +243,7 @@ TPMInfoList *qmp_query_tpm(Error **errp)
>  TPMInfoList *info, *head = NULL, *cur_item = NULL;
>
>  QLIST_FOREACH(drv, &tpm_backends, list) {
> -if (!tpm_model_is_registered(drv->fe_model)) {
> +if (!tpm_models[drv->fe_model]) {
>  continue;
>  }
>  info = g_new0(TPMInfoList, 1);
> @@ -317,7 +290,7 @@ TpmModelList *qmp_query_tpm_models(Error **errp)
>  TpmModelList *head = NULL, *prev = NULL, *cur_item;
>
>  for (i = 0; i < TPM_MODEL__MAX; i++) {
> -if (!tpm_model_is_registered(i)) {
> +if (!tpm_models[i]) {
>  continue;
>  }
>  cur_item = g_new0(TpmModelList, 1);
> --
> 2.7.5
>
>



-- 
Marc-André Lureau



Re: [Qemu-devel] [PATCH QEMU] xen/pt: allow QEMU to request MSI unmasking at bind time

2017-08-24 Thread Roger Pau Monne
On Thu, Aug 24, 2017 at 04:13:58AM -0600, Jan Beulich wrote:
> >>> On 24.08.17 at 12:06,  wrote:
> > On Thu, Aug 24, 2017 at 03:54:21AM -0600, Jan Beulich wrote:
> >> >>> On 24.08.17 at 11:47,  wrote:
> >> > @@ -274,7 +278,7 @@ int xen_pt_msi_update(XenPCIPassthroughState *s)
> >> >  {
> >> >  XenPTMSI *msi = s->msi;
> >> >  return msi_msix_update(s, msi_addr64(msi), msi->data, msi->pirq,
> >> > -   false, 0, &msi->pirq);
> >> > +   false, 0, &msi->pirq, false);
> >> >  }
> >> 
> >> I don't think this is correct when the device has mask bits.
> > 
> > Right, I thought I modified this. I've already changed
> > pt_irq_create_bind so that the original behavior is keep if the unmask
> > bit is not set. In this case this should be 'true' in order to keep
> > the previous behavior, which was correct for MSI.
> 
> Wouldn't you want to pass the state of the mask bit here,
> rather than uniformly hard coding true or false?

Yes, I think so. I've overlooked the MSI code because I thought we
allowed QEMU to directly write to the mask register, but that's not
true, it's trapped by Xen.

Thanks, Roger.



Re: [Qemu-devel] [PATCH 02/16] qapi: Drop superfluous qapi_enum_parse() parameter max

2017-08-24 Thread Marc-André Lureau
On Thu, Aug 24, 2017 at 10:45 AM, Markus Armbruster  wrote:
> The lookup tables have a sentinel, no need to make callers pass their
> size.
>
> Fun: the header has it in the wrong position.  Good riddance.
>
> Signed-off-by: Markus Armbruster 

Reviewed-by: Marc-André Lureau 


> ---
>  block.c  |  1 -
>  block/file-posix.c   |  7 +++
>  block/file-win32.c   |  2 +-
>  block/gluster.c  |  6 ++
>  block/parallels.c|  3 ++-
>  block/qcow2.c|  6 ++
>  blockdev.c   |  1 -
>  hmp.c|  2 +-
>  include/qapi/util.h  |  2 +-
>  migration/global_state.c |  3 +--
>  qapi/qapi-util.c |  4 ++--
>  qemu-img.c   |  3 +--
>  qemu-nbd.c   |  1 -
>  tests/test-qapi-util.c   | 15 +--
>  14 files changed, 21 insertions(+), 35 deletions(-)
>
> diff --git a/block.c b/block.c
> index 3615a68..dd0efa2 100644
> --- a/block.c
> +++ b/block.c
> @@ -1335,7 +1335,6 @@ static int bdrv_open_common(BlockDriverState *bs, 
> BlockBackend *file,
>  BlockdevDetectZeroesOptions value =
>  qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
>  detect_zeroes,
> -BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX,
>  BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
>  &local_err);
>  if (local_err) {
> diff --git a/block/file-posix.c b/block/file-posix.c
> index cb3bfce..97e8a92 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -439,7 +439,7 @@ static int raw_open_common(BlockDriverState *bs, QDict 
> *options,
>? BLOCKDEV_AIO_OPTIONS_NATIVE
>: BLOCKDEV_AIO_OPTIONS_THREADS;
>  aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, 
> "aio"),
> -  BLOCKDEV_AIO_OPTIONS__MAX, aio_default, 
> &local_err);
> +  aio_default, &local_err);
>  if (local_err) {
>  error_propagate(errp, local_err);
>  ret = -EINVAL;
> @@ -448,7 +448,7 @@ static int raw_open_common(BlockDriverState *bs, QDict 
> *options,
>  s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE);
>
>  locking = qapi_enum_parse(OnOffAuto_lookup, qemu_opt_get(opts, 
> "locking"),
> -  ON_OFF_AUTO__MAX, ON_OFF_AUTO_AUTO, 
> &local_err);
> +  ON_OFF_AUTO_AUTO, &local_err);
>  if (local_err) {
>  error_propagate(errp, local_err);
>  ret = -EINVAL;
> @@ -1975,8 +1975,7 @@ static int raw_create(const char *filename, QemuOpts 
> *opts, Error **errp)
>  nocow = qemu_opt_get_bool(opts, BLOCK_OPT_NOCOW, false);
>  buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
>  prealloc = qapi_enum_parse(PreallocMode_lookup, buf,
> -   PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,
> -   &local_err);
> +   PREALLOC_MODE_OFF, &local_err);
>  g_free(buf);
>  if (local_err) {
>  error_propagate(errp, local_err);
> diff --git a/block/file-win32.c b/block/file-win32.c
> index 4706335..978d805 100644
> --- a/block/file-win32.c
> +++ b/block/file-win32.c
> @@ -304,7 +304,7 @@ static bool get_aio_option(QemuOpts *opts, int flags, 
> Error **errp)
>  aio_default = (flags & BDRV_O_NATIVE_AIO) ? BLOCKDEV_AIO_OPTIONS_NATIVE
>: BLOCKDEV_AIO_OPTIONS_THREADS;
>  aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, 
> "aio"),
> -  BLOCKDEV_AIO_OPTIONS__MAX, aio_default, errp);
> +  aio_default, errp);
>
>  switch (aio) {
>  case BLOCKDEV_AIO_OPTIONS_NATIVE:
> diff --git a/block/gluster.c b/block/gluster.c
> index 3064a45..8367e80 100644
> --- a/block/gluster.c
> +++ b/block/gluster.c
> @@ -544,8 +544,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster 
> *gconf,
>  if (!strcmp(ptr, "tcp")) {
>  ptr = "inet";   /* accept legacy "tcp" */
>  }
> -type = qapi_enum_parse(SocketAddressType_lookup, ptr,
> -   SOCKET_ADDRESS_TYPE__MAX, -1, NULL);
> +type = qapi_enum_parse(SocketAddressType_lookup, ptr, -1, NULL);
>  if (type != SOCKET_ADDRESS_TYPE_INET
>  && type != SOCKET_ADDRESS_TYPE_UNIX) {
>  error_setg(&local_err,
> @@ -1002,8 +1001,7 @@ static int qemu_gluster_create(const char *filename,
>BDRV_SECTOR_SIZE);
>
>  tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
> -prealloc = qapi_enum_parse(PreallocMode_lookup, tmp,
> -   PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,
> +prealloc = qapi_enum_parse(PreallocMode_lookup, tmp, PREALLOC_MODE_OFF,
> &local_err);
>  g_free(tmp);
>  if (local_err) {
> diff --git a/block/para

Re: [Qemu-devel] [PATCH 09/16] crypto: Use qapi_enum_parse() in qcrypto_block_luks_name_lookup()

2017-08-24 Thread Marc-André Lureau
On Thu, Aug 24, 2017 at 10:46 AM, Markus Armbruster  wrote:
> Cc: "Daniel P. Berrange" 
> Signed-off-by: Markus Armbruster 

Reviewed-by: Marc-André Lureau 


> ---
>  crypto/block-luks.c | 19 +++
>  1 file changed, 7 insertions(+), 12 deletions(-)
>
> diff --git a/crypto/block-luks.c b/crypto/block-luks.c
> index afb8543..c3cacdb 100644
> --- a/crypto/block-luks.c
> +++ b/crypto/block-luks.c
> @@ -20,6 +20,7 @@
>
>  #include "qemu/osdep.h"
>  #include "qapi/error.h"
> +#include "qapi/util.h"
>  #include "qemu/bswap.h"
>
>  #include "crypto/block-luks.h"
> @@ -265,39 +266,33 @@ 
> qcrypto_block_luks_cipher_alg_lookup(QCryptoCipherAlgorithm alg,
>   * make that function emit a more friendly error message */
>  static int qcrypto_block_luks_name_lookup(const char *name,
>const char *const *map,
> -  size_t maplen,
>const char *type,
>Error **errp)
>  {
> -size_t i;
> -for (i = 0; i < maplen; i++) {
> -if (g_str_equal(map[i], name)) {
> -return i;
> -}
> -}
> +int ret = qapi_enum_parse(map, name, -1, NULL);
>
> -error_setg(errp, "%s %s not supported", type, name);
> -return 0;
> +if (ret < 0) {
> +error_setg(errp, "%s %s not supported", type, name);
> +return 0;
> +}
> +return ret;
>  }
>
>  #define qcrypto_block_luks_cipher_mode_lookup(name, errp)   \
>  qcrypto_block_luks_name_lookup(name,\
> QCryptoCipherMode_lookup,\
> -   QCRYPTO_CIPHER_MODE__MAX,\
> "Cipher mode",   \
> errp)
>
>  #define qcrypto_block_luks_hash_name_lookup(name, errp) \
>  qcrypto_block_luks_name_lookup(name,\
> QCryptoHashAlgorithm_lookup, \
> -   QCRYPTO_HASH_ALG__MAX,   \
> "Hash algorithm",\
> errp)
>
>  #define qcrypto_block_luks_ivgen_name_lookup(name, errp)\
>  qcrypto_block_luks_name_lookup(name,\
> QCryptoIVGenAlgorithm_lookup,\
> -   QCRYPTO_IVGEN_ALG__MAX,  \
> "IV generator",  \
> errp)
>
> --
> 2.7.5
>
>



-- 
Marc-André Lureau



Re: [Qemu-devel] AVMF & OVMF blobs in QEMU tree???

2017-08-24 Thread Gerd Hoffmann
  Hi,

> Having all our precompiled blobs be in a submodule would
> maybe be handy for properly keeping them separate from the
> QEMU code -- would that be useful for downstream distro
> packagers?

I like the clear separation.

Also you don't have to fetch the firmware submodule if you don't need
the prebuilds.

It would be a good opportunity to cleanup the mess we have in pc-bios/
right now.

Clear disadvantage is that firmware updates will become more
complicated then as two repos must be updated.  So either two pull
requests per firmware update, or write access to the firmware binary
repo for all firmware maintainers.

Or maybe make the firmware sources submodules of the firmware binary
repo instead of the qemu repo.

> In any case this seems like a good opportunity to write down
> exactly what our policy about ROM blobs is (eg where they
> are, how we update them, requirement for source, whether
> we allow source to be in a submodule not on qemu.org...)

Tried to write down the current state.

cheers,
  Gerd

-- docs/firmware.txt 

prebuilt firmware in qemu
=

The process of building firmware isn't as easy as building qemu
itself, for example because you must have cross compilers installed
when building firmware for other architectures.  So qemu ships
prebuilt firmware binaries for convenience reasons.


directories
---

pc-bios/
Firmware binaries.
Also other files like keymaps and logos which are copied to
$prefix/share/qemu by "make install".

pc-bios/optionrom/
Firmware sources, part of the qemu project.

roms/
Firmware sources, third-party projects, as git submodules.


third-party git repos
-

For third party firmware sources it is recommended to have a git
mirror on git.qemu.org.  In case the firmware license is GPL the git
mirror is mandatory for GPL compilance reasons:  We ship binaries, so
we must provide sources too.


building the firmware
-

Firmware builds should be done using rules in roms/Makefile.  That
serves as documentation how the firmware is built, and it also makes
firmware updates easier for the maintainer.

"make -C roms" prints a list of firmware build targets.
"make -C roms $target" kicks a build.


notes for specific firmwares


ipxe: see https://wiki.qemu.org/IpxeDownstreamForQemu




Re: [Qemu-devel] [PATCH v5 0/9] zpci detangling

2017-08-24 Thread Cornelia Huck
On Thu, 24 Aug 2017 09:49:18 +0200
Christian Borntraeger  wrote:

> As there are only minor things left, 
> whole series
> 
> Acked-by: Christian Borntraeger 

Thanks.

I've applied this to s390-next.



Re: [Qemu-devel] [PATCH v2 06/54] qapi: introduce qapi_enum_lookup()

2017-08-24 Thread Dr. David Alan Gilbert
* Marc-André Lureau (marcandre.lur...@redhat.com) wrote:
> Hi
> 
> - Original Message -
> > Marc-André Lureau  writes:
> > 
> > > This will help with the introduction of a new structure to handle
> > > enum lookup.

It would be good to make that comment explain why it's necessary.

> > > Signed-off-by: Marc-André Lureau 
> > > ---
> > [...]
> > >  45 files changed, 206 insertions(+), 122 deletions(-)
> > 
> > Hmm.
> > 
> > > diff --git a/include/qapi/util.h b/include/qapi/util.h
> > > index 7436ed815c..60733b6a80 100644
> > > --- a/include/qapi/util.h
> > > +++ b/include/qapi/util.h
> > > @@ -11,6 +11,8 @@
> > >  #ifndef QAPI_UTIL_H
> > >  #define QAPI_UTIL_H
> > >  
> > > +const char *qapi_enum_lookup(const char * const lookup[], int val);
> > > +
> > >  int qapi_enum_parse(const char * const lookup[], const char *buf,
> > >  int max, int def, Error **errp);
> > >  
> > > diff --git a/backends/hostmem.c b/backends/hostmem.c
> > > index 4606b73849..c4f795475c 100644
> > > --- a/backends/hostmem.c
> > > +++ b/backends/hostmem.c
> > > @@ -13,6 +13,7 @@
> > >  #include "sysemu/hostmem.h"
> > >  #include "hw/boards.h"
> > >  #include "qapi/error.h"
> > > +#include "qapi/util.h"
> > >  #include "qapi/visitor.h"
> > >  #include "qapi-types.h"
> > >  #include "qapi-visit.h"
> > > @@ -304,7 +305,7 @@ host_memory_backend_memory_complete(UserCreatable *uc,
> > > Error **errp)
> > >  return;
> > >  } else if (maxnode == 0 && backend->policy != MPOL_DEFAULT) {
> > >  error_setg(errp, "host-nodes must be set for policy %s",
> > > -   HostMemPolicy_lookup[backend->policy]);
> > > +qapi_enum_lookup(HostMemPolicy_lookup, backend->policy));
> > >  return;
> > >  }
> > >  
> > 
> > Lookup becomes even more verbose.
> > 
> > Could we claw back some readability with macros?  Say in addition to
> > 
> > typedef enum FOO {
> > ...
> > } FOO;
> > 
> > extern const char *const FOO_lookup[];
> > 
> > generate
> > 
> > #define FOO_str(val) qapi_enum_lookup(FOO_lookup, (val))
> > 
> > Needs a matching qapi-code-gen.txt update.
> > 
> > With that, this patch hunk would become
> > 
> >error_setg(errp, "host-nodes must be set for policy %s",
> >   -   HostMemPolicy_lookup[backend->policy]);
> >   +   HostMemPolicy_str(backend->policy);
> > 
> > Perhaps we could even throw in some type checking:
> > 
> > #define FOO_str(val) (type_check(typeof((val)), FOO) \
> >   + qapi_enum_lookup(FOO_lookup, (val)))
> > 
> > What do you think?  Want me to explore a fixup patch you could squash
> > in?
> > 
> 
> Yes, I had similar thoughts, but didn't spent too much time finding the best 
> proposal, that wasn't my main goal in the series. 
> 
> Indeed, I would prefer that further improvements be done as follow-up. Or if 
> you have a ready solution, I can squash it there. I can picture the conflicts 
> with the next patch though... 

If you did it as a separate patch it would have to be another
huge patch changing lots of areas.
I think the use of the macro to keep it simple should be in this one;
you can add the type check change later.

Dave

> > [Skipping lots of mechanical changes...]
> > 
> > I think you missed test-qobject-input-visitor.c and
> > string-input-visitor.c.
> > 
> > In test-qobject-input-visitor.c's test_visitor_in_enum():
> > 
> > v = visitor_input_test_init(data, "%s", EnumOne_lookup[i]);
> > 
> > You update it in PATCH 12, but the code only works as long as EnumOne
> > has no holes.  Mapping the enum to string like we do everywhere else in
> > this patch would be cleaner.
> > 
> 
> ok
> 
> > The loop control also subscripts EnumOne_lookup[i].  You take care of
> > that one in PATCH 12.  That's okay.
> > 
> > Same for test-string-input-visitor.c's test_visitor_in_enum().
> > 
> > There's one more in test_native_list_integer_helper():
> > 
> > g_string_append_printf(gstr_union,  "{ 'type': '%s', 'data': [ %s ] }",
> >UserDefNativeListUnionKind_lookup[kind],
> >gstr_list->str);
> > 
> > Same story.
> > 
> > The patch doesn't touch the _lookup[] subscripts you're going to replace
> > by qapi_enum_parse() in PATCH 07-11.  Understand, but I'd reorder the
> > patches: first replace by qapi_enum_parse(), because DRY (no need to
> > explain more at that point).  Then get rid of all the remaining
> > subscripting into _lookup[], i.e. this patch (explain it helps the next
> > one), then PATCH 12.
> > 
> 
> ok
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



Re: [Qemu-devel] A use-after-free in slirp

2017-08-24 Thread P J P
  Hello Samuel,

+-- On Wed, 23 Aug 2017, Samuel Thibault wrote --+
| The paste is not available any more. Is it really very large? It's usually 
| really better to just send it by mail, so it's archived in the mailing list 
| etc.

Yes, stack-trace was quite long.

===
==2704==ERROR: AddressSanitizer: heap-use-after-free on address 0x6141018c 
at pc 0x003921ea145d bp 0x7fd49c4fc940 sp 0x7fd49c4fc930
READ of size 4 at 0x6141018c thread T2
#0 0x3921ea145c in if_start slirp/if.c:230
#1 0x3921ea1015 in if_output slirp/if.c:141
#2 0x3921eadf1f in ip_output slirp/ip_output.c:85
#3 0x3921ed229e in tcp_respond slirp/tcp_subr.c:218
#4 0x3921ecc959 in tcp_input slirp/tcp_input.c:1392
#5 0x3921eab799 in ip_input slirp/ip_input.c:206
#6 0x3921eb6529 in slirp_input slirp/slirp.c:872
#7 0x3921e7c56f in net_slirp_receive net/slirp.c:119
#8 0x3921e60fe0 in nc_sendv_compat net/net.c:707
#9 0x3921e61170 in qemu_deliver_packet_iov net/net.c:734
#10 0x3921e67c53 in qemu_net_queue_deliver_iov net/queue.c:179
#11 0x3921e67e5b in qemu_net_queue_send_iov net/queue.c:224
#12 0x3921e61395 in qemu_sendv_packet_async net/net.c:770
#13 0x3921e613c2 in qemu_sendv_packet net/net.c:778
#14 0x3921e6961e in net_hub_receive_iov net/hub.c:72
#15 0x3921e69c12 in net_hub_port_receive_iov net/hub.c:123
#16 0x3921e61155 in qemu_deliver_packet_iov net/net.c:732
#17 0x3921e67ae7 in qemu_net_queue_deliver net/queue.c:164
#18 0x3921e67d59 in qemu_net_queue_send net/queue.c:199
#19 0x3921e60d58 in qemu_send_packet_async_with_flags net/net.c:661
#20 0x3921e60d90 in qemu_send_packet_async net/net.c:668
#21 0x3921e60dbd in qemu_send_packet net/net.c:674
#22 0x3921bef076 in ne2000_ioport_write hw/net/ne2000.c:302
#23 0x3921bf07c4 in ne2000_write hw/net/ne2000.c:688
#24 0x3921668a95 in memory_region_write_accessor 
/home/test/qemu/memory.c:529
#25 0x3921668d6e in access_with_adjusted_size /home/test/qemu/memory.c:595
#26 0x392166f4ca in memory_region_dispatch_write 
/home/test/qemu/memory.c:1337
#27 0x39215c633c in address_space_write_continue /home/test/qemu/exec.c:2942
#28 0x39215c65df in address_space_write /home/test/qemu/exec.c:2987
#29 0x39215c6df3 in address_space_rw /home/test/qemu/exec.c:3089
#30 0x39216a3159 in kvm_handle_io /home/test/qemu/accel/kvm/kvm-all.c:1795
#31 0x39216a4425 in kvm_cpu_exec /home/test/qemu/accel/kvm/kvm-all.c:2035
#32 0x3921636a6c in qemu_kvm_cpu_thread_fn /home/test/qemu/cpus.c:1128
#33 0x7fd4a5f4336c in start_thread (/lib64/libpthread.so.0+0x736c)
#34 0x7fd4a5c7bbbe in __GI___clone (/lib64/libc.so.6+0x110bbe)

0x6141018c is located 332 bytes inside of 416-byte region 
[0x61410040,0x614101e0)
freed by thread T2 here:
#0 0x7fd4a967c4b8 in __interceptor_free (/lib64/libasan.so.4+0xde4b8)
#1 0x3921ebf027 in sofree slirp/socket.c:106
#2 0x3921ed2cd5 in tcp_close slirp/tcp_subr.c:334
#3 0x3921eca600 in tcp_input slirp/tcp_input.c:948
#4 0x3921eab799 in ip_input slirp/ip_input.c:206
#5 0x3921eb6529 in slirp_input slirp/slirp.c:872
#6 0x3921e7c56f in net_slirp_receive net/slirp.c:119
#7 0x3921e60fe0 in nc_sendv_compat net/net.c:707
#8 0x3921e61170 in qemu_deliver_packet_iov net/net.c:734
#9 0x3921e67c53 in qemu_net_queue_deliver_iov net/queue.c:179
#10 0x3921e67e5b in qemu_net_queue_send_iov net/queue.c:224
#11 0x3921e61395 in qemu_sendv_packet_async net/net.c:770
#12 0x3921e613c2 in qemu_sendv_packet net/net.c:778
#13 0x3921e6961e in net_hub_receive_iov net/hub.c:72
#14 0x3921e69c12 in net_hub_port_receive_iov net/hub.c:123
#15 0x3921e61155 in qemu_deliver_packet_iov net/net.c:732
#16 0x3921e67ae7 in qemu_net_queue_deliver net/queue.c:164
#17 0x3921e67d59 in qemu_net_queue_send net/queue.c:199
#18 0x3921e60d58 in qemu_send_packet_async_with_flags net/net.c:661
#19 0x3921e60d90 in qemu_send_packet_async net/net.c:668
#20 0x3921e60dbd in qemu_send_packet net/net.c:674
#21 0x3921bef076 in ne2000_ioport_write hw/net/ne2000.c:302
#22 0x3921bf07c4 in ne2000_write hw/net/ne2000.c:688
#23 0x3921668a95 in memory_region_write_accessor 
/home/test/qemu/memory.c:529
#24 0x3921668d6e in access_with_adjusted_size /home/test/qemu/memory.c:595
#25 0x392166f4ca in memory_region_dispatch_write 
/home/test/qemu/memory.c:1337
#26 0x39215c633c in address_space_write_continue /home/test/qemu/exec.c:2942
#27 0x39215c65df in address_space_write /home/test/qemu/exec.c:2987
#28 0x39215c6df3 in address_space_rw /home/test/qemu/exec.c:3089
#29 0x39216a3159 in kvm_handle_io /home/test/qemu/accel/kvm/kvm-all.c:1795

previously allocated by thread T2 here:
#0 0x7fd4a967c850 in malloc (/lib64/libasan.so.4+0xde850)
#1 0x3921ebeaa5 in socreate slirp/socket.c:51
#2 0x3921ec7184 in tcp_input slirp/tcp_input.c:432
#3 0x3921eab799 in ip_input slirp/ip_input.c:206
#4 0x

Re: [Qemu-devel] [PATCH for-2.11] hw/s390x/s390-skeys: Mark the storage key devices with user_creatable = false

2017-08-24 Thread Cornelia Huck
On Thu, 24 Aug 2017 12:08:48 +0200
Thomas Huth  wrote:

> QEMU currently aborts if the user tries to create a skey device:
> 
> $ s390x-softmmu/qemu-system-s390x -nographic -device s390-skeys-qemu
> qemu-system-s390x: hw/s390x/s390-skeys.c:30: s390_get_skeys_device:
>  Assertion `ss' failed.
> Aborted (core dumped)
> 
> The storage key devices are only meant to be instantiated one time,
> internally. They can not be used by the user, so mark them with
> user_creatable = false.
> 
> Signed-off-by: Thomas Huth 
> ---
>  hw/s390x/s390-skeys-kvm.c | 4 
>  hw/s390x/s390-skeys.c | 4 
>  2 files changed, 8 insertions(+)

Thanks, applied.



Re: [Qemu-devel] [PATCH v2 08/54] hmp: use qapi_enum_parse() in hmp_migrate_set_capability

2017-08-24 Thread Dr. David Alan Gilbert
* Marc-André Lureau (marcandre.lur...@redhat.com) wrote:
> Signed-off-by: Marc-André Lureau 
> ---
>  hmp.c | 24 +++-
>  1 file changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/hmp.c b/hmp.c
> index 29e42ab661..4ba50e8e26 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -1544,23 +1544,21 @@ void hmp_migrate_set_capability(Monitor *mon, const 
> QDict *qdict)
>  bool state = qdict_get_bool(qdict, "state");
>  Error *err = NULL;
>  MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
> -int i;
> +int val;
>  
> -for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
> -if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
> -caps->value = g_malloc0(sizeof(*caps->value));
> -caps->value->capability = i;
> -caps->value->state = state;
> -caps->next = NULL;
> -qmp_migrate_set_capabilities(caps, &err);
> -break;
> -}
> +val = qapi_enum_parse(MigrationCapability_lookup, cap,
> +  MIGRATION_CAPABILITY__MAX, -1, &err);

It would be nice to macro that to something like:
   MigrationCapability_parse(cap, -1, &err);

which would stop the inevitable case of someone using the wrong _lookup
with the wrong _MAX.

I also wonder if having the qapi_enum_parse return a bool and take a
&int would be nicer - it would get rid of the need for the -1 default
and mean actually it could be an unsigned.

Still, those are only suggestions, so:

Reviewed-by: Dr. David Alan Gilbert 

> +if (val < 0) {
> +goto end;
>  }
>  
> -if (i == MIGRATION_CAPABILITY__MAX) {
> -error_setg(&err, QERR_INVALID_PARAMETER, cap);
> -}
> +caps->value = g_malloc0(sizeof(*caps->value));
> +caps->value->capability = val;
> +caps->value->state = state;
> +caps->next = NULL;
> +qmp_migrate_set_capabilities(caps, &err);
>  
> +end:
>  qapi_free_MigrationCapabilityStatusList(caps);
>  
>  if (err) {
> -- 
> 2.14.1.146.gd35faa819
> 
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



  1   2   3   4   >