Re: [Qemu-devel] [PULL 00/28] ppc-for-2.6 queue 20160125

2016-01-26 Thread Peter Maydell
On 26 January 2016 at 05:37, David Gibson  wrote:
> Good grief.  And this would be why I don't generally test 32-bit
> builds...

32-bit on 64-bit host is a special case of a cross-compile,
and cross-compiling is always pain... (My test 32-bit builds
are just done on a natively 32-bit machine.)

thanks
-- PMM



Re: [Qemu-devel] [PATCH 0/8] nbd: Fix failed assertion on negotiation error

2016-01-26 Thread Kevin Wolf
Am 25.01.2016 um 19:41 hat Max Reitz geschrieben:
> An error during negotiation, e.g. by the client trying to open an export
> that does not exist, should not lead to a crash of the server process.
> 
> The middle six patches of this series are taken from my series
> "block: Rework bdrv_close_all()", so here is a git-backport-diff against
> v7 of that series:

Thanks, applied to the block branch.

Kevin



[Qemu-devel] [RFC PATCH 05/16] block: Make bdrv_get_cluster_size public

2016-01-26 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 block/io.c| 2 +-
 include/block/block.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/io.c b/block/io.c
index b964e7e..15e461f 100644
--- a/block/io.c
+++ b/block/io.c
@@ -425,7 +425,7 @@ void bdrv_round_to_clusters(BlockDriverState *bs,
 }
 }
 
-static int bdrv_get_cluster_size(BlockDriverState *bs)
+int bdrv_get_cluster_size(BlockDriverState *bs)
 {
 BlockDriverInfo bdi;
 int ret;
diff --git a/include/block/block.h b/include/block/block.h
index b9b30cb..16b7845 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -435,7 +435,7 @@ void bdrv_round_to_clusters(BlockDriverState *bs,
 int64_t sector_num, int nb_sectors,
 int64_t *cluster_sector_num,
 int *cluster_nb_sectors);
-
+int bdrv_get_cluster_size(BlockDriverState *bs);
 const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
 void bdrv_get_backing_filename(BlockDriverState *bs,
char *filename, int filename_size);
-- 
2.4.3




[Qemu-devel] [RFC PATCH 06/16] block: Introduce bdrv_dirty_bitmap_set_persistent

2016-01-26 Thread Fam Zheng
By implementing bdrv_dirty_bitmap_set_persistent, a driver can support
the persistent dirty bitmap feature.

Once a dirty bitmap is made persistent, the driver is responsible for saving
the dirty bitmap when appropriate, for example before close; if a persistent
bitmap is removed or made non-persistent, .bdrv_dirty_bitmap_set_persistent
will be called, the driver should then remove the dirty bitmap from the disk.

This operation is not recursed in block layer, a filter such as blkdebug needs
to implement the callback and explicitly pass down to bs->file, etc.

Signed-off-by: Fam Zheng 
---
 block/dirty-bitmap.c | 38 ++
 include/block/block_int.h|  8 
 include/block/dirty-bitmap.h |  4 
 3 files changed, 50 insertions(+)

diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index 1aa7f76..882a0db 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -43,6 +43,7 @@ struct BdrvDirtyBitmap {
 int64_t size;   /* Size of the bitmap (Number of sectors) */
 bool disabled;  /* Bitmap is read-only */
 int active_iterators;   /* How many iterators are active */
+bool persistent;/* Whether this bitmap is persistent. */
 QLIST_ENTRY(BdrvDirtyBitmap) list;
 };
 
@@ -71,6 +72,37 @@ void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap)
 bitmap->name = NULL;
 }
 
+int bdrv_dirty_bitmap_set_persistent(BlockDriverState *bs,
+ BdrvDirtyBitmap *bitmap,
+ bool persistent, bool flag_only,
+ Error **errp)
+{
+int ret = 0;
+
+if (!bitmap->name) {
+error_setg(errp, "Cannot change the persistent status of an anonymous"
+ "bitmap");
+return -EINVAL;
+}
+
+if (persistent == bitmap->persistent) {
+return 0;
+}
+
+if (!flag_only) {
+if (!bs->drv || !bs->drv->bdrv_dirty_bitmap_set_persistent) {
+error_setg(errp, "Not supported in this format.");
+return -ENOTSUP;
+}
+ret = bs->drv->bdrv_dirty_bitmap_set_persistent(bs, bitmap, persistent,
+errp);
+}
+if (!ret) {
+bitmap->persistent = persistent;
+}
+return ret;
+}
+
 BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
   uint32_t granularity,
   const char *name,
@@ -194,6 +226,12 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState 
*bs,
 uint64_t granularity;
 BdrvDirtyBitmap *child;
 
+if (bitmap->persistent) {
+error_setg(errp, "Cannot create a successor for a bitmap that is "
+   "persistent");
+return -1;
+}
+
 if (bdrv_dirty_bitmap_frozen(bitmap)) {
 error_setg(errp, "Cannot create a successor for a bitmap that is "
"currently frozen");
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 5fa58e8..fbc34af 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -305,6 +305,14 @@ struct BlockDriver {
  */
 void (*bdrv_drain)(BlockDriverState *bs);
 
+/**
+ * Make the dirty bitmap persistent if persistent=true or transient
+ * otherwise.
+ */
+int (*bdrv_dirty_bitmap_set_persistent)(BlockDriverState *bs,
+BdrvDirtyBitmap *bitmap,
+bool persistent, Error **errp);
+
 QLIST_ENTRY(BlockDriver) list;
 };
 
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
index d14d923..5885720 100644
--- a/include/block/dirty-bitmap.h
+++ b/include/block/dirty-bitmap.h
@@ -24,6 +24,10 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState 
*bs,
 BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
 const char *name);
 void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap);
+int bdrv_dirty_bitmap_set_persistent(BlockDriverState *bs,
+ BdrvDirtyBitmap *bitmap,
+ bool persistent, bool flag_only,
+ Error **errp);
 void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
 void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
 void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
-- 
2.4.3




[Qemu-devel] [RFC PATCH 02/16] block: Set dirty before doing write

2016-01-26 Thread Fam Zheng
So that driver can write the dirty bits into persistent dirty bitmaps in
the write callback.

Signed-off-by: Fam Zheng 
---
 block/io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/io.c b/block/io.c
index 343ff1f..b964e7e 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1164,6 +1164,8 @@ static int coroutine_fn 
bdrv_aligned_pwritev(BlockDriverState *bs,
 }
 }
 
+bdrv_set_dirty(bs, sector_num, nb_sectors);
+
 if (ret < 0) {
 /* Do nothing, write notifier decided to fail this request */
 } else if (flags & BDRV_REQ_ZERO_WRITE) {
@@ -1179,8 +1181,6 @@ static int coroutine_fn 
bdrv_aligned_pwritev(BlockDriverState *bs,
 ret = bdrv_co_flush(bs);
 }
 
-bdrv_set_dirty(bs, sector_num, nb_sectors);
-
 if (bs->wr_highest_offset < offset + bytes) {
 bs->wr_highest_offset = offset + bytes;
 }
-- 
2.4.3




[Qemu-devel] [RFC PATCH 07/16] block: Only swap non-persistent dirty bitmaps

2016-01-26 Thread Fam Zheng
Persistent dirty bitmaps are special because they're tightly associated
with, or even belonging to the driver, swapping them doesn't make much
sense. Because this has nothing to do with backward compatibility, it's
okay to just let them stay with the old BDS.

Signed-off-by: Fam Zheng 
---
 block.c  | 11 +--
 block/dirty-bitmap.c | 25 +
 include/block/dirty-bitmap.h |  1 +
 3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/block.c b/block.c
index 78db342..3a29de2 100644
--- a/block.c
+++ b/block.c
@@ -2274,9 +2274,6 @@ static void bdrv_move_feature_fields(BlockDriverState 
*bs_dest,
 bs_dest->copy_on_read   = bs_src->copy_on_read;
 
 bs_dest->enable_write_cache = bs_src->enable_write_cache;
-
-/* dirty bitmap */
-bs_dest->dirty_bitmaps  = bs_src->dirty_bitmaps;
 }
 
 static void change_parent_backing_link(BlockDriverState *from,
@@ -2302,10 +2299,12 @@ static void change_parent_backing_link(BlockDriverState 
*from,
 }
 
 static void swap_feature_fields(BlockDriverState *bs_top,
-BlockDriverState *bs_new)
+BlockDriverState *bs_new,
+Error **errp)
 {
 BlockDriverState tmp;
 
+bdrv_dirty_bitmap_swap(bs_top, bs_new);
 bdrv_move_feature_fields(, bs_top);
 bdrv_move_feature_fields(bs_top, bs_new);
 bdrv_move_feature_fields(bs_new, );
@@ -2343,7 +2342,7 @@ void bdrv_append(BlockDriverState *bs_new, 
BlockDriverState *bs_top)
 change_parent_backing_link(bs_top, bs_new);
 
 /* Some fields always stay on top of the backing file chain */
-swap_feature_fields(bs_top, bs_new);
+swap_feature_fields(bs_top, bs_new, NULL);
 
 bdrv_set_backing_hd(bs_new, bs_top);
 bdrv_unref(bs_top);
@@ -2368,7 +2367,7 @@ void bdrv_replace_in_backing_chain(BlockDriverState *old, 
BlockDriverState *new)
  * swap instead so that pointers aren't duplicated and cause trouble.
  * (Also, bdrv_swap() used to do the same.) */
 assert(!new->blk);
-swap_feature_fields(old, new);
+swap_feature_fields(old, new, NULL);
 }
 change_parent_backing_link(old, new);
 
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index 882a0db..a3a401f 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -65,6 +65,31 @@ BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState 
*bs, const char *name)
 return NULL;
 }
 
+/* Swap non-persistent dirty bitmaps. */
+void bdrv_dirty_bitmap_swap(BlockDriverState *bs1, BlockDriverState *bs2)
+{
+BdrvDirtyBitmap *bm, *next;
+QLIST_HEAD(, BdrvDirtyBitmap) tmp = QLIST_HEAD_INITIALIZER();
+
+QLIST_FOREACH_SAFE(bm, >dirty_bitmaps, list, next) {
+if (bm->persistent) {
+continue;
+}
+QLIST_REMOVE(bm, list);
+QLIST_INSERT_HEAD(, bm, list);
+}
+QLIST_FOREACH_SAFE(bm, >dirty_bitmaps, list, next) {
+if (bm->persistent) {
+continue;
+}
+QLIST_REMOVE(bm, list);
+QLIST_INSERT_HEAD(>dirty_bitmaps, bm, list);
+}
+QLIST_FOREACH_SAFE(bm, , list, next) {
+QLIST_INSERT_HEAD(>dirty_bitmaps, bm, list);
+}
+}
+
 void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap)
 {
 assert(!bdrv_dirty_bitmap_frozen(bitmap));
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
index 5885720..a4de9c7 100644
--- a/include/block/dirty-bitmap.h
+++ b/include/block/dirty-bitmap.h
@@ -23,6 +23,7 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState 
*bs,
Error **errp);
 BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
 const char *name);
+void bdrv_dirty_bitmap_swap(BlockDriverState *bs1, BlockDriverState *bs2);
 void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap);
 int bdrv_dirty_bitmap_set_persistent(BlockDriverState *bs,
  BdrvDirtyBitmap *bitmap,
-- 
2.4.3




Re: [Qemu-devel] [PATCH v3] Add optionrom compatible with fw_cfg DMA version

2016-01-26 Thread Gerd Hoffmann
On Di, 2016-01-26 at 12:20 +0100, Marc Marí wrote:
> On Tue, 26 Jan 2016 11:11:54 +
> Stefan Hajnoczi  wrote:
> 
> > On Mon, Jan 25, 2016 at 02:17:48PM +0100, Marc Marí wrote:
> > > +linuxboot_dma.img: linuxboot_dma.o
> > > + $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m elf_i386
> > > -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@") +
> > >  %.img: %.o
> > >   $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -Ttext 0 -e
> > > _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")  
> > 
> > Why is -m elf_i386 necessary for linuxboot_dma.img but not for the
> > other *.img files?
> 
> I cannot give a precise explanation. But if I don't force an output
> type, I get this error:
> 
> Building optionrom/linuxboot_dma.img
> ld: i386 architecture of input file `linuxboot_dma.o' is incompatible
> with i386:x86-64 output

Any chance the linker needs -m32 too?

cheers,
  Gerd




Re: [Qemu-devel] [PATCH] gtk: use qemu_chr_alloc() to allocate CharDriverState

2016-01-26 Thread Gerd Hoffmann
On Do, 2016-01-21 at 11:56 +, Daniel P. Berrange wrote:
> The gd_vc_handler() callback is using g_malloc0() to
> allocate the CharDriverState struct. As a result the
> logfd field is getting initialized to 0, instead of
> -1 when no logfile is requested.

added to patch queue.

thanks,
  Gerd




Re: [Qemu-devel] trace in arch/x86/kernel/apic/apic.c:1309 setup_local_APIC

2016-01-26 Thread Yang Zhang

On 2016/1/26 18:43, Stefan Priebe - Profihost AG wrote:


Am 26.01.2016 um 11:13 schrieb Yang Zhang:

On 2016/1/26 15:22, Stefan Priebe - Profihost AG wrote:

Hi,

Am 26.01.2016 um 02:46 schrieb Han, Huaitong:

What is the host kernel version and host dmesg information? And does
the problem exist when you use latest kernel and QEMU to replace old
binary file?


Guest and Host is both 4.1.15. You mean the complete dmesg output from
host?

What do you mean with replace old binary file? I haven't tested Kernel
4.4 as we use 4.1 as it is a long term stable kernel release.


Have you seen this before? I mean use the old KVM like 3.10?


Guest or host? To test with a guest would be quite easy. Downgrading the
host is very difficult not sure if the hw is supported.


Host. Does the issue only exist on the Westmere CPU?







Stefan


On Mon, 2016-01-25 at 14:51 +0100, Stefan Priebe - Profihost AG wrote:

Hi,

while running qemu 2.4 on whestmere CPUs i'm pretty often getting
this
one while booting:
[0.811645] Switched APIC routing to physical x2apic.
[1.835678] [ cut here ]
[1.835704] WARNING: CPU: 0 PID: 1 at
arch/x86/kernel/apic/apic.c:1309 setup_local_APIC+0x284/0x340()
[1.835714] Modules linked in:
[1.835724] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.1.15+72-ph
#1
[1.835731] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
BIOS rel-1.8.2-0-g33fbe13 by qemu-project.org 04/01/2014
[1.835743]  b69ffcea 88042d5e3d68 b669c37b
0918
[1.835754]   88042d5e3da8 b6080d67
88042d5e3da8
[1.835765]  0001  8000

[1.835777] Call Trace:
[1.835789]  [] dump_stack+0x45/0x57
[1.835799]  [] warn_slowpath_common+0x97/0xe0
[1.835806]  [] warn_slowpath_null+0x1a/0x20
[1.835813]  [] setup_local_APIC+0x284/0x340
[1.835824]  [] apic_bsp_setup+0x5b/0xb0
[1.835832]  []
native_smp_prepare_cpus+0x23b/0x295
[1.835842]  [] kernel_init_freeable+0xc7/0x20f
[1.835853]  [] ? rest_init+0x80/0x80
[1.835860]  [] kernel_init+0xe/0xf0
[1.835870]  [] ret_from_fork+0x42/0x70
[1.835877]  [] ? rest_init+0x80/0x80
[1.835891] ---[ end trace bdbe630a8de2832c ]---
[1.837613] Spurious LAPIC timer interrupt on cpu 0
[1.837957] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
[1.939574] smpboot: CPU0: Intel Westmere E56xx/L56xx/X56xx
(Nehalem-C) (fam: 06, model: 2c, stepping: 01)
[1.939630] Performance Events: unsupported p6 CPU model 44 no PMU
driver, software events only.
[1.950868] KVM setup paravirtual spinlock

Greets,
Stefan
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html







--
best regards
yang



Re: [Qemu-devel] [PATCH 1/8] nbd: client_close on error in nbd_co_client_start

2016-01-26 Thread Paolo Bonzini


On 26/01/2016 10:32, Kevin Wolf wrote:
> Am 25.01.2016 um 19:41 hat Max Reitz geschrieben:
>> > Use client_close() if an error in nbd_co_client_start() occurs instead
>> > of manually inlining parts of it. This fixes an assertion error on the
>> > server side if nbd_negotiate() fails.
>> > 
>> > Signed-off-by: Max Reitz 
> Paolo, if you can Ack this one, I can take the series through my tree.

Of course.  I had the same patch queued from Daniel.

Acked-by: Paolo Bonzini 

Paolo



Re: [Qemu-devel] [PULL 00/13] IDE & FDC patches

2016-01-26 Thread Peter Maydell
On 25 January 2016 at 19:41, John Snow  wrote:
> The following changes since commit 6ee06cc3dc7e8eb238e2f60cfd04f094d5c6b948:
>
>   Merge remote-tracking branch 'remotes/lalrae/tags/mips-20160125' into 
> staging (2016-01-25 10:42:52 +)
>
> are available in the git repository at:
>
>   https://github.com/jnsnow/qemu.git tags/ide-pull-request
>
> for you to fetch changes up to 4812fa27fa75bce89738a82a191755853dd88408:
>
>   fdc: change auto fallback drive for ISA FDC to 288 (2016-01-25 14:36:01 
> -0500)
>
> 

Applied, thanks.

-- PMM



[Qemu-devel] [RFC PATCH 09/16] qmp: Add block-dirty-bitmap-set-persistent

2016-01-26 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 blockdev.c   | 20 
 qapi/block-core.json | 22 ++
 qmp-commands.hx  | 31 +++
 3 files changed, 73 insertions(+)

diff --git a/blockdev.c b/blockdev.c
index 08236f2..a9d6617 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2699,6 +2699,9 @@ void qmp_block_dirty_bitmap_remove(const char *node, 
const char *name,
name);
 goto out;
 }
+if (bdrv_dirty_bitmap_set_persistent(bs, bitmap, false, false, errp)) {
+goto out;
+}
 bdrv_dirty_bitmap_make_anon(bitmap);
 bdrv_release_dirty_bitmap(bs, bitmap);
 
@@ -2740,6 +2743,23 @@ void qmp_block_dirty_bitmap_clear(const char *node, 
const char *name,
 aio_context_release(aio_context);
 }
 
+void qmp_block_dirty_bitmap_set_persistent(const char *node, const char *name,
+   bool persistent, Error **errp)
+{
+AioContext *aio_context;
+BdrvDirtyBitmap *bitmap;
+BlockDriverState *bs;
+
+bitmap = block_dirty_bitmap_lookup(node, name, , _context, errp);
+if (!bitmap || !bs) {
+return;
+}
+
+bdrv_dirty_bitmap_set_persistent(bs, bitmap, persistent, false, errp);
+
+aio_context_release(aio_context);
+}
+
 void hmp_drive_del(Monitor *mon, const QDict *qdict)
 {
 const char *id = qdict_get_str(qdict, "id");
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 0ac107c..52689ed 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1263,6 +1263,28 @@
 '*on-target-error': 'BlockdevOnError' } }
 
 ##
+# @block-dirty-bitmap-set-persistent
+#
+# Update a dirty bitmap's persistent state on the device
+#
+# @node: name of device/node which the bitmap is tracking
+#
+# @name: name of the dirty bitmap
+#
+# @persistent: #optinal whether to make the bitmap persistent, default is false
+#
+# Returns: nothing on success
+#  If @node is not a valid block device, DeviceNotFound
+#  If @name is not found, GenericError with an explanation
+#  If an error happens when setting the persistent state, GenericError
+#  with an explanation
+#
+# Since 2.6
+##
+{ 'command': 'block-dirty-bitmap-set-persistent',
+  'data': { 'node': 'str', 'name': 'str', 'persistent': 'bool' } }
+
+##
 # @block_set_io_throttle:
 #
 # Change I/O throttle limits for a block drive.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index bd4428e..e37cf09 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1458,6 +1458,37 @@ Example:
 EQMP
 
 {
+.name   = "block-dirty-bitmap-set-persistent",
+.args_type  = "node:B,name:s,persistent:b",
+.mhandler.cmd_new = qmp_marshal_block_dirty_bitmap_set_persistent,
+},
+
+SQMP
+
+block-dirty-bitmap-set-persistent
+-
+Since 2.6
+
+Update the persistent state of a dirty bitmap. Format driver support is
+required.
+
+Arguments:
+
+- "node": device/node on which to update the dirty bitmap (json-string)
+- "name": name of the dirty bitmap to update (json-string)
+- "persistent": the state to update to. (json-bool)
+
+Example:
+
+-> { "execute": "block-dirty-bitmap-set-persistent",
+"arguments": { "node": "drive0",
+   "name": "bitmap0",
+   "persistent": true } }
+<- { "return": {} }
+
+EQMP
+
+{
 .name   = "blockdev-snapshot-sync",
 .args_type  = 
"device:s?,node-name:s?,snapshot-file:s,snapshot-node-name:s?,format:s?,mode:s?",
 .mhandler.cmd_new = qmp_marshal_blockdev_snapshot_sync,
-- 
2.4.3




[Qemu-devel] [RFC PATCH 12/16] iotests: Add qbm format to 041

2016-01-26 Thread Fam Zheng
Though a number of test cases dosn't apply because of cluster size and
blkdebug limitation, mirroring qbm can be covered by all other cases.

Signed-off-by: Fam Zheng 
---
 tests/qemu-iotests/041 | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
index c7da95d..3712aca 100755
--- a/tests/qemu-iotests/041
+++ b/tests/qemu-iotests/041
@@ -139,6 +139,8 @@ class TestSingleDrive(iotests.QMPTestCase):
 'target image does not match source after mirroring')
 
 def test_small_buffer2(self):
+if iotests.imgfmt == "qbm":
+return
 self.assert_no_active_block_jobs()
 
 qemu_img('create', '-f', iotests.imgfmt, '-o', 
'cluster_size=%d,size=%d'
@@ -155,6 +157,8 @@ class TestSingleDrive(iotests.QMPTestCase):
 'target image does not match source after mirroring')
 
 def test_large_cluster(self):
+if iotests.imgfmt == "qbm":
+return
 self.assert_no_active_block_jobs()
 
 qemu_img('create', '-f', iotests.imgfmt, '-o', 
'cluster_size=%d,backing_file=%s'
@@ -265,9 +269,9 @@ class TestMirrorNoBacking(iotests.QMPTestCase):
 os.remove(backing_img)
 try:
 os.remove(target_backing_img)
+os.remove(target_img)
 except:
 pass
-os.remove(target_img)
 
 def test_complete(self):
 self.assert_no_active_block_jobs()
@@ -300,6 +304,8 @@ class TestMirrorNoBacking(iotests.QMPTestCase):
 'target image does not match source after mirroring')
 
 def test_large_cluster(self):
+if iotests.imgfmt == "qbm":
+return
 self.assert_no_active_block_jobs()
 
 # qemu-img create fails if the image is not there
@@ -461,6 +467,8 @@ new_state = "1"
 self.vm.shutdown()
 
 def test_large_cluster(self):
+if iotests.imgfmt == "qbm":
+return
 self.assert_no_active_block_jobs()
 
 # Test COW into the target image.  The first half of the
@@ -568,6 +576,8 @@ new_state = "1"
 os.remove(self.blkdebug_file)
 
 def test_report_write(self):
+if iotests.imgfmt == "qbm":
+return
 self.assert_no_active_block_jobs()
 
 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
@@ -595,6 +605,8 @@ new_state = "1"
 self.vm.shutdown()
 
 def test_ignore_write(self):
+if iotests.imgfmt == "qbm":
+return
 self.assert_no_active_block_jobs()
 
 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
@@ -612,6 +624,8 @@ new_state = "1"
 self.vm.shutdown()
 
 def test_stop_write(self):
+if iotests.imgfmt == "qbm":
+return
 self.assert_no_active_block_jobs()
 
 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
@@ -981,4 +995,4 @@ class TestRepairQuorum(iotests.QMPTestCase):
 self.vm.shutdown()
 
 if __name__ == '__main__':
-iotests.main(supported_fmts=['qcow2', 'qed'])
+iotests.main(supported_fmts=['qcow2', 'qed', 'qbm'])
-- 
2.4.3




Re: [Qemu-devel] trace in arch/x86/kernel/apic/apic.c:1309 setup_local_APIC

2016-01-26 Thread Stefan Priebe - Profihost AG

Am 26.01.2016 um 11:13 schrieb Yang Zhang:
> On 2016/1/26 15:22, Stefan Priebe - Profihost AG wrote:
>> Hi,
>>
>> Am 26.01.2016 um 02:46 schrieb Han, Huaitong:
>>> What is the host kernel version and host dmesg information? And does
>>> the problem exist when you use latest kernel and QEMU to replace old
>>> binary file?
>>
>> Guest and Host is both 4.1.15. You mean the complete dmesg output from
>> host?
>>
>> What do you mean with replace old binary file? I haven't tested Kernel
>> 4.4 as we use 4.1 as it is a long term stable kernel release.
> 
> Have you seen this before? I mean use the old KVM like 3.10?

Guest or host? To test with a guest would be quite easy. Downgrading the
host is very difficult not sure if the hw is supported.

> 
>>
>> Stefan
>>
>>> On Mon, 2016-01-25 at 14:51 +0100, Stefan Priebe - Profihost AG wrote:
 Hi,

 while running qemu 2.4 on whestmere CPUs i'm pretty often getting
 this
 one while booting:
 [0.811645] Switched APIC routing to physical x2apic.
 [1.835678] [ cut here ]
 [1.835704] WARNING: CPU: 0 PID: 1 at
 arch/x86/kernel/apic/apic.c:1309 setup_local_APIC+0x284/0x340()
 [1.835714] Modules linked in:
 [1.835724] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.1.15+72-ph
 #1
 [1.835731] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
 BIOS rel-1.8.2-0-g33fbe13 by qemu-project.org 04/01/2014
 [1.835743]  b69ffcea 88042d5e3d68 b669c37b
 0918
 [1.835754]   88042d5e3da8 b6080d67
 88042d5e3da8
 [1.835765]  0001  8000
 
 [1.835777] Call Trace:
 [1.835789]  [] dump_stack+0x45/0x57
 [1.835799]  [] warn_slowpath_common+0x97/0xe0
 [1.835806]  [] warn_slowpath_null+0x1a/0x20
 [1.835813]  [] setup_local_APIC+0x284/0x340
 [1.835824]  [] apic_bsp_setup+0x5b/0xb0
 [1.835832]  []
 native_smp_prepare_cpus+0x23b/0x295
 [1.835842]  [] kernel_init_freeable+0xc7/0x20f
 [1.835853]  [] ? rest_init+0x80/0x80
 [1.835860]  [] kernel_init+0xe/0xf0
 [1.835870]  [] ret_from_fork+0x42/0x70
 [1.835877]  [] ? rest_init+0x80/0x80
 [1.835891] ---[ end trace bdbe630a8de2832c ]---
 [1.837613] Spurious LAPIC timer interrupt on cpu 0
 [1.837957] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
 [1.939574] smpboot: CPU0: Intel Westmere E56xx/L56xx/X56xx
 (Nehalem-C) (fam: 06, model: 2c, stepping: 01)
 [1.939630] Performance Events: unsupported p6 CPU model 44 no PMU
 driver, software events only.
 [1.950868] KVM setup paravirtual spinlock

 Greets,
 Stefan
 -- 
 To unsubscribe from this list: send the line "unsubscribe kvm" in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> -- 
>> To unsubscribe from this list: send the line "unsubscribe kvm" in
>> the body of a message to majord...@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
> 
> 



[Qemu-devel] [PATCH 0/4] usb: hotplug support for usb-bot and usb-uas

2016-01-26 Thread Gerd Hoffmann
  Hi,

Composite device hotplug is a long-standing issue in qemu.

PCI multifunction hotplug has been solved recently in a pci-specific
way, by simply not showing hot-plugged functions to the guest until
function #0 is plugged.

So I figured we maybe should check whenever we can apply a simliar trick
to USB composite devices.  As the usb subsystem already can hide usb
devices from the guest (used for example with usb-host, in case the
physical usb device is not plugged in the host machine) this turned out
to be surprisingly simple.

So, here we go.  Basic idea is the "attached" state becomes settable via
monitor.  Now you can create a usb-bot (or usb-uas) device, then attach
the scsi device(s) you want, and when you are done you flip attached to
true to make the composed device visible to the guest.

pleae review & comment,
  Gerd

Gerd Hoffmann (4):
  usb: make USBDevice->attached bool
  usb: add attached property
  usb-bot: hotplug support
  usb-uas: hotplug support

 hw/usb/bus.c | 50 ++
 hw/usb/dev-storage.c |  8 ++--
 hw/usb/dev-uas.c |  5 +
 include/hw/usb.h |  3 ++-
 4 files changed, 59 insertions(+), 7 deletions(-)

-- 
1.8.3.1




[Qemu-devel] [PATCH] net/traffic-mirrorer:Add traffic-mirroer

2016-01-26 Thread Zhang Chen
From: ZhangChen 

Traffic-mirrorer is a plugin of netfilter.
It make qemu has ability to copy and mirror guest's
net packet. we output packet to chardev.

usage:

-netdev tap,id=hn0
-chardev socket,id=mirrorer0,host=ip_primary,port=X,server,nowait
-traffic-mirrorer,id=m0,netdev=hn0,queue=tx,outdev=mirrorer0

Signed-off-by: ZhangChen 
Signed-off-by: Wen Congyang 
---
 net/Makefile.objs  |   1 +
 net/traffic-mirrorer.c | 173 +
 qemu-options.hx|   5 ++
 vl.c   |   3 +-
 4 files changed, 181 insertions(+), 1 deletion(-)
 create mode 100644 net/traffic-mirrorer.c

diff --git a/net/Makefile.objs b/net/Makefile.objs
index 5fa2f97..6466764 100644
--- a/net/Makefile.objs
+++ b/net/Makefile.objs
@@ -15,3 +15,4 @@ common-obj-$(CONFIG_VDE) += vde.o
 common-obj-$(CONFIG_NETMAP) += netmap.o
 common-obj-y += filter.o
 common-obj-y += filter-buffer.o
+common-obj-y += traffic-mirrorer.o
diff --git a/net/traffic-mirrorer.c b/net/traffic-mirrorer.c
new file mode 100644
index 000..3b0da82
--- /dev/null
+++ b/net/traffic-mirrorer.c
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
+ * Copyright (c) 2016 FUJITSU LIMITED
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Author: Zhang Chen 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ */
+
+#include "net/filter.h"
+#include "net/net.h"
+#include "qemu-common.h"
+#include "qapi/qmp/qerror.h"
+#include "qapi-visit.h"
+#include "qom/object.h"
+#include "qemu/main-loop.h"
+#include "qemu/error-report.h"
+#include "trace.h"
+#include "sysemu/char.h"
+#include "qemu/iov.h"
+
+#define FILTER_TRAFFIC_MIRRORER(obj) \
+OBJECT_CHECK(MirrorerState, (obj), TYPE_FILTER_TRAFFIC_MIRRORER)
+
+#define TYPE_FILTER_TRAFFIC_MIRRORER "traffic-mirrorer"
+
+typedef struct MirrorerState {
+NetFilterState parent_obj;
+char *outdev;
+CharDriverState *chr_out;
+
+} MirrorerState;
+
+static ssize_t traffic_mirrorer_send(NetFilterState *nf,
+ const struct iovec *iov,
+ int iovcnt)
+{
+MirrorerState *s = FILTER_TRAFFIC_MIRRORER(nf);
+ssize_t ret = 0;
+ssize_t size = 0;
+char *buf;
+
+size = iov_size(iov, iovcnt);
+if (!size) {
+return 0;
+}
+
+buf = g_malloc0(size);
+iov_to_buf(iov, iovcnt, 0, buf, size);
+ret = qemu_chr_fe_write(s->chr_out, (uint8_t *), sizeof(size));
+if (ret < 0) {
+g_free(buf);
+return ret;
+}
+
+ret = qemu_chr_fe_write(s->chr_out, (uint8_t *)buf, size);
+g_free(buf);
+return ret;
+}
+
+static ssize_t traffic_mirrorer_receive_iov(NetFilterState *nf,
+ NetClientState *sender,
+ unsigned flags,
+ const struct iovec *iov,
+ int iovcnt,
+ NetPacketSent *sent_cb)
+{
+/*
+ * We copy and mirror packet to outdev,
+ * then put back the packet.
+ */
+ssize_t ret = 0;
+
+ret = traffic_mirrorer_send(nf, iov, iovcnt);
+if (ret < 0) {
+error_report("traffic_mirrorer_send failed");
+}
+
+return 0;
+}
+
+static void traffic_mirrorer_cleanup(NetFilterState *nf)
+{
+MirrorerState *s = FILTER_TRAFFIC_MIRRORER(nf);
+
+if (s->chr_out) {
+qemu_chr_fe_release(s->chr_out);
+}
+}
+
+static void traffic_mirrorer_setup(NetFilterState *nf, Error **errp)
+{
+MirrorerState *s = FILTER_TRAFFIC_MIRRORER(nf);
+
+if (!s->outdev) {
+error_setg(errp, "filter traffic mirrorer needs 'outdev' property set!"
+"property set!");
+return;
+}
+
+s->chr_out = qemu_chr_find(s->outdev);
+if (s->chr_out == NULL) {
+error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+  "Device '%s' not found", s->outdev);
+return;
+}
+
+if (qemu_chr_fe_claim(s->chr_out) != 0) {
+error_setg(errp, QERR_DEVICE_IN_USE, s->outdev);
+return;
+}
+}
+
+static void traffic_mirrorer_class_init(ObjectClass *oc, void *data)
+{
+NetFilterClass *nfc = NETFILTER_CLASS(oc);
+
+nfc->setup = traffic_mirrorer_setup;
+nfc->cleanup = traffic_mirrorer_cleanup;
+nfc->receive_iov = traffic_mirrorer_receive_iov;
+}
+
+static char *traffic_mirrorer_get_outdev(Object *obj, Error **errp)
+{
+MirrorerState *s = FILTER_TRAFFIC_MIRRORER(obj);
+
+return g_strdup(s->outdev);
+}
+
+static void
+traffic_mirrorer_set_outdev(Object *obj, const char *value, Error **errp)
+{
+MirrorerState *s = FILTER_TRAFFIC_MIRRORER(obj);
+
+g_free(s->outdev);
+s->outdev = g_strdup(value);
+if (!s->outdev) {
+

Re: [Qemu-devel] [PATCH v2 1/3] linux-user/mmap.c: Set prot page flags for the correct region in mmap_frag()

2016-01-26 Thread Peter Maydell
On 26 January 2016 at 02:58, Chen Gang  wrote:
> The related comments for  "if (prot1 == 0)" code block is "no page was
> there, so we allocate one".
>
> So I guess this code block is not only allocate page for guest, but also
> for host. So prot1 is not only for the guest page, but also for host
> page.

The comment means specifically "allocate a host page".

> If we do not page_set_flags with PAGE_VALID, The next call
> in mmap_frag for the same area will let prot1 be 0, so still
> fall into "if (prot1 == 0)" code block.

But in what case will we call mmap_frag() again before we
call page_set_flags() at the bottom of target_mmap()?
That is what is not clear to me, and why I asked you to describe
what the case is that you're seeing problems with.

Reading the target_mmap() code, its intention seems to be:
 (a) if the whole allocation fits in one host page, call
 mmap_frag() once and then "goto the_end1"
 (b) otherwise, we'll call mmap_frag() once for the start
 of the guest mapping, and once for the end, which must
 be two different host pages

So if you're seeing mmap_frag() called twice for the same
host page then something is going wrong, but I'm not sure what.

thanks
-- PMM



Re: [Qemu-devel] Linux vhost-user interrupt management fixes

2016-01-26 Thread Didier Pallard

On 01/25/2016 10:22 AM, Victor Kaplansky wrote:

On Thu, Dec 03, 2015 at 10:53:16AM +0100, Didier Pallard wrote:

Hi,

I recently did some stress tests of a vhost-user interface using an UDP
traffic generator. Traffic generator was connected to 2 physical ports
that are in turn connected to 2 virtio ports through a linux bridge, VM
(running linux) doing routing to forward packets between the 2 virtio ports.
When traffic reaches high pps rates of small packets, I faced the 2 following
problems:

- at some time, my qemu socket becomes full, causing qemu to send incomplete
SET_VRING_CALL messages to vhost-user backend (without proper fd set in
ancillary data).
- after some time, some interrupts are lost, causing the VM to stop
transmitting packets.

Both problems come from the fact that interrupt masking/unmasking of the VM
is deferred to vhost-user backend through the linux socket.
First problem comes from the fact that socket buffer gets full; it is corrected
in the first patch of the serie.
Second problem is a bit more complex. From what i understand of the code,
when VM wants to mask/unmask interrupts, qemu traps the command and sends a
SET_VRING_CALL to the vhost-user to swap interrupt notifications either to
a dummy descriptor or to an fd that was given to kvm module to route
interruption to the VM. After sending SET_VRING_CALL message through
the socket, VM code continues to run, assuming that the interrupts are now
masked; but due to linux socket, this message may be buffered and not currently
treated by the vhost-user backend, ie interrupts are not really masked/unmasked
as they ought to be.
I think it can be solved in two different ways:
- by waiting for an acknowledgement of vhost-user backend before exiting
interrupt masking function, this ensures that interrupt masking is correctly
taken into account before giving back hand to the VM, but it has a very high
cost in term of cycles. Moreover, unless specifying a new option, it will
break current API, since existing vhost-user implementations do not
expect a return message on a SET_VRING_CALL call.
- second way could be, in case vhost-user is involved, to restore the
initial behaviour of interrupt masking (ie masking/unmasking interrupts
by taking/giving vring_call fd from/to kernel kvm module).
Patches 2 and 3 of the serie propose an implementation of this second option.

Didier


Tested-by: Victor Kaplansky 


Didier Pallard (3):
   char: fix vhost-user socket full
   virtio-pci: add an option to bypass guest_notifier_mask
   vhost-net: force guest_notifier_mask bypass in vhost-user case

  hw/net/vhost_net.c | 19 ++-
  hw/virtio/vhost.c  | 13 +
  hw/virtio/virtio-pci.c | 29 +++--
  hw/virtio/virtio-pci.h |  6 ++
  qemu-char.c| 10 ++
  5 files changed, 70 insertions(+), 7 deletions(-)

--
2.1.4




thanks for the tests, victor

didier




Re: [Qemu-devel] [PATCH] iotests: Limit supported formats for 118

2016-01-26 Thread Kevin Wolf
Am 26.01.2016 um 08:09 hat Markus Armbruster geschrieben:
> Max Reitz  writes:
> 
> > Image formats used in test 118 need to support image creation.
> >
> > Reported-by: Markus Armbruster 
> > Signed-off-by: Max Reitz 
> > ---
> >  tests/qemu-iotests/118 | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118
> > index 114d0e2..beb69d0 100755
> > --- a/tests/qemu-iotests/118
> > +++ b/tests/qemu-iotests/118
> > @@ -717,4 +717,6 @@ if __name__ == '__main__':
> >  # We need floppy and IDE CD-ROM
> >  iotests.notrun('not suitable for this machine type: %s' %
> > iotests.qemu_default_machine)
> > -iotests.main()
> > +# Need to support image creation
> > +iotests.main(supported_fmts=['vpc', 'parallels', 'qcow', 'vdi', 
> > 'qcow2',
> > + 'vmdk', 'raw', 'vhdx', 'qed'])
> 
> Reviewed-by: Markus Armbruster 

Thanks, applied to the block branch.

Kevin



Re: [Qemu-devel] [PATCH v2 1/3] linux-user/mmap.c: Set prot page flags for the correct region in mmap_frag()

2016-01-26 Thread Chen Gang

On 2016年01月26日 17:11, Peter Maydell wrote:
> On 26 January 2016 at 02:58, Chen Gang  wrote:
>> The related comments for  "if (prot1 == 0)" code block is "no page was
>> there, so we allocate one".
>>
>> So I guess this code block is not only allocate page for guest, but also
>> for host. So prot1 is not only for the guest page, but also for host
>> page.
> 
> The comment means specifically "allocate a host page".
> 

OK, thanks.

>> If we do not page_set_flags with PAGE_VALID, The next call
>> in mmap_frag for the same area will let prot1 be 0, so still
>> fall into "if (prot1 == 0)" code block.
> 
> But in what case will we call mmap_frag() again before we
> call page_set_flags() at the bottom of target_mmap()?
> That is what is not clear to me, and why I asked you to describe
> what the case is that you're seeing problems with.
> 

When I run WeChat.exe with i386 wine with qemu-i386 under sw_64 arch.

 - The related command:

   "./i386-linux-user/qemu-i386 -strace -L /upstream/i386_wine 
/upstream/i386_wine/usr/local/bin/wine "C:\\Program 
Files\\Tencent\\WeChat\\WeChat.exe" > ana/try/info-strace.log 2>&1"

 - The related output (no any munmap, 135168 = 128KB + 4KB):

   4600 
mmap2(0x0034,135168,PROT_READ,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0) = 
0x0034
   4600 mmap2(0x0034,135168,PROT_READ,MAP_SHARED|MAP_FIXED,8,0) = 0x0034
   4600 rt_sigprocmask(SIG_SETMASK,0x0033f574,NULL) = 0
   4600 rt_sigprocmask(SIG_BLOCK,0x7bced7e0,0x0033f5d0) = 0
   4600 write(3,0x33f6cc,64) = 64
   4600 read(4,0x33f6cc,64) = 1
   4600 rt_sigprocmask(SIG_SETMASK,0x0033f5d0,NULL) = 0
   4600 close(8) = 0
   4600 rt_sigprocmask(SIG_BLOCK,0x7bced7e0,0x0033f674) = 0
   4600 mprotect(0x0016,65536,PROT_READ|PROT_WRITE) = 0
   4600 rt_sigprocmask(SIG_SETMASK,0x0033f674,NULL) = 0
   4600 rt_sigprocmask(SIG_BLOCK,0x7bced7e0,0x0033f990) = 0
   4600 
mmap2(0x0034,135168,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE,-1,0)
 = 0x0034

wine often does like above, map the same position multiple times.

> Reading the target_mmap() code, its intention seems to be:
>  (a) if the whole allocation fits in one host page, call
>  mmap_frag() once and then "goto the_end1"

Also yes to me.

>  (b) otherwise, we'll call mmap_frag() once for the start
>  of the guest mapping, and once for the end, which must
>  be two different host pages
> 

Also yes to me.

> So if you're seeing mmap_frag() called twice for the same
> host page then something is going wrong, but I'm not sure what.
> 

For the case I provide above, it can call mmap_frag() twice for the same
host page.

By the way, after have a full test again, all related issues are OK, it
seems we need not this patch to fix current issues, it is really very
strange to me!(maybe it is fixed by my other patches? I don't know)

At present, our sw_64 qemu-i386 status:

 - Can run notepad.exe correctly, can run acdsee5.0.exe setup program
   successfully.

 - The performance is acceptable, after optimize the wine code (simply
   use 32 split times instead of 2 for reserve_area recursion), the
   initialization speed is really quick enough. :-)

 - When run WeChat.exe, it can popup connection GUI box, but will quit
   under sw_64. But for x86_64 qemu-i386, it can run WeChat.exe
   correctly (although after enter main gui, it is not stable enough).


Thanks.
-- 
Chen Gang (陈刚)

Open, share, and attitude like air, water, and life which God blessed



Re: [Qemu-devel] VFIO based vGPU(was Re: [Announcement] 2015-Q3 release of XenGT - a Mediated ...)

2016-01-26 Thread Neo Jia
On Mon, Jan 25, 2016 at 09:45:14PM +, Tian, Kevin wrote:
> > From: Alex Williamson [mailto:alex.william...@redhat.com]
> > Sent: Tuesday, January 26, 2016 5:30 AM
> > 
> > [cc +Neo @Nvidia]
> > 
> > Hi Jike,
> > 
> > On Mon, 2016-01-25 at 19:34 +0800, Jike Song wrote:
> > > On 01/20/2016 05:05 PM, Tian, Kevin wrote:
> > > > I would expect we can spell out next level tasks toward above
> > > > direction, upon which Alex can easily judge whether there are
> > > > some common VFIO framework changes that he can help :-)
> > >
> > > Hi Alex,
> > >
> > > Here is a draft task list after a short discussion w/ Kevin,
> > > would you please have a look?
> > >
> > >   Bus Driver
> > >
> > >   { in i915/vgt/xxx.c }
> > >
> > >   - define a subset of vfio_pci interfaces
> > >   - selective pass-through (say aperture)
> > >   - trap MMIO: interface w/ QEMU
> > 
> > What's included in the subset?  Certainly the bus reset ioctls really
> > don't apply, but you'll need to support the full device interface,
> > right?  That includes the region info ioctl and access through the vfio
> > device file descriptor as well as the interrupt info and setup ioctls.
> 
> That is the next level detail Jike will figure out and discuss soon.
> 
> yes, basic region info/access should be necessary. For interrupt, could
> you elaborate a bit what current interface is doing? If just about creating
> an eventfd for virtual interrupt injection, it applies to vgpu too.
> 
> > 
> > >   IOMMU
> > >
> > >   { in a new vfio_xxx.c }
> > >
> > >   - allocate: struct device & IOMMU group
> > 
> > It seems like the vgpu instance management would do this.
> > 
> > >   - map/unmap functions for vgpu
> > >   - rb-tree to maintain iova/hpa mappings
> > 
> > Yep, pretty much what type1 does now, but without mapping through the
> > IOMMU API.  Essentially just a database of the current userspace
> > mappings that can be accessed for page pinning and IOVA->HPA
> > translation.
> 
> The thought is to reuse iommu_type1.c, by abstracting several underlying
> operations and then put vgpu specific implementation in a vfio_vgpu.c (e.g.
> for map/unmap instead of using IOMMU API, an iova/hpa mapping is updated
> accordingly), etc.
> 
> This file will also connect between VFIO and vendor specific vgpu driver,
> e.g. exposing interfaces to allow the latter querying iova<->hpa and also 
> creating necessary VFIO structures like aforementioned device/IOMMUas...
> 
> > 
> > >   - interacts with kvmgt.c
> > >
> > >
> > >   vgpu instance management
> > >
> > >   { in i915 }
> > >
> > >   - path, create/destroy
> > >
> > 
> > Yes, and since you're creating and destroying the vgpu here, this is
> > where I'd expect a struct device to be created and added to an IOMMU
> > group.  The lifecycle management should really include links between
> > the vGPU and physical GPU, which would be much, much easier to do with
> > struct devices create here rather than at the point where we start
> > doing vfio "stuff".
> 
> It's invoked here, but expecting the function exposed by vfio_vgpu.c. It's
> not good to touch vfio internal structures from another module (such as
> i915.ko)
> 
> > 
> > Nvidia has also been looking at this and has some ideas how we might
> > standardize on some of the interfaces and create a vgpu framework to
> > help share code between vendors and hopefully make a more consistent
> > userspace interface for libvirt as well.  I'll let Neo provide some
> > details.  Thanks,
> > 
> 
> Nice to know that. Neo, please share your thought here.

Hi Alex, Kevin and Jike,

Thanks for adding me to this technical discussion, a great opportunity
for us to design together which can bring both Intel and NVIDIA vGPU solution to
KVM platform.

Instead of directly jumping to the proposal that we have been working on
recently for NVIDIA vGPU on KVM, I think it is better for me to put out couple
quick comments / thoughts regarding the existing discussions on this thread as
fundamentally I think we are solving the same problem, DMA, interrupt and MMIO.

Then we can look at what we have, hopefully we can reach some consensus soon.

> Yes, and since you're creating and destroying the vgpu here, this is
> where I'd expect a struct device to be created and added to an IOMMU
> group.  The lifecycle management should really include links between
> the vGPU and physical GPU, which would be much, much easier to do with
> struct devices create here rather than at the point where we start
> doing vfio "stuff".

Infact to keep vfio-vgpu to be more generic, vgpu device creation and management
can be centralized and done in vfio-vgpu. That also include adding to IOMMU
group and VFIO group.

Graphics driver can register with vfio-vgpu to get management and emulation call
backs to graphics driver.   

We already have struct vgpu_device in our proposal that keeps pointer to
physical device.  

> - vfio_pci will 

[Qemu-devel] [RFC PATCH 14/16] iotests: Add qbm to applicable test cases

2016-01-26 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 tests/qemu-iotests/004 | 2 +-
 tests/qemu-iotests/017 | 2 +-
 tests/qemu-iotests/018 | 2 +-
 tests/qemu-iotests/019 | 2 +-
 tests/qemu-iotests/020 | 2 +-
 tests/qemu-iotests/024 | 2 +-
 tests/qemu-iotests/025 | 2 +-
 tests/qemu-iotests/027 | 2 +-
 tests/qemu-iotests/028 | 2 +-
 tests/qemu-iotests/030 | 2 +-
 tests/qemu-iotests/034 | 2 +-
 tests/qemu-iotests/037 | 2 +-
 tests/qemu-iotests/038 | 2 +-
 tests/qemu-iotests/040 | 2 +-
 tests/qemu-iotests/050 | 2 +-
 tests/qemu-iotests/055 | 2 +-
 tests/qemu-iotests/056 | 2 +-
 tests/qemu-iotests/069 | 2 +-
 tests/qemu-iotests/072 | 2 +-
 tests/qemu-iotests/086 | 2 +-
 tests/qemu-iotests/096 | 2 +-
 tests/qemu-iotests/099 | 2 +-
 tests/qemu-iotests/110 | 2 +-
 tests/qemu-iotests/129 | 2 +-
 tests/qemu-iotests/132 | 2 +-
 tests/qemu-iotests/139 | 2 +-
 26 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/tests/qemu-iotests/004 b/tests/qemu-iotests/004
index 2ad77ed..a67882e 100755
--- a/tests/qemu-iotests/004
+++ b/tests/qemu-iotests/004
@@ -38,7 +38,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 . ./common.rc
 . ./common.filter
 
-_supported_fmt raw qcow qcow2 qed vdi vmdk vhdx
+_supported_fmt raw qcow qcow2 qed vdi vmdk vhdx qbm
 _supported_proto generic
 _supported_os Linux
 
diff --git a/tests/qemu-iotests/017 b/tests/qemu-iotests/017
index 3af3cdf..220d26f 100755
--- a/tests/qemu-iotests/017
+++ b/tests/qemu-iotests/017
@@ -40,7 +40,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 . ./common.pattern
 
 # Any format supporting backing files
-_supported_fmt qcow qcow2 vmdk qed
+_supported_fmt qcow qcow2 vmdk qed qbm
 _supported_proto generic
 _supported_os Linux
 _unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat"
diff --git a/tests/qemu-iotests/018 b/tests/qemu-iotests/018
index 07b2de9..185c617 100755
--- a/tests/qemu-iotests/018
+++ b/tests/qemu-iotests/018
@@ -40,7 +40,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 . ./common.pattern
 
 # Any format supporting backing files
-_supported_fmt qcow qcow2 vmdk qed
+_supported_fmt qcow qcow2 vmdk qed qbm
 _supported_proto file
 _supported_os Linux
 _unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat"
diff --git a/tests/qemu-iotests/019 b/tests/qemu-iotests/019
index 0937b5c..6354a7d 100755
--- a/tests/qemu-iotests/019
+++ b/tests/qemu-iotests/019
@@ -44,7 +44,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 . ./common.pattern
 
 # Any format supporting backing files
-_supported_fmt qcow qcow2 vmdk qed
+_supported_fmt qcow qcow2 vmdk qed qbm
 _supported_proto file
 _supported_os Linux
 _unsupported_imgopts "subformat=monolithicFlat" \
diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020
index 6625b55..187739b 100755
--- a/tests/qemu-iotests/020
+++ b/tests/qemu-iotests/020
@@ -42,7 +42,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 . ./common.pattern
 
 # Any format supporting backing files
-_supported_fmt qcow qcow2 vmdk qed
+_supported_fmt qcow qcow2 vmdk qed qbm
 _supported_proto generic
 _supported_os Linux
 _unsupported_imgopts "subformat=monolithicFlat" \
diff --git a/tests/qemu-iotests/024 b/tests/qemu-iotests/024
index 2c2d148..844bb11 100755
--- a/tests/qemu-iotests/024
+++ b/tests/qemu-iotests/024
@@ -42,7 +42,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 . ./common.pattern
 
 # Currently only qcow2 and qed support rebasing
-_supported_fmt qcow2 qed
+_supported_fmt qcow2 qed qbm
 _supported_proto file
 _supported_os Linux
 
diff --git a/tests/qemu-iotests/025 b/tests/qemu-iotests/025
index 467a4b7..6a7e592 100755
--- a/tests/qemu-iotests/025
+++ b/tests/qemu-iotests/025
@@ -39,7 +39,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 . ./common.filter
 . ./common.pattern
 
-_supported_fmt raw qcow2 qed
+_supported_fmt raw qcow2 qed qbm
 _supported_proto file sheepdog rbd nfs archipelago
 _supported_os Linux
 
diff --git a/tests/qemu-iotests/027 b/tests/qemu-iotests/027
index 3fa81b8..be97963 100755
--- a/tests/qemu-iotests/027
+++ b/tests/qemu-iotests/027
@@ -38,7 +38,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 . ./common.rc
 . ./common.filter
 
-_supported_fmt vmdk qcow qcow2 qed
+_supported_fmt vmdk qcow qcow2 qed qbm
 _supported_proto generic
 _supported_os Linux
 
diff --git a/tests/qemu-iotests/028 b/tests/qemu-iotests/028
index 4909b9b..43d3f0a 100755
--- a/tests/qemu-iotests/028
+++ b/tests/qemu-iotests/028
@@ -46,7 +46,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 
 # Any format supporting backing files except vmdk and qcow which do not support
 # smaller backing files.
-_supported_fmt qcow2 qed
+_supported_fmt qcow2 qed qbm
 _supported_proto file
 _supported_os Linux
 
diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030
index 32469ef..fe5ad4a 100755
--- a/tests/qemu-iotests/030
+++ b/tests/qemu-iotests/030
@@ -467,4 +467,4 @@ class TestSetSpeed(iotests.QMPTestCase):
 self.cancel_and_wait()
 
 if __name__ == '__main__':
-

[Qemu-devel] [PATCH 4/4] usb-uas: hotplug support

2016-01-26 Thread Gerd Hoffmann
Make attached property settable and turns off auto-attach in case the
device was hotplugged.  Hotplugging works simliar to usb-bot now.

Signed-off-by: Gerd Hoffmann 
---
 hw/usb/dev-uas.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c
index 38b26c5..4fd0bca 100644
--- a/hw/usb/dev-uas.c
+++ b/hw/usb/dev-uas.c
@@ -899,9 +899,13 @@ static void usb_uas_handle_destroy(USBDevice *dev)
 static void usb_uas_realize(USBDevice *dev, Error **errp)
 {
 UASDevice *uas = USB_UAS(dev);
+DeviceState *d = DEVICE(dev);
 
 usb_desc_create_serial(dev);
 usb_desc_init(dev);
+if (d->hotplugged) {
+uas->dev.auto_attach = 0;
+}
 
 QTAILQ_INIT(>results);
 QTAILQ_INIT(>requests);
@@ -939,6 +943,7 @@ static void usb_uas_class_initfn(ObjectClass *klass, void 
*data)
 uc->handle_control = usb_uas_handle_control;
 uc->handle_data= usb_uas_handle_data;
 uc->handle_destroy = usb_uas_handle_destroy;
+uc->attached_settable = true;
 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
 dc->fw_name = "storage";
 dc->vmsd = _usb_uas;
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH v3] Add optionrom compatible with fw_cfg DMA version

2016-01-26 Thread Stefan Hajnoczi
On Mon, Jan 25, 2016 at 02:17:48PM +0100, Marc Marí wrote:
> +linuxboot_dma.img: linuxboot_dma.o
> + $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m elf_i386 -Ttext 0 -e 
> _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
> +
>  %.img: %.o
>   $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -Ttext 0 -e _start -s -o $@ 
> $<,"  Building $(TARGET_DIR)$@")

Why is -m elf_i386 necessary for linuxboot_dma.img but not for the other
*.img files?


Otherwise:
Reviewed-by: Stefan Hajnoczi 


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH] audio: Clean up includes

2016-01-26 Thread Gerd Hoffmann
On Mo, 2016-01-18 at 17:33 +, Peter Maydell wrote:
> Clean up includes so that osdep.h is included first and headers
> which it implies are not included manually.
> 
> This commit was created with scripts/clean-includes.
> 
> Signed-off-by: Peter Maydell 

added to audio queue.

thanks,
  Gerd



[Qemu-devel] [RFC PATCH 16/16] iotests: Add persistent bitmap test case 141

2016-01-26 Thread Fam Zheng
For now it merely invokes block-dirty-bitmap-{add,set-persistent}.
Verification of the bitmap data and user data to be added in the future.

Signed-off-by: Fam Zheng 
---
 tests/qemu-iotests/141 | 62 ++
 tests/qemu-iotests/141.out |  5 
 tests/qemu-iotests/group   |  1 +
 3 files changed, 68 insertions(+)
 create mode 100644 tests/qemu-iotests/141
 create mode 100644 tests/qemu-iotests/141.out

diff --git a/tests/qemu-iotests/141 b/tests/qemu-iotests/141
new file mode 100644
index 000..434c7ce
--- /dev/null
+++ b/tests/qemu-iotests/141
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+#
+# Tests for persistent dirty bitmap
+#
+# Copyright (C) 2016 Red Hat, Inc.
+#
+# 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 .
+#
+
+import os
+import iotests
+from iotests import qemu_img, qemu_io
+
+test_img = os.path.join(iotests.test_dir, 'test.img')
+
+class TestPersistentDirtyBitmap(iotests.QMPTestCase):
+image_len = 64 * 1024 * 1024 # MB
+def setUp(self):
+# Write data to the image so we can compare later
+qemu_img('create', '-f', iotests.imgfmt, test_img, str(self.image_len))
+self.vm = iotests.VM().add_drive(test_img)
+self.vm.launch()
+
+def tearDown(self):
+self.vm.shutdown()
+os.remove(test_img)
+
+def do_test_create(self, n):
+def make_range(k):
+return (k * 65536, 512)
+r = range(n)
+for i in r:
+result = self.vm.qmp('block-dirty-bitmap-add', node='drive0',
+name='bitmap-%d' % i,
+persistent=True)
+self.assert_qmp(result, 'return', {})
+self.vm.hmp_qemu_io('drive0', 'write -P %d %d %d' % ((i % 255,) + 
make_range(i)))
+for i in r:
+result = self.vm.qmp('block-dirty-bitmap-set-persistent',
+ node='drive0', name='bitmap-%d' % i,
+ persistent=False)
+self.assert_qmp(result, 'return', {})
+
+def test_simple_one(self):
+self.do_test_create(1)
+
+def test_simple_multiple(self):
+self.do_test_create(10)
+
+if __name__ == '__main__':
+iotests.main(supported_fmts=['qbm'])
diff --git a/tests/qemu-iotests/141.out b/tests/qemu-iotests/141.out
new file mode 100644
index 000..fbc63e6
--- /dev/null
+++ b/tests/qemu-iotests/141.out
@@ -0,0 +1,5 @@
+..
+--
+Ran 2 tests
+
+OK
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index e220a00..877bdbb 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -142,4 +142,5 @@
 138 rw auto quick
 139 rw auto quick
 140 rw auto quick
+141 rw auto quick
 142 auto
-- 
2.4.3




[Qemu-devel] [RFC PATCH 11/16] qapi: Add "qbm" as a generic cow format driver

2016-01-26 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 qapi/block-core.json | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index 52689ed..97dc0cd 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1599,7 +1599,7 @@
 { 'enum': 'BlockdevDriver',
   'data': [ 'archipelago', 'blkdebug', 'blkverify', 'bochs', 'cloop',
 'dmg', 'file', 'ftp', 'ftps', 'host_cdrom', 'host_device',
-'http', 'https', 'null-aio', 'null-co', 'parallels',
+'http', 'https', 'null-aio', 'null-co', 'parallels', 'qbm',
 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'tftp', 'vdi', 'vhdx',
 'vmdk', 'vpc', 'vvfat' ] }
 
@@ -2058,6 +2058,7 @@
   'null-aio':   'BlockdevOptionsNull',
   'null-co':'BlockdevOptionsNull',
   'parallels':  'BlockdevOptionsGenericFormat',
+  'qbm':'BlockdevOptionsGenericCOWFormat',
   'qcow2':  'BlockdevOptionsQcow2',
   'qcow':   'BlockdevOptionsGenericCOWFormat',
   'qed':'BlockdevOptionsGenericCOWFormat',
-- 
2.4.3




[Qemu-devel] [PATCH 2/4] usb: add attached property

2016-01-26 Thread Gerd Hoffmann
USB devices in attached state are visible to the guest.  This patch adds
a QOM property for this.  Write access is opt-in per device.  Some
devices manage attached state automatically (usb-host, usb-serial), so
we can't enable write access universally but have to do it on a case by
case base.

Signed-off-by: Gerd Hoffmann 
---
 hw/usb/bus.c | 42 ++
 include/hw/usb.h |  1 +
 2 files changed, 43 insertions(+)

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index dd28041..17e0479 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -733,6 +733,47 @@ USBDevice *usbdevice_create(const char *cmdline)
 return dev;
 }
 
+static bool usb_get_attached(Object *obj, Error **errp)
+{
+USBDevice *dev = USB_DEVICE(obj);
+
+return dev->attached;
+}
+
+static void usb_set_attached(Object *obj, bool value, Error **errp)
+{
+USBDevice *dev = USB_DEVICE(obj);
+Error *err = NULL;
+
+if (dev->attached == value)
+return;
+
+if (value) {
+usb_device_attach(dev, );
+if (err) {
+error_propagate(errp, err);
+}
+} else {
+usb_device_detach(dev);
+}
+}
+
+static void usb_device_instance_init(Object *obj)
+{
+USBDevice *dev = USB_DEVICE(obj);
+USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+
+if (klass->attached_settable) {
+object_property_add_bool(obj, "attached",
+ usb_get_attached, usb_set_attached,
+ NULL);
+} else {
+object_property_add_bool(obj, "attached",
+ usb_get_attached, NULL,
+ NULL);
+}
+}
+
 static void usb_device_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *k = DEVICE_CLASS(klass);
@@ -746,6 +787,7 @@ static const TypeInfo usb_device_type_info = {
 .name = TYPE_USB_DEVICE,
 .parent = TYPE_DEVICE,
 .instance_size = sizeof(USBDevice),
+.instance_init = usb_device_instance_init,
 .abstract = true,
 .class_size = sizeof(USBDeviceClass),
 .class_init = usb_device_class_init,
diff --git a/include/hw/usb.h b/include/hw/usb.h
index f8432f9..6eaa19c 100644
--- a/include/hw/usb.h
+++ b/include/hw/usb.h
@@ -346,6 +346,7 @@ typedef struct USBDeviceClass {
 
 const char *product_desc;
 const USBDesc *usb_desc;
+bool attached_settable;
 } USBDeviceClass;
 
 typedef struct USBPortOps {
-- 
1.8.3.1




[Qemu-devel] [RFC PATCH 04/16] block: Move filename_decompose to block.c

2016-01-26 Thread Fam Zheng
With the return value decoupled from VMDK, it can be reused by other block
code.

Signed-off-by: Fam Zheng 
---
 block.c   | 40 
 block/vmdk.c  | 40 
 include/block/block.h |  2 ++
 3 files changed, 42 insertions(+), 40 deletions(-)

diff --git a/block.c b/block.c
index fa6ad1d..78db342 100644
--- a/block.c
+++ b/block.c
@@ -144,6 +144,46 @@ int path_is_absolute(const char *path)
 #endif
 }
 
+int filename_decompose(const char *filename, char *path, char *prefix,
+   char *postfix, size_t buf_len, Error **errp)
+{
+const char *p, *q;
+
+if (filename == NULL || !strlen(filename)) {
+error_setg(errp, "No filename provided");
+return -EINVAL;
+}
+p = strrchr(filename, '/');
+if (p == NULL) {
+p = strrchr(filename, '\\');
+}
+if (p == NULL) {
+p = strrchr(filename, ':');
+}
+if (p != NULL) {
+p++;
+if (p - filename >= buf_len) {
+return -EINVAL;
+}
+pstrcpy(path, p - filename + 1, filename);
+} else {
+p = filename;
+path[0] = '\0';
+}
+q = strrchr(p, '.');
+if (q == NULL) {
+pstrcpy(prefix, buf_len, p);
+postfix[0] = '\0';
+} else {
+if (q - p >= buf_len) {
+return -EINVAL;
+}
+pstrcpy(prefix, q - p + 1, p);
+pstrcpy(postfix, buf_len, q);
+}
+return 0;
+}
+
 /* if filename is absolute, just copy it to dest. Otherwise, build a
path to it by considering it is relative to base_path. URL are
supported. */
diff --git a/block/vmdk.c b/block/vmdk.c
index f8f7fcf..505e0c2 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1764,46 +1764,6 @@ exit:
 return ret;
 }
 
-static int filename_decompose(const char *filename, char *path, char *prefix,
-  char *postfix, size_t buf_len, Error **errp)
-{
-const char *p, *q;
-
-if (filename == NULL || !strlen(filename)) {
-error_setg(errp, "No filename provided");
-return VMDK_ERROR;
-}
-p = strrchr(filename, '/');
-if (p == NULL) {
-p = strrchr(filename, '\\');
-}
-if (p == NULL) {
-p = strrchr(filename, ':');
-}
-if (p != NULL) {
-p++;
-if (p - filename >= buf_len) {
-return VMDK_ERROR;
-}
-pstrcpy(path, p - filename + 1, filename);
-} else {
-p = filename;
-path[0] = '\0';
-}
-q = strrchr(p, '.');
-if (q == NULL) {
-pstrcpy(prefix, buf_len, p);
-postfix[0] = '\0';
-} else {
-if (q - p >= buf_len) {
-return VMDK_ERROR;
-}
-pstrcpy(prefix, q - p + 1, p);
-pstrcpy(postfix, buf_len, q);
-}
-return VMDK_OK;
-}
-
 static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
 {
 int idx = 0;
diff --git a/include/block/block.h b/include/block/block.h
index bfb76f8..b9b30cb 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -449,6 +449,8 @@ int bdrv_is_snapshot(BlockDriverState *bs);
 
 int path_has_protocol(const char *path);
 int path_is_absolute(const char *path);
+int filename_decompose(const char *filename, char *path, char *prefix,
+   char *postfix, size_t buf_len, Error **errp);
 void path_combine(char *dest, int dest_size,
   const char *base_path,
   const char *filename);
-- 
2.4.3




Re: [Qemu-devel] [PULL 00/28] ppc-for-2.6 queue 20160125

2016-01-26 Thread Gerd Hoffmann
  Hi,

> Just set up a 32bit vm and maybe configure it to automatically test your git 
> branch? ;)

Container works even better as you can kick the build right from the
(host) command line, without boot vm, login, ...

sudo systemd-nspawn \
--directory /path/to/32bit-distro-root \
--bind /home \
--share-system \
--user $USER \
make -C $HOME/projects/qemu/build-32bit

configure is a bit more complicated because systemd-nspaws lacks a
--workdir switch, you need either some wrapper scripting or have to boot
the container, login, cd $builddir and run configure manually.

HTH,
  Gerd




Re: [Qemu-devel] [PATCH v3] Add optionrom compatible with fw_cfg DMA version

2016-01-26 Thread Marc Marí
On Tue, 26 Jan 2016 11:11:54 +
Stefan Hajnoczi  wrote:

> On Mon, Jan 25, 2016 at 02:17:48PM +0100, Marc Marí wrote:
> > +linuxboot_dma.img: linuxboot_dma.o
> > +   $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m elf_i386
> > -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@") +
> >  %.img: %.o
> > $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -Ttext 0 -e
> > _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")  
> 
> Why is -m elf_i386 necessary for linuxboot_dma.img but not for the
> other *.img files?

I cannot give a precise explanation. But if I don't force an output
type, I get this error:

Building optionrom/linuxboot_dma.img
ld: i386 architecture of input file `linuxboot_dma.o' is incompatible
with i386:x86-64 output

Marc




Re: [Qemu-devel] [Qemu-ppc] [PATCH 00/13] cuda: misc fixes and cleanups

2016-01-26 Thread BALATON Zoltan

On Mon, 25 Jan 2016, Hervé Poussineau wrote:
Do you have a Linux/NetBSD/... image, where I can run some command line tool 
to probe the I2C bus?


Have you tried the iso from www.finnix.org? When booting it you may see a 
boot prompt on black screen with dark gray text first which is hard to 
read but pressing enter here should go on to boot.


Regards,
BALATON Zoltan

[Qemu-devel] [PATCH 2/4] fpu: Use plain 'int' rather than 'int_fast16_t' for shift counts

2016-01-26 Thread Peter Maydell
Use the plain 'int' type rather than 'int_fast16_t' for shift counts
in the various shift related functions, since we don't actually care
about the size of the integer at all here, and using int16_t would
be confusing.

This should be a safe change because int_fast16_t semantics
permit use of 'int' (and on 32-bit glibc that is what you get).

Signed-off-by: Peter Maydell 
---
 fpu/softfloat-macros.h | 16 
 fpu/softfloat.c| 36 
 2 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/fpu/softfloat-macros.h b/fpu/softfloat-macros.h
index e95b445..51947ef 100644
--- a/fpu/softfloat-macros.h
+++ b/fpu/softfloat-macros.h
@@ -99,7 +99,7 @@ this code that are retained.
 | The result is stored in the location pointed to by `zPtr'.
 **/
 
-static inline void shift32RightJamming(uint32_t a, int_fast16_t count, 
uint32_t *zPtr)
+static inline void shift32RightJamming(uint32_t a, int count, uint32_t *zPtr)
 {
 uint32_t z;
 
@@ -125,7 +125,7 @@ static inline void shift32RightJamming(uint32_t a, 
int_fast16_t count, uint32_t
 | The result is stored in the location pointed to by `zPtr'.
 **/
 
-static inline void shift64RightJamming(uint64_t a, int_fast16_t count, 
uint64_t *zPtr)
+static inline void shift64RightJamming(uint64_t a, int count, uint64_t *zPtr)
 {
 uint64_t z;
 
@@ -161,7 +161,7 @@ static inline void shift64RightJamming(uint64_t a, 
int_fast16_t count, uint64_t
 
 static inline void
  shift64ExtraRightJamming(
- uint64_t a0, uint64_t a1, int_fast16_t count, uint64_t *z0Ptr, uint64_t 
*z1Ptr)
+ uint64_t a0, uint64_t a1, int count, uint64_t *z0Ptr, uint64_t *z1Ptr)
 {
 uint64_t z0, z1;
 int8_t negCount = ( - count ) & 63;
@@ -198,7 +198,7 @@ static inline void
 
 static inline void
  shift128Right(
- uint64_t a0, uint64_t a1, int_fast16_t count, uint64_t *z0Ptr, uint64_t 
*z1Ptr)
+ uint64_t a0, uint64_t a1, int count, uint64_t *z0Ptr, uint64_t *z1Ptr)
 {
 uint64_t z0, z1;
 int8_t negCount = ( - count ) & 63;
@@ -233,7 +233,7 @@ static inline void
 
 static inline void
  shift128RightJamming(
- uint64_t a0, uint64_t a1, int_fast16_t count, uint64_t *z0Ptr, uint64_t 
*z1Ptr)
+ uint64_t a0, uint64_t a1, int count, uint64_t *z0Ptr, uint64_t *z1Ptr)
 {
 uint64_t z0, z1;
 int8_t negCount = ( - count ) & 63;
@@ -287,7 +287,7 @@ static inline void
  uint64_t a0,
  uint64_t a1,
  uint64_t a2,
- int_fast16_t count,
+ int count,
  uint64_t *z0Ptr,
  uint64_t *z1Ptr,
  uint64_t *z2Ptr
@@ -342,7 +342,7 @@ static inline void
 
 static inline void
  shortShift128Left(
- uint64_t a0, uint64_t a1, int_fast16_t count, uint64_t *z0Ptr, uint64_t 
*z1Ptr)
+ uint64_t a0, uint64_t a1, int count, uint64_t *z0Ptr, uint64_t *z1Ptr)
 {
 
 *z1Ptr = a1<

Re: [Qemu-devel] [PATCH] vmdk: Fix converting to streamOptimized

2016-01-26 Thread Kevin Wolf
Am 26.01.2016 um 04:16 hat Fam Zheng geschrieben:
> On Mon, 01/25 12:16, Kevin Wolf wrote:
> > Am 25.01.2016 um 03:26 hat Fam Zheng geschrieben:
> > > Commit d62d9dc4b8 lifted streamOptimized images's version to 3, but we
> > > now refuse to open version 3 images read-write.  We need to make
> > > streamOptimized an exception to allow converting to it. This fixes the
> > > accidentally broken iotests case 059 for the same reason.
> > > 
> > > Signed-off-by: Fam Zheng 
> > 
> > How different are version 3 images for other subformats? Are we
> > arbitrarily restrictring their use or is it really that they don't work
> > with our driver? And if they don't work with our driver, are we sure
> > that streamOptimized images can't use the features we don't support?
> > 
> > Or is the version defined per subformat and doesn't necessarily exist
> > for other types?
> 
> Version 3 images are undocumented except in the VMware KB article mentioned in
> the comment around this line (http://kb.vmware.com/kb/2064959). A few years
> ago, when users complained that QEMU doesn't support version 3 images, we
> presumed from the article that reading is okay, as the new feature is
> "persistent changed block tracking" (although it didn't say it is the only
> feature enabled by version 3), and went ahead enabling it.
> 
> This time, it seems newer VMware products only accept version 3 if the
> subformat is streamOptimized.  Again, without any documentation/specification
> update. Then our users complains again, so we add another exception to
> mitigate. As this subformat doesn't allow overwrite, the only use case is
> qemu-img converting to it.  So this is pretty safe - it's always operating a
> new image - and the approach is tested by multiple users (both upstream and
> downstream).

I see. Then I guess we can't do much else.

Thanks, applied to the block branch.

Kevin



Re: [Qemu-devel] [PATCH 0/3] merge SSDT into DSDT

2016-01-26 Thread Igor Mammedov
On Mon, 25 Jan 2016 15:01:36 +0200
"Michael S. Tsirkin"  wrote:

> On Mon, Jan 25, 2016 at 12:57:28PM +0100, Igor Mammedov wrote:
> > On Sun, 24 Jan 2016 08:32:23 +0200
> > "Michael S. Tsirkin"  wrote:
> >   
> > > On Fri, Jan 22, 2016 at 03:36:05PM +0100, Igor Mammedov wrote:  
> > > > Merging both tables will allow for futher ASL
> > > > simplification and cleanups per device/subsystem
> > > > And it also allows to reduce number of expected
> > > > binary blobs for ACPI tests which reduces tests
> > > > maintenance.  
> > > 
> > > What this does break, however, is adding XSDT which
> > > we might need to do in the future.
> > > I'd rather do the reverse and have as much as possible
> > > in the SSDT.  
> > It doesn't forbid us adding XSDT later,  
> 
> Right but we'll have to duplicate dsdt in xsdt, right?
nope, DSDT is pointed by FADT while SSDTs by RSDT/XSDT.

The only reason why we have DSDT/SSDT split now is that
DSDT used to be static while SSDT generated dynamically.
Now when both tables are dynamically generated there
is no point to keep them separate.

I don't see any benefit in keeping empty DSDT as you
suggest with all the content in SSDT, it the same as
having only DSDT table but we have to maintain 2 tables
in code and tests.
If at some point we use XSDT to hide non XP compatible
ASL (if that works at all) then SSDT is the place where
that non compat ASL should be put and pointed only by XSDT,
while the the rest of compatible code should stay in 
the main mandatory table (i.e. DSDT).

> 
> > DSDT should be kept XP compatible as it's more or less now
> > and incompatible features we could put in their own SSDTs
> > if we decide to go for XSDT approach to hide them form XP.
> > For example I plan to move cpu/memory hotplug ASL into separate
> > SSDTs and continue to simplify DSDT on top of this series.  
> 
> So I'm kind of confused. Why move hotplug to dsdt then move
> them back out to an SSDT? Let's just put everything in an
> SSDT ...
because right now cpu/mem hotplug ASL is split between both
tables so the first step to isolating and consolidating scattered
parts is to put everything into one table. After that it
will be more easy to verify changes that refactoring will
introduce using bios-tables-test and should simplify refactoring
patches and review.

As for moving hotplug into dedicated SSDTs, it's for purpose
of sharing that code with ARM target and later we possible
could use it also to hide XP incompatible ASL in them by
referencing them from only XSDT.

Why do you insist on putting everything into SSDT instead of DSDT?

> 
> > >   
> > > > Boot tested with RHEL72, WS2003, WS2012R2 guests.
> > > > 
> > > > git tree for testing:
> > > > https://github.com/imammedo/qemu.git merge_ssdt_into_dsdt_v1 
> > > > 
> > > > Igor Mammedov (3):
> > > >   pc: acpi: merge SSDT into DSDT
> > > >   tests: pc: acpi: drop not needed 'expected SSDT' blobs
> > > >   tests: pc: acpi: add expected DSDT.bridge blobs and update DSDT
> > > > blobs
> > > > 
> > > >  hw/i386/acpi-build.c | 246
> > > > ---
> > > > tests/acpi-test-data/pc/DSDT | Bin 3028 -> 5478 bytes
> > > > tests/acpi-test-data/pc/DSDT.bridge  | Bin 0 -> 7337 bytes
> > > > tests/acpi-test-data/pc/SSDT | Bin 2486 -> 0 bytes
> > > > tests/acpi-test-data/pc/SSDT.bridge  | Bin 4345 -> 0 bytes
> > > > tests/acpi-test-data/q35/DSDT| Bin 7666 -> 8321 bytes
> > > > tests/acpi-test-data/q35/DSDT.bridge | Bin 0 -> 8338 bytes
> > > > tests/acpi-test-data/q35/SSDT| Bin 691 -> 0 bytes
> > > > tests/acpi-test-data/q35/SSDT.bridge | Bin 708 -> 0 bytes 9 files
> > > > changed, 111 insertions(+), 135 deletions(-) create mode 100644
> > > > tests/acpi-test-data/pc/DSDT.bridge delete mode 100644
> > > > tests/acpi-test-data/pc/SSDT delete mode 100644
> > > > tests/acpi-test-data/pc/SSDT.bridge create mode 100644
> > > > tests/acpi-test-data/q35/DSDT.bridge delete mode 100644
> > > > tests/acpi-test-data/q35/SSDT delete mode 100644
> > > > tests/acpi-test-data/q35/SSDT.bridge
> > > > 
> > > > -- 
> > > > 1.8.3.1  
> > >   
> 




Re: [Qemu-devel] [libvirt] Call for mentors and project ideas for Google Summer of Code 2016

2016-01-26 Thread Michal Privoznik
On 25.01.2016 18:28, Stefan Hajnoczi wrote:
> The QEMU wiki page for Google Summer of Code 2016 is now available here:
> 
> http://qemu-project.org/Google_Summer_of_Code_2016
> 
> QEMU will apply for Google Summer of Code 2016 (https://g.co/gsoc/).
> If QEMU is accepted there will be funding for students to work on
> 12-week full-time open source projects remotely from May to August
> 2016.  QEMU provides a mentor for each student who gives advice and
> evaluates their progress.
> 
> If you have a project idea, especially if you are a regular
> contributor to QEMU and are willing to mentor this summer, please go
> to this wiki page and fill out the project idea template:
> 
> http://qemu-project.org/Google_Summer_of_Code_2016
> 
> The project ideas list is part of the application so that QEMU can
> participate in GSoC.  It's useful to have your project ideas on the
> wiki by February 8th 2016.
> 
> If you have any questions about project ideas or QEMU applying to
> GSoC, please reply to this thread.

Hey Stefan,

so as we spoke earlier in person, I think it's time for libvirt to try
and apply as a separate organization.

I went ahead and created similar GSoC ideas page for libvirt:

http://wiki.libvirt.org/page/Google_Summer_of_Code_2016

My question is, is qemu willing to back libvirt in case we don't get
selected and if so, should we duplicate the idea list into qemu wiki too?

Michal



Re: [Qemu-devel] trace in arch/x86/kernel/apic/apic.c:1309 setup_local_APIC

2016-01-26 Thread Yang Zhang

On 2016/1/26 15:22, Stefan Priebe - Profihost AG wrote:

Hi,

Am 26.01.2016 um 02:46 schrieb Han, Huaitong:

What is the host kernel version and host dmesg information? And does
the problem exist when you use latest kernel and QEMU to replace old
binary file?


Guest and Host is both 4.1.15. You mean the complete dmesg output from host?

What do you mean with replace old binary file? I haven't tested Kernel
4.4 as we use 4.1 as it is a long term stable kernel release.


Have you seen this before? I mean use the old KVM like 3.10?



Stefan


On Mon, 2016-01-25 at 14:51 +0100, Stefan Priebe - Profihost AG wrote:

Hi,

while running qemu 2.4 on whestmere CPUs i'm pretty often getting
this
one while booting:
[0.811645] Switched APIC routing to physical x2apic.
[1.835678] [ cut here ]
[1.835704] WARNING: CPU: 0 PID: 1 at
arch/x86/kernel/apic/apic.c:1309 setup_local_APIC+0x284/0x340()
[1.835714] Modules linked in:
[1.835724] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.1.15+72-ph
#1
[1.835731] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
BIOS rel-1.8.2-0-g33fbe13 by qemu-project.org 04/01/2014
[1.835743]  b69ffcea 88042d5e3d68 b669c37b
0918
[1.835754]   88042d5e3da8 b6080d67
88042d5e3da8
[1.835765]  0001  8000

[1.835777] Call Trace:
[1.835789]  [] dump_stack+0x45/0x57
[1.835799]  [] warn_slowpath_common+0x97/0xe0
[1.835806]  [] warn_slowpath_null+0x1a/0x20
[1.835813]  [] setup_local_APIC+0x284/0x340
[1.835824]  [] apic_bsp_setup+0x5b/0xb0
[1.835832]  []
native_smp_prepare_cpus+0x23b/0x295
[1.835842]  [] kernel_init_freeable+0xc7/0x20f
[1.835853]  [] ? rest_init+0x80/0x80
[1.835860]  [] kernel_init+0xe/0xf0
[1.835870]  [] ret_from_fork+0x42/0x70
[1.835877]  [] ? rest_init+0x80/0x80
[1.835891] ---[ end trace bdbe630a8de2832c ]---
[1.837613] Spurious LAPIC timer interrupt on cpu 0
[1.837957] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
[1.939574] smpboot: CPU0: Intel Westmere E56xx/L56xx/X56xx
(Nehalem-C) (fam: 06, model: 2c, stepping: 01)
[1.939630] Performance Events: unsupported p6 CPU model 44 no PMU
driver, software events only.
[1.950868] KVM setup paravirtual spinlock

Greets,
Stefan
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html




--
best regards
yang



[Qemu-devel] [RFC PATCH 01/16] doc: Add QBM format specification

2016-01-26 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 docs/specs/qbm.md | 118 ++
 1 file changed, 118 insertions(+)
 create mode 100644 docs/specs/qbm.md

diff --git a/docs/specs/qbm.md b/docs/specs/qbm.md
new file mode 100644
index 000..b91910b
--- /dev/null
+++ b/docs/specs/qbm.md
@@ -0,0 +1,118 @@
+QEMU Block Bitmap (QBM)
+===
+
+QBM is a multi-file disk format to allow storing persistent block bitmaps along
+with the tracked data image.  A QBM image includes one json descriptor file,
+one data image, one or more bitmap files that describe the block dirty status
+of the data image.
+
+The json file describes the structure of the image. The structure of the json
+descriptor file is:
+
+QBM-JSON-FILE := { "QBM": DESC-JSON }
+
+DESC-JSON := { "version": 1,
+   "image": IMAGE,
+   "BITMAPS": BITMAPS
+ }
+
+Fields in the top level json dictionary are:
+
+@version: An integer which must be 1.
+@image: A dictionary in IMAGE schema, as described later. It provides the
+information of the data image where user data is stored. Its format is
+documented in the "IMAGE schema" section.
+@bitmaps: A dictionary that describes one ore more bitmap files. The keys into
+  the dictionary are the names of bitmap, which must be strings, and
+  each value is a dictionary describing the information of the bitmap,
+  as documented below in the "BITMAP schema" section.
+
+=== IMAGE schema ===
+
+An IMAGE records the information of an image (such as a data image or a backing
+file). It has following fields:
+
+@file: The file name string of the referenced image. If it's a relative path,
+   the file should be found relative to the descriptor file's
+   location.
+@format: The format string of the file.
+
+=== BITMAP schema ===
+
+A BITMAP dictionary records the information of a bitmap (such as a dirty bitmap
+or a block allocation status bitmap). It has following mandatory fields:
+
+@file: The name of the bitmap file. The bitmap file is in little endian, both
+   byte-order-wise and bit-order-wise, which means the LSB in the byte 0
+   corresponds to the first sectors.
+@granularity-bytes: How many bytes of data does one bit in the bitmap track.
+This value must be a power of 2 and no less than 512.
+@type: The type of the bitmap.  Currently only "dirty" and "allocation" are
+   supported.
+   "dirty" indicates a block dirty bitmap; "allocation" indicates a
+   allocation status bitmap. There must be at most one "allocation" bitmap.
+
+If the type of the bitmap is "allocation", an extra field "backing" is also
+accepted:
+
+@backing: a dictionary as specified in the IMAGE schema. It can be used to
+  adding a backing file to raw image.
+
+
+=== Extended fields ===
+
+Implementations are allowed to extend the format schema by inserting additinoal
+members into above dictionaries, with key names that starts with either
+an "ext-hard-" or an "ext-soft-" prefix.
+
+Extended fields prefixed with "ext-soft-" are optional and can be ignored by
+parsers if they do not support it; fields starting with "ext-hard-" are
+mandatory and cannot be ignored, a parser should not proceed parsing the image
+if it does not support it.
+
+It is strongly recommended that the application names are also included in the
+extention name string, such as "ext-hard-qemu-", if the effect or
+interpretation of the field is local to a specific application.
+
+For example, QEMU can implement a "checksum" feature to make sure no files
+referred to by the json descriptor are modified inconsistently, by adding
+"ext-soft-qemu-checksum" fields in "image" and "bitmaps" descriptions, like in
+the json text found below.
+
+=== QBM descriptor file example ===
+
+This is the content of a QBM image's json descriptor file, which contains a
+data image (data.img), and three bitmaps, out of which the "allocation" bitmap
+associates a backing file to this image (base.img).
+
+{ "QBM": {
+"version": 1,
+"image": {
+"file": "data.img",
+"format": "raw"
+"ext-soft-qemu-checksum": "9eff24b72bd693cc8aa3e887141b96f8",
+},
+"bitmaps": {
+"0": {
+"file": "bitmap0.bin",
+"granularity-bytes": 512,
+"type": "dirty"
+},
+"1": {
+"file": "bitmap1.bin",
+"granularity-bytes": 4096,
+"type": "dirty"
+},
+"2": {
+"file": "bitmap3.bin",
+"granularity-bytes": 4096,
+"type": "allocation"
+"backing": {
+"file": "base.img",
+"format": "raw"
+"ext-soft-qemu-checksum": "fcad1f672b2fb19948405e7a1a18c2a7",
+},
+}
+}
+} }
+
-- 
2.4.3




[Qemu-devel] [PATCH 3/4] usb-bot: hotplug support

2016-01-26 Thread Gerd Hoffmann
This patch marks usb-bot as hot-pluggable device, makes attached
property settable and turns off auto-attach in case the device
was hotplugged.

Hot-plugging a usb-bot device with one or more scsi devices can be
done this way now:

  (1) device-add usb-bot,id=foo
  (2) device-add scsi-{hd,cd},bus=foo.0,lun=0
  (2b) optionally add more devices (luns 0 ... 15).
  (3) qom-set foo.attached = true

Signed-off-by: Gerd Hoffmann 
---
 hw/usb/dev-storage.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index 597d8fd..275e0ed 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -665,9 +665,14 @@ static void usb_msd_realize_storage(USBDevice *dev, Error 
**errp)
 static void usb_msd_realize_bot(USBDevice *dev, Error **errp)
 {
 MSDState *s = USB_STORAGE_DEV(dev);
+DeviceState *d = DEVICE(dev);
 
 usb_desc_create_serial(dev);
 usb_desc_init(dev);
+if (d->hotplugged) {
+s->dev.auto_attach = 0;
+}
+
 scsi_bus_new(>bus, sizeof(s->bus), DEVICE(dev),
  _msd_scsi_info_bot, NULL);
 usb_msd_handle_reset(dev);
@@ -839,10 +844,9 @@ static void usb_msd_instance_init(Object *obj)
 static void usb_msd_class_initfn_bot(ObjectClass *klass, void *data)
 {
 USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
-DeviceClass *dc = DEVICE_CLASS(klass);
 
 uc->realize = usb_msd_realize_bot;
-dc->hotpluggable = false;
+uc->attached_settable = true;
 }
 
 static const TypeInfo msd_info = {
-- 
1.8.3.1




Re: [Qemu-devel] [RFC PATCH 0/3] (Resend) TranslationBlock annotation mechanism

2016-01-26 Thread Bastian Koppelmann
Hi Peter,

thank you for your feedback.

>  (2) it feels a bit unpolished at the moment (lack of documentation,
> doesn't have any existing analysis tools that produce the format that
> the code reads that would make it immediately usable by an end-user)
> 
Sure this is unpolished but we wanted to get feedback before we put too
much work into it.

> I think that a design that would likely get better traction here with
> QEMU upstream would be one where you had tracepoints for relevant
> events like "executing new TB", and some means of writing a plugin
> to run code on those events, or perhaps just a post-analysis tool that
> ran on the trace file. Then the code for reading XML and adding up the
> relevant annotations would be confined to the plugin and wouldn't
> necessarily need to be upstream at all.
> 

We like your idea of a "plugin-api" that exposes hooks for relevant
events since this is more generic than our approach. We came up with a
list of relevant events for tracing:

- pre-/post-execute_tb
- pre-/post-translate_tb
- pre-/post-interrupt
(- memory access)

These are the hooks that would be sufficient for our ideas for plugins.
Do you have more suggestions for suitable hooks? Also, is there anything
similar already in QEMU on which we could build on?

> However you should take that design suggestion with a considerable
> pinch of salt, as I am very much not up to speed with the current
> state of our tracing infrastructure.

Who would I ask for the current state of tracing? Stefan?

Cheers,
Bastian




Re: [Qemu-devel] [PATCH 2/2] nbd: add missed aio_context_acquire in nbd_export_new

2016-01-26 Thread Paolo Bonzini


On 20/01/2016 08:12, Denis V. Lunev wrote:
> blk_invalidate_cache() can call qcow2_invalidate_cache which performs
> IO inside.
> 
> Signed-off-by: Denis V. Lunev 
> CC: Kevin Wolf 
> CC: Paolo Bonzini 
> ---
>  nbd.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/nbd.c b/nbd.c
> index b3d9654..b271db5 100644
> --- a/nbd.c
> +++ b/nbd.c
> @@ -1080,7 +1080,9 @@ NBDExport *nbd_export_new(BlockBackend *blk, off_t 
> dev_offset, off_t size,
>   * that BDRV_O_INCOMING is cleared and the image is ready for write
>   * access since the export could be available before migration handover.
>   */
> +aio_context_acquire(exp->ctx);
>  blk_invalidate_cache(blk, NULL);
> +aio_context_release(exp->ctx);
>  return exp;
>  
>  fail:
> 

Queuing this one myself.

Paolo



Re: [Qemu-devel] trace in arch/x86/kernel/apic/apic.c:1309 setup_local_APIC

2016-01-26 Thread Yang Zhang

On 2016/1/26 19:40, Stefan Priebe - Profihost AG wrote:


Am 26.01.2016 um 12:39 schrieb Yang Zhang:

On 2016/1/26 18:43, Stefan Priebe - Profihost AG wrote:


Am 26.01.2016 um 11:13 schrieb Yang Zhang:

On 2016/1/26 15:22, Stefan Priebe - Profihost AG wrote:

Hi,

Am 26.01.2016 um 02:46 schrieb Han, Huaitong:

What is the host kernel version and host dmesg information? And does
the problem exist when you use latest kernel and QEMU to replace old
binary file?


Guest and Host is both 4.1.15. You mean the complete dmesg output from
host?

What do you mean with replace old binary file? I haven't tested Kernel
4.4 as we use 4.1 as it is a long term stable kernel release.


Have you seen this before? I mean use the old KVM like 3.10?


Guest or host? To test with a guest would be quite easy. Downgrading the
host is very difficult not sure if the hw is supported.


Host. Does the issue only exist on the Westmere CPU?


Yes. All E5 Xeons v1, v2, v3 are working fine and i've never seen this
message.

Stefan









Stefan


On Mon, 2016-01-25 at 14:51 +0100, Stefan Priebe - Profihost AG wrote:

Hi,

while running qemu 2.4 on whestmere CPUs i'm pretty often getting
this
one while booting:
[0.811645] Switched APIC routing to physical x2apic.


Westmere doesn't have the x2apic support. It is strange to see it here. 
Can you try to disable x2apic manually on you Qemu cmdline?



[1.835678] [ cut here ]
[1.835704] WARNING: CPU: 0 PID: 1 at
arch/x86/kernel/apic/apic.c:1309 setup_local_APIC+0x284/0x340()
[1.835714] Modules linked in:
[1.835724] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.1.15+72-ph
#1
[1.835731] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
BIOS rel-1.8.2-0-g33fbe13 by qemu-project.org 04/01/2014
[1.835743]  b69ffcea 88042d5e3d68 b669c37b
0918
[1.835754]   88042d5e3da8 b6080d67
88042d5e3da8
[1.835765]  0001  8000

[1.835777] Call Trace:
[1.835789]  [] dump_stack+0x45/0x57
[1.835799]  [] warn_slowpath_common+0x97/0xe0
[1.835806]  [] warn_slowpath_null+0x1a/0x20
[1.835813]  [] setup_local_APIC+0x284/0x340
[1.835824]  [] apic_bsp_setup+0x5b/0xb0
[1.835832]  []
native_smp_prepare_cpus+0x23b/0x295
[1.835842]  [] kernel_init_freeable+0xc7/0x20f
[1.835853]  [] ? rest_init+0x80/0x80
[1.835860]  [] kernel_init+0xe/0xf0
[1.835870]  [] ret_from_fork+0x42/0x70
[1.835877]  [] ? rest_init+0x80/0x80
[1.835891] ---[ end trace bdbe630a8de2832c ]---
[1.837613] Spurious LAPIC timer interrupt on cpu 0
[1.837957] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
[1.939574] smpboot: CPU0: Intel Westmere E56xx/L56xx/X56xx
(Nehalem-C) (fam: 06, model: 2c, stepping: 01)
[1.939630] Performance Events: unsupported p6 CPU model 44 no PMU
driver, software events only.
[1.950868] KVM setup paravirtual spinlock

Greets,
Stefan
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html










--
best regards
yang



Re: [Qemu-devel] [Qemu-arm] Does QEMU support AArch64 Big Endian emulation on x86-64 host?

2016-01-26 Thread Ruslan Bilovol
On Mon, Jan 25, 2016 at 6:07 PM, Peter Maydell  wrote:
> On 25 January 2016 at 13:51, Ruslan Bilovol  wrote:
>>> I'm trying to run AArch64 Big Endian image under QEMU that I built for
>>> my x86-64 Ubuntu host from latest master branch and when I'm running
>>> kernel I'm getting next error:
>>>  > qemu: fatal: Trying to execute code outside RAM or ROM at 
>>> 0x50020880
>>>
>>> Similar image built as Little Endian runs fine with same QEMU tool
>>> (qemu-system-aarch64)
>>>
>>> So I'm wondering is it possible to run QEMU AArch64 Big Endian
>>> emulation on x86-64 host?
>
> It is not currently supported, no. However there are some patches
> on the list[*] to add this support, so I expect a future QEMU version
> will do this.
>
> [*] https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg03025.html

Thank you four quick answer.
I tried to apply this patch series to latest qemu master branch, but it
fails to apply in misc places. Peter Crosthwaite, could you please say
which commit ID is it based on?

Thanks,
Ruslan Bilovol



Re: [Qemu-devel] [PATCH 1/8] nbd: client_close on error in nbd_co_client_start

2016-01-26 Thread Kevin Wolf
Am 25.01.2016 um 19:41 hat Max Reitz geschrieben:
> Use client_close() if an error in nbd_co_client_start() occurs instead
> of manually inlining parts of it. This fixes an assertion error on the
> server side if nbd_negotiate() fails.
> 
> Signed-off-by: Max Reitz 

Paolo, if you can Ack this one, I can take the series through my tree.

Kevin

>  nbd/server.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/nbd/server.c b/nbd/server.c
> index 2265cb0..5169b59 100644
> --- a/nbd/server.c
> +++ b/nbd/server.c
> @@ -1080,8 +1080,7 @@ static coroutine_fn void nbd_co_client_start(void 
> *opaque)
>  nbd_export_get(exp);
>  }
>  if (nbd_negotiate(data)) {
> -shutdown(client->sock, 2);
> -client->close(client);
> +client_close(client);
>  goto out;
>  }
>  qemu_co_mutex_init(>send_lock);
> -- 
> 2.7.0
> 



Re: [Qemu-devel] [PATCH v2 0/5] q35: Remove old machines and unused compat code

2016-01-26 Thread Igor Mammedov
On Mon, 25 Jan 2016 12:27:47 +0100
Laszlo Ersek  wrote:

> On 01/23/16 17:02, Eduardo Habkost wrote:
> > This is another attempt to remove old q35 machine code. Now I am
> > also removing unused compat code to demonstrate the benefit of
> > throwing away the old code that nobody uses.
> > 
> > Eduardo Habkost (5):
> >   q35: Remove old machine versions
> >   machine: Remove no_tco field
> >   ich9: Remove enable_tco arguments from init functions
> >   q35: Remove unused q35-acpi-dsdt.aml file
> >   q35: No need to check gigabyte_align
> > 
> >  Makefile  |   2 +-
> >  hw/acpi/ich9.c|   8 +--
> >  hw/i386/pc_q35.c  | 176 
> > +-
> >  hw/isa/lpc_ich9.c |   4 +-
> >  include/hw/acpi/ich9.h|   1 -
> >  include/hw/boards.h   |   1 -
> >  include/hw/i386/ich9.h|   2 +-
> >  pc-bios/q35-acpi-dsdt.aml | Bin 7344 -> 0 bytes
> >  8 files changed, 9 insertions(+), 185 deletions(-)
> >  delete mode 100644 pc-bios/q35-acpi-dsdt.aml
> >   
> 
> I read / skimmed the earlier discussion:
> 
> http://thread.gmane.org/gmane.comp.emulators.qemu/356340
> http://thread.gmane.org/gmane.comp.emulators.qemu/382574
> 
> For patches 1, 2, 3, 5:
> 
> Reviewed-by: Laszlo Ersek 
> 
> For patch 4:
> 
> How about removing the following two files in addition:
> - hw/i386/q35-acpi-dsdt.dsl
> - hw/i386/q35-acpi-dsdt.hex.generated
above files don't exist in current master as there where removed
by DSDT->AML conversion series. And well, they weren't related
to legacy code removed here anyway.

> 
> and updating the references in "hw/i386/Makefile.objs"?
> 
> Thanks
> Laszlo




Re: [Qemu-devel] [PATCH v2 1/1] nvdimm: disable balloon

2016-01-26 Thread Igor Mammedov
On Mon, 25 Jan 2016 19:50:31 +0300
"Denis V. Lunev"  wrote:

> From: Vladimir Sementsov-Ogievskiy 
> 
> NVDIMM for now is planned to use as a backing store for DAX filesystem
> in the guest and thus this memory is excluded from guest memory management
> and LRUs.
> 
> In this case libvirt running QEMU along with configured balloon almost
> immediately inflates balloon and effectively kill the guest as
> qemu counts nvdimm as part of the ram.

Isn't issue in ballooning impl. and not of pc-dimm/nvdimm,
so make ballooning code to distinguish between kinds of memory
rather than adding not related fields to PCDIMMDeviceClass

why don't just move get_current_ram_size() into the sole user
virtio-balloon.c and ignore NVDIMMs when counting ram in
get_current_ram_size(),
that would be much less intrusive patch.

> 
> Counting dimm devices as part of the ram for ballooning was started from
> commit 463756d03:
>  virtio-balloon: Fix balloon not working correctly when hotplug memory
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy 
> Signed-off-by: Denis V. Lunev 
> CC: Stefan Hajnoczi 
> CC: Xiao Guangrong 
> CC: "Michael S. Tsirkin" 
> CC: Igor Mammedov 
> CC: Eric Blake 
> CC: Markus Armbruster 
> ---
> v2:
> - some rewordings, thanks to Eric Blake
> 
>  hw/mem/nvdimm.c  | 4 
>  hw/mem/pc-dimm.c | 7 ++-
>  include/hw/mem/pc-dimm.h | 1 +
>  qapi-schema.json | 5 -
>  4 files changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
> index 4fd397f..4f4d29a 100644
> --- a/hw/mem/nvdimm.c
> +++ b/hw/mem/nvdimm.c
> @@ -27,9 +27,13 @@
>  static void nvdimm_class_init(ObjectClass *oc, void *data)
>  {
>  DeviceClass *dc = DEVICE_CLASS(oc);
> +PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc);
>  
>  /* nvdimm hotplug has not been supported yet. */
>  dc->hotpluggable = false;
> +
> +/* ballooning is not supported */
> +ddc->in_ram = false;
>  }
>  
>  static TypeInfo nvdimm_info = {
> diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
> index d5cdab2..e0f869d 100644
> --- a/hw/mem/pc-dimm.c
> +++ b/hw/mem/pc-dimm.c
> @@ -164,6 +164,7 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
>  MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1);
>  PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1);
>  DeviceClass *dc = DEVICE_GET_CLASS(obj);
> +PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(obj);
>  PCDIMMDevice *dimm = PC_DIMM(obj);
>  
>  if (dev->id) {
> @@ -172,6 +173,7 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
>  }
>  di->hotplugged = dev->hotplugged;
>  di->hotpluggable = dc->hotpluggable;
> +di->in_ram = ddc->in_ram;
>  di->addr = dimm->addr;
>  di->slot = dimm->slot;
>  di->node = dimm->node;
> @@ -205,7 +207,9 @@ ram_addr_t get_current_ram_size(void)
>  if (value) {
>  switch (value->type) {
>  case MEMORY_DEVICE_INFO_KIND_DIMM:
> -size += value->u.dimm->size;
> +if (value->u.dimm->in_ram) {
> +size += value->u.dimm->size;
> +}
>  break;
>  default:
>  break;
> @@ -444,6 +448,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void 
> *data)
>  dc->props = pc_dimm_properties;
>  dc->desc = "DIMM memory module";
>  
> +ddc->in_ram = true;
>  ddc->get_memory_region = pc_dimm_get_memory_region;
>  }
>  
> diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
> index d83bf30..3bcb505 100644
> --- a/include/hw/mem/pc-dimm.h
> +++ b/include/hw/mem/pc-dimm.h
> @@ -65,6 +65,7 @@ typedef struct PCDIMMDevice {
>  typedef struct PCDIMMDeviceClass {
>  /* private */
>  DeviceClass parent_class;
> +bool in_ram;
>  
>  /* public */
>  MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm);
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 2e960db..3cafa2b 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -3922,6 +3922,8 @@
>  #
>  # @hotpluggable: true if device if could be added/removed while machine is 
> running
>  #
> +# @in-ram: true if device is counted in current ram size (since 2.6)
> +#
>  # Since: 2.1
>  ##
>  { 'struct': 'PCDIMMDeviceInfo',
> @@ -3932,7 +3934,8 @@
>  'node': 'int',
>  'memdev': 'str',
>  'hotplugged': 'bool',
> -'hotpluggable': 'bool'
> +'hotpluggable': 'bool',
> +'in-ram': 'bool'
>}
>  }
>  




[Qemu-devel] [RFC PATCH 00/16] Qemu Bit Map (QBM) - an overlay format for persistent dirty bitmap

2016-01-26 Thread Fam Zheng
Hi all,

This series introduces a simple format to enable support of persistence of
block dirty bitmaps. Block dirty bitmap is the tool to achieve incremental
backup, and persistence of block dirty bitmap makes incrememtal backup possible
across VM shutdowns, where existing in-memory dirty bitmaps cannot survive.

When user creates a "persisted" dirty bitmap, the QBM driver will create a
binary file and synchronize it with the existing in-memory block dirty bitmap
(BdrvDirtyBitmap). When the VM is powered down, the binary file has all the
bits saved on disk, which will be loaded and used to initialize the in-memory
block dirty bitmap next time the guest is started.

The idea of the format is to reuse as much existing infrastructure as possible
and avoid introducing complex data structures - it works with any image format,
by gluing it together plain bitmap files with a json descriptor file. The
advantage of this approach over extending existing formats, such as qcow2, is
that the new feature is implemented by an orthogonal driver, in a format
agnostic way. This way, even raw images can have their persistent dirty
bitmaps.  (And you will notice in this series, with a little forging to the
spec, raw images can also have backing files through a QBM overlay!)

Rather than superseding it, this intends to be coexistent in parallel with the
qcow2 bitmap extension that Vladimir is working on.  The block driver interface
changes in this series also try to be generic and compatible for both drivers.

The format's specification is added to docs/specs/, see patch 1.

Patches 2-7 are necessary block layer changes in order be friendly to
persistent dirty bitmap drivers.

Patches 8, 9 and 11 extends the QMP interface to expose the added feature.

Patch 10 implements the driver. (todo: checksum extension for image/bitmap
integrity check)

Patch 12 - 16 are the tests I have for QBM so far. I'm sure more can be added
as questions emerge. :)

The series applies on top of my "qemu-img map" series and "meta bitmap" series:

https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg04866.html
https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg03656.html

If you feel like to play with it, git branch is also available at:

https://github.com/famz/qemu qbm

Comments are welcome!

Fam


Fam Zheng (16):
  doc: Add QBM format specification
  block: Set dirty before doing write
  block: Allow .bdrv_close callback to release dirty bitmaps
  block: Move filename_decompose to block.c
  block: Make bdrv_get_cluster_size public
  block: Introduce bdrv_dirty_bitmap_set_persistent
  block: Only swap non-persistent dirty bitmaps
  qmp: Add optional parameter "persistent" in block-dirty-bitmap-add
  qmp: Add block-dirty-bitmap-set-persistent
  qbm: Implement format driver
  qapi: Add "qbm" as a generic cow format driver
  iotests: Add qbm format to 041
  iotests: Add qbm to case 097
  iotests: Add qbm to applicable test cases
  iotests: Add qbm specific test case 140
  iotests: Add persistent bitmap test case 141

 block.c  |   54 +-
 block/Makefile.objs  |1 +
 block/dirty-bitmap.c |   63 ++
 block/io.c   |6 +-
 block/qbm.c  | 1315 ++
 block/vmdk.c |   40 --
 blockdev.c   |   28 +-
 docs/specs/qbm.md|  118 
 include/block/block.h|4 +-
 include/block/block_int.h|8 +
 include/block/dirty-bitmap.h |5 +
 qapi/block-core.json |   31 +-
 qmp-commands.hx  |   34 +-
 tests/qemu-iotests/004   |2 +-
 tests/qemu-iotests/017   |2 +-
 tests/qemu-iotests/018   |2 +-
 tests/qemu-iotests/019   |2 +-
 tests/qemu-iotests/020   |2 +-
 tests/qemu-iotests/024   |2 +-
 tests/qemu-iotests/025   |2 +-
 tests/qemu-iotests/027   |2 +-
 tests/qemu-iotests/028   |2 +-
 tests/qemu-iotests/030   |2 +-
 tests/qemu-iotests/034   |2 +-
 tests/qemu-iotests/037   |2 +-
 tests/qemu-iotests/038   |2 +-
 tests/qemu-iotests/040   |2 +-
 tests/qemu-iotests/041   |   18 +-
 tests/qemu-iotests/050   |2 +-
 tests/qemu-iotests/055   |2 +-
 tests/qemu-iotests/056   |2 +-
 tests/qemu-iotests/069   |2 +-
 tests/qemu-iotests/072   |2 +-
 tests/qemu-iotests/086   |2 +-
 tests/qemu-iotests/095   |2 +-
 tests/qemu-iotests/096   |2 +-
 tests/qemu-iotests/097   |4 +-
 tests/qemu-iotests/099   |2 +-
 tests/qemu-iotests/110   |2 +-
 tests/qemu-iotests/129   |2 +-
 tests/qemu-iotests/132   |2 +-
 tests/qemu-iotests/139   |2 +-
 tests/qemu-iotests/140   |   80 +++
 tests/qemu-iotests/140.out   |  145 +
 tests/qemu-iotests/141   |   62 ++
 tests/qemu-iotests/141.out   |5 +
 tests/qemu-iotests/common|6 +
 tests/qemu-iotests/group |2 

Re: [Qemu-devel] [PATCH] net: set endianness on all backend devices

2016-01-26 Thread Laurent Vivier


On 22/01/2016 07:44, Jason Wang wrote:
> 
> 
> On 01/21/2016 04:42 PM, Laurent Vivier wrote:
>> ping
>>
>> [added Jason in cc:]
>>
>> On 13/01/2016 20:26, Laurent Vivier wrote:
>>> commit 5be7d9f1b1452613b95c6ba70b8d7ad3d0797991
>>>vhost-net: tell tap backend about the vnet endianness
>>>
>>> makes vhost net to set the endianness of the device, but only for
>>> the first device.
>>>
>>> In case of multiqueue, we have multiple devices... This patch sets the
>>> endianness for all the devices of the interface.
>>>
>>> Signed-off-by: Laurent Vivier 
>>> ---
>>>  hw/net/vhost_net.c | 23 +++
>>>  1 file changed, 11 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
>>> index 318c3e6..10e233a 100644
>>> --- a/hw/net/vhost_net.c
>>> +++ b/hw/net/vhost_net.c
>>> @@ -300,21 +300,19 @@ int vhost_net_start(VirtIODevice *dev, NetClientState 
>>> *ncs,
>>>  BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
>>>  VirtioBusState *vbus = VIRTIO_BUS(qbus);
>>>  VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
>>> -int r, e, i;
>>> +int r, e, i, j;
>>>  
>>>  if (!k->set_guest_notifiers) {
>>>  error_report("binding does not support guest notifiers");
>>> -r = -ENOSYS;
>>> -goto err;
>>> +return -ENOSYS;
>>>  }
>>>  
>>> -r = vhost_net_set_vnet_endian(dev, ncs[0].peer, true);
>>> -if (r < 0) {
>>> -goto err;
>>> -}
>>> -
>>> -for (i = 0; i < total_queues; i++) {
>>> -vhost_net_set_vq_index(get_vhost_net(ncs[i].peer), i * 2);
>>> +for (j = 0; j < total_queues; j++) {
>>> +r = vhost_net_set_vnet_endian(dev, ncs[j].peer, true);
>>> +if (r < 0) {
>>> +goto err_endian;
>>> +}
>>> +vhost_net_set_vq_index(get_vhost_net(ncs[j].peer), j * 2);
>>>  }
>>>  
>>>  r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
>>> @@ -343,8 +341,9 @@ err_start:
>>>  fflush(stderr);
>>>  }
>>>  err_endian:
>>> -vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
>>> -err:
>>> +while (--j >= 0) {
>>> +vhost_net_set_vnet_endian(dev, ncs[j].peer, false);
>>> +}
>>>  return r;
>>>  }
>>>  
> 
> Reviewed-by: Jason Wang 

Thanks Jason.

Who can pick this in his tree ?

Laurent



Re: [Qemu-devel] [PATCH 0/3] merge SSDT into DSDT

2016-01-26 Thread Michael S. Tsirkin
On Tue, Jan 26, 2016 at 10:55:04AM +0100, Igor Mammedov wrote:
> On Mon, 25 Jan 2016 15:01:36 +0200
> "Michael S. Tsirkin"  wrote:
> 
> > On Mon, Jan 25, 2016 at 12:57:28PM +0100, Igor Mammedov wrote:
> > > On Sun, 24 Jan 2016 08:32:23 +0200
> > > "Michael S. Tsirkin"  wrote:
> > >   
> > > > On Fri, Jan 22, 2016 at 03:36:05PM +0100, Igor Mammedov wrote:  
> > > > > Merging both tables will allow for futher ASL
> > > > > simplification and cleanups per device/subsystem
> > > > > And it also allows to reduce number of expected
> > > > > binary blobs for ACPI tests which reduces tests
> > > > > maintenance.  
> > > > 
> > > > What this does break, however, is adding XSDT which
> > > > we might need to do in the future.
> > > > I'd rather do the reverse and have as much as possible
> > > > in the SSDT.  
> > > It doesn't forbid us adding XSDT later,  
> > 
> > Right but we'll have to duplicate dsdt in xsdt, right?
> nope, DSDT is pointed by FADT while SSDTs by RSDT/XSDT.

Oops, I was confused when I wrote this.
You are right, I'll go back and review
everything in light of this.


> The only reason why we have DSDT/SSDT split now is that
> DSDT used to be static while SSDT generated dynamically.
> Now when both tables are dynamically generated there
> is no point to keep them separate.
> 
> I don't see any benefit in keeping empty DSDT as you
> suggest with all the content in SSDT, it the same as
> having only DSDT table but we have to maintain 2 tables
> in code and tests.
> If at some point we use XSDT to hide non XP compatible
> ASL (if that works at all) then SSDT is the place where
> that non compat ASL should be put and pointed only by XSDT,
> while the the rest of compatible code should stay in 
> the main mandatory table (i.e. DSDT).
> > 
> > > DSDT should be kept XP compatible as it's more or less now
> > > and incompatible features we could put in their own SSDTs
> > > if we decide to go for XSDT approach to hide them form XP.
> > > For example I plan to move cpu/memory hotplug ASL into separate
> > > SSDTs and continue to simplify DSDT on top of this series.  
> > 
> > So I'm kind of confused. Why move hotplug to dsdt then move
> > them back out to an SSDT? Let's just put everything in an
> > SSDT ...
> because right now cpu/mem hotplug ASL is split between both
> tables so the first step to isolating and consolidating scattered
> parts is to put everything into one table. After that it
> will be more easy to verify changes that refactoring will
> introduce using bios-tables-test and should simplify refactoring
> patches and review.
> 
> As for moving hotplug into dedicated SSDTs, it's for purpose
> of sharing that code with ARM target and later we possible
> could use it also to hide XP incompatible ASL in them by
> referencing them from only XSDT.
> 
> Why do you insist on putting everything into SSDT instead of DSDT?
> > 
> > > >   
> > > > > Boot tested with RHEL72, WS2003, WS2012R2 guests.
> > > > > 
> > > > > git tree for testing:
> > > > > https://github.com/imammedo/qemu.git merge_ssdt_into_dsdt_v1 
> > > > > 
> > > > > Igor Mammedov (3):
> > > > >   pc: acpi: merge SSDT into DSDT
> > > > >   tests: pc: acpi: drop not needed 'expected SSDT' blobs
> > > > >   tests: pc: acpi: add expected DSDT.bridge blobs and update DSDT
> > > > > blobs
> > > > > 
> > > > >  hw/i386/acpi-build.c | 246
> > > > > ---
> > > > > tests/acpi-test-data/pc/DSDT | Bin 3028 -> 5478 bytes
> > > > > tests/acpi-test-data/pc/DSDT.bridge  | Bin 0 -> 7337 bytes
> > > > > tests/acpi-test-data/pc/SSDT | Bin 2486 -> 0 bytes
> > > > > tests/acpi-test-data/pc/SSDT.bridge  | Bin 4345 -> 0 bytes
> > > > > tests/acpi-test-data/q35/DSDT| Bin 7666 -> 8321 bytes
> > > > > tests/acpi-test-data/q35/DSDT.bridge | Bin 0 -> 8338 bytes
> > > > > tests/acpi-test-data/q35/SSDT| Bin 691 -> 0 bytes
> > > > > tests/acpi-test-data/q35/SSDT.bridge | Bin 708 -> 0 bytes 9 files
> > > > > changed, 111 insertions(+), 135 deletions(-) create mode 100644
> > > > > tests/acpi-test-data/pc/DSDT.bridge delete mode 100644
> > > > > tests/acpi-test-data/pc/SSDT delete mode 100644
> > > > > tests/acpi-test-data/pc/SSDT.bridge create mode 100644
> > > > > tests/acpi-test-data/q35/DSDT.bridge delete mode 100644
> > > > > tests/acpi-test-data/q35/SSDT delete mode 100644
> > > > > tests/acpi-test-data/q35/SSDT.bridge
> > > > > 
> > > > > -- 
> > > > > 1.8.3.1  
> > > >   
> > 



Re: [Qemu-devel] [PATCH] hmp: avoid redundant null termination of buffer

2016-01-26 Thread Michael Tokarev
18.01.2016 17:23, Markus Armbruster wrote:
[...]
> Applied to my monitor-next with these tweaks:
> 
> diff --git a/hmp.c b/hmp.c
> index 8be03df..9c571f5 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -1739,7 +1739,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)
>  keyname_len = separator ? separator - keys : strlen(keys);
>  
>  /* Be compatible with old interface, convert user inputted "<" */
> -if (!strncmp(keys, "<", 1) && keyname_len == 1) {
> +if (keys[0] == '<' && keyname_len == 1) {
>  keys = "less";
>  keyname_len = 4;
>  }
> @@ -1758,7 +1758,8 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)
>  if (strstart(keys, "0x", NULL)) {
>  char *endp;
>  int value = strtoul(keys, , 0);
> -if (*endp != '\0' && *endp != '-') {
> +assert(endp <= keys + keyname_len);
> +if (endp != keys + keyname_len) {
>  goto err_out;
>  }
>  keylist->value->type = KEY_VALUE_KIND_NUMBER;

Marcus, where's your monitor-next branch?  Repository at
git://repo.or.cz/qemu/armbru.git , monitor-next branch does
not contain this change, last commit to hmp.c dated Sep-8.

Thanks,

/mjt



Re: [Qemu-devel] [PATCH v2 0/5] q35: Remove old machines and unused compat code

2016-01-26 Thread Igor Mammedov
On Sat, 23 Jan 2016 14:02:08 -0200
Eduardo Habkost  wrote:

> This is another attempt to remove old q35 machine code. Now I am
> also removing unused compat code to demonstrate the benefit of
> throwing away the old code that nobody uses.
Reviewed-by: Igor Mammedov 

> 
> Eduardo Habkost (5):
>   q35: Remove old machine versions
>   machine: Remove no_tco field
>   ich9: Remove enable_tco arguments from init functions
>   q35: Remove unused q35-acpi-dsdt.aml file
>   q35: No need to check gigabyte_align
> 
>  Makefile  |   2 +-
>  hw/acpi/ich9.c|   8 +--
>  hw/i386/pc_q35.c  | 176 
> +-
>  hw/isa/lpc_ich9.c |   4 +-
>  include/hw/acpi/ich9.h|   1 -
>  include/hw/boards.h   |   1 -
>  include/hw/i386/ich9.h|   2 +-
>  pc-bios/q35-acpi-dsdt.aml | Bin 7344 -> 0 bytes
>  8 files changed, 9 insertions(+), 185 deletions(-)
>  delete mode 100644 pc-bios/q35-acpi-dsdt.aml
> 




Re: [Qemu-devel] [PATCH v17 7/9] add MachineClass->default_props for setting default device properties

2016-01-26 Thread Igor Mammedov
On Sat, 23 Jan 2016 12:59:56 -0200
Eduardo Habkost  wrote:

> On Tue, Jan 19, 2016 at 02:06:27PM +0100, Igor Mammedov wrote:
> > Signed-off-by: Igor Mammedov 
> > ---
> >  include/hw/boards.h | 1 +
> >  vl.c| 4 
> >  2 files changed, 5 insertions(+)
> > 
> > diff --git a/include/hw/boards.h b/include/hw/boards.h
> > index 0f30959..d495611 100644
> > --- a/include/hw/boards.h
> > +++ b/include/hw/boards.h
> > @@ -90,6 +90,7 @@ struct MachineClass {
> >  const char *default_machine_opts;
> >  const char *default_boot_order;
> >  const char *default_display;
> > +GlobalProperty *default_props;
> >  GlobalProperty *compat_props;  
> 
> Could you explain (in a comment?) the purpose of each field? They
> seem to do exactly the same thing, so why couldn't they become a
> single linked list, where the compat classes just append new
> items to the existing default_props list?
> 
> (If we build default_props by appending instead of overwriting
> the parent class list, we will be able to finally eliminate
> PC_COMPAT_* macro nesting)
The only reason I've added it as separate field is to keep the
current way compat_props are working instead of rewriting
not related to this series part.

Alternatively we could add qdev_prop_prepend_global_list() API
and add static defaults calling it from board's machine-init.



Re: [Qemu-devel] [PATCH v2 1/3] linux-user/mmap.c: Set prot page flags for the correct region in mmap_frag()

2016-01-26 Thread Peter Maydell
On 26 January 2016 at 10:19, Chen Gang  wrote:
> When I run WeChat.exe with i386 wine with qemu-i386 under sw_64 arch.
>
>  - The related command:
>
>"./i386-linux-user/qemu-i386 -strace -L /upstream/i386_wine 
> /upstream/i386_wine/usr/local/bin/wine "C:\\Program 
> Files\\Tencent\\WeChat\\WeChat.exe" > ana/try/info-strace.log 2>&1"
>
>  - The related output (no any munmap, 135168 = 128KB + 4KB):
>
>4600 
> mmap2(0x0034,135168,PROT_READ,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0) = 
> 0x0034
>4600 mmap2(0x0034,135168,PROT_READ,MAP_SHARED|MAP_FIXED,8,0) = 
> 0x0034
>4600 rt_sigprocmask(SIG_SETMASK,0x0033f574,NULL) = 0
>4600 rt_sigprocmask(SIG_BLOCK,0x7bced7e0,0x0033f5d0) = 0
>4600 write(3,0x33f6cc,64) = 64
>4600 read(4,0x33f6cc,64) = 1
>4600 rt_sigprocmask(SIG_SETMASK,0x0033f5d0,NULL) = 0
>4600 close(8) = 0
>4600 rt_sigprocmask(SIG_BLOCK,0x7bced7e0,0x0033f674) = 0
>4600 mprotect(0x0016,65536,PROT_READ|PROT_WRITE) = 0
>4600 rt_sigprocmask(SIG_SETMASK,0x0033f674,NULL) = 0
>4600 rt_sigprocmask(SIG_BLOCK,0x7bced7e0,0x0033f990) = 0
>4600 
> mmap2(0x0034,135168,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE,-1,0)
>  = 0x0034
>
> wine often does like above, map the same position multiple times.

That output seems to show all the mmap calls working fine, though.

>> Reading the target_mmap() code, its intention seems to be:
>>  (a) if the whole allocation fits in one host page, call
>>  mmap_frag() once and then "goto the_end1"
>
> Also yes to me.
>
>>  (b) otherwise, we'll call mmap_frag() once for the start
>>  of the guest mapping, and once for the end, which must
>>  be two different host pages
>>
>
> Also yes to me.
>
>> So if you're seeing mmap_frag() called twice for the same
>> host page then something is going wrong, but I'm not sure what.
>>
>
> For the case I provide above, it can call mmap_frag() twice for the same
> host page.

For the same single call to target_mmap() ? What is the code flow
within QEMU that causes this?

thanks
-- PMM



Re: [Qemu-devel] VFIO based vGPU(was Re: [Announcement] 2015-Q3 release of XenGT - a Mediated ...)

2016-01-26 Thread Neo Jia
On Mon, Jan 25, 2016 at 09:45:14PM +, Tian, Kevin wrote:
> > From: Alex Williamson [mailto:alex.william...@redhat.com]
> > Sent: Tuesday, January 26, 2016 5:30 AM
> > 
> > [cc +Neo @Nvidia]
> > 
> > Hi Jike,
> > 
> > On Mon, 2016-01-25 at 19:34 +0800, Jike Song wrote:
> > > On 01/20/2016 05:05 PM, Tian, Kevin wrote:
> > > > I would expect we can spell out next level tasks toward above
> > > > direction, upon which Alex can easily judge whether there are
> > > > some common VFIO framework changes that he can help :-)
> > >
> > > Hi Alex,
> > >
> > > Here is a draft task list after a short discussion w/ Kevin,
> > > would you please have a look?
> > >
> > >   Bus Driver
> > >
> > >   { in i915/vgt/xxx.c }
> > >
> > >   - define a subset of vfio_pci interfaces
> > >   - selective pass-through (say aperture)
> > >   - trap MMIO: interface w/ QEMU
> > 
> > What's included in the subset?  Certainly the bus reset ioctls really
> > don't apply, but you'll need to support the full device interface,
> > right?  That includes the region info ioctl and access through the vfio
> > device file descriptor as well as the interrupt info and setup ioctls.
> 
> That is the next level detail Jike will figure out and discuss soon.
> 
> yes, basic region info/access should be necessary. For interrupt, could
> you elaborate a bit what current interface is doing? If just about creating
> an eventfd for virtual interrupt injection, it applies to vgpu too.
> 
> > 
> > >   IOMMU
> > >
> > >   { in a new vfio_xxx.c }
> > >
> > >   - allocate: struct device & IOMMU group
> > 
> > It seems like the vgpu instance management would do this.
> > 
> > >   - map/unmap functions for vgpu
> > >   - rb-tree to maintain iova/hpa mappings
> > 
> > Yep, pretty much what type1 does now, but without mapping through the
> > IOMMU API.  Essentially just a database of the current userspace
> > mappings that can be accessed for page pinning and IOVA->HPA
> > translation.
> 
> The thought is to reuse iommu_type1.c, by abstracting several underlying
> operations and then put vgpu specific implementation in a vfio_vgpu.c (e.g.
> for map/unmap instead of using IOMMU API, an iova/hpa mapping is updated
> accordingly), etc.
> 
> This file will also connect between VFIO and vendor specific vgpu driver,
> e.g. exposing interfaces to allow the latter querying iova<->hpa and also 
> creating necessary VFIO structures like aforementioned device/IOMMUas...
> 
> > 
> > >   - interacts with kvmgt.c
> > >
> > >
> > >   vgpu instance management
> > >
> > >   { in i915 }
> > >
> > >   - path, create/destroy
> > >
> > 
> > Yes, and since you're creating and destroying the vgpu here, this is
> > where I'd expect a struct device to be created and added to an IOMMU
> > group.  The lifecycle management should really include links between
> > the vGPU and physical GPU, which would be much, much easier to do with
> > struct devices create here rather than at the point where we start
> > doing vfio "stuff".
> 
> It's invoked here, but expecting the function exposed by vfio_vgpu.c. It's
> not good to touch vfio internal structures from another module (such as
> i915.ko)
> 
> > 
> > Nvidia has also been looking at this and has some ideas how we might
> > standardize on some of the interfaces and create a vgpu framework to
> > help share code between vendors and hopefully make a more consistent
> > userspace interface for libvirt as well.  I'll let Neo provide some
> > details.  Thanks,
> > 
> 
> Nice to know that. Neo, please share your thought here.

Hi Alex, Kevin and Jike,

(Seems I shouldn't use attachment, resend it again to the list, patches are
inline at the end)

Thanks for adding me to this technical discussion, a great opportunity
for us to design together which can bring both Intel and NVIDIA vGPU solution to
KVM platform.

Instead of directly jumping to the proposal that we have been working on
recently for NVIDIA vGPU on KVM, I think it is better for me to put out couple
quick comments / thoughts regarding the existing discussions on this thread as
fundamentally I think we are solving the same problem, DMA, interrupt and MMIO.

Then we can look at what we have, hopefully we can reach some consensus soon.

> Yes, and since you're creating and destroying the vgpu here, this is
> where I'd expect a struct device to be created and added to an IOMMU
> group.  The lifecycle management should really include links between
> the vGPU and physical GPU, which would be much, much easier to do with
> struct devices create here rather than at the point where we start
> doing vfio "stuff".

Infact to keep vfio-vgpu to be more generic, vgpu device creation and management
can be centralized and done in vfio-vgpu. That also include adding to IOMMU
group and VFIO group.

Graphics driver can register with vfio-vgpu to get management and emulation call
backs to graphics driver.   

We already 

[Qemu-devel] [RFC PATCH 10/16] qbm: Implement format driver

2016-01-26 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 block/Makefile.objs |1 +
 block/qbm.c | 1315 +++
 2 files changed, 1316 insertions(+)
 create mode 100644 block/qbm.c

diff --git a/block/Makefile.objs b/block/Makefile.objs
index cdd8655..ba7 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -5,6 +5,7 @@ block-obj-y += qed-check.o
 block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o vhdx-log.o
 block-obj-y += quorum.o
 block-obj-y += parallels.o blkdebug.o blkverify.o
+block-obj-y += qbm.o
 block-obj-y += block-backend.o snapshot.o qapi.o
 block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
 block-obj-$(CONFIG_POSIX) += raw-posix.o
diff --git a/block/qbm.c b/block/qbm.c
new file mode 100644
index 000..91e129f
--- /dev/null
+++ b/block/qbm.c
@@ -0,0 +1,1315 @@
+/*
+ * Block driver for the QBM format
+ *
+ * Copyright (c) 2016 Red Hat Inc.
+ *
+ * Authors:
+ * Fam Zheng 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu-common.h"
+#include "block/block_int.h"
+#include "qapi/qmp/qerror.h"
+#include "qemu/error-report.h"
+#include "qemu/module.h"
+#include "migration/migration.h"
+#include "qapi/qmp/qint.h"
+#include "qapi/qmp/qjson.h"
+
+#define QBM_BUF_SIZE_MAX (32 << 20)
+
+typedef enum QBMBitmapType {
+QBM_TYPE_DIRTY,
+QBM_TYPE_ALLOC,
+} QBMBitmapType;
+
+typedef struct QBMBitmap {
+BdrvDirtyBitmap *bitmap;
+BdrvChild *file;
+char *name;
+QBMBitmapType type;
+} QBMBitmap;
+
+typedef struct BDRVQBMState {
+BdrvChild *image;
+BdrvDirtyBitmap *alloc_bitmap;
+QDict *desc;
+QDict *backing_dict;
+QBMBitmap *bitmaps;
+int num_bitmaps;
+} BDRVQBMState;
+
+static const char *qbm_token_consume(const char *p, const char *token)
+{
+size_t len = strlen(token);
+
+if (!p) {
+return NULL;
+}
+while (*p && (*p == ' ' ||
+  *p == '\t' ||
+  *p == '\n' ||
+  *p == '\r')) {
+p++;
+}
+if (strncmp(p, token, len)) {
+return p + len;
+}
+return NULL;
+}
+
+static int qbm_probe(const uint8_t *buf, int buf_size, const char *filename)
+{
+const char *p;
+p = strstr((const char *)buf, "\"QBM\"");
+if (!p) {
+p = strstr((const char *)buf, "'QBM'");
+}
+if (!p) {
+return 0;
+}
+p = qbm_token_consume(p, ":");
+p = qbm_token_consume(p, "{");
+if (p && *p) {
+return 100;
+}
+return 0;
+}
+
+static void qbm_load_bitmap(BlockDriverState *bs, QBMBitmap *bm, Error **errp)
+{
+int r;
+BDRVQBMState *s = bs->opaque;
+int64_t bitmap_file_size;
+int64_t bitmap_size;
+uint8_t *buf = NULL;
+BlockDriverState *file = bm->file->bs;
+int64_t image_size = bdrv_getlength(s->image->bs);
+
+if (image_size < 0) {
+error_setg(errp, "Cannot get image size: %s", s->image->bs->filename);
+return;
+}
+bitmap_size = bdrv_dirty_bitmap_serialization_size(bm->bitmap, 0,
+bdrv_dirty_bitmap_size(bm->bitmap));
+if (bitmap_size > QBM_BUF_SIZE_MAX) {
+error_setg(errp, "Bitmap too big");
+return;
+}
+bitmap_file_size = bdrv_getlength(file);
+if (bitmap_file_size < bitmap_size) {
+error_setg(errp,
+   "Bitmap \"%s\" file too small "
+   "(expecting at least %ld bytes but got %ld bytes): %s",
+   bm->name, bitmap_size, bitmap_file_size, file->filename);
+goto out;
+}
+buf = qemu_blockalign(file, bitmap_size);
+r = bdrv_pread(file, 0, buf, bitmap_size);
+if (r < 0) {
+error_setg(errp, "Failed to read bitmap file \"%s\"",
+   file->filename);
+goto out;
+}
+bdrv_dirty_bitmap_deserialize_part(bm->bitmap, buf, 0, bs->total_sectors,
+   true);
+
+out:
+   

Re: [Qemu-devel] [PATCH] memory: exit when hugepage allocation fails if mem-prealloc

2016-01-26 Thread Paolo Bonzini


On 22/01/2016 15:15, Luiz Capitulino wrote:
> When -mem-prealloc is passed on the command-line, the expected
> behavior is to exit if the hugepage allocation fails.  However,
> this behavior is broken since commit cc57501dee which made
> hugepage allocation fall back to regular ram in case of faliure.
> 
> This commit restores the expected behavior for -mem-prealloc.
> 
> Signed-off-by: Luiz Capitulino 
> ---
>  numa.c | 9 +
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/numa.c b/numa.c
> index 425ef8d..0e1638d 100644
> --- a/numa.c
> +++ b/numa.c
> @@ -418,12 +418,13 @@ static void allocate_system_memory_nonnuma(MemoryRegion 
> *mr, Object *owner,
>  Error *err = NULL;
>  memory_region_init_ram_from_file(mr, owner, name, ram_size, false,
>   mem_path, );
> -
> -/* Legacy behavior: if allocation failed, fall back to
> - * regular RAM allocation.
> - */
>  if (err) {
>  error_report_err(err);
> +if (mem_prealloc)
> +exit(1);
> +/* Legacy behavior: if allocation failed, fall back to
> + * regular RAM allocation.
> + */
>  memory_region_init_ram(mr, owner, name, ram_size, _fatal);
>  }
>  #else
> 

Right, patch cc57501dee did the correct change but it was insufficient.
 I'll add the braces for you and queue the patch.

Paolo



[Qemu-devel] [PATCH 1/4] usb: make USBDevice->attached bool

2016-01-26 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 hw/usb/bus.c | 8 
 include/hw/usb.h | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 1bbe930..dd28041 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -52,9 +52,9 @@ static int usb_device_post_load(void *opaque, int version_id)
 USBDevice *dev = opaque;
 
 if (dev->state == USB_STATE_NOTATTACHED) {
-dev->attached = 0;
+dev->attached = false;
 } else {
-dev->attached = 1;
+dev->attached = true;
 }
 if (dev->setup_index < 0 ||
 dev->setup_len < 0 ||
@@ -530,7 +530,7 @@ void usb_device_attach(USBDevice *dev, Error **errp)
 return;
 }
 
-dev->attached++;
+dev->attached = true;
 usb_attach(port);
 }
 
@@ -544,7 +544,7 @@ int usb_device_detach(USBDevice *dev)
 trace_usb_port_detach(bus->busnr, port->path);
 
 usb_detach(port);
-dev->attached--;
+dev->attached = false;
 return 0;
 }
 
diff --git a/include/hw/usb.h b/include/hw/usb.h
index c8b6e7b..f8432f9 100644
--- a/include/hw/usb.h
+++ b/include/hw/usb.h
@@ -234,7 +234,7 @@ struct USBDevice {
 uint8_t addr;
 char product_desc[32];
 int auto_attach;
-int attached;
+bool attached;
 
 int32_t state;
 uint8_t setup_buf[8];
-- 
1.8.3.1




[Qemu-devel] [RFC PATCH 15/16] iotests: Add qbm specific test case 140

2016-01-26 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 tests/qemu-iotests/140 |  80 +
 tests/qemu-iotests/140.out | 145 +
 tests/qemu-iotests/common  |   6 ++
 tests/qemu-iotests/group   |   1 +
 4 files changed, 232 insertions(+)
 create mode 100755 tests/qemu-iotests/140
 create mode 100644 tests/qemu-iotests/140.out

diff --git a/tests/qemu-iotests/140 b/tests/qemu-iotests/140
new file mode 100755
index 000..e5c3c56
--- /dev/null
+++ b/tests/qemu-iotests/140
@@ -0,0 +1,80 @@
+#!/bin/bash
+#
+# General tests for QBM format
+#
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# 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 .
+#
+
+# creator
+owner=f...@redhat.com
+
+seq="$(basename $0)"
+echo "QA output created by $seq"
+
+here="$PWD"
+tmp=/tmp/$$
+status=1   # failure is the default!
+
+_cleanup()
+{
+return
+_cleanup_test_img
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+_supported_fmt qbm
+_supported_proto file
+_supported_os Linux
+
+size=128M
+
+echo
+echo "=== Create a QBM file with no option ==="
+_make_test_img $size
+_img_info
+cat $TEST_IMG
+
+for n in 0 1 3; do
+echo
+echo "=== Create a QBM file with $n dirty bitmap(s) ==="
+echo
+_make_test_img -o dirty-bitmaps=$n $size
+_img_info
+cat $TEST_IMG
+done
+
+
+$QEMU_IMG map $TEST_IMG
+
+echo
+echo "=== Create a QBM file with raw backing image ==="
+IMGFMT=raw TEST_IMG=$TEST_IMG.base _make_test_img $size
+$QEMU_IO_PROG -f raw $TEST_IMG.base -c "write 0 $size" | _filter_qemu_io
+_make_test_img -o dirty-bitmaps=1 -b $TEST_IMG.base
+cat $TEST_IMG
+_img_info
+
+$QEMU_IO $TEST_IMG -c "write 130560 131072" | _filter_qemu_io
+$QEMU_IMG map $TEST_IMG
+
+# success, all done
+echo "*** done"
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/140.out b/tests/qemu-iotests/140.out
new file mode 100644
index 000..1d9cefb
--- /dev/null
+++ b/tests/qemu-iotests/140.out
@@ -0,0 +1,145 @@
+QA output created by 140
+
+=== Create a QBM file with no option ===
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
+image: TEST_DIR/t.IMGFMT
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 512
+{
+"QBM": {
+"bitmaps": {
+},
+"image": {
+"format": "raw",
+"file": "t-data.img.qbm"
+},
+"version": 1,
+"creator": "QEMU"
+}
+}
+
+=== Create a QBM file with 0 dirty bitmap(s) ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 dirty-bitmaps=0
+image: TEST_DIR/t.IMGFMT
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 512
+{
+"QBM": {
+"bitmaps": {
+},
+"image": {
+"format": "raw",
+"file": "t-data.img.qbm"
+},
+"version": 1,
+"creator": "QEMU"
+}
+}
+
+=== Create a QBM file with 1 dirty bitmap(s) ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 dirty-bitmaps=1
+image: TEST_DIR/t.IMGFMT
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 512
+{
+"QBM": {
+"bitmaps": {
+"dirty.0": {
+"granularity-bytes": 65536,
+"type": "dirty",
+"file": "t-dirty.0.bitmap.qbm"
+}
+},
+"image": {
+"format": "raw",
+"file": "t-data.img.qbm"
+},
+"version": 1,
+"creator": "QEMU"
+}
+}
+
+=== Create a QBM file with 3 dirty bitmap(s) ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 dirty-bitmaps=3
+image: TEST_DIR/t.IMGFMT
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 512
+{
+"QBM": {
+"bitmaps": {
+"dirty.1": {
+"granularity-bytes": 65536,
+"type": "dirty",
+"file": "t-dirty.1.bitmap.qbm"
+},
+"dirty.2": {
+"granularity-bytes": 65536,
+"type": "dirty",
+"file": "t-dirty.2.bitmap.qbm"
+},
+"dirty.0": {
+"granularity-bytes": 65536,
+"type": "dirty",
+"file": "t-dirty.0.bitmap.qbm"
+}
+},
+"image": {
+"format": "raw",
+

[Qemu-devel] [RFC PATCH 13/16] iotests: Add qbm to case 097

2016-01-26 Thread Fam Zheng
The output of "qemu-img map" will be slightly different for qbm because
the data image paths are not $TEST_IMG, but the pattern is predicatable
enough so we can just filter it out.

Signed-off-by: Fam Zheng 
---
 tests/qemu-iotests/095 | 2 +-
 tests/qemu-iotests/097 | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tests/qemu-iotests/095 b/tests/qemu-iotests/095
index dad04b9..2f68953 100755
--- a/tests/qemu-iotests/095
+++ b/tests/qemu-iotests/095
@@ -43,7 +43,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 . ./common.filter
 . ./common.qemu
 
-_supported_fmt qcow2
+_supported_fmt qcow2 qbm
 _supported_proto file
 _supported_os Linux
 
diff --git a/tests/qemu-iotests/097 b/tests/qemu-iotests/097
index c7a613b..2252d62 100755
--- a/tests/qemu-iotests/097
+++ b/tests/qemu-iotests/097
@@ -42,7 +42,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 . ./common.pattern
 
 # Any format supporting backing files and bdrv_make_empty
-_supported_fmt qcow qcow2
+_supported_fmt qcow qcow2 qbm
 _supported_proto file
 _supported_os Linux
 
@@ -109,9 +109,11 @@ else
 # Both top and intermediate should be unchanged
 fi
 
+{
 $QEMU_IMG map "$TEST_IMG.base" | _filter_qemu_img_map
 $QEMU_IMG map "$TEST_IMG.itmd" | _filter_qemu_img_map
 $QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map
+} | sed -e 's/.data.img//'
 
 done
 
-- 
2.4.3




[Qemu-devel] [PATCH 3/4] fpu: Use plain 'int' rather than 'int_fast16_t' for exponents

2016-01-26 Thread Peter Maydell
Use the plain 'int' type rather than 'int_fast16_t' for handling
exponents. Exponents don't need to be exactly 16 bits, so using int16_t
for them would confuse more than it clarified.

This should be a safe change because int_fast16_t semantics
permit use of 'int' (and on 32-bit glibc that is what you get).

Signed-off-by: Peter Maydell 
---
 fpu/softfloat-macros.h |   2 +-
 fpu/softfloat.c| 122 -
 2 files changed, 62 insertions(+), 62 deletions(-)

diff --git a/fpu/softfloat-macros.h b/fpu/softfloat-macros.h
index 51947ef..9cc6158 100644
--- a/fpu/softfloat-macros.h
+++ b/fpu/softfloat-macros.h
@@ -635,7 +635,7 @@ static uint64_t estimateDiv128To64( uint64_t a0, uint64_t 
a1, uint64_t b )
 | value.
 **/
 
-static uint32_t estimateSqrt32(int_fast16_t aExp, uint32_t a)
+static uint32_t estimateSqrt32(int aExp, uint32_t a)
 {
 static const uint16_t sqrtOddAdjustments[] = {
 0x0004, 0x0022, 0x005D, 0x00B1, 0x011D, 0x019F, 0x0236, 0x02E0,
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 89e6fd9..02a279c 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -119,7 +119,7 @@ static inline uint32_t extractFloat16Frac(float16 a)
 | Returns the exponent bits of the half-precision floating-point value `a'.
 **/
 
-static inline int_fast16_t extractFloat16Exp(float16 a)
+static inline int extractFloat16Exp(float16 a)
 {
 return (float16_val(a) >> 10) & 0x1f;
 }
@@ -315,7 +315,7 @@ static inline uint32_t extractFloat32Frac( float32 a )
 | Returns the exponent bits of the single-precision floating-point value `a'.
 **/
 
-static inline int_fast16_t extractFloat32Exp(float32 a)
+static inline int extractFloat32Exp(float32 a)
 {
 
 return ( float32_val(a)>>23 ) & 0xFF;
@@ -356,7 +356,7 @@ float32 float32_squash_input_denormal(float32 a, 
float_status *status)
 **/
 
 static void
- normalizeFloat32Subnormal(uint32_t aSig, int_fast16_t *zExpPtr, uint32_t 
*zSigPtr)
+ normalizeFloat32Subnormal(uint32_t aSig, int *zExpPtr, uint32_t *zSigPtr)
 {
 int8_t shiftCount;
 
@@ -377,7 +377,7 @@ static void
 | significand.
 **/
 
-static inline float32 packFloat32(flag zSign, int_fast16_t zExp, uint32_t zSig)
+static inline float32 packFloat32(flag zSign, int zExp, uint32_t zSig)
 {
 
 return make_float32(
@@ -407,7 +407,7 @@ static inline float32 packFloat32(flag zSign, int_fast16_t 
zExp, uint32_t zSig)
 | Binary Floating-Point Arithmetic.
 **/
 
-static float32 roundAndPackFloat32(flag zSign, int_fast16_t zExp, uint32_t 
zSig,
+static float32 roundAndPackFloat32(flag zSign, int zExp, uint32_t zSig,
float_status *status)
 {
 int8_t roundingMode;
@@ -482,7 +482,7 @@ static float32 roundAndPackFloat32(flag zSign, int_fast16_t 
zExp, uint32_t zSig,
 **/
 
 static float32
- normalizeRoundAndPackFloat32(flag zSign, int_fast16_t zExp, uint32_t zSig,
+ normalizeRoundAndPackFloat32(flag zSign, int zExp, uint32_t zSig,
   float_status *status)
 {
 int8_t shiftCount;
@@ -508,7 +508,7 @@ static inline uint64_t extractFloat64Frac( float64 a )
 | Returns the exponent bits of the double-precision floating-point value `a'.
 **/
 
-static inline int_fast16_t extractFloat64Exp(float64 a)
+static inline int extractFloat64Exp(float64 a)
 {
 
 return ( float64_val(a)>>52 ) & 0x7FF;
@@ -549,7 +549,7 @@ float64 float64_squash_input_denormal(float64 a, 
float_status *status)
 **/
 
 static void
- normalizeFloat64Subnormal(uint64_t aSig, int_fast16_t *zExpPtr, uint64_t 
*zSigPtr)
+ normalizeFloat64Subnormal(uint64_t aSig, int *zExpPtr, uint64_t *zSigPtr)
 {
 int8_t shiftCount;
 
@@ -570,7 +570,7 @@ static void
 | significand.
 **/
 
-static inline float64 packFloat64(flag zSign, int_fast16_t zExp, uint64_t zSig)
+static inline float64 packFloat64(flag zSign, int zExp, uint64_t zSig)
 {
 
 return make_float64(
@@ -600,12 +600,12 @@ static inline float64 packFloat64(flag zSign, 
int_fast16_t zExp, uint64_t zSig)
 | Binary Floating-Point Arithmetic.
 **/
 
-static float64 roundAndPackFloat64(flag zSign, int_fast16_t zExp, uint64_t 
zSig,

[Qemu-devel] [PATCH 4/4] osdep.h: Remove int_fast*_t Solaris compatibility code

2016-01-26 Thread Peter Maydell
We now do not use the int_fast*_t types anywhere in QEMU, so we can
remove the compatibility definitions we were providing for the
benefit of ancient Solaris versions.

Signed-off-by: Peter Maydell 
---
 include/qemu/osdep.h | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 59a7f8d..cad78ae 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -73,13 +73,6 @@
 
 #include "qapi/error.h"
 
-#if defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10
-/* [u]int_fast*_t not in  */
-typedef unsigned char   uint_fast8_t;
-typedef unsigned intuint_fast16_t;
-typedef signed int  int_fast16_t;
-#endif
-
 #ifndef O_LARGEFILE
 #define O_LARGEFILE 0
 #endif
-- 
1.9.1




[Qemu-devel] [PATCH 1/4] fpu: Remove use of int_fast16_t in conversions to int16

2016-01-26 Thread Peter Maydell
Make the functions which convert floating point to 16 bit integer
return int16_t rather than int_fast16_t, and correspondingly use
int_fast16_t in their internal implementations where appropriate.

(These functions are used only by the ARM target.)

Signed-off-by: Peter Maydell 
---
 fpu/softfloat.c | 28 ++--
 include/fpu/softfloat.h | 16 
 2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 162c211..fc6a160 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -1617,7 +1617,7 @@ int32_t float32_to_int32_round_to_zero(float32 a, 
float_status *status)
 | returned.
 **/
 
-int_fast16_t float32_to_int16_round_to_zero(float32 a, float_status *status)
+int16_t float32_to_int16_round_to_zero(float32 a, float_status *status)
 {
 flag aSign;
 int_fast16_t aExp, shiftCount;
@@ -3150,7 +3150,7 @@ int32_t float64_to_int32_round_to_zero(float64 a, 
float_status *status)
 | returned.
 **/
 
-int_fast16_t float64_to_int16_round_to_zero(float64 a, float_status *status)
+int16_t float64_to_int16_round_to_zero(float64 a, float_status *status)
 {
 flag aSign;
 int_fast16_t aExp, shiftCount;
@@ -7118,10 +7118,10 @@ uint32_t float32_to_uint32_round_to_zero(float32 a, 
float_status *status)
 return res;
 }
 
-int_fast16_t float32_to_int16(float32 a, float_status *status)
+int16_t float32_to_int16(float32 a, float_status *status)
 {
 int32_t v;
-int_fast16_t res;
+int16_t res;
 int old_exc_flags = get_float_exception_flags(status);
 
 v = float32_to_int32(a, status);
@@ -7138,10 +7138,10 @@ int_fast16_t float32_to_int16(float32 a, float_status 
*status)
 return res;
 }
 
-uint_fast16_t float32_to_uint16(float32 a, float_status *status)
+uint16_t float32_to_uint16(float32 a, float_status *status)
 {
 int32_t v;
-uint_fast16_t res;
+uint16_t res;
 int old_exc_flags = get_float_exception_flags(status);
 
 v = float32_to_int32(a, status);
@@ -7158,10 +7158,10 @@ uint_fast16_t float32_to_uint16(float32 a, float_status 
*status)
 return res;
 }
 
-uint_fast16_t float32_to_uint16_round_to_zero(float32 a, float_status *status)
+uint16_t float32_to_uint16_round_to_zero(float32 a, float_status *status)
 {
 int64_t v;
-uint_fast16_t res;
+uint16_t res;
 int old_exc_flags = get_float_exception_flags(status);
 
 v = float32_to_int64_round_to_zero(a, status);
@@ -7211,10 +7211,10 @@ uint32_t float64_to_uint32_round_to_zero(float64 a, 
float_status *status)
 return res;
 }
 
-int_fast16_t float64_to_int16(float64 a, float_status *status)
+int16_t float64_to_int16(float64 a, float_status *status)
 {
 int64_t v;
-int_fast16_t res;
+int16_t res;
 int old_exc_flags = get_float_exception_flags(status);
 
 v = float64_to_int32(a, status);
@@ -7231,10 +7231,10 @@ int_fast16_t float64_to_int16(float64 a, float_status 
*status)
 return res;
 }
 
-uint_fast16_t float64_to_uint16(float64 a, float_status *status)
+uint16_t float64_to_uint16(float64 a, float_status *status)
 {
 int64_t v;
-uint_fast16_t res;
+uint16_t res;
 int old_exc_flags = get_float_exception_flags(status);
 
 v = float64_to_int32(a, status);
@@ -7251,10 +7251,10 @@ uint_fast16_t float64_to_uint16(float64 a, float_status 
*status)
 return res;
 }
 
-uint_fast16_t float64_to_uint16_round_to_zero(float64 a, float_status *status)
+uint16_t float64_to_uint16_round_to_zero(float64 a, float_status *status)
 {
 int64_t v;
-uint_fast16_t res;
+uint16_t res;
 int old_exc_flags = get_float_exception_flags(status);
 
 v = float64_to_int64_round_to_zero(a, status);
diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h
index 575a739..624ed61 100644
--- a/include/fpu/softfloat.h
+++ b/include/fpu/softfloat.h
@@ -362,10 +362,10 @@ extern const float16 float16_default_nan;
 /*
 | Software IEC/IEEE single-precision conversion routines.
 **/
-int_fast16_t float32_to_int16(float32, float_status *status);
-uint_fast16_t float32_to_uint16(float32, float_status *status);
-int_fast16_t float32_to_int16_round_to_zero(float32, float_status *status);
-uint_fast16_t float32_to_uint16_round_to_zero(float32, float_status *status);
+int16_t float32_to_int16(float32, float_status *status);
+uint16_t float32_to_uint16(float32, float_status *status);
+int16_t float32_to_int16_round_to_zero(float32, float_status *status);
+uint16_t float32_to_uint16_round_to_zero(float32, float_status *status);
 int32_t float32_to_int32(float32, float_status *status);
 int32_t float32_to_int32_round_to_zero(float32, float_status *status);
 

Re: [Qemu-devel] [PATCH v3 3/3] target-arm: Implement the S2 MMU inputsize > pamax check

2016-01-26 Thread Edgar E. Iglesias
On Mon, Jan 25, 2016 at 12:57:41PM +, Peter Maydell wrote:
> On 22 January 2016 at 09:50, Edgar E. Iglesias  
> wrote:
> > From: "Edgar E. Iglesias" 
> >
> > Implement the inputsize > pamax check for Stage 2 translations.
> > We have multiple choices for how to respond to errors and
> > choose to fault.
> >
> > Signed-off-by: Edgar E. Iglesias 
> > ---
> >  target-arm/helper.c | 16 
> >  1 file changed, 12 insertions(+), 4 deletions(-)
> >
> > diff --git a/target-arm/helper.c b/target-arm/helper.c
> > index 2a6fa94..8901762 100644
> > --- a/target-arm/helper.c
> > +++ b/target-arm/helper.c
> > @@ -6809,7 +6809,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, 
> > target_ulong address,
> >   */
> >  int startlevel = extract32(tcr->raw_tcr, 6, 2);
> >  unsigned int pamax = arm_pamax(cpu);
> > -bool ok;
> > +bool ok = true;
> >
> >  if (va_size == 32 || stride == 9) {
> >  /* AArch32 or 4KB pages */
> > @@ -6819,9 +6819,17 @@ static bool get_phys_addr_lpae(CPUARMState *env, 
> > target_ulong address,
> >  level = 3 - startlevel;
> >  }
> >
> > -/* Check that the starting level is valid. */
> > -ok = check_s2_startlevel(cpu, va_size == 64, level,
> > - inputsize, stride, pamax);
> > +if (va_size == 64 &&
> > +inputsize > pamax &&
> > +(arm_el_is_aa64(env, 1) || inputsize > 40)) {
> > +/* We have multiple choices but choose to fault.  */
> 
> Can we say specifically "This is CONSTRAINED UNPREDICTABLE and
> we choose...", please?

I'll change this for v4.

Thanks!
Edgar



Re: [Qemu-devel] [RFC 0/10] Support Receive-Segment-Offload(RSC) for WHQL test of Window guest

2016-01-26 Thread Jason Wang


On 01/26/2016 02:44 PM, Fam Zheng wrote:
> On Tue, 01/26 06:24, w...@redhat.com wrote:
>> Wei Xu (10):
>>   'Segment', 'Chain' and 'Status' enumeration.
>>   Initilize & Cleanup.
>>   Chain lookup and packets caching.
>>   Tcp general data coalescing
>>   The draining timer
>>   IPv4 checksum.
>>   TCP control packet handling
>>   Sanity check & More bypass cases check.
>>   IPv6 support.
>>   Statistics.
> Please add subsystem prefixes to subjects, like:
>
>   "virtio-net: IPv6 support"
>   "virtio-net: Statistics

And need to be more verbose. E.g:

- "Statistics" is too generic, something like "TCP coalescing
statistics" is much better.
- "virtio-net: IPv6 support" which is really confusing since it lacks
some context. Reviewers may suspect there's no ipv6 support in the past.
- "Tcp general data coalescing, the parameters is a little bit horrible,
it's complicated to read, should can be optimized later." is too long to
be a subject. "Tcp general data coalescing" should be ok. For personal
comment like "the parameters is a little bit horrible, it's complicated
to read, should can be optimized later." could be places below '---' in
the patch.

And need a more verbose commit log please. At least I could not figure
out what is happening just form most of the commit logs. [1] is a very
good documentation for how to describe your changes, please have a look
at that and describe the changes correctly in each commit log. You can
also have a look at git history to see how it was done.

[1]
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/SubmittingPatches#n106

Thanks
>
> This applies to the cover letter too.
>
> (nit-pick: period "." is not necessary)
>
> Fam
>




Re: [Qemu-devel] [PATCH RFC 6/7] net/filter: Add a default filter to each netdev

2016-01-26 Thread Hailiang Zhang

On 2016/1/27 13:59, Jason Wang wrote:



On 01/27/2016 08:37 AM, Hailiang Zhang wrote:

On 2016/1/26 11:18, Jason Wang wrote:



On 01/25/2016 03:22 PM, Hailiang Zhang wrote:

On 2016/1/25 13:18, Jason Wang wrote:



On 01/22/2016 04:36 PM, zhanghailiang wrote:

We add each netdev a default buffer filter, which the name is
'nop', and the default buffer filter is disabled, so it has
no side effect for packets delivering in qemu net layer.

The default buffer filter can be used by COLO or Micro-checkpoint,
The reason we add the default filter is we hope to support
hot add network during COLO state in future.

Signed-off-by: zhanghailiang 
---
include/net/filter.h | 11 +++
net/dump.c   |  2 --
net/filter.c | 15 ++-
net/net.c| 18 ++
4 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/include/net/filter.h b/include/net/filter.h
index c7bd8f9..2043609 100644
--- a/include/net/filter.h
+++ b/include/net/filter.h
@@ -22,6 +22,16 @@
#define NETFILTER_CLASS(klass) \
OBJECT_CLASS_CHECK(NetFilterClass, (klass), TYPE_NETFILTER)



[...]



nf->netdev = ncs[0];
+nf->is_default = !strcmp(path, DEFAULT_FILTER_NAME);
+/*
+* For the default buffer filter, it will be disabled by default,
+* So it will not buffer any packets.
+*/
+if (nf->is_default) {
+nf->enabled = false;
+}


This seems not very elegant. Besides DEFAULT_FILTER_NAME(TYPE), we may
also want a DEFAULT_FILTER_PROPERTIES? Then you can store the "status"
into properties.



A little confused, do you mean add a 'default' property for filter ?
Just like the new 'status' property which is exported to users ?
Is the type of 'default' property string or bool ?


For example, is it possible to store the default property into a string
and just create the filter through qemu_opts_parse_noisily() by just


We still need to use some *visit* helpers to realize the capability,
because the object_add() helper need a 'Visitor *v' parameter, and the
codes
will be like:
QemuOptsList qemu_filter_opts = {
 .name = "default-filter",
 .head = QTAILQ_HEAD_INITIALIZER(qemu_filter_opts.head),
 .desc = {
 {
 .name = "netdev",
 .type = QEMU_OPT_STRING,
 },{
 .name = "status",
 .type = QEMU_OPT_STRING,
 },
 { /* end of list */ }
 },
};
void netdev_add_filter(const char *netdev_id,
const char *filter_type,
const char *id,
bool is_default,
Error **errp)
{
sprintf(optarg, "netdev=%s,status=%s", netdev_id,
 is_default ? "disable" : "enable");
 opts = qemu_opts_parse_noisily(_filter_opts,
optarg, false);
 if (!opts) {
 error_report("Failed to parse param '%s'", optarg);
 exit(1);
 }

 qdict = qemu_opts_to_qdict(opts, NULL);
 ov = opts_visitor_new(opts);
 visit_start_struct(opts_get_visitor(ov), , NULL, NULL, 0,
);
 if (err) {
 goto out_clean;
 }
 object_add(filter_type, id, qdict, opts_get_visitor(ov), );
 if (err) {
 goto out_clean;
 }

 visit_end_struct(opts_get_visitor(ov), );
 if (err) {
 qmp_object_del(id, NULL);
 goto out_clean;
 }

}

Or, we can simplify patch 4 by using qmp_object_add(), codes will be
like:

void netdev_add_filter(const char *netdev_id,
const char *filter_type,
const char *id,
bool is_default,
Error **errp)
{
 ... ...

 qov = qmp_output_visitor_new();
 ov = qmp_output_get_visitor(qov);
 visit_start_struct(ov,  , NULL, NULL, 0, );
 if (err) {
 goto out;
 }
 visit_type_str(ov, >name, "netdev", );
 if (err) {
 goto out;
 }
 status = is_default ? g_strdup("disable") : g_strdup("enable");
 visit_type_str(ov, , "status", );
 g_free(status);
 if (err) {
 goto out;
 }
 visit_end_struct(ov, );
 if (err) {
 goto out;
 }
 obj = qmp_output_get_qobject(qov);
 g_assert(obj != NULL);
 qmp_object_add(filter_type, id, true, obj, );
 qmp_output_visitor_cleanup(qov);
 qobject_decref(obj);

}

what's your suggestion ? :)



Can we just reuse object_create()? here



Yes, the codes is more clean if we reuse it.
I will fix it like that in v2, thanks.


Thanks,
Hailiang



.







Re: [Qemu-devel] [PATCH 03/10] target-ppc: Rework ppc_store_slb

2016-01-26 Thread Thomas Huth
On 27.01.2016 01:04, David Gibson wrote:
> On Mon, Jan 25, 2016 at 08:22:51PM +0100, Alexander Graf wrote:
>>
>>
>> On 01/25/2016 06:15 AM, David Gibson wrote:
>>> ppc_store_slb updates the SLB for PPC cpus with 64-bit hash MMUs.
>>> Currently it takes two parameters, which contain values encoded as the
>>> register arguments to the slbmte instruction, one register contains the
>>> ESID portion of the SLBE and also the slot number, the other contains the
>>> VSID portion of the SLBE.
>>>
>>> We're shortly going to want to do some SLB updates from other code where
>>> it is more convenient to supply the slot number and ESID separately, so
>>> rework this function and its callers to work this way.
>>>
>>> As a bonus, this slightly simplifies the emulation of segment registers for
>>> when running a 32-bit OS on a 64-bit CPU.
>>>
>>> Signed-off-by: David Gibson 
>>> ---
>>>  target-ppc/kvm.c|  2 +-
>>>  target-ppc/mmu-hash64.c | 24 +---
>>>  target-ppc/mmu-hash64.h |  3 ++-
>>>  target-ppc/mmu_helper.c | 14 +-
>>>  4 files changed, 21 insertions(+), 22 deletions(-)
...
>>> @@ -196,7 +198,7 @@ void helper_store_slb(CPUPPCState *env, target_ulong 
>>> rb, target_ulong rs)
>>>  {
>>>  PowerPCCPU *cpu = ppc_env_get_cpu(env);
>>> -if (ppc_store_slb(cpu, rb, rs) < 0) {
>>> +if (ppc_store_slb(cpu, rb & 0xfff, rb & ~0xfff, rs) < 0) {
>>
>> This might truncate the esid to 32bits on 32bits hosts, no? Should be
>> 0xfffULL instead.
> 
> Good point, nice catch.

Are you sure that it is really needed? If I run the following test
program on my 64-bit system:

int main()
{
unsigned long long ll = -1ULL;
printf("%llx %llx\n", ll, ll & ~0xfff);
return 0;
}

Then I get this output:

 f000

So it sounds like the value is sign-extended when it is cast to 64-bit.

However, if you respin this patch series anyway, then maybe better add
the ULL for clarity.

 Thomas




signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH V3] net: always walk through filters in reverse if traffic is egress

2016-01-26 Thread Jason Wang


On 01/26/2016 01:00 PM, Li Zhijian wrote:
> Previously, if we attach more than filters for one netdev, IN/OUT traffic pass
> through filters in a same order.
> ingress: netdev ->filter1 ->filter2 ->...filter[n] ->emulated device
> egress: emulated device ->filter1 ->filter2 ->...filter[n] ->netdev.
>
> But some scenes, we hope filters handle the egress traffic in a reverse order.
> For example, in colo-proxy (will be implemented later), we have a redirector
> filter and a colo-rewriter filter, we need the filter behavior like that:
> ingress(->)/egress(<-): chardev<->redirector<->colo-rewriter<->emulated device
>
> After this changes, egress traffic always pass through filters in a reverse
> order.
>
> Signed-off-by: Wen Congyang 
> Signed-off-by: Li Zhijian 
> Reviewed-by: Yang Hongyang 

Applied with minor tweaks on commit log:

https://github.com/jasowang/qemu/commit/ec96442e398191f84aab824180aa83cd5eda0010

and use:

QTAILQ_HEAD(NetFilterHead, NetFilterState) filters;

instead.

Thanks

> ---
>  include/net/net.h |  4 +++-
>  net/filter.c  | 21 +++--
>  net/net.c | 20 +++-
>  3 files changed, 37 insertions(+), 8 deletions(-)
>
> diff --git a/include/net/net.h b/include/net/net.h
> index 7af3e15..1d807cc 100644
> --- a/include/net/net.h
> +++ b/include/net/net.h
> @@ -79,6 +79,8 @@ typedef struct NetClientInfo {
>  SetVnetBE *set_vnet_be;
>  } NetClientInfo;
>  
> +QTAILQ_HEAD(NetFilterHead, NetFilterState);
> +
>  struct NetClientState {
>  NetClientInfo *info;
>  int link_down;
> @@ -92,7 +94,7 @@ struct NetClientState {
>  NetClientDestructor *destructor;
>  unsigned int queue_index;
>  unsigned rxfilter_notify_enabled:1;
> -QTAILQ_HEAD(, NetFilterState) filters;
> +struct NetFilterHead filters;
>  };
>  
>  typedef struct NICState {
> diff --git a/net/filter.c b/net/filter.c
> index 5d90f83..17a8398 100644
> --- a/net/filter.c
> +++ b/net/filter.c
> @@ -34,6 +34,22 @@ ssize_t qemu_netfilter_receive(NetFilterState *nf,
>  return 0;
>  }
>  
> +static NetFilterState *netfilter_next(NetFilterState *nf,
> +  NetFilterDirection dir)
> +{
> +NetFilterState *next;
> +
> +if (dir == NET_FILTER_DIRECTION_TX) {
> +/* forward walk through filters */
> +next = QTAILQ_NEXT(nf, next);
> +} else {
> +/* reverse order */
> +next = QTAILQ_PREV(nf, NetFilterHead, next);
> +}
> +
> +return next;
> +}
> +
>  ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,
>  unsigned flags,
>  const struct iovec *iov,
> @@ -43,7 +59,7 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,
>  int ret = 0;
>  int direction;
>  NetFilterState *nf = opaque;
> -NetFilterState *next = QTAILQ_NEXT(nf, next);
> +NetFilterState *next = NULL;
>  
>  if (!sender || !sender->peer) {
>  /* no receiver, or sender been deleted, no need to pass it further */
> @@ -61,6 +77,7 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,
>  direction = nf->direction;
>  }
>  
> +next = netfilter_next(nf, direction);
>  while (next) {
>  /*
>   * if qemu_netfilter_pass_to_next been called, means that
> @@ -73,7 +90,7 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,
>  if (ret) {
>  return ret;
>  }
> -next = QTAILQ_NEXT(next, next);
> +next = netfilter_next(next, direction);
>  }
>  
>  /*
> diff --git a/net/net.c b/net/net.c
> index 87dd356..c929c41 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -580,11 +580,21 @@ static ssize_t filter_receive_iov(NetClientState *nc,
>  ssize_t ret = 0;
>  NetFilterState *nf = NULL;
>  
> -QTAILQ_FOREACH(nf, >filters, next) {
> -ret = qemu_netfilter_receive(nf, direction, sender, flags, iov,
> - iovcnt, sent_cb);
> -if (ret) {
> -return ret;
> +if (direction == NET_FILTER_DIRECTION_TX) {
> +QTAILQ_FOREACH(nf, >filters, next) {
> +ret = qemu_netfilter_receive(nf, direction, sender, flags, iov,
> + iovcnt, sent_cb);
> +if (ret) {
> +return ret;
> +}
> +}
> +} else {
> +QTAILQ_FOREACH_REVERSE(nf, >filters, NetFilterHead, next) {
> +ret = qemu_netfilter_receive(nf, direction, sender, flags, iov,
> + iovcnt, sent_cb);
> +if (ret) {
> +return ret;
> +}
>  }
>  }
>  




Re: [Qemu-devel] VFIO based vGPU(was Re: [Announcement] 2015-Q3 release of XenGT - a Mediated ...)

2016-01-26 Thread Jike Song
On 01/27/2016 11:07 AM, Alex Williamson wrote:
> On Wed, 2016-01-27 at 09:47 +0800, Jike Song wrote:
>> On 01/27/2016 06:56 AM, Alex Williamson wrote:
>>> On Tue, 2016-01-26 at 22:39 +, Tian, Kevin wrote:
> From: Alex Williamson [mailto:alex.william...@redhat.com]
> Sent: Wednesday, January 27, 2016 6:27 AM
>  
> On Tue, 2016-01-26 at 22:15 +, Tian, Kevin wrote:
>>> From: Alex Williamson [mailto:alex.william...@redhat.com]
>>> Sent: Wednesday, January 27, 2016 6:08 AM
>>>  
>>>  
>>  
>> Today KVMGT (not using VFIO yet) registers I/O emulation callbacks to
>> KVM, so VM MMIO access will be forwarded to KVMGT directly for
>> emulation in kernel. If we reuse above R/W flags, the whole emulation
>> path would be unnecessarily long with obvious performance impact. We
>> either need a new flag here to indicate in-kernel emulation (bias 
>> from
>> passthrough support), or just hide the region alternatively (let 
>> KVMGT
>> to handle I/O emulation itself like today).
>  
> That sounds like a future optimization TBH.  There's very strict
> layering between vfio and kvm.  Physical device assignment could make
> use of it as well, avoiding a round trip through userspace when an
> ioread/write would do.  Userspace also needs to orchestrate those 
> kinds
> of accelerators, there might be cases where userspace wants to see 
> those
> transactions for debugging or manipulating the device.  We can't 
> simply
> take shortcuts to provide such direct access.  Thanks,
>  
  
 But we have to balance such debugging flexibility and acceptable 
 performance.
 To me the latter one is more important otherwise there'd be no real 
 usage
 around this technique, while for debugging there are other alternative 
 (e.g.
 ftrace) Consider some extreme case with 100k traps/second and then see
 how much impact a 2-3x longer emulation path can bring...
>>>  
>>> Are you jumping to the conclusion that it cannot be done with proper
>>> layering in place?  Performance is important, but it's not an excuse to
>>> abandon designing interfaces between independent components.  Thanks,
>>>  
>>  
>> Two are not controversial. My point is to remove unnecessary long trip
>> as possible. After another thought, yes we can reuse existing read/write
>> flags:
>>  - KVMGT will expose a private control variable whether in-kernel
>> delivery is required;
>  
> But in-kernel delivery is never *required*.  Wouldn't userspace want to
> deliver in-kernel any time it possibly could?
>  
>>  - when the variable is true, KVMGT will register in-kernel MMIO
>> emulation callbacks then VM MMIO request will be delivered to KVMGT
>> directly;
>>  - when the variable is false, KVMGT will not register anything.
>> VM MMIO request will then be delivered to Qemu and then ioread/write
>> will be used to finally reach KVMGT emulation logic;
>  
> No, that means the interface is entirely dependent on a backdoor through
> KVM.  Why can't userspace (QEMU) do something like register an MMIO
> region with KVM handled via a provided file descriptor and offset,
> couldn't KVM then call the file ops without a kernel exit?  Thanks,
>  
  
 Could you elaborate this thought? If it can achieve the purpose w/o
 a kernel exit definitely we can adapt to it. :-)
>>>  
>>> I only thought of it when replying to the last email and have been doing
>>> some research, but we already do quite a bit of synchronization through
>>> file descriptors.  The kvm-vfio pseudo device uses a group file
>>> descriptor to ensure a user has access to a group, allowing some degree
>>> of interaction between modules.  Eventfds and irqfds already make use of
>>> f_ops on file descriptors to poke data.  So, if KVM had information that
>>> an MMIO region was backed by a file descriptor for which it already has
>>> a reference via fdget() (and verified access rights and whatnot), then
>>> it ought to be a simple matter to get to f_ops->read/write knowing the
>>> base offset of that MMIO region.  Perhaps it could even simply use
>>> __vfs_read/write().  Then we've got a proper reference to the file
>>> descriptor for ownership purposes and we've transparently jumped across
>>> modules without any implicit knowledge of the other end.  Could it work?
>>  
>> This is OK for KVMGT, from fops to vgpu device-model would always be simple.
>> The only question is, how is KVM hypervisor supposed to get the fd on 
>> VM-exitings?
> 
> Hi Jike,
> 
> Sorry, I don't understand "on VM-exiting".  KVM would hold a reference
> to the fd via fdget(), so the vfio device wouldn't be closed until the
> VM 

Re: [Qemu-devel] [PULL 00/28] ppc-for-2.6 queue 20160125

2016-01-26 Thread David Gibson
On Tue, Jan 26, 2016 at 11:56:15AM +0100, Gerd Hoffmann wrote:
>   Hi,
> 
> > Just set up a 32bit vm and maybe configure it to automatically test your 
> > git branch? ;)
> 
> Container works even better as you can kick the build right from the
> (host) command line, without boot vm, login, ...
> 
> sudo systemd-nspawn \
> --directory /path/to/32bit-distro-root \
> --bind /home \
> --share-system \
> --user $USER \
> make -C $HOME/projects/qemu/build-32bit
> 
> configure is a bit more complicated because systemd-nspaws lacks a
> --workdir switch, you need either some wrapper scripting or have to boot
> the container, login, cd $builddir and run configure manually.

Hmm.  Is there a HOWTO for setting up a 32-bit container?  Containers
aren't something I've had the time to become familiar with so far.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v5 1/2] configure: detect ifunc and avx2 attribute

2016-01-26 Thread Liang Li
Detect if the compiler can support the ifun and avx2, if so, set
CONFIG_AVX2_OPT which will be used to turn on the avx2 instruction
optimization.

Suggested-by: Paolo Bonzini 
Suggested-by: Peter Maydell 
Signed-off-by: Liang Li 
---
 configure | 21 +
 1 file changed, 21 insertions(+)

diff --git a/configure b/configure
index 3506e44..a50dcf5 100755
--- a/configure
+++ b/configure
@@ -311,6 +311,7 @@ smartcard=""
 libusb=""
 usb_redir=""
 opengl=""
+avx2_opt="no"
 zlib="yes"
 lzo=""
 snappy=""
@@ -1832,6 +1833,21 @@ EOF
 fi
 
 ##
+# avx2 optimization requirement check
+
+cat > $TMPC << EOF
+static void bar(void) {}
+static void *bar_ifunc(void) {return (void*) bar;}
+static void foo(void) __attribute__((ifunc("bar_ifunc")));
+int main(void) { foo(); return 0; }
+EOF
+if compile_prog "-mavx2" "" ; then
+if readelf --syms $TMPE |grep "IFUNC.*foo" >/dev/null 2>&1; then
+avx2_opt="yes"
+fi
+fi
+
+#
 # zlib check
 
 if test "$zlib" != "no" ; then
@@ -4922,6 +4938,7 @@ echo "bzip2 support $bzip2"
 echo "NUMA host support $numa"
 echo "tcmalloc support  $tcmalloc"
 echo "jemalloc support  $jemalloc"
+echo "avx2 optimization $avx2_opt"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -5306,6 +5323,10 @@ if test "$opengl" = "yes" ; then
   echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
 fi
 
+if test "$avx2_opt" = "yes" ; then
+  echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
+fi
+
 if test "$lzo" = "yes" ; then
   echo "CONFIG_LZO=y" >> $config_host_mak
 fi
-- 
1.9.1




[Qemu-devel] [PATCH v5 2/2] cutils: add avx2 instruction optimization

2016-01-26 Thread Liang Li
buffer_find_nonzero_offset() is a hot function during live migration.
Now it use SSE2 instructions for optimization. For platform supports
AVX2 instructions, use AVX2 instructions for optimization can help
to improve the performance of buffer_find_nonzero_offset() about 30%
comparing to SSE2.

Live migration can be faster with this optimization, the test result
shows that for an 8GiB RAM idle guest just boots, this patch can help
to shorten the total live migration time about 6%.

This patch use the ifunc mechanism to select the proper function when
running, for platform supports AVX2, execute the AVX2 instructions,
else, execute the original instructions.

Signed-off-by: Liang Li 
Suggested-by: Paolo Bonzini 
Suggested-by: Richard Henderson 
Reviewed-by: Paolo Bonzini 
---
 include/qemu-common.h |   8 +---
 util/cutils.c | 118 --
 2 files changed, 115 insertions(+), 11 deletions(-)

diff --git a/include/qemu-common.h b/include/qemu-common.h
index 22b010c..f4c8c24 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -483,13 +483,7 @@ void qemu_hexdump(const char *buf, FILE *fp, const char 
*prefix, size_t size);
 #endif
 
 #define BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR 8
-static inline bool
-can_use_buffer_find_nonzero_offset(const void *buf, size_t len)
-{
-return (len % (BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR
-   * sizeof(VECTYPE)) == 0
-&& ((uintptr_t) buf) % sizeof(VECTYPE) == 0);
-}
+bool can_use_buffer_find_nonzero_offset(const void *buf, size_t len);
 size_t buffer_find_nonzero_offset(const void *buf, size_t len);
 
 /*
diff --git a/util/cutils.c b/util/cutils.c
index cfeb848..5c8ee5c 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -161,6 +161,14 @@ int qemu_fdatasync(int fd)
 #endif
 }
 
+static bool
+can_use_buffer_find_nonzero_offset_inner(const void *buf, size_t len)
+{
+return (len % (BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR
+   * sizeof(VECTYPE)) == 0
+&& ((uintptr_t) buf) % sizeof(VECTYPE) == 0);
+}
+
 /*
  * Searches for an area with non-zero content in a buffer
  *
@@ -169,8 +177,8 @@ int qemu_fdatasync(int fd)
  * and addr must be a multiple of sizeof(VECTYPE) due to
  * restriction of optimizations in this function.
  *
- * can_use_buffer_find_nonzero_offset() can be used to check
- * these requirements.
+ * can_use_buffer_find_nonzero_offset_inner() can be used to
+ * check these requirements.
  *
  * The return value is the offset of the non-zero area rounded
  * down to a multiple of sizeof(VECTYPE) for the first
@@ -181,13 +189,13 @@ int qemu_fdatasync(int fd)
  * If the buffer is all zero the return value is equal to len.
  */
 
-size_t buffer_find_nonzero_offset(const void *buf, size_t len)
+static size_t buffer_find_nonzero_offset_inner(const void *buf, size_t len)
 {
 const VECTYPE *p = buf;
 const VECTYPE zero = (VECTYPE){0};
 size_t i;
 
-assert(can_use_buffer_find_nonzero_offset(buf, len));
+assert(can_use_buffer_find_nonzero_offset_inner(buf, len));
 
 if (!len) {
 return 0;
@@ -216,6 +224,108 @@ size_t buffer_find_nonzero_offset(const void *buf, size_t 
len)
 return i * sizeof(VECTYPE);
 }
 
+#ifdef CONFIG_AVX2_OPT
+#pragma GCC push_options
+#pragma GCC target("avx2")
+#include 
+#include 
+
+#define AVX2_VECTYPE__m256i
+#define AVX2_SPLAT(p)   _mm256_set1_epi8(*(p))
+#define AVX2_ALL_EQ(v1, v2) \
+(_mm256_movemask_epi8(_mm256_cmpeq_epi8(v1, v2)) == 0x)
+#define AVX2_VEC_OR(v1, v2) (_mm256_or_si256(v1, v2))
+
+static bool
+can_use_buffer_find_nonzero_offset_avx2(const void *buf, size_t len)
+{
+return (len % (BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR
+   * sizeof(AVX2_VECTYPE)) == 0
+&& ((uintptr_t) buf) % sizeof(AVX2_VECTYPE) == 0);
+}
+
+static size_t buffer_find_nonzero_offset_avx2(const void *buf, size_t len)
+{
+const AVX2_VECTYPE *p = buf;
+const AVX2_VECTYPE zero = (AVX2_VECTYPE){0};
+size_t i;
+
+assert(can_use_buffer_find_nonzero_offset_avx2(buf, len));
+
+if (!len) {
+return 0;
+}
+
+for (i = 0; i < BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR; i++) {
+if (!AVX2_ALL_EQ(p[i], zero)) {
+return i * sizeof(AVX2_VECTYPE);
+}
+}
+
+for (i = BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR;
+ i < len / sizeof(AVX2_VECTYPE);
+ i += BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR) {
+AVX2_VECTYPE tmp0 = AVX2_VEC_OR(p[i + 0], p[i + 1]);
+AVX2_VECTYPE tmp1 = AVX2_VEC_OR(p[i + 2], p[i + 3]);
+AVX2_VECTYPE tmp2 = AVX2_VEC_OR(p[i + 4], p[i + 5]);
+AVX2_VECTYPE tmp3 = AVX2_VEC_OR(p[i + 6], p[i + 7]);
+AVX2_VECTYPE tmp01 = AVX2_VEC_OR(tmp0, tmp1);
+AVX2_VECTYPE tmp23 = AVX2_VEC_OR(tmp2, tmp3);
+if (!AVX2_ALL_EQ(AVX2_VEC_OR(tmp01, tmp23), zero)) {
+ 

[Qemu-devel] [PATCH v5 0/2] add avx2 instruction optimization

2016-01-26 Thread Liang Li
buffer_find_nonzero_offset() is a hot function during live migration.
Now it use SSE2 instructions for optimization. For platform supports
AVX2 instructions, use the AVX2 instructions for optimization can help
to improve the performance of zero page checking about 30% comparing
to SSE2.
Live migration can be faster with this optimization, the test result
shows that for an 8GB RAM idle guest, this patch can help to shorten
the total live migration time about 6%.

This patch use the ifunc mechanism to select the proper function when
running, for platform supports AVX2, execute the AVX2 instructions,
else, execute the original instructions.

With this patch, the QEMU binary can run on both platforms support AVX2
or not.

Compiler which doesn't support the AVX2 and ifunc attribute can also build
the source code successfully.

v5 -> v4 changes:
  * Enhance the ifunc attribute detection (Paolo's suggestion)

v3 -> v4 changes:
  * Use the GCC #pragma to make things simple (Paolo's suggestion) 
  * Put avx2 related code in cutils.c (Richard's suggestion)
  * Change the configure, detect ifunc and avx2 attributes together

v2 -> v3 changes:
  * Detect the ifunc attribute support (Paolo's suggestion) 
  * Use the ifunc attribute instead of the inline asm (Richard's suggestion)
  * Change the configure (Juan's suggestion)

Liang Li (2):
  configure: detect ifunc and avx2 attribute
  cutils: add avx2 instruction optimization

 configure |  21 +
 include/qemu-common.h |   8 +---
 util/cutils.c | 118 --
 3 files changed, 136 insertions(+), 11 deletions(-)

-- 
1.9.1




Re: [Qemu-devel] [PATCH v2] net: netmap: use nm_open() to open netmap ports

2016-01-26 Thread Jason Wang


On 01/26/2016 02:24 AM, Vincenzo Maffione wrote:
> This patch simplifies the netmap backend code by means of the nm_open()
> helper function provided by netmap_user.h, which hides the details of
> open(), iotcl() and mmap() carried out on the netmap device.
>
> Moreover, the semantic of nm_open() makes it possible to open special
> netmap ports (e.g. pipes, monitors) and use special modes (e.g. host rings
> only, single queue mode, exclusive access).
>
> Signed-off-by: Vincenzo Maffione 

Applied to -net.

Thanks

> ---
>  net/netmap.c | 97 
> 
>  1 file changed, 32 insertions(+), 65 deletions(-)
>
> diff --git a/net/netmap.c b/net/netmap.c
> index 5558368..27295ab 100644
> --- a/net/netmap.c
> +++ b/net/netmap.c
> @@ -39,21 +39,12 @@
>  #include "qemu/error-report.h"
>  #include "qemu/iov.h"
>  
> -/* Private netmap device info. */
> -typedef struct NetmapPriv {
> -int fd;
> -size_t  memsize;
> -void*mem;
> -struct netmap_if*nifp;
> -struct netmap_ring  *rx;
> -struct netmap_ring  *tx;
> -charfdname[PATH_MAX];/* Normally "/dev/netmap". 
> */
> -charifname[IFNAMSIZ];
> -} NetmapPriv;
> -
>  typedef struct NetmapState {
>  NetClientState  nc;
> -NetmapPriv  me;
> +struct nm_desc  *nmd;
> +charifname[IFNAMSIZ];
> +struct netmap_ring  *tx;
> +struct netmap_ring  *rx;
>  boolread_poll;
>  boolwrite_poll;
>  struct ioveciov[IOV_MAX];
> @@ -90,44 +81,23 @@ pkt_copy(const void *_src, void *_dst, int l)
>   * Open a netmap device. We assume there is only one queue
>   * (which is the case for the VALE bridge).
>   */
> -static void netmap_open(NetmapPriv *me, Error **errp)
> +static struct nm_desc *netmap_open(const NetdevNetmapOptions *nm_opts,
> +   Error **errp)
>  {
> -int fd;
> -int err;
> -size_t l;
> +struct nm_desc *nmd;
>  struct nmreq req;
>  
> -me->fd = fd = open(me->fdname, O_RDWR);
> -if (fd < 0) {
> -error_setg_file_open(errp, errno, me->fdname);
> -return;
> -}
>  memset(, 0, sizeof(req));
> -pstrcpy(req.nr_name, sizeof(req.nr_name), me->ifname);
> -req.nr_ringid = NETMAP_NO_TX_POLL;
> -req.nr_version = NETMAP_API;
> -err = ioctl(fd, NIOCREGIF, );
> -if (err) {
> -error_setg_errno(errp, errno, "Unable to register %s", me->ifname);
> -goto error;
> -}
> -l = me->memsize = req.nr_memsize;
>  
> -me->mem = mmap(0, l, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
> -if (me->mem == MAP_FAILED) {
> -error_setg_errno(errp, errno, "Unable to mmap netmap shared memory");
> -me->mem = NULL;
> -goto error;
> +nmd = nm_open(nm_opts->ifname, , NETMAP_NO_TX_POLL,
> +  NULL);
> +if (nmd == NULL) {
> +error_setg_errno(errp, errno, "Failed to nm_open() %s",
> + nm_opts->ifname);
> +return NULL;
>  }
>  
> -me->nifp = NETMAP_IF(me->mem, req.nr_offset);
> -me->tx = NETMAP_TXRING(me->nifp, 0);
> -me->rx = NETMAP_RXRING(me->nifp, 0);
> -
> -return;
> -
> -error:
> -close(me->fd);
> +return nmd;
>  }
>  
>  static void netmap_send(void *opaque);
> @@ -136,7 +106,7 @@ static void netmap_writable(void *opaque);
>  /* Set the event-loop handlers for the netmap backend. */
>  static void netmap_update_fd_handler(NetmapState *s)
>  {
> -qemu_set_fd_handler(s->me.fd,
> +qemu_set_fd_handler(s->nmd->fd,
>  s->read_poll ? netmap_send : NULL,
>  s->write_poll ? netmap_writable : NULL,
>  s);
> @@ -188,7 +158,7 @@ static ssize_t netmap_receive(NetClientState *nc,
>const uint8_t *buf, size_t size)
>  {
>  NetmapState *s = DO_UPCAST(NetmapState, nc, nc);
> -struct netmap_ring *ring = s->me.tx;
> +struct netmap_ring *ring = s->tx;
>  uint32_t i;
>  uint32_t idx;
>  uint8_t *dst;
> @@ -218,7 +188,7 @@ static ssize_t netmap_receive(NetClientState *nc,
>  ring->slot[i].flags = 0;
>  pkt_copy(buf, dst, size);
>  ring->cur = ring->head = nm_ring_next(ring, i);
> -ioctl(s->me.fd, NIOCTXSYNC, NULL);
> +ioctl(s->nmd->fd, NIOCTXSYNC, NULL);
>  
>  return size;
>  }
> @@ -227,7 +197,7 @@ static ssize_t netmap_receive_iov(NetClientState *nc,
>  const struct iovec *iov, int iovcnt)
>  {
>  NetmapState *s = DO_UPCAST(NetmapState, nc, nc);
> -struct netmap_ring *ring = s->me.tx;
> +struct netmap_ring *ring = s->tx;
>  uint32_t last;
>  uint32_t idx;
>  uint8_t *dst;
> @@ -284,7 +254,7 @@ static ssize_t netmap_receive_iov(NetClientState *nc,
>  /* Now update ring->cur and ring->head. */
>  ring->cur = ring->head 

Re: [Qemu-devel] [PATCH v2] net/filter: Fix the output information for command 'info network'

2016-01-26 Thread Jason Wang


On 01/27/2016 12:59 AM, Eric Blake wrote:
> On 01/25/2016 11:43 PM, zhanghailiang wrote:
>> The properties of netfilter object could be changed by 'qom-set'
>> command, but the output of 'info network' command is not updated,
>> because it got the old information through nf->info_str, it will
>> not be updated while we change the value of netfilter's property.
>>
>> Here we split a helper function that could collect the output
>> information for filter, and also remove the useless member
>> 'info_str' from struct NetFilterState.
>>
>> Signed-off-by: zhanghailiang 
>> Cc: Jason Wang 
>> Cc: Eric Blake 
>> Cc: Markus Armbruster 
>> Cc: Yang Hongyang 
>> ---
>> v2:
>> - write the information to monitor directly instead of
>>   printing into a temporary string before output them. (Eric's comment)
> Looks a lot nicer compared to v1!
> Reviewed-by: Eric Blake 
>

Applied to -net.

Thanks




Re: [Qemu-devel] [PATCH RFC 6/7] net/filter: Add a default filter to each netdev

2016-01-26 Thread Jason Wang


On 01/27/2016 08:37 AM, Hailiang Zhang wrote:
> On 2016/1/26 11:18, Jason Wang wrote:
>>
>>
>> On 01/25/2016 03:22 PM, Hailiang Zhang wrote:
>>> On 2016/1/25 13:18, Jason Wang wrote:


 On 01/22/2016 04:36 PM, zhanghailiang wrote:
> We add each netdev a default buffer filter, which the name is
> 'nop', and the default buffer filter is disabled, so it has
> no side effect for packets delivering in qemu net layer.
>
> The default buffer filter can be used by COLO or Micro-checkpoint,
> The reason we add the default filter is we hope to support
> hot add network during COLO state in future.
>
> Signed-off-by: zhanghailiang 
> ---
>include/net/filter.h | 11 +++
>net/dump.c   |  2 --
>net/filter.c | 15 ++-
>net/net.c| 18 ++
>4 files changed, 43 insertions(+), 3 deletions(-)
>
> diff --git a/include/net/filter.h b/include/net/filter.h
> index c7bd8f9..2043609 100644
> --- a/include/net/filter.h
> +++ b/include/net/filter.h
> @@ -22,6 +22,16 @@
>#define NETFILTER_CLASS(klass) \
>OBJECT_CLASS_CHECK(NetFilterClass, (klass), TYPE_NETFILTER)
>
>>
>> [...]
>>
>
>nf->netdev = ncs[0];
> +nf->is_default = !strcmp(path, DEFAULT_FILTER_NAME);
> +/*
> +* For the default buffer filter, it will be disabled by default,
> +* So it will not buffer any packets.
> +*/
> +if (nf->is_default) {
> +nf->enabled = false;
> +}

 This seems not very elegant. Besides DEFAULT_FILTER_NAME(TYPE), we may
 also want a DEFAULT_FILTER_PROPERTIES? Then you can store the "status"
 into properties.

>>>
>>> A little confused, do you mean add a 'default' property for filter ?
>>> Just like the new 'status' property which is exported to users ?
>>> Is the type of 'default' property string or bool ?
>>
>> For example, is it possible to store the default property into a string
>> and just create the filter through qemu_opts_parse_noisily() by just
>
> We still need to use some *visit* helpers to realize the capability,
> because the object_add() helper need a 'Visitor *v' parameter, and the
> codes
> will be like:
> QemuOptsList qemu_filter_opts = {
> .name = "default-filter",
> .head = QTAILQ_HEAD_INITIALIZER(qemu_filter_opts.head),
> .desc = {
> {
> .name = "netdev",
> .type = QEMU_OPT_STRING,
> },{
> .name = "status",
> .type = QEMU_OPT_STRING,
> },
> { /* end of list */ }
> },
> };
> void netdev_add_filter(const char *netdev_id,
>const char *filter_type,
>const char *id,
>bool is_default,
>Error **errp)
> {
>sprintf(optarg, "netdev=%s,status=%s", netdev_id,
> is_default ? "disable" : "enable");
> opts = qemu_opts_parse_noisily(_filter_opts,
>optarg, false);
> if (!opts) {
> error_report("Failed to parse param '%s'", optarg);
> exit(1);
> }
>
> qdict = qemu_opts_to_qdict(opts, NULL);
> ov = opts_visitor_new(opts);
> visit_start_struct(opts_get_visitor(ov), , NULL, NULL, 0,
> );
> if (err) {
> goto out_clean;
> }
> object_add(filter_type, id, qdict, opts_get_visitor(ov), );
> if (err) {
> goto out_clean;
> }
>
> visit_end_struct(opts_get_visitor(ov), );
> if (err) {
> qmp_object_del(id, NULL);
> goto out_clean;
> }
>
> }
>
> Or, we can simplify patch 4 by using qmp_object_add(), codes will be
> like:
>
> void netdev_add_filter(const char *netdev_id,
>const char *filter_type,
>const char *id,
>bool is_default,
>Error **errp)
> {
> ... ...
>
> qov = qmp_output_visitor_new();
> ov = qmp_output_get_visitor(qov);
> visit_start_struct(ov,  , NULL, NULL, 0, );
> if (err) {
> goto out;
> }
> visit_type_str(ov, >name, "netdev", );
> if (err) {
> goto out;
> }
> status = is_default ? g_strdup("disable") : g_strdup("enable");
> visit_type_str(ov, , "status", );
> g_free(status);
> if (err) {
> goto out;
> }
> visit_end_struct(ov, );
> if (err) {
> goto out;
> }
> obj = qmp_output_get_qobject(qov);
> g_assert(obj != NULL);
> qmp_object_add(filter_type, id, true, obj, );
> qmp_output_visitor_cleanup(qov);
> qobject_decref(obj);
>
> }
>
> what's your suggestion ? :)
>

Can we just reuse object_create()? here

> Thanks,
> Hailiang 




[Qemu-devel] [PATCH] migration: remove useless code.

2016-01-26 Thread Liang Li
Since 's->state' will be set in migrate_init(), there is no
need to set it before calling migrate_init(). The code and
the related comments can be removed.

Signed-off-by: Liang Li 
---
 migration/migration.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index aaca451..ae38242 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1006,12 +1006,6 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 return;
 }
 
-/* We are starting a new migration, so we want to start in a clean
-   state.  This change is only needed if previous migration
-   failed/was cancelled.  We don't use migrate_set_state() because
-   we are setting the initial state, not changing it. */
-s->state = MIGRATION_STATUS_NONE;
-
 s = migrate_init();
 
 if (strstart(uri, "tcp:", )) {
-- 
1.9.1




Re: [Qemu-devel] [PATCH] migration: remove useless code.

2016-01-26 Thread Fam Zheng
On Wed, 01/27 14:11, Liang Li wrote:
> Since 's->state' will be set in migrate_init(), there is no
> need to set it before calling migrate_init(). The code and
> the related comments can be removed.

Reviewed-by: Fam Zheng 

> 
> Signed-off-by: Liang Li 
> ---
>  migration/migration.c | 6 --
>  1 file changed, 6 deletions(-)
> 
> diff --git a/migration/migration.c b/migration/migration.c
> index aaca451..ae38242 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -1006,12 +1006,6 @@ void qmp_migrate(const char *uri, bool has_blk, bool 
> blk,
>  return;
>  }
>  
> -/* We are starting a new migration, so we want to start in a clean
> -   state.  This change is only needed if previous migration
> -   failed/was cancelled.  We don't use migrate_set_state() because
> -   we are setting the initial state, not changing it. */
> -s->state = MIGRATION_STATUS_NONE;
> -
>  s = migrate_init();
>  
>  if (strstart(uri, "tcp:", )) {
> -- 
> 1.9.1
> 
> 



Re: [Qemu-devel] [PATCH v2 08/13] block: Support meta dirty bitmap

2016-01-26 Thread Fam Zheng
On Tue, 01/26 10:49, Vladimir Sementsov-Ogievskiy wrote:
> On 26.01.2016 09:25, Fam Zheng wrote:
> >On Fri, 01/22 15:05, Vladimir Sementsov-Ogievskiy wrote:
> >>>In my migration series I need iterators, get granularity, and
> >>>something like hbitmap_count  for meta bitmaps. You can add them
> >>>here if you want, or I can add them in my series.
> >Okay, I can add that.
> >
> >I have one more question on the interface: what dirty bitmaps are going to be
> >migrated? At this moment there are dirty bitmaps created by block jobs
> >(drive-mirror), and in-memory dirty bitmaps created for incremental backup;
> >later there will be persistent dirty bitmaps owned by block drivers (extended
> >version of qcow2, and in QBM driver I'm working on). Which of them are 
> >subject
> >of migration in your series?
> >
> >I'm asking because I want to know whether we need to implement multiple meta
> >bitmaps on one block dirty bitmap.
> >
> >Fam
> Only named bitmaps are migrated. For now, only qmp-created bitmaps
> are named. So, it can be in-memory dirty bitmaps or, in future,
> persistent dirty bitmaps.
> 
> Why multiple meta bitmaps?

The complication is from combining persistence and migration of a dirty bitmap.

To begin with, persistence drivers (qcow2 or QBM) would need meta dirty bitmaps
to avoid writing unchanged dirty bit ranges to disk, just like in migration.
This means if the persisted named dirty bitmap is being migrated, both the
block driver and migration code will then need their own meta dirty bitmaps,
that is where the question rose.

One step back, we haven't sorted out "migrating persistent dirty bitmap" at all
(see below). So it's probably okay to disallow that as the first step.

P.S. For discussion, I think we ultimately want users to be able to continue
their incremental backup even across the migration point.  If they're using
shared storage, I think it is possible even without dirty bitmap migration, by
flushing the dirty bitmap at src side then loading it at dest side. Otherwise
it is trickier as we will have to migrate the persisted dirty bitmap - the dest
side must use a capable format, and we need to check this capability when
migration starts.   By that time, the meta dirty bitmap interface can be
extended to allow at least two meta bitmaps on the same dirty bitmap.

Fam



Re: [Qemu-devel] [PATCH v5 00/12] Dirty bitmaps migration

2016-01-26 Thread Vladimir Sementsov-Ogievskiy

On 03.06.2015 01:17, John Snow wrote:


On 05/28/2015 04:56 PM, Denis V. Lunev wrote:

On 28/05/15 23:09, John Snow wrote:

On 05/26/2015 10:51 AM, Denis V. Lunev wrote:

On 26/05/15 17:48, Denis V. Lunev wrote:

On 21/05/15 19:44, John Snow wrote:

On 05/21/2015 09:57 AM, Denis V. Lunev wrote:

On 21/05/15 16:51, Vladimir Sementsov-Ogievskiy wrote:

Hi all.

Hmm. There is an interesting suggestion from Denis Lunev (in CC)
about
how to drop meta bitmaps and make things easer.

method:


start migration

disk and memory are migrated, but not dirty bitmaps.

stop vm

create all necessary bitmaps in destination vm (empty, but with same
names and granularities and enabled flag)

start destination vm

empty bitmaps are tracking now

start migrating dirty bitmaps. merge them to corresponding bitmaps

in destination
while bitmaps are migrating, they should be in some kind of
'inconsistent' state.
so, we can't start backup or other migration while bitmaps are
migrating, but vm is already _running_ on destination.

what do you think about it?


the description is a bit incorrect

- start migration process, perform memory and disk migration
  as usual. VM is still executed at source
- start VM on target. VM on source should be on pause as usual,
  do not finish migration process. Running VM on target "writes"
  normally setting dirty bits as usual
- copy active dirty bitmaps from source to target. This is safe
  as VM on source is not running
- "OR" copied bitmaps with ones running on target
- finish migration process (stop source VM).

Downtime will not be increased due to dirty bitmaps with this
approach, migration process is very simple - plain data copy.

Regards,
   Den


I was actually just discussing the live migration approach a little
bit
ago with Stefan, trying to decide on the "right" packet format (The
only
two patches I haven't ACKed yet are ones in which we need to choose a
send size) and we decided that 1KiB chunk sends would be
appropriate for
live migration.

I think I'm okay with that method, but obviously this approach
outlined
here would also work very well and would avoid meta bitmaps, chunk
sizes, migration tuning, convergence questions, etc etc etc.

You'd need to add a new status to the bitmap on the target (maybe
"INCOMPLETE" or "MIGRATING") that prevents it from being used for a
backup operation without preventing it from recording new writes.

My only concern is how easy it will be to work this into the migration
workflow.

It would require some sort of "post-migration" ternary phase, I
suppose,
for devices/data that can be transferred after the VM starts -- and I
suspect we'll be the only use of that phase for now.

David, what are your thoughts, here? Would you prefer Vladimir and I
push forward on the live migration approach, or add a new post-hoc
phase? This approach might be simpler on the block layer, but I
would be
rather upset if he scrapped his entire series for the second time for
another approach that also didn't get accepted.

--js

hmmm It looks like we should proceed with this to fit 2.4 dates.
There is not much interest at the moment. I think that we could
implement this later in 2.5 etc...

Regards,
  Den

oops. I have written something strange. Anyway, I think that for
now we should proceed with this patchset to fit QEMU 2.4 dates.
The implementation with additional stage (my proposal) could be
added later, f.e. in 2.5 as I do not see much interest from migration
gurus.

In this case the review will take a ... lot of time.

Regards,
  Den


That sounds good to me. I think this solution is workable for 2.4, and
we can begin working on a post-migration phase for the future to help
simplify our cases a lot.

I have been out sick much of this week, so apologies in my lack of
fervor getting this series upstream recently.

--js

no prob :)

Had a chat with Stefan about this approach and apparently that's what
the postcopy migration patches on-list are all about.

Stefan brought up the point of post-hoc reliability: It's possible to
transfer control to the new VM and then lose your link, making migration
completion impossible. Adding a post-copy phase to our existing live
migration is a non-starter, because it introduces unfairly this
unreliability to the existing system.

However, we can make this idea work for migrations started via the
post-copy mechanism, because the entire migration already carries that
known risk of completion failure.

It seems like the likely outcome though is that migrations will be able
to be completed with either mechanism in the future: either up-front
migration or post-copy migration. In that light, it seems we won't be
able to fully rid ourselves of the meta_bitmap idea, making the
post-copy idea here not too useful in culling our complexity, since
we'll have to support the current standard live migration anyway.

So I have reviewed the current set of patches under the assumption that
it seems like the right way to 

Re: [Qemu-devel] [PATCH v4 4/8] bcm2835_peripherals: add rollup device for bcm2835 peripherals

2016-01-26 Thread Peter Crosthwaite
On Mon, Jan 25, 2016 at 10:23 PM, Andrew Baumann
 wrote:
>> From: Peter Crosthwaite [mailto:crosthwaitepe...@gmail.com]
>> Sent: Monday, 25 January 2016 22:14
>>
>> On Fri, Jan 15, 2016 at 3:58 PM, Andrew Baumann
>>  wrote:
> [...]
>> > +static void bcm2835_peripherals_init(Object *obj)
>> > +{
>> > +BCM2835PeripheralState *s = BCM2835_PERIPHERALS(obj);
>> > +
>> > +/* Memory region for peripheral devices, which we export to our
>> parent */
>> > +memory_region_init_io(>peri_mr, obj, NULL, s, "bcm2835-
>> peripherals",
>> > +  0x100);
>>
>> Should this just be normal memory_region_init?
>
> I think so -- it's just a container region, and I probably copy and pasted 
> the API here. The two MR init APIs seem almost but not-quite identical when 
> NULL callbacks are used. Can you briefly explain the difference?
>

hmm I guess the defaulting to _mem_ops. memory_region_init
looks to assume you will populate the usable subregions. Are you
relying on unassigned ops?

>> > +object_property_add_child(obj, "peripheral-io", OBJECT(>peri_mr),
>> NULL);
>>
>> This seems like a weird parenting, to have the SoC as child to an
>> object it just created. Is the problem you need a parent before others
>> can parent to you?
>
> I'm confused by this question: Unless I'm mistaken, the parent here is 
> BCM2835PeripheralState, the child is the new memory region we just called 
> init on.
>

My bad - I have it backwards.

Regards,
Peter

> Thanks,
> Andrew



Re: [Qemu-devel] [RFC PATCH 2/4] configure: introduce --extra-libs

2016-01-26 Thread Alex Bennée

Paolo Bonzini  writes:

> On 25/01/2016 19:15, Alex Bennée wrote:
>>
>> Paolo Bonzini  writes:
>>
>>> On 25/01/2016 17:49, Alex Bennée wrote:
 If for example you want to use the thread sanitizer you want to ensure all
 binaries are linked with the library:

   ./configure ${TARGETS} --cc=gcc-5 --cxx=g++-5 \
 --extra-cflags="-fsanitize=thread" --extra-libs="-ltsan"
>>>
>>> Shouldn't -fsanitize=thread work as a linker command line flag too?
>>
>> No, the sanitizers are compile time options as they instrument the
>> generated code. It's just in the case of the ThreadSanitizer you also
>> need the support library.
>
> That's certainly not the case.  My system has at least a libubsan,
> libasan and liblsan (in addition to libtsan), and "gcc -dumpspecs"
> suggests that the -fsanitize options are also valid at link time:
>
>%{%:sanitize(address):%{!shared:libasan_preinit%O%s} 
> %{static-libasan:%{!shared:-Bstatic --whole-archive -lasan --no-whole-archive 
> -Bdynamic}}%{!static-libasan:-lasan}}
>%{%:sanitize(thread):%{static-libtsan:%{!shared:-Bstatic --whole-archive 
> -ltsan --no-whole-archive -Bdynamic}}%{!static-libtsan:-ltsan}}
>%{%:sanitize(leak):%{static-liblsan:%{!shared:-Bstatic --whole-archive 
> -llsan --no-whole-archive -Bdynamic}}%{!static-liblsan:-llsan}}
>
> (GCC specs are what they are, but you get the idea).

Hmm odd. I ran the undefined and address sanitizers without having to
mess with the ldflags. I'll have a deeper dive into the docs to see
whats going on.

>
> Paolo


--
Alex Bennée



Re: [Qemu-devel] [PATCH] net: set endianness on all backend devices

2016-01-26 Thread Greg Kurz
On Tue, 26 Jan 2016 11:53:21 +0100
Laurent Vivier  wrote:

> On 22/01/2016 07:44, Jason Wang wrote:
> > 
> > 
> > On 01/21/2016 04:42 PM, Laurent Vivier wrote:  
> >> ping
> >>
> >> [added Jason in cc:]
> >>
> >> On 13/01/2016 20:26, Laurent Vivier wrote:  
> >>> commit 5be7d9f1b1452613b95c6ba70b8d7ad3d0797991
> >>>vhost-net: tell tap backend about the vnet endianness
> >>>
> >>> makes vhost net to set the endianness of the device, but only for
> >>> the first device.
> >>>
> >>> In case of multiqueue, we have multiple devices... This patch sets the
> >>> endianness for all the devices of the interface.
> >>>
> >>> Signed-off-by: Laurent Vivier 
> >>> ---
> >>>  hw/net/vhost_net.c | 23 +++
> >>>  1 file changed, 11 insertions(+), 12 deletions(-)
> >>>
> >>> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> >>> index 318c3e6..10e233a 100644
> >>> --- a/hw/net/vhost_net.c
> >>> +++ b/hw/net/vhost_net.c
> >>> @@ -300,21 +300,19 @@ int vhost_net_start(VirtIODevice *dev, 
> >>> NetClientState *ncs,
> >>>  BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
> >>>  VirtioBusState *vbus = VIRTIO_BUS(qbus);
> >>>  VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
> >>> -int r, e, i;
> >>> +int r, e, i, j;
> >>>  
> >>>  if (!k->set_guest_notifiers) {
> >>>  error_report("binding does not support guest notifiers");
> >>> -r = -ENOSYS;
> >>> -goto err;
> >>> +return -ENOSYS;
> >>>  }
> >>>  
> >>> -r = vhost_net_set_vnet_endian(dev, ncs[0].peer, true);
> >>> -if (r < 0) {
> >>> -goto err;
> >>> -}
> >>> -
> >>> -for (i = 0; i < total_queues; i++) {
> >>> -vhost_net_set_vq_index(get_vhost_net(ncs[i].peer), i * 2);
> >>> +for (j = 0; j < total_queues; j++) {
> >>> +r = vhost_net_set_vnet_endian(dev, ncs[j].peer, true);
> >>> +if (r < 0) {
> >>> +goto err_endian;
> >>> +}
> >>> +vhost_net_set_vq_index(get_vhost_net(ncs[j].peer), j * 2);
> >>>  }
> >>>  
> >>>  r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
> >>> @@ -343,8 +341,9 @@ err_start:
> >>>  fflush(stderr);
> >>>  }
> >>>  err_endian:
> >>> -vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
> >>> -err:
> >>> +while (--j >= 0) {
> >>> +vhost_net_set_vnet_endian(dev, ncs[j].peer, false);
> >>> +}
> >>>  return r;
> >>>  }
> >>>
> > 
> > Reviewed-by: Jason Wang   
> 
> Thanks Jason.
> 
> Who can pick this in his tree ?
> 

According to MAINTAINERS, this must go through Michael's tree, but it
looks like he is very busy reworking memory barriers in the kernel...

> Laurent
> 

--
Greg




[Qemu-devel] [PATCH] MAINTAINERS: Add section for FPU emulation

2016-01-26 Thread Peter Maydell
Add an entry to the MAINTAINERS file for our softfloat FPU
emulation code. This code is only 'odd fixes' but it's useful to
record who to cc on patches to it.

Signed-off-by: Peter Maydell 
---
Would anybody else like to be listed here (ie to be cc'd on softfloat
patches) ? Richard? Aurelien?


 MAINTAINERS | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index b6ed87a..65786e6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -79,6 +79,12 @@ F: include/exec/exec-all.h
 F: include/exec/helper*.h
 F: include/exec/tb-hash.h
 
+FPU emulation
+M: Peter Maydell 
+S: Odd Fixes
+F: fpu/
+F: include/fpu/
+
 Alpha
 M: Richard Henderson 
 S: Maintained
-- 
1.9.1




Re: [Qemu-devel] [RFC 0/10] Support Receive-Segment-Offload(RSC) for WHQL test of Window guest

2016-01-26 Thread Wei Xu



On 01/26/2016 02:44 PM, Fam Zheng wrote:

On Tue, 01/26 06:24, w...@redhat.com wrote:

Wei Xu (10):
   'Segment', 'Chain' and 'Status' enumeration.
   Initilize & Cleanup.
   Chain lookup and packets caching.
   Tcp general data coalescing
   The draining timer
   IPv4 checksum.
   TCP control packet handling
   Sanity check & More bypass cases check.
   IPv6 support.
   Statistics.

Please add subsystem prefixes to subjects, like:

   "virtio-net: IPv6 support"
   "virtio-net: Statistics"

This applies to the cover letter too.

(nit-pick: period "." is not necessary)

Thanks Fam.

Wei


Fam






[Qemu-devel] [PATCH v4 01/10] qom: add helpers for UserCreatable object types

2016-01-26 Thread Daniel P. Berrange
The QMP monitor code has two helper methods object_add
and qmp_object_del that are called from several places
in the code (QMP, HMP and main emulator startup).

The HMP and main emulator startup code also share
further logic that extracts the qom-type & id
values from a qdict.

We soon need to use this logic from qemu-img, qemu-io
and qemu-nbd too, but don't want those to depend on
the monitor, nor do we want to duplicate the code.

To avoid this, move some code out of qmp.c and hmp.c
adding 3 new methods to qom/object_interfaces.c

 - user_creatable_add - takes a QDict holding a full
   object definition & instantiates it
 - user_creatable_add_type - takes an ID, type name,
   and QDict holding object properties & instantiates
   it
 - user_creatable_del - takes an ID and deletes the
   corresponding object

The existing code is updated to use these new methods.

Signed-off-by: Daniel P. Berrange 
---
 hmp.c   |  52 ---
 include/monitor/monitor.h   |   3 -
 include/qom/object_interfaces.h |  48 ++
 qmp.c   |  76 ++
 qom/object_interfaces.c | 139 
 vl.c|  48 --
 6 files changed, 216 insertions(+), 150 deletions(-)

diff --git a/hmp.c b/hmp.c
index 54f2620..95930b0 100644
--- a/hmp.c
+++ b/hmp.c
@@ -29,6 +29,7 @@
 #include "qapi/string-output-visitor.h"
 #include "qapi/util.h"
 #include "qapi-visit.h"
+#include "qom/object_interfaces.h"
 #include "ui/console.h"
 #include "block/qapi.h"
 #include "qemu-io.h"
@@ -1652,58 +1653,27 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)
 void hmp_object_add(Monitor *mon, const QDict *qdict)
 {
 Error *err = NULL;
-Error *err_end = NULL;
 QemuOpts *opts;
-char *type = NULL;
-char *id = NULL;
-void *dummy = NULL;
 OptsVisitor *ov;
-QDict *pdict;
+Object *obj = NULL;
 
 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, );
 if (err) {
-goto out;
+hmp_handle_error(mon, );
+return;
 }
 
 ov = opts_visitor_new(opts);
-pdict = qdict_clone_shallow(qdict);
-
-visit_start_struct(opts_get_visitor(ov), , NULL, NULL, 0, );
-if (err) {
-goto out_clean;
-}
-
-qdict_del(pdict, "qom-type");
-visit_type_str(opts_get_visitor(ov), , "qom-type", );
-if (err) {
-goto out_end;
-}
+obj = user_creatable_add(qdict, opts_get_visitor(ov), );
+opts_visitor_cleanup(ov);
+qemu_opts_del(opts);
 
-qdict_del(pdict, "id");
-visit_type_str(opts_get_visitor(ov), , "id", );
 if (err) {
-goto out_end;
+hmp_handle_error(mon, );
 }
-
-object_add(type, id, pdict, opts_get_visitor(ov), );
-
-out_end:
-visit_end_struct(opts_get_visitor(ov), _end);
-if (!err && err_end) {
-qmp_object_del(id, NULL);
+if (obj) {
+object_unref(obj);
 }
-error_propagate(, err_end);
-out_clean:
-opts_visitor_cleanup(ov);
-
-QDECREF(pdict);
-qemu_opts_del(opts);
-g_free(id);
-g_free(type);
-g_free(dummy);
-
-out:
-hmp_handle_error(mon, );
 }
 
 void hmp_getfd(Monitor *mon, const QDict *qdict)
@@ -1933,7 +1903,7 @@ void hmp_object_del(Monitor *mon, const QDict *qdict)
 const char *id = qdict_get_str(qdict, "id");
 Error *err = NULL;
 
-qmp_object_del(id, );
+user_creatable_del(id, );
 hmp_handle_error(mon, );
 }
 
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 91b95ae..aa0f373 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -43,9 +43,6 @@ void monitor_read_command(Monitor *mon, int show_prompt);
 int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
   void *opaque);
 
-void object_add(const char *type, const char *id, const QDict *qdict,
-Visitor *v, Error **errp);
-
 AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
 bool has_opaque, const char *opaque,
 Error **errp);
diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
index 283ae0d..7bbaf2f 100644
--- a/include/qom/object_interfaces.h
+++ b/include/qom/object_interfaces.h
@@ -2,6 +2,8 @@
 #define OBJECT_INTERFACES_H
 
 #include "qom/object.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/visitor.h"
 
 #define TYPE_USER_CREATABLE "user-creatable"
 
@@ -72,4 +74,50 @@ void user_creatable_complete(Object *obj, Error **errp);
  * from implements USER_CREATABLE interface.
  */
 bool user_creatable_can_be_deleted(UserCreatable *uc, Error **errp);
+
+/**
+ * user_creatable_add:
+ * @qdict: the object definition
+ * @v: the visitor
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Create an instance of the user creatable object whose type,
+ * is defined in @qdict by the 

[Qemu-devel] [PATCH v4 00/10] Make qemu-img/qemu-nbd/qemu-io CLI more flexible

2016-01-26 Thread Daniel P. Berrange
This series of patches expands the syntax of the qemu-img,
qemu-nbd and qemu-io commands to make them more flexible.

  v0: https://lists.gnu.org/archive/html/qemu-devel/2015-10/msg04365.html
  v1: https://lists.gnu.org/archive/html/qemu-devel/2015-12/msg04014.html
  v2: https://lists.gnu.org/archive/html/qemu-devel/2015-12/msg04354.html
  v3: https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg03381.html

First all three gain a --object parameter, which allows
instantiation of user creatable object types. The immediate
use case is to allow for creation of the 'secret' object
type to pass passwords for curl, iscsi and rbd drivers.
For qemu-nbd this will also be needed to create TLS
certificates for encryption support.

Then all three gain a '--image-opts' parameter which causes
the positional filenames to be interepreted as option strings
rather tha nplain filenames. This avoids the need to use the
JSON syntax, or to add custom CLI args for each block backend
option that exists. The immediate use case is to allow the
user to specify the ID of the 'secret' object they just created.

Finally, there are a few small cleanup patches

The first 4 patches in this series are a pre-requisite for
3 other series

 - Support for TLS in NBD
 - Support for secrets for passwd auth in curl, rbd, iscsi
   (fixes a CVE issue in libvirt)
 - Support for LUKS encryption passwords

Hopefully the --object patches are fairly uncontroversial
and can be merged soon. The latter patches for --image-opts
are very nice to have, but not a hard blocker right now
since the 'json:{}' syntax can be used until they are
merged.

Changed in v4:

 - Fix error reporting when object_create fails

Changed in v3:

 - Rebase to resolve with conflicts against recently
   merged code
 - Remove use of errx()

Changed in v2:

 - Share more common code in qom/object_interfaces.c to
   avoid duplicating so much of 'object_create' in each
   command
 - Remove previously added '--source optstring' parameter
   which replaced the positional filenames, in favour of
   keeping the positional filenames but using a --image-opts
   boolean arg to change their interpretation
 - Added docs for --image-opts to qemu-img man page
 - Use printf instead of echo -n in examples
 - Line wrap help string based on user terminal width not
   source code width
 - Update qemu-nbd/qemu-io to use constants for options
 - Update qemu-nbd to avoid overlapping option values



Daniel P. Berrange (10):
  qom: add helpers for UserCreatable object types
  qemu-img: add support for --object command line arg
  qemu-nbd: add support for --object command line arg
  qemu-io: add support for --object command line arg
  qemu-io: allow specifying image as a set of options args
  qemu-nbd: allow specifying image as a set of options args
  qemu-img: allow specifying image as a set of options args
  qemu-nbd: don't overlap long option values with short options
  qemu-nbd: use no_argument/required_argument constants
  qemu-io: use no_argument/required_argument constants

 hmp.c   |  52 +---
 include/monitor/monitor.h   |   3 -
 include/qom/object_interfaces.h |  48 
 qemu-img-cmds.hx|  44 +--
 qemu-img.c  | 588 +---
 qemu-img.texi   |  14 +
 qemu-io.c   | 114 +++-
 qemu-nbd.c  | 150 --
 qemu-nbd.texi   |   6 +
 qmp.c   |  76 +-
 qom/object_interfaces.c | 139 ++
 vl.c|  48 +---
 12 files changed, 1029 insertions(+), 253 deletions(-)

-- 
2.5.0




[Qemu-devel] [PATCH v4 03/10] qemu-nbd: add support for --object command line arg

2016-01-26 Thread Daniel P. Berrange
Allow creation of user creatable object types with qemu-nbd
via a new --object command line arg. This will be used to supply
passwords and/or encryption keys to the various block driver
backends via the recently added 'secret' object type.

 # printf letmein > mypasswd.txt
 # qemu-nbd --object secret,id=sec0,file=mypasswd.txt \
  ...other nbd args...

Signed-off-by: Daniel P. Berrange 
---
 qemu-nbd.c| 54 ++
 qemu-nbd.texi |  6 ++
 2 files changed, 60 insertions(+)

diff --git a/qemu-nbd.c b/qemu-nbd.c
index ede4a54..8e5d36c 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -23,9 +23,12 @@
 #include "qemu/main-loop.h"
 #include "qemu/sockets.h"
 #include "qemu/error-report.h"
+#include "qemu/config-file.h"
 #include "block/snapshot.h"
 #include "qapi/util.h"
 #include "qapi/qmp/qstring.h"
+#include "qapi/opts-visitor.h"
+#include "qom/object_interfaces.h"
 
 #include 
 #include 
@@ -44,6 +47,7 @@
 #define QEMU_NBD_OPT_AIO   2
 #define QEMU_NBD_OPT_DISCARD   3
 #define QEMU_NBD_OPT_DETECT_ZEROES 4
+#define QEMU_NBD_OPT_OBJECT5
 
 static NBDExport *exp;
 static int verbose;
@@ -77,6 +81,9 @@ static void usage(const char *name)
 "  -o, --offset=OFFSET   offset into the image\n"
 "  -P, --partition=NUM   only expose partition NUM\n"
 "\n"
+"General purpose options:\n"
+"  --object type,id=ID,...   define an object such as 'secret' for providing\n"
+"passwords and/or encryption keys\n"
 #ifdef __linux__
 "Kernel NBD client support:\n"
 "  -c, --connect=DEV connect FILE to the local NBD device DEV\n"
@@ -374,6 +381,35 @@ static SocketAddress *nbd_build_socket_address(const char 
*sockpath,
 }
 
 
+static QemuOptsList qemu_object_opts = {
+.name = "object",
+.implied_opt_name = "qom-type",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
+.desc = {
+{ }
+},
+};
+
+static int object_create(void *opaque, QemuOpts *opts, Error **errp)
+{
+Error *err = NULL;
+OptsVisitor *ov;
+QDict *pdict;
+
+ov = opts_visitor_new(opts);
+pdict = qemu_opts_to_qdict(opts, NULL);
+
+user_creatable_add(pdict, opts_get_visitor(ov), );
+opts_visitor_cleanup(ov);
+QDECREF(pdict);
+
+if (err) {
+error_propagate(errp, err);
+return -1;
+}
+return 0;
+}
+
 int main(int argc, char **argv)
 {
 BlockBackend *blk;
@@ -411,6 +447,7 @@ int main(int argc, char **argv)
 { "format", 1, NULL, 'f' },
 { "persistent", 0, NULL, 't' },
 { "verbose", 0, NULL, 'v' },
+{ "object", 1, NULL, QEMU_NBD_OPT_OBJECT },
 { NULL, 0, NULL, 0 }
 };
 int ch;
@@ -428,6 +465,7 @@ int main(int argc, char **argv)
 Error *local_err = NULL;
 BlockdevDetectZeroesOptions detect_zeroes = 
BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF;
 QDict *options = NULL;
+QemuOpts *opts;
 
 /* The client thread uses SIGTERM to interrupt the server.  A signal
  * handler ensures that "qemu-nbd -v -c" exits with a nice status code.
@@ -436,6 +474,8 @@ int main(int argc, char **argv)
 memset(_sigterm, 0, sizeof(sa_sigterm));
 sa_sigterm.sa_handler = termsig_handler;
 sigaction(SIGTERM, _sigterm, NULL);
+module_call_init(MODULE_INIT_QOM);
+qemu_add_opts(_object_opts);
 qemu_init_exec_dir(argv[0]);
 
 while ((ch = getopt_long(argc, argv, sopt, lopt, _ind)) != -1) {
@@ -588,6 +628,13 @@ int main(int argc, char **argv)
 usage(argv[0]);
 exit(0);
 break;
+case QEMU_NBD_OPT_OBJECT:
+opts = qemu_opts_parse_noisily(qemu_find_opts("object"),
+   optarg, true);
+if (!opts) {
+exit(1);
+}
+break;
 case '?':
 error_report("Try `%s --help' for more information.", argv[0]);
 exit(EXIT_FAILURE);
@@ -600,6 +647,13 @@ int main(int argc, char **argv)
 exit(EXIT_FAILURE);
 }
 
+if (qemu_opts_foreach(qemu_find_opts("object"),
+  object_create,
+  NULL, _err)) {
+error_report_err(local_err);
+exit(1);
+}
+
 if (disconnect) {
 fd = open(argv[optind], O_RDWR);
 if (fd < 0) {
diff --git a/qemu-nbd.texi b/qemu-nbd.texi
index 46fd483..9f9daca 100644
--- a/qemu-nbd.texi
+++ b/qemu-nbd.texi
@@ -14,6 +14,12 @@ Export QEMU disk image using NBD protocol.
 @table @option
 @item @var{filename}
  is a disk image filename
+@item --object type,id=@var{id},...props...
+  define a new instance of the @var{type} object class identified by @var{id}.
+  See the @code{qemu(1)} manual page for full details of the properties
+  supported. The common object type that it makes sense to define is the
+  @code{secret} object, which is used to supply passwords and/or encryption
+  keys.
 @item -p, --port=@var{port}
   port to listen on 

[Qemu-devel] [PATCH v4 02/10] qemu-img: add support for --object command line arg

2016-01-26 Thread Daniel P. Berrange
Allow creation of user creatable object types with qemu-img
via a new --object command line arg. This will be used to supply
passwords and/or encryption keys to the various block driver
backends via the recently added 'secret' object type.

 # printf letmein > mypasswd.txt
 # qemu-img info --object secret,id=sec0,file=mypasswd.txt \
  ...other info args...

Signed-off-by: Daniel P. Berrange 
---
 qemu-img-cmds.hx |  44 -
 qemu-img.c   | 284 +--
 qemu-img.texi|   8 ++
 3 files changed, 306 insertions(+), 30 deletions(-)

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index 9567774..5bb1de7 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -10,68 +10,68 @@ STEXI
 ETEXI
 
 DEF("check", img_check,
-"check [-q] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] 
filename")
+"check [-q] [--object objectdef] [-f fmt] [--output=ofmt] [-r [leaks | 
all]] [-T src_cache] filename")
 STEXI
-@item check [-q] [-f @var{fmt}] [--output=@var{ofmt}] [-r [leaks | all]] [-T 
@var{src_cache}] @var{filename}
+@item check [--object objectdef] [-q] [-f @var{fmt}] [--output=@var{ofmt}] [-r 
[leaks | all]] [-T @var{src_cache}] @var{filename}
 ETEXI
 
 DEF("create", img_create,
-"create [-q] [-f fmt] [-o options] filename [size]")
+"create [-q] [--object objectdef] [-f fmt] [-o options] filename [size]")
 STEXI
-@item create [-q] [-f @var{fmt}] [-o @var{options}] @var{filename} [@var{size}]
+@item create [--object objectdef] [-q] [-f @var{fmt}] [-o @var{options}] 
@var{filename} [@var{size}]
 ETEXI
 
 DEF("commit", img_commit,
-"commit [-q] [-f fmt] [-t cache] [-b base] [-d] [-p] filename")
+"commit [-q] [--object objectdef] [-f fmt] [-t cache] [-b base] [-d] [-p] 
filename")
 STEXI
-@item commit [-q] [-f @var{fmt}] [-t @var{cache}] [-b @var{base}] [-d] [-p] 
@var{filename}
+@item commit [--object objectdef] [-q] [-f @var{fmt}] [-t @var{cache}] [-b 
@var{base}] [-d] [-p] @var{filename}
 ETEXI
 
 DEF("compare", img_compare,
-"compare [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] filename1 
filename2")
+"compare [--object objectdef] [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] 
[-s] filename1 filename2")
 STEXI
-@item compare [-f @var{fmt}] [-F @var{fmt}] [-T @var{src_cache}] [-p] [-q] 
[-s] @var{filename1} @var{filename2}
+@item compare [--object objectdef] [-f @var{fmt}] [-F @var{fmt}] [-T 
@var{src_cache}] [-p] [-q] [-s] @var{filename1} @var{filename2}
 ETEXI
 
 DEF("convert", img_convert,
-"convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O 
output_fmt] [-o options] [-s snapshot_id_or_name] [-l snapshot_param] [-S 
sparse_size] filename [filename2 [...]] output_filename")
+"convert [--object objectdef] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T 
src_cache] [-O output_fmt] [-o options] [-s snapshot_id_or_name] [-l 
snapshot_param] [-S sparse_size] filename [filename2 [...]] output_filename")
 STEXI
-@item convert [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T 
@var{src_cache}] [-O @var{output_fmt}] [-o @var{options}] [-s 
@var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] 
@var{filename} [@var{filename2} [...]] @var{output_filename}
+@item convert [--object objectdef] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t 
@var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-o @var{options}] [-s 
@var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] 
@var{filename} [@var{filename2} [...]] @var{output_filename}
 ETEXI
 
 DEF("info", img_info,
-"info [-f fmt] [--output=ofmt] [--backing-chain] filename")
+"info [--object objectdef] [-f fmt] [--output=ofmt] [--backing-chain] 
filename")
 STEXI
-@item info [-f @var{fmt}] [--output=@var{ofmt}] [--backing-chain] 
@var{filename}
+@item info [--object objectdef] [-f @var{fmt}] [--output=@var{ofmt}] 
[--backing-chain] @var{filename}
 ETEXI
 
 DEF("map", img_map,
-"map [-f fmt] [--output=ofmt] filename")
+"map [--object objectdef] [-f fmt] [--output=ofmt] filename")
 STEXI
-@item map [-f @var{fmt}] [--output=@var{ofmt}] @var{filename}
+@item map [--object objectdef] [-f @var{fmt}] [--output=@var{ofmt}] 
@var{filename}
 ETEXI
 
 DEF("snapshot", img_snapshot,
-"snapshot [-q] [-l | -a snapshot | -c snapshot | -d snapshot] filename")
+"snapshot [--object objectdef] [-q] [-l | -a snapshot | -c snapshot | -d 
snapshot] filename")
 STEXI
-@item snapshot [-q] [-l | -a @var{snapshot} | -c @var{snapshot} | -d 
@var{snapshot}] @var{filename}
+@item snapshot [--object objectdef] [-q] [-l | -a @var{snapshot} | -c 
@var{snapshot} | -d @var{snapshot}] @var{filename}
 ETEXI
 
 DEF("rebase", img_rebase,
-"rebase [-q] [-f fmt] [-t cache] [-T src_cache] [-p] [-u] -b backing_file 
[-F backing_fmt] filename")
+"rebase [--object objectdef] [-q] [-f fmt] [-t cache] [-T src_cache] [-p] 
[-u] -b backing_file [-F backing_fmt] filename")
 STEXI
-@item rebase [-q] [-f @var{fmt}] 

[Qemu-devel] [PATCH v4 04/10] qemu-io: add support for --object command line arg

2016-01-26 Thread Daniel P. Berrange
Allow creation of user creatable object types with qemu-io
via a new --object command line arg. This will be used to supply
passwords and/or encryption keys to the various block driver
backends via the recently added 'secret' object type.

 # printf letmein > mypasswd.txt
 # qemu-io --object secret,id=sec0,file=mypasswd.txt \
  ...other args...

Signed-off-by: Daniel P. Berrange 
---
 qemu-io.c | 54 ++
 1 file changed, 54 insertions(+)

diff --git a/qemu-io.c b/qemu-io.c
index d593f19..d1432ea 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -18,6 +18,8 @@
 #include "qemu/config-file.h"
 #include "qemu/readline.h"
 #include "qapi/qmp/qstring.h"
+#include "qapi/opts-visitor.h"
+#include "qom/object_interfaces.h"
 #include "sysemu/block-backend.h"
 #include "block/block_int.h"
 #include "trace/control.h"
@@ -200,6 +202,8 @@ static void usage(const char *name)
 "Usage: %s [-h] [-V] [-rsnm] [-f FMT] [-c STRING] ... [file]\n"
 "QEMU Disk exerciser\n"
 "\n"
+"  --object OBJECTDEF   define an object such as 'secret' for\n"
+"   passwords and/or encryption keys\n"
 "  -c, --cmd STRING execute command with its arguments\n"
 "   from the given string\n"
 "  -f, --format FMT specifies the block driver to use\n"
@@ -361,6 +365,38 @@ static void reenable_tty_echo(void)
 qemu_set_tty_echo(STDIN_FILENO, true);
 }
 
+enum {
+OPTION_OBJECT = 256,
+};
+
+static QemuOptsList qemu_object_opts = {
+.name = "object",
+.implied_opt_name = "qom-type",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
+.desc = {
+{ }
+},
+};
+
+static int object_create(void *opaque, QemuOpts *opts, Error **errp)
+{
+Error *err = NULL;
+OptsVisitor *ov;
+QDict *pdict;
+
+ov = opts_visitor_new(opts);
+pdict = qemu_opts_to_qdict(opts, NULL);
+
+user_creatable_add(pdict, opts_get_visitor(ov), );
+opts_visitor_cleanup(ov);
+QDECREF(pdict);
+if (err) {
+error_propagate(errp, err);
+return -1;
+}
+return 0;
+}
+
 int main(int argc, char **argv)
 {
 int readonly = 0;
@@ -379,6 +415,7 @@ int main(int argc, char **argv)
 { "discard", 1, NULL, 'd' },
 { "cache", 1, NULL, 't' },
 { "trace", 1, NULL, 'T' },
+{ "object", 1, NULL, OPTION_OBJECT },
 { NULL, 0, NULL, 0 }
 };
 int c;
@@ -386,6 +423,7 @@ int main(int argc, char **argv)
 int flags = BDRV_O_UNMAP;
 Error *local_error = NULL;
 QDict *opts = NULL;
+QemuOpts *qopts = NULL;
 
 #ifdef CONFIG_POSIX
 signal(SIGPIPE, SIG_IGN);
@@ -394,6 +432,8 @@ int main(int argc, char **argv)
 progname = basename(argv[0]);
 qemu_init_exec_dir(argv[0]);
 
+module_call_init(MODULE_INIT_QOM);
+qemu_add_opts(_object_opts);
 bdrv_init();
 
 while ((c = getopt_long(argc, argv, sopt, lopt, _index)) != -1) {
@@ -445,6 +485,13 @@ int main(int argc, char **argv)
 case 'h':
 usage(progname);
 exit(0);
+case OPTION_OBJECT:
+qopts = qemu_opts_parse_noisily(qemu_find_opts("object"),
+optarg, true);
+if (!qopts) {
+exit(1);
+}
+break;
 default:
 usage(progname);
 exit(1);
@@ -461,6 +508,13 @@ int main(int argc, char **argv)
 exit(1);
 }
 
+if (qemu_opts_foreach(qemu_find_opts("object"),
+  object_create,
+  NULL, _error)) {
+error_report_err(local_error);
+exit(1);
+}
+
 /* initialize commands */
 qemuio_add_command(_cmd);
 qemuio_add_command(_cmd);
-- 
2.5.0




[Qemu-devel] [PATCH v4 10/10] qemu-io: use no_argument/required_argument constants

2016-01-26 Thread Daniel P. Berrange
When declaring the 'struct option' array, use the standard
constants no_argument/required_argument, instead of magic
values 0 and 1.

Reviewed-by: Eric Blake 
Signed-off-by: Daniel P. Berrange 
---
 qemu-io.c | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/qemu-io.c b/qemu-io.c
index 51d8272..0f759bb 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -413,21 +413,21 @@ int main(int argc, char **argv)
 int readonly = 0;
 const char *sopt = "hVc:d:f:rsnmgkt:T:";
 const struct option lopt[] = {
-{ "help", 0, NULL, 'h' },
-{ "version", 0, NULL, 'V' },
-{ "offset", 1, NULL, 'o' },
-{ "cmd", 1, NULL, 'c' },
-{ "format", 1, NULL, 'f' },
-{ "read-only", 0, NULL, 'r' },
-{ "snapshot", 0, NULL, 's' },
-{ "nocache", 0, NULL, 'n' },
-{ "misalign", 0, NULL, 'm' },
-{ "native-aio", 0, NULL, 'k' },
-{ "discard", 1, NULL, 'd' },
-{ "cache", 1, NULL, 't' },
-{ "trace", 1, NULL, 'T' },
-{ "object", 1, NULL, OPTION_OBJECT },
-{ "image-opts", 0, NULL, OPTION_IMAGE_OPTS },
+{ "help", no_argument, NULL, 'h' },
+{ "version", no_argument, NULL, 'V' },
+{ "offset", required_argument, NULL, 'o' },
+{ "cmd", required_argument, NULL, 'c' },
+{ "format", required_argument, NULL, 'f' },
+{ "read-only", no_argument, NULL, 'r' },
+{ "snapshot", no_argument, NULL, 's' },
+{ "nocache", no_argument, NULL, 'n' },
+{ "misalign", no_argument, NULL, 'm' },
+{ "native-aio", no_argument, NULL, 'k' },
+{ "discard", required_argument, NULL, 'd' },
+{ "cache", required_argument, NULL, 't' },
+{ "trace", required_argument, NULL, 'T' },
+{ "object", required_argument, NULL, OPTION_OBJECT },
+{ "image-opts", no_argument, NULL, OPTION_IMAGE_OPTS },
 { NULL, 0, NULL, 0 }
 };
 int c;
-- 
2.5.0




[Qemu-devel] [PATCH v4 06/10] qemu-nbd: allow specifying image as a set of options args

2016-01-26 Thread Daniel P. Berrange
Currently qemu-nbd allows an image filename to be passed on the
command line, but unless using the JSON format, it does not have
a way to set any options except the format eg

   qemu-nbd https://127.0.0.1/images/centos7.iso
   qemu-nbd /home/berrange/demo.qcow2

This adds a --image-opts arg that indicates that the positional
filename should be interpreted as a full option string, not
just a filename.

   qemu-nbd --image-opts driver=http,url=https://127.0.0.1/images,sslverify=off
   qemu-nbd --image-opts file=/home/berrange/demo.qcow2

This flag is mutually exclusive with the '-f' flag.

Signed-off-by: Daniel P. Berrange 
---
 qemu-nbd.c | 45 -
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git a/qemu-nbd.c b/qemu-nbd.c
index 8e5d36c..764698f 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -48,6 +48,7 @@
 #define QEMU_NBD_OPT_DISCARD   3
 #define QEMU_NBD_OPT_DETECT_ZEROES 4
 #define QEMU_NBD_OPT_OBJECT5
+#define QEMU_NBD_OPT_IMAGE_OPTS6
 
 static NBDExport *exp;
 static int verbose;
@@ -381,6 +382,16 @@ static SocketAddress *nbd_build_socket_address(const char 
*sockpath,
 }
 
 
+static QemuOptsList file_opts = {
+.name = "file",
+.implied_opt_name = "file",
+.head = QTAILQ_HEAD_INITIALIZER(file_opts.head),
+.desc = {
+/* no elements => accept any params */
+{ /* end of list */ }
+},
+};
+
 static QemuOptsList qemu_object_opts = {
 .name = "object",
 .implied_opt_name = "qom-type",
@@ -448,6 +459,7 @@ int main(int argc, char **argv)
 { "persistent", 0, NULL, 't' },
 { "verbose", 0, NULL, 'v' },
 { "object", 1, NULL, QEMU_NBD_OPT_OBJECT },
+{ "image-opts", 0, NULL, QEMU_NBD_OPT_IMAGE_OPTS },
 { NULL, 0, NULL, 0 }
 };
 int ch;
@@ -466,6 +478,7 @@ int main(int argc, char **argv)
 BlockdevDetectZeroesOptions detect_zeroes = 
BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF;
 QDict *options = NULL;
 QemuOpts *opts;
+bool imageOpts = false;
 
 /* The client thread uses SIGTERM to interrupt the server.  A signal
  * handler ensures that "qemu-nbd -v -c" exits with a nice status code.
@@ -635,6 +648,9 @@ int main(int argc, char **argv)
 exit(1);
 }
 break;
+case QEMU_NBD_OPT_IMAGE_OPTS:
+imageOpts = true;
+break;
 case '?':
 error_report("Try `%s --help' for more information.", argv[0]);
 exit(EXIT_FAILURE);
@@ -744,13 +760,32 @@ int main(int argc, char **argv)
 bdrv_init();
 atexit(bdrv_close_all);
 
-if (fmt) {
-options = qdict_new();
-qdict_put(options, "driver", qstring_from_str(fmt));
+srcpath = argv[optind];
+if (imageOpts) {
+char *file = NULL;
+if (fmt) {
+error_report("--image-opts and -f are mutually exclusive");
+exit(EXIT_FAILURE);
+}
+opts = qemu_opts_parse_noisily(_opts, srcpath, true);
+if (!opts) {
+qemu_opts_reset(_opts);
+exit(EXIT_FAILURE);
+}
+file = g_strdup(qemu_opt_get(opts, "file"));
+qemu_opt_unset(opts, "file");
+options = qemu_opts_to_qdict(opts, NULL);
+qemu_opts_reset(_opts);
+blk = blk_new_open("hda", file, NULL, options, flags, _err);
+g_free(file);
+} else {
+if (fmt) {
+options = qdict_new();
+qdict_put(options, "driver", qstring_from_str(fmt));
+}
+blk = blk_new_open("hda", srcpath, NULL, options, flags, _err);
 }
 
-srcpath = argv[optind];
-blk = blk_new_open("hda", srcpath, NULL, options, flags, _err);
 if (!blk) {
 error_reportf_err(local_err, "Failed to blk_new_open '%s': ",
   argv[optind]);
-- 
2.5.0




[Qemu-devel] [PATCH v4 05/10] qemu-io: allow specifying image as a set of options args

2016-01-26 Thread Daniel P. Berrange
Currently qemu-io allows an image filename to be passed on the
command line, but unless using the JSON format, it does not have
a way to set any options except the format eg

 qemu-io https://127.0.0.1/images/centos7.iso
 qemu-io /home/berrange/demo.qcow2

This adds a --image-opts arg that indicates that the positional
filename should be interpreted as a full option string, not
just a filename.

 qemu-io --image-opts driver=http,url=https://127.0.0.1/images,sslverify=off
 qemu-io --image-opts file=/home/berrange/demo.qcow2

This flag is mutually exclusive with the '-f' flag.

Signed-off-by: Daniel P. Berrange 
---
 qemu-io.c | 34 +-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/qemu-io.c b/qemu-io.c
index d1432ea..51d8272 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -367,6 +367,7 @@ static void reenable_tty_echo(void)
 
 enum {
 OPTION_OBJECT = 256,
+OPTION_IMAGE_OPTS = 257,
 };
 
 static QemuOptsList qemu_object_opts = {
@@ -397,6 +398,16 @@ static int object_create(void *opaque, QemuOpts *opts, 
Error **errp)
 return 0;
 }
 
+static QemuOptsList file_opts = {
+.name = "file",
+.implied_opt_name = "file",
+.head = QTAILQ_HEAD_INITIALIZER(file_opts.head),
+.desc = {
+/* no elements => accept any params */
+{ /* end of list */ }
+},
+};
+
 int main(int argc, char **argv)
 {
 int readonly = 0;
@@ -416,6 +427,7 @@ int main(int argc, char **argv)
 { "cache", 1, NULL, 't' },
 { "trace", 1, NULL, 'T' },
 { "object", 1, NULL, OPTION_OBJECT },
+{ "image-opts", 0, NULL, OPTION_IMAGE_OPTS },
 { NULL, 0, NULL, 0 }
 };
 int c;
@@ -424,6 +436,7 @@ int main(int argc, char **argv)
 Error *local_error = NULL;
 QDict *opts = NULL;
 QemuOpts *qopts = NULL;
+bool imageOpts = false;
 
 #ifdef CONFIG_POSIX
 signal(SIGPIPE, SIG_IGN);
@@ -492,6 +505,9 @@ int main(int argc, char **argv)
 exit(1);
 }
 break;
+case OPTION_IMAGE_OPTS:
+imageOpts = true;
+break;
 default:
 usage(progname);
 exit(1);
@@ -534,7 +550,23 @@ int main(int argc, char **argv)
 flags |= BDRV_O_RDWR;
 }
 
-if ((argc - optind) == 1) {
+if (imageOpts) {
+char *file;
+qopts = qemu_opts_parse_noisily(_opts, argv[optind], false);
+if (!qopts) {
+exit(1);
+}
+if (opts) {
+error_report("--image-opts and -f are mutually exclusive");
+exit(1);
+}
+file = g_strdup(qemu_opt_get(qopts, "file"));
+qemu_opt_unset(qopts, "file");
+opts = qemu_opts_to_qdict(qopts, NULL);
+qemu_opts_reset(_opts);
+openfile(file, flags, opts);
+g_free(file);
+} else if ((argc - optind) == 1) {
 openfile(argv[optind], flags, opts);
 }
 command_loop();
-- 
2.5.0




[Qemu-devel] [PATCH v4 08/10] qemu-nbd: don't overlap long option values with short options

2016-01-26 Thread Daniel P. Berrange
When defining values for long options, the normal practice is
to start numbering from 256, to avoid overlap with the range
of valid values for short options.

Reviewed-by: Eric Blake 
Signed-off-by: Daniel P. Berrange 
---
 qemu-nbd.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/qemu-nbd.c b/qemu-nbd.c
index 764698f..bbc79f4 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -43,12 +43,12 @@
 #include 
 
 #define SOCKET_PATH"/var/lock/qemu-nbd-%s"
-#define QEMU_NBD_OPT_CACHE 1
-#define QEMU_NBD_OPT_AIO   2
-#define QEMU_NBD_OPT_DISCARD   3
-#define QEMU_NBD_OPT_DETECT_ZEROES 4
-#define QEMU_NBD_OPT_OBJECT5
-#define QEMU_NBD_OPT_IMAGE_OPTS6
+#define QEMU_NBD_OPT_CACHE 256
+#define QEMU_NBD_OPT_AIO   257
+#define QEMU_NBD_OPT_DISCARD   258
+#define QEMU_NBD_OPT_DETECT_ZEROES 259
+#define QEMU_NBD_OPT_OBJECT260
+#define QEMU_NBD_OPT_IMAGE_OPTS261
 
 static NBDExport *exp;
 static int verbose;
-- 
2.5.0




[Qemu-devel] [PATCH v4 09/10] qemu-nbd: use no_argument/required_argument constants

2016-01-26 Thread Daniel P. Berrange
When declaring the 'struct option' array, use the standard
constants no_argument/required_argument, instead of magic
values 0 and 1.

Reviewed-by: Eric Blake 
Signed-off-by: Daniel P. Berrange 
---
 qemu-nbd.c | 47 ---
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/qemu-nbd.c b/qemu-nbd.c
index bbc79f4..58e1610 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -437,29 +437,30 @@ int main(int argc, char **argv)
 const char *sn_id_or_name = NULL;
 const char *sopt = "hVb:o:p:rsnP:c:dvk:e:f:tl:";
 struct option lopt[] = {
-{ "help", 0, NULL, 'h' },
-{ "version", 0, NULL, 'V' },
-{ "bind", 1, NULL, 'b' },
-{ "port", 1, NULL, 'p' },
-{ "socket", 1, NULL, 'k' },
-{ "offset", 1, NULL, 'o' },
-{ "read-only", 0, NULL, 'r' },
-{ "partition", 1, NULL, 'P' },
-{ "connect", 1, NULL, 'c' },
-{ "disconnect", 0, NULL, 'd' },
-{ "snapshot", 0, NULL, 's' },
-{ "load-snapshot", 1, NULL, 'l' },
-{ "nocache", 0, NULL, 'n' },
-{ "cache", 1, NULL, QEMU_NBD_OPT_CACHE },
-{ "aio", 1, NULL, QEMU_NBD_OPT_AIO },
-{ "discard", 1, NULL, QEMU_NBD_OPT_DISCARD },
-{ "detect-zeroes", 1, NULL, QEMU_NBD_OPT_DETECT_ZEROES },
-{ "shared", 1, NULL, 'e' },
-{ "format", 1, NULL, 'f' },
-{ "persistent", 0, NULL, 't' },
-{ "verbose", 0, NULL, 'v' },
-{ "object", 1, NULL, QEMU_NBD_OPT_OBJECT },
-{ "image-opts", 0, NULL, QEMU_NBD_OPT_IMAGE_OPTS },
+{ "help", no_argument, NULL, 'h' },
+{ "version", no_argument, NULL, 'V' },
+{ "bind", required_argument, NULL, 'b' },
+{ "port", required_argument, NULL, 'p' },
+{ "socket", required_argument, NULL, 'k' },
+{ "offset", required_argument, NULL, 'o' },
+{ "read-only", no_argument, NULL, 'r' },
+{ "partition", required_argument, NULL, 'P' },
+{ "connect", required_argument, NULL, 'c' },
+{ "disconnect", no_argument, NULL, 'd' },
+{ "snapshot", no_argument, NULL, 's' },
+{ "load-snapshot", required_argument, NULL, 'l' },
+{ "nocache", no_argument, NULL, 'n' },
+{ "cache", required_argument, NULL, QEMU_NBD_OPT_CACHE },
+{ "aio", required_argument, NULL, QEMU_NBD_OPT_AIO },
+{ "discard", required_argument, NULL, QEMU_NBD_OPT_DISCARD },
+{ "detect-zeroes", required_argument, NULL,
+  QEMU_NBD_OPT_DETECT_ZEROES },
+{ "shared", required_argument, NULL, 'e' },
+{ "format", required_argument, NULL, 'f' },
+{ "persistent", no_argument, NULL, 't' },
+{ "verbose", no_argument, NULL, 'v' },
+{ "object", required_argument, NULL, QEMU_NBD_OPT_OBJECT },
+{ "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS },
 { NULL, 0, NULL, 0 }
 };
 int ch;
-- 
2.5.0




[Qemu-devel] [PATCH v4 07/10] qemu-img: allow specifying image as a set of options args

2016-01-26 Thread Daniel P. Berrange
Currently qemu-img allows an image filename to be passed on the
command line, but unless using the JSON format, it does not have
a way to set any options except the format eg

   qemu-img info https://127.0.0.1/images/centos7.iso

This adds a --image-opts arg that indicates that the positional
filename should be interpreted as a full option string, not
just a filename.

   qemu-img info --source driver=http,url=https://127.0.0.1/images,sslverify=off

This flag is mutually exclusive with the '-f' / '-F' flags.

Signed-off-by: Daniel P. Berrange 
---
 qemu-img-cmds.hx |  44 
 qemu-img.c   | 304 +--
 qemu-img.texi|   6 ++
 3 files changed, 303 insertions(+), 51 deletions(-)

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index 5bb1de7..ee5c770 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -10,68 +10,68 @@ STEXI
 ETEXI
 
 DEF("check", img_check,
-"check [-q] [--object objectdef] [-f fmt] [--output=ofmt] [-r [leaks | 
all]] [-T src_cache] filename")
+"check [-q] [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] 
[-r [leaks | all]] [-T src_cache] filename")
 STEXI
-@item check [--object objectdef] [-q] [-f @var{fmt}] [--output=@var{ofmt}] [-r 
[leaks | all]] [-T @var{src_cache}] @var{filename}
+@item check [--object objectdef] [--image-opts] [-q] [-f @var{fmt}] 
[--output=@var{ofmt}] [-r [leaks | all]] [-T @var{src_cache}] @var{filename}
 ETEXI
 
 DEF("create", img_create,
-"create [-q] [--object objectdef] [-f fmt] [-o options] filename [size]")
+"create [-q] [--object objectdef] [--image-opts] [-f fmt] [-o options] 
filename [size]")
 STEXI
-@item create [--object objectdef] [-q] [-f @var{fmt}] [-o @var{options}] 
@var{filename} [@var{size}]
+@item create [--object objectdef] [--image-opts] [-q] [-f @var{fmt}] [-o 
@var{options}] @var{filename} [@var{size}]
 ETEXI
 
 DEF("commit", img_commit,
-"commit [-q] [--object objectdef] [-f fmt] [-t cache] [-b base] [-d] [-p] 
filename")
+"commit [-q] [--object objectdef] [--image-opts] [-f fmt] [-t cache] [-b 
base] [-d] [-p] filename")
 STEXI
-@item commit [--object objectdef] [-q] [-f @var{fmt}] [-t @var{cache}] [-b 
@var{base}] [-d] [-p] @var{filename}
+@item commit [--object objectdef] [--image-opts] [-q] [-f @var{fmt}] [-t 
@var{cache}] [-b @var{base}] [-d] [-p] @var{filename}
 ETEXI
 
 DEF("compare", img_compare,
-"compare [--object objectdef] [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] 
[-s] filename1 filename2")
+"compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T 
src_cache] [-p] [-q] [-s] filename1 filename2")
 STEXI
-@item compare [--object objectdef] [-f @var{fmt}] [-F @var{fmt}] [-T 
@var{src_cache}] [-p] [-q] [-s] @var{filename1} @var{filename2}
+@item compare [--object objectdef] [--image-opts] [-f @var{fmt}] [-F 
@var{fmt}] [-T @var{src_cache}] [-p] [-q] [-s] @var{filename1} @var{filename2}
 ETEXI
 
 DEF("convert", img_convert,
-"convert [--object objectdef] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T 
src_cache] [-O output_fmt] [-o options] [-s snapshot_id_or_name] [-l 
snapshot_param] [-S sparse_size] filename [filename2 [...]] output_filename")
+"convert [--object objectdef] [--image-opts] [-c] [-p] [-q] [-n] [-f fmt] 
[-t cache] [-T src_cache] [-O output_fmt] [-o options] [-s snapshot_id_or_name] 
[-l snapshot_param] [-S sparse_size] filename [filename2 [...]] 
output_filename")
 STEXI
-@item convert [--object objectdef] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t 
@var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-o @var{options}] [-s 
@var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] 
@var{filename} [@var{filename2} [...]] @var{output_filename}
+@item convert [--object objectdef] [--image-opts] [-c] [-p] [-q] [-n] [-f 
@var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-o 
@var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S 
@var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
 ETEXI
 
 DEF("info", img_info,
-"info [--object objectdef] [-f fmt] [--output=ofmt] [--backing-chain] 
filename")
+"info [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] 
[--backing-chain] filename")
 STEXI
-@item info [--object objectdef] [-f @var{fmt}] [--output=@var{ofmt}] 
[--backing-chain] @var{filename}
+@item info [--object objectdef] [--image-opts] [-f @var{fmt}] 
[--output=@var{ofmt}] [--backing-chain] @var{filename}
 ETEXI
 
 DEF("map", img_map,
-"map [--object objectdef] [-f fmt] [--output=ofmt] filename")
+"map [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] 
filename")
 STEXI
-@item map [--object objectdef] [-f @var{fmt}] [--output=@var{ofmt}] 
@var{filename}
+@item map [--object objectdef] [--image-opts] [-f @var{fmt}] 
[--output=@var{ofmt}] @var{filename}
 ETEXI
 
 DEF("snapshot", img_snapshot,
-"snapshot [--object objectdef] [-q] [-l | -a snapshot | -c 

[Qemu-devel] [PULL 03/49] char: don't assume telnet initialization will not block

2016-01-26 Thread Paolo Bonzini
From: "Daniel P. Berrange" 

The current code for doing telnet initialization is writing to
a socket without checking the return status. While it is highly
unlikely to be a problem when writing to a bare socket, as the
buffers are large enough to prevent blocking, this cannot be
assumed safe with TLS sockets. So write the telnet initialization
code into a memory buffer and then use an I/O watch to fully
send the data.

Signed-off-by: Daniel P. Berrange 
Message-Id: <1453202071-10289-4-git-send-email-berra...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 qemu-char.c | 87 -
 1 file changed, 69 insertions(+), 18 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 8e9156a..f0cea8a 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2877,19 +2877,70 @@ static void tcp_chr_update_read_handler(CharDriverState 
*chr)
 }
 }
 
-#define IACSET(x,a,b,c) x[0] = a; x[1] = b; x[2] = c;
-static void tcp_chr_telnet_init(QIOChannel *ioc)
+typedef struct {
+CharDriverState *chr;
+char buf[12];
+size_t buflen;
+} TCPCharDriverTelnetInit;
+
+static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc,
+   GIOCondition cond G_GNUC_UNUSED,
+   gpointer user_data)
+{
+TCPCharDriverTelnetInit *init = user_data;
+ssize_t ret;
+
+ret = qio_channel_write(ioc, init->buf, init->buflen, NULL);
+if (ret < 0) {
+if (ret == QIO_CHANNEL_ERR_BLOCK) {
+ret = 0;
+} else {
+tcp_chr_disconnect(init->chr);
+return FALSE;
+}
+}
+init->buflen -= ret;
+
+if (init->buflen == 0) {
+tcp_chr_connect(init->chr);
+return FALSE;
+}
+
+memmove(init->buf, init->buf + ret, init->buflen);
+
+return TRUE;
+}
+
+static void tcp_chr_telnet_init(CharDriverState *chr)
 {
-char buf[3];
-/* Send the telnet negotion to put telnet in binary, no echo, single char 
mode */
-IACSET(buf, 0xff, 0xfb, 0x01);  /* IAC WILL ECHO */
-qio_channel_write(ioc, buf, 3, NULL);
-IACSET(buf, 0xff, 0xfb, 0x03);  /* IAC WILL Suppress go ahead */
-qio_channel_write(ioc, buf, 3, NULL);
-IACSET(buf, 0xff, 0xfb, 0x00);  /* IAC WILL Binary */
-qio_channel_write(ioc, buf, 3, NULL);
-IACSET(buf, 0xff, 0xfd, 0x00);  /* IAC DO Binary */
-qio_channel_write(ioc, buf, 3, NULL);
+TCPCharDriver *s = chr->opaque;
+TCPCharDriverTelnetInit *init =
+g_new0(TCPCharDriverTelnetInit, 1);
+size_t n = 0;
+
+init->chr = chr;
+init->buflen = 12;
+
+#define IACSET(x, a, b, c)  \
+do {\
+x[n++] = a; \
+x[n++] = b; \
+x[n++] = c; \
+} while (0)
+
+/* Prep the telnet negotion to put telnet in binary,
+ * no echo, single char mode */
+IACSET(init->buf, 0xff, 0xfb, 0x01);  /* IAC WILL ECHO */
+IACSET(init->buf, 0xff, 0xfb, 0x03);  /* IAC WILL Suppress go ahead */
+IACSET(init->buf, 0xff, 0xfb, 0x00);  /* IAC WILL Binary */
+IACSET(init->buf, 0xff, 0xfd, 0x00);  /* IAC DO Binary */
+
+#undef IACSET
+
+qio_channel_add_watch(
+s->ioc, G_IO_OUT,
+tcp_chr_telnet_init_io,
+init, NULL);
 }
 
 static int tcp_chr_new_client(CharDriverState *chr, QIOChannelSocket *sioc)
@@ -2909,7 +2960,12 @@ static int tcp_chr_new_client(CharDriverState *chr, 
QIOChannelSocket *sioc)
 g_source_remove(s->listen_tag);
 s->listen_tag = 0;
 }
-tcp_chr_connect(chr);
+
+if (s->do_telnetopt) {
+tcp_chr_telnet_init(chr);
+} else {
+tcp_chr_connect(chr);
+}
 
 return 0;
 }
@@ -2935,7 +2991,6 @@ static gboolean tcp_chr_accept(QIOChannel *channel,
void *opaque)
 {
 CharDriverState *chr = opaque;
-TCPCharDriver *s = chr->opaque;
 QIOChannelSocket *sioc;
 
 sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(channel),
@@ -2944,10 +2999,6 @@ static gboolean tcp_chr_accept(QIOChannel *channel,
 return TRUE;
 }
 
-if (s->do_telnetopt) {
-tcp_chr_telnet_init(QIO_CHANNEL(sioc));
-}
-
 tcp_chr_new_client(chr, sioc);
 
 object_unref(OBJECT(sioc));
-- 
1.8.3.1





[Qemu-devel] [PULL 00/49] chardev, NBD, cpus, scripts/ changes for 2015-01-26

2016-01-26 Thread Paolo Bonzini
The following changes since commit 3db34bf64ab4f8797565dd8750003156c32b301d:

  Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-peter' 
into staging (2016-01-18 17:40:50 +)

are available in the git repository at:


  git://github.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to 0932a8ff6feec098a30191e8ae9c3d3aa759e844:

  scripts/dump-guest-memory.py: Fix module docstring (2016-01-26 13:55:19 +0100)


* chardev support for TLS and leak fix
* NBD fix from Denis
* condvar fix from Dave
* kvm_stat and dump-guest-memory almost rewrite
* mem-prealloc fix from Luiz
* manpage style improvement


Daniel P. Berrange (4):
  char: remove fixed length filename allocation
  char: convert from GIOChannel to QIOChannel
  char: don't assume telnet initialization will not block
  char: introduce support for TLS encrypted TCP chardev backend

Denis V. Lunev (1):
  nbd: add missed aio_context_acquire in nbd_export_new

Dr. David Alan Gilbert (1):
  cpus: use broadcast on qemu_pause_cond

Janosch Frank (40):
  scripts/kvm/kvm_stat: Cleanup of multiple imports
  scripts/kvm/kvm_stat: Replaced os.listdir with os.walk
  scripts/kvm/kvm_stat: Make constants uppercase
  scripts/kvm/kvm_stat: Removed unneeded PERF constants
  scripts/kvm/kvm_stat: Mark globals in functions
  scripts/kvm/kvm_stat: Invert dictionaries
  scripts/kvm/kvm_stat: Cleanup of path variables
  scripts/kvm/kvm_stat: Improve debugfs access checking
  scripts/kvm/kvm_stat: Introduce main function
  scripts/kvm/kvm_stat: Fix spaces around keyword assignments
  scripts/kvm/kvm_stat: Rename variables that redefine globals
  scripts/kvm/kvm_stat: Moved DebugfsProvider
  scripts/kvm/kvm_stat: Fixup syscall error reporting
  scripts/kvm/kvm_stat: Set sensible no. files rlimit
  scripts/kvm/kvm_stat: Cleanup of platform detection
  scripts/kvm/kvm_stat: Make cpu detection a function
  scripts/kvm/kvm_stat: Rename _perf_event_open
  scripts/kvm/kvm_stat: Introduce properties for providers
  scripts/kvm/kvm_stat: Cleanup of TracepointProvider
  scripts/kvm/kvm_stat: Cleanup cpu list retrieval
  scripts/kvm/kvm_stat: Encapsulate filters variable
  scripts/kvm/kvm_stat: Cleanup of Stats class
  scripts/kvm/kvm_stat: Cleanup of Groups class
  scripts/kvm/kvm_stat: Cleanup of Event class
  scripts/kvm/kvm_stat: Group arch specific data
  scripts/kvm/kvm_stat: Remove unneeded X86_EXIT_REASONS
  scripts/kvm/kvm_stat: Make tui function a class
  scripts/kvm/kvm_stat: Fix output formatting
  scripts/kvm/kvm_stat: Cleanup and pre-init perf_event_attr
  scripts/kvm/kvm_stat: Read event values as u64
  scripts/kvm/kvm_stat: Fix rlimit for unprivileged users
  scripts/kvm/kvm_stat: Fixup filtering
  scripts/kvm/kvm_stat: Add interactive filtering
  scripts/kvm/kvm_stat: Add optparse description
  scripts/dump-guest-memory.py: Move constants to the top
  scripts/dump-guest-memory.py: Make methods functions
  scripts/dump-guest-memory.py: Improve python 3 compatibility
  scripts/dump-guest-memory.py: Cleanup functions
  scripts/dump-guest-memory.py: Introduce multi-arch support
  scripts/dump-guest-memory.py: Fix module docstring

Luiz Capitulino (1):
  memory: exit when hugepage allocation fails if mem-prealloc

Paolo Bonzini (1):
  qemu-char: avoid leak in qemu_chr_open_pp_fd

Sitsofe Wheeler (1):
  docs: Style the command and its options in the synopsis

 cpus.c |4 +-
 fsdev/virtfs-proxy-helper.texi |2 +-
 nbd/server.c   |2 +
 numa.c |   11 +-
 qapi-schema.json   |2 +
 qemu-char.c|  924 ---
 qemu-doc.texi  |8 +-
 qemu-ga.texi   |2 +-
 qemu-img.texi  |2 +-
 qemu-options.hx|9 +-
 scripts/dump-guest-memory.py   |  762 +++--
 scripts/kvm/kvm_stat   | 1199 +++-
 tests/Makefile |2 +-
 13 files changed, 1662 insertions(+), 1267 deletions(-)
-- 
1.8.3.1




[Qemu-devel] [PULL 01/49] char: remove fixed length filename allocation

2016-01-26 Thread Paolo Bonzini
From: "Daniel P. Berrange" 

A variety of places were snprintf()ing into a fixed length
filename buffer. Some of the buffers were stack allocated,
while another was heap allocated with g_malloc(). Switch
them all to heap allocated using g_strdup_printf() avoiding
arbitrary length restrictions.

This also facilitates later patches which will want to
populate the filename by calling external functions
which do not support use of a pre-allocated buffer.

Signed-off-by: Daniel P. Berrange 
Message-Id: <1453202071-10289-2-git-send-email-berra...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 qemu-char.c | 86 +++--
 1 file changed, 44 insertions(+), 42 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index e133f4f..8e96f90 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -88,39 +88,37 @@
 
 #define READ_BUF_LEN 4096
 #define READ_RETRIES 10
-#define CHR_MAX_FILENAME_SIZE 256
 #define TCP_MAX_FDS 16
 
 /***/
 /* Socket address helpers */
 
-static int SocketAddress_to_str(char *dest, int max_len,
-const char *prefix, SocketAddress *addr,
-bool is_listen, bool is_telnet)
+static char *SocketAddress_to_str(const char *prefix, SocketAddress *addr,
+  bool is_listen, bool is_telnet)
 {
 switch (addr->type) {
 case SOCKET_ADDRESS_KIND_INET:
-return snprintf(dest, max_len, "%s%s:%s:%s%s", prefix,
-is_telnet ? "telnet" : "tcp", addr->u.inet->host,
-addr->u.inet->port, is_listen ? ",server" : "");
+return g_strdup_printf("%s%s:%s:%s%s", prefix,
+   is_telnet ? "telnet" : "tcp", 
addr->u.inet->host,
+   addr->u.inet->port, is_listen ? ",server" : "");
 break;
 case SOCKET_ADDRESS_KIND_UNIX:
-return snprintf(dest, max_len, "%sunix:%s%s", prefix,
-addr->u.q_unix->path, is_listen ? ",server" : "");
+return g_strdup_printf("%sunix:%s%s", prefix,
+   addr->u.q_unix->path,
+   is_listen ? ",server" : "");
 break;
 case SOCKET_ADDRESS_KIND_FD:
-return snprintf(dest, max_len, "%sfd:%s%s", prefix, addr->u.fd->str,
-is_listen ? ",server" : "");
+return g_strdup_printf("%sfd:%s%s", prefix, addr->u.fd->str,
+   is_listen ? ",server" : "");
 break;
 default:
 abort();
 }
 }
 
-static int sockaddr_to_str(char *dest, int max_len,
-   struct sockaddr_storage *ss, socklen_t ss_len,
-   struct sockaddr_storage *ps, socklen_t ps_len,
-   bool is_listen, bool is_telnet)
+static char *sockaddr_to_str(struct sockaddr_storage *ss, socklen_t ss_len,
+ struct sockaddr_storage *ps, socklen_t ps_len,
+ bool is_listen, bool is_telnet)
 {
 char shost[NI_MAXHOST], sserv[NI_MAXSERV];
 char phost[NI_MAXHOST], pserv[NI_MAXSERV];
@@ -129,9 +127,9 @@ static int sockaddr_to_str(char *dest, int max_len,
 switch (ss->ss_family) {
 #ifndef _WIN32
 case AF_UNIX:
-return snprintf(dest, max_len, "unix:%s%s",
-((struct sockaddr_un *)(ss))->sun_path,
-is_listen ? ",server" : "");
+return g_strdup_printf("unix:%s%s",
+   ((struct sockaddr_un *)(ss))->sun_path,
+   is_listen ? ",server" : "");
 #endif
 case AF_INET6:
 left  = "[";
@@ -142,14 +140,14 @@ static int sockaddr_to_str(char *dest, int max_len,
 sserv, sizeof(sserv), NI_NUMERICHOST | NI_NUMERICSERV);
 getnameinfo((struct sockaddr *) ps, ps_len, phost, sizeof(phost),
 pserv, sizeof(pserv), NI_NUMERICHOST | NI_NUMERICSERV);
-return snprintf(dest, max_len, "%s:%s%s%s:%s%s <-> %s%s%s:%s",
-is_telnet ? "telnet" : "tcp",
-left, shost, right, sserv,
-is_listen ? ",server" : "",
-left, phost, right, pserv);
+return g_strdup_printf("%s:%s%s%s:%s%s <-> %s%s%s:%s",
+   is_telnet ? "telnet" : "tcp",
+   left, shost, right, sserv,
+   is_listen ? ",server" : "",
+   left, phost, right, pserv);
 
 default:
-return snprintf(dest, max_len, "unknown");
+return g_strdup_printf("unknown");
 }
 }
 
@@ -1074,15 +1072,18 @@ static CharDriverState *qemu_chr_open_pipe(const char 
*id,
 {
 ChardevHostdev *opts = backend->u.pipe;
 int fd_in, fd_out;
-char 

[Qemu-devel] [PULL 07/49] scripts/kvm/kvm_stat: Cleanup of multiple imports

2016-01-26 Thread Paolo Bonzini
From: Janosch Frank 

Removed multiple imports of the same module and moved all imports to
the top.

It is not necessary to import a module each time one of its
functions/classes is used.
For readability each import should get its own line.

Signed-off-by: Janosch Frank 
Message-Id: <1452525484-32309-2-git-send-email-fran...@linux.vnet.ibm.com>
Signed-off-by: Paolo Bonzini 
---
 scripts/kvm/kvm_stat | 26 +++---
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 7e5d256..3fadbfb 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -12,8 +12,16 @@
 # the COPYING file in the top-level directory.
 
 import curses
-import sys, os, time, optparse, ctypes
-from ctypes import *
+import sys
+import os
+import time
+import optparse
+import ctypes
+import fcntl
+import resource
+import struct
+import re
+from collections import defaultdict
 
 class DebugfsProvider(object):
 def __init__(self):
@@ -285,12 +293,10 @@ filters['kvm_userspace_exit'] = ('reason', 
invert(userspace_exit_reasons))
 if exit_reasons:
 filters['kvm_exit'] = ('exit_reason', invert(exit_reasons))
 
-import struct, array
-
 libc = ctypes.CDLL('libc.so.6')
 syscall = libc.syscall
 get_errno = libc.__errno_location
-get_errno.restype = POINTER(c_int)
+get_errno.restype = ctypes.POINTER(ctypes.c_int)
 
 class perf_event_attr(ctypes.Structure):
 _fields_ = [('type', ctypes.c_uint32),
@@ -334,8 +340,6 @@ PERF_FORMAT_TOTAL_TIME_RUNNING  = 1 << 1
 PERF_FORMAT_ID  = 1 << 2
 PERF_FORMAT_GROUP   = 1 << 3
 
-import re
-
 sys_tracing = '/sys/kernel/debug/tracing'
 
 class Group(object):
@@ -378,17 +382,13 @@ class Event(object):
 err = get_errno()[0]
 raise Exception('perf_event_open failed, errno = ' + err.__str__())
 if filter:
-import fcntl
 fcntl.ioctl(fd, ioctl_numbers['SET_FILTER'], filter)
 self.fd = fd
 def enable(self):
-import fcntl
 fcntl.ioctl(self.fd, ioctl_numbers['ENABLE'], 0)
 def disable(self):
-import fcntl
 fcntl.ioctl(self.fd, ioctl_numbers['DISABLE'], 0)
 def reset(self):
-import fcntl
 fcntl.ioctl(self.fd, ioctl_numbers['RESET'], 0)
 
 class TracepointProvider(object):
@@ -426,7 +426,6 @@ class TracepointProvider(object):
 def _setup(self, _fields):
 self._fields = _fields
 cpus = self._online_cpus()
-import resource
 nfiles = len(cpus) * 1000
 resource.setrlimit(resource.RLIMIT_NOFILE, (nfiles, nfiles))
 events = []
@@ -454,7 +453,6 @@ class TracepointProvider(object):
 else:
 event.disable()
 def read(self):
-from collections import defaultdict
 ret = defaultdict(int)
 for group in self.group_leaders:
 for name, val in group.read().iteritems():
@@ -468,7 +466,6 @@ class Stats:
 self._update()
 def _update(self):
 def wanted(key):
-import re
 if not self.fields_filter:
 return True
 return re.match(self.fields_filter, key) is not None
@@ -640,7 +637,6 @@ stats = Stats(providers, fields = options.fields)
 if options.log:
 log(stats)
 elif not options.once:
-import curses.wrapper
 curses.wrapper(tui, stats)
 else:
 batch(stats)
-- 
1.8.3.1





[Qemu-devel] [PULL 06/49] qemu-char: avoid leak in qemu_chr_open_pp_fd

2016-01-26 Thread Paolo Bonzini
drv leaks if qemu_chr_alloc returns an error.

Signed-off-by: Paolo Bonzini 
---
 qemu-char.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 7ded3c2..ae813d0 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1740,18 +1740,19 @@ static CharDriverState *qemu_chr_open_pp_fd(int fd,
 return NULL;
 }
 
-drv = g_new0(ParallelCharDriver, 1);
-drv->fd = fd;
-drv->mode = IEEE1284_MODE_COMPAT;
-
 chr = qemu_chr_alloc(backend, errp);
 if (!chr) {
 return NULL;
 }
+
+drv = g_new0(ParallelCharDriver, 1);
+chr->opaque = drv;
 chr->chr_write = null_chr_write;
 chr->chr_ioctl = pp_ioctl;
 chr->chr_close = pp_close;
-chr->opaque = drv;
+
+drv->fd = fd;
+drv->mode = IEEE1284_MODE_COMPAT;
 
 return chr;
 }
-- 
1.8.3.1





  1   2   3   4   >