Re: [Qemu-devel] [PATCH v6 3/9] vdi: Use QEMU UUID API

2016-09-17 Thread Stefan Weil

On 08/17/16 09:28, Fam Zheng wrote:

The UUID operations we need from libuuid is fully supported by QEMU UUID
implementation. Use it, and remove the unused code.


See Eric's annotation.



Signed-off-by: Fam Zheng 
---
 block/vdi.c | 73 ++---
 1 file changed, 17 insertions(+), 56 deletions(-)


Reviewed-by: Stefan Weil 




Re: [Qemu-devel] [PATCH] vfio: Fix regression in MSI routing configuration

2016-09-17 Thread Peter Xu
Good to know that we have a solution. :)

I think this is a good fix, however I still do not understand why this
is happening... Please see below comment.

On Thu, Sep 15, 2016 at 04:11:48PM +1000, David Gibson wrote:
> d1f6af6 "kvm-irqchip: simplify kvm_irqchip_add_msi_route" was a cleanup
> of kvmchip routing configuration, that was mostly intended for x86.
> However, it also contains a subtle change in behaviour which breaks EEH[1]
> error recovery on certain VFIO passthrough devices on spapr guests.  So far
> it's only been seen on a BCM5719 NIC on a POWER8 server, but there may be
> other hardware with the same problem.  It's also possible there could be
> circumstances where it causes a bug on x86 as well, though I don't know of
> any obvious candidates.
> 
> Prior to d1f6af6, both vfio_msix_vector_do_use() and
> vfio_add_kvm_msi_virq() used msg == NULL as a special flag to mark this
> as the "dummy" vector used to make the host hardware state sync with the
> guest expected hardware state in terms of MSI configuration.
> 
> Specifically that flag caused vfio_add_kvm_msi_virq() to become a no-op,
> meaning the dummy irq would always be delivered via qemu.

AFAICT, QEMU is not delivering that *dummy* IRQ as well. IIUC here the
dummy IRQ refers to the one in vfio_msix_enable():

vfio_msix_vector_do_use(>pdev, 0, NULL, NULL);
vfio_msix_vector_release(>pdev, 0);

Here we registered this dummy one to sync up the guest and host
hardware state for some reason. However, the handler is NULL here,
means that even QEMU won't handle it if it happens. And the only
difference is that during this extremely small period, kvm will handle
the interrupt with an uninitialized MSI message, but assuming that
would never happen since no one should start to use MSI yet. After
release(), interrupts will be dropped for all cases.

So looks like it is not related to "whether QEMU or KVM will handle
the interrupt", but something else.

Generally speaking, the process of registering the IRQ should be
something like (using QEMU with d1f6af6 change):

1. vfio_msix_enable(): when MSIX is enabled. this will trigger
   vfio_add_kvm_msi_virq(), but quickly it is unregistered (virq will
   be there, but VFIO will assign the VFIO handler to
   vector->interrupt, rather than vector->kvm_interrupt, so that virq
   won't take effect).

2. vfio_msix_vector_use(): when an MSIX entry is finally used and
   setup. this will trigger vfio_update_kvm_msi_virq(), to update the
   interrupt information to the "real one".

IMHO we should always receive interrupts after step (2). And as we
have traced (with David), step (2) was updating the correct interrupt
information even with commit d1f6af6. But I think I might be wrong (or
say, the above assumption is not correct), because commit d1f6af6
indeed caused problem with EHH and this specific hardware. I am just
do not know why it is triggering the issue. And that's why I want to
know whether there is anything special with that NIC's driver.

Again, this is totally a discussion only, and I am totally agree with
current change to fix the issue. Just in case someone knows the reason
behind this.

Thanks,

-- peterx



Re: [Qemu-devel] [PATCH] CAN bus MIOe-3680 PCI (dual SJA1000 channel) emulation added.

2016-09-17 Thread Deniz Eren
Hi Pavel,

Thank you for the merge - CAN-bus support for QEMU is very important in my 
opinion. Most embedded applications utilise CAN and virtualising this interface 
gives an amazing integration test harness.



Best regards,
Deniz

Sent from my iPhone

Deniz Eren
+61 400 307 762

> On 9 Sep. 2016, at 3:10 am, Pavel Pisa  wrote:
> 
> Hello Deniz,
> 
> thanks much for contribution and testing.
> 
> I have applied your patches to our QEMU
> repo
> 
>  https://github.com/CTU-IIG/qemu
> 
> You find QEMU-2.6.1 based version of our merged
> patches on "merged-2.6" branch.
> 
> I have updated and shortly tested all our topic branches
> with actual QEMU-2.7.0 release. Simple test with
> Linux within Linux and SocketCAN on both sides
> works for PCI CAN-S (single SJA1000 channel) card
> well with QEMU-2.7.0.
> 
> So I have undated all topics branches "can-pci",
> "mf624" and "apohw" to this version then and created
> "merged-2.7" branch. "merged" branch is now moved
> to "merged-2.7" as well.
> 
> Your offer to help with mainlining is great as well.
> Some discussion with somebody from core QEMU team
> member is required.
> 
> I hope that actual CAN chip driver and PCI cards
> follow QOM model right way. Problem is the simple
> bus used for mesages delivery between CAN controllers.
> These buses should be converted somehow to QOM acceptable
> model. But for embedded development when you do not
> freeze emulated system state is actual solution quite
> usable as well.
> 
> It would be great to implement CAN FD (Flexible Datarate)
> controller emulation support as well.
> 
> I am trying to find some diploma student for that for
> two years already because he/she can have continuous
> time for such work and testing which I cannot find.
> Help from other instreested or project users would
> be great as well.
> 
> Best wishes,
> 
>  Pavel
> 
> 
> 
> 


[Qemu-devel] [PATCH v8 10/12] uuid: Tighten uuid parse

2016-09-17 Thread Fam Zheng
sscanf is relatively loose (tolerate) on some invalid formats that we
should fail instead of generating a wrong uuid structure, like with
whitespaces and short strings.

Add and use a helper function to first check the format.

Signed-off-by: Fam Zheng 
---
 util/uuid.c | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/util/uuid.c b/util/uuid.c
index 4701903..dd6b5fd 100644
--- a/util/uuid.c
+++ b/util/uuid.c
@@ -61,12 +61,34 @@ char *qemu_uuid_unparse_strdup(const QemuUUID *uuid)
uu[13], uu[14], uu[15]);
 }
 
+static bool qemu_uuid_is_valid(const char *str)
+{
+int i;
+
+for (i = 0; i < strlen(str); i++) {
+const char c = str[i];
+if (i == 8 || i == 13 || i == 18 || i == 23) {
+if (str[i] != '-') {
+return false;
+}
+} else {
+if ((c >= '0' && c <= '9') ||
+(c >= 'A' && c <= 'F') ||
+(c >= 'a' && c <= 'f')) {
+continue;
+}
+return false;
+}
+}
+return i == 36;
+}
+
 int qemu_uuid_parse(const char *str, QemuUUID *uuid)
 {
 unsigned char *uu = >data[0];
 int ret;
 
-if (strlen(str) != 36) {
+if (!qemu_uuid_is_valid(str)) {
 return -1;
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH v8 04/12] vdi: Use QEMU UUID API

2016-09-17 Thread Fam Zheng
The UUID operations we need from libuuid are fully supported by QEMU UUID
implementation. Use it, and remove the unused code.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 block/vdi.c | 73 ++---
 1 file changed, 17 insertions(+), 56 deletions(-)

diff --git a/block/vdi.c b/block/vdi.c
index 8a1cf97..96b78d5 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -58,14 +58,7 @@
 #include "migration/migration.h"
 #include "qemu/coroutine.h"
 #include "qemu/cutils.h"
-
-#if defined(CONFIG_UUID)
-#include 
-#else
-/* TODO: move uuid emulation to some central place in QEMU. */
-#include "sysemu/sysemu.h" /* UUID_FMT */
-typedef unsigned char uuid_t[16];
-#endif
+#include "qemu/uuid.h"
 
 /* Code configuration options. */
 
@@ -140,28 +133,6 @@ typedef unsigned char uuid_t[16];
 #define VDI_DISK_SIZE_MAX((uint64_t)VDI_BLOCKS_IN_IMAGE_MAX * \
   (uint64_t)DEFAULT_CLUSTER_SIZE)
 
-#if !defined(CONFIG_UUID)
-static inline void uuid_generate(uuid_t out)
-{
-memset(out, 0, sizeof(uuid_t));
-}
-
-static inline int uuid_is_null(const uuid_t uu)
-{
-uuid_t null_uuid = { 0 };
-return memcmp(uu, null_uuid, sizeof(uuid_t)) == 0;
-}
-
-# if defined(CONFIG_VDI_DEBUG)
-static inline void uuid_unparse(const uuid_t uu, char *out)
-{
-snprintf(out, 37, UUID_FMT,
-uu[0], uu[1], uu[2], uu[3], uu[4], uu[5], uu[6], uu[7],
-uu[8], uu[9], uu[10], uu[11], uu[12], uu[13], uu[14], uu[15]);
-}
-# endif
-#endif
-
 typedef struct {
 char text[0x40];
 uint32_t signature;
@@ -182,10 +153,10 @@ typedef struct {
 uint32_t block_extra;   /* unused here */
 uint32_t blocks_in_image;
 uint32_t blocks_allocated;
-uuid_t uuid_image;
-uuid_t uuid_last_snap;
-uuid_t uuid_link;
-uuid_t uuid_parent;
+QemuUUID uuid_image;
+QemuUUID uuid_last_snap;
+QemuUUID uuid_link;
+QemuUUID uuid_parent;
 uint64_t unused2[7];
 } QEMU_PACKED VdiHeader;
 
@@ -206,16 +177,6 @@ typedef struct {
 Error *migration_blocker;
 } BDRVVdiState;
 
-/* Change UUID from little endian (IPRT = VirtualBox format) to big endian
- * format (network byte order, standard, see RFC 4122) and vice versa.
- */
-static void uuid_convert(uuid_t uuid)
-{
-bswap32s((uint32_t *)[0]);
-bswap16s((uint16_t *)[4]);
-bswap16s((uint16_t *)[6]);
-}
-
 static void vdi_header_to_cpu(VdiHeader *header)
 {
 le32_to_cpus(>signature);
@@ -234,10 +195,10 @@ static void vdi_header_to_cpu(VdiHeader *header)
 le32_to_cpus(>block_extra);
 le32_to_cpus(>blocks_in_image);
 le32_to_cpus(>blocks_allocated);
-uuid_convert(header->uuid_image);
-uuid_convert(header->uuid_last_snap);
-uuid_convert(header->uuid_link);
-uuid_convert(header->uuid_parent);
+qemu_uuid_bswap(>uuid_image);
+qemu_uuid_bswap(>uuid_last_snap);
+qemu_uuid_bswap(>uuid_link);
+qemu_uuid_bswap(>uuid_parent);
 }
 
 static void vdi_header_to_le(VdiHeader *header)
@@ -258,10 +219,10 @@ static void vdi_header_to_le(VdiHeader *header)
 cpu_to_le32s(>block_extra);
 cpu_to_le32s(>blocks_in_image);
 cpu_to_le32s(>blocks_allocated);
-uuid_convert(header->uuid_image);
-uuid_convert(header->uuid_last_snap);
-uuid_convert(header->uuid_link);
-uuid_convert(header->uuid_parent);
+qemu_uuid_bswap(>uuid_image);
+qemu_uuid_bswap(>uuid_last_snap);
+qemu_uuid_bswap(>uuid_link);
+qemu_uuid_bswap(>uuid_parent);
 }
 
 #if defined(CONFIG_VDI_DEBUG)
@@ -469,11 +430,11 @@ static int vdi_open(BlockDriverState *bs, QDict *options, 
int flags,
(uint64_t)header.blocks_in_image * header.block_size);
 ret = -ENOTSUP;
 goto fail;
-} else if (!uuid_is_null(header.uuid_link)) {
+} else if (!qemu_uuid_is_null(_link)) {
 error_setg(errp, "unsupported VDI image (non-NULL link UUID)");
 ret = -ENOTSUP;
 goto fail;
-} else if (!uuid_is_null(header.uuid_parent)) {
+} else if (!qemu_uuid_is_null(_parent)) {
 error_setg(errp, "unsupported VDI image (non-NULL parent UUID)");
 ret = -ENOTSUP;
 goto fail;
@@ -821,8 +782,8 @@ static int vdi_create(const char *filename, QemuOpts *opts, 
Error **errp)
 if (image_type == VDI_TYPE_STATIC) {
 header.blocks_allocated = blocks;
 }
-uuid_generate(header.uuid_image);
-uuid_generate(header.uuid_last_snap);
+qemu_uuid_generate(_image);
+qemu_uuid_generate(_last_snap);
 /* There is no need to set header.uuid_link or header.uuid_parent here. */
 #if defined(CONFIG_VDI_DEBUG)
 vdi_header_print();
-- 
2.7.4




[Qemu-devel] [PATCH v8 11/12] tests: Add uuid tests

2016-09-17 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 tests/Makefile.include |   2 +
 tests/test-uuid.c  | 177 +
 2 files changed, 179 insertions(+)
 create mode 100644 tests/test-uuid.c

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 2f11064..15e7f8f 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -115,6 +115,7 @@ check-unit-y += tests/test-logging$(EXESUF)
 check-unit-$(CONFIG_REPLICATION) += tests/test-replication$(EXESUF)
 check-unit-y += tests/test-bufferiszero$(EXESUF)
 gcov-files-check-bufferiszero-y = util/bufferiszero.c
+check-unit-y += tests/test-uuid$(EXESUF)
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -658,6 +659,7 @@ tests/test-filter-mirror$(EXESUF): 
tests/test-filter-mirror.o $(qtest-obj-y)
 tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o 
$(qtest-obj-y)
 tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o 
contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y)
 tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o
+tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y)
 
 tests/migration/stress$(EXESUF): tests/migration/stress.o
$(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< 
,"  LINK  $(TARGET_DIR)$@")
diff --git a/tests/test-uuid.c b/tests/test-uuid.c
new file mode 100644
index 000..77dcdc4
--- /dev/null
+++ b/tests/test-uuid.c
@@ -0,0 +1,177 @@
+/*
+ * QEMU UUID Library
+ *
+ * Copyright (c) 2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see .
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/uuid.h"
+
+struct {
+const char *uuidstr;
+QemuUUID uuid;
+bool uuidstr_is_valid;
+bool check_unparse;
+} uuid_test_data[] = {
+{/* Normal */
+"586ece27-7f09-41e0-9e74-e901317e9d42",
+{ { {
+ 0x58, 0x6e, 0xce, 0x27, 0x7f, 0x09, 0x41, 0xe0,
+ 0x9e, 0x74, 0xe9, 0x01, 0x31, 0x7e, 0x9d, 0x42,
+} } },
+true, true,
+}, { /* NULL */
+"----",
+{ },
+true, true,
+}, { /* Upper case */
+"0CC6C752-3961-4028-A286-C05CC616D396",
+{ { {
+ 0x0c, 0xc6, 0xc7, 0x52, 0x39, 0x61, 0x40, 0x28,
+ 0xa2, 0x86, 0xc0, 0x5c, 0xc6, 0x16, 0xd3, 0x96,
+} } },
+true, false,
+}, { /* Mixed case */
+"0CC6C752-3961-4028-a286-c05cc616D396",
+{ { {
+ 0x0c, 0xc6, 0xc7, 0x52, 0x39, 0x61, 0x40, 0x28,
+ 0xa2, 0x86, 0xc0, 0x5c, 0xc6, 0x16, 0xd3, 0x96,
+} } },
+true, false,
+}, { /* Empty */
+""
+}, { /* Too short */
+"abc",
+}, { /* Non-hex */
+"abcdefgh----",
+}, { /* No '-' */
+"0cc6c75239614028a286c05cc616d396",
+}, { /* '-' in wrong position */
+"0cc6c-7523961-4028-a286-c05cc616d396",
+}, { /* Double '-' */
+"0cc6c752--3961-4028-a286-c05cc616d396",
+}, { /* Too long */
+"00",
+}, { /* Invalid char in the beginning */
+")cc6c752-3961-4028-a286-c05cc616d396",
+}, { /* Invalid char in the beginning, in extra */
+")0cc6c752-3961-4028-a286-c05cc616d396",
+}, { /* Invalid char in the middle */
+"0cc6c752-39*1-4028-a286-c05cc616d396",
+}, { /* Invalid char in the middle, in extra */
+"0cc6c752-39*61-4028-a286-c05cc616d396",
+}, { /* Invalid char in the end */
+"0cc6c752-3961-4028-a286-c05cc616d39&",
+}, { /* Invalid char in the end, in extra */
+"0cc6c752-3961-4028-a286-c05cc616d396&",
+}, { /* Short end and trailing space */
+"0cc6c752-3961-4028-a286-c05cc616d39 ",
+}, { /* Leading space and short end */
+" 0cc6c752-3961-4028-a286-c05cc616d39",
+},
+};
+
+static inline bool uuid_is_valid(QemuUUID *uuid)
+{
+return qemu_uuid_is_null(uuid) ||
+((uuid->data[6] & 0xf0) == 0x40 && (uuid->data[8] & 0xc0) == 0x80);
+}
+
+static void test_uuid_generate(void)
+{
+QemuUUID uuid;
+int i;
+
+for (i = 0; i < 100; ++i) {
+qemu_uuid_generate();
+g_assert(uuid_is_valid());
+}
+}
+
+static void test_uuid_is_null(void)
+{
+QemuUUID uuid_null = { };
+QemuUUID uuid_not_null = { { {
+ 

[Qemu-devel] [PATCH v8 03/12] vhdx: Use QEMU UUID API

2016-09-17 Thread Fam Zheng
This removes our dependency to libuuid, so that the driver can always be
built.

Similar to how we handled data plane configure options, --enable-vhdx
and --disable-vhdx are also changed to a nop with a message saying it's
obsolete.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 block/Makefile.objs |  2 +-
 block/vhdx-endian.c |  3 ---
 block/vhdx.c|  9 -
 configure   | 27 +++
 4 files changed, 8 insertions(+), 33 deletions(-)

diff --git a/block/Makefile.objs b/block/Makefile.objs
index 55da626..f23ee18 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -2,7 +2,7 @@ block-obj-y += raw_bsd.o qcow.o vdi.o vmdk.o cloop.o bochs.o 
vpc.o vvfat.o
 block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o 
qcow2-cache.o
 block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-obj-y += qed-check.o
-block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o vhdx-log.o
+block-obj-y += vhdx.o vhdx-endian.o vhdx-log.o
 block-obj-y += quorum.o
 block-obj-y += parallels.o blkdebug.o blkverify.o blkreplay.o
 block-obj-y += block-backend.o snapshot.o qapi.o
diff --git a/block/vhdx-endian.c b/block/vhdx-endian.c
index c306b90..429d755 100644
--- a/block/vhdx-endian.c
+++ b/block/vhdx-endian.c
@@ -21,9 +21,6 @@
 #include "qemu/bswap.h"
 #include "block/vhdx.h"
 
-#include 
-
-
 /*
  * All the VHDX formats on disk are little endian - the following
  * are helper import/export functions to correctly convert
diff --git a/block/vhdx.c b/block/vhdx.c
index 75ef2b1..0ba2f0a 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -25,8 +25,7 @@
 #include "qemu/bswap.h"
 #include "block/vhdx.h"
 #include "migration/migration.h"
-
-#include 
+#include "qemu/uuid.h"
 
 /* Options for VHDX creation */
 
@@ -213,11 +212,11 @@ bool vhdx_checksum_is_valid(uint8_t *buf, size_t size, 
int crc_offset)
  */
 void vhdx_guid_generate(MSGUID *guid)
 {
-uuid_t uuid;
+QemuUUID uuid;
 assert(guid != NULL);
 
-uuid_generate(uuid);
-memcpy(guid, uuid, sizeof(MSGUID));
+qemu_uuid_generate();
+memcpy(guid, , sizeof(MSGUID));
 }
 
 /* Check for region overlaps inside the VHDX image */
diff --git a/configure b/configure
index 7d083bd..b71b80a 100755
--- a/configure
+++ b/configure
@@ -317,7 +317,6 @@ vte=""
 virglrenderer=""
 tpm="yes"
 libssh2=""
-vhdx=""
 numa=""
 tcmalloc="no"
 jemalloc="no"
@@ -1103,6 +1102,9 @@ for opt do
   --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
   echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
   ;;
+  --enable-vhdx|--disable-vhdx)
+  echo "$0: $opt is obsolete, VHDX driver is always built" >&2
+  ;;
   --disable-gtk) gtk="no"
   ;;
   --enable-gtk) gtk="yes"
@@ -1143,10 +1145,6 @@ for opt do
   ;;
   --enable-libssh2) libssh2="yes"
   ;;
-  --enable-vhdx) vhdx="yes"
-  ;;
-  --disable-vhdx) vhdx="no"
-  ;;
   --disable-numa) numa="no"
   ;;
   --enable-numa) numa="yes"
@@ -1389,7 +1387,6 @@ disabled with --disable-FEATURE, default is enabled if 
available:
   archipelago Archipelago backend
   tpm TPM support
   libssh2 ssh block device support
-  vhdxsupport for the Microsoft VHDX image format
   numalibnuma support
   tcmalloctcmalloc support
   jemallocjemalloc support
@@ -2690,19 +2687,6 @@ EOF
   fi
 fi
 
-if test "$vhdx" = "yes" ; then
-if test "$uuid" = "no" ; then
-error_exit "uuid required for VHDX support"
-fi
-elif test "$vhdx" != "no" ; then
-if test "$uuid" = "yes" ; then
-vhdx=yes
-else
-vhdx=no
-fi
-fi
-
-##
 # xfsctl() probe, used for raw-posix
 if test "$xfs" != "no" ; then
   cat > $TMPC << EOF
@@ -4918,7 +4902,6 @@ echo "TPM support   $tpm"
 echo "libssh2 support   $libssh2"
 echo "TPM passthrough   $tpm_passthrough"
 echo "QOM debugging $qom_cast_debug"
-echo "vhdx  $vhdx"
 echo "lzo support   $lzo"
 echo "snappy support$snappy"
 echo "bzip2 support $bzip2"
@@ -5443,10 +5426,6 @@ if test "$libssh2" = "yes" ; then
   echo "LIBSSH2_LIBS=$libssh2_libs" >> $config_host_mak
 fi
 
-if test "$vhdx" = "yes" ; then
-  echo "CONFIG_VHDX=y" >> $config_host_mak
-fi
-
 # USB host support
 if test "$libusb" = "yes"; then
   echo "HOST_USB=libusb legacy" >> $config_host_mak
-- 
2.7.4




[Qemu-devel] [PATCH v8 09/12] vl: Switch qemu_uuid to QemuUUID

2016-09-17 Thread Fam Zheng
Update all qemu_uuid users as well, especially get rid of the duplicated
low level g_strdup_printf, sscanf and snprintf calls with QEMU UUID API.

Since qemu_uuid_parse is quite tangled with qemu_uuid, its switching to
QemuUUID is done here too to keep everything in sync and avoid code
churn.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 hw/ipmi/ipmi_bmc_sim.c |  2 +-
 hw/nvram/fw_cfg.c  |  2 +-
 hw/ppc/spapr.c |  7 +--
 hw/ppc/spapr_rtas.c|  3 ++-
 hw/smbios/smbios.c | 12 ++--
 hw/xenpv/xen_domainbuild.c |  6 +-
 include/qemu/uuid.h|  2 +-
 include/sysemu/sysemu.h|  3 ++-
 qmp.c  | 10 ++
 ui/spice-core.c|  2 +-
 util/uuid.c| 11 ++-
 vl.c   |  6 +++---
 12 files changed, 27 insertions(+), 39 deletions(-)

diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
index dc9c14c..17c7c0e 100644
--- a/hw/ipmi/ipmi_bmc_sim.c
+++ b/hw/ipmi/ipmi_bmc_sim.c
@@ -1773,7 +1773,7 @@ static void ipmi_sim_realize(DeviceState *dev, Error 
**errp)
 ibs->acpi_power_state[1] = 0;
 
 if (qemu_uuid_set) {
-memcpy(>uuid, qemu_uuid, 16);
+memcpy(>uuid, _uuid, 16);
 } else {
 memset(>uuid, 0, 16);
 }
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 1776b1b..92aa563 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -883,7 +883,7 @@ static void fw_cfg_init1(DeviceState *dev)
 qdev_init_nofail(dev);
 
 fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (char *)"QEMU", 4);
-fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
+fw_cfg_add_bytes(s, FW_CFG_UUID, _uuid, 16);
 fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)!machine->enable_graphics);
 fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
 fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index ca77bb0..bdb689c 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -332,12 +332,7 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,
 g_free(buf);
 }
 
-buf = g_strdup_printf(UUID_FMT, qemu_uuid[0], qemu_uuid[1],
-  qemu_uuid[2], qemu_uuid[3], qemu_uuid[4],
-  qemu_uuid[5], qemu_uuid[6], qemu_uuid[7],
-  qemu_uuid[8], qemu_uuid[9], qemu_uuid[10],
-  qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
-  qemu_uuid[14], qemu_uuid[15]);
+buf = qemu_uuid_unparse_strdup(_uuid);
 
 _FDT((fdt_property_string(fdt, "vm,uuid", buf)));
 if (qemu_uuid_set) {
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index 27b5ad4..02ce273 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -303,7 +303,8 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,
 break;
 }
 case RTAS_SYSPARM_UUID:
-ret = sysparm_st(buffer, length, qemu_uuid, (qemu_uuid_set ? 16 : 0));
+ret = sysparm_st(buffer, length, (unsigned char *)_uuid,
+ (qemu_uuid_set ? 16 : 0));
 break;
 default:
 ret = RTAS_OUT_NOT_SUPPORTED;
diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 0705eb1..9a6552a 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -80,7 +80,7 @@ static struct {
 
 static struct {
 const char *manufacturer, *product, *version, *serial, *sku, *family;
-/* uuid is in qemu_uuid[] */
+/* uuid is in qemu_uuid */
 } type1;
 
 static struct {
@@ -409,7 +409,7 @@ static void smbios_build_type_1_fields(void)
  * BIOS.
  */
 smbios_add_field(1, offsetof(struct smbios_type_1, uuid),
- qemu_uuid, 16);
+ _uuid, 16);
 }
 }
 
@@ -484,9 +484,9 @@ static void smbios_build_type_0_table(void)
 /* Encode UUID from the big endian encoding described on RFC4122 to the wire
  * format specified by SMBIOS version 2.6.
  */
-static void smbios_encode_uuid(struct smbios_uuid *uuid, const uint8_t *buf)
+static void smbios_encode_uuid(struct smbios_uuid *uuid, QemuUUID *in)
 {
-memcpy(uuid, buf, 16);
+memcpy(uuid, , 16);
 if (smbios_uuid_encoded) {
 uuid->time_low = bswap32(uuid->time_low);
 uuid->time_mid = bswap16(uuid->time_mid);
@@ -503,7 +503,7 @@ static void smbios_build_type_1_table(void)
 SMBIOS_TABLE_SET_STR(1, version_str, type1.version);
 SMBIOS_TABLE_SET_STR(1, serial_number_str, type1.serial);
 if (qemu_uuid_set) {
-smbios_encode_uuid(>uuid, qemu_uuid);
+smbios_encode_uuid(>uuid, _uuid);
 } else {
 memset(>uuid, 0, 16);
 }
@@ -1002,7 +1002,7 @@ void smbios_entry_add(QemuOpts *opts)
 
 val = qemu_opt_get(opts, "uuid");
 if (val) {
-if (qemu_uuid_parse(val, qemu_uuid) != 0) {
+if (qemu_uuid_parse(val, _uuid) != 0) {
 

[Qemu-devel] [PATCH v8 12/12] Add UUID files to MAINTAINERS

2016-09-17 Thread Fam Zheng
I understand that we've been keeping eyes on the uncovered files. Since
I'm adding some more files I volunteer to look after them in the futuer.

Signed-off-by: Fam Zheng 
---
 MAINTAINERS | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 7d43026..764d2e4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1333,6 +1333,12 @@ F: include/qemu/throttle.h
 F: util/throttle.c
 L: qemu-bl...@nongnu.org
 
+UUID
+M: Fam Zheng 
+S: Supported
+F: util/uuid.c
+F: include/qemu/uuid.h
+
 Usermode Emulation
 --
 Overall
-- 
2.7.4




[Qemu-devel] [PATCH v8 08/12] configure: Remove detection code for UUID

2016-09-17 Thread Fam Zheng
All code now uses built-in UUID implementation. Remove the code of
libuuid and make --enable-uuid and --disable-uuid only print a message.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 configure | 43 ---
 1 file changed, 4 insertions(+), 39 deletions(-)

diff --git a/configure b/configure
index b71b80a..f12e809 100755
--- a/configure
+++ b/configure
@@ -212,7 +212,6 @@ sdlabi=""
 virtfs=""
 vnc="yes"
 sparse="no"
-uuid=""
 vde=""
 vnc_sasl=""
 vnc_jpeg=""
@@ -886,10 +885,6 @@ for opt do
   ;;
   --disable-slirp) slirp="no"
   ;;
-  --disable-uuid) uuid="no"
-  ;;
-  --enable-uuid) uuid="yes"
-  ;;
   --disable-vde) vde="no"
   ;;
   --enable-vde) vde="yes"
@@ -1105,6 +1100,9 @@ for opt do
   --enable-vhdx|--disable-vhdx)
   echo "$0: $opt is obsolete, VHDX driver is always built" >&2
   ;;
+  --enable-uuid|--disable-uuid)
+  echo "$0: $opt is obsolete, UUID support is always built" >&2
+  ;;
   --disable-gtk) gtk="no"
   ;;
   --enable-gtk) gtk="yes"
@@ -1363,7 +1361,6 @@ disabled with --disable-FEATURE, default is enabled if 
available:
   bluez   bluez stack connectivity
   kvm KVM acceleration support
   rdmaRDMA-based migration support
-  uuiduuid support
   vde support for vde network
   netmap  support for netmap network
   linux-aio   Linux AIO support
@@ -2659,34 +2656,6 @@ if compile_prog "" "" ; then
 fi
 
 ##
-# uuid_generate() probe, used for vdi block driver
-# Note that on some systems (notably MacOSX) no extra library
-# need be linked to get the uuid functions.
-if test "$uuid" != "no" ; then
-  uuid_libs="-luuid"
-  cat > $TMPC << EOF
-#include 
-int main(void)
-{
-uuid_t my_uuid;
-uuid_generate(my_uuid);
-return 0;
-}
-EOF
-  if compile_prog "" "" ; then
-uuid="yes"
-  elif compile_prog "" "$uuid_libs" ; then
-uuid="yes"
-libs_softmmu="$uuid_libs $libs_softmmu"
-libs_tools="$uuid_libs $libs_tools"
-  else
-if test "$uuid" = "yes" ; then
-  feature_not_found "uuid" "Install libuuid devel"
-fi
-uuid=no
-  fi
-fi
-
 # xfsctl() probe, used for raw-posix
 if test "$xfs" != "no" ; then
   cat > $TMPC << EOF
@@ -4059,7 +4028,7 @@ EOF
   if compile_prog "$vss_win32_include" "" ; then
 guest_agent_with_vss="yes"
 QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
-libs_qga="-lole32 -loleaut32 -lshlwapi -luuid -lstdc++ 
-Wl,--enable-stdcall-fixup $libs_qga"
+libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup 
$libs_qga"
 qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"
   else
 if test "$vss_win32_sdk" != "" ; then
@@ -4868,7 +4837,6 @@ echo "preadv support$preadv"
 echo "fdatasync $fdatasync"
 echo "madvise   $madvise"
 echo "posix_madvise $posix_madvise"
-echo "uuid support  $uuid"
 echo "libcap-ng support $cap_ng"
 echo "vhost-net support $vhost_net"
 echo "vhost-scsi support $vhost_scsi"
@@ -5058,9 +5026,6 @@ fi
 if test "$fnmatch" = "yes" ; then
   echo "CONFIG_FNMATCH=y" >> $config_host_mak
 fi
-if test "$uuid" = "yes" ; then
-  echo "CONFIG_UUID=y" >> $config_host_mak
-fi
 if test "$xfs" = "yes" ; then
   echo "CONFIG_XFS=y" >> $config_host_mak
 fi
-- 
2.7.4




[Qemu-devel] [PATCH v8 07/12] tests: No longer dependent on CONFIG_UUID

2016-09-17 Thread Fam Zheng
crypto now uses built-in uuid implementation, so this check is not
needed.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 tests/test-crypto-block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/test-crypto-block.c b/tests/test-crypto-block.c
index a38110d..1957a86 100644
--- a/tests/test-crypto-block.c
+++ b/tests/test-crypto-block.c
@@ -28,7 +28,7 @@
 #include 
 #endif
 
-#if defined(CONFIG_UUID) && (defined(_WIN32) || defined RUSAGE_THREAD)
+#if (defined(_WIN32) || defined RUSAGE_THREAD)
 #define TEST_LUKS
 #else
 #undef TEST_LUKS
-- 
2.7.4




[Qemu-devel] [PATCH v8 01/12] util: Add UUID API

2016-09-17 Thread Fam Zheng
A number of different places across the code base use CONFIG_UUID. Some
of them are soft dependency, some are not built if libuuid is not
available, some come with dummy fallback, some throws runtime error.

It is hard to maintain, and hard to reason for users.

Since UUID is a simple standard with only a small number of operations,
it is cleaner to have a central support in libqemuutil. This patch adds
qemu_uuid_* functions that all uuid users in the code base can
rely on. Except for qemu_uuid_generate which is new code, all other
functions are just copy from existing fallbacks from other files.

Note that qemu_uuid_parse is moved without updating the function
signature to use QemuUUID, to keep this patch simple.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 arch_init.c | 19 ---
 block/iscsi.c   |  2 +-
 hw/smbios/smbios.c  |  1 +
 include/qemu/uuid.h | 59 
 include/sysemu/sysemu.h |  4 ---
 qmp.c   |  1 +
 stubs/uuid.c|  2 +-
 util/Makefile.objs  |  1 +
 util/uuid.c | 91 +
 vl.c|  1 +
 10 files changed, 156 insertions(+), 25 deletions(-)
 create mode 100644 include/qemu/uuid.h
 create mode 100644 util/uuid.c

diff --git a/arch_init.c b/arch_init.c
index fa05973..5cc58b2 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -235,25 +235,6 @@ void audio_init(void)
 }
 }
 
-int qemu_uuid_parse(const char *str, uint8_t *uuid)
-{
-int ret;
-
-if (strlen(str) != 36) {
-return -1;
-}
-
-ret = sscanf(str, UUID_FMT, [0], [1], [2], [3],
- [4], [5], [6], [7], [8], [9],
- [10], [11], [12], [13], [14],
- [15]);
-
-if (ret != 16) {
-return -1;
-}
-return 0;
-}
-
 void do_acpitable_option(const QemuOpts *opts)
 {
 #ifdef TARGET_I386
diff --git a/block/iscsi.c b/block/iscsi.c
index 95ce9e1..961ac76 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -36,7 +36,7 @@
 #include "block/block_int.h"
 #include "block/scsi.h"
 #include "qemu/iov.h"
-#include "sysemu/sysemu.h"
+#include "qemu/uuid.h"
 #include "qmp-commands.h"
 #include "qapi/qmp/qstring.h"
 #include "crypto/secret.h"
diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 74c7102..0705eb1 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -20,6 +20,7 @@
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
 #include "sysemu/sysemu.h"
+#include "qemu/uuid.h"
 #include "sysemu/cpus.h"
 #include "hw/smbios/smbios.h"
 #include "hw/loader.h"
diff --git a/include/qemu/uuid.h b/include/qemu/uuid.h
new file mode 100644
index 000..bc0601e
--- /dev/null
+++ b/include/qemu/uuid.h
@@ -0,0 +1,59 @@
+/*
+ *  QEMU UUID functions
+ *
+ *  Copyright 2016 Red Hat, Inc.
+ *
+ *  Authors:
+ *   Fam Zheng 
+ *
+ * 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.
+ *
+ */
+
+#ifndef QEMU_UUID_H
+#define QEMU_UUID_H
+
+#include "qemu-common.h"
+
+/* Version 4 UUID (pseudo random numbers), RFC4122 4.4. */
+
+typedef struct {
+union {
+unsigned char data[16];
+struct {
+/* Generated in BE endian, can be swapped with qemu_uuid_bswap. */
+uint32_t time_low;
+uint16_t time_mid;
+uint16_t time_high_and_version;
+uint8_t  clock_seq_and_reserved;
+uint8_t  clock_seq_low;
+uint8_t  node[6];
+} fields;
+};
+} QemuUUID;
+
+#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-" \
+ "%02hhx%02hhx-%02hhx%02hhx-" \
+ "%02hhx%02hhx-" \
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
+
+#define UUID_FMT_LEN 36
+
+#define UUID_NONE "----"
+
+void qemu_uuid_generate(QemuUUID *out);
+
+int qemu_uuid_is_null(const QemuUUID *uu);
+
+void qemu_uuid_unparse(const QemuUUID *uuid, char *out);
+
+char *qemu_uuid_unparse_strdup(const QemuUUID *uuid);
+
+int qemu_uuid_parse(const char *str, uint8_t *uuid);
+
+void qemu_uuid_bswap(QemuUUID *uuid);
+
+#endif
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index ee7c760..6111950 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -18,10 +18,6 @@ extern const char *bios_name;
 extern const char *qemu_name;
 extern uint8_t qemu_uuid[];
 extern bool qemu_uuid_set;
-int qemu_uuid_parse(const char *str, uint8_t *uuid);
-
-#define UUID_FMT 
"%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
-#define UUID_NONE "----"
 
 bool runstate_check(RunState state);
 void runstate_set(RunState new_state);
diff --git a/qmp.c b/qmp.c
index 

[Qemu-devel] [PATCH v8 06/12] crypto: Switch to QEMU UUID API

2016-09-17 Thread Fam Zheng
The uuid generation doesn't return error, so update the function
signature and calling code accordingly.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 crypto/block-luks.c | 26 +++---
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index aba4455..da65dc0 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -29,10 +29,7 @@
 #include "crypto/pbkdf.h"
 #include "crypto/secret.h"
 #include "crypto/random.h"
-
-#ifdef CONFIG_UUID
-#include 
-#endif
+#include "qemu/uuid.h"
 
 #include "qemu/coroutine.h"
 
@@ -877,18 +874,12 @@ qcrypto_block_luks_open(QCryptoBlock *block,
 }
 
 
-static int
-qcrypto_block_luks_uuid_gen(uint8_t *uuidstr, Error **errp)
+static void
+qcrypto_block_luks_uuid_gen(uint8_t *uuidstr)
 {
-#ifdef CONFIG_UUID
-uuid_t uuid;
-uuid_generate(uuid);
-uuid_unparse(uuid, (char *)uuidstr);
-return 0;
-#else
-error_setg(errp, "Unable to generate uuids on this platform");
-return -1;
-#endif
+QemuUUID uuid;
+qemu_uuid_generate();
+qemu_uuid_unparse(, (char *)uuidstr);
 }
 
 static int
@@ -961,10 +952,7 @@ qcrypto_block_luks_create(QCryptoBlock *block,
  * it out to disk
  */
 luks->header.version = QCRYPTO_BLOCK_LUKS_VERSION;
-if (qcrypto_block_luks_uuid_gen(luks->header.uuid,
-errp) < 0) {
-goto error;
-}
+qcrypto_block_luks_uuid_gen(luks->header.uuid);
 
 cipher_alg = qcrypto_block_luks_cipher_alg_lookup(luks_opts.cipher_alg,
   errp);
-- 
2.7.4




[Qemu-devel] [PATCH v8 02/12] uuid: Make null_uuid static

2016-09-17 Thread Fam Zheng
So that it doesn't have to be zeroed at each call.

Suggested-by: Eric Blake 
Signed-off-by: Fam Zheng 
---
 util/uuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/uuid.c b/util/uuid.c
index 6815904..f0c1eeb 100644
--- a/util/uuid.c
+++ b/util/uuid.c
@@ -40,7 +40,7 @@ void qemu_uuid_generate(QemuUUID *uuid)
 
 int qemu_uuid_is_null(const QemuUUID *uu)
 {
-QemuUUID null_uuid = { 0 };
+static QemuUUID null_uuid;
 return memcmp(uu, _uuid, sizeof(QemuUUID)) == 0;
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH v8 05/12] vpc: Use QEMU UUID API

2016-09-17 Thread Fam Zheng
Previously we conditionally generated footer->uuid, when libuuid was
available. Now that we have a built-in implementation, we can switch to
it.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 block/vpc.c | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/block/vpc.c b/block/vpc.c
index 43707ed..8d5886f 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -30,9 +30,7 @@
 #include "qemu/module.h"
 #include "migration/migration.h"
 #include "qemu/bswap.h"
-#if defined(CONFIG_UUID)
-#include 
-#endif
+#include "qemu/uuid.h"
 
 /**/
 
@@ -89,7 +87,7 @@ typedef struct vhd_footer {
 uint32_tchecksum;
 
 /* UUID used to identify a parent hard disk (backing file) */
-uint8_t uuid[16];
+QemuUUIDuuid;
 
 uint8_t in_saved_state;
 } QEMU_PACKED VHDFooter;
@@ -980,9 +978,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, 
Error **errp)
 
 footer->type = cpu_to_be32(disk_type);
 
-#if defined(CONFIG_UUID)
-uuid_generate(footer->uuid);
-#endif
+qemu_uuid_generate(>uuid);
 
 footer->checksum = cpu_to_be32(vpc_checksum(buf, HEADER_SIZE));
 
-- 
2.7.4




[Qemu-devel] [PATCH v8 00/12] UUID clean ups for 2.8

2016-09-17 Thread Fam Zheng
v8: Fix patchew compiling failure on 32 bit mingw, using QEMU_PTR_IS_ALIGNED.

v7: Address Eric's comments:
01, 03-09: Add Eric's r-b line.
01: Commit message syntax fix.
Remove trailing comma in copyright header.
Remove 'glib.h' inclusion.
02: New patch to make null_uuid.
09: Fix missed qemu_uuid.
Also update "qemu_uuid[]" to "qemu_uuid" in a comment.
10: New patch to make uuid parse more robust against invalid formats.
11: Add test cases suggested by Eric.
Fix unwanted double dashes.
12: Added MAINTAINERS patch.

v6: Fix initializer syntax that is disliked by centos6.

v5: Add union fields in QemuUUID to help the alignment necessary for bswap, and
assert. [Richard]
Update the test case initializer syntax accordingly.

v4: Use memcpy instead of pointer type cast. [Richard]
Keep parameter order consistent with libuuid. [Jeff]
qemu_uuid_convert -> qemu_uuid_bswap. [Jeff]

v3: Negative tests. [Daniel]
Update QemuUUID type from array to struct. [Markus]
Add qemu_uuid_unparse_strdup.
Add qemu_uuid_convert.
Redirect configure obsoleted option message to stderr. [Jeff]
vdi: uuid_convert -> qemu_uuid_convert.
Fix commit message syntax errors in vpc patch. [Jeff]
Further cleanup around qemu_uuid.

v2: Fix the endianness wrongness. [Jeff]
Add tests/test-uuid.c. [Denial]
Add r-b of Stefan Weil to the VDI patch.

The facts how we use libuuid now are not particularly pleasant.

- VHDX driver depends on uuid, but is unconditionally checked in iotests 109.
  If it is not built, the test would fail, leaving no hint about that. In fact
  this even makes the feature implementation a bit ugly because it compromises
  the write protection on block 0 with image probing, silently.

- A few other libuuid users, in block/ and crypto/, use it as an optional
  dependency, and compromises certain functionalities if it is not available.

- On the other hand, there are already a few uuid function fallbacks in those
  callers, as well as some duplicated sscanf, snprintf and g_strdup_printf
  around UUID_FMT, which can be replaced with UUID parse/unparse routines.

So instead of making libuuid a hard requirement, let's simply move the
fallbacks to util and implement the random version of uuid generation, and be
done with it.

Fam

Fam Zheng (12):
  util: Add UUID API
  uuid: Make null_uuid static
  vhdx: Use QEMU UUID API
  vdi: Use QEMU UUID API
  vpc: Use QEMU UUID API
  crypto: Switch to QEMU UUID API
  tests: No longer dependent on CONFIG_UUID
  configure: Remove detection code for UUID
  vl: Switch qemu_uuid to QemuUUID
  uuid: Tighten uuid parse
  tests: Add uuid tests
  Add UUID files to MAINTAINERS

 MAINTAINERS|   6 ++
 arch_init.c|  19 -
 block/Makefile.objs|   2 +-
 block/iscsi.c  |   2 +-
 block/vdi.c|  73 +--
 block/vhdx-endian.c|   3 -
 block/vhdx.c   |   9 +--
 block/vpc.c|  10 +--
 configure  |  70 ++
 crypto/block-luks.c|  26 ++-
 hw/ipmi/ipmi_bmc_sim.c |   2 +-
 hw/nvram/fw_cfg.c  |   2 +-
 hw/ppc/spapr.c |   7 +-
 hw/ppc/spapr_rtas.c|   3 +-
 hw/smbios/smbios.c |  13 ++--
 hw/xenpv/xen_domainbuild.c |   6 +-
 include/qemu/uuid.h|  59 +++
 include/sysemu/sysemu.h|   7 +-
 qmp.c  |  11 +--
 stubs/uuid.c   |   2 +-
 tests/Makefile.include |   2 +
 tests/test-crypto-block.c  |   2 +-
 tests/test-uuid.c  | 177 +
 ui/spice-core.c|   2 +-
 util/Makefile.objs |   1 +
 util/uuid.c| 114 +
 vl.c   |   7 +-
 27 files changed, 424 insertions(+), 213 deletions(-)
 create mode 100644 include/qemu/uuid.h
 create mode 100644 tests/test-uuid.c
 create mode 100644 util/uuid.c

-- 
2.7.4




Re: [Qemu-devel] [PATCH v7 00/12] UUID clean ups for 2.8

2016-09-17 Thread Fam Zheng
On Sat, 09/17 20:16, no-re...@ec2-52-6-146-230.compute-1.amazonaws.com wrote:
> /tmp/qemu-test/src/util/uuid.c: In function 'qemu_uuid_bswap':
> /tmp/qemu-test/src/util/uuid.c:110:7: error: cast from pointer to integer of 
> different size [-Werror=pointer-to-int-cast]
>  assert(QEMU_IS_ALIGNED((uint64_t)uuid, sizeof(uint32_t)));

Changing to QEMU_PTR_IS_ALIGNED.

Fam



[Qemu-devel] [PATCH] Add resolutions via the command-line

2016-09-17 Thread G 3
Add the ability to add resolutions from the command-line. This patch  
works by
looking for a property called 'resolutions' in the options node of  
OpenBIOS.

If it is found all the resolutions are parsed and loaded.

Example command-line:

-prom-env resolutions=512x342,640x480,800x600,1024x600,1200x700,1440x900

Signed-off-by: John Arbuckle 
---
 QemuVGADriver/src/QemuVga.c | 227 ++ 
+-

 1 file changed, 225 insertions(+), 2 deletions(-)

diff --git a/QemuVGADriver/src/QemuVga.c b/QemuVGADriver/src/QemuVga.c
index 4584242..d74fa41 100644
--- a/QemuVGADriver/src/QemuVga.c
+++ b/QemuVGADriver/src/QemuVga.c
@@ -3,6 +3,7 @@
 #include "DriverQDCalls.h"
 #include "QemuVga.h"
 #include 
+#include 

 /* List of supported modes */
 struct vMode {
@@ -18,7 +19,21 @@ static struct vMode vModes[] =  {
{ 1600, 1200 },
{ 1920, 1080 },
{ 1920, 1200 },
-   { 0,0 }
+   
+   /* The rest are place holders */
+   { 0,0 },
+   { 0,0 },
+   { 0,0 },
+   { 0,0 },
+   { 0,0 },
+   { 0,0 },
+   { 0,0 },
+   { 0,0 },
+   { 0,0 },
+   { 0,0 },
+   { 0,0 },
+   { 0,0 },
+   { 0,0 },
 };

 static void VgaWriteB(UInt16 port, UInt8 val)
@@ -147,11 +162,219 @@ static InterruptMemberNumber  
PCIInterruptHandler(InterruptSetMember ISTmember,

 }
 #endif

+/*
+ * Get the resolution set at the specified index.
+ * The string returned needs to be freed when no longer used.
+ */
+static char *get_set(const char *resolution_set_str, int set_number)
+{
+   const int max_buf_size = 100;
+   char c, *buffer;
+   int index, comma_count;
+
+   buffer = (char *) malloc(max_buf_size);
+   comma_count = 0;
+   index = 0;
+   set_number++; /* Makes things easier to understand */
+
+   c = *(resolution_set_str++);
+   while (c != '\0') {
+   buffer[index++] = c;
+   c = *(resolution_set_str++);
+   if (c == ',') {
+   comma_count++;
+   if (comma_count == set_number || index >= max_buf_size) 
{
+   buffer[index] = '\0';
+   return buffer;
+   }
+   
+   else {
+   /* reset the buffer */
+   index = 0;
+   c = *(resolution_set_str++);
+   }
+   }
+   }
+   
+   buffer[index] = '\0';
+
+   return buffer;
+}
+
+/*
+ * Get the number of resolution sets
+ */
+
+static int get_set_count(const char *resolution_sets_str)
+{
+   char c;
+   int count;
+   
+   /* Count the number of commas */
+   count = 0;
+   c = *(resolution_sets_str++);
+   while (c != '\0') {
+   if (c == ',') {
+   count++;
+   }
+   c = *(resolution_sets_str++);
+   }
+
+   return count + 1;
+}
+
+/*
+ * Returns the width value of a resolution set
+ * Example:
+ * input: 16000x9000
+ * output: 16000
+ */
+
+static int get_width(const char *resolution_str)
+{
+   int index;
+   char c;
+   const int max_buf_size = 25;
+   char buffer[max_buf_size];
+   c = *(resolution_str++);
+   index = 0;
+   while (c != 'x' && index < max_buf_size) {
+   buffer[index++] = c;
+   c = *(resolution_str++);
+   }
+   
+   /* Terminate string */
+   buffer[index] = '\0';
+   
+   return atoi(buffer);
+}
+
+/*
+ * Returns the height value of a resolution set
+ * Example
+ * input: 16000x9000
+ * output: 9000
+ */
+
+static int get_height(const char *resolution_str)
+{
+   int index;
+   char c;
+   const int max_buf_size = 25;
+   char buffer[max_buf_size];
+   
+   /* skip to character after x */
+   while (*resolution_str != 'x') {
+   resolution_str++;
+   }
+   resolution_str++;
+   
+   /* Add digits of the height to the buffer */
+   index = 0;
+   c = *(resolution_str++);
+   while (c != '\0') {
+   buffer[index++] = c;
+   c = *(resolution_str++);
+   if(index >= max_buf_size) {
+   break;
+   }
+   }
+   
+   /* Terminate string */
+   buffer[index] = '\0';
+   
+   return atoi(buffer);
+}
+
+/*
+ * Looks in the /chosen node for the value of the resolutions property
+ */
+static int add_user_resolutions(void)
+{  
+   RegEntryID *entry_id;
+   OSErr err;
+   Boolean is_done;
+   void *value;
+   RegPropertyValueSize property_size;
+   int index, res_set_count;
+   char *set_str;
+   
+   #define PROPERTY_NAME "resolutions"
+   #define NODE_PATH "Devices:device-tree:options"
+
+   /* init the entry variable */
+  

[Qemu-devel] [PATCH v7 09/12] vl: Switch qemu_uuid to QemuUUID

2016-09-17 Thread Fam Zheng
Update all qemu_uuid users as well, especially get rid of the duplicated
low level g_strdup_printf, sscanf and snprintf calls with QEMU UUID API.

Since qemu_uuid_parse is quite tangled with qemu_uuid, its switching to
QemuUUID is done here too to keep everything in sync and avoid code
churn.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 hw/ipmi/ipmi_bmc_sim.c |  2 +-
 hw/nvram/fw_cfg.c  |  2 +-
 hw/ppc/spapr.c |  7 +--
 hw/ppc/spapr_rtas.c|  3 ++-
 hw/smbios/smbios.c | 12 ++--
 hw/xenpv/xen_domainbuild.c |  6 +-
 include/qemu/uuid.h|  2 +-
 include/sysemu/sysemu.h|  3 ++-
 qmp.c  | 10 ++
 ui/spice-core.c|  2 +-
 util/uuid.c| 11 ++-
 vl.c   |  6 +++---
 12 files changed, 27 insertions(+), 39 deletions(-)

diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
index dc9c14c..17c7c0e 100644
--- a/hw/ipmi/ipmi_bmc_sim.c
+++ b/hw/ipmi/ipmi_bmc_sim.c
@@ -1773,7 +1773,7 @@ static void ipmi_sim_realize(DeviceState *dev, Error 
**errp)
 ibs->acpi_power_state[1] = 0;
 
 if (qemu_uuid_set) {
-memcpy(>uuid, qemu_uuid, 16);
+memcpy(>uuid, _uuid, 16);
 } else {
 memset(>uuid, 0, 16);
 }
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 1776b1b..92aa563 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -883,7 +883,7 @@ static void fw_cfg_init1(DeviceState *dev)
 qdev_init_nofail(dev);
 
 fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (char *)"QEMU", 4);
-fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
+fw_cfg_add_bytes(s, FW_CFG_UUID, _uuid, 16);
 fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)!machine->enable_graphics);
 fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
 fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index ca77bb0..bdb689c 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -332,12 +332,7 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,
 g_free(buf);
 }
 
-buf = g_strdup_printf(UUID_FMT, qemu_uuid[0], qemu_uuid[1],
-  qemu_uuid[2], qemu_uuid[3], qemu_uuid[4],
-  qemu_uuid[5], qemu_uuid[6], qemu_uuid[7],
-  qemu_uuid[8], qemu_uuid[9], qemu_uuid[10],
-  qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
-  qemu_uuid[14], qemu_uuid[15]);
+buf = qemu_uuid_unparse_strdup(_uuid);
 
 _FDT((fdt_property_string(fdt, "vm,uuid", buf)));
 if (qemu_uuid_set) {
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index 27b5ad4..02ce273 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -303,7 +303,8 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,
 break;
 }
 case RTAS_SYSPARM_UUID:
-ret = sysparm_st(buffer, length, qemu_uuid, (qemu_uuid_set ? 16 : 0));
+ret = sysparm_st(buffer, length, (unsigned char *)_uuid,
+ (qemu_uuid_set ? 16 : 0));
 break;
 default:
 ret = RTAS_OUT_NOT_SUPPORTED;
diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 0705eb1..9a6552a 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -80,7 +80,7 @@ static struct {
 
 static struct {
 const char *manufacturer, *product, *version, *serial, *sku, *family;
-/* uuid is in qemu_uuid[] */
+/* uuid is in qemu_uuid */
 } type1;
 
 static struct {
@@ -409,7 +409,7 @@ static void smbios_build_type_1_fields(void)
  * BIOS.
  */
 smbios_add_field(1, offsetof(struct smbios_type_1, uuid),
- qemu_uuid, 16);
+ _uuid, 16);
 }
 }
 
@@ -484,9 +484,9 @@ static void smbios_build_type_0_table(void)
 /* Encode UUID from the big endian encoding described on RFC4122 to the wire
  * format specified by SMBIOS version 2.6.
  */
-static void smbios_encode_uuid(struct smbios_uuid *uuid, const uint8_t *buf)
+static void smbios_encode_uuid(struct smbios_uuid *uuid, QemuUUID *in)
 {
-memcpy(uuid, buf, 16);
+memcpy(uuid, , 16);
 if (smbios_uuid_encoded) {
 uuid->time_low = bswap32(uuid->time_low);
 uuid->time_mid = bswap16(uuid->time_mid);
@@ -503,7 +503,7 @@ static void smbios_build_type_1_table(void)
 SMBIOS_TABLE_SET_STR(1, version_str, type1.version);
 SMBIOS_TABLE_SET_STR(1, serial_number_str, type1.serial);
 if (qemu_uuid_set) {
-smbios_encode_uuid(>uuid, qemu_uuid);
+smbios_encode_uuid(>uuid, _uuid);
 } else {
 memset(>uuid, 0, 16);
 }
@@ -1002,7 +1002,7 @@ void smbios_entry_add(QemuOpts *opts)
 
 val = qemu_opt_get(opts, "uuid");
 if (val) {
-if (qemu_uuid_parse(val, qemu_uuid) != 0) {
+if (qemu_uuid_parse(val, _uuid) != 0) {
 

[Qemu-devel] [PATCH v7 08/12] configure: Remove detection code for UUID

2016-09-17 Thread Fam Zheng
All code now uses built-in UUID implementation. Remove the code of
libuuid and make --enable-uuid and --disable-uuid only print a message.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 configure | 43 ---
 1 file changed, 4 insertions(+), 39 deletions(-)

diff --git a/configure b/configure
index b71b80a..f12e809 100755
--- a/configure
+++ b/configure
@@ -212,7 +212,6 @@ sdlabi=""
 virtfs=""
 vnc="yes"
 sparse="no"
-uuid=""
 vde=""
 vnc_sasl=""
 vnc_jpeg=""
@@ -886,10 +885,6 @@ for opt do
   ;;
   --disable-slirp) slirp="no"
   ;;
-  --disable-uuid) uuid="no"
-  ;;
-  --enable-uuid) uuid="yes"
-  ;;
   --disable-vde) vde="no"
   ;;
   --enable-vde) vde="yes"
@@ -1105,6 +1100,9 @@ for opt do
   --enable-vhdx|--disable-vhdx)
   echo "$0: $opt is obsolete, VHDX driver is always built" >&2
   ;;
+  --enable-uuid|--disable-uuid)
+  echo "$0: $opt is obsolete, UUID support is always built" >&2
+  ;;
   --disable-gtk) gtk="no"
   ;;
   --enable-gtk) gtk="yes"
@@ -1363,7 +1361,6 @@ disabled with --disable-FEATURE, default is enabled if 
available:
   bluez   bluez stack connectivity
   kvm KVM acceleration support
   rdmaRDMA-based migration support
-  uuiduuid support
   vde support for vde network
   netmap  support for netmap network
   linux-aio   Linux AIO support
@@ -2659,34 +2656,6 @@ if compile_prog "" "" ; then
 fi
 
 ##
-# uuid_generate() probe, used for vdi block driver
-# Note that on some systems (notably MacOSX) no extra library
-# need be linked to get the uuid functions.
-if test "$uuid" != "no" ; then
-  uuid_libs="-luuid"
-  cat > $TMPC << EOF
-#include 
-int main(void)
-{
-uuid_t my_uuid;
-uuid_generate(my_uuid);
-return 0;
-}
-EOF
-  if compile_prog "" "" ; then
-uuid="yes"
-  elif compile_prog "" "$uuid_libs" ; then
-uuid="yes"
-libs_softmmu="$uuid_libs $libs_softmmu"
-libs_tools="$uuid_libs $libs_tools"
-  else
-if test "$uuid" = "yes" ; then
-  feature_not_found "uuid" "Install libuuid devel"
-fi
-uuid=no
-  fi
-fi
-
 # xfsctl() probe, used for raw-posix
 if test "$xfs" != "no" ; then
   cat > $TMPC << EOF
@@ -4059,7 +4028,7 @@ EOF
   if compile_prog "$vss_win32_include" "" ; then
 guest_agent_with_vss="yes"
 QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
-libs_qga="-lole32 -loleaut32 -lshlwapi -luuid -lstdc++ 
-Wl,--enable-stdcall-fixup $libs_qga"
+libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup 
$libs_qga"
 qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"
   else
 if test "$vss_win32_sdk" != "" ; then
@@ -4868,7 +4837,6 @@ echo "preadv support$preadv"
 echo "fdatasync $fdatasync"
 echo "madvise   $madvise"
 echo "posix_madvise $posix_madvise"
-echo "uuid support  $uuid"
 echo "libcap-ng support $cap_ng"
 echo "vhost-net support $vhost_net"
 echo "vhost-scsi support $vhost_scsi"
@@ -5058,9 +5026,6 @@ fi
 if test "$fnmatch" = "yes" ; then
   echo "CONFIG_FNMATCH=y" >> $config_host_mak
 fi
-if test "$uuid" = "yes" ; then
-  echo "CONFIG_UUID=y" >> $config_host_mak
-fi
 if test "$xfs" = "yes" ; then
   echo "CONFIG_XFS=y" >> $config_host_mak
 fi
-- 
2.7.4




[Qemu-devel] [PATCH v7 06/12] crypto: Switch to QEMU UUID API

2016-09-17 Thread Fam Zheng
The uuid generation doesn't return error, so update the function
signature and calling code accordingly.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 crypto/block-luks.c | 26 +++---
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index aba4455..da65dc0 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -29,10 +29,7 @@
 #include "crypto/pbkdf.h"
 #include "crypto/secret.h"
 #include "crypto/random.h"
-
-#ifdef CONFIG_UUID
-#include 
-#endif
+#include "qemu/uuid.h"
 
 #include "qemu/coroutine.h"
 
@@ -877,18 +874,12 @@ qcrypto_block_luks_open(QCryptoBlock *block,
 }
 
 
-static int
-qcrypto_block_luks_uuid_gen(uint8_t *uuidstr, Error **errp)
+static void
+qcrypto_block_luks_uuid_gen(uint8_t *uuidstr)
 {
-#ifdef CONFIG_UUID
-uuid_t uuid;
-uuid_generate(uuid);
-uuid_unparse(uuid, (char *)uuidstr);
-return 0;
-#else
-error_setg(errp, "Unable to generate uuids on this platform");
-return -1;
-#endif
+QemuUUID uuid;
+qemu_uuid_generate();
+qemu_uuid_unparse(, (char *)uuidstr);
 }
 
 static int
@@ -961,10 +952,7 @@ qcrypto_block_luks_create(QCryptoBlock *block,
  * it out to disk
  */
 luks->header.version = QCRYPTO_BLOCK_LUKS_VERSION;
-if (qcrypto_block_luks_uuid_gen(luks->header.uuid,
-errp) < 0) {
-goto error;
-}
+qcrypto_block_luks_uuid_gen(luks->header.uuid);
 
 cipher_alg = qcrypto_block_luks_cipher_alg_lookup(luks_opts.cipher_alg,
   errp);
-- 
2.7.4




[Qemu-devel] [PATCH v7 04/12] vdi: Use QEMU UUID API

2016-09-17 Thread Fam Zheng
The UUID operations we need from libuuid are fully supported by QEMU UUID
implementation. Use it, and remove the unused code.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 block/vdi.c | 73 ++---
 1 file changed, 17 insertions(+), 56 deletions(-)

diff --git a/block/vdi.c b/block/vdi.c
index 8a1cf97..96b78d5 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -58,14 +58,7 @@
 #include "migration/migration.h"
 #include "qemu/coroutine.h"
 #include "qemu/cutils.h"
-
-#if defined(CONFIG_UUID)
-#include 
-#else
-/* TODO: move uuid emulation to some central place in QEMU. */
-#include "sysemu/sysemu.h" /* UUID_FMT */
-typedef unsigned char uuid_t[16];
-#endif
+#include "qemu/uuid.h"
 
 /* Code configuration options. */
 
@@ -140,28 +133,6 @@ typedef unsigned char uuid_t[16];
 #define VDI_DISK_SIZE_MAX((uint64_t)VDI_BLOCKS_IN_IMAGE_MAX * \
   (uint64_t)DEFAULT_CLUSTER_SIZE)
 
-#if !defined(CONFIG_UUID)
-static inline void uuid_generate(uuid_t out)
-{
-memset(out, 0, sizeof(uuid_t));
-}
-
-static inline int uuid_is_null(const uuid_t uu)
-{
-uuid_t null_uuid = { 0 };
-return memcmp(uu, null_uuid, sizeof(uuid_t)) == 0;
-}
-
-# if defined(CONFIG_VDI_DEBUG)
-static inline void uuid_unparse(const uuid_t uu, char *out)
-{
-snprintf(out, 37, UUID_FMT,
-uu[0], uu[1], uu[2], uu[3], uu[4], uu[5], uu[6], uu[7],
-uu[8], uu[9], uu[10], uu[11], uu[12], uu[13], uu[14], uu[15]);
-}
-# endif
-#endif
-
 typedef struct {
 char text[0x40];
 uint32_t signature;
@@ -182,10 +153,10 @@ typedef struct {
 uint32_t block_extra;   /* unused here */
 uint32_t blocks_in_image;
 uint32_t blocks_allocated;
-uuid_t uuid_image;
-uuid_t uuid_last_snap;
-uuid_t uuid_link;
-uuid_t uuid_parent;
+QemuUUID uuid_image;
+QemuUUID uuid_last_snap;
+QemuUUID uuid_link;
+QemuUUID uuid_parent;
 uint64_t unused2[7];
 } QEMU_PACKED VdiHeader;
 
@@ -206,16 +177,6 @@ typedef struct {
 Error *migration_blocker;
 } BDRVVdiState;
 
-/* Change UUID from little endian (IPRT = VirtualBox format) to big endian
- * format (network byte order, standard, see RFC 4122) and vice versa.
- */
-static void uuid_convert(uuid_t uuid)
-{
-bswap32s((uint32_t *)[0]);
-bswap16s((uint16_t *)[4]);
-bswap16s((uint16_t *)[6]);
-}
-
 static void vdi_header_to_cpu(VdiHeader *header)
 {
 le32_to_cpus(>signature);
@@ -234,10 +195,10 @@ static void vdi_header_to_cpu(VdiHeader *header)
 le32_to_cpus(>block_extra);
 le32_to_cpus(>blocks_in_image);
 le32_to_cpus(>blocks_allocated);
-uuid_convert(header->uuid_image);
-uuid_convert(header->uuid_last_snap);
-uuid_convert(header->uuid_link);
-uuid_convert(header->uuid_parent);
+qemu_uuid_bswap(>uuid_image);
+qemu_uuid_bswap(>uuid_last_snap);
+qemu_uuid_bswap(>uuid_link);
+qemu_uuid_bswap(>uuid_parent);
 }
 
 static void vdi_header_to_le(VdiHeader *header)
@@ -258,10 +219,10 @@ static void vdi_header_to_le(VdiHeader *header)
 cpu_to_le32s(>block_extra);
 cpu_to_le32s(>blocks_in_image);
 cpu_to_le32s(>blocks_allocated);
-uuid_convert(header->uuid_image);
-uuid_convert(header->uuid_last_snap);
-uuid_convert(header->uuid_link);
-uuid_convert(header->uuid_parent);
+qemu_uuid_bswap(>uuid_image);
+qemu_uuid_bswap(>uuid_last_snap);
+qemu_uuid_bswap(>uuid_link);
+qemu_uuid_bswap(>uuid_parent);
 }
 
 #if defined(CONFIG_VDI_DEBUG)
@@ -469,11 +430,11 @@ static int vdi_open(BlockDriverState *bs, QDict *options, 
int flags,
(uint64_t)header.blocks_in_image * header.block_size);
 ret = -ENOTSUP;
 goto fail;
-} else if (!uuid_is_null(header.uuid_link)) {
+} else if (!qemu_uuid_is_null(_link)) {
 error_setg(errp, "unsupported VDI image (non-NULL link UUID)");
 ret = -ENOTSUP;
 goto fail;
-} else if (!uuid_is_null(header.uuid_parent)) {
+} else if (!qemu_uuid_is_null(_parent)) {
 error_setg(errp, "unsupported VDI image (non-NULL parent UUID)");
 ret = -ENOTSUP;
 goto fail;
@@ -821,8 +782,8 @@ static int vdi_create(const char *filename, QemuOpts *opts, 
Error **errp)
 if (image_type == VDI_TYPE_STATIC) {
 header.blocks_allocated = blocks;
 }
-uuid_generate(header.uuid_image);
-uuid_generate(header.uuid_last_snap);
+qemu_uuid_generate(_image);
+qemu_uuid_generate(_last_snap);
 /* There is no need to set header.uuid_link or header.uuid_parent here. */
 #if defined(CONFIG_VDI_DEBUG)
 vdi_header_print();
-- 
2.7.4




[Qemu-devel] [PATCH v7 12/12] Add UUID files to MAINTAINERS

2016-09-17 Thread Fam Zheng
I understand that we've been keeping eyes on the uncovered files. Since
I'm adding some more files I volunteer to look after them in the futuer.

Signed-off-by: Fam Zheng 
---
 MAINTAINERS | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 7d43026..764d2e4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1333,6 +1333,12 @@ F: include/qemu/throttle.h
 F: util/throttle.c
 L: qemu-bl...@nongnu.org
 
+UUID
+M: Fam Zheng 
+S: Supported
+F: util/uuid.c
+F: include/qemu/uuid.h
+
 Usermode Emulation
 --
 Overall
-- 
2.7.4




[Qemu-devel] [PATCH v7 03/12] vhdx: Use QEMU UUID API

2016-09-17 Thread Fam Zheng
This removes our dependency to libuuid, so that the driver can always be
built.

Similar to how we handled data plane configure options, --enable-vhdx
and --disable-vhdx are also changed to a nop with a message saying it's
obsolete.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 block/Makefile.objs |  2 +-
 block/vhdx-endian.c |  3 ---
 block/vhdx.c|  9 -
 configure   | 27 +++
 4 files changed, 8 insertions(+), 33 deletions(-)

diff --git a/block/Makefile.objs b/block/Makefile.objs
index 55da626..f23ee18 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -2,7 +2,7 @@ block-obj-y += raw_bsd.o qcow.o vdi.o vmdk.o cloop.o bochs.o 
vpc.o vvfat.o
 block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o 
qcow2-cache.o
 block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-obj-y += qed-check.o
-block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o vhdx-log.o
+block-obj-y += vhdx.o vhdx-endian.o vhdx-log.o
 block-obj-y += quorum.o
 block-obj-y += parallels.o blkdebug.o blkverify.o blkreplay.o
 block-obj-y += block-backend.o snapshot.o qapi.o
diff --git a/block/vhdx-endian.c b/block/vhdx-endian.c
index c306b90..429d755 100644
--- a/block/vhdx-endian.c
+++ b/block/vhdx-endian.c
@@ -21,9 +21,6 @@
 #include "qemu/bswap.h"
 #include "block/vhdx.h"
 
-#include 
-
-
 /*
  * All the VHDX formats on disk are little endian - the following
  * are helper import/export functions to correctly convert
diff --git a/block/vhdx.c b/block/vhdx.c
index 75ef2b1..0ba2f0a 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -25,8 +25,7 @@
 #include "qemu/bswap.h"
 #include "block/vhdx.h"
 #include "migration/migration.h"
-
-#include 
+#include "qemu/uuid.h"
 
 /* Options for VHDX creation */
 
@@ -213,11 +212,11 @@ bool vhdx_checksum_is_valid(uint8_t *buf, size_t size, 
int crc_offset)
  */
 void vhdx_guid_generate(MSGUID *guid)
 {
-uuid_t uuid;
+QemuUUID uuid;
 assert(guid != NULL);
 
-uuid_generate(uuid);
-memcpy(guid, uuid, sizeof(MSGUID));
+qemu_uuid_generate();
+memcpy(guid, , sizeof(MSGUID));
 }
 
 /* Check for region overlaps inside the VHDX image */
diff --git a/configure b/configure
index 7d083bd..b71b80a 100755
--- a/configure
+++ b/configure
@@ -317,7 +317,6 @@ vte=""
 virglrenderer=""
 tpm="yes"
 libssh2=""
-vhdx=""
 numa=""
 tcmalloc="no"
 jemalloc="no"
@@ -1103,6 +1102,9 @@ for opt do
   --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
   echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
   ;;
+  --enable-vhdx|--disable-vhdx)
+  echo "$0: $opt is obsolete, VHDX driver is always built" >&2
+  ;;
   --disable-gtk) gtk="no"
   ;;
   --enable-gtk) gtk="yes"
@@ -1143,10 +1145,6 @@ for opt do
   ;;
   --enable-libssh2) libssh2="yes"
   ;;
-  --enable-vhdx) vhdx="yes"
-  ;;
-  --disable-vhdx) vhdx="no"
-  ;;
   --disable-numa) numa="no"
   ;;
   --enable-numa) numa="yes"
@@ -1389,7 +1387,6 @@ disabled with --disable-FEATURE, default is enabled if 
available:
   archipelago Archipelago backend
   tpm TPM support
   libssh2 ssh block device support
-  vhdxsupport for the Microsoft VHDX image format
   numalibnuma support
   tcmalloctcmalloc support
   jemallocjemalloc support
@@ -2690,19 +2687,6 @@ EOF
   fi
 fi
 
-if test "$vhdx" = "yes" ; then
-if test "$uuid" = "no" ; then
-error_exit "uuid required for VHDX support"
-fi
-elif test "$vhdx" != "no" ; then
-if test "$uuid" = "yes" ; then
-vhdx=yes
-else
-vhdx=no
-fi
-fi
-
-##
 # xfsctl() probe, used for raw-posix
 if test "$xfs" != "no" ; then
   cat > $TMPC << EOF
@@ -4918,7 +4902,6 @@ echo "TPM support   $tpm"
 echo "libssh2 support   $libssh2"
 echo "TPM passthrough   $tpm_passthrough"
 echo "QOM debugging $qom_cast_debug"
-echo "vhdx  $vhdx"
 echo "lzo support   $lzo"
 echo "snappy support$snappy"
 echo "bzip2 support $bzip2"
@@ -5443,10 +5426,6 @@ if test "$libssh2" = "yes" ; then
   echo "LIBSSH2_LIBS=$libssh2_libs" >> $config_host_mak
 fi
 
-if test "$vhdx" = "yes" ; then
-  echo "CONFIG_VHDX=y" >> $config_host_mak
-fi
-
 # USB host support
 if test "$libusb" = "yes"; then
   echo "HOST_USB=libusb legacy" >> $config_host_mak
-- 
2.7.4




[Qemu-devel] [PATCH v7 07/12] tests: No longer dependent on CONFIG_UUID

2016-09-17 Thread Fam Zheng
crypto now uses built-in uuid implementation, so this check is not
needed.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 tests/test-crypto-block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/test-crypto-block.c b/tests/test-crypto-block.c
index a38110d..1957a86 100644
--- a/tests/test-crypto-block.c
+++ b/tests/test-crypto-block.c
@@ -28,7 +28,7 @@
 #include 
 #endif
 
-#if defined(CONFIG_UUID) && (defined(_WIN32) || defined RUSAGE_THREAD)
+#if (defined(_WIN32) || defined RUSAGE_THREAD)
 #define TEST_LUKS
 #else
 #undef TEST_LUKS
-- 
2.7.4




[Qemu-devel] [PATCH v7 11/12] tests: Add uuid tests

2016-09-17 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 tests/Makefile.include |   2 +
 tests/test-uuid.c  | 177 +
 2 files changed, 179 insertions(+)
 create mode 100644 tests/test-uuid.c

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 2f11064..15e7f8f 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -115,6 +115,7 @@ check-unit-y += tests/test-logging$(EXESUF)
 check-unit-$(CONFIG_REPLICATION) += tests/test-replication$(EXESUF)
 check-unit-y += tests/test-bufferiszero$(EXESUF)
 gcov-files-check-bufferiszero-y = util/bufferiszero.c
+check-unit-y += tests/test-uuid$(EXESUF)
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -658,6 +659,7 @@ tests/test-filter-mirror$(EXESUF): 
tests/test-filter-mirror.o $(qtest-obj-y)
 tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o 
$(qtest-obj-y)
 tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o 
contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y)
 tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o
+tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y)
 
 tests/migration/stress$(EXESUF): tests/migration/stress.o
$(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< 
,"  LINK  $(TARGET_DIR)$@")
diff --git a/tests/test-uuid.c b/tests/test-uuid.c
new file mode 100644
index 000..77dcdc4
--- /dev/null
+++ b/tests/test-uuid.c
@@ -0,0 +1,177 @@
+/*
+ * QEMU UUID Library
+ *
+ * Copyright (c) 2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see .
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/uuid.h"
+
+struct {
+const char *uuidstr;
+QemuUUID uuid;
+bool uuidstr_is_valid;
+bool check_unparse;
+} uuid_test_data[] = {
+{/* Normal */
+"586ece27-7f09-41e0-9e74-e901317e9d42",
+{ { {
+ 0x58, 0x6e, 0xce, 0x27, 0x7f, 0x09, 0x41, 0xe0,
+ 0x9e, 0x74, 0xe9, 0x01, 0x31, 0x7e, 0x9d, 0x42,
+} } },
+true, true,
+}, { /* NULL */
+"----",
+{ },
+true, true,
+}, { /* Upper case */
+"0CC6C752-3961-4028-A286-C05CC616D396",
+{ { {
+ 0x0c, 0xc6, 0xc7, 0x52, 0x39, 0x61, 0x40, 0x28,
+ 0xa2, 0x86, 0xc0, 0x5c, 0xc6, 0x16, 0xd3, 0x96,
+} } },
+true, false,
+}, { /* Mixed case */
+"0CC6C752-3961-4028-a286-c05cc616D396",
+{ { {
+ 0x0c, 0xc6, 0xc7, 0x52, 0x39, 0x61, 0x40, 0x28,
+ 0xa2, 0x86, 0xc0, 0x5c, 0xc6, 0x16, 0xd3, 0x96,
+} } },
+true, false,
+}, { /* Empty */
+""
+}, { /* Too short */
+"abc",
+}, { /* Non-hex */
+"abcdefgh----",
+}, { /* No '-' */
+"0cc6c75239614028a286c05cc616d396",
+}, { /* '-' in wrong position */
+"0cc6c-7523961-4028-a286-c05cc616d396",
+}, { /* Double '-' */
+"0cc6c752--3961-4028-a286-c05cc616d396",
+}, { /* Too long */
+"00",
+}, { /* Invalid char in the beginning */
+")cc6c752-3961-4028-a286-c05cc616d396",
+}, { /* Invalid char in the beginning, in extra */
+")0cc6c752-3961-4028-a286-c05cc616d396",
+}, { /* Invalid char in the middle */
+"0cc6c752-39*1-4028-a286-c05cc616d396",
+}, { /* Invalid char in the middle, in extra */
+"0cc6c752-39*61-4028-a286-c05cc616d396",
+}, { /* Invalid char in the end */
+"0cc6c752-3961-4028-a286-c05cc616d39&",
+}, { /* Invalid char in the end, in extra */
+"0cc6c752-3961-4028-a286-c05cc616d396&",
+}, { /* Short end and trailing space */
+"0cc6c752-3961-4028-a286-c05cc616d39 ",
+}, { /* Leading space and short end */
+" 0cc6c752-3961-4028-a286-c05cc616d39",
+},
+};
+
+static inline bool uuid_is_valid(QemuUUID *uuid)
+{
+return qemu_uuid_is_null(uuid) ||
+((uuid->data[6] & 0xf0) == 0x40 && (uuid->data[8] & 0xc0) == 0x80);
+}
+
+static void test_uuid_generate(void)
+{
+QemuUUID uuid;
+int i;
+
+for (i = 0; i < 100; ++i) {
+qemu_uuid_generate();
+g_assert(uuid_is_valid());
+}
+}
+
+static void test_uuid_is_null(void)
+{
+QemuUUID uuid_null = { };
+QemuUUID uuid_not_null = { { {
+ 

[Qemu-devel] [PATCH v7 02/12] uuid: Make null_uuid static

2016-09-17 Thread Fam Zheng
So that it doesn't have to be zeroed at each call.

Suggested-by: Eric Blake 
Signed-off-by: Fam Zheng 
---
 util/uuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/uuid.c b/util/uuid.c
index 08a7fd3..2e47f4a 100644
--- a/util/uuid.c
+++ b/util/uuid.c
@@ -40,7 +40,7 @@ void qemu_uuid_generate(QemuUUID *uuid)
 
 int qemu_uuid_is_null(const QemuUUID *uu)
 {
-QemuUUID null_uuid = { 0 };
+static QemuUUID null_uuid;
 return memcmp(uu, _uuid, sizeof(QemuUUID)) == 0;
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH v7 10/12] uuid: Tighten uuid parse

2016-09-17 Thread Fam Zheng
sscanf is relatively loose (tolerate) on some invalid formats that we
should fail instead of generating a wrong uuid structure, like with
whitespaces and short strings.

Add and use a helper function to first check the format.

Signed-off-by: Fam Zheng 
---
 util/uuid.c | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/util/uuid.c b/util/uuid.c
index e05ea54..81b54c3 100644
--- a/util/uuid.c
+++ b/util/uuid.c
@@ -61,12 +61,34 @@ char *qemu_uuid_unparse_strdup(const QemuUUID *uuid)
uu[13], uu[14], uu[15]);
 }
 
+static bool qemu_uuid_is_valid(const char *str)
+{
+int i;
+
+for (i = 0; i < strlen(str); i++) {
+const char c = str[i];
+if (i == 8 || i == 13 || i == 18 || i == 23) {
+if (str[i] != '-') {
+return false;
+}
+} else {
+if ((c >= '0' && c <= '9') ||
+(c >= 'A' && c <= 'F') ||
+(c >= 'a' && c <= 'f')) {
+continue;
+}
+return false;
+}
+}
+return i == 36;
+}
+
 int qemu_uuid_parse(const char *str, QemuUUID *uuid)
 {
 unsigned char *uu = >data[0];
 int ret;
 
-if (strlen(str) != 36) {
+if (!qemu_uuid_is_valid(str)) {
 return -1;
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH v7 05/12] vpc: Use QEMU UUID API

2016-09-17 Thread Fam Zheng
Previously we conditionally generated footer->uuid, when libuuid was
available. Now that we have a built-in implementation, we can switch to
it.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 block/vpc.c | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/block/vpc.c b/block/vpc.c
index 43707ed..8d5886f 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -30,9 +30,7 @@
 #include "qemu/module.h"
 #include "migration/migration.h"
 #include "qemu/bswap.h"
-#if defined(CONFIG_UUID)
-#include 
-#endif
+#include "qemu/uuid.h"
 
 /**/
 
@@ -89,7 +87,7 @@ typedef struct vhd_footer {
 uint32_tchecksum;
 
 /* UUID used to identify a parent hard disk (backing file) */
-uint8_t uuid[16];
+QemuUUIDuuid;
 
 uint8_t in_saved_state;
 } QEMU_PACKED VHDFooter;
@@ -980,9 +978,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, 
Error **errp)
 
 footer->type = cpu_to_be32(disk_type);
 
-#if defined(CONFIG_UUID)
-uuid_generate(footer->uuid);
-#endif
+qemu_uuid_generate(>uuid);
 
 footer->checksum = cpu_to_be32(vpc_checksum(buf, HEADER_SIZE));
 
-- 
2.7.4




[Qemu-devel] [PATCH v7 01/12] util: Add UUID API

2016-09-17 Thread Fam Zheng
A number of different places across the code base use CONFIG_UUID. Some
of them are soft dependency, some are not built if libuuid is not
available, some come with dummy fallback, some throws runtime error.

It is hard to maintain, and hard to reason for users.

Since UUID is a simple standard with only a small number of operations,
it is cleaner to have a central support in libqemuutil. This patch adds
qemu_uuid_* functions that all uuid users in the code base can
rely on. Except for qemu_uuid_generate which is new code, all other
functions are just copy from existing fallbacks from other files.

Note that qemu_uuid_parse is moved without updating the function
signature to use QemuUUID, to keep this patch simple.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
---
 arch_init.c | 19 ---
 block/iscsi.c   |  2 +-
 hw/smbios/smbios.c  |  1 +
 include/qemu/uuid.h | 59 
 include/sysemu/sysemu.h |  4 ---
 qmp.c   |  1 +
 stubs/uuid.c|  2 +-
 util/Makefile.objs  |  1 +
 util/uuid.c | 91 +
 vl.c|  1 +
 10 files changed, 156 insertions(+), 25 deletions(-)
 create mode 100644 include/qemu/uuid.h
 create mode 100644 util/uuid.c

diff --git a/arch_init.c b/arch_init.c
index fa05973..5cc58b2 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -235,25 +235,6 @@ void audio_init(void)
 }
 }
 
-int qemu_uuid_parse(const char *str, uint8_t *uuid)
-{
-int ret;
-
-if (strlen(str) != 36) {
-return -1;
-}
-
-ret = sscanf(str, UUID_FMT, [0], [1], [2], [3],
- [4], [5], [6], [7], [8], [9],
- [10], [11], [12], [13], [14],
- [15]);
-
-if (ret != 16) {
-return -1;
-}
-return 0;
-}
-
 void do_acpitable_option(const QemuOpts *opts)
 {
 #ifdef TARGET_I386
diff --git a/block/iscsi.c b/block/iscsi.c
index 95ce9e1..961ac76 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -36,7 +36,7 @@
 #include "block/block_int.h"
 #include "block/scsi.h"
 #include "qemu/iov.h"
-#include "sysemu/sysemu.h"
+#include "qemu/uuid.h"
 #include "qmp-commands.h"
 #include "qapi/qmp/qstring.h"
 #include "crypto/secret.h"
diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 74c7102..0705eb1 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -20,6 +20,7 @@
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
 #include "sysemu/sysemu.h"
+#include "qemu/uuid.h"
 #include "sysemu/cpus.h"
 #include "hw/smbios/smbios.h"
 #include "hw/loader.h"
diff --git a/include/qemu/uuid.h b/include/qemu/uuid.h
new file mode 100644
index 000..bc0601e
--- /dev/null
+++ b/include/qemu/uuid.h
@@ -0,0 +1,59 @@
+/*
+ *  QEMU UUID functions
+ *
+ *  Copyright 2016 Red Hat, Inc.
+ *
+ *  Authors:
+ *   Fam Zheng 
+ *
+ * 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.
+ *
+ */
+
+#ifndef QEMU_UUID_H
+#define QEMU_UUID_H
+
+#include "qemu-common.h"
+
+/* Version 4 UUID (pseudo random numbers), RFC4122 4.4. */
+
+typedef struct {
+union {
+unsigned char data[16];
+struct {
+/* Generated in BE endian, can be swapped with qemu_uuid_bswap. */
+uint32_t time_low;
+uint16_t time_mid;
+uint16_t time_high_and_version;
+uint8_t  clock_seq_and_reserved;
+uint8_t  clock_seq_low;
+uint8_t  node[6];
+} fields;
+};
+} QemuUUID;
+
+#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-" \
+ "%02hhx%02hhx-%02hhx%02hhx-" \
+ "%02hhx%02hhx-" \
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
+
+#define UUID_FMT_LEN 36
+
+#define UUID_NONE "----"
+
+void qemu_uuid_generate(QemuUUID *out);
+
+int qemu_uuid_is_null(const QemuUUID *uu);
+
+void qemu_uuid_unparse(const QemuUUID *uuid, char *out);
+
+char *qemu_uuid_unparse_strdup(const QemuUUID *uuid);
+
+int qemu_uuid_parse(const char *str, uint8_t *uuid);
+
+void qemu_uuid_bswap(QemuUUID *uuid);
+
+#endif
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index ee7c760..6111950 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -18,10 +18,6 @@ extern const char *bios_name;
 extern const char *qemu_name;
 extern uint8_t qemu_uuid[];
 extern bool qemu_uuid_set;
-int qemu_uuid_parse(const char *str, uint8_t *uuid);
-
-#define UUID_FMT 
"%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
-#define UUID_NONE "----"
 
 bool runstate_check(RunState state);
 void runstate_set(RunState new_state);
diff --git a/qmp.c b/qmp.c
index 

[Qemu-devel] [PATCH v7 00/12] UUID clean ups for 2.8

2016-09-17 Thread Fam Zheng
v7: Address Eric's comments:
01, 03-09: Add Eric's r-b line.
01: Commit message syntax fix.
Remove trailing comma in copyright header.
Remove 'glib.h' inclusion.
02: New patch to make null_uuid.
09: Fix missed qemu_uuid.
Also update "qemu_uuid[]" to "qemu_uuid" in a comment.
10: New patch to make uuid parse more robust against invalid formats.
11: Add test cases suggested by Eric.
Fix unwanted double dashes.
12: Added MAINTAINERS patch.

v6: Fix initializer syntax that is disliked by centos6.

v5: Add union fields in QemuUUID to help the alignment necessary for bswap, and
assert. [Richard]
Update the test case initializer syntax accordingly.

v4: Use memcpy instead of pointer type cast. [Richard]
Keep parameter order consistent with libuuid. [Jeff]
qemu_uuid_convert -> qemu_uuid_bswap. [Jeff]

v3: Negative tests. [Daniel]
Update QemuUUID type from array to struct. [Markus]
Add qemu_uuid_unparse_strdup.
Add qemu_uuid_convert.
Redirect configure obsoleted option message to stderr. [Jeff]
vdi: uuid_convert -> qemu_uuid_convert.
Fix commit message syntax errors in vpc patch. [Jeff]
Further cleanup around qemu_uuid.

v2: Fix the endianness wrongness. [Jeff]
Add tests/test-uuid.c. [Denial]
Add r-b of Stefan Weil to the VDI patch.

The facts how we use libuuid now are not particularly pleasant.

- VHDX driver depends on uuid, but is unconditionally checked in iotests 109.
  If it is not built, the test would fail, leaving no hint about that. In fact
  this even makes the feature implementation a bit ugly because it compromises
  the write protection on block 0 with image probing, silently.

- A few other libuuid users, in block/ and crypto/, use it as an optional
  dependency, and compromises certain functionalities if it is not available.

- On the other hand, there are already a few uuid function fallbacks in those
  callers, as well as some duplicated sscanf, snprintf and g_strdup_printf
  around UUID_FMT, which can be replaced with UUID parse/unparse routines.

So instead of making libuuid a hard requirement, let's simply move the
fallbacks to util and implement the random version of uuid generation, and be
done with it.

Fam

Fam Zheng (12):
  util: Add UUID API
  uuid: Make null_uuid static
  vhdx: Use QEMU UUID API
  vdi: Use QEMU UUID API
  vpc: Use QEMU UUID API
  crypto: Switch to QEMU UUID API
  tests: No longer dependent on CONFIG_UUID
  configure: Remove detection code for UUID
  vl: Switch qemu_uuid to QemuUUID
  uuid: Tighten uuid parse
  tests: Add uuid tests
  Add UUID files to MAINTAINERS

 MAINTAINERS|   6 ++
 arch_init.c|  19 -
 block/Makefile.objs|   2 +-
 block/iscsi.c  |   2 +-
 block/vdi.c|  73 +--
 block/vhdx-endian.c|   3 -
 block/vhdx.c   |   9 +--
 block/vpc.c|  10 +--
 configure  |  70 ++
 crypto/block-luks.c|  26 ++-
 hw/ipmi/ipmi_bmc_sim.c |   2 +-
 hw/nvram/fw_cfg.c  |   2 +-
 hw/ppc/spapr.c |   7 +-
 hw/ppc/spapr_rtas.c|   3 +-
 hw/smbios/smbios.c |  13 ++--
 hw/xenpv/xen_domainbuild.c |   6 +-
 include/qemu/uuid.h|  59 +++
 include/sysemu/sysemu.h|   7 +-
 qmp.c  |  11 +--
 stubs/uuid.c   |   2 +-
 tests/Makefile.include |   2 +
 tests/test-crypto-block.c  |   2 +-
 tests/test-uuid.c  | 177 +
 ui/spice-core.c|   2 +-
 util/Makefile.objs |   1 +
 util/uuid.c| 114 +
 vl.c   |   7 +-
 27 files changed, 424 insertions(+), 213 deletions(-)
 create mode 100644 include/qemu/uuid.h
 create mode 100644 tests/test-uuid.c
 create mode 100644 util/uuid.c

-- 
2.7.4




Re: [Qemu-devel] [RFC 00/13] Live memory snapshot based on userfaultfd

2016-09-17 Thread Hailiang Zhang

Hi Andrea,

Any comments ?

Thanks.

On 2016/9/6 11:39, Hailiang Zhang wrote:

Hi Andrea,

I tested it with the new live memory snapshot with --enable-kvm, it doesn't 
work.

To make things simple, I simplified the codes, only left the codes that can 
tested
the write-protect capability. You can find the codes from
https://github.com/coloft/qemu/tree/test-userfault-write-protect.
You can reproduce the problem easily with it.

Tested result as follow,
[root@localhost qemu]# x86_64-softmmu/qemu-system-x86_64 --enable-kvm -drive 
file=/mnt/sdb/win7/win7.qcow2,if=none,id=drive-ide0-0-1,format=qcow2,cache=none 
 -device ide-hd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1  -vnc :7 -m 
8192 -smp 1 -netdev tap,id=bn0 -device virtio-net-pci,id=net-pci0,netdev=bn0  
--monitor stdio
QEMU 2.6.95 monitor - type 'help' for more information
(qemu) migrate file:/home/xxx
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
qemu-system-x86_64: postcopy_ram_fault_thread: 7f07fb92a000 fault and remove 
write protect!
error: kvm run failed Bad address
EAX=0004 EBX= ECX=83b2ac20 EDX=c022
ESI=85fe33f4 EDI=c020 EBP=83b2abcc ESP=83b2abc0
EIP=8bd2ff0c EFL=00010293 [--S-A-C] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0023   00c0f300 DPL=3 DS   [-WA]
CS =0008   00c09b00 DPL=0 CS32 [-RA]
SS =0010   00c09300 DPL=0 DS   [-WA]
DS =0023   00c0f300 DPL=3 DS   [-WA]
FS =0030 83b2dc00 3748 00409300 DPL=0 DS   [-WA]
GS =   
LDT=   
TR =0028 801e2000 20ab 8b00 DPL=0 TSS32-busy
GDT= 80b95000 03ff
IDT= 80b95400 07ff
CR0=8001003b CR2=030b5000 CR3=00185000 CR4=06f8
DR0= DR1= DR2= 
DR3=
DR6=0ff0 DR7=0400
EFER=0800
Code=8b ff 55 8b ec 53 56 8b 75 08 57 8b 7e 34 56 e8 30 f7 ff ff <6a> 00 57 8a 
d8 e8 96 14 00 00 6a 04 83 c7 02 57 e8 8b 14 00 00 5f c6 46 5b 00 5e 8a c3 5b

I investigated kvm and userfault codes. we use MMU Notifier to integrating KVM 
with the Linux
Memory Management.

Here for userfault write-protect, the function calling paths are:
userfaultfd_ioctl
-> userfaultfd_writeprotect
  -> mwriteprotect_range
-> change_protection (Directly call mprotect helper here)
  -> change_protection_range
-> change_pud_range
  -> change_pmd_range
 -> mmu_notifier_invalidate_range_start(mm, mni_start, end);
-> kvm_mmu_notifier_invalidate_range_start (KVM module)
OK, here, we remove the item from spte. (If we use EPT hardware, we remove
the page table entry for it).
That's why we can get fault notifying for VM.
And It seems that we can't fix the userfault (remove the page's write-protect 
authority)
by this function calling paths.

Here my question is, for userfault write-protect capability, why we remove the 
page table
entry instead of marking it as read-only.
Actually, for KVM, we have a mmu notifier (kvm_mmu_notifier_change_pte) to do 
this,
We can use it to remove the writable authority for KVM page table, just like 
KVM dirty log tracking
does. Please see function __rmap_write_protect() in KVM.

Another question, is mprotect() works normally with KVM ? (I didn't test it.), 
I think
KSM and swap can work with KVM properly.

Besides, there seems to be a bug for userfault write-protect.
We use UFFDIO_COPY_MODE_DONTWAKE in userfaultfd_writeprotect, should it be
UFFDIO_WRITEPROTECT_MODE_DONTWAKE 

Re: [Qemu-devel] [PATCH v6 1/9] util: Add UUID API

2016-09-17 Thread Fam Zheng
On Sat, 09/17 16:29, Eric Blake wrote:
> On 08/17/2016 02:28 AM, Fam Zheng wrote:
> > A number of different places across the code base use CONFIG_UUID. Some
> > of them are soft dependency, some are not built if libuuid is not
> > available, some come with dummy fallback, some throws runtime error.
> > 
> > It is hard to maintain, and hard to reason for users.
> > 
> > Since UUID is a simple standard with only a small number of operations,
> > it is cleaner to have a central support in libqemuutil. This patch adds
> > qemu_uuid_* the functions so that all uuid users in the code base can
> 
> s/the functions so/functions/
> 
> > rely on. Except for qemu_uuid_generate which is new code, all other
> > functions are just copy from existing fallbacks from other files.
> > 
> > Note that qemu_uuid_parse is moved without updating the function
> > signature to use QemuUUID, to keep this patch simple.
> > 
> > Signed-off-by: Fam Zheng 
> > ---
> 
> > +++ b/include/qemu/uuid.h
> > @@ -0,0 +1,59 @@
> > +/*
> > + *  QEMU UUID functions
> > + *
> > + *  Copyright 2016 Red Hat, Inc.,
> 
> Why the trailing comma?

Simply a typo. Will fix.

> 
> > +++ b/util/uuid.c
> > @@ -0,0 +1,92 @@
> > +/*
> > + *  QEMU UUID functions
> > + *
> > + *  Copyright 2016 Red Hat, Inc.,
> 
> copy-and-paste? :)
> 
> 
> > +
> > +#include "qemu/osdep.h"
> > +#include "qemu-common.h"
> > +#include "qemu/uuid.h"
> > +#include "qemu/bswap.h"
> > +#include 
> 
> Do you still need the  header here? And if so, shouldn't it be
> right after osdep.h?

Yes, it will be removed.

> 
> > +
> > +void qemu_uuid_generate(QemuUUID *uuid)
> > +{
> > +int i;
> > +uint32_t tmp[4];
> > +
> > +QEMU_BUILD_BUG_ON(sizeof(QemuUUID) != 16);
> > +
> > +for (i = 0; i < 4; ++i) {
> > +tmp[i] = g_random_int();
> > +}
> > +memcpy(uuid, tmp, sizeof(tmp));
> > +/* Set the two most significant bits (bits 6 and 7) of the
> > +  clock_seq_hi_and_reserved to zero and one, respectively. */
> > +uuid->data[8] = (uuid->data[8] & 0x3f) | 0x80;
> > +/* Set the four most significant bits (bits 12 through 15) of the
> > +  time_hi_and_version field to the 4-bit version number.
> > +  */
> > +uuid->data[6] = (uuid->data[6] & 0xf) | 0x40;
> > +}
> 
> Looks okay.
> 
> > +
> > +int qemu_uuid_is_null(const QemuUUID *uu)
> > +{
> > +QemuUUID null_uuid = { 0 };
> 
> Could make this static, so that it doesn't have to be zeroed on every
> entry to this function (but in a separate patch, since this one just
> moved it, right?)

Sure, will do.

> 
> > +return memcmp(uu, _uuid, sizeof(QemuUUID)) == 0;
> > +}
> > +
> 
> Once the nits are cleaned up, you can add:
> Reviewed-by: Eric Blake 

Thanks!

Fam






Re: [Qemu-devel] [PATCH 2/2] aio: improve aio_poll performance by checking epoll only once

2016-09-17 Thread Yaowei Bai
On Wed, Sep 14, 2016 at 05:40:17PM +0100, Stefan Hajnoczi wrote:
> On Wed, Sep 14, 2016 at 07:03:39AM -0400, Yaowei Bai wrote:
> > As epoll whether enabled or not is a global setting, we can just
> > check it only once rather than checking it with every node iteration.
> > Through this we can avoid a lot of checks when epoll is not enabled.
> > 
> > Signed-off-by: Yaowei Bai 
> > Reviewed-by: Xiubo Li 
> > ---
> >  aio-posix.c | 12 +++-
> >  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> The commit message says "improve aio_poll performance" but no benchmark
> results were provided.  Therefore I can't take this patch as a
> performance optimization.  I'm still happy to merge the patch since it
> makes the if statement simpler but I'll rename it to "aio-posix: avoid
> unnecessary aio_epoll_enabled() calls".

Sorry for replying late, i just came back from my vacation. And i'd like
to say it's ok for me to rename the commit message. Thank you for doing
it.

> 
> I don't think this patch gives a measurable performance improvement.  If

Yes, i agree with you at this point in consideration of there's no too many
fds to poll at most time.

> you believe otherwise, please post benchmark results.  Please let me
> know what you think.
> 
> Stefan







[Qemu-devel] [PATCH] linux-user: fix mremap for 64bit targets on 32bit hosts

2016-09-17 Thread Felix Janda
Signed-off-by: Felix Janda 
---
 linux-user/mmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index c4371d9..4882816 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -682,7 +682,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong 
old_size,
 
 if (flags & MREMAP_FIXED) {
 host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
- old_size, new_size,
+ (size_t) old_size, (size_t) new_size,
  flags,
  g2h(new_addr));
 
@@ -701,7 +701,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong 
old_size,
 host_addr = MAP_FAILED;
 } else {
 host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
- old_size, new_size,
+ (size_t) old_size, (size_t) new_size,
  flags | MREMAP_FIXED,
  g2h(mmap_start));
 if (reserved_va) {
-- 
2.7.3



Re: [Qemu-devel] [PATCH v5 7/8] linux-user: Fix syslog() syscall support

2016-09-17 Thread Laurent Vivier


Le 14/09/2016 à 22:20, Aleksandar Markovic a écrit :
> From: Aleksandar Markovic 
> 
> There are currently several problems related to syslog() support.
> 
> For example, if the second argument "bufp" of target syslog() syscall
> is NULL, the current implementation always returns error code EFAULT.
> However, NULL is a perfectly valid value for the second argument for
> many use cases of this syscall. This is, for example, visible from
> this excerpt of man page for syslog(2):
> 
>> EINVAL Bad arguments (e.g., bad type; or for type 2, 3, or 4, buf is
>>NULL, or len is less than zero; or for type 8, the level is
>>outside the range 1 to 8).
> 
> Moreover, the argument "bufp" is ignored for all cases of values of the
> first argument, except 2, 3 and 4. This means that for such cases
> (the first argument is not 2, 3 or 4), there is no need to pass "buf"
> between host and target, and it can be set to NULL while calling host's
> syslog(), without loss of emulation accuracy.
> 
> Note also that if "bufp" is NULL and the first argument is 2, 3 or 4, the
> correct returned error code is EINVAL, not EFAULT.
> 
> All these details are reflected in this patch.
> 
> "#ifdef TARGET_NR_syslog" is also proprerly inserted when needed.
> 
> Support for Qemu's "-strace" switch for syslog() syscall is included too.
> 
> LTP tests syslog11 and syslog12 pass with this patch (while fail without
> it), on any platform.
> 
> Signed-off-by: Aleksandar Markovic 
> ---
>  linux-user/strace.c   | 68 
> +++
>  linux-user/strace.list|  2 +-
>  linux-user/syscall.c  | 23 +++-
>  linux-user/syscall_defs.h | 25 +
>  4 files changed, 111 insertions(+), 7 deletions(-)
> 
> diff --git a/linux-user/strace.c b/linux-user/strace.c
> index 61911e7..6177f2c 100644
> --- a/linux-user/strace.c
> +++ b/linux-user/strace.c
> @@ -1709,6 +1709,74 @@ print_rt_sigprocmask(const struct syscallname *name,
>  }
>  #endif
>  
> +#ifdef TARGET_NR_syslog
> +static void
> +print_syslog_action(abi_ulong arg, int last)
> +{

The double "%s" and duplicate gemu_log() are not really nice.

you can do:

const char *type;

> +switch (arg) {
> +case TARGET_SYSLOG_ACTION_CLOSE: {
> +gemu_log("%s%s", "SYSLOG_ACTION_CLOSE", get_comma(last));


type = "SYSLOG_ACTION_CLOSE";
break;
...
> +default: {
> +print_raw_param("%ld", arg, last);

   return;

> +}
> +}

gemu_log(%s%s", type, get_comma(last));

> +}
> +
> +static void
> +print_syslog(const struct syscallname *name,
> +abi_long arg0, abi_long arg1, abi_long arg2,
> +abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> +print_syscall_prologue(name);
> +print_syslog_action(arg0, 0);
> +print_pointer(arg1, 0);
> +print_raw_param("%d", arg2, 1);
> +print_syscall_epilogue(name);
> +}
> +#endif
> +
>  #ifdef TARGET_NR_mknod
>  static void
>  print_mknod(const struct syscallname *name,
> diff --git a/linux-user/strace.list b/linux-user/strace.list
> index 0bf1bea..2f99ac2 100644
> --- a/linux-user/strace.list
> +++ b/linux-user/strace.list
> @@ -1380,7 +1380,7 @@
>  { TARGET_NR_sys_kexec_load, "sys_kexec_load" , NULL, NULL, NULL },
>  #endif
>  #ifdef TARGET_NR_syslog
> -{ TARGET_NR_syslog, "syslog" , NULL, NULL, NULL },
> +{ TARGET_NR_syslog, "syslog" , NULL, print_syslog, NULL },
>  #endif
>  #ifdef TARGET_NR_sysmips
>  { TARGET_NR_sysmips, "sysmips" , NULL, NULL, NULL },
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 4ffcce5..37ce908 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -9219,14 +9219,25 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> arg1,
>  ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5);
>  break;
>  #endif
> -
> +#ifdef TARGET_NR_syslog
>  case TARGET_NR_syslog:
> -if (!(p = lock_user_string(arg2)))
> -goto efault;
> -ret = get_errno(sys_syslog((int)arg1, p, (int)arg3));
> -unlock_user(p, arg2, 0);
> +{
> +if (((int)arg1 == TARGET_SYSLOG_ACTION_READ) ||
> +((int)arg1 == TARGET_SYSLOG_ACTION_READ_ALL) ||
> +((int)arg1 == TARGET_SYSLOG_ACTION_READ_CLEAR)) {
> +p = lock_user_string(arg2);

arg2 is empty. length is given by arg3.
Use lock_user(VERIFY_WRITE, arg2, arg3, 0) for that.

> +if (!p) {
> +ret = -TARGET_EINVAL;
> +goto fail;
> +}
> +ret = get_errno(sys_syslog((int)arg1, p, (int)arg3));
> +unlock_user(p, arg2, 0);

unlock_user(p, arg2, arg3);

> +} else {
> +ret = get_errno(sys_syslog((int)arg1, NULL, (int)arg3));
> +}
> +}
>  break;
> -
> +#endif
>  case 

Re: [Qemu-devel] [PATCH 0/2] pc: fixes broken compat logic

2016-09-17 Thread Longpeng (Mike)
Hi Igor,

On 2016/9/14 18:01, Igor Mammedov wrote:

> fixes mistakes made by:
> 
>  targte-i386: Add virtual L3 cache support
>  https://www.mail-archive.com/qemu-devel@nongnu.org/msg395418.html
> 
> Igor Mammedov (2):
>   pc: fix regression introduced by adding 2.8 machine
>   target-i386: turn off CPU.l3-cache only for 2.7 and older machine
> types
> 
>  include/hw/i386/pc.h | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 

You're right, thank you for correcting my mistakes :)

-- 
Regards,
Longpeng(Mike)




Re: [Qemu-devel] [PATCH v5 8/8] linux-user: Remove a duplicate item from strace.list

2016-09-17 Thread Laurent Vivier


Le 14/09/2016 à 22:20, Aleksandar Markovic a écrit :
> From: Aleksandar Markovic 
> 
> There is a duplicate item in strace.list. It is benign, but it
> shouldn't be there. It is the only duplicate in strace.list. This
> patch removes it.
> 
> Signed-off-by: Aleksandar Markovic 
> ---
>  linux-user/strace.list | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/linux-user/strace.list b/linux-user/strace.list
> index 2f99ac2..f74545f 100644
> --- a/linux-user/strace.list
> +++ b/linux-user/strace.list
> @@ -1532,9 +1532,6 @@
>  #ifdef TARGET_NR_utimensat
>  { TARGET_NR_utimensat, "utimensat", NULL, print_utimensat, NULL },
>  #endif
> -#ifdef TARGET_NR_sync_file_range
> -{ TARGET_NR_sync_file_range, "sync_file_range", NULL, NULL, NULL },
> -#endif
>  #ifdef TARGET_NR_sync_file_range2
>  { TARGET_NR_sync_file_range2, "sync_file_range2", NULL, NULL, NULL },
>  #endif
> 


You should remove the other one, as this one has been added when the
syscall has been implemented:

c727f47 linux-user: Implement sync_file_range{,2} syscalls

Laurent



Re: [Qemu-devel] [PATCH v5 6/8] linux-user: Fix socketcall() syscall support

2016-09-17 Thread Laurent Vivier


Le 14/09/2016 à 22:19, Aleksandar Markovic a écrit :
> From: Aleksandar Markovic 
> 
> do_socketcall() function in Qemu's syscalls.c is implemented to mirror
> corespondant implementation of socketcall() in Linux kernel. (see kernel
> source file net/socket.c, definition of socketcall).
> 
> However, error codes are wrong for the cases of invalid values of the first
> argument. This patch in this sense brings do_socketcall() closer to its
> kernel counterpart.
> 
> Also, this patch fixes failure of LTP test socketcall02, if executed on some
> Qemu emulated sywstems (uer mode).
> 
> Signed-off-by: Aleksandar Markovic 
> ---
>  linux-user/syscall.c | 21 -
>  1 file changed, 12 insertions(+), 9 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index bdc12ae..4ffcce5 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -3845,15 +3845,18 @@ static abi_long do_socketcall(int num, abi_ulong vptr)
>  [SOCKOP_getsockopt] = 5,  /* sockfd, level, optname, optval, optlen 
> */
>  };
>  abi_long a[6]; /* max 6 args */
> +unsigned i;
>  
> -/* first, collect the arguments in a[] according to ac[] */
> -if (num >= 0 && num < ARRAY_SIZE(ac)) {
> -unsigned i;
> -assert(ARRAY_SIZE(a) >= ac[num]); /* ensure we have space for args */
> -for (i = 0; i < ac[num]; ++i) {
> -if (get_user_ual(a[i], vptr + i * sizeof(abi_long)) != 0) {
> -return -TARGET_EFAULT;
> -}
> +/* check the range of the first argument num */
> +if (num < 0 || num > ARRAY_SIZE(ac)) {
> +return -TARGET_EINVAL;
> +}

I'm not sure you can check this using the array index. kernel checks
against "num" value, i.e.:

if (num < 1 || num > SOCKOP_sendmmsg) {
return -TARGET_EINVAL;
}


> +/* collect the arguments in a[] according to ac[] */
> +assert(ARRAY_SIZE(a) >= ac[num]); /* ensure we have space for args */

instead, do this like the kernel does:

if (ac[num] > ARRAY_SIZE(a)) {
return -TARGET_EINVAL;
}

> +for (i = 0; i < ac[num]; ++i) {
> +if (get_user_ual(a[i], vptr + i * sizeof(abi_long)) != 0) {
> +return -TARGET_EFAULT;
>  }
>  }
>  
> @@ -3901,7 +3904,7 @@ static abi_long do_socketcall(int num, abi_ulong vptr)
>  return do_getsockopt(a[0], a[1], a[2], a[3], a[4]);
>  default:
>  gemu_log("Unsupported socketcall: %d\n", num);
> -return -TARGET_ENOSYS;
> +return -TARGET_EINVAL;
>  }
>  }
>  #endif
> 



Re: [Qemu-devel] [PATCH v5 5/8] linux-user: Fix msgrcv() and msgsnd() syscalls support

2016-09-17 Thread Laurent Vivier


Le 14/09/2016 à 22:19, Aleksandar Markovic a écrit :
> From: Aleksandar Markovic 
> 
> If syscalls msgrcv() and msgsnd() fail, they return E2BIG, EACCES,
> EAGAIN, EFAULT, EIDRM, EINTR, EINVAL, ENOMEM, or ENOMSG.
> 
> By examining negative scenarios of these syscalls for Mips, it was
> established that ENOMSG does not have the same value accross all
> platforms, but it is nevertheless not included for conversion in
> the correspondant conversion table defined in linux-user/syscall.c.
> This is certainly a bug, since it leads to the incorrect emulation
> of msgrcv() and msgsnd() for scenarios involving ENOMSG.
> 
> This patch fixes this by extending the conversion table to include
> ENOMSG.
> 
> Also, LTP test msgrcv04 will be fixed for some platforms.
> 
> Signed-off-by: Aleksandar Markovic 

Reviewed-by: Laurent Vivier 

> ---
>  linux-user/syscall.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 7f8ae41..bdc12ae 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -750,6 +750,9 @@ static uint16_t 
> host_to_target_errno_table[ERRNO_TABLE_SIZE] = {
>  #ifdef ENOTRECOVERABLE
>  [ENOTRECOVERABLE]= TARGET_ENOTRECOVERABLE,
>  #endif
> +#ifdef ENOMSG
> +[ENOMSG]= TARGET_ENOMSG,
> +#endif
>  };
>  
>  static inline int host_to_target_errno(int err)
> 



Re: [Qemu-devel] [PATCH v5 4/8] linux-user: Add support for ustat() syscall

2016-09-17 Thread Laurent Vivier


Le 14/09/2016 à 22:19, Aleksandar Markovic a écrit :
> From: Aleksandar Markovic 
> 
> This patch implements Qemu user mode ustat() syscall support.
> 
> Syscall ustat() returns information about a mounted filesystem.
> 
> The implementation is similar to the implementations of statfs(),
> fstatfs() and other related syscalls. It is based on invocation of
> host's ustat(), and its key part is in the correspondent case segment
> of the main switch statement of the function do_syscall(), in file
> linux-user/syscalls.c. All necessary conversions of data structures
> from target to host and from host to target are covered. Sufficient
> support for "-strace" option for this syscall is already present,
> and this patch does not change it.
> 
> This patch also fixes failures of LTP tests ustat01, and ustat02, if
> executed on Qemu-emulated systems.
> 
> Signed-off-by: Aleksandar Markovic 
> ---
>  linux-user/syscall.c | 25 -
>  1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 3436ee6..7f8ae41 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -48,6 +48,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -8098,7 +8099,29 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> arg1,
>  break;
>  #ifdef TARGET_NR_ustat
>  case TARGET_NR_ustat:
> -goto unimplemented;
> +{
> +struct ustat ust;
> +int cnt;
> +ret = get_errno(ustat(arg1, ));
> +
> +if (!is_error(ret)) {
> +struct ustat *target_ust;

You must define your own "struct target_ustat" as __kernel_daddr_t and
__kernel_ino_t are long (or int).

> +
> +if (!lock_user_struct(VERIFY_WRITE, target_ust, arg2, 0)) {
> +goto efault;
> +}
> +
> +__put_user(ust.f_tfree, _ust->f_tfree);
> +__put_user(ust.f_tinode, _ust->f_tinode);
> +
> +for (cnt = 0; cnt < 6; cnt++) {
> +__put_user(ust.f_fname[cnt], _ust->f_fname[cnt]);
> +__put_user(ust.f_fpack[cnt], _ust->f_fpack[cnt]);
> +}

As the structure is locked and they are "char", you can do memcpy().

> +unlock_user_struct(target_ust, arg2, 1);
> +}
> +break;
> +  }
>  #endif
>  #ifdef TARGET_NR_dup2
>  case TARGET_NR_dup2:
> 

Laurent



Re: [Qemu-devel] [PATCH v5 3/8] linux-user: Add support for sysfs() syscall

2016-09-17 Thread Laurent Vivier


Le 14/09/2016 à 22:19, Aleksandar Markovic a écrit :
> From: Aleksandar Markovic 
> 
> This patch implements Qemu user mode sysfs() syscall support.
> 
> Syscall sysfs() involves returning information about the filesystem types
> currently present in the kernel, and can operate in three distinct flavors,
> depending on its first argument.
> 
> The implementation is based on invocation of host's sysfs(), and
> its key part is in the correspondent case segment of the main switch
> statement of the function do_syscall(), in file linux-user/syscalls.c.
> All necessary conversions of data structures from target to host and from
> host to target are covered. Based on the value of the first argument, three
> cases are distinguished, and such conversions are implemented separately
> for each case. Relevant support for "-strace" option is included in files
> linux-user/strace.c and linux-user/strace.list.
> 
> This patch also fixes failures of LTP tests sysfs01, sysfs02, sysfs03,
> sysfs04, sysfs05, and sysfs06, if executed in Qemu user mode.
> 
> Signed-off-by: Aleksandar Markovic 
> ---
>  linux-user/strace.c| 25 +
>  linux-user/strace.list |  2 +-
>  linux-user/syscall.c   | 42 +-
>  3 files changed, 67 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/strace.c b/linux-user/strace.c
> index 4524c70..61911e7 100644
> --- a/linux-user/strace.c
> +++ b/linux-user/strace.c
> @@ -2151,6 +2151,31 @@ print_kill(const struct syscallname *name,
>  }
>  #endif
>  
> +#if defined(TARGET_NR_sysfs)
> +static void
> +print_sysfs(const struct syscallname *name,
> +abi_long arg0, abi_long arg1, abi_long arg2,
> +abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> +print_syscall_prologue(name);

perhaps you can move here:

print_raw_param("%d", arg0, 0);

> +switch (arg0) {
> +case 1:
> +print_raw_param("%d", arg0, 1);

should be ", 0);"

> +print_string(arg1, 1);
> +break;
> +case 2:
> +print_raw_param("%d", arg0, 0);
> +print_raw_param("%u", arg1, 0);
> +print_pointer(arg2, 1);
> +break;
> +default:
> +print_raw_param("%d", arg0, 1);
> +break;

in syscall.c, you use 3 for this, and default is EINVAL.

> +}
> +print_syscall_epilogue(name);
> +}
> +#endif
> +
>  /*
>   * An array of all of the syscalls we know about
>   */
> diff --git a/linux-user/strace.list b/linux-user/strace.list
> index 00b2e9b..0bf1bea 100644
> --- a/linux-user/strace.list
> +++ b/linux-user/strace.list
> @@ -1371,7 +1371,7 @@
>  { TARGET_NR_sys_epoll_wait, "sys_epoll_wait" , NULL, NULL, NULL },
>  #endif
>  #ifdef TARGET_NR_sysfs
> -{ TARGET_NR_sysfs, "sysfs" , NULL, NULL, NULL },
> +{ TARGET_NR_sysfs, "sysfs" , NULL, print_sysfs, NULL },
>  #endif
>  #ifdef TARGET_NR_sysinfo
>  { TARGET_NR_sysinfo, "sysinfo" , NULL, NULL, NULL },
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index eab9207..3436ee6 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -9549,7 +9549,47 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> arg1,
>  #endif
>  #ifdef TARGET_NR_sysfs
>  case TARGET_NR_sysfs:
> -goto unimplemented;
> +switch (arg1) {
> +case 1:
> +{
> +if (arg2 != 0) {

"arg2 == NULL" will be managed by lock_user_string()

> +p = lock_user_string(arg2);
> +if (!p) {
> +goto efault;
> +}
> +ret = get_errno(syscall(__NR_sysfs, arg1, p));
> +unlock_user(p, arg2, 0);
> +} else {
> +ret = get_errno(syscall(__NR_sysfs, arg1, NULL));

why?

> +}
> +}
> +break;
> +case 2:
> +{
> +if (arg3 != 0) {
> +char buf[PATH_MAX];

PATH_MAX (4096) should be a little bit excessive for a filesystem name.
they have rarely more than 16 characters.

> +int len;
> +memset(buf, 0, PATH_MAX);
> +ret = get_errno(syscall(__NR_sysfs, arg1, arg2, buf));
> +len = PATH_MAX;
> +if (len > strlen(buf)) {
> +len = strlen(buf);
> +}
> +if (copy_to_user(arg3, buf, len) != 0) {
> +goto efault;
> +}
> +} else {
> +ret = get_errno(syscall(__NR_sysfs, arg1, arg2, NULL));

Why?
just let the copy_to_user() trigger the "goto efault" in the case of
arg3 == 0.

> +}
> +}
> +break;
> +case 3:
> +ret = get_errno(syscall(__NR_sysfs, arg1));
> +break;
> +default:
> +ret = -EINVAL;
> +   

Re: [Qemu-devel] [PATCH v5 2/8] linux-user: Add support for clock_adjtime() syscall

2016-09-17 Thread Laurent Vivier


Le 14/09/2016 à 22:19, Aleksandar Markovic a écrit :
> From: Aleksandar Markovic 
> 
> This patch implements Qemu user mode clock_adjtime() syscall support.
> 
> The implementation is based on invocation of host's clock_adjtime(), and is
> very similar to the implementation of adjtimex() syscall support. The main
> difference is the presence of "clockid_t" argument in clock_adjtime().
> 
> Signed-off-by: Aleksandar Rikalo 
> Signed-off-by: Aleksandar Markovic 
> ---
>  linux-user/strace.c| 13 +
>  linux-user/strace.list |  3 +++
>  linux-user/syscall.c   | 19 ++-
>  3 files changed, 34 insertions(+), 1 deletion(-)
> 
> diff --git a/linux-user/strace.c b/linux-user/strace.c
> index 7ddcaf8..4524c70 100644
> --- a/linux-user/strace.c
> +++ b/linux-user/strace.c
> @@ -968,6 +968,19 @@ print_chmod(const struct syscallname *name,
>  }
>  #endif
>  
> +#ifdef TARGET_NR_clock_adjtime
> +static void
> +print_clock_adjtime(const struct syscallname *name,
> +abi_long arg0, abi_long arg1, abi_long arg2,
> +abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> +print_syscall_prologue(name);
> +print_raw_param("%d", arg0, 0);
> +print_pointer(arg1, 1);
> +print_syscall_epilogue(name);
> +}
> +#endif
> +
>  #ifdef TARGET_NR_clone
>  static void do_print_clone(unsigned int flags, abi_ulong newsp,
> abi_ulong parent_tidptr, target_ulong newtls,
> diff --git a/linux-user/strace.list b/linux-user/strace.list
> index 9a665a8..00b2e9b 100644
> --- a/linux-user/strace.list
> +++ b/linux-user/strace.list
> @@ -72,6 +72,9 @@
>  #ifdef TARGET_NR_chroot
>  { TARGET_NR_chroot, "chroot" , NULL, NULL, NULL },
>  #endif
> +#ifdef TARGET_NR_clock_adjtime
> +{ TARGET_NR_clock_adjtime, "clock_adjtime" , NULL, print_clock_adjtime, NULL 
> },
> +#endif
>  #ifdef TARGET_NR_clock_getres
>  { TARGET_NR_clock_getres, "clock_getres" , NULL, NULL, NULL },
>  #endif
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 5643840..eab9207 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -6579,7 +6579,7 @@ static inline abi_long target_ftruncate64(void 
> *cpu_env, abi_long arg1,
>  }
>  #endif
>  
> -#ifdef TARGET_NR_adjtimex
> +#if defined(TARGET_NR_adjtimex) || defined(TARGET_NR_clock_adjtime)
>  static inline abi_long target_to_host_timex(struct timex *host_buf,
>  abi_long target_addr)
>  {
> @@ -9509,6 +9509,23 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> arg1,
>  }
>  break;
>  #endif
> +#ifdef TARGET_NR_clock_adjtime
> +case TARGET_NR_clock_adjtime:
> +{
> +struct timex host_buf;
> +
> +if (target_to_host_timex(_buf, arg2) != 0) {
> +goto efault;
> +}
> +ret = get_errno(clock_adjtime(arg1, _buf));
> +if (!is_error(ret) && arg1) {

Why do you check arg1 here ?

> +if (host_to_target_timex(arg2, _buf) != 0) {
> +goto efault;
> +}
> +}
> +}
> +break;
> +#endif
>  #ifdef TARGET_NR_create_module
>  case TARGET_NR_create_module:
>  #endif
> 

Laurent



Re: [Qemu-devel] [PATCH v5 1/8] linux-user: Add support for adjtimex() syscall

2016-09-17 Thread Laurent Vivier


Le 17/09/2016 à 20:40, Laurent Vivier a écrit :
> 
> 
> Le 14/09/2016 à 22:19, Aleksandar Markovic a écrit :

>>  static inline abi_long target_to_host_timespec(struct timespec *host_ts,
>> abi_ulong target_addr)
>>  {
>> @@ -9419,8 +9492,23 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
>> arg1,
>>  break;
>>  #endif
>>  #endif
>> +#ifdef TARGET_NR_adjtimex
>>  case TARGET_NR_adjtimex:
>> -goto unimplemented;
>> +{
>> +struct timex host_buf;
>> +
> 
> check arg1 != NULL, so you manage target_to_host and host_to_target NULL
> case.

In fact, I think you should not check that, it will be managed by
lock_user_struct().

Laurent



[Qemu-devel] [PULL v2 6/8] blockdev: Modularize nfs block driver

2016-09-17 Thread Max Reitz
From: Colin Lord 

Modularizes the nfs block driver so that it gets dynamically loaded.

Signed-off-by: Colin Lord 
Reviewed-by: Stefan Hajnoczi 
Message-id: 1471008424-16465-5-git-send-email-cl...@redhat.com
Reviewed-by: Max Reitz 
Signed-off-by: Max Reitz 
---
 block/Makefile.objs | 1 +
 configure   | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/block/Makefile.objs b/block/Makefile.objs
index 3da471e..cb158e9 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -29,6 +29,7 @@ block-obj-y += crypto.o
 
 common-obj-y += stream.o
 
+nfs.o-libs := $(LIBNFS_LIBS)
 iscsi.o-cflags := $(LIBISCSI_CFLAGS)
 iscsi.o-libs   := $(LIBISCSI_LIBS)
 curl.o-cflags  := $(CURL_CFLAGS)
diff --git a/configure b/configure
index 7d083bd..2efc338 100755
--- a/configure
+++ b/configure
@@ -4578,7 +4578,6 @@ if test "$libnfs" != "no" ; then
   if $pkg_config --atleast-version=1.9.3 libnfs; then
 libnfs="yes"
 libnfs_libs=$($pkg_config --libs libnfs)
-LIBS="$LIBS $libnfs_libs"
   else
 if test "$libnfs" = "yes" ; then
   feature_not_found "libnfs" "Install libnfs devel >= 1.9.3"
@@ -5351,7 +5350,8 @@ if test "$libiscsi" = "yes" ; then
 fi
 
 if test "$libnfs" = "yes" ; then
-  echo "CONFIG_LIBNFS=y" >> $config_host_mak
+  echo "CONFIG_LIBNFS=m" >> $config_host_mak
+  echo "LIBNFS_LIBS=$libnfs_libs" >> $config_host_mak
 fi
 
 if test "$seccomp" = "yes"; then
-- 
2.9.3




[Qemu-devel] [PULL v2 5/8] blockdev: Add dynamic module loading for block drivers

2016-09-17 Thread Max Reitz
From: Marc Mari 

Extend the current module interface to allow for block drivers to be
loaded dynamically on request. The only block drivers that can be
converted into modules are the drivers that don't perform any init
operation except for registering themselves.

In addition, only the protocol drivers are being modularized, as they
are the only ones which see significant performance benefits. The format
drivers do not generally link to external libraries, so modularizing
them is of no benefit from a performance perspective.

All the necessary module information is located in a new structure found
in module_block.h

This spoils the purpose of 5505e8b76f (block/dmg: make it modular).

Before this patch, if module build is enabled, block-dmg.so is linked to
libbz2, whereas the main binary is not. In downstream, theoretically, it
means only the qemu-block-extra package depends on libbz2, while the
main QEMU package needn't to. With this patch, we (temporarily) change
the case so that the main QEMU depends on libbz2 again.

Signed-off-by: Marc Marí 
Signed-off-by: Colin Lord 
Reviewed-by: Stefan Hajnoczi 
Message-id: 1471008424-16465-4-git-send-email-cl...@redhat.com
Reviewed-by: Max Reitz 
Signed-off-by: Max Reitz 
---
 Makefile  |  3 ---
 block.c   | 62 +--
 block/Makefile.objs   |  3 +--
 include/qemu/module.h |  3 +++
 util/module.c | 38 +--
 5 files changed, 70 insertions(+), 39 deletions(-)

diff --git a/Makefile b/Makefile
index f2c3b24..6c5c01b 100644
--- a/Makefile
+++ b/Makefile
@@ -248,9 +248,6 @@ Makefile: $(version-obj-y) $(version-lobj-y)
 libqemustub.a: $(stub-obj-y)
 libqemuutil.a: $(util-obj-y)
 
-block-modules = $(foreach o,$(block-obj-m),"$(basename $(subst /,-,$o))",) NULL
-util/module.o-cflags = -D'CONFIG_BLOCK_MODULES=$(block-modules)'
-
 ##
 
 qemu-img.o: qemu-img-cmds.h
diff --git a/block.c b/block.c
index 66ed1c0..adbe8bb 100644
--- a/block.c
+++ b/block.c
@@ -27,6 +27,7 @@
 #include "block/blockjob.h"
 #include "block/nbd.h"
 #include "qemu/error-report.h"
+#include "module_block.h"
 #include "qemu/module.h"
 #include "qapi/qmp/qerror.h"
 #include "qapi/qmp/qbool.h"
@@ -242,17 +243,40 @@ BlockDriverState *bdrv_new(void)
 return bs;
 }
 
-BlockDriver *bdrv_find_format(const char *format_name)
+static BlockDriver *bdrv_do_find_format(const char *format_name)
 {
 BlockDriver *drv1;
+
 QLIST_FOREACH(drv1, _drivers, list) {
 if (!strcmp(drv1->format_name, format_name)) {
 return drv1;
 }
 }
+
 return NULL;
 }
 
+BlockDriver *bdrv_find_format(const char *format_name)
+{
+BlockDriver *drv1;
+size_t i;
+
+drv1 = bdrv_do_find_format(format_name);
+if (drv1) {
+return drv1;
+}
+
+/* The driver isn't registered, maybe we need to load a module */
+for (i = 0; i < ARRAY_SIZE(block_driver_modules); ++i) {
+if (!strcmp(block_driver_modules[i].format_name, format_name)) {
+block_module_load_one(block_driver_modules[i].library_name);
+break;
+}
+}
+
+return bdrv_do_find_format(format_name);
+}
+
 static int bdrv_is_whitelisted(BlockDriver *drv, bool read_only)
 {
 static const char *whitelist_rw[] = {
@@ -461,6 +485,19 @@ static BlockDriver *find_hdev_driver(const char *filename)
 return drv;
 }
 
+static BlockDriver *bdrv_do_find_protocol(const char *protocol)
+{
+BlockDriver *drv1;
+
+QLIST_FOREACH(drv1, _drivers, list) {
+if (drv1->protocol_name && !strcmp(drv1->protocol_name, protocol)) {
+return drv1;
+}
+}
+
+return NULL;
+}
+
 BlockDriver *bdrv_find_protocol(const char *filename,
 bool allow_protocol_prefix,
 Error **errp)
@@ -469,6 +506,7 @@ BlockDriver *bdrv_find_protocol(const char *filename,
 char protocol[128];
 int len;
 const char *p;
+size_t i;
 
 /* TODO Drivers without bdrv_file_open must be specified explicitly */
 
@@ -495,15 +533,25 @@ BlockDriver *bdrv_find_protocol(const char *filename,
 len = sizeof(protocol) - 1;
 memcpy(protocol, filename, len);
 protocol[len] = '\0';
-QLIST_FOREACH(drv1, _drivers, list) {
-if (drv1->protocol_name &&
-!strcmp(drv1->protocol_name, protocol)) {
-return drv1;
+
+drv1 = bdrv_do_find_protocol(protocol);
+if (drv1) {
+return drv1;
+}
+
+for (i = 0; i < ARRAY_SIZE(block_driver_modules); ++i) {
+if (block_driver_modules[i].protocol_name &&
+!strcmp(block_driver_modules[i].protocol_name, protocol)) {
+block_module_load_one(block_driver_modules[i].library_name);
+break;
 }
 

[Qemu-devel] [PULL v2 8/8] iotest 055: refactor and speed up

2016-09-17 Thread Max Reitz
From: Vladimir Sementsov-Ogievskiy 

Source disk is created and filled with test data before each test case.
Instead initialize it once for the whole unit.

Test disk filling patterns are merged into one pattern.

Also TestSetSpeed used different image_len for source and target (by
mistake) - this is automatically fixed here.

Signed-off-by: Vladimir Sementsov-Ogievskiy 
Message-id: 1470748523-13856-1-git-send-email-vsement...@virtuozzo.com
Reviewed-by: Pavel Butsykin 
Reviewed-by: Max Reitz 
Signed-off-by: Max Reitz 
---
 tests/qemu-iotests/055 | 52 +-
 1 file changed, 18 insertions(+), 34 deletions(-)

diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055
index ff4535e..1d3fd04 100755
--- a/tests/qemu-iotests/055
+++ b/tests/qemu-iotests/055
@@ -29,17 +29,24 @@ test_img = os.path.join(iotests.test_dir, 'test.img')
 target_img = os.path.join(iotests.test_dir, 'target.img')
 blockdev_target_img = os.path.join(iotests.test_dir, 'blockdev-target.img')
 
-class TestSingleDrive(iotests.QMPTestCase):
-image_len = 64 * 1024 * 1024 # MB
+image_len = 64 * 1024 * 1024 # MB
+
+def setUpModule():
+qemu_img('create', '-f', iotests.imgfmt, test_img, str(image_len))
+qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x11 0 64k', test_img)
+qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x00 64k 128k', test_img)
+qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x22 162k 32k', test_img)
+qemu_io('-f', iotests.imgfmt, '-c', 'write -P0xd5 1M 32k', test_img)
+qemu_io('-f', iotests.imgfmt, '-c', 'write -P0xdc 32M 124k', test_img)
+qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x33 67043328 64k', test_img)
 
+def tearDownModule():
+os.remove(test_img)
+
+
+class TestSingleDrive(iotests.QMPTestCase):
 def setUp(self):
-# Write data to the image so we can compare later
-qemu_img('create', '-f', iotests.imgfmt, test_img, 
str(TestSingleDrive.image_len))
-qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 0 64k', test_img)
-qemu_io('-f', iotests.imgfmt, '-c', 'write -P0xd5 1M 32k', test_img)
-qemu_io('-f', iotests.imgfmt, '-c', 'write -P0xdc 32M 124k', test_img)
-qemu_io('-f', iotests.imgfmt, '-c', 'write -P0xdc 67043328 64k', 
test_img)
-qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, 
str(TestSingleDrive.image_len))
+qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, 
str(image_len))
 
 self.vm = 
iotests.VM().add_drive(test_img).add_drive(blockdev_target_img)
 if iotests.qemu_default_machine == 'pc':
@@ -48,7 +55,6 @@ class TestSingleDrive(iotests.QMPTestCase):
 
 def tearDown(self):
 self.vm.shutdown()
-os.remove(test_img)
 os.remove(blockdev_target_img)
 try:
 os.remove(target_img)
@@ -155,19 +161,14 @@ class TestSingleDrive(iotests.QMPTestCase):
 self.assert_qmp(result, 'error/class', 'GenericError')
 
 class TestSetSpeed(iotests.QMPTestCase):
-image_len = 80 * 1024 * 1024 # MB
-
 def setUp(self):
-qemu_img('create', '-f', iotests.imgfmt, test_img, 
str(TestSetSpeed.image_len))
-qemu_io('-f', iotests.imgfmt, '-c', 'write -P1 0 512', test_img)
-qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, 
str(TestSingleDrive.image_len))
+qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, 
str(image_len))
 
 self.vm = 
iotests.VM().add_drive(test_img).add_drive(blockdev_target_img)
 self.vm.launch()
 
 def tearDown(self):
 self.vm.shutdown()
-os.remove(test_img)
 os.remove(blockdev_target_img)
 try:
 os.remove(target_img)
@@ -243,15 +244,8 @@ class TestSetSpeed(iotests.QMPTestCase):
 self.do_test_set_speed_invalid('blockdev-backup',  'drive1')
 
 class TestSingleTransaction(iotests.QMPTestCase):
-image_len = 64 * 1024 * 1024 # MB
-
 def setUp(self):
-qemu_img('create', '-f', iotests.imgfmt, test_img, 
str(TestSingleTransaction.image_len))
-qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 0 64k', test_img)
-qemu_io('-f', iotests.imgfmt, '-c', 'write -P0xd5 1M 32k', test_img)
-qemu_io('-f', iotests.imgfmt, '-c', 'write -P0xdc 32M 124k', test_img)
-qemu_io('-f', iotests.imgfmt, '-c', 'write -P0xdc 67043328 64k', 
test_img)
-qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, 
str(TestSingleDrive.image_len))
+qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, 
str(image_len))
 
 self.vm = 
iotests.VM().add_drive(test_img).add_drive(blockdev_target_img)
 if iotests.qemu_default_machine == 'pc':
@@ -260,7 +254,6 @@ class TestSingleTransaction(iotests.QMPTestCase):
 
 def tearDown(self):
 self.vm.shutdown()
-os.remove(test_img)
 

[Qemu-devel] [PULL v2 1/8] qemu-img: add the 'dd' subcommand

2016-09-17 Thread Max Reitz
From: Reda Sallahi 

This patch adds a basic dd subcommand analogous to dd(1) to qemu-img.

For the start, this implements the bs, if, of and count options and requires
both if and of to be specified (no stdin/stdout if not specified) and doesn't
support tty, pipes, etc.

The image format must be specified with -O for the output if the raw format
is not the intended one.

Two tests are added to test qemu-img dd.

Signed-off-by: Reda Sallahi 
Message-id: 20160810024312.14544-1-fullma...@gmail.com
Reviewed-by: Stefan Hajnoczi 
[mreitz: Moved test 158 to 170]
Signed-off-by: Max Reitz 
---
 qemu-img-cmds.hx |   6 +
 qemu-img.c   | 303 ++-
 qemu-img.texi|  25 
 tests/qemu-iotests/159   |  70 +
 tests/qemu-iotests/159.out   |  87 +++
 tests/qemu-iotests/170   |  67 +
 tests/qemu-iotests/170.out   |  15 ++
 tests/qemu-iotests/common.filter |   9 ++
 tests/qemu-iotests/common.rc |   5 +-
 tests/qemu-iotests/group |   2 +
 10 files changed, 584 insertions(+), 5 deletions(-)
 create mode 100755 tests/qemu-iotests/159
 create mode 100644 tests/qemu-iotests/159.out
 create mode 100755 tests/qemu-iotests/170
 create mode 100644 tests/qemu-iotests/170.out

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index 7e95b2d..03bdd7a 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -45,6 +45,12 @@ STEXI
 @item convert [--object @var{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("dd", img_dd,
+"dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] 
if=input of=output")
+STEXI
+@item dd [--image-opts] [-f @var{fmt}] [-O @var{output_fmt}] 
[bs=@var{block_size}] [count=@var{blocks}] if=@var{input} of=@var{output}
+ETEXI
+
 DEF("info", img_info,
 "info [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] 
[--backing-chain] filename")
 STEXI
diff --git a/qemu-img.c b/qemu-img.c
index ea52486..5bdac8d 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -166,7 +166,14 @@ static void QEMU_NORETURN help(void)
"Parameters to compare subcommand:\n"
"  '-f' first image format\n"
"  '-F' second image format\n"
-   "  '-s' run in Strict mode - fail on different image size or sector 
allocation\n";
+   "  '-s' run in Strict mode - fail on different image size or sector 
allocation\n"
+   "\n"
+   "Parameters to dd subcommand:\n"
+   "  'bs=BYTES' read and write up to BYTES bytes at a time "
+   "(default: 512)\n"
+   "  'count=N' copy only N input blocks\n"
+   "  'if=FILE' read from FILE\n"
+   "  'of=FILE' write to FILE\n";
 
 printf("%s\nSupported formats:", help_msg);
 bdrv_iterate_format(format_print, NULL);
@@ -3796,6 +3803,300 @@ out:
 return 0;
 }
 
+#define C_BS  01
+#define C_COUNT   02
+#define C_IF  04
+#define C_OF  010
+
+struct DdInfo {
+unsigned int flags;
+int64_t count;
+};
+
+struct DdIo {
+int bsz;/* Block size */
+char *filename;
+uint8_t *buf;
+};
+
+struct DdOpts {
+const char *name;
+int (*f)(const char *, struct DdIo *, struct DdIo *, struct DdInfo *);
+unsigned int flag;
+};
+
+static int img_dd_bs(const char *arg,
+ struct DdIo *in, struct DdIo *out,
+ struct DdInfo *dd)
+{
+char *end;
+int64_t res;
+
+res = qemu_strtosz_suffix(arg, , QEMU_STRTOSZ_DEFSUFFIX_B);
+
+if (res <= 0 || res > INT_MAX || *end) {
+error_report("invalid number: '%s'", arg);
+return 1;
+}
+in->bsz = out->bsz = res;
+
+return 0;
+}
+
+static int img_dd_count(const char *arg,
+struct DdIo *in, struct DdIo *out,
+struct DdInfo *dd)
+{
+char *end;
+
+dd->count = qemu_strtosz_suffix(arg, , QEMU_STRTOSZ_DEFSUFFIX_B);
+
+if (dd->count < 0 || *end) {
+error_report("invalid number: '%s'", arg);
+return 1;
+}
+
+return 0;
+}
+
+static int img_dd_if(const char *arg,
+ struct DdIo *in, struct DdIo *out,
+ struct DdInfo *dd)
+{
+in->filename = g_strdup(arg);
+
+return 0;
+}
+
+static int img_dd_of(const char *arg,
+ struct DdIo *in, struct DdIo *out,
+ struct DdInfo *dd)
+{
+out->filename = g_strdup(arg);
+
+return 0;
+}
+
+static int img_dd(int argc, char **argv)
+{
+int ret = 0;
+char *arg = NULL;
+char *tmp;
+BlockDriver *drv = NULL, *proto_drv = NULL;
+BlockBackend *blk1 = NULL, *blk2 = NULL;

[Qemu-devel] [PULL v2 2/8] qemu-img: add skip option to dd

2016-09-17 Thread Max Reitz
From: Reda Sallahi 

This adds the skip option which allows qemu-img dd to skip a number of blocks
before copying the input.

A test case was added to test the skip option.

Signed-off-by: Reda Sallahi 
Message-id: 20160810141609.32727-1-fullma...@gmail.com
Signed-off-by: Max Reitz 
---
 qemu-img-cmds.hx   |  4 +--
 qemu-img.c | 50 
 qemu-img.texi  |  4 ++-
 tests/qemu-iotests/160 | 72 ++
 tests/qemu-iotests/160.out | 51 
 tests/qemu-iotests/group   |  1 +
 6 files changed, 174 insertions(+), 8 deletions(-)
 create mode 100755 tests/qemu-iotests/160
 create mode 100644 tests/qemu-iotests/160.out

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index 03bdd7a..f054599 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -46,9 +46,9 @@ STEXI
 ETEXI
 
 DEF("dd", img_dd,
-"dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] 
if=input of=output")
+"dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] 
[skip=blocks] if=input of=output")
 STEXI
-@item dd [--image-opts] [-f @var{fmt}] [-O @var{output_fmt}] 
[bs=@var{block_size}] [count=@var{blocks}] if=@var{input} of=@var{output}
+@item dd [--image-opts] [-f @var{fmt}] [-O @var{output_fmt}] 
[bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] if=@var{input} 
of=@var{output}
 ETEXI
 
 DEF("info", img_info,
diff --git a/qemu-img.c b/qemu-img.c
index 5bdac8d..ceffefe 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -173,7 +173,8 @@ static void QEMU_NORETURN help(void)
"(default: 512)\n"
"  'count=N' copy only N input blocks\n"
"  'if=FILE' read from FILE\n"
-   "  'of=FILE' write to FILE\n";
+   "  'of=FILE' write to FILE\n"
+   "  'skip=N' skip N bs-sized blocks at the start of input\n";
 
 printf("%s\nSupported formats:", help_msg);
 bdrv_iterate_format(format_print, NULL);
@@ -3807,6 +3808,7 @@ out:
 #define C_COUNT   02
 #define C_IF  04
 #define C_OF  010
+#define C_SKIP020
 
 struct DdInfo {
 unsigned int flags;
@@ -3817,6 +3819,7 @@ struct DdIo {
 int bsz;/* Block size */
 char *filename;
 uint8_t *buf;
+int64_t offset;
 };
 
 struct DdOpts {
@@ -3877,6 +3880,22 @@ static int img_dd_of(const char *arg,
 return 0;
 }
 
+static int img_dd_skip(const char *arg,
+   struct DdIo *in, struct DdIo *out,
+   struct DdInfo *dd)
+{
+char *end;
+
+in->offset = qemu_strtosz_suffix(arg, , QEMU_STRTOSZ_DEFSUFFIX_B);
+
+if (in->offset < 0 || *end) {
+error_report("invalid number: '%s'", arg);
+return 1;
+}
+
+return 0;
+}
+
 static int img_dd(int argc, char **argv)
 {
 int ret = 0;
@@ -3900,12 +3919,14 @@ static int img_dd(int argc, char **argv)
 struct DdIo in = {
 .bsz = 512, /* Block size is by default 512 bytes */
 .filename = NULL,
-.buf = NULL
+.buf = NULL,
+.offset = 0
 };
 struct DdIo out = {
 .bsz = 512,
 .filename = NULL,
-.buf = NULL
+.buf = NULL,
+.offset = 0
 };
 
 const struct DdOpts options[] = {
@@ -3913,6 +3934,7 @@ static int img_dd(int argc, char **argv)
 { "count", img_dd_count, C_COUNT },
 { "if", img_dd_if, C_IF },
 { "of", img_dd_of, C_OF },
+{ "skip", img_dd_skip, C_SKIP },
 { NULL, NULL, 0 }
 };
 const struct option long_options[] = {
@@ -4032,7 +4054,14 @@ static int img_dd(int argc, char **argv)
 size = dd.count * in.bsz;
 }
 
-qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size, _abort);
+/* Overflow means the specified offset is beyond input image's size */
+if (dd.flags & C_SKIP && (in.offset > INT64_MAX / in.bsz ||
+  size < in.bsz * in.offset)) {
+qemu_opt_set_number(opts, BLOCK_OPT_SIZE, 0, _abort);
+} else {
+qemu_opt_set_number(opts, BLOCK_OPT_SIZE,
+size - in.bsz * in.offset, _abort);
+}
 
 ret = bdrv_create(drv, out.filename, opts, _err);
 if (ret < 0) {
@@ -4051,9 +4080,20 @@ static int img_dd(int argc, char **argv)
 goto out;
 }
 
+if (dd.flags & C_SKIP && (in.offset > INT64_MAX / in.bsz ||
+  size < in.offset * in.bsz)) {
+/* We give a warning if the skip option is bigger than the input
+ * size and create an empty output disk image (i.e. like dd(1)).
+ */
+error_report("%s: cannot skip to specified offset", in.filename);
+in_pos = size;
+} else {
+in_pos = in.offset * in.bsz;
+}
+
 in.buf = g_new(uint8_t, in.bsz);
 
-for (in_pos = 0, out_pos = 0; in_pos < size; block_count++) {
+for (out_pos = 0; in_pos < size; block_count++) 

[Qemu-devel] [PULL v2 7/8] commit: get the overlay node before manipulating the backing chain

2016-09-17 Thread Max Reitz
From: Alberto Garcia 

The 'block-commit' command has a 'top' parameter to specify the
topmost node from which the data is going to be copied.

   [E] <- [D] <- [C] <- [B] <- [A]

In this case if [C] is the top node then this is the result:

   [E] <- [B] <- [A]

[B] must be modified so its backing image string points to [E] instead
of [C]. commit_start() takes care of reopening [B] in read-write
mode, and commit_complete() puts it back in read-only mode once the
operation has finished.

In order to find [B] (the overlay node) we look for the node that has
[C] (the top node) as its backing image. However in commit_complete()
we're doing it after [C] has been removed from the chain, so [B] is
never found and remains in read-write mode.

This patch gets the overlay node before the backing chain is
manipulated.

Signed-off-by: Alberto Garcia 
Message-id: 1471836963-28548-1-git-send-email-be...@igalia.com
Signed-off-by: Max Reitz 
---
 block/commit.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/block/commit.c b/block/commit.c
index 553e18d..a02539b 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -83,7 +83,7 @@ static void commit_complete(BlockJob *job, void *opaque)
 BlockDriverState *active = s->active;
 BlockDriverState *top = blk_bs(s->top);
 BlockDriverState *base = blk_bs(s->base);
-BlockDriverState *overlay_bs;
+BlockDriverState *overlay_bs = bdrv_find_overlay(active, top);
 int ret = data->ret;
 
 if (!block_job_is_cancelled(>common) && ret == 0) {
@@ -97,7 +97,6 @@ static void commit_complete(BlockJob *job, void *opaque)
 if (s->base_flags != bdrv_get_flags(base)) {
 bdrv_reopen(base, s->base_flags, NULL);
 }
-overlay_bs = bdrv_find_overlay(active, top);
 if (overlay_bs && s->orig_overlay_flags != bdrv_get_flags(overlay_bs)) {
 bdrv_reopen(overlay_bs, s->orig_overlay_flags, NULL);
 }
-- 
2.9.3




[Qemu-devel] [PULL v2 4/8] blockdev: Add dynamic generation of module_block.h

2016-09-17 Thread Max Reitz
From: Marc Mari 

To simplify the addition of new block modules, add a script that generates
module_block.h automatically from the modules' source code.

This script assumes that the QEMU coding style rules are followed.

Signed-off-by: Marc Marí 
Signed-off-by: Colin Lord 
Reviewed-by: Stefan Hajnoczi 
Message-id: 1471008424-16465-3-git-send-email-cl...@redhat.com
Reviewed-by: Max Reitz 
Signed-off-by: Max Reitz 
---
 Makefile|   7 +++
 scripts/modules/module_block.py | 108 
 2 files changed, 115 insertions(+)
 create mode 100644 scripts/modules/module_block.py

diff --git a/Makefile b/Makefile
index 1fad5b7..f2c3b24 100644
--- a/Makefile
+++ b/Makefile
@@ -76,6 +76,8 @@ GENERATED_HEADERS += trace/generated-ust-provider.h
 GENERATED_SOURCES += trace/generated-ust.c
 endif
 
+GENERATED_HEADERS += module_block.h
+
 # Don't try to regenerate Makefile or configure
 # We don't generate any of them
 Makefile: ;
@@ -353,6 +355,11 @@ ivshmem-client$(EXESUF): $(ivshmem-client-obj-y) 
libqemuutil.a libqemustub.a
 ivshmem-server$(EXESUF): $(ivshmem-server-obj-y) libqemuutil.a libqemustub.a
$(call LINK, $^)
 
+module_block.h: $(SRC_PATH)/scripts/modules/module_block.py config-host.mak
+   $(call quiet-command,$(PYTHON) $< $@ \
+   $(addprefix $(SRC_PATH)/,$(patsubst %.mo,%.c,$(block-obj-m))), \
+   "  GEN   $@")
+
 clean:
 # avoid old build problems by removing potentially incorrect old files
rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h 
gen-op-arm.h
diff --git a/scripts/modules/module_block.py b/scripts/modules/module_block.py
new file mode 100644
index 000..db4fb54
--- /dev/null
+++ b/scripts/modules/module_block.py
@@ -0,0 +1,108 @@
+#!/usr/bin/python
+#
+# Module information generator
+#
+# Copyright Red Hat, Inc. 2015 - 2016
+#
+# Authors:
+#  Marc Mari 
+#
+# This work is licensed under the terms of the GNU GPL, version 2.
+# See the COPYING file in the top-level directory.
+
+from __future__ import print_function
+import sys
+import os
+
+def get_string_struct(line):
+data = line.split()
+
+# data[0] -> struct element name
+# data[1] -> =
+# data[2] -> value
+
+return data[2].replace('"', '')[:-1]
+
+def add_module(fheader, library, format_name, protocol_name):
+lines = []
+lines.append('.library_name = "' + library + '",')
+if format_name != "":
+lines.append('.format_name = "' + format_name + '",')
+if protocol_name != "":
+lines.append('.protocol_name = "' + protocol_name + '",')
+
+text = '\n'.join(lines)
+fheader.write('\n{\n' + text + '\n},')
+
+def process_file(fheader, filename):
+# This parser assumes the coding style rules are being followed
+with open(filename, "r") as cfile:
+found_something = False
+found_start = False
+library, _ = os.path.splitext(os.path.basename(filename))
+for line in cfile:
+if found_start:
+line = line.replace('\n', '')
+if line.find(".format_name") != -1:
+format_name = get_string_struct(line)
+elif line.find(".protocol_name") != -1:
+protocol_name = get_string_struct(line)
+elif line == "};":
+add_module(fheader, library, format_name, protocol_name)
+found_start = False
+elif line.find("static BlockDriver") != -1:
+found_something = True
+found_start = True
+format_name = ""
+protocol_name = ""
+
+if not found_something:
+print("No BlockDriver struct found in " + filename + ". \
+Is this really a module?", file=sys.stderr)
+sys.exit(1)
+
+def print_top(fheader):
+fheader.write('''/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
+/*
+ * QEMU Block Module Infrastructure
+ *
+ * Authors:
+ *  Marc Mari   
+ */
+
+''')
+
+fheader.write('''#ifndef QEMU_MODULE_BLOCK_H
+#define QEMU_MODULE_BLOCK_H
+
+#include "qemu-common.h"
+
+static const struct {
+const char *format_name;
+const char *protocol_name;
+const char *library_name;
+} block_driver_modules[] = {''')
+
+def print_bottom(fheader):
+fheader.write('''
+};
+
+#endif
+''')
+
+# First argument: output file
+# All other arguments: modules source files (.c)
+output_file = sys.argv[1]
+with open(output_file, 'w') as fheader:
+print_top(fheader)
+
+for filename in sys.argv[2:]:
+if os.path.isfile(filename):
+process_file(fheader, filename)
+else:
+print("File " + filename + " does not exist.", file=sys.stderr)
+sys.exit(1)
+
+print_bottom(fheader)
+
+sys.exit(0)
-- 

[Qemu-devel] [PULL v2 3/8] blockdev: prepare iSCSI block driver for dynamic loading

2016-09-17 Thread Max Reitz
From: Colin Lord 

This commit moves the initialization of the QemuOptsList qemu_iscsi_opts
struct out of block/iscsi.c in order to allow the iscsi module to be
dynamically loaded.

Signed-off-by: Colin Lord 
Reviewed-by: Fam Zheng 
Reviewed-by: Stefan Hajnoczi 
Message-id: 1471008424-16465-2-git-send-email-cl...@redhat.com
Reviewed-by: Max Reitz 
Signed-off-by: Max Reitz 
---
 block/iscsi.c | 36 
 vl.c  | 40 
 2 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 95ce9e1..c4a0937 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -2010,45 +2010,9 @@ static BlockDriver bdrv_iscsi = {
 .bdrv_attach_aio_context = iscsi_attach_aio_context,
 };
 
-static QemuOptsList qemu_iscsi_opts = {
-.name = "iscsi",
-.head = QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts.head),
-.desc = {
-{
-.name = "user",
-.type = QEMU_OPT_STRING,
-.help = "username for CHAP authentication to target",
-},{
-.name = "password",
-.type = QEMU_OPT_STRING,
-.help = "password for CHAP authentication to target",
-},{
-.name = "password-secret",
-.type = QEMU_OPT_STRING,
-.help = "ID of the secret providing password for CHAP "
-"authentication to target",
-},{
-.name = "header-digest",
-.type = QEMU_OPT_STRING,
-.help = "HeaderDigest setting. "
-"{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
-},{
-.name = "initiator-name",
-.type = QEMU_OPT_STRING,
-.help = "Initiator iqn name to use when connecting",
-},{
-.name = "timeout",
-.type = QEMU_OPT_NUMBER,
-.help = "Request timeout in seconds (default 0 = no timeout)",
-},
-{ /* end of list */ }
-},
-};
-
 static void iscsi_block_init(void)
 {
 bdrv_register(_iscsi);
-qemu_add_opts(_iscsi_opts);
 }
 
 block_init(iscsi_block_init);
diff --git a/vl.c b/vl.c
index ad2664b..4132e40 100644
--- a/vl.c
+++ b/vl.c
@@ -507,6 +507,43 @@ static QemuOptsList qemu_fw_cfg_opts = {
 },
 };
 
+#ifdef CONFIG_LIBISCSI
+static QemuOptsList qemu_iscsi_opts = {
+.name = "iscsi",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts.head),
+.desc = {
+{
+.name = "user",
+.type = QEMU_OPT_STRING,
+.help = "username for CHAP authentication to target",
+},{
+.name = "password",
+.type = QEMU_OPT_STRING,
+.help = "password for CHAP authentication to target",
+},{
+.name = "password-secret",
+.type = QEMU_OPT_STRING,
+.help = "ID of the secret providing password for CHAP "
+"authentication to target",
+},{
+.name = "header-digest",
+.type = QEMU_OPT_STRING,
+.help = "HeaderDigest setting. "
+"{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
+},{
+.name = "initiator-name",
+.type = QEMU_OPT_STRING,
+.help = "Initiator iqn name to use when connecting",
+},{
+.name = "timeout",
+.type = QEMU_OPT_NUMBER,
+.help = "Request timeout in seconds (default 0 = no timeout)",
+},
+{ /* end of list */ }
+},
+};
+#endif
+
 /**
  * Get machine options
  *
@@ -3016,6 +3053,9 @@ int main(int argc, char **argv, char **envp)
 qemu_add_opts(_icount_opts);
 qemu_add_opts(_semihosting_config_opts);
 qemu_add_opts(_fw_cfg_opts);
+#ifdef CONFIG_LIBISCSI
+qemu_add_opts(_iscsi_opts);
+#endif
 module_call_init(MODULE_INIT_OPTS);
 
 runstate_init();
-- 
2.9.3




[Qemu-devel] [PULL v2 0/8] Block layer patches

2016-09-17 Thread Max Reitz
The following changes since commit e3571ae30cd26d19efd4554c25e32ef64d6a36b3:

  Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20160916' into 
staging (2016-09-16 16:54:50 +0100)

are available in the git repository at:

  git://github.com/XanClic/qemu.git tags/pull-block-2016-09-17

for you to fetch changes up to 61601533ace153922fec04460f0b9b168b244968:

  iotest 055: refactor and speed up (2016-09-17 23:51:18 +0200)


Block patches for 2.8


Alberto Garcia (1):
  commit: get the overlay node before manipulating the backing chain

Colin Lord (2):
  blockdev: prepare iSCSI block driver for dynamic loading
  blockdev: Modularize nfs block driver

Marc Mari (2):
  blockdev: Add dynamic generation of module_block.h
  blockdev: Add dynamic module loading for block drivers

Reda Sallahi (2):
  qemu-img: add the 'dd' subcommand
  qemu-img: add skip option to dd

Vladimir Sementsov-Ogievskiy (1):
  iotest 055: refactor and speed up

 Makefile |  10 +-
 block.c  |  62 ++-
 block/Makefile.objs  |   4 +-
 block/commit.c   |   3 +-
 block/iscsi.c|  36 
 configure|   4 +-
 include/qemu/module.h|   3 +
 qemu-img-cmds.hx |   6 +
 qemu-img.c   | 343 ++-
 qemu-img.texi|  27 +++
 scripts/modules/module_block.py  | 108 
 tests/qemu-iotests/055   |  52 ++
 tests/qemu-iotests/159   |  70 
 tests/qemu-iotests/159.out   |  87 ++
 tests/qemu-iotests/160   |  72 
 tests/qemu-iotests/160.out   |  51 ++
 tests/qemu-iotests/170   |  67 
 tests/qemu-iotests/170.out   |  15 ++
 tests/qemu-iotests/common.filter |   9 +
 tests/qemu-iotests/common.rc |   5 +-
 tests/qemu-iotests/group |   3 +
 util/module.c|  38 ++---
 vl.c |  40 +
 23 files changed, 997 insertions(+), 118 deletions(-)
 create mode 100644 scripts/modules/module_block.py
 create mode 100755 tests/qemu-iotests/159
 create mode 100644 tests/qemu-iotests/159.out
 create mode 100755 tests/qemu-iotests/160
 create mode 100644 tests/qemu-iotests/160.out
 create mode 100755 tests/qemu-iotests/170
 create mode 100644 tests/qemu-iotests/170.out

-- 
2.9.3




Re: [Qemu-devel] [PATCH v6 9/9] tests: Add uuid tests

2016-09-17 Thread Eric Blake
On 08/17/2016 02:28 AM, Fam Zheng wrote:
> Signed-off-by: Fam Zheng 
> ---
>  tests/Makefile.include |   2 +
>  tests/test-uuid.c  | 173 
> +
>  2 files changed, 175 insertions(+)
>  create mode 100644 tests/test-uuid.c
> 

> +}, { /* Double '-' */
> +"0cc6c752--3961-4028-a286-c05cc616d396",
> +}, { /* Too long */
> +"00",
> +}, { /* Invalid char in the beginning */
> +")cc6c752--3961-4028-a286-c05cc616d396",

Umm, why the double dash in this and the remaining tests?  They are
failing for the wrong reason.

> +}, { /* Invalid char in the beginning, in extra */
> +")0cc6c752--3961-4028-a286-c05cc616d396",
> +}, { /* Invalid char in the middle */
> +"0cc6c752--39*1-4028-a286-c05cc616d396",
> +}, { /* Invalid char in the middle, in extra */
> +"0cc6c752--39*61-4028-a286-c05cc616d396",
> +}, { /* Invalid char in the end */
> +"0cc6c752--3961-4028-a286-c05cc616d39&",
> +}, { /* Invalid char in the end, in extra */
> +"0cc6c752--3961-4028-a286-c05cc616d396&",

And, I was able to quickly prove that you are missing a couple of tests:

}, { /* Leading space and short end */
" 0cc6c752-3961-4028-a286-c05cc616d39",
},

Whoops - that test fails.
GTESTER tests/test-uuid
**
ERROR:tests/test-uuid.c:126:test_uuid_parse: assertion failed (!r ==
is_valid): (1 == 0)

Yay for sscanf() not doing what we want.  :(  We've had a latent bug for
as long as we've been calling sscanf(UUID_FMT).

Why does it fail, you ask?  Because sscanf() skips leading spaces, and
doesn't start counting the %02hhx parse until after the leading space;
then the final %02hhx parse happily stops parsing with just 1 character.
 The string is the right length, but the wrong format.

Also:

}, { /* Short end and trailing space */
"0cc6c752-3961-4028-a286-c05cc616d39 ",

You may want to add a followup patch that tightens parsing; perhaps
using strspn() to double check that not only is the input string the
right length, but also that it only has [a-fA-F0-9-], so that any
whitespace that sneaks past sscanf() is detected.


-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v6 8/9] vl: Switch qemu_uuid to QemuUUID

2016-09-17 Thread Eric Blake
On 09/17/2016 04:38 PM, Eric Blake wrote:
> On 08/17/2016 02:28 AM, Fam Zheng wrote:
>> Update all qemu_uuid users as well, especially get rid of the duplicated
>> low level g_strdup_printf, sscanf and snprintf calls with QEMU UUID API.
>>
>> Since qemu_uuid_parse is quite tangled with qemu_uuid, it's switching to
>> QemuUUID is done here too to keep everything in sync and avoid code
>> churn.
>>
>> Signed-off-by: Fam Zheng 
>> ---
> 
> Reviewed-by: Eric Blake 
> 

Spoke too soon; this fails compilation for me, because you missed a few
spots:

  CCui/sdl2-2d.o
ui/spice-core.c: In function ‘qemu_spice_init’:
ui/spice-core.c:799:41: error: incompatible type for argument 2 of
‘spice_server_set_uuid’
 spice_server_set_uuid(spice_server, qemu_uuid);
 ^
In file included from /usr/include/spice-server/spice.h:25:0,
 from ui/spice-core.c:19:
/usr/include/spice-server/spice-server.h:121:6: note: expected ‘const
uint8_t * {aka const unsigned char *}’ but argument is of type ‘QemuUUID
{aka struct }’
 void spice_server_set_uuid(SpiceServer *s, const uint8_t uuid[16]);
  ^

/home/eblake/qemu/hw/ppc/spapr_rtas.c: In function
‘rtas_ibm_get_system_parameter’:
/home/eblake/qemu/hw/ppc/spapr_rtas.c:306:42: error: incompatible type
for argument 3 of ‘sysparm_st’
 ret = sysparm_st(buffer, length, qemu_uuid, (qemu_uuid_set ? 16
: 0));
  ^
/home/eblake/qemu/hw/ppc/spapr_rtas.c:261:19: note: expected ‘const void
*’ but argument is of type ‘QemuUUID {aka struct }’
 static inline int sysparm_st(target_ulong addr, target_ulong len,
   ^~
/home/eblake/qemu/rules.mak:60: recipe for target 'hw/ppc/spapr_rtas.o'
failed


The fixups should be obvious, though, so fold them in, and you can keep R-b.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v6 8/9] vl: Switch qemu_uuid to QemuUUID

2016-09-17 Thread Eric Blake
On 08/17/2016 02:28 AM, Fam Zheng wrote:
> Update all qemu_uuid users as well, especially get rid of the duplicated
> low level g_strdup_printf, sscanf and snprintf calls with QEMU UUID API.
> 
> Since qemu_uuid_parse is quite tangled with qemu_uuid, it's switching to
> QemuUUID is done here too to keep everything in sync and avoid code
> churn.
> 
> Signed-off-by: Fam Zheng 
> ---

Reviewed-by: Eric Blake 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v6 5/9] crypto: Switch to QEMU UUID API

2016-09-17 Thread Eric Blake
On 08/17/2016 02:28 AM, Fam Zheng wrote:
> The uuid generation doesn't return error, so update the function
> signature and calling code accordingly.
> 
> Signed-off-by: Fam Zheng 
> ---
>  crypto/block-luks.c | 26 +++---
>  1 file changed, 7 insertions(+), 19 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v6 6/9] tests: No longer dependent on CONFIG_UUID

2016-09-17 Thread Eric Blake
On 08/17/2016 02:28 AM, Fam Zheng wrote:
> crypto now uses built-in uuid implementation, so this check is not
> needed.
> 
> Signed-off-by: Fam Zheng 
> ---
>  tests/test-crypto-block.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v6 7/9] configure: Remove detection code for UUID

2016-09-17 Thread Eric Blake
On 08/17/2016 02:28 AM, Fam Zheng wrote:
> All code now uses built-in UUID implementation. Remove the code of
> libuuid and make --enable-uuid and --disable-uuid only print a message.
> 
> Signed-off-by: Fam Zheng 
> ---
>  configure | 43 ---
>  1 file changed, 4 insertions(+), 39 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PULL 00/18] Block layer patches

2016-09-17 Thread Max Reitz
On 15.09.2016 18:10, Peter Maydell wrote:
> On 14 September 2016 at 17:40, Max Reitz  wrote:
>> The following changes since commit 507e4ddc3abf67391bcbc9624fd60b969c159b78:
>>
>>   Merge remote-tracking branch 'remotes/mjt/tags/trivial-patches-fetch' into 
>> staging (2016-09-13 17:55:35 +0100)
>>
>> are available in the git repository at:
>>
>>   git://github.com/XanClic/qemu.git tags/pull-block-2016-09-14
>>
>> for you to fetch changes up to 262a8020cf666ae7108040683038cc46be4c48d2:
>>
>>   iotest 055: refactor and speed up (2016-09-14 17:56:42 +0200)
>>
>> 
>> Block patches for 2.8
>>
>> 
> 
> Compile failure on 32 bit:
>   CCutil/qemu-option.o
> /home/petmay01/qemu/util/hbitmap.c: In function 'hbitmap_serialization_size':
> /home/petmay01/qemu/util/hbitmap.c:439:5: error: passing argument 5 of
> 'serialization_chunk' from incompatible pointer type [-Werror]
>  serialization_chunk(hb, start, count, , _count);
>  ^
> /home/petmay01/qemu/util/hbitmap.c:410:13: note: expected 'size_t *'
> but argument is of type 'uint64_t *'
>  static void serialization_chunk(const HBitmap *hb,
>  ^
> /home/petmay01/qemu/util/hbitmap.c: In function 'hbitmap_serialize_part':
> /home/petmay01/qemu/util/hbitmap.c:453:5: error: passing argument 5 of
> 'serialization_chunk' from incompatible pointer type [-Werror]
>  serialization_chunk(hb, start, count, , _count);
>  ^
> /home/petmay01/qemu/util/hbitmap.c:410:13: note: expected 'size_t *'
> but argument is of type 'uint64_t *'
>  static void serialization_chunk(const HBitmap *hb,
>  ^
> /home/petmay01/qemu/util/hbitmap.c: In function 'hbitmap_deserialize_part':
> /home/petmay01/qemu/util/hbitmap.c:476:5: error: passing argument 5 of
> 'serialization_chunk' from incompatible pointer type [-Werror]
>  serialization_chunk(hb, start, count, , _count);
>  ^
> /home/petmay01/qemu/util/hbitmap.c:410:13: note: expected 'size_t *'
> but argument is of type 'uint64_t *'
>  static void serialization_chunk(const HBitmap *hb,
>  ^
> /home/petmay01/qemu/util/hbitmap.c: In function 'hbitmap_deserialize_zeroes':
> /home/petmay01/qemu/util/hbitmap.c:505:5: error: passing argument 5 of
> 'serialization_chunk' from incompatible pointer type [-Werror]
>  serialization_chunk(hb, start, count, , _count);
>  ^
> /home/petmay01/qemu/util/hbitmap.c:410:13: note: expected 'size_t *'
> but argument is of type 'uint64_t *'
>  static void serialization_chunk(const HBitmap *hb,
>  ^
> cc1: all warnings being treated as errors
> 
> 
> Test failure on big-endian ppc64be:
> 
>   /hbitmap/serialize/granularity:  OK
>   /hbitmap/serialize/basic:**
> ERROR:/home/pm215/qemu/tests/test-hbitmap.c:774:hbitmap_test_serialize_range:
> assertion failed: (is_set)
> FAIL
> GTester: last random seed: R02Se8652df9788b7a1ec926da1717ff2d26
> (pid=34146)
>   /hbitmap/serialize/part: **
> ERROR:/home/pm215/qemu/tests/test-hbitmap.c:843:test_hbitmap_serialize_part:
> assertion failed (should_set == test_bit(j, (unsigned long *)buf)): (1
> == 0)
> FAIL
> GTester: last random seed: R02S3e07d1d6dcda6b90721e062eca26e6b9
> (pid=34147)
>   /hbitmap/serialize/zeroes:   OK
> FAIL: tests/test-hbitmap

Thank you! That looks interesting. I'll drop the series in question from
my queue and send a v2.

Max



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v6 3/9] vdi: Use QEMU UUID API

2016-09-17 Thread Eric Blake
On 08/17/2016 02:28 AM, Fam Zheng wrote:
> The UUID operations we need from libuuid is fully supported by QEMU UUID

s/is/are/

> implementation. Use it, and remove the unused code.
> 
> Signed-off-by: Fam Zheng 
> ---
>  block/vdi.c | 73 
> ++---
>  1 file changed, 17 insertions(+), 56 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v6 4/9] vpc: Use QEMU UUID API

2016-09-17 Thread Eric Blake
On 08/17/2016 02:28 AM, Fam Zheng wrote:
> Previously we conditionally generated footer->uuid, when libuuid was
> available. Now that we have a built-in implementation, we can switch to
> it.
> 
> Signed-off-by: Fam Zheng 
> ---
>  block/vpc.c | 10 +++---
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v6 2/9] vhdx: Use QEMU UUID API

2016-09-17 Thread Eric Blake
On 08/17/2016 02:28 AM, Fam Zheng wrote:
> This removes our dependency to libuuid, so that the driver can always be
> built.
> 
> Similar to how we handled data plane configure options, --enable-vhdx
> and --disable-vhdx are also changed to a nop with a message saying it's
> obsolete.
> 
> Signed-off-by: Fam Zheng 
> ---

Reviewed-by: Eric Blake 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v8 07/10] hbitmap: serialization

2016-09-17 Thread Max Reitz
On 02.08.2016 02:12, John Snow wrote:
> From: Vladimir Sementsov-Ogievskiy 
> 
> Functions to serialize / deserialize(restore) HBitmap. HBitmap should be
> saved to linear sequence of bits independently of endianness and bitmap
> array element (unsigned long) size. Therefore Little Endian is chosen.
> 
> These functions are appropriate for dirty bitmap migration, restoring
> the bitmap in several steps is available. To save performance, every
> step writes only the last level of the bitmap. All other levels are
> restored by hbitmap_deserialize_finish() as a last step of restoring.
> So, HBitmap is inconsistent while restoring.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy 
> [Fix left shift operand to 1UL; add "finish" parameter. - Fam]
> Signed-off-by: Fam Zheng 
> Reviewed-by: Max Reitz 
> 
> Signed-off-by: John Snow 
> ---
>  include/qemu/hbitmap.h |  79 
>  util/hbitmap.c | 137 
> +
>  2 files changed, 216 insertions(+)
> 

[...]

> diff --git a/util/hbitmap.c b/util/hbitmap.c
> index f303975..6a13c12 100644
> --- a/util/hbitmap.c
> +++ b/util/hbitmap.c
> @@ -397,6 +397,143 @@ bool hbitmap_get(const HBitmap *hb, uint64_t item)
>  return (hb->levels[HBITMAP_LEVELS - 1][pos >> BITS_PER_LEVEL] & bit) != 
> 0;
>  }
>  
> +uint64_t hbitmap_serialization_granularity(const HBitmap *hb)
> +{
> +/* Require at least 64 bit granularity to be safe on both 64 bit and 32 
> bit
> + * hosts. */
> +return 64 << hb->granularity;
> +}
> +
> +/* Start should be aligned to serialization granularity, chunk size should be
> + * aligned to serialization granularity too, except for last chunk.
> + */
> +static void serialization_chunk(const HBitmap *hb,
> +uint64_t start, uint64_t count,
> +unsigned long **first_el, size_t *el_count)

As spotted by both Peter and the automatic build system, the last
parameter should be a uint64_t *.

Also, there's the issue Peter spotted on a BE machine:

http://lists.nongnu.org/archive/html/qemu-block/2016-09/msg00261.html

Because the latter is probably not as trivially fixable as the former, I
guess I'll have to drop this series from my queue for now.

Max

> +{
> +uint64_t last = start + count - 1;
> +uint64_t gran = hbitmap_serialization_granularity(hb);
> +
> +assert((start & (gran - 1)) == 0);
> +assert((last >> hb->granularity) < hb->size);
> +if ((last >> hb->granularity) != hb->size - 1) {
> +assert((count & (gran - 1)) == 0);
> +}
> +
> +start = (start >> hb->granularity) >> BITS_PER_LEVEL;
> +last = (last >> hb->granularity) >> BITS_PER_LEVEL;
> +
> +*first_el = >levels[HBITMAP_LEVELS - 1][start];
> +*el_count = last - start + 1;
> +}
> +



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v6 1/9] util: Add UUID API

2016-09-17 Thread Eric Blake
On 08/17/2016 02:28 AM, Fam Zheng wrote:
> A number of different places across the code base use CONFIG_UUID. Some
> of them are soft dependency, some are not built if libuuid is not
> available, some come with dummy fallback, some throws runtime error.
> 
> It is hard to maintain, and hard to reason for users.
> 
> Since UUID is a simple standard with only a small number of operations,
> it is cleaner to have a central support in libqemuutil. This patch adds
> qemu_uuid_* the functions so that all uuid users in the code base can

s/the functions so/functions/

> rely on. Except for qemu_uuid_generate which is new code, all other
> functions are just copy from existing fallbacks from other files.
> 
> Note that qemu_uuid_parse is moved without updating the function
> signature to use QemuUUID, to keep this patch simple.
> 
> Signed-off-by: Fam Zheng 
> ---

> +++ b/include/qemu/uuid.h
> @@ -0,0 +1,59 @@
> +/*
> + *  QEMU UUID functions
> + *
> + *  Copyright 2016 Red Hat, Inc.,

Why the trailing comma?

> +++ b/util/uuid.c
> @@ -0,0 +1,92 @@
> +/*
> + *  QEMU UUID functions
> + *
> + *  Copyright 2016 Red Hat, Inc.,

copy-and-paste? :)


> +
> +#include "qemu/osdep.h"
> +#include "qemu-common.h"
> +#include "qemu/uuid.h"
> +#include "qemu/bswap.h"
> +#include 

Do you still need the  header here? And if so, shouldn't it be
right after osdep.h?

> +
> +void qemu_uuid_generate(QemuUUID *uuid)
> +{
> +int i;
> +uint32_t tmp[4];
> +
> +QEMU_BUILD_BUG_ON(sizeof(QemuUUID) != 16);
> +
> +for (i = 0; i < 4; ++i) {
> +tmp[i] = g_random_int();
> +}
> +memcpy(uuid, tmp, sizeof(tmp));
> +/* Set the two most significant bits (bits 6 and 7) of the
> +  clock_seq_hi_and_reserved to zero and one, respectively. */
> +uuid->data[8] = (uuid->data[8] & 0x3f) | 0x80;
> +/* Set the four most significant bits (bits 12 through 15) of the
> +  time_hi_and_version field to the 4-bit version number.
> +  */
> +uuid->data[6] = (uuid->data[6] & 0xf) | 0x40;
> +}

Looks okay.

> +
> +int qemu_uuid_is_null(const QemuUUID *uu)
> +{
> +QemuUUID null_uuid = { 0 };

Could make this static, so that it doesn't have to be zeroed on every
entry to this function (but in a separate patch, since this one just
moved it, right?)

> +return memcmp(uu, _uuid, sizeof(QemuUUID)) == 0;
> +}
> +

Once the nits are cleaned up, you can add:
Reviewed-by: Eric Blake 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] Adding resolutions to the VGA driver

2016-09-17 Thread G 3


On Sep 17, 2016, at 3:59 AM, Michael Tokarev wrote:


16.09.2016 11:37, Michael Fritscher wrote:

Am 15.09.2016 um 19:21 schrieb Programmingkid:
Following resolutions are also quite common:

1280x960
1280x1024 (Most LCD-Monitors in the 15-17 zoll range had this for  
a long

time, also a standard VESA Resolution)
1400x1050
1600x1200 (Many LCD-Monitors in the 20-21 zoll range had this for  
a long

time, rather "common" resolution)
1920x1080 (the standard full HD resolution)
2560x1440 (the common "next step" after 1920x1080)
3840×2160 (the standard 4k resolution, also known as 2160(p) or  
UHDTV)

7680x4320 (the standard 8k resolution, also known as 4320p, is also
defined as UHDTV)


Please note that resolutions those pixel counts don't divide to 8
wont work with qemu.  In the past that was lead to crashes, now
just garbled guest display.

Or maybe even 16, memory is failing.

/mjt


Thank you very much for the info. This would explain why 1366x768 was  
all messed up in Mac OS X.


[Qemu-devel] [Bug 1624726] Re: Integrator/CP regression after QOM'ification of integratorcp.c

2016-09-17 Thread Jakub Jermar
** Bug watch added: Email to helenos-devel@lists #
   mailto:helenos-de...@lists.modry.cz

** Also affects: helenos via
   mailto:helenos-de...@lists.modry.cz
   Importance: Undecided
   Status: New

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

Title:
  Integrator/CP regression after QOM'ification of integratorcp.c

Status in HelenOS branches:
  New
Status in QEMU:
  New

Bug description:
  The following command line no longer works (i.e. the guest does not
  boot) with QEMU 2.7.0:

  qemu-system-arm -M integratorcp -m 128M -kernel
  HelenOS-0.6.0-arm32-integratorcp.boot

  The HelenOS image can be downloaded here:

  http://www.helenos.org/releases/HelenOS-0.6.0-arm32-integratorcp.boot

  I did git bisect and came to this revision:

  a1f42e0c9abc1028a8bb8686dbb3749fcd2d18e8 is the first bad commit
  commit a1f42e0c9abc1028a8bb8686dbb3749fcd2d18e8
  Author: xiaoqiang.zhao 
  Date:   Mon Mar 7 15:05:44 2016 +0800

  hw/arm: QOM'ify integratorcp.c
  
  * Drop the use of old SysBus init function and use instance_init
  * Remove the empty 'icp_pic_class_init' from Typeinfo
  
  Signed-off-by: xiaoqiang zhao 
  Reviewed-by: Peter Maydell 
  Signed-off-by: Peter Maydell 

  :04 04 b73418ea3fb69ed72438776e78786456fe4c414c
  b483e8579037fdae7d136b2f4ada3147bdde92f1 M  hw

  Upon closer inspection, I discovered that for some reason s->memsz in
  integratorcm_init() is zero. In the last good revision, this value was
  128. As a temporary workaround, hardcoding it to this expected value
  fixes the problem.

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



[Qemu-devel] [Bug 1624726] [NEW] Integrator/CP regression after QOM'ification of integratorcp.c

2016-09-17 Thread Jakub Jermar
Public bug reported:

The following command line no longer works (i.e. the guest does not
boot) with QEMU 2.7.0:

qemu-system-arm -M integratorcp -m 128M -kernel
HelenOS-0.6.0-arm32-integratorcp.boot

The HelenOS image can be downloaded here:

http://www.helenos.org/releases/HelenOS-0.6.0-arm32-integratorcp.boot

I did git bisect and came to this revision:

a1f42e0c9abc1028a8bb8686dbb3749fcd2d18e8 is the first bad commit
commit a1f42e0c9abc1028a8bb8686dbb3749fcd2d18e8
Author: xiaoqiang.zhao 
Date:   Mon Mar 7 15:05:44 2016 +0800

hw/arm: QOM'ify integratorcp.c

* Drop the use of old SysBus init function and use instance_init
* Remove the empty 'icp_pic_class_init' from Typeinfo

Signed-off-by: xiaoqiang zhao 
Reviewed-by: Peter Maydell 
Signed-off-by: Peter Maydell 

:04 04 b73418ea3fb69ed72438776e78786456fe4c414c
b483e8579037fdae7d136b2f4ada3147bdde92f1 M  hw

Upon closer inspection, I discovered that for some reason s->memsz in
integratorcm_init() is zero. In the last good revision, this value was
128. As a temporary workaround, hardcoding it to this expected value
fixes the problem.

** Affects: helenos
 Importance: Undecided
 Status: New

** Affects: qemu
 Importance: Undecided
 Status: New


** Tags: arm helenos integratorcp

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

Title:
  Integrator/CP regression after QOM'ification of integratorcp.c

Status in HelenOS branches:
  New
Status in QEMU:
  New

Bug description:
  The following command line no longer works (i.e. the guest does not
  boot) with QEMU 2.7.0:

  qemu-system-arm -M integratorcp -m 128M -kernel
  HelenOS-0.6.0-arm32-integratorcp.boot

  The HelenOS image can be downloaded here:

  http://www.helenos.org/releases/HelenOS-0.6.0-arm32-integratorcp.boot

  I did git bisect and came to this revision:

  a1f42e0c9abc1028a8bb8686dbb3749fcd2d18e8 is the first bad commit
  commit a1f42e0c9abc1028a8bb8686dbb3749fcd2d18e8
  Author: xiaoqiang.zhao 
  Date:   Mon Mar 7 15:05:44 2016 +0800

  hw/arm: QOM'ify integratorcp.c
  
  * Drop the use of old SysBus init function and use instance_init
  * Remove the empty 'icp_pic_class_init' from Typeinfo
  
  Signed-off-by: xiaoqiang zhao 
  Reviewed-by: Peter Maydell 
  Signed-off-by: Peter Maydell 

  :04 04 b73418ea3fb69ed72438776e78786456fe4c414c
  b483e8579037fdae7d136b2f4ada3147bdde92f1 M  hw

  Upon closer inspection, I discovered that for some reason s->memsz in
  integratorcm_init() is zero. In the last good revision, this value was
  128. As a temporary workaround, hardcoding it to this expected value
  fixes the problem.

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



Re: [Qemu-devel] [PATCH v18 00/13] AVR target

2016-09-17 Thread Michael Rolnik
Thank you Richard.


On Sat, Sep 17, 2016 at 1:00 AM, Richard Henderson  wrote:

> This is Michael's v17, with some adjustments of my own:
>
> (1) Fix the whitespace errors reported by "git am",
> (2) Replace the utf-8 characters with normal ascii,
> (3) Ditch the separate compilation of translate.c.
>
> I retained the two separate files that could be regenerated
> from the included cpugen program, but merged in translate-insn.c.
> Not that it matters, but the code generated is about 3k smaller.
>
>
> r~
>
>
> Michael Rolnik (9):
>   target-avr: AVR cores support is added.
>   target-avr: adding AVR CPU features/flavors
>   target-avr: adding a sample AVR board
>   target-avr: adding instructions encodings
>   target-avr: adding AVR interrupt handling
>   target-avr: adding helpers for IN, OUT, SLEEP, WBR & unsupported
> instructions
>   target-avr: adding instruction translation
>   target-avr: instruction decoder generator
>   target-avr: adding instruction decoder
>
> Richard Henderson (4):
>   target-avr: Put env pointer in DisasContext
>   target-avr: Put all translation code into one compilation unit
>   target-avr: Respect .inc.c convention
>   target-avr: Merge translate-inst.inc.c into translate.c
>
>  MAINTAINERS|6 +
>  arch_init.c|2 +
>  configure  |5 +
>  default-configs/avr-softmmu.mak|   21 +
>  hw/avr/Makefile.objs   |   21 +
>  hw/avr/sample.c|  111 ++
>  include/disas/bfd.h|6 +
>  include/sysemu/arch_init.h |1 +
>  target-avr/Makefile.objs   |   23 +
>  target-avr/cpu-qom.h   |   84 +
>  target-avr/cpu.c   |  602 ++
>  target-avr/cpu.h   |  237 +++
>  target-avr/cpugen/CMakeLists.txt   |   38 +
>  target-avr/cpugen/README.md|   17 +
>  target-avr/cpugen/cpu/avr.yaml |  213 ++
>  target-avr/cpugen/src/CMakeLists.txt   |   62 +
>  target-avr/cpugen/src/cpugen.cpp   |  457 +
>  target-avr/cpugen/src/utils.cpp|   26 +
>  target-avr/cpugen/src/utils.h  |   78 +
>  target-avr/cpugen/xsl/decode.c.xsl |  103 +
>  target-avr/cpugen/xsl/translate-inst.h.xsl |  118 ++
>  target-avr/cpugen/xsl/utils.xsl|  108 ++
>  target-avr/decode.inc.c|  689 +++
>  target-avr/gdbstub.c   |   85 +
>  target-avr/helper.c|  355 
>  target-avr/helper.h|   28 +
>  target-avr/machine.c   |  114 ++
>  target-avr/translate-inst.h|  691 +++
>  target-avr/translate.c | 2911
> 
>  29 files changed, 7212 insertions(+)
>  create mode 100644 default-configs/avr-softmmu.mak
>  create mode 100644 hw/avr/Makefile.objs
>  create mode 100644 hw/avr/sample.c
>  create mode 100644 target-avr/Makefile.objs
>  create mode 100644 target-avr/cpu-qom.h
>  create mode 100644 target-avr/cpu.c
>  create mode 100644 target-avr/cpu.h
>  create mode 100644 target-avr/cpugen/CMakeLists.txt
>  create mode 100644 target-avr/cpugen/README.md
>  create mode 100644 target-avr/cpugen/cpu/avr.yaml
>  create mode 100644 target-avr/cpugen/src/CMakeLists.txt
>  create mode 100644 target-avr/cpugen/src/cpugen.cpp
>  create mode 100644 target-avr/cpugen/src/utils.cpp
>  create mode 100644 target-avr/cpugen/src/utils.h
>  create mode 100644 target-avr/cpugen/xsl/decode.c.xsl
>  create mode 100644 target-avr/cpugen/xsl/translate-inst.h.xsl
>  create mode 100644 target-avr/cpugen/xsl/utils.xsl
>  create mode 100644 target-avr/decode.inc.c
>  create mode 100644 target-avr/gdbstub.c
>  create mode 100644 target-avr/helper.c
>  create mode 100644 target-avr/helper.h
>  create mode 100644 target-avr/machine.c
>  create mode 100644 target-avr/translate-inst.h
>  create mode 100644 target-avr/translate.c
>
> --
> 2.7.4
>
>


-- 
Best Regards,
Michael Rolnik


Re: [Qemu-devel] [PATCH v5 1/8] linux-user: Add support for adjtimex() syscall

2016-09-17 Thread Laurent Vivier


Le 14/09/2016 à 22:19, Aleksandar Markovic a écrit :
> From: Aleksandar Markovic 
> 
> This patch implements Qemu user mode adjtimex() syscall support.
> 
> Syscall adjtimex() reads and optionally sets parameters for a clock
> adjustment algorithm used in network synchonization or similar scenarios.
> 
> The implementation is based on invocation of host's adjtimex(), and
> its key part is in the correspondent case segment of the main switch
> statement of the function do_syscall(), in file linux-user/syscalls.c.
> Also, support for related structure "timex" is added to the file
> linux-user/syscall_defs.h, based on its definition in Linux kernel. All
> necessary conversions of the data structures from target to host and from
> host to target are covered. Two new functions, target_to_host_timex() and
> host_to_target_timex(), are provided for the purpose of such conversions.
> Moreover, the relevant support for "-strace" Qemu option is included in
> files linux-user/strace.c and linux-user/strace.list.
> 
> This patch also fixes failures of LTP tests adjtimex01 and adjtimex02, if
> executed in Qemu user mode.
> 
> Signed-off-by: Aleksandar Rikalo 
> Signed-off-by: Aleksandar Markovic 
> ---
>  linux-user/strace.c   | 12 +++
>  linux-user/strace.list|  2 +-
>  linux-user/syscall.c  | 90 
> ++-
>  linux-user/syscall_defs.h | 28 +++
>  4 files changed, 130 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/strace.c b/linux-user/strace.c
> index cc10dc4..7ddcaf8 100644
> --- a/linux-user/strace.c
> +++ b/linux-user/strace.c
> @@ -919,6 +919,18 @@ print_access(const struct syscallname *name,
>  }
>  #endif
>  
> +#ifdef TARGET_NR_adjtimex
> +static void
> +print_adjtimex(const struct syscallname *name,
> +abi_long arg0, abi_long arg1, abi_long arg2,
> +abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> +print_syscall_prologue(name);
> +print_pointer(arg0, 1);
> +print_syscall_epilogue(name);
> +}
> +#endif
> +
>  #ifdef TARGET_NR_brk
>  static void
>  print_brk(const struct syscallname *name,
> diff --git a/linux-user/strace.list b/linux-user/strace.list
> index aa967a2..9a665a8 100644
> --- a/linux-user/strace.list
> +++ b/linux-user/strace.list
> @@ -16,7 +16,7 @@
>  { TARGET_NR_add_key, "add_key" , NULL, NULL, NULL },
>  #endif
>  #ifdef TARGET_NR_adjtimex
> -{ TARGET_NR_adjtimex, "adjtimex" , NULL, NULL, NULL },
> +{ TARGET_NR_adjtimex, "adjtimex" , NULL, print_adjtimex, NULL },
>  #endif
>  #ifdef TARGET_NR_afs_syscall
>  { TARGET_NR_afs_syscall, "afs_syscall" , NULL, NULL, NULL },
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index ca06943..5643840 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -35,6 +35,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #ifdef __ia64__
>  int __clone2(int (*fn)(void *), void *child_stack_base,
>   size_t stack_size, int flags, void *arg, ...);
> @@ -6578,6 +6579,78 @@ static inline abi_long target_ftruncate64(void 
> *cpu_env, abi_long arg1,
>  }
>  #endif
>  
> +#ifdef TARGET_NR_adjtimex
> +static inline abi_long target_to_host_timex(struct timex *host_buf,
> +abi_long target_addr)
> +{
> +struct target_timex *target_buf;

target_tx instead of target_buf would be nicer(?)

> +
> +if (!lock_user_struct(VERIFY_READ, target_buf, target_addr, 1)) {
> +return -TARGET_EFAULT;
> +}
> +
> +host_buf->modes = tswap32(target_buf->modes);
> +host_buf->offset = tswapal(target_buf->offset);
> +host_buf->freq = tswapal(target_buf->freq);
> +host_buf->maxerror = tswapal(target_buf->maxerror);
> +host_buf->esterror = tswapal(target_buf->esterror);
> +host_buf->status = tswap32(target_buf->status);
> +host_buf->constant = tswapal(target_buf->constant);
> +host_buf->precision = tswapal(target_buf->precision);
> +host_buf->tolerance = tswapal(target_buf->tolerance);
> +host_buf->time.tv_sec = tswapal(target_buf->time.tv_sec);
> +host_buf->time.tv_usec = tswapal(target_buf->time.tv_usec);
> +host_buf->tick = tswapal(target_buf->tick);
> +host_buf->ppsfreq = tswapal(target_buf->ppsfreq);
> +host_buf->jitter = tswapal(target_buf->jitter);
> +host_buf->shift = tswap32(target_buf->shift);
> +host_buf->stabil = tswapal(target_buf->stabil);
> +host_buf->jitcnt = tswapal(target_buf->jitcnt);
> +host_buf->calcnt = tswapal(target_buf->calcnt);
> +host_buf->errcnt = tswapal(target_buf->errcnt);
> +host_buf->stbcnt = tswapal(target_buf->stbcnt);
> +host_buf->tai = tswap32(target_buf->tai);

You should use __get_user(), see
c7e35da linux-user: Handle negative values in timespec conversion


> +
> +unlock_user_struct(target_buf, target_addr, 0);
> +return 0;
> +}
> +
> +static inline abi_long 

Re: [Qemu-devel] [PATCH RFC v1 00/29] ARC cores

2016-09-17 Thread Michael Rolnik
H Alexey.

Thanks.

I need some help in getting a small code that exercises interrupts. For
several years I wrote FW for ARC based platforms (ARC4 & ARC6), but it
seems I forgot some of the things related to interrupts. I compiled
FreeRTOS demo from embARC, however I could not find interrupt vectors
there, I assume their board has ROM.
So, if you can help me with such a code, it would be great.

thanks,
Michael



On Fri, Sep 16, 2016 at 6:01 PM, Alexey Brodkin  wrote:

> Hi Michael,
>
> On Fri, 2016-09-09 at 01:31 +0300, Michael Rolnik wrote:
> > This series of patches adds ARC target to QEMU. It indends to support
> > - ARCtangent-A5 processor
> > - ARC 600 processor
> > - ARC 700 processor
> >
> > All instructions except ASLS are implemented. Not fully tested yet.
> > However I was able to execute correctly recursive fibonacci calculation.
> > Reset vector is assumed to be some hardcoded value which worked for my
> test.
> > I am planning to get FreeRTOS for ARC, once I get it, I will able to
> verify
> > and complete interrupt support.
>
> That's both very unexpected and cool!
>
> I tried your patches on top of current QEMU git master and it:
>  a) Builds for ARC
>  b) Very simple code really works!
>
> I was able to single-step with GDB through program as simple as:
> ->8-
> .global _start
> _start:
> mov r0, 1
> mov r1, 2
> mov r1, r0
> ->8-
>
> That's what I saw in GDB:
> ->8-
> (gdb) disassemble
> Dump of assembler code for function _start:
> => 0x0100 <+0>: mov r0,0x1
>0x0104 <+4>: mov r1,0x2
>0x0108 <+8>: mov r1,r0
> End of assembler dump.
> (gdb) p $r0
> $1 = 0
> (gdb) stepi
> 0x0104 in _start ()
> (gdb) p $r0
> $2 = 1
> (gdb) stepi
> 0x0108 in _start ()
> (gdb) p $r1
> $3 = 2
> (gdb) stepi
> 0x010c in ?? ()
> (gdb) p $r1
> $4 = 1
> ->8-
>
> So again this is very promising even though a lot is essentially missing
> from
> this very first implementation.
>
> Anyways IMHO it would be good to have these patches accepted so people may
> start
> playing with that stuff adding missing things one by one.
>
> Let me know if you need any help from my side.
>
> Regards,
> Alexey




-- 
Best Regards,
Michael Rolnik


[Qemu-devel] Parallel vcpu operation with qemu2.6.0 on KVM

2016-09-17 Thread Tech Linux
Hi All
I am launching an x86 debian system as guest on my x86 host machine. The
host is an 8-core, 2-socket machine booted with RHEL7 with KVM enabled. 2
PCI devices are being emulated on the guest.
-I need to verify the concurrent operation of these PCI devices. PCI device
A is designed in such a way that accesing a particular BAR offset X induces
sleep() in this device for fixed duration. During this sleep duration, the
test application tries to access BAR for PCI device B & write data to it.
- Global locking is cleared while creating  memory regions for both PCI
devices.
- Task affinity is set for processes launched to kick test applications
which are trying to access BARs for PCI A & B.
- When QEMU is booted with -smp 4 option, 4 vcpus are created. By Setting
task affinity , I force the scheduler to schedule access operation for both
devices to separate vcpus.
- In that case, even if PCI device A goes to sleep on say vcpu0, PCI device
B BAR access should be scheduled on another vcpu number chosen using
taskset .
- This behavior is not being observed. When device A enter sleep, R/W
operations on device B are halted & they resume only when device A comes
out of sleep.
- However when I use -smp8 option & instead of setting task affinity for
single vcpu, a range of vcpu numbers is specified( e.g. taskset -c 2,3,4
testPCIdev ), the whole experiment is a succes. Both devices can be
accessed parallely.
Can anyone please share view on why such behavior is observed ?
I am currenty in dark regarding debuggig this problem & need a pointer as
to how should I start debugging this issue.

Regards
LT


[Qemu-devel] [PATCH 6/6] tests/tcg: Add tests-tcg hook in Makefile

2016-09-17 Thread Pranith Kumar
Signed-off-by: Pranith Kumar 
---
 tests/Makefile.include |  1 +
 tests/tcg/Makefile.include | 34 ++
 2 files changed, 35 insertions(+)
 create mode 100644 tests/tcg/Makefile.include

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 2f11064..5f314ed 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -803,3 +803,4 @@ all: $(QEMU_IOTESTS_HELPERS-y)
 
 -include $(wildcard tests/*.d)
 -include $(wildcard tests/libqos/*.d)
+-include $(SRC_PATH)/tests/tcg/Makefile.include
diff --git a/tests/tcg/Makefile.include b/tests/tcg/Makefile.include
new file mode 100644
index 000..a55cb03
--- /dev/null
+++ b/tests/tcg/Makefile.include
@@ -0,0 +1,34 @@
+#
+# linux-user TCG tests
+#
+# The Make is expected to be invoked in the ${BUILD_DIR} directory
+# using the tests-tcg target
+#
+BUILD_DIR?=$(CURDIR)
+include $(BUILD_DIR)/config-host.mak   # brings in SRC_PATH
+
+UNAME_P := $(shell uname -p)
+
+tests-tcg: prepare $(UNAME_P)
+
+prepare:
+   mkdir -p $(BUILD_DIR)/$(UNAME_P)-linux-user/tests/
+
+x86_64:
+   cd $(BUILD_DIR)/x86_64-linux-user/tests/ && \
+   make -f $(SRC_PATH)/tests/tcg/i386/Makefile
+
+i386:
+   cd $(BUILD_DIR)/i386-linux-user/tests/ && \
+   make -f $(SRC_PATH)/tests/tcg/i386/Makefile
+
+arm:
+   cd $(BUILD_DIR)/arm-linux-user/tests/ && \
+   make -f $(SRC_PATH)/tests/tcg/arm/Makefile
+
+aarch64:
+   cd $(BUILD_DIR)/aarch64-linux-user/tests/ && \
+   make -f $(SRC_PATH)/tests/tcg/arm/Makefile
+
+.PHONY: tests-tcg
+
-- 
2.9.3




[Qemu-devel] [PATCH 5/6] tests/tcg: Add and update Makefiles

2016-09-17 Thread Pranith Kumar
Signed-off-by: Pranith Kumar 
---
 tests/tcg/alpha/Makefile | 38 +++--
 tests/tcg/arm/Makefile   | 28 +-
 tests/tcg/cris/Makefile  | 17 +++--
 tests/tcg/i386/Makefile  | 23 +-
 tests/tcg/lm32/Makefile  | 17 +++--
 tests/tcg/mips/Makefile  | 46 
 tests/tcg/mips/mips32-dsp/Makefile   | 17 +++--
 tests/tcg/mips/mips32-dspr2/Makefile | 17 +++--
 tests/tcg/mips/mips64-dsp/Makefile   | 18 --
 tests/tcg/mips/mips64-dspr2/Makefile | 17 -
 tests/tcg/openrisc/Makefile  | 19 ---
 tests/tcg/xtensa/Makefile| 17 +++--
 12 files changed, 223 insertions(+), 51 deletions(-)
 create mode 100644 tests/tcg/mips/Makefile

diff --git a/tests/tcg/alpha/Makefile b/tests/tcg/alpha/Makefile
index 2b1f03d..e20315f 100644
--- a/tests/tcg/alpha/Makefile
+++ b/tests/tcg/alpha/Makefile
@@ -1,33 +1,47 @@
-CROSS=alpha-linux-gnu-
-CC=$(CROSS)gcc
-AS=$(CROSS)as
+# -*- Mode: makefile -*-
+#
+# Alpha linux-user TCG tests
+#
+# The Make is expected to be called in the
+# ${BUILD_DIR}/alpha-linux-user/tests directory
+#
 
-SIM=../../alpha-linux-user/qemu-alpha
+BUILD_DIR?=$(CURDIR)
+include $(BUILD_DIR)/config-host.mak   # brings in SRC_PATH
+include ../config-target.mak   # TARGET_NAME
+include $(SRC_PATH)/rules.mak
 
-CFLAGS=-O
-LINK=$(CC) -o $@ crt.o $< -nostdlib
+$(call set-vpath, $(SRC_PATH)/tests/tcg/alpha)
+
+QEMU=$(BUILD_DIR)/alpha-linux-user/qemu-alpha
+
+# Compiler set-up, default to system compiler if not set
+CROSS_CC?=$(CC)
+
+CFLAGS=-Wall -O2 -g -fno-strict-aliasing -static
+LDFLAGS=-nostdlib
 
 TESTS=test-cond test-cmov
 
 all: hello-alpha $(TESTS)
 
 hello-alpha: hello-alpha.o crt.o
-   $(LINK)
+   $(CROSS_CC) -o $@ crt.o $< $(LDFLAGS)
 
 test-cond: test-cond.o crt.o
-   $(LINK)
+   $(CROSS_CC) -o $@ crt.o $< $(LDFLAGS)
 
 test-cmov.o: test-cond.c
-   $(CC) -c $(CFLAGS) -DTEST_CMOV -o $@ $<
+   $(CROSS_CC) -c $(CFLAGS) -DTEST_CMOV -o $@ $<
 
 test-cmov: test-cmov.o crt.o
-   $(LINK)
+   $(CROSS_CC) -o $@ crt.o $< $(LDFLAGS)
 
 test-ovf: test-ovf.o crt.o
-   $(LINK)
+   $(CROSS_CC) -o $@ crt.o $< $(LDFLAGS)
 
 check: $(TESTS)
-   for f in $(TESTS); do $(SIM) $$f || exit 1; done
+   for f in $(TESTS); do $(QEMU) $$f || exit 1; done
 
 clean:
$(RM) *.o *~ hello-alpha $(TESTS)
diff --git a/tests/tcg/arm/Makefile b/tests/tcg/arm/Makefile
index c2ae491..8eafae6 100644
--- a/tests/tcg/arm/Makefile
+++ b/tests/tcg/arm/Makefile
@@ -1,21 +1,27 @@
-BUILD_DIR?=$(CURDIR)
-SRC_PATH=../../../
-include $(BUILD_DIR)/config-host.mak
+# -*- Mode: makefile -*-
+#
+# Arm linux-user TCG tests
+#
+# The Make is expected to be called in the
+# ${BUILD_DIR}/arm-linux-user/tests directory
+#
+
+BUILD_DIR=../..
+include $(BUILD_DIR)/config-host.mak   # brings in SRC_PATH
+include ../config-target.mak   # TARGET_NAME
 include $(SRC_PATH)/rules.mak
 
 $(call set-vpath, $(SRC_PATH)/tests/tcg/arm)
 
 QEMU=$(BUILD_DIR)/arm-linux-user/qemu-arm
 
+# Compiler set-up, default to system compiler if not set
+CROSS_CC?=$(CC)
+
 QEMU_INCLUDES += -I$(BUILD_DIR)
 CFLAGS=-Wall -O2 -g -fno-strict-aliasing
 LDFLAGS=
 
-# TODO: automatically detect ARM and MIPS compilers, and run those too
-
-# runcom maps page 0, so it requires root privileges
-# also, pi_10.com runs indefinitely
-
 TESTS=hello-arm arm-iwmmxt
 
 all: $(patsubst %,run-%,$(TESTS))
@@ -33,13 +39,13 @@ run-arm-iwmmxt: arm-iwmmxt
 
 # arm test
 hello-arm: hello-arm.o
-   arm-linux-gnueabi-ld -o $@ $<
+   $(CROSS_CC) -o $@ $<
 
 hello-arm.o: hello-arm.c
-   arm-linux-gnueabi-gcc -Wall -g -O2 -c -o $@ $<
+   $(CROSS_CC) -Wall -g -O2 -c -o $@ $<
 
 arm-iwmmxt: test-arm-iwmmxt.s
-   cpp < $< | arm-linux-gnueabi-gcc -Wall -static -march=iwmmxt 
-mabi=aapcs -x assembler - -o $@
+   cpp < $< | $(CROSS_CC) -Wall -static -march=iwmmxt -mabi=aapcs -x 
assembler - -o $@
 
 clean:
rm -f *~ *.o $(TESTS)
diff --git a/tests/tcg/cris/Makefile b/tests/tcg/cris/Makefile
index d34bfd8..aa8be36 100644
--- a/tests/tcg/cris/Makefile
+++ b/tests/tcg/cris/Makefile
@@ -1,7 +1,20 @@
--include ../../../config-host.mak
+# -*- Mode: makefile -*-
+#
+# Cris linux-user TCG tests
+#
+# The Make is expected to be called in the
+# ${BUILD_DIR}/cris-linux-user/tests directory
+#
+
+BUILD_DIR=../..
+include $(BUILD_DIR)/config-host.mak   # brings in SRC_PATH
+include ../config-target.mak   # TARGET_NAME
+include $(SRC_PATH)/rules.mak
+
+$(call set-vpath, $(SRC_PATH)/tests/tcg/arm)
 
 CROSS=crisv32-axis-linux-gnu-
-SIM=../../../cris-linux-user/qemu-cris -L ./
+SIM=$(BUILD_DIR)/cris-linux-user/qemu-cris -L ./
 SIMG=cris-axis-linux-gnu-run --sysroot=./
 
 CC  = $(CROSS)gcc
diff --git a/tests/tcg/i386/Makefile b/tests/tcg/i386/Makefile
index 

[Qemu-devel] [PATCH 2/6] tests/tcg: Move arm tests to arch specific folder

2016-09-17 Thread Pranith Kumar
Signed-off-by: Pranith Kumar 
---
 tests/tcg/arm/Makefile| 45 +++
 tests/tcg/{ => arm}/hello-arm.c   |  0
 tests/tcg/{ => arm}/test-arm-iwmmxt.s |  0
 3 files changed, 45 insertions(+)
 create mode 100644 tests/tcg/arm/Makefile
 rename tests/tcg/{ => arm}/hello-arm.c (100%)
 rename tests/tcg/{ => arm}/test-arm-iwmmxt.s (100%)

diff --git a/tests/tcg/arm/Makefile b/tests/tcg/arm/Makefile
new file mode 100644
index 000..c2ae491
--- /dev/null
+++ b/tests/tcg/arm/Makefile
@@ -0,0 +1,45 @@
+BUILD_DIR?=$(CURDIR)
+SRC_PATH=../../../
+include $(BUILD_DIR)/config-host.mak
+include $(SRC_PATH)/rules.mak
+
+$(call set-vpath, $(SRC_PATH)/tests/tcg/arm)
+
+QEMU=$(BUILD_DIR)/arm-linux-user/qemu-arm
+
+QEMU_INCLUDES += -I$(BUILD_DIR)
+CFLAGS=-Wall -O2 -g -fno-strict-aliasing
+LDFLAGS=
+
+# TODO: automatically detect ARM and MIPS compilers, and run those too
+
+# runcom maps page 0, so it requires root privileges
+# also, pi_10.com runs indefinitely
+
+TESTS=hello-arm arm-iwmmxt
+
+all: $(patsubst %,run-%,$(TESTS))
+test: all
+
+# rules to run tests
+
+run-%: %
+   $(QEMU) ./$*
+
+#.PHONY: $(patsubst %,run-%,$(TESTS))
+
+run-hello-arm: hello-arm
+run-arm-iwmmxt: arm-iwmmxt
+
+# arm test
+hello-arm: hello-arm.o
+   arm-linux-gnueabi-ld -o $@ $<
+
+hello-arm.o: hello-arm.c
+   arm-linux-gnueabi-gcc -Wall -g -O2 -c -o $@ $<
+
+arm-iwmmxt: test-arm-iwmmxt.s
+   cpp < $< | arm-linux-gnueabi-gcc -Wall -static -march=iwmmxt 
-mabi=aapcs -x assembler - -o $@
+
+clean:
+   rm -f *~ *.o $(TESTS)
diff --git a/tests/tcg/hello-arm.c b/tests/tcg/arm/hello-arm.c
similarity index 100%
rename from tests/tcg/hello-arm.c
rename to tests/tcg/arm/hello-arm.c
diff --git a/tests/tcg/test-arm-iwmmxt.s b/tests/tcg/arm/test-arm-iwmmxt.s
similarity index 100%
rename from tests/tcg/test-arm-iwmmxt.s
rename to tests/tcg/arm/test-arm-iwmmxt.s
-- 
2.9.3




[Qemu-devel] [PATCH 4/6] tests/tcg: Create and populate misc tests for arch independent tests

2016-09-17 Thread Pranith Kumar
Signed-off-by: Pranith Kumar 
---
 tests/tcg/misc/Makefile   | 81 +++
 tests/tcg/{ => misc}/linux-test.c |  3 ++
 tests/tcg/{ => misc}/sha1.c   |  0
 tests/tcg/{ => misc}/test-mmap.c  |  0
 tests/tcg/{ => misc}/test_path.c  |  0
 tests/tcg/{ => misc}/testthread.c |  0
 6 files changed, 84 insertions(+)
 create mode 100644 tests/tcg/misc/Makefile
 rename tests/tcg/{ => misc}/linux-test.c (99%)
 rename tests/tcg/{ => misc}/sha1.c (100%)
 rename tests/tcg/{ => misc}/test-mmap.c (100%)
 rename tests/tcg/{ => misc}/test_path.c (100%)
 rename tests/tcg/{ => misc}/testthread.c (100%)

diff --git a/tests/tcg/misc/Makefile b/tests/tcg/misc/Makefile
new file mode 100644
index 000..0aa6f2e
--- /dev/null
+++ b/tests/tcg/misc/Makefile
@@ -0,0 +1,81 @@
+# -*- Mode: makefile -*-
+#
+# Generic linux-user TCG tests
+#
+# These tests all use standard non-architecture specific APIs so can
+# be built for all TCG targets. The Make is expected to be called in
+# the ${BUILD_DIR}/$(TARGET_NAME_ARCH)-linux-user/tests directory
+#
+# To build for other architectures call make with CROSS_CC set
+#
+
+BUILD_DIR=../..
+include $(BUILD_DIR)/config-host.mak   # brings in SRC_PATH
+include ../config-target.mak   # TARGET_NAME
+include $(SRC_PATH)/rules.mak
+
+$(call set-vpath, $(SRC_PATH)/tests/tcg/misc)
+
+QEMU=$(BUILD_DIR)/$(TARGET_NAME)-linux-user/qemu-$(TARGET_NAME)
+
+# Compiler set-up, default to system compiler if not set
+CROSS_CC?=$(CC)
+
+CFLAGS=-Wall -O2 -g -fno-strict-aliasing -static
+LDFLAGS=
+
+TESTS=linux-test \
+  testthread \
+  sha1 \
+  test-mmap
+
+all: $(patsubst %,run-%,$(TESTS))
+test: all
+
+# rules to run tests
+
+run-%: %
+   -$(QEMU) ./$*
+
+run-linux-test: linux-test
+run-testthread: testthread
+run-sha1: sha1
+run-test_path: test_path
+
+run-test-mmap: test-mmap
+   -$(QEMU) ./test-mmap
+   -$(QEMU) -p 8192 ./test-mmap 8192
+   -$(QEMU) -p 16384 ./test-mmap 16384
+   -$(QEMU) -p 32768 ./test-mmap 32768
+
+run-test_path: test_path
+
+# rules to compile tests
+
+# These two need to be re-written as relying on glib (rather than just glibc)
+# test_path: test_path.o
+#  $(CROSS_CC) $^ -o $@ -lglib-2.0
+
+# test_path.o: test_path.c
+#  $(CROSS_CC) $^ -c -o $@ $(QEMU_INCLUDES) `pkg-config --cflags --libs 
glib-2.0`
+
+testthread: testthread.c
+   $(CROSS_CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lpthread
+
+# generic Linux and CPU test
+linux-test: linux-test.c
+   $(CROSS_CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lm
+
+test-mmap: test-mmap.c
+   $(CROSS_CC) $(CFLAGS) -Wall -O2 $(LDFLAGS) -o $@ $< -static
+
+# speed test
+sha1: sha1.c
+   $(CROSS_CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
+
+speed: sha1
+   time ./sha1
+   time $(QEMU) ./sha1
+
+clean:
+   rm -f *~ *.o $(TESTS)
diff --git a/tests/tcg/linux-test.c b/tests/tcg/misc/linux-test.c
similarity index 99%
rename from tests/tcg/linux-test.c
rename to tests/tcg/misc/linux-test.c
index 5070d31..41ad91c 100644
--- a/tests/tcg/linux-test.c
+++ b/tests/tcg/misc/linux-test.c
@@ -39,6 +39,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include "qemu/compiler.h"
 #include "qemu/cutils.h"
 
 #define TESTPATH "/tmp/linux-test.tmp"
diff --git a/tests/tcg/sha1.c b/tests/tcg/misc/sha1.c
similarity index 100%
rename from tests/tcg/sha1.c
rename to tests/tcg/misc/sha1.c
diff --git a/tests/tcg/test-mmap.c b/tests/tcg/misc/test-mmap.c
similarity index 100%
rename from tests/tcg/test-mmap.c
rename to tests/tcg/misc/test-mmap.c
diff --git a/tests/tcg/test_path.c b/tests/tcg/misc/test_path.c
similarity index 100%
rename from tests/tcg/test_path.c
rename to tests/tcg/misc/test_path.c
diff --git a/tests/tcg/testthread.c b/tests/tcg/misc/testthread.c
similarity index 100%
rename from tests/tcg/testthread.c
rename to tests/tcg/misc/testthread.c
-- 
2.9.3




[Qemu-devel] [PATCH v3 0/6] Clean up TCG tests

2016-09-17 Thread Pranith Kumar
Hello,

This patch series cleans up the tcg tests in tests/tcg folder.

The tests have bit-rotten and were not compiling or running. I fixed
the Makefiles to make them compile but there are tests which do not
pass.

The motivation is to add litmus tests to each arch and have them run
using the 'make check' target to test consistency on TCG.

There are no maintainers listed for this test folder. So I am cc'ing
people who I think might be interested.

As suggested by rth in v1 posting, I hooked up 'tests-tcg' target to
run native tests. Detecting cross compilers or running the tests
in docker containers are suggested ideas to make running the tests
easier.

v3:
  - Update with review feedback from Alex Bennée.

v2:
  - Add tests-tcg target to invoke native tests.

Pranith Kumar (6):
  tests/tcg: Move i386 tests to arch specific folder
  tests/tcg: Move arm tests to arch specific folder
  tests/tcg: Move mips test to arch specific folder
  tests/tcg: Create and populate misc tests for arch independent tests
  tests/tcg: Add and update Makefiles
  tests/tcg: Add tests-tcg hook in Makefile

 tests/Makefile.include  |   1 +
 tests/tcg/Makefile  | 156 
 tests/tcg/Makefile.include  |  34 +++
 tests/tcg/alpha/Makefile|  38 +---
 tests/tcg/arm/Makefile  |  51 +++
 tests/tcg/{ => arm}/hello-arm.c |   0
 tests/tcg/{ => arm}/test-arm-iwmmxt.s   |   0
 tests/tcg/cris/Makefile |  17 +++-
 tests/tcg/i386/Makefile |  87 ++
 tests/tcg/{ => i386}/hello-i386.c   |   9 +-
 tests/tcg/{ => i386}/pi_10.com  | Bin
 tests/tcg/{ => i386}/runcom.c   |   0
 tests/tcg/{ => i386}/test-i386-code16.S |   0
 tests/tcg/{ => i386}/test-i386-fprem.c  |   0
 tests/tcg/{ => i386}/test-i386-muldiv.h |   0
 tests/tcg/{ => i386}/test-i386-shift.h  |   0
 tests/tcg/{ => i386}/test-i386-ssse3.c  |   0
 tests/tcg/{ => i386}/test-i386-vm86.S   |   0
 tests/tcg/{ => i386}/test-i386.c|   0
 tests/tcg/{ => i386}/test-i386.h|   0
 tests/tcg/lm32/Makefile |  17 +++-
 tests/tcg/mips/Makefile |  46 ++
 tests/tcg/{ => mips}/hello-mips.c   |   0
 tests/tcg/mips/mips32-dsp/Makefile  |  17 +++-
 tests/tcg/mips/mips32-dspr2/Makefile|  17 +++-
 tests/tcg/mips/mips64-dsp/Makefile  |  18 +++-
 tests/tcg/mips/mips64-dspr2/Makefile|  17 +++-
 tests/tcg/misc/Makefile |  81 +
 tests/tcg/{ => misc}/linux-test.c   |   3 +
 tests/tcg/{ => misc}/sha1.c |   0
 tests/tcg/{ => misc}/test-mmap.c|   0
 tests/tcg/{ => misc}/test_path.c|   0
 tests/tcg/{ => misc}/testthread.c   |   0
 tests/tcg/openrisc/Makefile |  19 +++-
 tests/tcg/xtensa/Makefile   |  17 +++-
 35 files changed, 457 insertions(+), 188 deletions(-)
 delete mode 100644 tests/tcg/Makefile
 create mode 100644 tests/tcg/Makefile.include
 create mode 100644 tests/tcg/arm/Makefile
 rename tests/tcg/{ => arm}/hello-arm.c (100%)
 rename tests/tcg/{ => arm}/test-arm-iwmmxt.s (100%)
 create mode 100644 tests/tcg/i386/Makefile
 rename tests/tcg/{ => i386}/hello-i386.c (71%)
 rename tests/tcg/{ => i386}/pi_10.com (100%)
 rename tests/tcg/{ => i386}/runcom.c (100%)
 rename tests/tcg/{ => i386}/test-i386-code16.S (100%)
 rename tests/tcg/{ => i386}/test-i386-fprem.c (100%)
 rename tests/tcg/{ => i386}/test-i386-muldiv.h (100%)
 rename tests/tcg/{ => i386}/test-i386-shift.h (100%)
 rename tests/tcg/{ => i386}/test-i386-ssse3.c (100%)
 rename tests/tcg/{ => i386}/test-i386-vm86.S (100%)
 rename tests/tcg/{ => i386}/test-i386.c (100%)
 rename tests/tcg/{ => i386}/test-i386.h (100%)
 create mode 100644 tests/tcg/mips/Makefile
 rename tests/tcg/{ => mips}/hello-mips.c (100%)
 create mode 100644 tests/tcg/misc/Makefile
 rename tests/tcg/{ => misc}/linux-test.c (99%)
 rename tests/tcg/{ => misc}/sha1.c (100%)
 rename tests/tcg/{ => misc}/test-mmap.c (100%)
 rename tests/tcg/{ => misc}/test_path.c (100%)
 rename tests/tcg/{ => misc}/testthread.c (100%)

-- 
2.9.3




[Qemu-devel] [PATCH 1/6] tests/tcg: Move i386 tests to arch specific folder

2016-09-17 Thread Pranith Kumar
Signed-off-by: Pranith Kumar 
---
 tests/tcg/Makefile  | 156 
 tests/tcg/i386/Makefile |  88 ++
 tests/tcg/{ => i386}/hello-i386.c   |   9 +-
 tests/tcg/{ => i386}/pi_10.com  | Bin
 tests/tcg/{ => i386}/runcom.c   |   0
 tests/tcg/{ => i386}/test-i386-code16.S |   0
 tests/tcg/{ => i386}/test-i386-fprem.c  |   0
 tests/tcg/{ => i386}/test-i386-muldiv.h |   0
 tests/tcg/{ => i386}/test-i386-shift.h  |   0
 tests/tcg/{ => i386}/test-i386-ssse3.c  |   0
 tests/tcg/{ => i386}/test-i386-vm86.S   |   0
 tests/tcg/{ => i386}/test-i386.c|   0
 tests/tcg/{ => i386}/test-i386.h|   0
 13 files changed, 93 insertions(+), 160 deletions(-)
 delete mode 100644 tests/tcg/Makefile
 create mode 100644 tests/tcg/i386/Makefile
 rename tests/tcg/{ => i386}/hello-i386.c (71%)
 rename tests/tcg/{ => i386}/pi_10.com (100%)
 rename tests/tcg/{ => i386}/runcom.c (100%)
 rename tests/tcg/{ => i386}/test-i386-code16.S (100%)
 rename tests/tcg/{ => i386}/test-i386-fprem.c (100%)
 rename tests/tcg/{ => i386}/test-i386-muldiv.h (100%)
 rename tests/tcg/{ => i386}/test-i386-shift.h (100%)
 rename tests/tcg/{ => i386}/test-i386-ssse3.c (100%)
 rename tests/tcg/{ => i386}/test-i386-vm86.S (100%)
 rename tests/tcg/{ => i386}/test-i386.c (100%)
 rename tests/tcg/{ => i386}/test-i386.h (100%)

diff --git a/tests/tcg/Makefile b/tests/tcg/Makefile
deleted file mode 100644
index 89e3342..000
--- a/tests/tcg/Makefile
+++ /dev/null
@@ -1,156 +0,0 @@
--include ../../config-host.mak
--include $(SRC_PATH)/rules.mak
-
-$(call set-vpath, $(SRC_PATH)/tests/tcg)
-
-QEMU=../../i386-linux-user/qemu-i386
-QEMU_X86_64=../../x86_64-linux-user/qemu-x86_64
-CC_X86_64=$(CC_I386) -m64
-
-QEMU_INCLUDES += -I../..
-CFLAGS=-Wall -O2 -g -fno-strict-aliasing
-#CFLAGS+=-msse2
-LDFLAGS=
-
-# TODO: automatically detect ARM and MIPS compilers, and run those too
-
-# runcom maps page 0, so it requires root privileges
-# also, pi_10.com runs indefinitely
-
-I386_TESTS=hello-i386 \
-  linux-test \
-  testthread \
-  sha1-i386 \
-  test-i386 \
-  test-i386-fprem \
-  test-mmap \
-  # runcom
-
-# native i386 compilers sometimes are not biarch.  assume cross-compilers are
-ifneq ($(ARCH),i386)
-I386_TESTS+=run-test-x86_64
-endif
-
-TESTS = test_path
-ifneq ($(call find-in-path, $(CC_I386)),)
-TESTS += $(I386_TESTS)
-endif
-
-all: $(patsubst %,run-%,$(TESTS))
-test: all
-
-# rules to run tests
-
-.PHONY: $(patsubst %,run-%,$(TESTS))
-
-run-%: %
-   -$(QEMU) ./$*
-
-run-hello-i386: hello-i386
-run-linux-test: linux-test
-run-testthread: testthread
-run-sha1-i386: sha1-i386
-
-run-test-i386: test-i386
-   ./test-i386 > test-i386.ref
-   -$(QEMU) test-i386 > test-i386.out
-   @if diff -u test-i386.ref test-i386.out ; then echo "Auto Test OK"; fi
-
-run-test-i386-fprem: test-i386-fprem
-   ./test-i386-fprem > test-i386-fprem.ref
-   -$(QEMU) test-i386-fprem > test-i386-fprem.out
-   @if diff -u test-i386-fprem.ref test-i386-fprem.out ; then echo "Auto 
Test OK"; fi
-
-run-test-x86_64: test-x86_64
-   ./test-x86_64 > test-x86_64.ref
-   -$(QEMU_X86_64) test-x86_64 > test-x86_64.out
-   @if diff -u test-x86_64.ref test-x86_64.out ; then echo "Auto Test OK"; 
fi
-
-run-test-mmap: test-mmap
-   -$(QEMU) ./test-mmap
-   -$(QEMU) -p 8192 ./test-mmap 8192
-   -$(QEMU) -p 16384 ./test-mmap 16384
-   -$(QEMU) -p 32768 ./test-mmap 32768
-
-run-runcom: runcom
-   -$(QEMU) ./runcom $(SRC_PATH)/tests/pi_10.com
-
-run-test_path: test_path
-   ./test_path
-
-# rules to compile tests
-
-test_path: test_path.o
-
-test_path.o: test_path.c
-
-hello-i386: hello-i386.c
-   $(CC_I386) -nostdlib $(CFLAGS) -static $(LDFLAGS) -o $@ $<
-   strip $@
-
-testthread: testthread.c
-   $(CC_I386) $(CFLAGS) $(LDFLAGS) -o $@ $< -lpthread
-
-# i386/x86_64 emulation test (test various opcodes) */
-test-i386: test-i386.c test-i386-code16.S test-i386-vm86.S \
-   test-i386.h test-i386-shift.h test-i386-muldiv.h
-   $(CC_I386) $(QEMU_INCLUDES) $(CFLAGS) $(LDFLAGS) -o $@ \
-  $(

[Qemu-devel] [PATCH 3/6] tests/tcg: Move mips test to arch specific folder

2016-09-17 Thread Pranith Kumar
Signed-off-by: Pranith Kumar 
---
 tests/tcg/{ => mips}/hello-mips.c | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename tests/tcg/{ => mips}/hello-mips.c (100%)

diff --git a/tests/tcg/hello-mips.c b/tests/tcg/mips/hello-mips.c
similarity index 100%
rename from tests/tcg/hello-mips.c
rename to tests/tcg/mips/hello-mips.c
-- 
2.9.3




[Qemu-devel] Help wanted: QEMU Advent Calendar 2016

2016-09-17 Thread Thomas Huth

 Hi all!

This year, we are celebrating the 10th anniversary of KVM [1] (and the
25th anniversary of Linux), so to contribute to this celebration, we
would like to reanimate the QEMU Advent Calendar.

If you didn't see the previous QEMU Advent Calendar 2014 yet, have a look at

  http://www.qemu-advent-calendar.org/

This year, too, the QEMU Advent Calendar 2016 will be a website that
reveals a new disk image for download each day in December until the
holiday season starts. Launching the disk image under QEMU will bring up
a nice surprise!

But to be able to make this happen, we need help from people who
- have ideas for disk images
- would like to prepare one or more disk images.
Ideally, you have an idea for a disk image and also prepare it yourself.
But we also are glad to get just the ideas, or help from people who
would like to prepare a disk image with the idea from somebody else!

Disk image requirements:
 * We need 24 disk images (for the first 24 days of December)
 * Content must be freely redistributable (i.e. no proprietary
   license that prevents distribution). For GPL based software,
   you need to provide the source code, too.
 * Provide a name and a short description of the disk image
   (e.g. with hints on what to try)
 * Provide a ./run shell script that prints out the name and
   description/hints and launches QEMU
 * Provide a screenshot/image/logo for the website
 * Size should be ideally under 100 MB per disk image

Are you interested in participating? Then please reply to this email
(off-list if you do not want to spoil your idea for disk images).

Or do you have questions? Then feel free to reply or ask on the #qemu
channel on irc.oftc.net, too.

 Thomas & Kashyap


PS: The QEMU Advent Calendar 2016 is a secular calendar (not
religious). The idea is for the QEMU community to create a fun
experience to share with everyone, and to celebrate the 10th anniversary
of KVM. You don't need to celebrate Christmas or another religious
festival to participate!

PPS: Thanks to Stefan Hajnoczi for organizing the Advent Calendar 2014
... as you might have noticed, I also shamelessly lent some ideas and
sentences from his announcement e-mail from two years ago :-) [2]


[1] According to the following presentation, the anouncement of KVM was
in October 2006:
 http://www.linux-kvm.org/images/6/61/KvmForum2007$kf2007-keynote.pdf

[2] http://lists.nongnu.org/archive/html/qemu-devel/2014-10/msg02592.html



[Qemu-devel] 答复: Re: [PATCH v2] object: Add 'help' option for all available backends and properties

2016-09-17 Thread Lin Ma


>>> "Daniel P. Berrange"  2016/9/12 星期一 下午 11:56 >>>
>On Sun, Sep 11, 2016 at 01:53:01PM +0800, Lin Ma wrote:
>> '-object help' prints available user creatable backends.
>> '-object $typename,help' prints relevant properties.
>> 
>> Signed-off-by: Lin Ma 
>> ---
>>  include/qom/object_interfaces.h |   2 +
>>  qemu-options.hx   |   7 ++-
>>  qom/object_interfaces.c   | 112 
>>  vl.c |   5 ++
>>  4 files changed, 125 insertions(+), 1 deletion(-)
>
>> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
>> index bf59846..4ee8643 100644
>> --- a/qom/object_interfaces.c
>> +++ b/qom/object_interfaces.c
>> @@ -5,6 +5,7 @@
>>  #include "qapi-visit.h"
>>  #include "qapi/qmp-output-visitor.h"
>>  #include "qapi/opts-visitor.h"
>> +#include "qemu/help_option.h"
>>  
>>  void user_creatable_complete(Object *obj, Error **errp)
>>  {
>> @@ -212,6 +213,117 @@ void user_creatable_del(const char *id, Error **errp)
>>object_unparent(obj);
>>  }
>>  
>> +int user_creatable_help_func(void *opaque, QemuOpts *opts, Error **errp)
>> +{
>> +Visitor *v;
>> +char *type = NULL;
>> +Error *local_err = NULL;
>> +
>> +int i;
>> +char *values = NULL;
>> +Object *obj;
>> +ObjectPropertyInfoList *props = NULL;
>> +ObjectProperty *prop;
>> +ObjectPropertyIterator iter;
>> +ObjectPropertyInfoList *start;
>> +
>> +struct EnumProperty {
>> +const char * const *strings;
>> +int (*get)(Object *, Error **);
>> +void (*set)(Object *, int, Error **);
>> +} *enumprop;
>
>Ewww, this struct is declared privately in object.c and
>you're declaring it here so you can poke at private
>data belonging to the object internal impl. This is
>not ok in any way.
>
Yes, this way is ugly.
What I want to do is parsing the enum <-> string mappings through the 
EnumProperty
to make the output more reasonable.
It should be parsed in object.c, But I can't assume the size of enum str list, 
then can't
pre-alloc it in user_creatable_help_func. So far I havn't figured out a good 
way to return
a string array that including the enum str list to user_creatable_help_func for 
printing.
May I have your suggestions?

>> +v = opts_visitor_new(opts);
>> +visit_start_struct(v, NULL, NULL, 0, _err);
>> +if (local_err) {
>> +goto out;
>> +}
>> +
>> +visit_type_str(v, "qom-type", , _err);
>> +if (local_err) {
>> +goto out_visit;
>> +}
>> +
>> +if (type && is_help_option(type)) {
>> +printf("Available object backend types:\n");
>> +GSList *list = object_class_get_list(TYPE_USER_CREATABLE, false);
>> +while (list) {
>> +const char *name;
>> +name = object_class_get_name(OBJECT_CLASS(list->data));
>> +if (strcmp(name, TYPE_USER_CREATABLE)) {
>> +printf("%s\n", name);
>> +}
>> +list = list->next;
>> +}
>> +g_slist_free(list);
>> +goto out_visit;
>> +}
>> +
>> +if (!type || !qemu_opt_has_help_opt(opts)) {
>> +visit_end_struct(v, NULL);
>> +return 0;
>> +}
>> +
>> +if (!object_class_by_name(type)) {
>> +printf("invalid object type: %s\n", type);
>> +goto out_visit;
>> +}
>> +obj = object_new(type);
>> +object_property_iter_init(, obj);
>> +
>> +while ((prop = object_property_iter_next())) {
>> +ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
>> +entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
>> +entry->next = props;
>> +props = entry;
>> +entry->value->name = g_strdup(prop->name);
>> +i = 0;
>> +enumprop = prop->opaque;
>> +if (!g_str_equal(prop->type, "string") && \
>> +!g_str_equal(prop->type, "bool") && \
>> +!g_str_equal(prop->type, "struct tm") && \
>> +!g_str_equal(prop->type, "int") && \
>> +!g_str_equal(prop->
type, "uint8") && \
>> +!g_str_equal(prop->type, "uint16") && \
>> +!g_str_equal(prop->type, "uint32") && \
>> +!g_str_equal(prop->type, "uint64")) {
>
>It is absolutely *not* safe to assume that the result of
>this condition is an enum.
>
Yes, It does not make sense and is not safe. Writing this way becasue
I can't figure out a way to judge whether the type is an enum or not.
May I have your ideas?

>> +while (enumprop->strings[i] != NULL) {
>> +if (i != 0) {
>> +values = g_strdup_printf("%s/%s",
>> +
>> values, enumprop->strings[i]);
>
>Leaking the old memory for 'values'.
>
Ok, I'll fix it.
>> +} else {
>> + 

[Qemu-devel] 答复: Re: [PATCH v2] object: Add 'help' option for all available backends and properties

2016-09-17 Thread Lin Ma


>>> Markus Armbruster  2016/9/12 星期一 下午 11:42 >>>
>Lin Ma  writes:
>
>> '-object help' prints available user creatable backends.
>> '-object $typename,help' prints relevant properties.
>>
>> Signed-off-by: Lin Ma 
>> ---
>>  include/qom/object_interfaces.h |   2 +
>>  qemu-options.hx   |   7 ++-
>>  qom/object_interfaces.c   | 112 
>>  vl.c |   5 ++
>>  4 files changed, 125 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/qom/object_interfaces.h 
>> b/include/qom/object_interfaces.h
>> index 8b17f4d..197cd5f 100644
>> --- a/include/qom/object_interfaces.h
>> +++ b/include/qom/object_interfaces.h
>> @@ -165,4 +165,6 @@ int user_creatable_add_opts_foreach(void *opaque,
>>   */
>>  void user_creatable_del(const char *id, Error **errp);
>>  
>> +int user_creatable_help_func(void *opaque, QemuOpts *opts, Error **errp);
>> +
>>  #endif
>> diff --git a/qemu-options.hx b/qemu-options.hx
>> index a71aaf8..fade53c 100644
>> --- a/qemu-options.hx
>> +++ b/qemu-options.hx
>> @@ -3752,7 +3752,9 @@ DEF("object", HAS_ARG, QEMU_OPTION_object,
>>"  create a new object of type TYPENAME setting 
>> properties\n"
>>"  in the order they are specified.  Note that 
>> the 'id'\n"
>>"  property must be set.  These objects are 
>> placed in the\n"
>> -"  '/objects' path.\n",
>> +"  '/objects' path.\n"
>> +"  Use '-object help' to print available 
>> backend types and\n"
>> +"  '-object typename,help' to print relevant 
>> properties.\n",
>>QEMU_ARCH_ALL)
>>  STEXI
>>  @item -object @var{typename}[,@var{prop1}=@var{value1},...]
>> @@ -3762,6 +3764,9 @@ in the order they are specified.  Note that the 'id'
>>  property must be set.  These objects are placed in the
>>  '/objects' path.
>>  
>> +Use '-object help' to print available backend types and
>> +'-object typename,help' to print relevant properties.
>> +
>
>Make that
>
>  +Use @code{-object help} to print available backend types and
>  +@code{-object @var{typename},help} to print relevant properties.
>  +
>
Ok.

>>  @table @option
>>  
>>  @item -object 
>> memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off}
>> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
>> index bf59846..4ee8643 100644
>> --- a/qom/object_interfaces.c
>> +++ b/qom/object_interfaces.c
>> @@ -5,6 +5,7 @@
>>  #include "qapi-visit.h"
>>  #include "qapi/qmp-output-visitor.h"
>>  #include "qapi/opts-visitor.h"
>> +#include "qemu/help_option.h"
>>  
>>  void user_creatable_complete(Object *obj, Error **errp)
>>  {
>> @@ -212,6 +213,117 @@ void user_creatable_del(const char *id, Error **errp)
>>object_unparent(obj);
>>  }
>>  
>> +int user_creatable_help_func(void *opaque, QemuOpts *opts, Error **errp)
>> +{
>> +Visitor *v;
>> +char *type = NULL;
>> +Error *local_err = NULL;
>> +
>
>Why this blank line?
>
I'll remove it.

>> +int i;
>> +char *values = NULL;
>> +Object *obj;
>> +ObjectPropertyInfoList *props = NULL;
>> +ObjectProperty *prop;
>> +ObjectPropertyIterator iter;
>> +ObjectPropertyInfoList *start;
>> +
>> +struct EnumProperty {
>> +const char * const *strings;
>> +int (*get)(Object *, Error **);
>> +void (*set)(Object *, int, Error **);
>> +} *enumprop;
>
>Copied from object.c.  Big no-no.  Whatever you do with this probably
>belongs into object.c instead.
>
Yes, this way is ugly.
What I want to do is parsing the enum <-> string mappings through the 
EnumProperty
to make the output more reasonable.
It should be parsed in object.c, But I can't assume the size of enum str list, 
then can't
pre-alloc it in user_creatable_help_func. So far I havn't figured out a good 
way to return
a string array that including the enum str list to user_creatable_help_func for 
printing.
May I have your suggestions?

>> +
>> +
 v = opts_visitor_new(opts);
>> +visit_start_struct(v, NULL, NULL, 0, _err);
>> +if (local_err) {
>> +goto out;
>> +}
>> +
>> +visit_type_str(v, "qom-type", , _err);
>> +if (local_err) {
>> +goto out_visit;
>> +}
>> +
>> +if (type && is_help_option(type)) {
>
>I think the Options visitor is overkill.  Much simpler:
>
>  type = qemu_opt_get(opts, "qom-type");
>  if (type && is_help_option(type)) {
>
Yes, it is much simpler, I'll use this instead of visitor code.

>> +printf("Available object backend types:\n");
>> +GSList *list = object_class_get_list(TYPE_USER_CREATABLE, false);
>> +while (list) {
>> +const char *name;
>> +name = object_class_get_name(OBJECT_CLASS(list->data));
>> + 

Re: [Qemu-devel] Adding resolutions to the VGA driver

2016-09-17 Thread Michael Tokarev

16.09.2016 11:37, Michael Fritscher wrote:

Am 15.09.2016 um 19:21 schrieb Programmingkid:
Following resolutions are also quite common:

1280x960
1280x1024 (Most LCD-Monitors in the 15-17 zoll range had this for a long
time, also a standard VESA Resolution)
1400x1050
1600x1200 (Many LCD-Monitors in the 20-21 zoll range had this for a long
time, rather "common" resolution)
1920x1080 (the standard full HD resolution)
2560x1440 (the common "next step" after 1920x1080)
3840×2160 (the standard 4k resolution, also known as 2160(p) or UHDTV)
7680x4320 (the standard 8k resolution, also known as 4320p, is also
defined as UHDTV)


Please note that resolutions those pixel counts don't divide to 8
wont work with qemu.  In the past that was lead to crashes, now
just garbled guest display.

Or maybe even 16, memory is failing.

/mjt



Re: [Qemu-devel] [V17 3/4] hw/i386: Introduce AMD IOMMU

2016-09-17 Thread David Kiarie
On Sat, Sep 17, 2016 at 7:59 AM, David Kiarie 
wrote:

>
>
> On 16/09/16 21:58, Michael S. Tsirkin wrote:
>
>> On Wed, Aug 31, 2016 at 07:17:42PM +0300, David Kiarie wrote:
>>
> Hi Michael,
>
> +
>> +/* issue a PCIe completion packet for devid */
>> +typedef struct QEMU_PACKED {
>> +uint32_t reserved_1:16;
>> +uint32_t devid:16;
>> +
>> +#ifdef HOST_WORDS_BIGENDIAN
>> +uint32_t type:4;  /* command type   */
>> +uint32_t reserved_2:8;
>> +uint32_t pasid_19_0:20
>> +#else
>> +uint32_t pasid_19_0:20;
>> +uint32_t reserved_2:8;
>> +uint32_t type:4;
>> +#endif /* __BIG_ENDIAN_BITFIELD */
>> +
>> +#ifdef HOST_WORDS_BIGENDIAN
>> +uint32_t reserved_3:29;
>> +uint32_t guest:1;
>> +uint32_t reserved_4:2;
>> +#else
>> +uint32_t reserved_3:2;
>> +uint32_t guest:1;
>> +uint32_t reserved_4:29;
>> +#endif /* __BIG_ENDIAN_BITFIELD */
>> +
>> +uint32_t completion_tag:16;  /* PCIe PRI information */
>> +uint32_t reserved_5:16;
>> +} CMDCompletePPR;
>> So as Peter points, out, we don't do this kind of
>> thing. Pls drop this ifdefery and rework using
>> masks and cpu_to_le. E.g.
>>
>>  > +#ifdef HOST_WORDS_BIGENDIAN
>>  > +uint32_t reserved_3:29;
>>  > +uint32_t guest:1;
>>  > +uint32_t reserved_4:2;
>>  > +#else
>>  > +uint32_t reserved_3:2;
>>  > +uint32_t guest:1;
>>  > +uint32_t reserved_4:29;
>>  > +#endif /* __BIG_ENDIAN_BITFIELD */
>>
>>  guest = 1;
>>
>> ->
>>
>> #define GUEST cpu_to_le32(0x1 << 2)
>> uint32_t guest;
>>
>> guest = GUEST;
>>
>
> This might not solve the problem we are encountering here. I don't intent
> to write any values to these fields. I only intend to read.
>
> I read into these structs using 'dma_memory_read' which gives me a memory
> order dependent on the host. Byte swapping the read buffer will lead into
> some of the fields being permanently corrupted since they span across byte
> boundaries. I actually didn't have any bitfields(and was not taking care of
> BE) but then there were some complains that the code was barely readable
> hence the bitfields and later the ifdefinery but I've never checked that
> the BE code complies.


'extract64' seems to solve everything though so I can get rid of all the
host dependent defines: didn't know we had this before.


>