Re: [Qemu-devel] [PATCH v2 5/5] block: qemu-iotests: make test 019 and 086 work with spaced pathnames

2014-04-10 Thread Fam Zheng
On Wed, 04/09 22:41, Jeff Cody wrote:
> Both tests 019 and 086 need proper quotations to work with pathnames
> that contain spaces.
> 
> Signed-off-by: Jeff Cody 
> ---
>  tests/qemu-iotests/019 | 2 +-
>  tests/qemu-iotests/086 | 8 
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/qemu-iotests/019 b/tests/qemu-iotests/019
> index e67445c..f5ecbf5 100755
> --- a/tests/qemu-iotests/019
> +++ b/tests/qemu-iotests/019
> @@ -96,7 +96,7 @@ mv "$TEST_IMG" "$TEST_IMG.orig"
>  for backing_option in "-B " "-o backing_file="; do
>  
>  echo
> -echo Testing conversion with $backing_option$TEST_IMG.base | 
> _filter_testdir | _filter_imgfmt
> +echo Testing conversion with $backing_option"$TEST_IMG.base" | 
> _filter_testdir | _filter_imgfmt
>  echo
>  $QEMU_IMG convert -O $IMGFMT $backing_option"$TEST_IMG.base" 
> "$TEST_IMG.orig" "$TEST_IMG"
>  
> diff --git a/tests/qemu-iotests/086 b/tests/qemu-iotests/086
> index 48fe85b..d9a80cf 100755
> --- a/tests/qemu-iotests/086
> +++ b/tests/qemu-iotests/086
> @@ -51,10 +51,10 @@ function run_qemu_img()
>  size=128M
>  
>  _make_test_img $size
> -$QEMU_IO -c 'write 0 1M' $TEST_IMG | _filter_qemu_io
> -$QEMU_IO -c 'write 2M 1M' $TEST_IMG | _filter_qemu_io
> -$QEMU_IO -c 'write 4M 1M' $TEST_IMG | _filter_qemu_io
> -$QEMU_IO -c 'write 32M 1M' $TEST_IMG | _filter_qemu_io
> +$QEMU_IO -c 'write 0 1M' "$TEST_IMG" | _filter_qemu_io
> +$QEMU_IO -c 'write 2M 1M' "$TEST_IMG" | _filter_qemu_io
> +$QEMU_IO -c 'write 4M 1M' "$TEST_IMG" | _filter_qemu_io
> +$QEMU_IO -c 'write 32M 1M' "$TEST_IMG" | _filter_qemu_io
>  
>  $QEMU_IMG convert -p -O $IMGFMT -f $IMGFMT "$TEST_IMG" "$TEST_IMG".base  
> 2>&1 |\
>  _filter_testdir | sed -e 's/\r/\n/g'
> -- 
> 1.8.3.1
> 
> 

Reviewed-by: Fam Zheng 



Re: [Qemu-devel] [PATCH v2 4/5] block: qemu-iotests - fix image cleanup when using spaced pathnames

2014-04-10 Thread Fam Zheng
On Wed, 04/09 22:41, Jeff Cody wrote:
> The _rm_test_img() function in common.rc did not quote the image
> file, which left droppings in the scratch directory (and performed
> a potentially unsafe rm -f).
> 
> This adds the necessary quotes.
> 
> Signed-off-by: Jeff Cody 
> ---
>  tests/qemu-iotests/common.rc | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
> index 7f00883..195c564 100644
> --- a/tests/qemu-iotests/common.rc
> +++ b/tests/qemu-iotests/common.rc
> @@ -178,10 +178,10 @@ _rm_test_img()
>  local img=$1

Since we are quoting $img, should we quote $1 as well?

Fam

>  if [ "$IMGFMT" = "vmdk" ]; then
>  # Remove all the extents for vmdk
> -$QEMU_IMG info $img 2>/dev/null | grep 'filename:' | cut -f 2 -d: \
> +"$QEMU_IMG" info "$img" 2>/dev/null | grep 'filename:' | cut -f 2 
> -d: \
>  | xargs -I {} rm -f "{}"
>  fi
> -rm -f $img
> +rm -f "$img"
>  }
>  
>  _cleanup_test_img()
> -- 
> 1.8.3.1
> 
> 



[Qemu-devel] [PATCH 01/16] cutils: tighten qemu_parse_fd()

2014-04-10 Thread Laszlo Ersek
qemu_parse_fd() used to handle at least the following strings incorrectly:
o "-2": simply let through
o "2147483648": returned as LONG_MAX==INT_MAX on ILP32 (with ERANGE
ignored); implementation-defined behavior on LP64

Signed-off-by: Laszlo Ersek 
---
 util/cutils.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/util/cutils.c b/util/cutils.c
index b337293..dbe7412 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -22,10 +22,12 @@
  * THE SOFTWARE.
  */
 #include "qemu-common.h"
 #include "qemu/host-utils.h"
 #include 
+#include 
+#include 
 
 #include "qemu/sockets.h"
 #include "qemu/iov.h"
 #include "net/net.h"
 
@@ -455,15 +457,20 @@ int parse_uint_full(const char *s, unsigned long long 
*value, int base)
 return 0;
 }
 
 int qemu_parse_fd(const char *param)
 {
-int fd;
-char *endptr = NULL;
+long fd;
+char *endptr;
 
+errno = 0;
 fd = strtol(param, &endptr, 10);
-if (*endptr || (fd == 0 && param == endptr)) {
+if (param == endptr /* no conversion performed */||
+errno != 0  /* not representable as long; possibly others */ ||
+*endptr != '\0' /* final string not empty */ ||
+fd < 0  /* invalid as file descriptor */ ||
+fd > INT_MAX/* not representable as int */) {
 return -1;
 }
 return fd;
 }
 
-- 
1.8.3.1





[Qemu-devel] [PATCH 07/16] pci: add Error-propagating pci_add_capability2()

2014-04-10 Thread Laszlo Ersek
... and rebase pci_add_capability() to it.

Signed-off-by: Laszlo Ersek 
---
 include/hw/pci/pci.h |  4 
 hw/pci/pci.c | 32 ++--
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 693dd6b..8c25ae5 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -4,10 +4,11 @@
 #include "qemu-common.h"
 
 #include "hw/qdev.h"
 #include "exec/memory.h"
 #include "sysemu/dma.h"
+#include "qapi/error.h"
 
 /* PCI includes legacy ISA access.  */
 #include "hw/isa/isa.h"
 
 #include "hw/pci/pcie.h"
@@ -306,10 +307,13 @@ void pci_register_vga(PCIDevice *pci_dev, MemoryRegion 
*mem,
 void pci_unregister_vga(PCIDevice *pci_dev);
 pcibus_t pci_get_bar_addr(PCIDevice *pci_dev, int region_num);
 
 int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
uint8_t offset, uint8_t size);
+int pci_add_capability2(PCIDevice *pdev, uint8_t cap_id,
+   uint8_t offset, uint8_t size,
+   Error **errp);
 
 void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
 
 uint8_t pci_find_capability(PCIDevice *pci_dev, uint8_t cap_id);
 
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 2a9f08e..64e6f23 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2011,32 +2011,52 @@ static void pci_del_option_rom(PCIDevice *pdev)
  * Find and reserve space and add capability to the linked list
  * in pci config space */
 int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
uint8_t offset, uint8_t size)
 {
+int ret;
+Error *local_err = NULL;
+
+ret = pci_add_capability2(pdev, cap_id, offset, size, &local_err);
+if (local_err) {
+assert(ret < 0);
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
+} else {
+/* success implies a positive offset in config space */
+assert(ret > 0);
+}
+return ret;
+}
+
+int pci_add_capability2(PCIDevice *pdev, uint8_t cap_id,
+   uint8_t offset, uint8_t size,
+   Error **errp)
+{
 uint8_t *config;
 int i, overlapping_cap;
 
 if (!offset) {
 offset = pci_find_space(pdev, size);
 if (!offset) {
+error_setg(errp, "out of PCI config space");
 return -ENOSPC;
 }
 } else {
 /* Verify that capabilities don't overlap.  Note: device assignment
  * depends on this check to verify that the device is not broken.
  * Should never trigger for emulated devices, but it's helpful
  * for debugging these. */
 for (i = offset; i < offset + size; i++) {
 overlapping_cap = pci_find_capability_at_offset(pdev, i);
 if (overlapping_cap) {
-fprintf(stderr, "ERROR: %s:%02x:%02x.%x "
-"Attempt to add PCI capability %x at offset "
-"%x overlaps existing capability %x at offset %x\n",
-pci_root_bus_path(pdev), pci_bus_num(pdev->bus),
-PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
-cap_id, offset, overlapping_cap, i);
+error_setg(errp, "%s:%02x:%02x.%x "
+   "Attempt to add PCI capability %x at offset "
+   "%x overlaps existing capability %x at offset %x",
+   pci_root_bus_path(pdev), pci_bus_num(pdev->bus),
+   PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
+   cap_id, offset, overlapping_cap, i);
 return -EINVAL;
 }
 }
 }
 
-- 
1.8.3.1





[Qemu-devel] [PATCH 02/16] monitor: add Error-propagating monitor_handle_fd_param2()

2014-04-10 Thread Laszlo Ersek
and rebase monitor_handle_fd_param() to it. (Note that this will slightly
change the behavior when the qemu_parse_fd() branch is selected and it
fails: we now report (and in case of QMP, set) the error immediately,
rather than allowing the caller to set its own error message (if any)).

Signed-off-by: Laszlo Ersek 
---
 include/monitor/monitor.h |  1 +
 monitor.c | 29 +++--
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index a49ea11..07e3d29 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -73,10 +73,11 @@ int monitor_read_block_device_key(Monitor *mon, const char 
*device,
   BlockDriverCompletionFunc *completion_cb,
   void *opaque);
 
 int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp);
 int monitor_handle_fd_param(Monitor *mon, const char *fdname);
+int monitor_handle_fd_param2(Monitor *mon, const char *fdname, Error **errp);
 
 void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 GCC_FMT_ATTR(2, 0);
 void monitor_printf(Monitor *mon, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 void monitor_print_filename(Monitor *mon, const char *filename);
diff --git a/monitor.c b/monitor.c
index 342e83b..0ef9749 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2634,20 +2634,37 @@ int monitor_fdset_dup_fd_remove(int dup_fd)
 int monitor_handle_fd_param(Monitor *mon, const char *fdname)
 {
 int fd;
 Error *local_err = NULL;
 
+fd = monitor_handle_fd_param2(mon, fdname, &local_err);
+if (local_err) {
+qerror_report_err(local_err);
+error_free(local_err);
+}
+return fd;
+}
+
+int monitor_handle_fd_param2(Monitor *mon, const char *fdname, Error **errp)
+{
+int fd;
+Error *local_err = NULL;
+
 if (!qemu_isdigit(fdname[0]) && mon) {
-
 fd = monitor_get_fd(mon, fdname, &local_err);
-if (fd == -1) {
-qerror_report_err(local_err);
-error_free(local_err);
-return -1;
-}
 } else {
 fd = qemu_parse_fd(fdname);
+if (fd == -1) {
+error_setg(&local_err, "Invalid file descriptor number '%s'",
+   fdname);
+}
+}
+if (local_err) {
+error_propagate(errp, local_err);
+assert(fd == -1);
+} else {
+assert(fd != -1);
 }
 
 return fd;
 }
 
-- 
1.8.3.1





[Qemu-devel] [PATCH 00/16] PCI device assignment: improve error reporting over QMP

2014-04-10 Thread Laszlo Ersek
This is for .

In general, we want to propagate non-fatal (ie. non-exit()ing,
non-abort()ing) errors to the QMP caller, rather than printing them
on-site. The series focuses on errors raised at PCI assignment time (ie.
reachable from assigned_initfn()), other errors are not converted.

Errors are not propagated through assigned_initfn(); let's wait for
someone else to convert "kvm-pci-assign" from qdev to QOM. The series is
nonetheless an improvement, because the forwarding of initialization
errors now stops just before device_realize(). We set the
stored/persistent monitor error there.

Informative and warning messages (that report about circumstances that
don't break the assignment operation) cannot terminate in
qerror_report_err(), because that would set the persistent monitor
error, breaking the high level (QMP) operation.

A call graph rooted in assigned_initfn() was generated with cflow.
Leaves that could never fail were removed from the graph (and this
property similarly propagated upwards as far as possible).

The patchset loosely follows a bottom-up algorithm on this calltree. Any
leaf that reports an error internally and returns a related failure is
converted to "throw" an Error structure instead. All direct callers of
the converted leaf are addressed at once, in the same patch, to consume
the error (and they become the new leaves gradually).

When the leaf to be converted is also called outside of
"hw/i386/kvm/pci-assign.c", the conversion keeps a compatibility
function under the original name, so that conversion of callers
unrelated to PCI assignment can be deferred.

Reviewers should copy the call graph to a text file, and mark, as the
series progresses, fully converted functions. (Ie. functions that now
report their terminating error messages with Error objects only.)

  assigned_initfn()
  error_report()
  get_real_device()
  monitor_handle_fd_param()
  error_report()
  get_real_vendor_id()
  get_real_id()
  error_report()
  get_real_device_id()
  get_real_id()
  error_report()
  assigned_device_pci_cap_init()
  check_irqchip_in_kernel()
  error_report()
  pci_add_capability()
  error_report()
  assigned_dev_register_msix_mmio()
  error_report()
  assigned_dev_register_regions()
  error_report()
  assign_device()
  error_report()
  assign_failed_examine()
  get_real_vendor_id()
  get_real_id()
  error_report()
  get_real_device_id()
  get_real_id()
  error_report()
  error_printf()
  error_report()
  assign_intx()
  check_irqchip_in_kernel()
  error_report()
  error_report()
  error_printf()

Laszlo Ersek (16):
  cutils: tighten qemu_parse_fd()
  monitor: add Error-propagating monitor_handle_fd_param2()
  pci-assign: accept Error from monitor_handle_fd_param2()
  pci-assign: make assign_failed_examine() just format the cause
  pci-assign: propagate errors from get_real_id()
  pci-assign: propagate Error from check_irqchip_in_kernel()
  pci: add Error-propagating pci_add_capability2()
  pci-assign: accept Error from pci_add_capability2()
  pci-assign: assignment should fail if we can't read config space
  pci-assign: propagate errors from get_real_device()
  pci-assign: propagate errors from assigned_device_pci_cap_init()
  pci-assign: propagate errors from assigned_dev_register_msix_mmio()
  pci-assign: propagate errors from assigned_dev_register_regions()
  pci-assign: propagate errors from assign_device()
  pci-assign: propagate errors from assign_intx()
  pci-assign: assigned_initfn(): set monitor error in common error
handler

 include/hw/pci/pci.h  |   4 +
 include/monitor/monitor.h |   1 +
 hw/i386/kvm/pci-assign.c  | 273 --
 hw/pci/pci.c  |  32 +-
 monitor.c |  29 -
 util/cutils.c |  13 ++-
 6 files changed, 232 insertions(+), 120 deletions(-)

-- 
1.8.3.1




[Qemu-devel] [PATCH 08/16] pci-assign: accept Error from pci_add_capability2()

2014-04-10 Thread Laszlo Ersek
Propagate any errors while adding PCI capabilities to
assigned_device_pci_cap_init(). We'll continue the propagation upwards
when assigned_device_pci_cap_init() becomes a leaf itself (when none of
its callees will report errors internally any longer when detecting and
returning them).

Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 35 ---
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index b4696aa..f91d4fb 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -1261,12 +1261,15 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
 error_free(local_err);
 return -ENOTSUP;
 }
 dev->cap.available |= ASSIGNED_DEVICE_CAP_MSI;
 /* Only 32-bit/no-mask currently supported */
-ret = pci_add_capability(pci_dev, PCI_CAP_ID_MSI, pos, 10);
+ret = pci_add_capability2(pci_dev, PCI_CAP_ID_MSI, pos, 10,
+  &local_err);
 if (ret < 0) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
 return ret;
 }
 pci_dev->msi_cap = pos;
 
 pci_set_word(pci_dev->config + pos + PCI_MSI_FLAGS,
@@ -1292,12 +1295,15 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
 error_report("%s", error_get_pretty(local_err));
 error_free(local_err);
 return -ENOTSUP;
 }
 dev->cap.available |= ASSIGNED_DEVICE_CAP_MSIX;
-ret = pci_add_capability(pci_dev, PCI_CAP_ID_MSIX, pos, 12);
+ret = pci_add_capability2(pci_dev, PCI_CAP_ID_MSIX, pos, 12,
+  &local_err);
 if (ret < 0) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
 return ret;
 }
 pci_dev->msix_cap = pos;
 
 pci_set_word(pci_dev->config + pos + PCI_MSIX_FLAGS,
@@ -1320,12 +1326,15 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
 /* Minimal PM support, nothing writable, device appears to NAK changes */
 pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_PM, 0);
 if (pos) {
 uint16_t pmc;
 
-ret = pci_add_capability(pci_dev, PCI_CAP_ID_PM, pos, PCI_PM_SIZEOF);
+ret = pci_add_capability2(pci_dev, PCI_CAP_ID_PM, pos, PCI_PM_SIZEOF,
+  &local_err);
 if (ret < 0) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
 return ret;
 }
 
 assigned_dev_setup_cap_read(dev, pos, PCI_PM_SIZEOF);
 
@@ -1386,12 +1395,15 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
 error_report("%s: Unsupported PCI express capability version %d",
  __func__, version);
 return -EINVAL;
 }
 
-ret = pci_add_capability(pci_dev, PCI_CAP_ID_EXP, pos, size);
+ret = pci_add_capability2(pci_dev, PCI_CAP_ID_EXP, pos, size,
+  &local_err);
 if (ret < 0) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
 return ret;
 }
 
 assigned_dev_setup_cap_read(dev, pos, size);
 
@@ -1460,12 +1472,15 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
 if (pos) {
 uint16_t cmd;
 uint32_t status;
 
 /* Only expose the minimum, 8 byte capability */
-ret = pci_add_capability(pci_dev, PCI_CAP_ID_PCIX, pos, 8);
+ret = pci_add_capability2(pci_dev, PCI_CAP_ID_PCIX, pos, 8,
+  &local_err);
 if (ret < 0) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
 return ret;
 }
 
 assigned_dev_setup_cap_read(dev, pos, 8);
 
@@ -1486,12 +1501,15 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
 }
 
 pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_VPD, 0);
 if (pos) {
 /* Direct R/W passthrough */
-ret = pci_add_capability(pci_dev, PCI_CAP_ID_VPD, pos, 8);
+ret = pci_add_capability2(pci_dev, PCI_CAP_ID_VPD, pos, 8,
+  &local_err);
 if (ret < 0) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
 return ret;
 }
 
 assigned_dev_setup_cap_read(dev, pos, 8);
 
@@ -1502,12 +1520,15 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
 /* Devices can have multiple vendor capabilities, get them all */
 for (pos = 0; (pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_VNDR, pos));
 pos += PCI_CAP_LIST_NEXT) {
 uint8_t len = pci_get_byte(pci_dev->config + pos + PCI_CAP_FLAGS);
 /* Direct R/W passthrough */
-ret 

[Qemu-devel] [PATCH 11/16] pci-assign: propagate errors from assigned_device_pci_cap_init()

2014-04-10 Thread Laszlo Ersek
Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 45 +++--
 1 file changed, 19 insertions(+), 26 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index c6d1094..2de6559 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -1235,11 +1235,11 @@ static void assigned_dev_setup_cap_read(AssignedDevice 
*dev, uint32_t offset,
 {
 assigned_dev_direct_config_read(dev, offset, len);
 assigned_dev_emulate_config_read(dev, offset + PCI_CAP_LIST_NEXT, 1);
 }
 
-static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
+static int assigned_device_pci_cap_init(PCIDevice *pci_dev, Error **errp)
 {
 AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
 PCIRegion *pci_region = dev->real_device.regions;
 int ret, pos;
 Error *local_err = NULL;
@@ -1254,21 +1254,19 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
  * MSI capability is the 1st capability in capability config */
 pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSI, 0);
 if (pos != 0 && kvm_check_extension(kvm_state, KVM_CAP_ASSIGN_DEV_IRQ)) {
 verify_irqchip_in_kernel(&local_err);
 if (local_err) {
-error_report("%s", error_get_pretty(local_err));
-error_free(local_err);
+error_propagate(errp, local_err);
 return -ENOTSUP;
 }
 dev->cap.available |= ASSIGNED_DEVICE_CAP_MSI;
 /* Only 32-bit/no-mask currently supported */
 ret = pci_add_capability2(pci_dev, PCI_CAP_ID_MSI, pos, 10,
   &local_err);
 if (ret < 0) {
-error_report("%s", error_get_pretty(local_err));
-error_free(local_err);
+error_propagate(errp, local_err);
 return ret;
 }
 pci_dev->msi_cap = pos;
 
 pci_set_word(pci_dev->config + pos + PCI_MSI_FLAGS,
@@ -1289,20 +1287,18 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
 int bar_nr;
 uint32_t msix_table_entry;
 
 verify_irqchip_in_kernel(&local_err);
 if (local_err) {
-error_report("%s", error_get_pretty(local_err));
-error_free(local_err);
+error_propagate(errp, local_err);
 return -ENOTSUP;
 }
 dev->cap.available |= ASSIGNED_DEVICE_CAP_MSIX;
 ret = pci_add_capability2(pci_dev, PCI_CAP_ID_MSIX, pos, 12,
   &local_err);
 if (ret < 0) {
-error_report("%s", error_get_pretty(local_err));
-error_free(local_err);
+error_propagate(errp, local_err);
 return ret;
 }
 pci_dev->msix_cap = pos;
 
 pci_set_word(pci_dev->config + pos + PCI_MSIX_FLAGS,
@@ -1328,12 +1324,11 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
 uint16_t pmc;
 
 ret = pci_add_capability2(pci_dev, PCI_CAP_ID_PM, pos, PCI_PM_SIZEOF,
   &local_err);
 if (ret < 0) {
-error_report("%s", error_get_pretty(local_err));
-error_free(local_err);
+error_propagate(errp, local_err);
 return ret;
 }
 
 assigned_dev_setup_cap_read(dev, pos, PCI_PM_SIZEOF);
 
@@ -1367,12 +1362,12 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
  * PCIe v3.0 spec that regs should exist and be read as 0,
  * not optionally provided and shorten the struct size.
  */
 size = MIN(0x3c, PCI_CONFIG_SPACE_SIZE - pos);
 if (size < 0x34) {
-error_report("%s: Invalid size PCIe cap-id 0x%x",
- __func__, PCI_CAP_ID_EXP);
+error_setg(errp, "Invalid size PCIe cap-id 0x%x",
+   PCI_CAP_ID_EXP);
 return -EINVAL;
 } else if (size != 0x3c) {
 error_report("WARNING, %s: PCIe cap-id 0x%x has "
  "non-standard size 0x%x; std size should be 0x3c",
  __func__, PCI_CAP_ID_EXP, size);
@@ -1389,31 +1384,30 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
 size = 0x3c;
 }
 }
 
 if (size == 0) {
-error_report("%s: Unsupported PCI express capability version %d",
- __func__, version);
+error_setg(errp, "Unsupported PCI express capability version %d",
+   version);
 return -EINVAL;
 }
 
 ret = pci_add_capability2(pci_dev, PCI_CAP_ID_EXP, pos, size,
   &local_err);
 if (ret < 0) {
-error_report("%s", error_get_pretty(local_err));
-error_free(local_err);
+error_propagate(errp, local_err);
 return ret;
 }
 
 assigned_dev_setu

[Qemu-devel] [PATCH 03/16] pci-assign: accept Error from monitor_handle_fd_param2()

2014-04-10 Thread Laszlo Ersek
Propagate any errors in monitor fd handling up to get_real_device(), and
report them there. We'll continue the propagation upwards when
get_real_device() becomes a leaf itself (when none of its callees will
report errors internally any longer when detecting and returning an
error).

Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index a825871..bfce97f 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -539,22 +539,27 @@ static int get_real_device(AssignedDevice *pci_dev)
 FILE *f;
 uint64_t start, end, size, flags;
 uint16_t id;
 PCIRegion *rp;
 PCIDevRegions *dev = &pci_dev->real_device;
+Error *local_err = NULL;
 
 dev->region_number = 0;
 
 snprintf(dir, sizeof(dir), "/sys/bus/pci/devices/%04x:%02x:%02x.%x/",
  pci_dev->host.domain, pci_dev->host.bus,
  pci_dev->host.slot, pci_dev->host.function);
 
 snprintf(name, sizeof(name), "%sconfig", dir);
 
 if (pci_dev->configfd_name && *pci_dev->configfd_name) {
-dev->config_fd = monitor_handle_fd_param(cur_mon, 
pci_dev->configfd_name);
-if (dev->config_fd < 0) {
+dev->config_fd = monitor_handle_fd_param2(cur_mon,
+  pci_dev->configfd_name,
+  &local_err);
+if (local_err) {
+qerror_report_err(local_err);
+error_free(local_err);
 return 1;
 }
 } else {
 dev->config_fd = open(name, O_RDWR);
 
-- 
1.8.3.1





[Qemu-devel] [PATCH 06/16] pci-assign: propagate Error from check_irqchip_in_kernel()

2014-04-10 Thread Laszlo Ersek
Rename check_irqchip_in_kernel() to verify_irqchip_in_kernel(), so that
the name reflects our expectation better. Rather than returning a bool,
make it do nothing or set an Error.

Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 997ef09..b4696aa 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -839,34 +839,36 @@ static int assign_device(AssignedDevice *dev)
 }
 }
 return r;
 }
 
-static bool check_irqchip_in_kernel(void)
+static void verify_irqchip_in_kernel(Error **errp)
 {
 if (kvm_irqchip_in_kernel()) {
-return true;
+return;
 }
-error_report("pci-assign: error: requires KVM with in-kernel irqchip "
- "enabled");
-return false;
+error_setg(errp, "pci-assign requires KVM with in-kernel irqchip enabled");
 }
 
 static int assign_intx(AssignedDevice *dev)
 {
 AssignedIRQType new_type;
 PCIINTxRoute intx_route;
 bool intx_host_msi;
 int r;
+Error *local_err = NULL;
 
 /* Interrupt PIN 0 means don't use INTx */
 if (assigned_dev_pci_read_byte(&dev->dev, PCI_INTERRUPT_PIN) == 0) {
 pci_device_set_intx_routing_notifier(&dev->dev, NULL);
 return 0;
 }
 
-if (!check_irqchip_in_kernel()) {
+verify_irqchip_in_kernel(&local_err);
+if (local_err) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
 return -ENOTSUP;
 }
 
 pci_device_set_intx_routing_notifier(&dev->dev,
  assigned_dev_update_irq_routing);
@@ -1239,10 +1241,11 @@ static void assigned_dev_setup_cap_read(AssignedDevice 
*dev, uint32_t offset,
 static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
 {
 AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
 PCIRegion *pci_region = dev->real_device.regions;
 int ret, pos;
+Error *local_err = NULL;
 
 /* Clear initial capabilities pointer and status copied from hw */
 pci_set_byte(pci_dev->config + PCI_CAPABILITY_LIST, 0);
 pci_set_word(pci_dev->config + PCI_STATUS,
  pci_get_word(pci_dev->config + PCI_STATUS) &
@@ -1250,11 +1253,14 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
 
 /* Expose MSI capability
  * MSI capability is the 1st capability in capability config */
 pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSI, 0);
 if (pos != 0 && kvm_check_extension(kvm_state, KVM_CAP_ASSIGN_DEV_IRQ)) {
-if (!check_irqchip_in_kernel()) {
+verify_irqchip_in_kernel(&local_err);
+if (local_err) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
 return -ENOTSUP;
 }
 dev->cap.available |= ASSIGNED_DEVICE_CAP_MSI;
 /* Only 32-bit/no-mask currently supported */
 ret = pci_add_capability(pci_dev, PCI_CAP_ID_MSI, pos, 10);
@@ -1279,11 +1285,14 @@ static int assigned_device_pci_cap_init(PCIDevice 
*pci_dev)
 pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSIX, 0);
 if (pos != 0 && kvm_device_msix_supported(kvm_state)) {
 int bar_nr;
 uint32_t msix_table_entry;
 
-if (!check_irqchip_in_kernel()) {
+verify_irqchip_in_kernel(&local_err);
+if (local_err) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
 return -ENOTSUP;
 }
 dev->cap.available |= ASSIGNED_DEVICE_CAP_MSIX;
 ret = pci_add_capability(pci_dev, PCI_CAP_ID_MSIX, pos, 12);
 if (ret < 0) {
-- 
1.8.3.1





[Qemu-devel] [PATCH 04/16] pci-assign: make assign_failed_examine() just format the cause

2014-04-10 Thread Laszlo Ersek
This allows us to report the entire error with one error_report() call,
easing future error propagation.

Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 30 +++---
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index bfce97f..6b8db25 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -729,11 +729,16 @@ static void free_assigned_device(AssignedDevice *dev)
 }
 
 free_msi_virqs(dev);
 }
 
-static void assign_failed_examine(AssignedDevice *dev)
+/* This function tries to determine the cause of the PCI assignment failure. It
+ * always returns the cause as a dynamically allocated, human readable string.
+ * If the function fails to determine the cause for any internal reason, then
+ * the returned string will state that fact.
+ */
+static char *assign_failed_examine(const AssignedDevice *dev)
 {
 char name[PATH_MAX], dir[PATH_MAX], driver[PATH_MAX] = {}, *ns;
 uint16_t vendor_id, device_id;
 int r;
 
@@ -759,12 +764,12 @@ static void assign_failed_examine(AssignedDevice *dev)
 if (get_real_vendor_id(dir, &vendor_id) ||
 get_real_device_id(dir, &device_id)) {
 goto fail;
 }
 
-error_printf("*** The driver '%s' is occupying your device "
-"%04x:%02x:%02x.%x.\n"
+return g_strdup_printf(
+"*** The driver '%s' is occupying your device %04x:%02x:%02x.%x.\n"
 "***\n"
 "*** You can try the following commands to free it:\n"
 "***\n"
 "*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub/new_id\n"
 "*** $ echo \"%04x:%02x:%02x.%x\" > /sys/bus/pci/drivers/%s/unbind\n"
@@ -776,14 +781,12 @@ static void assign_failed_examine(AssignedDevice *dev)
 dev->host.function, vendor_id, device_id,
 dev->host.domain, dev->host.bus, dev->host.slot, dev->host.function,
 ns, dev->host.domain, dev->host.bus, dev->host.slot,
 dev->host.function, vendor_id, device_id);
 
-return;
-
 fail:
-error_report("Couldn't find out why.");
+return g_strdup("Couldn't find out why.");
 }
 
 static int assign_device(AssignedDevice *dev)
 {
 uint32_t flags = KVM_DEV_ASSIGN_ENABLE_IOMMU;
@@ -808,18 +811,23 @@ static int assign_device(AssignedDevice *dev)
 flags |= KVM_DEV_ASSIGN_PCI_2_3;
 }
 
 r = kvm_device_pci_assign(kvm_state, &dev->host, flags, &dev->dev_id);
 if (r < 0) {
-error_report("Failed to assign device \"%s\" : %s",
- dev->dev.qdev.id, strerror(-r));
-
 switch (r) {
-case -EBUSY:
-assign_failed_examine(dev);
+case -EBUSY: {
+char *cause;
+
+cause = assign_failed_examine(dev);
+error_report("Failed to assign device \"%s\" : %s\n%s",
+ dev->dev.qdev.id, strerror(-r), cause);
+g_free(cause);
 break;
+}
 default:
+error_report("Failed to assign device \"%s\" : %s",
+ dev->dev.qdev.id, strerror(-r));
 break;
 }
 }
 return r;
 }
-- 
1.8.3.1





[Qemu-devel] [PATCH 15/16] pci-assign: propagate errors from assign_intx()

2014-04-10 Thread Laszlo Ersek
Among the callers, only assigned_initfn() should set the  monitor's stored
error. Other callers may run in contexts where the monitor's stored error
makes no sense. For example:

assigned_dev_pci_write_config()
  assigned_dev_update_msix()
assign_intx()

Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 39 ---
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 0fedca8..6891729 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -845,11 +845,11 @@ static void verify_irqchip_in_kernel(Error **errp)
 return;
 }
 error_setg(errp, "pci-assign requires KVM with in-kernel irqchip enabled");
 }
 
-static int assign_intx(AssignedDevice *dev)
+static int assign_intx(AssignedDevice *dev, Error **errp)
 {
 AssignedIRQType new_type;
 PCIINTxRoute intx_route;
 bool intx_host_msi;
 int r;
@@ -861,12 +861,11 @@ static int assign_intx(AssignedDevice *dev)
 return 0;
 }
 
 verify_irqchip_in_kernel(&local_err);
 if (local_err) {
-error_report("%s", error_get_pretty(local_err));
-error_free(local_err);
+error_propagate(errp, local_err);
 return -ENOTSUP;
 }
 
 pci_device_set_intx_routing_notifier(&dev->dev,
  assigned_dev_update_irq_routing);
@@ -925,14 +924,15 @@ retry:
  "using MSI instead");
 error_printf("Some devices do not work properly in this mode.\n");
 dev->features |= ASSIGNED_DEVICE_PREFER_MSI_MASK;
 goto retry;
 }
-error_report("Failed to assign irq for \"%s\": %s",
- dev->dev.qdev.id, strerror(-r));
-error_report("Perhaps you are assigning a device "
- "that shares an IRQ with another device?");
+error_setg_errno(errp, -r,
+ "Failed to assign irq for \"%s\"\n"
+ "Perhaps you are assigning a device "
+ "that shares an IRQ with another device?",
+ dev->dev.qdev.id);
 return r;
 }
 
 dev->intx_route = intx_route;
 dev->assigned_irq_type = new_type;
@@ -954,12 +954,15 @@ static void assigned_dev_update_irq_routing(PCIDevice 
*dev)
 {
 AssignedDevice *assigned_dev = DO_UPCAST(AssignedDevice, dev, dev);
 Error *err = NULL;
 int r;
 
-r = assign_intx(assigned_dev);
+r = assign_intx(assigned_dev, &err);
 if (r < 0) {
+error_report("%s", error_get_pretty(err));
+error_free(err);
+err = NULL;
 qdev_unplug(&dev->qdev, &err);
 assert(!err);
 }
 }
 
@@ -1006,11 +1009,17 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
 
 assigned_dev->intx_route.mode = PCI_INTX_DISABLED;
 assigned_dev->intx_route.irq = -1;
 assigned_dev->assigned_irq_type = ASSIGNED_IRQ_MSI;
 } else {
-assign_intx(assigned_dev);
+Error *local_err = NULL;
+
+assign_intx(assigned_dev, &local_err);
+if (local_err) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
+}
 }
 }
 
 static void assigned_dev_update_msi_msg(PCIDevice *pci_dev)
 {
@@ -1148,11 +1157,17 @@ static void assigned_dev_update_msix(PCIDevice *pci_dev)
 }
 assigned_dev->intx_route.mode = PCI_INTX_DISABLED;
 assigned_dev->intx_route.irq = -1;
 assigned_dev->assigned_irq_type = ASSIGNED_IRQ_MSIX;
 } else {
-assign_intx(assigned_dev);
+Error *local_err = NULL;
+
+assign_intx(assigned_dev, &local_err);
+if (local_err) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
+}
 }
 }
 
 static uint32_t assigned_dev_pci_read_config(PCIDevice *pci_dev,
  uint32_t address, int len)
@@ -1817,12 +1832,14 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 error_free(local_err);
 goto out;
 }
 
 /* assign legacy INTx to the device */
-r = assign_intx(dev);
+r = assign_intx(dev, &local_err);
 if (r < 0) {
+qerror_report_err(local_err);
+error_free(local_err);
 goto assigned_out;
 }
 
 assigned_dev_load_option_rom(dev);
 
-- 
1.8.3.1





[Qemu-devel] [PATCH 12/16] pci-assign: propagate errors from assigned_dev_register_msix_mmio()

2014-04-10 Thread Laszlo Ersek
The return type is also changed from "int" to "void", because it was used
in a success vs. failure sense only (the caller didn't distinguish error
codes from each other, and even assigned_dev_register_msix_mmio() masked
mmap()'s errno values with a common -EFAULT).

Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 2de6559..3a904e8 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -1642,24 +1642,23 @@ static void assigned_dev_msix_reset(AssignedDevice *dev)
 for (i = 0, entry = dev->msix_table; i < dev->msix_max; i++, entry++) {
 entry->ctrl = cpu_to_le32(0x1); /* Masked */
 }
 }
 
-static int assigned_dev_register_msix_mmio(AssignedDevice *dev)
+static void assigned_dev_register_msix_mmio(AssignedDevice *dev, Error **errp)
 {
 dev->msix_table = mmap(NULL, MSIX_PAGE_SIZE, PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
 if (dev->msix_table == MAP_FAILED) {
-error_report("fail allocate msix_table! %s", strerror(errno));
-return -EFAULT;
+error_setg_errno(errp, errno, "failed to allocate msix_table");
+return;
 }
 
 assigned_dev_msix_reset(dev);
 
 memory_region_init_io(&dev->mmio, OBJECT(dev), &assigned_dev_msix_mmio_ops,
   dev, "assigned-dev-msix", MSIX_PAGE_SIZE);
-return 0;
 }
 
 static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev)
 {
 if (!dev->msix_table) {
@@ -1786,11 +1785,14 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 goto out;
 }
 
 /* intercept MSI-X entry page in the MMIO */
 if (dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) {
-if (assigned_dev_register_msix_mmio(dev)) {
+assigned_dev_register_msix_mmio(dev, &local_err);
+if (local_err) {
+qerror_report_err(local_err);
+error_free(local_err);
 goto out;
 }
 }
 
 /* handle real device's MMIO/PIO BARs */
-- 
1.8.3.1





[Qemu-devel] [PATCH 09/16] pci-assign: assignment should fail if we can't read config space

2014-04-10 Thread Laszlo Ersek
assigned_initfn()
  get_real_device()
read()

Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index f91d4fb..e89bb6a 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -574,10 +574,11 @@ again:
 if (r < 0) {
 if (errno == EINTR || errno == EAGAIN) {
 goto again;
 }
 error_report("%s: read failed, errno = %d", __func__, errno);
+return 1;
 }
 
 /* Restore or clear multifunction, this is always controlled by qemu */
 if (pci_dev->dev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
 pci_dev->dev.config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION;
-- 
1.8.3.1





[Qemu-devel] [PATCH 10/16] pci-assign: propagate errors from get_real_device()

2014-04-10 Thread Laszlo Ersek
Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index e89bb6a..c6d1094 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -530,11 +530,11 @@ static void get_real_device_id(const char *devpath, 
uint16_t *val,
Error **errp)
 {
 get_real_id(devpath, "device", val, errp);
 }
 
-static int get_real_device(AssignedDevice *pci_dev)
+static void get_real_device(AssignedDevice *pci_dev, Error **errp)
 {
 char dir[128], name[128];
 int fd, r = 0;
 FILE *f;
 uint64_t start, end, size, flags;
@@ -554,31 +554,32 @@ static int get_real_device(AssignedDevice *pci_dev)
 if (pci_dev->configfd_name && *pci_dev->configfd_name) {
 dev->config_fd = monitor_handle_fd_param2(cur_mon,
   pci_dev->configfd_name,
   &local_err);
 if (local_err) {
-qerror_report_err(local_err);
-error_free(local_err);
-return 1;
+error_propagate(errp, local_err);
+return;
 }
 } else {
 dev->config_fd = open(name, O_RDWR);
 
 if (dev->config_fd == -1) {
-error_report("%s: %s: %m", __func__, name);
-return 1;
+error_setg_file_open(errp, errno, name);
+return;
 }
 }
 again:
 r = read(dev->config_fd, pci_dev->dev.config,
  pci_config_size(&pci_dev->dev));
 if (r < 0) {
 if (errno == EINTR || errno == EAGAIN) {
 goto again;
 }
-error_report("%s: read failed, errno = %d", __func__, errno);
-return 1;
+error_setg_errno(errp, errno, "read(\"%s\")",
+ (pci_dev->configfd_name && *pci_dev->configfd_name) ?
+ pci_dev->configfd_name : name);
+return;
 }
 
 /* Restore or clear multifunction, this is always controlled by qemu */
 if (pci_dev->dev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
 pci_dev->dev.config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION;
@@ -594,12 +595,12 @@ again:
 
 snprintf(name, sizeof(name), "%sresource", dir);
 
 f = fopen(name, "r");
 if (f == NULL) {
-error_report("%s: %s: %m", __func__, name);
-return 1;
+error_setg_file_open(errp, errno, name);
+return;
 }
 
 for (r = 0; r < PCI_ROM_SLOT; r++) {
 if (fscanf(f, "%" SCNi64 " %" SCNi64 " %" SCNi64 "\n",
&start, &end, &flags) != 3) {
@@ -640,32 +641,29 @@ again:
 fclose(f);
 
 /* read and fill vendor ID */
 get_real_vendor_id(dir, &id, &local_err);
 if (local_err) {
-error_report("%s", error_get_pretty(local_err));
-error_free(local_err);
-return 1;
+error_propagate(errp, local_err);
+return;
 }
 pci_dev->dev.config[0] = id & 0xff;
 pci_dev->dev.config[1] = (id & 0xff00) >> 8;
 
 /* read and fill device ID */
 get_real_device_id(dir, &id, &local_err);
 if (local_err) {
-error_report("%s", error_get_pretty(local_err));
-error_free(local_err);
-return 1;
+error_propagate(errp, local_err);
+return;
 }
 pci_dev->dev.config[2] = id & 0xff;
 pci_dev->dev.config[3] = (id & 0xff00) >> 8;
 
 pci_word_test_and_clear_mask(pci_dev->emulate_config_write + PCI_COMMAND,
  PCI_COMMAND_MASTER | 
PCI_COMMAND_INTX_DISABLE);
 
 dev->region_number = r;
-return 0;
 }
 
 static void free_msi_virqs(AssignedDevice *dev)
 {
 int i;
@@ -1749,10 +1747,11 @@ static void reset_assigned_device(DeviceState *dev)
 static int assigned_initfn(struct PCIDevice *pci_dev)
 {
 AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
 uint8_t e_intx;
 int r;
+Error *local_err = NULL;
 
 if (!kvm_enabled()) {
 error_report("pci-assign: error: requires KVM support");
 return -1;
 }
@@ -1781,13 +1780,14 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 assigned_dev_direct_config_read(dev, PCI_MIN_GNT, 1);
 assigned_dev_direct_config_read(dev, PCI_MAX_LAT, 1);
 memcpy(dev->emulate_config_write, dev->emulate_config_read,
sizeof(dev->emulate_config_read));
 
-if (get_real_device(dev)) {
-error_report("pci-assign: Error: Couldn't get real device (%s)!",
- dev->dev.qdev.id);
+get_real_device(dev, &local_err);
+if (local_err) {
+qerror_report_err(local_err);
+error_free(local_err);
 goto out;
 }
 
 if (assigned_device_pci_cap_init(pci_dev) < 0) {
 goto out;
-- 
1.8.3.1





[Qemu-devel] [PATCH 05/16] pci-assign: propagate errors from get_real_id()

2014-04-10 Thread Laszlo Ersek
get_real_id() has two thin wrappers (and no other callers),
get_real_vendor_id() and get_real_device_id(); it's easiest to convert
them in one fell swoop.

Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 45 +++--
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 6b8db25..997ef09 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -497,47 +497,47 @@ static int assigned_dev_register_regions(PCIRegion 
*io_regions,
 
 /* success */
 return 0;
 }
 
-static int get_real_id(const char *devpath, const char *idname, uint16_t *val)
+static void get_real_id(const char *devpath, const char *idname, uint16_t *val,
+Error **errp)
 {
 FILE *f;
 char name[128];
 long id;
 
 snprintf(name, sizeof(name), "%s%s", devpath, idname);
 f = fopen(name, "r");
 if (f == NULL) {
-error_report("%s: %s: %m", __func__, name);
-return -1;
+error_setg_file_open(errp, errno, name);
+return;
 }
 if (fscanf(f, "%li\n", &id) == 1) {
 *val = id;
 } else {
-fclose(f);
-return -1;
+error_setg(errp, "Failed to parse contents of '%s'", name);
 }
 fclose(f);
-
-return 0;
 }
 
-static int get_real_vendor_id(const char *devpath, uint16_t *val)
+static void get_real_vendor_id(const char *devpath, uint16_t *val,
+   Error **errp)
 {
-return get_real_id(devpath, "vendor", val);
+get_real_id(devpath, "vendor", val, errp);
 }
 
-static int get_real_device_id(const char *devpath, uint16_t *val)
+static void get_real_device_id(const char *devpath, uint16_t *val,
+   Error **errp)
 {
-return get_real_id(devpath, "device", val);
+get_real_id(devpath, "device", val, errp);
 }
 
 static int get_real_device(AssignedDevice *pci_dev)
 {
 char dir[128], name[128];
-int fd, r = 0, v;
+int fd, r = 0;
 FILE *f;
 uint64_t start, end, size, flags;
 uint16_t id;
 PCIRegion *rp;
 PCIDevRegions *dev = &pci_dev->real_device;
@@ -637,20 +637,24 @@ again:
 }
 
 fclose(f);
 
 /* read and fill vendor ID */
-v = get_real_vendor_id(dir, &id);
-if (v) {
+get_real_vendor_id(dir, &id, &local_err);
+if (local_err) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
 return 1;
 }
 pci_dev->dev.config[0] = id & 0xff;
 pci_dev->dev.config[1] = (id & 0xff00) >> 8;
 
 /* read and fill device ID */
-v = get_real_device_id(dir, &id);
-if (v) {
+get_real_device_id(dir, &id, &local_err);
+if (local_err) {
+error_report("%s", error_get_pretty(local_err));
+error_free(local_err);
 return 1;
 }
 pci_dev->dev.config[2] = id & 0xff;
 pci_dev->dev.config[3] = (id & 0xff00) >> 8;
 
@@ -739,10 +743,11 @@ static void free_assigned_device(AssignedDevice *dev)
 static char *assign_failed_examine(const AssignedDevice *dev)
 {
 char name[PATH_MAX], dir[PATH_MAX], driver[PATH_MAX] = {}, *ns;
 uint16_t vendor_id, device_id;
 int r;
+Error *local_err = NULL;
 
 snprintf(dir, sizeof(dir), "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/",
 dev->host.domain, dev->host.bus, dev->host.slot,
 dev->host.function);
 
@@ -759,12 +764,16 @@ static char *assign_failed_examine(const AssignedDevice 
*dev)
 goto fail;
 }
 
 ns++;
 
-if (get_real_vendor_id(dir, &vendor_id) ||
-get_real_device_id(dir, &device_id)) {
+if ((get_real_vendor_id(dir, &vendor_id, &local_err), local_err) ||
+(get_real_device_id(dir, &device_id, &local_err), local_err)) {
+/* We're already analyzing an assignment error, so we suppress this
+ * one just like the others above.
+ */
+error_free(local_err);
 goto fail;
 }
 
 return g_strdup_printf(
 "*** The driver '%s' is occupying your device %04x:%02x:%02x.%x.\n"
-- 
1.8.3.1





[Qemu-devel] [PATCH 13/16] pci-assign: propagate errors from assigned_dev_register_regions()

2014-04-10 Thread Laszlo Ersek
Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 3a904e8..9aa92a1 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -392,13 +392,14 @@ static uint8_t pci_find_cap_offset(PCIDevice *d, uint8_t 
cap, uint8_t start)
 pos += PCI_CAP_LIST_NEXT;
 }
 return 0;
 }
 
-static int assigned_dev_register_regions(PCIRegion *io_regions,
- unsigned long regions_num,
- AssignedDevice *pci_dev)
+static void assigned_dev_register_regions(PCIRegion *io_regions,
+  unsigned long regions_num,
+  AssignedDevice *pci_dev,
+  Error **errp)
 {
 uint32_t i;
 PCIRegion *cur_region = io_regions;
 
 for (i = 0; i < regions_num; i++, cur_region++) {
@@ -423,13 +424,13 @@ static int assigned_dev_register_regions(PCIRegion 
*io_regions,
 cur_region->resource_fd,
 (off_t)0);
 
 if (pci_dev->v_addrs[i].u.r_virtbase == MAP_FAILED) {
 pci_dev->v_addrs[i].u.r_virtbase = NULL;
-error_report("%s: Error: Couldn't mmap 0x%" PRIx64 "!",
- __func__, cur_region->base_addr);
-return -1;
+error_setg_errno(errp, errno, "Couldn't mmap 0x%" PRIx64 "!",
+ cur_region->base_addr);
+return;
 }
 
 pci_dev->v_addrs[i].r_size = cur_region->size;
 pci_dev->v_addrs[i].e_size = 0;
 
@@ -494,11 +495,10 @@ static int assigned_dev_register_regions(PCIRegion 
*io_regions,
  &pci_dev->v_addrs[i].container);
 }
 }
 
 /* success */
-return 0;
 }
 
 static void get_real_id(const char *devpath, const char *idname, uint16_t *val,
 Error **errp)
 {
@@ -1794,13 +1794,16 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 goto out;
 }
 }
 
 /* handle real device's MMIO/PIO BARs */
-if (assigned_dev_register_regions(dev->real_device.regions,
-  dev->real_device.region_number,
-  dev)) {
+assigned_dev_register_regions(dev->real_device.regions,
+  dev->real_device.region_number, dev,
+  &local_err);
+if (local_err) {
+qerror_report_err(local_err);
+error_free(local_err);
 goto out;
 }
 
 /* handle interrupt routing */
 e_intx = dev->dev.config[PCI_INTERRUPT_PIN] - 1;
-- 
1.8.3.1





[Qemu-devel] [PATCH 14/16] pci-assign: propagate errors from assign_device()

2014-04-10 Thread Laszlo Ersek
Also, change the return type to "void"; the function is static (with a
sole caller) and the negative errno values are not distinguished from each
other.

Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 29 +++--
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 9aa92a1..0fedca8 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -793,27 +793,27 @@ static char *assign_failed_examine(const AssignedDevice 
*dev)
 
 fail:
 return g_strdup("Couldn't find out why.");
 }
 
-static int assign_device(AssignedDevice *dev)
+static void assign_device(AssignedDevice *dev, Error **errp)
 {
 uint32_t flags = KVM_DEV_ASSIGN_ENABLE_IOMMU;
 int r;
 
 /* Only pass non-zero PCI segment to capable module */
 if (!kvm_check_extension(kvm_state, KVM_CAP_PCI_SEGMENT) &&
 dev->host.domain) {
-error_report("Can't assign device inside non-zero PCI segment "
- "as this KVM module doesn't support it.");
-return -ENODEV;
+error_setg(errp, "Can't assign device inside non-zero PCI segment "
+   "as this KVM module doesn't support it.");
+return;
 }
 
 if (!kvm_check_extension(kvm_state, KVM_CAP_IOMMU)) {
-error_report("No IOMMU found.  Unable to assign device \"%s\"",
- dev->dev.qdev.id);
-return -ENODEV;
+error_setg(errp, "No IOMMU found.  Unable to assign device \"%s\"",
+   dev->dev.qdev.id);
+return;
 }
 
 if (dev->features & ASSIGNED_DEVICE_SHARE_INTX_MASK &&
 kvm_has_intx_set_mask()) {
 flags |= KVM_DEV_ASSIGN_PCI_2_3;
@@ -824,22 +824,21 @@ static int assign_device(AssignedDevice *dev)
 switch (r) {
 case -EBUSY: {
 char *cause;
 
 cause = assign_failed_examine(dev);
-error_report("Failed to assign device \"%s\" : %s\n%s",
- dev->dev.qdev.id, strerror(-r), cause);
+error_setg_errno(errp, -r, "Failed to assign device \"%s\"\n%s",
+ dev->dev.qdev.id, cause);
 g_free(cause);
 break;
 }
 default:
-error_report("Failed to assign device \"%s\" : %s",
- dev->dev.qdev.id, strerror(-r));
+error_setg_errno(errp, -r, "Failed to assign device \"%s\"",
+ dev->dev.qdev.id);
 break;
 }
 }
-return r;
 }
 
 static void verify_irqchip_in_kernel(Error **errp)
 {
 if (kvm_irqchip_in_kernel()) {
@@ -1810,12 +1809,14 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 dev->intpin = e_intx;
 dev->intx_route.mode = PCI_INTX_DISABLED;
 dev->intx_route.irq = -1;
 
 /* assign device to guest */
-r = assign_device(dev);
-if (r < 0) {
+assign_device(dev, &local_err);
+if (local_err) {
+qerror_report_err(local_err);
+error_free(local_err);
 goto out;
 }
 
 /* assign legacy INTx to the device */
 r = assign_intx(dev);
-- 
1.8.3.1





[Qemu-devel] [PATCH 16/16] pci-assign: assigned_initfn(): set monitor error in common error handler

2014-04-10 Thread Laszlo Ersek
Signed-off-by: Laszlo Ersek 
---
 hw/i386/kvm/pci-assign.c | 26 ++
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 6891729..e55421a 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -1754,18 +1754,18 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 uint8_t e_intx;
 int r;
 Error *local_err = NULL;
 
 if (!kvm_enabled()) {
-error_report("pci-assign: error: requires KVM support");
-return -1;
+error_setg(&local_err, "pci-assign requires KVM support");
+goto exit_with_error;
 }
 
 if (!dev->host.domain && !dev->host.bus && !dev->host.slot &&
 !dev->host.function) {
-error_report("pci-assign: error: no host device specified");
-return -1;
+error_setg(&local_err, "no host device specified");
+goto exit_with_error;
 }
 
 /*
  * Set up basic config space access control. Will be further refined during
  * device initialization.
@@ -1786,38 +1786,30 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 memcpy(dev->emulate_config_write, dev->emulate_config_read,
sizeof(dev->emulate_config_read));
 
 get_real_device(dev, &local_err);
 if (local_err) {
-qerror_report_err(local_err);
-error_free(local_err);
 goto out;
 }
 
 if (assigned_device_pci_cap_init(pci_dev, &local_err) < 0) {
-qerror_report_err(local_err);
-error_free(local_err);
 goto out;
 }
 
 /* intercept MSI-X entry page in the MMIO */
 if (dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) {
 assigned_dev_register_msix_mmio(dev, &local_err);
 if (local_err) {
-qerror_report_err(local_err);
-error_free(local_err);
 goto out;
 }
 }
 
 /* handle real device's MMIO/PIO BARs */
 assigned_dev_register_regions(dev->real_device.regions,
   dev->real_device.region_number, dev,
   &local_err);
 if (local_err) {
-qerror_report_err(local_err);
-error_free(local_err);
 goto out;
 }
 
 /* handle interrupt routing */
 e_intx = dev->dev.config[PCI_INTERRUPT_PIN] - 1;
@@ -1826,20 +1818,16 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 dev->intx_route.irq = -1;
 
 /* assign device to guest */
 assign_device(dev, &local_err);
 if (local_err) {
-qerror_report_err(local_err);
-error_free(local_err);
 goto out;
 }
 
 /* assign legacy INTx to the device */
 r = assign_intx(dev, &local_err);
 if (r < 0) {
-qerror_report_err(local_err);
-error_free(local_err);
 goto assigned_out;
 }
 
 assigned_dev_load_option_rom(dev);
 
@@ -1847,12 +1835,18 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 
 return 0;
 
 assigned_out:
 deassign_device(dev);
+
 out:
 free_assigned_device(dev);
+
+exit_with_error:
+assert(local_err);
+qerror_report_err(local_err);
+error_free(local_err);
 return -1;
 }
 
 static void assigned_exitfn(struct PCIDevice *pci_dev)
 {
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH v2 5/6] qemu-img: Specify backing file for commit

2014-04-10 Thread Fam Zheng
On Tue, 04/08 14:50, Max Reitz wrote:
> Introduce a new parameter for qemu-img commit which may be used to
> explicitly specify the backing file unto which an image should be
> committed if the backing chain has more than a single layer.
> 
> Signed-off-by: Max Reitz 
> ---
>  qemu-img-cmds.hx |  4 ++--
>  qemu-img.c   | 22 +++---
>  qemu-img.texi|  8 +++-
>  3 files changed, 24 insertions(+), 10 deletions(-)
> 
> diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
> index 8bc55cd..7f62f6d 100644
> --- a/qemu-img-cmds.hx
> +++ b/qemu-img-cmds.hx
> @@ -22,9 +22,9 @@ STEXI
>  ETEXI
>  
>  DEF("commit", img_commit,
> -"commit [-q] [-f fmt] [-t cache] [-p] filename")
> +"commit [-q] [-f fmt] [-t cache] [-b backing_file] [-p] filename")
>  STEXI
> -@item commit [-q] [-f @var{fmt}] [-t @var{cache}] [-p] @var{filename}
> +@item commit [-q] [-f @var{fmt}] [-t @var{cache}] [-b @var{backing_file}] 
> [-p] @var{filename}
>  ETEXI
>  
>  DEF("compare", img_compare,
> diff --git a/qemu-img.c b/qemu-img.c
> index 0a9eff7..9d4bdbc 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -725,15 +725,16 @@ static void run_block_job(BlockJob *job, Error **errp)
>  static int img_commit(int argc, char **argv)
>  {
>  int c, ret, flags;
> -const char *filename, *fmt, *cache;
> +const char *filename, *fmt, *cache, *base;
>  BlockDriverState *bs, *base_bs;
>  bool progress = false, quiet = false;
>  Error *local_err = NULL;
>  
>  fmt = NULL;
>  cache = BDRV_DEFAULT_CACHE;
> +base = NULL;
>  for(;;) {
> -c = getopt(argc, argv, "f:ht:qp");
> +c = getopt(argc, argv, "f:ht:b:qp");
>  if (c == -1) {
>  break;
>  }
> @@ -748,6 +749,9 @@ static int img_commit(int argc, char **argv)
>  case 't':
>  cache = optarg;
>  break;
> +case 'b':
> +base = optarg;
> +break;
>  case 'p':
>  progress = true;
>  break;
> @@ -782,12 +786,16 @@ static int img_commit(int argc, char **argv)
>  qemu_progress_init(progress, 1.f);
>  qemu_progress_print(0.f, 100);
>  
> -/* This is different from QMP, which by default uses the deepest file in 
> the
> - * backing chain (i.e., the very base); however, the traditional 
> behavior of
> - * qemu-img commit is using the immediate backing file. */
> -base_bs = bs->backing_hd;
> +if (base) {
> +base_bs = bdrv_find_backing_image(bs, base);
> +} else {
> +/* This is different from QMP, which by default uses the deepest 
> file in
> + * the backing chain (i.e., the very base); however, the traditional
> + * behavior of qemu-img commit is using the immediate backing file. 
> */
> +base_bs = bs->backing_hd;
> +}
>  if (!base_bs) {
> -error_set(&local_err, QERR_BASE_NOT_FOUND, "NULL");
> +error_set(&local_err, QERR_BASE_NOT_FOUND, base ?: "NULL");
>  goto done;
>  }
>  
> diff --git a/qemu-img.texi b/qemu-img.texi
> index 1a9c08f..4a9f493 100644
> --- a/qemu-img.texi
> +++ b/qemu-img.texi
> @@ -140,7 +140,7 @@ this case. @var{backing_file} will never be modified 
> unless you use the
>  The size can also be specified using the @var{size} option with @code{-o},
>  it doesn't need to be specified separately in this case.
>  
> -@item commit [-q] [-f @var{fmt}] [-t @var{cache}] [-p] @var{filename}
> +@item commit [-q] [-f @var{fmt}] [-t @var{cache}] [-b @var{backing_file}] 
> [-p] @var{filename}
>  
>  Commit the changes recorded in @var{filename} in its base image or backing 
> file.
>  If the backing file is smaller than the snapshot, then the backing file will 
> be
> @@ -149,6 +149,12 @@ the backing file, the backing file will not be 
> truncated.  If you want the
>  backing file to match the size of the smaller snapshot, you can safely 
> truncate
>  it yourself once the commit operation successfully completes.
>  
> +If the backing chain of the given image file @var{filename} has more than one
> +layer, the backing file unto which the changes shall be committed may be
> +specified as @var{backing_file} (which has to be part of @var{filename}'s
> +backing chain). If @var{filename} is not specified, the immediate backing 
> file

s/@var{filename}/@var{backing_file}/ ?

BTW how about just calling it 'base' as in qmp commands, because backing_file
has usages in (slightly) different context of create.

Other than the two questions,

Reviewed-by: Fam Zheng 

> +of the top image (which is @var{filename}) will be used.
> +
>  @item compare [-f @var{fmt}] [-F @var{fmt}] [-p] [-s] [-q] @var{filename1} 
> @var{filename2}
>  
>  Check if two images have the same content. You can compare images with
> -- 
> 1.9.1
> 
> 



[Qemu-devel] [PATCHES] add virtio input device

2014-04-10 Thread Gerd Hoffmann
  Hi,

Here comes a bunch of patches inplementing the virtio input device for
review.  One patch for the virtio specification.  One patch for the
linux kernel.  A small patch series for qemu.  Please review.

Note that the qemu patch series has dependencies on unmerged input layer
patches (waiting for the tree being opened up for 2.1), so if you wanna
play with please fetch everything here:
http://www.kraxel.org/cgit/qemu/log/?h=rebase/input-wip

cheers,
  Gerd




[Qemu-devel] [PATCH spec] Add virtio input device specification

2014-04-10 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 content.tex  |   2 +
 virtio-input.tex | 135 +++
 2 files changed, 137 insertions(+)
 create mode 100644 virtio-input.tex

diff --git a/content.tex b/content.tex
index c31a99e..196950d 100644
--- a/content.tex
+++ b/content.tex
@@ -4887,6 +4887,8 @@ descriptor for the \field{sense_len}, \field{residual},
 \field{status_qualifier}, \field{status}, \field{response} and
 \field{sense} fields.
 
+\input{virtio-input.tex}
+
 \chapter{Reserved Feature Bits}\label{sec:Reserved Feature Bits}
 
 Currently there are three device-independent feature bits defined:
diff --git a/virtio-input.tex b/virtio-input.tex
new file mode 100644
index 000..3c34a52
--- /dev/null
+++ b/virtio-input.tex
@@ -0,0 +1,135 @@
+\section{Input Device}\label{sec:Device Types / Input Device}
+
+The virtio input device can be used to create virtual human interface
+devices such as keyboards, mice and tables.  It basically sends linux
+input layer events over virtio.
+See \url{file:///usr/include/linux/input.h}.
+
+\subsection{Device ID}\label{sec:Device Types / Input Device / Device ID}
+
+18
+
+\subsection{Virtqueues}\label{sec:Device Types / Input Device / Virtqueues}
+
+\begin{description}
+\item[0] eventq
+\item[1] statusq
+\end{description}
+
+\subsection{Feature bits}\label{sec:Device Types / Input Device / Feature bits}
+
+None.
+
+\subsection{Device configuration layout}\label{sec:Device Types / Input Device 
/ Device configuration layout}
+
+Device configuration holds all information the guest needs to handle
+the device, most importantly the events which are supported.
+
+\begin{lstlisting}
+enum virtio_input_config_select {
+   VIRTIO_INPUT_CFG_UNSET  = 0x00,
+   VIRTIO_INPUT_CFG_ID_NAME= 0x01,
+   VIRTIO_INPUT_CFG_ID_SERIAL  = 0x02,
+   VIRTIO_INPUT_CFG_ID_SEAT= 0x03,
+   VIRTIO_INPUT_CFG_PROP_BITS  = 0x10,
+   VIRTIO_INPUT_CFG_EV_BITS= 0x11,
+   VIRTIO_INPUT_CFG_ABS_INFO   = 0x12,
+};
+
+struct virtio_input_absinfo {
+   le32  min;
+   le32  max;
+   le32  fuzz;
+   le32  flat;
+};
+
+struct virtio_input_config {
+   u8select;
+   u8subsel;
+   u8size;
+   u8reserved;
+   union {
+   char string[128];
+   u8   bitmap[128];
+   struct virtio_input_absinfo abs;
+   } u;
+};
+\end{lstlisting}
+
+To query a specific piece of information the driver MUST set
+\field{select} and \field{subsel} accordingly, then check \field{size}
+to see and how much information is available.  \field{size} can be
+zero if no information is available.
+
+\begin{description}
+
+\item[VIRTIO_INPUT_CFG_ID_NAME]
+\field{subsel} is not used and MUST be zero.
+Returns the name of the device, in \field{u.string}.
+
+Same as EVIOCGNAME ioctl for linux evdev devices.
+
+\item[VIRTIO_INPUT_CFG_ID_SERIAL]
+\field{subsel} is not used and MUST be zero.
+Returns the serial number of the device, in \field{u.string}.
+
+\item[VIRTIO_INPUT_CFG_ID_SEAT]
+\field{subsel} is not used and MUST be zero.
+Returns the seat the device should be assigned to, in \field{u.string}.
+
+\item[VIRTIO_INPUT_CFG_PROP_BITS]
+\field{subsel} is not used and MUST be zero.
+Returns input properties (INPUT_PROP_*) of the device, in \field{u.bitmap}.
+
+\item[VIRTIO_INPUT_CFG_EV_BITS]
+\field{subsel} specifies the event type (EV_*).  If \field{size} is
+non-zero the event type is supported and a bitmap the of supported
+event codes is returned in \field{u.bitmap}.
+
+Same as EVIOCGBIT ioctl.
+
+\item[VIRTIO_INPUT_CFG_ABS_INFO]
+\field{subsel} specifies the absolute axes (ABS_*).
+Informations about the axis will be returned in \field{u.abs}.
+
+Same as EVIOCGABS ioctl.
+
+\end{description}
+
+\subsection{Device Initialization}\label{sec:Device Types / Input Device / 
Device Initialization}
+
+\begin{enumerate}
+\item The device is queried for supported event types and codes.
+\item The eventq is populated with receive buffers.
+\end{enumerate}
+
+\subsection{Device Operation}\label{sec:Device Types / Input Device / Device 
Operation}
+
+\begin{enumerate}
+\item Input events such as press and release events for keys and
+  buttons and motion events are send from the device to the driver
+  using the eventq.
+\item Status feedback such as keyboard led updates are sent from the
+  driver to the device using the statusq.
+\item Both queues use the same virtio_input_event struct.
+  \field{type}, \field{code} and \field{value} are filled according to
+  the linux input layer (evdev) interface, except that the fields are
+  in little endian byte order whereas the evdev ioctl interface uses
+  native endian.
+\end{enumerate}
+
+\begin{lstlisting}
+struct virtio_input_event {
+   le16 type;
+   le16 code;
+   le32 value;
+};
+\end{lstlisting}
+
+\subsection{TODO List}\label{sec:Device Types / Input Device / TODO List}
+
+\begin{description}
+\item[Multitouch]
+Just 

[Qemu-devel] [PATCH qemu 4/6] virtio-input: emulated devices

2014-04-10 Thread Gerd Hoffmann
This patch adds the virtio-input-hid base class and
virtio-{keyboard,mouse,tablet} subclasses building on the base class.
They are hooked up to the qemu input core and deliver input events
to the guest like all other hid devices (ps/2 kbd, usb tablet, ...).

Using them is as simple as adding "-device virtio-tablet-pci" to your
command line.  If you want add multiple devices but don't want waste
a pci slot for each you can compose a multifunction device this way:

qemu -device virtio-keyboard-pci,addr=0d.0,multifunction=on \
 -device virtio-tablet-pci,addr=0d.1,multifunction=on

Signed-off-by: Gerd Hoffmann 
---
 hw/input/Makefile.objs   |   1 +
 hw/input/virtio-input-hid.c  | 486 +++
 hw/virtio/virtio-pci.c   |  68 ++
 hw/virtio/virtio-pci.h   |  13 ++
 include/hw/virtio/virtio-input.h |  22 ++
 5 files changed, 590 insertions(+)
 create mode 100644 hw/input/virtio-input-hid.c

diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
index ee8bba9..0dae710 100644
--- a/hw/input/Makefile.objs
+++ b/hw/input/Makefile.objs
@@ -10,6 +10,7 @@ common-obj-$(CONFIG_VMMOUSE) += vmmouse.o
 
 ifeq ($(CONFIG_LINUX),y)
 common-obj-$(CONFIG_VIRTIO) += virtio-input.o
+common-obj-$(CONFIG_VIRTIO) += virtio-input-hid.o
 endif
 
 obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
new file mode 100644
index 000..2db993e
--- /dev/null
+++ b/hw/input/virtio-input-hid.c
@@ -0,0 +1,486 @@
+/*
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ */
+
+#include "qemu/iov.h"
+
+#include "hw/qdev.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-input.h"
+
+#include "ui/console.h"
+
+#include 
+
+#define VIRTIO_ID_NAME_KEYBOARD "QEMU Virtio Keyboard"
+#define VIRTIO_ID_NAME_MOUSE"QEMU Virtio Mouse"
+#define VIRTIO_ID_NAME_TABLET   "QEMU Virtio Tablet"
+
+/* - */
+
+static const unsigned int keymap_qcode[Q_KEY_CODE_MAX] = {
+[Q_KEY_CODE_ESC] = KEY_ESC,
+[Q_KEY_CODE_1]   = KEY_1,
+[Q_KEY_CODE_2]   = KEY_2,
+[Q_KEY_CODE_3]   = KEY_3,
+[Q_KEY_CODE_4]   = KEY_4,
+[Q_KEY_CODE_5]   = KEY_5,
+[Q_KEY_CODE_6]   = KEY_6,
+[Q_KEY_CODE_7]   = KEY_7,
+[Q_KEY_CODE_8]   = KEY_8,
+[Q_KEY_CODE_9]   = KEY_9,
+[Q_KEY_CODE_0]   = KEY_0,
+[Q_KEY_CODE_MINUS]   = KEY_MINUS,
+[Q_KEY_CODE_EQUAL]   = KEY_EQUAL,
+[Q_KEY_CODE_BACKSPACE]   = KEY_BACKSPACE,
+
+[Q_KEY_CODE_TAB] = KEY_TAB,
+[Q_KEY_CODE_Q]   = KEY_Q,
+[Q_KEY_CODE_W]   = KEY_W,
+[Q_KEY_CODE_E]   = KEY_E,
+[Q_KEY_CODE_R]   = KEY_R,
+[Q_KEY_CODE_T]   = KEY_T,
+[Q_KEY_CODE_Y]   = KEY_Y,
+[Q_KEY_CODE_U]   = KEY_U,
+[Q_KEY_CODE_I]   = KEY_I,
+[Q_KEY_CODE_O]   = KEY_O,
+[Q_KEY_CODE_P]   = KEY_P,
+[Q_KEY_CODE_BRACKET_LEFT]= KEY_LEFTBRACE,
+[Q_KEY_CODE_BRACKET_RIGHT]   = KEY_RIGHTBRACE,
+[Q_KEY_CODE_RET] = KEY_ENTER,
+
+[Q_KEY_CODE_CTRL]= KEY_LEFTCTRL,
+[Q_KEY_CODE_A]   = KEY_A,
+[Q_KEY_CODE_S]   = KEY_S,
+[Q_KEY_CODE_D]   = KEY_D,
+[Q_KEY_CODE_F]   = KEY_F,
+[Q_KEY_CODE_G]   = KEY_G,
+[Q_KEY_CODE_H]   = KEY_H,
+[Q_KEY_CODE_J]   = KEY_J,
+[Q_KEY_CODE_K]   = KEY_K,
+[Q_KEY_CODE_L]   = KEY_L,
+[Q_KEY_CODE_SEMICOLON]   = KEY_SEMICOLON,
+[Q_KEY_CODE_APOSTROPHE]  = KEY_APOSTROPHE,
+[Q_KEY_CODE_GRAVE_ACCENT]= KEY_GRAVE,
+
+[Q_KEY_CODE_SHIFT]   = KEY_LEFTSHIFT,
+[Q_KEY_CODE_BACKSLASH]   = KEY_BACKSLASH,
+[Q_KEY_CODE_LESS]= KEY_102ND,
+[Q_KEY_CODE_Z]   = KEY_Z,
+[Q_KEY_CODE_X]   = KEY_X,
+[Q_KEY_CODE_C]   = KEY_C,
+[Q_KEY_CODE_V]   = KEY_V,
+[Q_KEY_CODE_B]   = KEY_B,
+[Q_KEY_CODE_N]   = KEY_N,
+[Q_KEY_CODE_M]   = KEY_M,
+[Q_KEY_CODE_COMMA]   = KEY_COMMA,
+[Q_KEY_CODE_DOT] = KEY_DOT,
+[Q_KEY_CODE_SLASH]   = KEY_SLASH,
+[Q_KEY_CODE_SHIFT_R] = KEY_RIGHTSHIFT,
+
+[Q_KEY_CODE_ALT] = KEY_LEFTALT,
+[Q_KEY_CODE_SPC] = KEY_SPACE,
+[Q_KEY_CODE_CAPS_LOC

[Qemu-devel] [PATCH qemu 3/6] virtio-input: core code & base class

2014-04-10 Thread Gerd Hoffmann
This patch adds virtio-input support to qemu.  It brings a abstract
base class providing core support, other classes can build on it to
actually implement input devices.

virtio-input basically sends linux input layer events (evdev) over
virtio.

Signed-off-by: Gerd Hoffmann 
---
 hw/input/Makefile.objs   |   4 +
 hw/input/virtio-input.c  | 253 +++
 hw/virtio/virtio-pci.c   |  36 ++
 hw/virtio/virtio-pci.h   |  14 +++
 include/hw/virtio/virtio-input.h | 105 
 include/hw/virtio/virtio.h   |   1 +
 6 files changed, 413 insertions(+)
 create mode 100644 hw/input/virtio-input.c
 create mode 100644 include/hw/virtio/virtio-input.h

diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
index e8c80b9..ee8bba9 100644
--- a/hw/input/Makefile.objs
+++ b/hw/input/Makefile.objs
@@ -8,6 +8,10 @@ common-obj-$(CONFIG_STELLARIS_INPUT) += stellaris_input.o
 common-obj-$(CONFIG_TSC2005) += tsc2005.o
 common-obj-$(CONFIG_VMMOUSE) += vmmouse.o
 
+ifeq ($(CONFIG_LINUX),y)
+common-obj-$(CONFIG_VIRTIO) += virtio-input.o
+endif
+
 obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
 obj-$(CONFIG_PXA2XX) += pxa2xx_keypad.o
 obj-$(CONFIG_TSC210X) += tsc210x.o
diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c
new file mode 100644
index 000..35f0cfc
--- /dev/null
+++ b/hw/input/virtio-input.c
@@ -0,0 +1,253 @@
+/*
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ */
+
+#include "qemu/iov.h"
+
+#include "hw/qdev.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-input.h"
+
+#include "ui/console.h"
+
+#include 
+
+/* - */
+
+void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event)
+{
+VirtQueueElement elem;
+int len;
+
+if (!virtqueue_pop(vinput->evt, &elem)) {
+fprintf(stderr, "%s: virtqueue empty, dropping event\n", __func__);
+return;
+}
+len = iov_from_buf(elem.in_sg, elem.in_num,
+   0, event, sizeof(*event));
+virtqueue_push(vinput->evt, &elem, len);
+}
+
+static void virtio_input_handle_evt(VirtIODevice *vdev, VirtQueue *vq)
+{
+/* nothing */
+}
+
+static void virtio_input_handle_sts(VirtIODevice *vdev, VirtQueue *vq)
+{
+VirtIOInputClass *vic = VIRTIO_INPUT_GET_CLASS(vdev);
+VirtIOInput *vinput = VIRTIO_INPUT(vdev);
+virtio_input_event event;
+VirtQueueElement elem;
+int len;
+
+while (virtqueue_pop(vinput->sts, &elem)) {
+memset(&event, 0, sizeof(event));
+len = iov_to_buf(elem.out_sg, elem.out_num,
+ 0, &event, sizeof(event));
+if (vic->handle_status) {
+vic->handle_status(vinput, &event);
+}
+virtqueue_push(vinput->sts, &elem, len);
+}
+virtio_notify(vdev, vinput->sts);
+}
+
+static virtio_input_config *virtio_input_find_config(VirtIOInput *vinput,
+ uint8_t select,
+ uint8_t subsel)
+{
+VirtIOInputConfig *cfg;
+
+QTAILQ_FOREACH(cfg, &vinput->cfg_list, node) {
+if (select == cfg->config.select &&
+subsel == cfg->config.subsel) {
+return &cfg->config;
+}
+}
+return NULL;
+}
+
+void virtio_input_add_config(VirtIOInput *vinput,
+ virtio_input_config *config)
+{
+VirtIOInputConfig *cfg;
+
+if (virtio_input_find_config(vinput, config->select, config->subsel)) {
+/* should not happen */
+fprintf(stderr, "%s: duplicate config: %d/%d\n",
+__func__, config->select, config->subsel);
+abort();
+}
+
+cfg = g_new0(VirtIOInputConfig, 1);
+cfg->config = *config;
+QTAILQ_INSERT_TAIL(&vinput->cfg_list, cfg, node);
+}
+
+void virtio_input_init_config(VirtIOInput *vinput,
+  virtio_input_config *config)
+{
+int i = 0;
+
+QTAILQ_INIT(&vinput->cfg_list);
+while (config[i].select) {
+virtio_input_add_config(vinput, config + i);
+i++;
+}
+}
+
+void virtio_input_idstr_config(VirtIOInput *vinput,
+   uint8_t select, const char *string)
+{
+virtio_input_config id;
+
+if (!string) {
+return;
+}
+memset(&id, 0, sizeof(id));
+id.select = select;
+id.size = snprintf(id.u.string, sizeof(id.u.string), "%s", string);
+virtio_input_add_config(vinput, &id);
+}
+
+static void virtio_input_get_config(VirtIODevice *vdev, uint8_t *config_data)
+{
+VirtIOInput *vinput = VIRTIO_INPUT(vdev);
+virtio_input_config *config;
+
+config = virtio_input_find_config(vinput, vinput->cfg_select,
+  vinput->cfg_subsel);
+if (config) {
+memcpy(config_data, config, vinput-

[Qemu-devel] [PATCH qemu 1/6] pci: add virtio input pci device id

2014-04-10 Thread Gerd Hoffmann
Using 0x1012 because virtio id is 18 (0x12).

Signed-off-by: Gerd Hoffmann 
---
 docs/specs/pci-ids.txt | 1 +
 include/hw/pci/pci.h   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/docs/specs/pci-ids.txt b/docs/specs/pci-ids.txt
index 3c65e1a..3b0a448 100644
--- a/docs/specs/pci-ids.txt
+++ b/docs/specs/pci-ids.txt
@@ -22,6 +22,7 @@ maintained as part of the virtio specification.
 1af4:1004  SCSI host bus adapter device
 1af4:1005  entropy generator device
 1af4:1009  9p filesystem device
+1af4:1012  input device
 
 1af4:10f0  Available for experimental usage without registration.  Must get
to  official ID when the code leaves the test lab (i.e. when seeking
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 693dd6b..6539cbd 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -80,6 +80,7 @@
 #define PCI_DEVICE_ID_VIRTIO_SCSI0x1004
 #define PCI_DEVICE_ID_VIRTIO_RNG 0x1005
 #define PCI_DEVICE_ID_VIRTIO_9P  0x1009
+#define PCI_DEVICE_ID_VIRTIO_INPUT   0x1012
 
 #define PCI_VENDOR_ID_REDHAT 0x1b36
 #define PCI_DEVICE_ID_REDHAT_BRIDGE  0x0001
-- 
1.8.3.1




Re: [Qemu-devel] QEMU: PCI bus name on PowerPC platforms

2014-04-10 Thread Daniel P. Berrange
On Wed, Mar 05, 2014 at 03:33:39PM +0100, Paolo Bonzini wrote:
> Il 05/03/2014 15:21, Daniel P. Berrange ha scritto:
> >>alpha/typhoon.c:b = pci_register_bus(dev, "pci",
> >>mips/gt64xxx_pci.c: phb->bus = pci_register_bus(dev, "pci",
> >>pci-host/apb.c:phb->bus = pci_register_bus(DEVICE(phb), "pci",
> >>pci-host/bonito.c:phb->bus = pci_register_bus(DEVICE(dev), "pci",
> >>sh4/sh_pci.c:phb->bus = pci_register_bus(DEVICE(dev), "pci",
> >>pci-host/versatile.c:pci_bus_new_inplace(&s->pci_bus, 
> >>sizeof(s->pci_bus), DEVICE(obj), "pci",
> >>
> >>plus pseries which has its own rules because it supports multiple PCI
> >>host bridges, but probably can also be changed from "pci" to NULL.
> >
> >I'm not sure I understand the effect of changing 'pci' to NULL in this
> >code, from libvirt's POV. Would using NULL mean we can rely on using
> >"pci.0" as the default PCI bus name or not ?
> 
> Yes.  But the next bus that the user creates (e.g. from a PCI bridge
> without an "id") would be "pci.1" instead of having a duplicate
> "pci.0").  Needs a bit more testing of course.

What's the status of this ?  I see the patch merged which only changes
the bus name for ppc64  spapr-pci board

commit 1b8601b0ea0b91467561e0bbddd52a833e4b2b1a
Author: Alexey Kardashevskiy 
Date:   Thu Mar 6 14:11:00 2014 +1100

spapr-pci: Change the default PCI bus naming

but AFAICT nothing got merged to change this for all the other boards as
discussed here :-(  This is painful for libvirt since we have todo even
more hacks triggered off machine names now, instead of being able to
rely on pci.0 naming as we hoped.


Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



[Qemu-devel] [PATCH linux] Add virtio-input driver.

2014-04-10 Thread Gerd Hoffmann
virtio-input is basically evdev-events-over-virtio, so this driver isn't
much more than forwarding incoming events to the linux input layer.

Signed-off-by: Gerd Hoffmann 
---
 drivers/virtio/Kconfig|  10 ++
 drivers/virtio/Makefile   |   1 +
 drivers/virtio/virtio_input.c | 329 ++
 include/uapi/linux/virtio_ids.h   |   1 +
 include/uapi/linux/virtio_input.h |  66 
 5 files changed, 407 insertions(+)
 create mode 100644 drivers/virtio/virtio_input.c
 create mode 100644 include/uapi/linux/virtio_input.h

diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index c6683f2..05e2fda 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -31,6 +31,16 @@ config VIRTIO_BALLOON
 
 If unsure, say M.
 
+config VIRTIO_INPUT
+   tristate "Virtio input driver"
+   depends on VIRTIO
+   depends on INPUT
+   ---help---
+This driver supports virtio input devices such as
+keyboards, mice and tablets.
+
+If unsure, say M.
+
  config VIRTIO_MMIO
tristate "Platform bus driver for memory mapped virtio devices"
depends on HAS_IOMEM
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 9076635..45aeaac 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -2,3 +2,4 @@ obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
+obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o
diff --git a/drivers/virtio/virtio_input.c b/drivers/virtio/virtio_input.c
new file mode 100644
index 000..25036fb
--- /dev/null
+++ b/drivers/virtio/virtio_input.c
@@ -0,0 +1,329 @@
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+struct virtio_input {
+   struct virtio_device   *vdev;
+   struct input_dev   *idev;
+   char   name[64];
+   char   serial[64];
+   char   seat[64];
+   char   phys[64];
+   struct virtqueue   *evt, *sts;
+   struct virtio_input_event  evts[64];
+};
+
+static ssize_t serial_show(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   struct input_dev *idev = to_input_dev(dev);
+   struct virtio_input *vi = input_get_drvdata(idev);
+   return sprintf(buf, "%s\n", vi->serial);
+}
+static DEVICE_ATTR_RO(serial);
+
+static ssize_t seat_show(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   struct input_dev *idev = to_input_dev(dev);
+   struct virtio_input *vi = input_get_drvdata(idev);
+   return sprintf(buf, "%s\n", vi->seat);
+}
+static DEVICE_ATTR_RO(seat);
+
+static struct attribute *dev_attrs[] = {
+   &dev_attr_serial.attr,
+   &dev_attr_seat.attr,
+   NULL
+};
+
+static umode_t dev_attrs_are_visible(struct kobject *kobj,
+struct attribute *a, int n)
+{
+   struct device *dev = container_of(kobj, struct device, kobj);
+   struct input_dev *idev = to_input_dev(dev);
+   struct virtio_input *vi = input_get_drvdata(idev);
+
+   if (a == &dev_attr_serial.attr && !strlen(vi->serial))
+   return 0;
+   if (a == &dev_attr_seat.attr && !strlen(vi->seat))
+   return 0;
+
+   return a->mode;
+}
+
+static struct attribute_group dev_attr_grp = {
+   .attrs =dev_attrs,
+   .is_visible =   dev_attrs_are_visible,
+};
+
+static const struct attribute_group *dev_attr_groups[] = {
+   &dev_attr_grp,
+   NULL
+};
+
+static void virtinput_queue_evtbuf(struct virtio_input *vi,
+  struct virtio_input_event *evtbuf)
+{
+   struct scatterlist sg[1];
+
+   sg_init_one(sg, evtbuf, sizeof(*evtbuf));
+   virtqueue_add_inbuf(vi->evt, sg, 1, evtbuf, GFP_ATOMIC);
+}
+
+static void virtinput_recv_events(struct virtqueue *vq)
+{
+   struct virtio_input *vi = vq->vdev->priv;
+   struct virtio_input_event *event;
+   unsigned int len;
+
+   while ((event = virtqueue_get_buf(vi->evt, &len)) != NULL) {
+   input_event(vi->idev,
+   le16_to_cpu(event->type),
+   le16_to_cpu(event->code),
+   le32_to_cpu(event->value));
+   virtinput_queue_evtbuf(vi, event);
+   }
+   virtqueue_kick(vq);
+}
+
+static int virtinput_send_status(struct virtio_input *vi,
+u16 type, u16 code, s32 value)
+{
+   struct virtio_input_event *stsbuf;
+   struct scatterlist sg[1];
+
+   stsbuf = kzalloc(sizeof(*stsbuf), GFP_ATOMIC);
+   if (!stsbuf)
+   return -ENOMEM;
+
+   stsbuf->type  = cpu_to_le16(type);
+   stsbuf->code  = cpu_to_le16(code);
+   stsbuf->value = cpu_to_le32(value);
+  

[Qemu-devel] [PATCH qemu 6/6] virtio-input: evdev passthrough

2014-04-10 Thread Gerd Hoffmann
This allows to assign host input devices to the guest:

qemu -device virto-input-host-pci,evdev=/dev/input/event

The guest gets exclusive access to the input device, so be careful
with assigning the keyboard if you have only one connected to your
machine.

Signed-off-by: Gerd Hoffmann 
---
 hw/input/Makefile.objs   |   1 +
 hw/input/virtio-input-host.c | 174 +++
 hw/virtio/virtio-pci.c   |  31 +++
 hw/virtio/virtio-pci.h   |  10 +++
 include/hw/virtio/virtio-input.h |  13 +++
 5 files changed, 229 insertions(+)
 create mode 100644 hw/input/virtio-input-host.c

diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
index 0179154..9461b37 100644
--- a/hw/input/Makefile.objs
+++ b/hw/input/Makefile.objs
@@ -12,6 +12,7 @@ ifeq ($(CONFIG_LINUX),y)
 common-obj-$(CONFIG_VIRTIO) += virtio-input.o
 common-obj-$(CONFIG_VIRTIO) += virtio-input-hid.o
 common-obj-$(CONFIG_VIRTIO) += virtio-input-control.o
+common-obj-$(CONFIG_VIRTIO) += virtio-input-host.o
 endif
 
 obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
diff --git a/hw/input/virtio-input-host.c b/hw/input/virtio-input-host.c
new file mode 100644
index 000..663d967
--- /dev/null
+++ b/hw/input/virtio-input-host.c
@@ -0,0 +1,174 @@
+/*
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ */
+
+#include "qemu-common.h"
+#include "qemu/sockets.h"
+
+#include "hw/qdev.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-input.h"
+
+#include "ui/console.h"
+
+#include 
+
+/* - */
+
+static struct virtio_input_config virtio_input_host_config[] = {
+{ /* empty list */ },
+};
+
+static void virtio_input_host_event(void *opaque)
+{
+VirtIOInputHost *vhost = opaque;
+VirtIOInput *vinput = VIRTIO_INPUT(vhost);
+struct virtio_input_event virtio;
+struct input_event evdev;
+bool notify = false;
+int rc;
+
+for (;;) {
+rc = read(vhost->fd, &evdev, sizeof(evdev));
+if (rc != sizeof(evdev)) {
+break;
+}
+
+virtio.type  = cpu_to_le16(evdev.type);
+virtio.code  = cpu_to_le16(evdev.code);
+virtio.value = cpu_to_le32(evdev.value);
+virtio_input_send(vinput, &virtio);
+
+if (evdev.type == EV_SYN) {
+notify = true;
+}
+}
+
+if (notify) {
+virtio_notify(VIRTIO_DEVICE(vhost), vinput->evt);
+}
+}
+
+static void virtio_input_bits_config(VirtIOInputHost *vhost,
+ int type, int count)
+{
+virtio_input_config bits;
+int rc, i, size = 0;
+
+memset(&bits, 0, sizeof(bits));
+rc = ioctl(vhost->fd, EVIOCGBIT(type, count/8), bits.u.bitmap);
+if (rc < 0) {
+return;
+}
+
+for (i = 0; i < count/8; i++) {
+if (bits.u.bitmap[i]) {
+size = i+1;
+}
+}
+if (size == 0) {
+return;
+}
+
+bits.select = VIRTIO_INPUT_CFG_EV_BITS;
+bits.subsel = type;
+bits.size   = size;
+virtio_input_add_config(VIRTIO_INPUT(vhost), &bits);
+}
+
+static void virtio_input_host_realize(DeviceState *dev, Error **errp)
+{
+VirtIOInputHost *vhost = VIRTIO_INPUT_HOST(dev);
+VirtIOInput *vinput = VIRTIO_INPUT(dev);
+virtio_input_config id;
+int rc, ver;
+
+if (!vhost->evdev) {
+error_setg(errp, "evdev property is required");
+return;
+}
+
+vhost->fd = open(vhost->evdev, O_RDWR);
+if (vhost->fd < 0)  {
+error_setg_file_open(errp, errno, vhost->evdev);
+return;
+}
+qemu_set_nonblock(vhost->fd);
+
+rc = ioctl(vhost->fd, EVIOCGVERSION, &ver);
+if (rc < 0) {
+error_setg(errp, "%s: is not an evdev device", vhost->evdev);
+goto err_close;
+}
+
+rc = ioctl(vhost->fd, EVIOCGRAB, 1);
+if (rc < 0) {
+error_setg_errno(errp, errno, "%s: failed to get exclusive access",
+ vhost->evdev);
+goto err_close;
+}
+
+memset(&id, 0, sizeof(id));
+ioctl(vhost->fd, EVIOCGNAME(sizeof(id.u.string)-1), id.u.string);
+id.select = VIRTIO_INPUT_CFG_ID_NAME;
+id.size = strlen(id.u.string);
+virtio_input_add_config(vinput, &id);
+
+virtio_input_bits_config(vhost, EV_KEY, KEY_CNT);
+virtio_input_bits_config(vhost, EV_REL, REL_CNT);
+virtio_input_bits_config(vhost, EV_ABS, ABS_CNT);
+virtio_input_bits_config(vhost, EV_MSC, MSC_CNT);
+virtio_input_bits_config(vhost, EV_SW,  SW_CNT);
+
+qemu_set_fd_handler(vhost->fd, virtio_input_host_event, NULL, vhost);
+return;
+
+err_close:
+close(vhost->fd);
+vhost->fd = -1;
+return;
+}
+
+static void virtio_input_host_unrealize(DeviceState *dev, Error **errp)
+{
+VirtIOInputHost *vhost = VIRTIO_INPUT_HOST(dev);
+
+if (vhost->fd > 0) {
+qemu_set_fd_handler(vhost->fd, 

[Qemu-devel] [PATCH qemu 5/6] virtio-input: control device

2014-04-10 Thread Gerd Hoffmann
Device for sending non-input control messages to the guest.  For now
this is only a single event: shutdown requests are sent as power button
press to the guest.

Possible other use is signaling sound volume changes to the guest (via
EV_ABS / ABS_VOLUME).  I expect we'll find more over time.

Signed-off-by: Gerd Hoffmann 
---
 hw/input/Makefile.objs   |   1 +
 hw/input/virtio-input-control.c  | 112 +++
 hw/virtio/virtio-pci.c   |  29 ++
 hw/virtio/virtio-pci.h   |  10 
 include/hw/virtio/virtio-input.h |  12 +
 5 files changed, 164 insertions(+)
 create mode 100644 hw/input/virtio-input-control.c

diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
index 0dae710..0179154 100644
--- a/hw/input/Makefile.objs
+++ b/hw/input/Makefile.objs
@@ -11,6 +11,7 @@ common-obj-$(CONFIG_VMMOUSE) += vmmouse.o
 ifeq ($(CONFIG_LINUX),y)
 common-obj-$(CONFIG_VIRTIO) += virtio-input.o
 common-obj-$(CONFIG_VIRTIO) += virtio-input-hid.o
+common-obj-$(CONFIG_VIRTIO) += virtio-input-control.o
 endif
 
 obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
diff --git a/hw/input/virtio-input-control.c b/hw/input/virtio-input-control.c
new file mode 100644
index 000..3e439e6
--- /dev/null
+++ b/hw/input/virtio-input-control.c
@@ -0,0 +1,112 @@
+/*
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ */
+
+#include "qemu/iov.h"
+
+#include "hw/qdev.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-input.h"
+
+#include "ui/console.h"
+
+#include 
+
+#define VIRTIO_ID_NAME_CTRL "QEMU Virtio Control Panel"
+
+/* - */
+
+static void virtio_input_key_config(VirtIOInput *vinput)
+{
+static const int keylist[] = { KEY_POWER };
+virtio_input_config keys;
+int i, bit, byte, bmax = 0;
+
+memset(&keys, 0, sizeof(keys));
+for (i = 0; i < ARRAY_SIZE(keylist); i++) {
+byte = keylist[i] / 8;
+bit  = keylist[i] % 8;
+keys.u.bitmap[byte] |= (1 << bit);
+if (bmax < byte+1) {
+bmax = byte+1;
+}
+}
+keys.select = VIRTIO_INPUT_CFG_EV_BITS;
+keys.subsel = EV_KEY;
+keys.size   = bmax;
+virtio_input_add_config(vinput, &keys);
+}
+
+static void virtio_input_ctrl_keypress(VirtIOInput *vinput, int keycode)
+{
+virtio_input_event key_down = {
+.type  = cpu_to_le16(EV_KEY),
+.code  = cpu_to_le16(keycode),
+.value = 1,
+};
+virtio_input_event key_up = {
+.type  = cpu_to_le16(EV_KEY),
+.code  = cpu_to_le16(keycode),
+.value = 0,
+};
+virtio_input_event sync = {
+.type  = cpu_to_le16(EV_SYN),
+.code  = cpu_to_le16(SYN_REPORT),
+.value = 0,
+};
+
+virtio_input_send(vinput, &key_down);
+virtio_input_send(vinput, &sync);
+virtio_input_send(vinput, &key_up);
+virtio_input_send(vinput, &sync);
+virtio_notify(VIRTIO_DEVICE(vinput), vinput->evt);
+}
+
+static void virtio_input_ctrl_powerdown(Notifier *n, void *opaque)
+{
+VirtIOInputCtrl *vctrl =
+container_of(n, VirtIOInputCtrl, powerdown);
+
+virtio_input_ctrl_keypress(VIRTIO_INPUT(vctrl), KEY_POWER);
+}
+
+/* - */
+
+static struct virtio_input_config virtio_ctrl_config[] = {
+{
+.select= VIRTIO_INPUT_CFG_ID_NAME,
+.size  = sizeof(VIRTIO_ID_NAME_CTRL),
+.u.string  = VIRTIO_ID_NAME_CTRL,
+},
+{ /* end of list */ },
+};
+
+static void virtio_ctrl_init(Object *obj)
+{
+VirtIOInput *vinput = VIRTIO_INPUT(obj);
+VirtIOInputCtrl *vctrl = VIRTIO_INPUT_CTRL(obj);
+
+virtio_input_init_config(vinput, virtio_ctrl_config);
+virtio_input_key_config(vinput);
+
+vctrl->powerdown.notify = virtio_input_ctrl_powerdown;
+qemu_register_powerdown_notifier(&vctrl->powerdown);
+}
+
+static const TypeInfo virtio_ctrl_info = {
+.name  = TYPE_VIRTIO_INPUT_CTRL,
+.parent= TYPE_VIRTIO_INPUT,
+.instance_size = sizeof(VirtIOInputCtrl),
+.instance_init = virtio_ctrl_init,
+};
+
+/* - */
+
+static void virtio_register_types(void)
+{
+type_register_static(&virtio_ctrl_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index b421c01..9446d45 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1541,6 +1541,12 @@ static Property virtio_input_hid_pci_properties[] = {
 DEFINE_PROP_END_OF_LIST(),
 };
 
+static Property virtio_input_ctrl_pci_properties[] = {
+DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
+DEFINE_PROP_END_OF_LIST(),
+};
+
 static int virtio_input_pci_init(VirtIOPCIPro

[Qemu-devel] [PATCH qemu 2/6] pci: add virtio gpu pci device id

2014-04-10 Thread Gerd Hoffmann
Using 0x1010 because virtio id is 16 (0x10).

Signed-off-by: Gerd Hoffmann 
---
 docs/specs/pci-ids.txt | 1 +
 include/hw/pci/pci.h   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/docs/specs/pci-ids.txt b/docs/specs/pci-ids.txt
index 3b0a448..69a2de9 100644
--- a/docs/specs/pci-ids.txt
+++ b/docs/specs/pci-ids.txt
@@ -22,6 +22,7 @@ maintained as part of the virtio specification.
 1af4:1004  SCSI host bus adapter device
 1af4:1005  entropy generator device
 1af4:1009  9p filesystem device
+1af4:1010  gpu device
 1af4:1012  input device
 
 1af4:10f0  Available for experimental usage without registration.  Must get
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 6539cbd..6ebc5fa 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -80,6 +80,7 @@
 #define PCI_DEVICE_ID_VIRTIO_SCSI0x1004
 #define PCI_DEVICE_ID_VIRTIO_RNG 0x1005
 #define PCI_DEVICE_ID_VIRTIO_9P  0x1009
+#define PCI_DEVICE_ID_VIRTIO_GPU 0x1010
 #define PCI_DEVICE_ID_VIRTIO_INPUT   0x1012
 
 #define PCI_VENDOR_ID_REDHAT 0x1b36
-- 
1.8.3.1




Re: [Qemu-devel] [Qemu-ppc] [PATCH 0/2] QEMU Monitor Instruction Disassembly Incorrect for PPC LE

2014-04-10 Thread Alexander Graf


On 09.04.14 21:53, Tom Musta wrote:

Fix disassembly in the QEMU monitor for Little Endian codes.  Also fix the 
comment
and tighten up a flag check in the closely related disassembler code for
tracing.

V2: Fixed target_disas comment and bit decoding.
V3: Make monitor_disas flag documentation refer to target_disas documentation.
V4: Minor corrections to comments.


Does this also fix -d in_asm?


Alex




Re: [Qemu-devel] [Qemu-ppc] [PATCH 0/2] QEMU Monitor Instruction Disassembly Incorrect for PPC LE

2014-04-10 Thread Alexander Graf


On 10.04.14 12:12, Alexander Graf wrote:


On 09.04.14 21:53, Tom Musta wrote:
Fix disassembly in the QEMU monitor for Little Endian codes.  Also 
fix the comment

and tighten up a flag check in the closely related disassembler code for
tracing.

V2: Fixed target_disas comment and bit decoding.
V3: Make monitor_disas flag documentation refer to target_disas 
documentation.

V4: Minor corrections to comments.


Does this also fix -d in_asm?


Ah, that one is already good :).

Thanks, applied to ppc-next.


Alex




Re: [Qemu-devel] [PATCH qemu 4/6] virtio-input: emulated devices

2014-04-10 Thread Michael S. Tsirkin
On Thu, Apr 10, 2014 at 11:07:52AM +0200, Gerd Hoffmann wrote:
> This patch adds the virtio-input-hid base class and
> virtio-{keyboard,mouse,tablet} subclasses building on the base class.
> They are hooked up to the qemu input core and deliver input events
> to the guest like all other hid devices (ps/2 kbd, usb tablet, ...).
> 
> Using them is as simple as adding "-device virtio-tablet-pci" to your
> command line.  If you want add multiple devices but don't want waste
> a pci slot for each you can compose a multifunction device this way:
> 
> qemu -device virtio-keyboard-pci,addr=0d.0,multifunction=on \
>  -device virtio-tablet-pci,addr=0d.1,multifunction=on
> 
> Signed-off-by: Gerd Hoffmann 

Hmm - that's interesting.
I was under the impression that a single pci function can be
a keyboard, mouse and tablet at the same time.

If they aren't why don't we assign distinct device IDs to them
after all?

> ---
>  hw/input/Makefile.objs   |   1 +
>  hw/input/virtio-input-hid.c  | 486 
> +++
>  hw/virtio/virtio-pci.c   |  68 ++
>  hw/virtio/virtio-pci.h   |  13 ++
>  include/hw/virtio/virtio-input.h |  22 ++
>  5 files changed, 590 insertions(+)
>  create mode 100644 hw/input/virtio-input-hid.c
> 
> diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
> index ee8bba9..0dae710 100644
> --- a/hw/input/Makefile.objs
> +++ b/hw/input/Makefile.objs
> @@ -10,6 +10,7 @@ common-obj-$(CONFIG_VMMOUSE) += vmmouse.o
>  
>  ifeq ($(CONFIG_LINUX),y)
>  common-obj-$(CONFIG_VIRTIO) += virtio-input.o
> +common-obj-$(CONFIG_VIRTIO) += virtio-input-hid.o
>  endif
>  
>  obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
> diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
> new file mode 100644
> index 000..2db993e
> --- /dev/null
> +++ b/hw/input/virtio-input-hid.c
> @@ -0,0 +1,486 @@
> +/*
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> + * (at your option) any later version.  See the COPYING file in the
> + * top-level directory.
> + */
> +
> +#include "qemu/iov.h"
> +
> +#include "hw/qdev.h"
> +#include "hw/virtio/virtio.h"
> +#include "hw/virtio/virtio-input.h"
> +
> +#include "ui/console.h"
> +
> +#include 
> +
> +#define VIRTIO_ID_NAME_KEYBOARD "QEMU Virtio Keyboard"
> +#define VIRTIO_ID_NAME_MOUSE"QEMU Virtio Mouse"
> +#define VIRTIO_ID_NAME_TABLET   "QEMU Virtio Tablet"
> +
> +/* - */
> +
> +static const unsigned int keymap_qcode[Q_KEY_CODE_MAX] = {
> +[Q_KEY_CODE_ESC] = KEY_ESC,
> +[Q_KEY_CODE_1]   = KEY_1,
> +[Q_KEY_CODE_2]   = KEY_2,
> +[Q_KEY_CODE_3]   = KEY_3,
> +[Q_KEY_CODE_4]   = KEY_4,
> +[Q_KEY_CODE_5]   = KEY_5,
> +[Q_KEY_CODE_6]   = KEY_6,
> +[Q_KEY_CODE_7]   = KEY_7,
> +[Q_KEY_CODE_8]   = KEY_8,
> +[Q_KEY_CODE_9]   = KEY_9,
> +[Q_KEY_CODE_0]   = KEY_0,
> +[Q_KEY_CODE_MINUS]   = KEY_MINUS,
> +[Q_KEY_CODE_EQUAL]   = KEY_EQUAL,
> +[Q_KEY_CODE_BACKSPACE]   = KEY_BACKSPACE,
> +
> +[Q_KEY_CODE_TAB] = KEY_TAB,
> +[Q_KEY_CODE_Q]   = KEY_Q,
> +[Q_KEY_CODE_W]   = KEY_W,
> +[Q_KEY_CODE_E]   = KEY_E,
> +[Q_KEY_CODE_R]   = KEY_R,
> +[Q_KEY_CODE_T]   = KEY_T,
> +[Q_KEY_CODE_Y]   = KEY_Y,
> +[Q_KEY_CODE_U]   = KEY_U,
> +[Q_KEY_CODE_I]   = KEY_I,
> +[Q_KEY_CODE_O]   = KEY_O,
> +[Q_KEY_CODE_P]   = KEY_P,
> +[Q_KEY_CODE_BRACKET_LEFT]= KEY_LEFTBRACE,
> +[Q_KEY_CODE_BRACKET_RIGHT]   = KEY_RIGHTBRACE,
> +[Q_KEY_CODE_RET] = KEY_ENTER,
> +
> +[Q_KEY_CODE_CTRL]= KEY_LEFTCTRL,
> +[Q_KEY_CODE_A]   = KEY_A,
> +[Q_KEY_CODE_S]   = KEY_S,
> +[Q_KEY_CODE_D]   = KEY_D,
> +[Q_KEY_CODE_F]   = KEY_F,
> +[Q_KEY_CODE_G]   = KEY_G,
> +[Q_KEY_CODE_H]   = KEY_H,
> +[Q_KEY_CODE_J]   = KEY_J,
> +[Q_KEY_CODE_K]   = KEY_K,
> +[Q_KEY_CODE_L]   = KEY_L,
> +[Q_KEY_CODE_SEMICOLON]   = KEY_SEMICOLON,
> +[Q_KEY_CODE_APOSTROPHE]  = KEY_APOSTROPHE,
> +[Q_KEY_CODE_GRAVE_ACCENT]= KEY_GRAVE,
> +
> +[Q_KEY_CODE_SHIFT]   = KEY_LEFTSHIFT,
> +[Q_KEY_CODE_BACKSLASH]   = KEY_BACKSLASH,
> +[Q_KEY_CODE_LESS]= KEY_102ND,
> +[Q_KEY_CODE_Z]   = KEY_Z,
> +[Q_KEY_CODE_X]   = KEY_X,
> +[Q_KEY_CODE_C]   = KEY_C,
> +[Q_KEY_CODE_V]  

Re: [Qemu-devel] [PATCH qemu 6/6] virtio-input: evdev passthrough

2014-04-10 Thread Michael S. Tsirkin
On Thu, Apr 10, 2014 at 11:07:54AM +0200, Gerd Hoffmann wrote:
> This allows to assign host input devices to the guest:
> 
> qemu -device virto-input-host-pci,evdev=/dev/input/event
> 
> The guest gets exclusive access to the input device, so be careful
> with assigning the keyboard if you have only one connected to your
> machine.
> 
> Signed-off-by: Gerd Hoffmann 
> ---
>  hw/input/Makefile.objs   |   1 +
>  hw/input/virtio-input-host.c | 174 
> +++
>  hw/virtio/virtio-pci.c   |  31 +++
>  hw/virtio/virtio-pci.h   |  10 +++
>  include/hw/virtio/virtio-input.h |  13 +++
>  5 files changed, 229 insertions(+)
>  create mode 100644 hw/input/virtio-input-host.c
> 
> diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
> index 0179154..9461b37 100644
> --- a/hw/input/Makefile.objs
> +++ b/hw/input/Makefile.objs
> @@ -12,6 +12,7 @@ ifeq ($(CONFIG_LINUX),y)
>  common-obj-$(CONFIG_VIRTIO) += virtio-input.o
>  common-obj-$(CONFIG_VIRTIO) += virtio-input-hid.o
>  common-obj-$(CONFIG_VIRTIO) += virtio-input-control.o
> +common-obj-$(CONFIG_VIRTIO) += virtio-input-host.o
>  endif
>  
>  obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
> diff --git a/hw/input/virtio-input-host.c b/hw/input/virtio-input-host.c
> new file mode 100644
> index 000..663d967
> --- /dev/null
> +++ b/hw/input/virtio-input-host.c
> @@ -0,0 +1,174 @@
> +/*
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> + * (at your option) any later version.  See the COPYING file in the
> + * top-level directory.
> + */
> +
> +#include "qemu-common.h"
> +#include "qemu/sockets.h"
> +
> +#include "hw/qdev.h"
> +#include "hw/virtio/virtio.h"
> +#include "hw/virtio/virtio-input.h"
> +
> +#include "ui/console.h"
> +
> +#include 
> +
> +/* - */
> +
> +static struct virtio_input_config virtio_input_host_config[] = {
> +{ /* empty list */ },
> +};
> +
> +static void virtio_input_host_event(void *opaque)
> +{
> +VirtIOInputHost *vhost = opaque;

I'd prefer a name that does not imply
vhost infrastructure - which is an out of process QEMU backend
(kernel or another userspace process) accessing guest
memory directly.
This one is completely in-process.

> +VirtIOInput *vinput = VIRTIO_INPUT(vhost);
> +struct virtio_input_event virtio;
> +struct input_event evdev;
> +bool notify = false;
> +int rc;
> +
> +for (;;) {

You might want to limit this, requeue if there's
a storm of events.

> +rc = read(vhost->fd, &evdev, sizeof(evdev));
> +if (rc != sizeof(evdev)) {
> +break;
> +}
> +
> +virtio.type  = cpu_to_le16(evdev.type);
> +virtio.code  = cpu_to_le16(evdev.code);
> +virtio.value = cpu_to_le32(evdev.value);
> +virtio_input_send(vinput, &virtio);
> +
> +if (evdev.type == EV_SYN) {
> +notify = true;
> +}
> +}
> +
> +if (notify) {
> +virtio_notify(VIRTIO_DEVICE(vhost), vinput->evt);
> +}
> +}
> +
> +static void virtio_input_bits_config(VirtIOInputHost *vhost,
> + int type, int count)
> +{
> +virtio_input_config bits;
> +int rc, i, size = 0;
> +
> +memset(&bits, 0, sizeof(bits));
> +rc = ioctl(vhost->fd, EVIOCGBIT(type, count/8), bits.u.bitmap);
> +if (rc < 0) {
> +return;
> +}
> +
> +for (i = 0; i < count/8; i++) {
> +if (bits.u.bitmap[i]) {
> +size = i+1;
> +}
> +}
> +if (size == 0) {
> +return;
> +}
> +
> +bits.select = VIRTIO_INPUT_CFG_EV_BITS;
> +bits.subsel = type;
> +bits.size   = size;
> +virtio_input_add_config(VIRTIO_INPUT(vhost), &bits);
> +}
> +
> +static void virtio_input_host_realize(DeviceState *dev, Error **errp)
> +{
> +VirtIOInputHost *vhost = VIRTIO_INPUT_HOST(dev);
> +VirtIOInput *vinput = VIRTIO_INPUT(dev);
> +virtio_input_config id;
> +int rc, ver;
> +
> +if (!vhost->evdev) {
> +error_setg(errp, "evdev property is required");
> +return;
> +}
> +
> +vhost->fd = open(vhost->evdev, O_RDWR);
> +if (vhost->fd < 0)  {
> +error_setg_file_open(errp, errno, vhost->evdev);
> +return;
> +}
> +qemu_set_nonblock(vhost->fd);
> +
> +rc = ioctl(vhost->fd, EVIOCGVERSION, &ver);
> +if (rc < 0) {
> +error_setg(errp, "%s: is not an evdev device", vhost->evdev);
> +goto err_close;
> +}

Hmm is that all?
Don't we want to report versioning info to guests?


> +
> +rc = ioctl(vhost->fd, EVIOCGRAB, 1);
> +if (rc < 0) {
> +error_setg_errno(errp, errno, "%s: failed to get exclusive access",
> + vhost->evdev);
> +goto err_close;
> +}
> +
> +memset(&id, 0, sizeof(id));
> +ioctl(vhost->fd, EVIOCGNAME(sizeof(id.u.string)-1), id.u.string);
> +id.select = VIRTIO_INPUT_CFG_ID_NAME;
>

Re: [Qemu-devel] [PATCH qemu 3/6] virtio-input: core code & base class

2014-04-10 Thread Michael S. Tsirkin
On Thu, Apr 10, 2014 at 11:07:51AM +0200, Gerd Hoffmann wrote:
> This patch adds virtio-input support to qemu.  It brings a abstract
> base class providing core support, other classes can build on it to
> actually implement input devices.
> 
> virtio-input basically sends linux input layer events (evdev) over
> virtio.
> 
> Signed-off-by: Gerd Hoffmann 
> ---
>  hw/input/Makefile.objs   |   4 +
>  hw/input/virtio-input.c  | 253 
> +++
>  hw/virtio/virtio-pci.c   |  36 ++
>  hw/virtio/virtio-pci.h   |  14 +++
>  include/hw/virtio/virtio-input.h | 105 
>  include/hw/virtio/virtio.h   |   1 +
>  6 files changed, 413 insertions(+)
>  create mode 100644 hw/input/virtio-input.c
>  create mode 100644 include/hw/virtio/virtio-input.h
> 
> diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
> index e8c80b9..ee8bba9 100644
> --- a/hw/input/Makefile.objs
> +++ b/hw/input/Makefile.objs
> @@ -8,6 +8,10 @@ common-obj-$(CONFIG_STELLARIS_INPUT) += stellaris_input.o
>  common-obj-$(CONFIG_TSC2005) += tsc2005.o
>  common-obj-$(CONFIG_VMMOUSE) += vmmouse.o
>  
> +ifeq ($(CONFIG_LINUX),y)
> +common-obj-$(CONFIG_VIRTIO) += virtio-input.o
> +endif
> +
>  obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
>  obj-$(CONFIG_PXA2XX) += pxa2xx_keypad.o
>  obj-$(CONFIG_TSC210X) += tsc210x.o
> diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c
> new file mode 100644
> index 000..35f0cfc
> --- /dev/null
> +++ b/hw/input/virtio-input.c
> @@ -0,0 +1,253 @@
> +/*
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> + * (at your option) any later version.  See the COPYING file in the
> + * top-level directory.
> + */
> +
> +#include "qemu/iov.h"
> +
> +#include "hw/qdev.h"
> +#include "hw/virtio/virtio.h"
> +#include "hw/virtio/virtio-input.h"
> +
> +#include "ui/console.h"
> +
> +#include 
> +
> +/* - */
> +
> +void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event)
> +{
> +VirtQueueElement elem;
> +int len;
> +
> +if (!virtqueue_pop(vinput->evt, &elem)) {
> +fprintf(stderr, "%s: virtqueue empty, dropping event\n", __func__);
> +return;

Looks scary.

> +}
> +len = iov_from_buf(elem.in_sg, elem.in_num,
> +   0, event, sizeof(*event));
> +virtqueue_push(vinput->evt, &elem, len);
> +}
> +
> +static void virtio_input_handle_evt(VirtIODevice *vdev, VirtQueue *vq)
> +{
> +/* nothing */
> +}
> +
> +static void virtio_input_handle_sts(VirtIODevice *vdev, VirtQueue *vq)
> +{
> +VirtIOInputClass *vic = VIRTIO_INPUT_GET_CLASS(vdev);
> +VirtIOInput *vinput = VIRTIO_INPUT(vdev);
> +virtio_input_event event;
> +VirtQueueElement elem;
> +int len;
> +
> +while (virtqueue_pop(vinput->sts, &elem)) {
> +memset(&event, 0, sizeof(event));
> +len = iov_to_buf(elem.out_sg, elem.out_num,
> + 0, &event, sizeof(event));
> +if (vic->handle_status) {
> +vic->handle_status(vinput, &event);
> +}
> +virtqueue_push(vinput->sts, &elem, len);
> +}
> +virtio_notify(vdev, vinput->sts);
> +}
> +
> +static virtio_input_config *virtio_input_find_config(VirtIOInput *vinput,
> + uint8_t select,
> + uint8_t subsel)
> +{
> +VirtIOInputConfig *cfg;
> +
> +QTAILQ_FOREACH(cfg, &vinput->cfg_list, node) {
> +if (select == cfg->config.select &&
> +subsel == cfg->config.subsel) {
> +return &cfg->config;
> +}
> +}
> +return NULL;
> +}
> +
> +void virtio_input_add_config(VirtIOInput *vinput,
> + virtio_input_config *config)
> +{
> +VirtIOInputConfig *cfg;
> +
> +if (virtio_input_find_config(vinput, config->select, config->subsel)) {
> +/* should not happen */
> +fprintf(stderr, "%s: duplicate config: %d/%d\n",
> +__func__, config->select, config->subsel);
> +abort();
> +}
> +
> +cfg = g_new0(VirtIOInputConfig, 1);
> +cfg->config = *config;
> +QTAILQ_INSERT_TAIL(&vinput->cfg_list, cfg, node);
> +}
> +
> +void virtio_input_init_config(VirtIOInput *vinput,
> +  virtio_input_config *config)
> +{
> +int i = 0;
> +
> +QTAILQ_INIT(&vinput->cfg_list);
> +while (config[i].select) {
> +virtio_input_add_config(vinput, config + i);
> +i++;
> +}
> +}
> +
> +void virtio_input_idstr_config(VirtIOInput *vinput,
> +   uint8_t select, const char *string)
> +{
> +virtio_input_config id;
> +
> +if (!string) {
> +return;
> +}
> +memset(&id, 0, sizeof(id));
> +id.select = select;
> +id.size = snprintf(id.u.string, sizeof(id.u.string), "%s", string);
> +virtio_inpu

Re: [Qemu-devel] [PATCH v2 3/5] block: qemu-iotests - test for live migration

2014-04-10 Thread Jeff Cody
On Thu, Apr 10, 2014 at 02:16:46PM +0800, Fam Zheng wrote:
> On Wed, 04/09 22:41, Jeff Cody wrote:
> > This is an initial, simple live migration test from one
> > running VM to another, using monitor commands.
> > 
> > This is also an example on using the new common.qemu functions
> > for controlling multiple running qemu instances, for tests that
> > need a live qemu vm.
> > 
> > Signed-off-by: Jeff Cody 
> > ---
> >  tests/qemu-iotests/089 | 97 
> > ++
> >  tests/qemu-iotests/089.out | 20 ++
> 
> I used 089 in my last image fleecing series, (originally 083 but already 
> used).
> So one of us need to shift the case number.
>

I'll bump mine to 090, your series is more complicated and has been
around longer.

> 
> >  tests/qemu-iotests/group   |  1 +
> >  3 files changed, 118 insertions(+)
> >  create mode 100755 tests/qemu-iotests/089
> >  create mode 100644 tests/qemu-iotests/089.out
> > 
> > diff --git a/tests/qemu-iotests/089 b/tests/qemu-iotests/089
> > new file mode 100755
> > index 000..22a7cf1
> > --- /dev/null
> > +++ b/tests/qemu-iotests/089
> > @@ -0,0 +1,97 @@
> > +#!/bin/bash
> > +#
> > +# Live migration test
> > +#
> > +# Performs a migration from one VM to another via monitor commands
> > +#
> > +# Copyright (C) 2014 Red Hat, Inc.
> > +#
> > +# This program is free software; you can redistribute it and/or modify
> > +# it under the terms of the GNU General Public License as published by
> > +# the Free Software Foundation; either version 2 of the License, or
> > +# (at your option) any later version.
> > +#
> > +# This program is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public License
> > +# along with this program.  If not, see .
> > +#
> > +
> > +# creator
> > +owner=jc...@redhat.com
> > +
> > +seq=`basename $0`
> > +echo "QA output created by $seq"
> > +
> > +here=`pwd`
> > +status=1   # failure is the default!
> > +
> > +MIG_FIFO="${TEST_DIR}/migrate"
> > +
> > +_cleanup()
> > +{
> > +rm -f "${MIG_FIFO}"
> > +_cleanup_qemu
> > +   _cleanup_test_img
> > +
> > +}
> > +trap "_cleanup; exit \$status" 0 1 2 3 15
> > +
> > +# get standard environment, filters and checks
> > +. ./common.rc
> > +. ./common.filter
> > +. ./common.qemu
> > +
> > +_supported_fmt qcow2
> > +_supported_proto file
> > +_supported_os Linux
> > +
> > +size=1G
> > +
> > +IMGOPTS="cluster_size=512" _make_test_img $size
> > +
> > +mkfifo "${MIG_FIFO}"
> > +
> > +echo
> > +echo === Starting QEMU VM1 ===
> > +echo
> > +
> > +qemu_comm_method="monitor"
> > +_launch_qemu -drive file="${TEST_IMG}",cache=none,id=disk
> > +h1=$QEMU_HANDLE
> > +
> > +echo
> > +echo === Starting QEMU VM2 ===
> > +echo
> > +_launch_qemu -drive file="${TEST_IMG}",cache=none,id=disk \
> > + -incoming "exec: cat '${MIG_FIFO}'"
> > +h2=$QEMU_HANDLE
> > +
> > +echo
> > +echo === VM 1: Migrate from VM1 to VM2  ===
> > +echo
> > +
> > +silent=yes
> > +_send_qemu_cmd $h1 'qemu-io disk "write 0 4M"' "(qemu)"
> > +echo "vm1: qemu-io disk write complete"
> > +_send_qemu_cmd $h1 "migrate \"exec: cat > '${MIG_FIFO}'\"" "(qemu)"
> > +echo "vm1: live migration started"
> > +qemu_cmd_repeat=20 _send_qemu_cmd $h1 "info migrate" "completed"
> > +echo "vm1: live migration completed"
> > +
> > +echo
> > +echo === VM 2: Post-migration, write to disk, verify running ===
> > +echo
> > +
> > +_send_qemu_cmd $h2 'qemu-io disk "write 4M 1M"' "(qemu)"
> > +echo "vm2: qemu-io disk write complete"
> > +qemu_cmd_repeat=20 _send_qemu_cmd $h2 "info status" "running"
> > +echo "vm2: qemu process running successfully"
> > +
> > +
> > +echo "*** done"
> > +rm -f $seq.full
> > +status=0
> > diff --git a/tests/qemu-iotests/089.out b/tests/qemu-iotests/089.out
> > new file mode 100644
> > index 000..4e9e6c9
> > --- /dev/null
> > +++ b/tests/qemu-iotests/089.out
> > @@ -0,0 +1,20 @@
> > +QA output created by 089
> > +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 
> > +
> > +=== Starting QEMU VM1 ===
> > +
> > +
> > +=== Starting QEMU VM2 ===
> > +
> > +
> > +=== VM 1: Migrate from VM1 to VM2 ===
> > +
> > +vm1: qemu-io disk write complete
> > +vm1: live migration started
> > +vm1: live migration completed
> > +
> > +=== VM 2: Post-migration, write to disk, verify running ===
> > +
> > +vm2: qemu-io disk write complete
> > +vm2: qemu process running successfully
> > +*** done
> > diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
> > index 864643d..73e6b5d 100644
> > --- a/tests/qemu-iotests/group
> > +++ b/tests/qemu-iotests/group
> > @@ -95,3 +95,4 @@
> >  086 rw auto quick
> >  087 rw auto
> >  088 rw auto
> > +089 rw auto
> > -- 
> > 1.8.3.1
> > 
> > 



Re: [Qemu-devel] [PATCH] iscsi: Remember to set ret for iscsi_open in error case

2014-04-10 Thread Kevin Wolf
Am 10.04.2014 um 03:33 hat Fam Zheng geschrieben:
> Signed-off-by: Fam Zheng 

Thanks, applied to the block branch.

Kevin



[Qemu-devel] Should we have a 2.0-rc3 ?

2014-04-10 Thread Peter Maydell
So far I know of at least three fixes which should probably
go into 2.0:
 * my fix for the configure stack-protector checks on MacOSX
 * MST's pull request updating the ACPI test blobs
 * MST says we need to update the hex files for ACPI too
   (otherwise you get a different ACPI blob depending on whether
your build system had iasl or not, if I understand correctly)

Are there any others?

So we have two choices:

(A) get those fixes into git today, and tag an rc3; that
would then need some testing time and presumably we'd hope
to tag it as the 2.0 release on Monday or Tuesday next week

(B) say that the above are not worth fixing in 2.0 proper
and plan to do a 2.0.1 in a few weeks with the above plus
any other breakage that people find.

Opinions?

thanks
-- PMM



Re: [Qemu-devel] Error propagation in generated visitors and command marshallers

2014-04-10 Thread Kevin Wolf
Am 09.04.2014 um 17:48 hat Markus Armbruster geschrieben:
> I stumbled over this while trying to purge error_is_set() from the code.
> 
> 
> Here's how we commonly use the Error API:
> 
> Error *err = NULL;
> 
> foo(arg, &err)
> if (err) {
> goto out;
> }
> bar(arg, &err)
> if (err) {
> goto out;
> }
> 
> This ensures that err is null on entry, both for foo() and for bar().
> Many functions rely on that, like this:
> 
> void foo(ArgType arg, Error **errp)
> {
> if (frobnicate(arg) < 0) {
> error_setg(errp, "Can't frobnicate");
> // This asserts errp != NULL
> }
> }
> 
> 
> Here's how some of our visitor code uses the Error API (for real code,
> check out generated qmp-marshal.c):
> 
> Error *err = NULL;
> QmpInputVisitor *mi = qmp_input_visitor_new_strict(QOBJECT(args));
> Visitor *v = qmp_input_get_visitor(mi);
> char *foo = NULL;
> char *bar = NULL;
> 
> visit_type_str(v, &foo, "foo", &err);
> visit_type_str(v, &bar, "bar", &err);
> if (err) {
> goto out;
> }
> 
> Unlike above, this may pass a non-null errp to the second
> visit_type_str(), namely when the first one fails.
> 
> The visitor functions guard against that, like this:
> 
> void visit_type_str(Visitor *v, char **obj, const char *name, Error 
> **errp)
> {
> if (!error_is_set(errp)) {
> v->type_str(v, obj, name, errp);
> }
> }
> 
> As discussed before, error_is_set() is almost almost wrong, fragile or
> unclean.  What if errp is null?  Then we fail to stop visiting after an
> error.
> 
> The function could be improved like this:
> 
> void visit_type_str(Visitor *v, char **obj, const char *name, Error 
> **errp)
> {
> assert(errp);
> if (!*errp) {
> v->type_str(v, obj, name, errp);
> }
> }
> 
> 
> But: is it a good idea to have both patterns in the code?  Should we
> perhaps use the common pattern for visiting, too?  Like this:
> 
> visit_type_str(v, &foo, "foo", &err);
> if (err) {
> goto out;
> }
> visit_type_str(v, &bar, "bar", &err);
> if (err) {
> goto out;
> }
> 
> Then we can assume *errp is clear on function entry, like this:
> 
> void visit_type_str(Visitor *v, char **obj, const char *name, Error 
> **errp)
> {
> v->type_str(v, obj, name, errp);
> }
> 
> Should execute roughly the same number of conditional branches.
> 
> Tedious repetition of "if (err) goto out" in the caller, but that's what
> we do elsewhere, and unlike elsewhere, these one's are generated.
> 
> Opinions?

I agree, use the same style as everywhere else.

The pattern in the generated visitor that I find more annoying, though,
is that it has a lot of code like:

if (!error_is_set(errp)) {
/* long block of code here */
}

And I believe there are even cases where this nests. There are also
error_propagate() calls that can (and do in the common case) propagate
NULL, this way selecting the first error, if any, but not stopping on
the first error. I always found it confusing to read that code.

Kevin



Re: [Qemu-devel] Should we have a 2.0-rc3 ?

2014-04-10 Thread Alexander Graf


On 10.04.14 13:17, Peter Maydell wrote:

So far I know of at least three fixes which should probably
go into 2.0:
  * my fix for the configure stack-protector checks on MacOSX
  * MST's pull request updating the ACPI test blobs
  * MST says we need to update the hex files for ACPI too
(otherwise you get a different ACPI blob depending on whether
 your build system had iasl or not, if I understand correctly)

Are there any others?

So we have two choices:

(A) get those fixes into git today, and tag an rc3; that
would then need some testing time and presumably we'd hope
to tag it as the 2.0 release on Monday or Tuesday next week

(B) say that the above are not worth fixing in 2.0 proper
and plan to do a 2.0.1 in a few weeks with the above plus
any other breakage that people find.

Opinions?


I think the best way forward is to do both. Do an rc3 with _only_ those 
patches. Wait until Tuesday and do the final GA tag there.


Then schedule a 2.0.1 in a few weeks. There will be bug fixes.

And don't apply last-minute fixes from mst in the future :).


Alex




Re: [Qemu-devel] [PATCH qemu 5/6] virtio-input: control device

2014-04-10 Thread Michael S. Tsirkin
On Thu, Apr 10, 2014 at 11:07:53AM +0200, Gerd Hoffmann wrote:
> Device for sending non-input control messages to the guest.  For now
> this is only a single event: shutdown requests are sent as power button
> press to the guest.
> 
> Possible other use is signaling sound volume changes to the guest (via
> EV_ABS / ABS_VOLUME).  I expect we'll find more over time.
> 
> Signed-off-by: Gerd Hoffmann 

Why not use a keyboard device for this?

> ---
>  hw/input/Makefile.objs   |   1 +
>  hw/input/virtio-input-control.c  | 112 
> +++
>  hw/virtio/virtio-pci.c   |  29 ++
>  hw/virtio/virtio-pci.h   |  10 
>  include/hw/virtio/virtio-input.h |  12 +
>  5 files changed, 164 insertions(+)
>  create mode 100644 hw/input/virtio-input-control.c
> 
> diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
> index 0dae710..0179154 100644
> --- a/hw/input/Makefile.objs
> +++ b/hw/input/Makefile.objs
> @@ -11,6 +11,7 @@ common-obj-$(CONFIG_VMMOUSE) += vmmouse.o
>  ifeq ($(CONFIG_LINUX),y)
>  common-obj-$(CONFIG_VIRTIO) += virtio-input.o
>  common-obj-$(CONFIG_VIRTIO) += virtio-input-hid.o
> +common-obj-$(CONFIG_VIRTIO) += virtio-input-control.o
>  endif
>  
>  obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
> diff --git a/hw/input/virtio-input-control.c b/hw/input/virtio-input-control.c
> new file mode 100644
> index 000..3e439e6
> --- /dev/null
> +++ b/hw/input/virtio-input-control.c
> @@ -0,0 +1,112 @@
> +/*
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> + * (at your option) any later version.  See the COPYING file in the
> + * top-level directory.
> + */
> +
> +#include "qemu/iov.h"
> +
> +#include "hw/qdev.h"
> +#include "hw/virtio/virtio.h"
> +#include "hw/virtio/virtio-input.h"
> +
> +#include "ui/console.h"
> +
> +#include 
> +
> +#define VIRTIO_ID_NAME_CTRL "QEMU Virtio Control Panel"
> +
> +/* - */
> +
> +static void virtio_input_key_config(VirtIOInput *vinput)
> +{
> +static const int keylist[] = { KEY_POWER };
> +virtio_input_config keys;
> +int i, bit, byte, bmax = 0;
> +
> +memset(&keys, 0, sizeof(keys));
> +for (i = 0; i < ARRAY_SIZE(keylist); i++) {
> +byte = keylist[i] / 8;
> +bit  = keylist[i] % 8;
> +keys.u.bitmap[byte] |= (1 << bit);
> +if (bmax < byte+1) {
> +bmax = byte+1;
> +}
> +}
> +keys.select = VIRTIO_INPUT_CFG_EV_BITS;
> +keys.subsel = EV_KEY;
> +keys.size   = bmax;
> +virtio_input_add_config(vinput, &keys);
> +}
> +
> +static void virtio_input_ctrl_keypress(VirtIOInput *vinput, int keycode)
> +{
> +virtio_input_event key_down = {
> +.type  = cpu_to_le16(EV_KEY),
> +.code  = cpu_to_le16(keycode),
> +.value = 1,
> +};
> +virtio_input_event key_up = {
> +.type  = cpu_to_le16(EV_KEY),
> +.code  = cpu_to_le16(keycode),
> +.value = 0,
> +};
> +virtio_input_event sync = {
> +.type  = cpu_to_le16(EV_SYN),
> +.code  = cpu_to_le16(SYN_REPORT),
> +.value = 0,
> +};
> +
> +virtio_input_send(vinput, &key_down);
> +virtio_input_send(vinput, &sync);
> +virtio_input_send(vinput, &key_up);
> +virtio_input_send(vinput, &sync);
> +virtio_notify(VIRTIO_DEVICE(vinput), vinput->evt);
> +}
> +
> +static void virtio_input_ctrl_powerdown(Notifier *n, void *opaque)
> +{
> +VirtIOInputCtrl *vctrl =
> +container_of(n, VirtIOInputCtrl, powerdown);
> +
> +virtio_input_ctrl_keypress(VIRTIO_INPUT(vctrl), KEY_POWER);
> +}
> +
> +/* - */
> +
> +static struct virtio_input_config virtio_ctrl_config[] = {
> +{
> +.select= VIRTIO_INPUT_CFG_ID_NAME,
> +.size  = sizeof(VIRTIO_ID_NAME_CTRL),
> +.u.string  = VIRTIO_ID_NAME_CTRL,
> +},
> +{ /* end of list */ },
> +};
> +
> +static void virtio_ctrl_init(Object *obj)
> +{
> +VirtIOInput *vinput = VIRTIO_INPUT(obj);
> +VirtIOInputCtrl *vctrl = VIRTIO_INPUT_CTRL(obj);
> +
> +virtio_input_init_config(vinput, virtio_ctrl_config);
> +virtio_input_key_config(vinput);
> +
> +vctrl->powerdown.notify = virtio_input_ctrl_powerdown;
> +qemu_register_powerdown_notifier(&vctrl->powerdown);
> +}
> +
> +static const TypeInfo virtio_ctrl_info = {
> +.name  = TYPE_VIRTIO_INPUT_CTRL,
> +.parent= TYPE_VIRTIO_INPUT,
> +.instance_size = sizeof(VirtIOInputCtrl),
> +.instance_init = virtio_ctrl_init,
> +};
> +
> +/* - */
> +
> +static void virtio_register_types(void)
> +{
> +type_register_static(&virtio_ctrl_info);
> +}
> +
> +type_init(virtio_register_types)
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index b421c01..9446d45 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/

[Qemu-devel] [PATCH] qemu-char: Allow a chardev to reconnect if disconnected

2014-04-10 Thread arei.gonglei
From: Huangweidong 

Allow a socket chardev reconnect if the connection drops while in use.

Signed-off-by: Huangweidong 
Signed-off-by: Gonglei 
---
This patch is modified according to corey's patch. Some changes below:
1. IMO it's unnecessary that chardev reconnect if it fails to connect at 
startup.
Qemu exit in this scene. In this way the patch does not change interface of 
chardev.
It would be much more simple.
2. I set the reconnect timer one second, just like pty.

 include/sysemu/char.h |  2 ++
 qemu-char.c   | 50 ++
 2 files changed, 52 insertions(+)

diff --git a/include/sysemu/char.h b/include/sysemu/char.h
index b81a6ff..f646ac8 100644
--- a/include/sysemu/char.h
+++ b/include/sysemu/char.h
@@ -19,6 +19,7 @@
 #define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */
 #define CHR_EVENT_CLOSED  5 /* connection closed */
 
+#define CHR_SOCK_RECONNECT_TIME 1 /* reconnection time (second) */
 
 #define CHR_IOCTL_SERIAL_SET_PARAMS   1
 typedef struct {
@@ -82,6 +83,7 @@ struct CharDriverState {
 guint fd_in_tag;
 QemuOpts *opts;
 QTAILQ_ENTRY(CharDriverState) next;
+QEMUTimer *recon_timer;
 };
 
 /**
diff --git a/qemu-char.c b/qemu-char.c
index 54ed244..a87a345 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -96,9 +96,17 @@ void qemu_chr_be_event(CharDriverState *s, int event)
 /* Keep track if the char device is open */
 switch (event) {
 case CHR_EVENT_OPENED:
+if (s->recon_timer) {
+timer_del(s->recon_timer);
+}
 s->be_open = 1;
 break;
 case CHR_EVENT_CLOSED:
+if (s->recon_timer) {
+timer_mod(s->recon_timer,
+(get_clock() +
+ (CHR_SOCK_RECONNECT_TIME * get_ticks_per_sec(;
+}
 s->be_open = 0;
 break;
 }
@@ -2619,6 +2627,43 @@ static void tcp_chr_close(CharDriverState *chr)
 qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
 }
 
+static void recon_timeout(void *opaque)
+{
+CharDriverState *chr = opaque;
+QemuOpts *opts = chr->opts;
+TCPCharDriver *tcp = (TCPCharDriver *)chr->opaque;
+int fd = -1;
+Error *local_err = NULL;
+
+if (chr->be_open) {
+return;
+}
+
+if (tcp->is_unix) {
+fd = unix_connect_opts(opts, &local_err, NULL, NULL);
+} else {
+fd = inet_connect_opts(opts, &local_err, NULL, NULL);
+}
+
+if (fd < 0) {
+goto fail;
+}
+
+tcp->fd = fd;
+socket_set_nodelay(fd);
+tcp->chan = io_channel_from_socket(tcp->fd);
+tcp_chr_connect(chr);
+printf("chardev: socket reconnect sucess\n");
+return;
+
+fail:
+if (local_err) {
+qerror_report_err(local_err);
+error_free(local_err);
+}
+qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
+}
+
 static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay,
 bool is_listen, bool is_telnet,
 bool is_waitconnect,
@@ -2693,6 +2738,11 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, 
bool do_nodelay,
 socket_set_nodelay(fd);
 s->chan = io_channel_from_socket(s->fd);
 tcp_chr_connect(chr);
+chr->recon_timer = timer_new(QEMU_CLOCK_REALTIME, SCALE_NS,
+ recon_timeout, chr);
+timer_mod(chr->recon_timer,
+   (get_clock() +
+(CHR_SOCK_RECONNECT_TIME * get_ticks_per_sec(;
 }
 
 if (is_listen && is_waitconnect) {
-- 
1.7.12.4





Re: [Qemu-devel] [PATCH qemu 4/6] virtio-input: emulated devices

2014-04-10 Thread Gerd Hoffmann
On Do, 2014-04-10 at 13:55 +0300, Michael S. Tsirkin wrote:
> On Thu, Apr 10, 2014 at 11:07:52AM +0200, Gerd Hoffmann wrote:
> > This patch adds the virtio-input-hid base class and
> > virtio-{keyboard,mouse,tablet} subclasses building on the base class.
> > They are hooked up to the qemu input core and deliver input events
> > to the guest like all other hid devices (ps/2 kbd, usb tablet, ...).
> > 
> > Using them is as simple as adding "-device virtio-tablet-pci" to your
> > command line.  If you want add multiple devices but don't want waste
> > a pci slot for each you can compose a multifunction device this way:
> > 
> > qemu -device virtio-keyboard-pci,addr=0d.0,multifunction=on \
> >  -device virtio-tablet-pci,addr=0d.1,multifunction=on
> > 
> > Signed-off-by: Gerd Hoffmann 
> 
> Hmm - that's interesting.
> I was under the impression that a single pci function can be
> a keyboard, mouse and tablet at the same time.

It is possible to create a device supporting both keyboard and
mouse/tablet events.  Which will also show up as single input device in
the guest then.  People and software tends to not expect that though, so
I think it is better to keep them separate.

> If they aren't why don't we assign distinct device IDs to them
> after all?

pci device ids I assume?  Sure, we can do that.  Will make lspci output
a bit more informative (no need to check /proc/bus/input/devices to
figure what kind of input device it is).

> > +[Q_KEY_CODE_META_L]  = KEY_LEFTMETA,
> > +[Q_KEY_CODE_META_R]  = KEY_RIGHTMETA,
> > +[Q_KEY_CODE_MENU]= KEY_MENU,
> > +};
> 
> OK these are values send to guest, right?

Yes.

> And they are from linux/input.h, right? But are these
> reasonable in a cross-platform device?

Can't see strong reasons speaking against it.  It's kernel/userspace
API, therefore stable.  There are keycodes defined for pretty much
anything you can think of.

linux guest code is dead simple.  For other guests supporting it
shouldn't be that hard too, they basically need a mapping table to map
the linux KEY_* codes into their internal representation.

> E.g. Linux is pretty good at backwards compatibility
> but less good at versioning.

--verbose please.

> That header says "Most of the keys/buttons are modeled after USB HUT
> 1.12" but as far as I could see the codes are not from HUT, correct?

No, the codes are different.

> Would it be a good idea to use codes from HUT directly?
> This way we could extend functionality without adding lots of
> text to the spec, simply by referring to HUT.

I want to simply refer to linux/input.h in the spec.

> Also what defines the subset selected?

All keys in linux/input.h are supported by the virtio input protocol.

The current qemu kbd emulation covers all keys qemu knows (see QKeyCode
in qapi-schema.json).

> > +static const unsigned int axismap_abs[INPUT_AXIS_MAX] = {
> > +[INPUT_AXIS_X]   = ABS_X,
> > +[INPUT_AXIS_Y]   = ABS_Y,
> > +};
> > +
> 
> In the future, it seems like a good idea to report raw
> multi-touch events to guests - this would need a different
> interface along the lines of
> Documentation/input/multi-touch-protocol.txt

Should be no big deal.  Not looked at that deeply yet due to lack of
test hardware, but I think all we need is mapping the info from
EVIOCGMTSLOTS into config space, simliar to how it is done for
EVIOCGABS.

> Do MT devices generate ST events as well so it's ok to just
> filter out everything we don't recognize?

Yes, as far I know both mt and st events are generated.

> > +static void virtio_input_hid_handle_status(VirtIOInput *vinput,
> > +   virtio_input_event *event)
> > +{
> > +VirtIOInputHID *vhid = VIRTIO_INPUT_HID(vinput);
> > +int ledbit = 0;
> > +
> > +switch (le16_to_cpu(event->type)) {
> > +case EV_LED:
> > +if (event->code == LED_NUML) {
> > +ledbit = QEMU_NUM_LOCK_LED;
> > +} else if (event->code == LED_CAPSL) {
> > +ledbit = QEMU_CAPS_LOCK_LED;
> > +} else if (event->code == LED_SCROLLL) {
> > +ledbit = QEMU_SCROLL_LOCK_LED;
> > +}
> > +if (event->value) {
> > +vhid->ledstate |= ledbit;
> > +} else {
> > +vhid->ledstate &= ~ledbit;
> > +}
> > +kbd_put_ledstate(vhid->ledstate);
> 
> What does this do? notice led light up on one keyboard and propagate
> state to all keyboards?

Notify everybody interested in about kbd led changes.  ps/2+usb kbd
emulations do the same.

It is used by vnc for example, to make sure capslock/numlock state
between guest and host stay in sync.

cheers,
  Gerd





[Qemu-devel] [RFC PATCH V3 1/7] linux-headers: Update KVM headers from v3.15

2014-04-10 Thread Pranavkumar Sawargaonkar
Syncup KVM related linux headers from v3.15.

Signed-off-by: Pranavkumar Sawargaonkar 
Signed-off-by: Anup Patel 
---
 linux-headers/asm-arm/kvm.h   |   19 +-
 linux-headers/asm-arm64/kvm.h |   21 +--
 linux-headers/linux/kvm.h |   10 ++
 linux-headers/linux/psci.h|   77 +
 4 files changed, 108 insertions(+), 19 deletions(-)
 create mode 100644 linux-headers/linux/psci.h

diff --git a/linux-headers/asm-arm/kvm.h b/linux-headers/asm-arm/kvm.h
index ef0c878..6574ddf 100644
--- a/linux-headers/asm-arm/kvm.h
+++ b/linux-headers/asm-arm/kvm.h
@@ -20,6 +20,7 @@
 #define __ARM_KVM_H__
 
 #include 
+#include 
 #include 
 
 #define __KVM_HAVE_GUEST_DEBUG
@@ -83,6 +84,7 @@ struct kvm_regs {
 #define KVM_VGIC_V2_CPU_SIZE   0x2000
 
 #define KVM_ARM_VCPU_POWER_OFF 0 /* CPU is started in OFF state */
+#define KVM_ARM_VCPU_PSCI_0_2  1 /* CPU uses PSCI v0.2 */
 
 struct kvm_vcpu_init {
__u32 target;
@@ -194,16 +196,15 @@ struct kvm_arch_memory_slot {
 
 /* PSCI interface */
 #define KVM_PSCI_FN_BASE   0x95c1ba5e
-#define KVM_PSCI_FN(n) (KVM_PSCI_FN_BASE + (n))
 
-#define KVM_PSCI_FN_CPU_SUSPENDKVM_PSCI_FN(0)
-#define KVM_PSCI_FN_CPU_OFFKVM_PSCI_FN(1)
-#define KVM_PSCI_FN_CPU_ON KVM_PSCI_FN(2)
-#define KVM_PSCI_FN_MIGRATEKVM_PSCI_FN(3)
+#define KVM_PSCI_FN_CPU_SUSPENDPSCI_FN(KVM_PSCI_FN_BASE, 0)
+#define KVM_PSCI_FN_CPU_OFFPSCI_FN(KVM_PSCI_FN_BASE, 1)
+#define KVM_PSCI_FN_CPU_ON PSCI_FN(KVM_PSCI_FN_BASE, 2)
+#define KVM_PSCI_FN_MIGRATEPSCI_FN(KVM_PSCI_FN_BASE, 3)
 
-#define KVM_PSCI_RET_SUCCESS   0
-#define KVM_PSCI_RET_NI((unsigned long)-1)
-#define KVM_PSCI_RET_INVAL ((unsigned long)-2)
-#define KVM_PSCI_RET_DENIED((unsigned long)-3)
+#define KVM_PSCI_RET_SUCCESS   PSCI_RET_SUCCESS
+#define KVM_PSCI_RET_NIPSCI_RET_NOT_SUPPORTED
+#define KVM_PSCI_RET_INVAL PSCI_RET_INVALID_PARAMS
+#define KVM_PSCI_RET_DENIEDPSCI_RET_DENIED
 
 #endif /* __ARM_KVM_H__ */
diff --git a/linux-headers/asm-arm64/kvm.h b/linux-headers/asm-arm64/kvm.h
index eaf54a3..9b67161 100644
--- a/linux-headers/asm-arm64/kvm.h
+++ b/linux-headers/asm-arm64/kvm.h
@@ -31,6 +31,7 @@
 #define KVM_NR_SPSR5
 
 #ifndef __ASSEMBLY__
+#include 
 #include 
 #include 
 
@@ -77,6 +78,7 @@ struct kvm_regs {
 
 #define KVM_ARM_VCPU_POWER_OFF 0 /* CPU is started in OFF state */
 #define KVM_ARM_VCPU_EL1_32BIT 1 /* CPU running a 32bit VM */
+#define KVM_ARM_VCPU_PSCI_0_2  2 /* CPU uses PSCI v0.2 */
 
 struct kvm_vcpu_init {
__u32 target;
@@ -177,19 +179,18 @@ struct kvm_arch_memory_slot {
 /* Highest supported SPI, from VGIC_NR_IRQS */
 #define KVM_ARM_IRQ_GIC_MAX127
 
-/* PSCI interface */
+/* PSCI v0.1 interface */
 #define KVM_PSCI_FN_BASE   0x95c1ba5e
-#define KVM_PSCI_FN(n) (KVM_PSCI_FN_BASE + (n))
 
-#define KVM_PSCI_FN_CPU_SUSPENDKVM_PSCI_FN(0)
-#define KVM_PSCI_FN_CPU_OFFKVM_PSCI_FN(1)
-#define KVM_PSCI_FN_CPU_ON KVM_PSCI_FN(2)
-#define KVM_PSCI_FN_MIGRATEKVM_PSCI_FN(3)
+#define KVM_PSCI_FN_CPU_SUSPENDPSCI_FN(KVM_PSCI_FN_BASE, 0)
+#define KVM_PSCI_FN_CPU_OFFPSCI_FN(KVM_PSCI_FN_BASE, 1)
+#define KVM_PSCI_FN_CPU_ON PSCI_FN(KVM_PSCI_FN_BASE, 2)
+#define KVM_PSCI_FN_MIGRATEPSCI_FN(KVM_PSCI_FN_BASE, 3)
 
-#define KVM_PSCI_RET_SUCCESS   0
-#define KVM_PSCI_RET_NI((unsigned long)-1)
-#define KVM_PSCI_RET_INVAL ((unsigned long)-2)
-#define KVM_PSCI_RET_DENIED((unsigned long)-3)
+#define KVM_PSCI_RET_SUCCESS   PSCI_RET_SUCCESS
+#define KVM_PSCI_RET_NIPSCI_RET_NOT_SUPPORTED
+#define KVM_PSCI_RET_INVAL PSCI_RET_INVALID_PARAMS
+#define KVM_PSCI_RET_DENIEDPSCI_RET_DENIED
 
 #endif
 
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index e27a4b3..fa4a2f7 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -171,6 +171,7 @@ struct kvm_pit_config {
 #define KVM_EXIT_WATCHDOG 21
 #define KVM_EXIT_S390_TSCH22
 #define KVM_EXIT_EPR  23
+#define KVM_EXIT_SYSTEM_EVENT 24
 
 /* For KVM_EXIT_INTERNAL_ERROR */
 /* Emulate instruction failed. */
@@ -301,6 +302,13 @@ struct kvm_run {
struct {
__u32 epr;
} epr;
+   /* KVM_EXIT_SYSTEM_EVENT */
+   struct {
+#define KVM_SYSTEM_EVENT_SHUTDOWN   1
+#define KVM_SYSTEM_EVENT_RESET  2
+   __u32 type;
+   __u64 flags;
+   } system_event;
/* Fix the size of the union. */
char padding[

[Qemu-devel] [RFC PATCH V3 2/7] kvm: Handle exit reason KVM_EXIT_SYSTEM_EVENT

2014-04-10 Thread Pranavkumar Sawargaonkar
In-kernel PSCI v0.2 emulation of KVM ARM/ARM64 forwards SYSTEM_OFF
and SYSTEM_RESET function calls to QEMU using KVM_EXIT_SYSTEM_EVENT
exit reason.

This patch updates kvm_cpu_exec() to handle KVM_SYSTEM_EVENT_SHUTDOWN
and KVM_SYSTEM_EVENT_RESET system-level events from QEMU-side.

Signed-off-by: Pranavkumar Sawargaonkar 
Signed-off-by: Anup Patel 
---
 kvm-all.c |   16 
 1 file changed, 16 insertions(+)

diff --git a/kvm-all.c b/kvm-all.c
index cd4111d..53edbc9 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1724,6 +1724,22 @@ int kvm_cpu_exec(CPUState *cpu)
 case KVM_EXIT_INTERNAL_ERROR:
 ret = kvm_handle_internal_error(cpu, run);
 break;
+case KVM_EXIT_SYSTEM_EVENT:
+switch (run->system_event.type) {
+case KVM_SYSTEM_EVENT_SHUTDOWN:
+qemu_system_shutdown_request();
+ret = EXCP_INTERRUPT;
+break;
+case KVM_SYSTEM_EVENT_RESET:
+qemu_system_reset_request();
+ret = EXCP_INTERRUPT;
+break;
+default:
+DPRINTF("kvm_arch_handle_exit\n");
+ret = kvm_arch_handle_exit(cpu, run);
+break;
+}
+break;
 default:
 DPRINTF("kvm_arch_handle_exit\n");
 ret = kvm_arch_handle_exit(cpu, run);
-- 
1.7.9.5




[Qemu-devel] [RFC PATCH V3 3/7] target-arm: Enable KVM_ARM_VCPU_PSCI_0_2 feature when possible

2014-04-10 Thread Pranavkumar Sawargaonkar
Latest linux kernel supports in-kernel emulation of PSCI v0.2 but
to enable it we need to select KVM_ARM_VCPU_PSCI_0_2 feature using
KVM_ARM_VCPU_INIT ioctl.

Also, we can use KVM_ARM_VCPU_PSCI_0_2 feature for VCPU only when
linux kernel has KVM_CAP_ARM_PSCI_0_2 capability.

This patch updates kvm_arch_init_vcpu() to enable KVM_ARM_VCPU_PSCI_0_2
feature for VCPU when KVM ARM/ARM64 has KVM_CAP_ARM_PSCI_0_2 capability.

Signed-off-by: Pranavkumar Sawargaonkar 
Signed-off-by: Anup Patel 
---
 target-arm/kvm32.c |5 -
 target-arm/kvm64.c |5 -
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/target-arm/kvm32.c b/target-arm/kvm32.c
index a4fde07..afeff01 100644
--- a/target-arm/kvm32.c
+++ b/target-arm/kvm32.c
@@ -181,7 +181,10 @@ int kvm_arch_init_vcpu(CPUState *cs)
 init.target = cpu->kvm_target;
 memset(init.features, 0, sizeof(init.features));
 if (cpu->start_powered_off) {
-init.features[0] = 1 << KVM_ARM_VCPU_POWER_OFF;
+init.features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
+}
+if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
+init.features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
 }
 ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
 if (ret) {
diff --git a/target-arm/kvm64.c b/target-arm/kvm64.c
index 1b7ca90..02bba45 100644
--- a/target-arm/kvm64.c
+++ b/target-arm/kvm64.c
@@ -90,7 +90,10 @@ int kvm_arch_init_vcpu(CPUState *cs)
 init.target = cpu->kvm_target;
 memset(init.features, 0, sizeof(init.features));
 if (cpu->start_powered_off) {
-init.features[0] = 1 << KVM_ARM_VCPU_POWER_OFF;
+init.features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
+}
+if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
+init.features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
 }
 ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
 
-- 
1.7.9.5




[Qemu-devel] [RFC PATCH V3 0/7] PSCI v0.2 support for KVM ARM/ARM64

2014-04-10 Thread Pranavkumar Sawargaonkar
Recentely patches have been posted for in-kernel emulation of PSCI v0.2
http://www.spinics.net/lists/arm-kernel/msg305467.html
This patchset adds the QEMU side changes for providing PSCI v0.2 to VM.

ChangeLog:

V3: 
 - Rebase this patchset against v8 patchset for in-kernel PSCI v0.2 emulation
   (http://www.spinics.net/lists/kvm-arm/msg08780.html)
 - Added common kvm_arm_vcpu_init() function for kvm arm and kvm arm64

V2:
 - Rebase this patchset against v6 patchset for in-kernel PSCI v0.2 emulation
   (http://www.spinics.net/lists/arm-kernel/msg319037.html)
 - Handle KVM_EXIT_SYSTEM_EVENT in kvm-all.c:kvm_cpu_exec()
 - Drop change in kvm_arm_get_host_cpu_features()
 - Improve comments and description of kvm_arch_reset_vcpu() implementation

V1:
 - Initial RFC patchset

Pranavkumar Sawargaonkar (7):
  linux-headers: Update KVM headers from v3.15
  kvm: Handle exit reason KVM_EXIT_SYSTEM_EVENT
  target-arm: Enable KVM_ARM_VCPU_PSCI_0_2 feature when possible
  target-arm: Provide PSCI v0.2 constants to generic QEMU code
  hw/arm/virt: Use PSCI v0.2 function IDs when kernel supports it
  target-arm: Common kvm_arm_vcpu_init() for KVM ARM and KVM ARM64
  target-arm: Implement kvm_arch_reset_vcpu() for KVM ARM64

 hw/arm/virt.c |   28 ---
 kvm-all.c |   16 +
 linux-headers/asm-arm/kvm.h   |   19 +-
 linux-headers/asm-arm64/kvm.h |   21 +--
 linux-headers/linux/kvm.h |   10 ++
 linux-headers/linux/psci.h|   77 +
 target-arm/kvm-consts.h   |   63 +++--
 target-arm/kvm.c  |   23 
 target-arm/kvm32.c|   15 ++--
 target-arm/kvm64.c|   23 ++--
 target-arm/kvm_arm.h  |   14 
 11 files changed, 251 insertions(+), 58 deletions(-)
 create mode 100644 linux-headers/linux/psci.h

-- 
1.7.9.5




[Qemu-devel] [RFC PATCH V3 4/7] target-arm: Provide PSCI v0.2 constants to generic QEMU code

2014-04-10 Thread Pranavkumar Sawargaonkar
Provide QEMU PSCI v0.2 constants for non-KVM code; this will
allow us to avoid an #ifdef in boards which set up a PSCI v0.2
node in the device tree.

Signed-off-by: Pranavkumar Sawargaonkar 
Signed-off-by: Anup Patel 
---
 target-arm/kvm-consts.h |   63 ++-
 1 file changed, 52 insertions(+), 11 deletions(-)

diff --git a/target-arm/kvm-consts.h b/target-arm/kvm-consts.h
index 6009a33..5cf93ab 100644
--- a/target-arm/kvm-consts.h
+++ b/target-arm/kvm-consts.h
@@ -38,17 +38,58 @@ MISMATCH_CHECK(CP_REG_SIZE_U64, KVM_REG_SIZE_U64)
 MISMATCH_CHECK(CP_REG_ARM, KVM_REG_ARM)
 MISMATCH_CHECK(CP_REG_ARCH_MASK, KVM_REG_ARCH_MASK)
 
-#define PSCI_FN_BASE 0x95c1ba5e
-#define PSCI_FN(n) (PSCI_FN_BASE + (n))
-#define PSCI_FN_CPU_SUSPEND PSCI_FN(0)
-#define PSCI_FN_CPU_OFF PSCI_FN(1)
-#define PSCI_FN_CPU_ON PSCI_FN(2)
-#define PSCI_FN_MIGRATE PSCI_FN(3)
-
-MISMATCH_CHECK(PSCI_FN_CPU_SUSPEND, KVM_PSCI_FN_CPU_SUSPEND)
-MISMATCH_CHECK(PSCI_FN_CPU_OFF, KVM_PSCI_FN_CPU_OFF)
-MISMATCH_CHECK(PSCI_FN_CPU_ON, KVM_PSCI_FN_CPU_ON)
-MISMATCH_CHECK(PSCI_FN_MIGRATE, KVM_PSCI_FN_MIGRATE)
+/* PSCI v0.1 interface */
+#define QEMU_PSCI_FN_BASE 0x95c1ba5e
+#define QEMU_PSCI_FN(n) (QEMU_PSCI_FN_BASE + (n))
+#define QEMU_PSCI_FN_CPU_SUSPEND QEMU_PSCI_FN(0)
+#define QEMU_PSCI_FN_CPU_OFF QEMU_PSCI_FN(1)
+#define QEMU_PSCI_FN_CPU_ON QEMU_PSCI_FN(2)
+#define QEMU_PSCI_FN_MIGRATE QEMU_PSCI_FN(3)
+
+MISMATCH_CHECK(QEMU_PSCI_FN_CPU_SUSPEND, KVM_PSCI_FN_CPU_SUSPEND)
+MISMATCH_CHECK(QEMU_PSCI_FN_CPU_OFF, KVM_PSCI_FN_CPU_OFF)
+MISMATCH_CHECK(QEMU_PSCI_FN_CPU_ON, KVM_PSCI_FN_CPU_ON)
+MISMATCH_CHECK(QEMU_PSCI_FN_MIGRATE, KVM_PSCI_FN_MIGRATE)
+
+/* PSCI v0.2 interface */
+#define QEMU_PSCI_0_2_FN_BASE 0x8400
+#define QEMU_PSCI_0_2_FN(n) (QEMU_PSCI_0_2_FN_BASE + (n))
+#define QEMU_PSCI_0_2_FN64_BASE 0xC400
+#define QEMU_PSCI_0_2_FN64(n) (QEMU_PSCI_0_2_FN64_BASE + (n))
+#define QEMU_PSCI_0_2_FN_PSCI_VERSION QEMU_PSCI_0_2_FN(0)
+#define QEMU_PSCI_0_2_FN_CPU_SUSPEND QEMU_PSCI_0_2_FN(1)
+#define QEMU_PSCI_0_2_FN_CPU_OFF QEMU_PSCI_0_2_FN(2)
+#define QEMU_PSCI_0_2_FN_CPU_ON QEMU_PSCI_0_2_FN(3)
+#define QEMU_PSCI_0_2_FN_AFFINITY_INFO QEMU_PSCI_0_2_FN(4)
+#define QEMU_PSCI_0_2_FN_MIGRATE QEMU_PSCI_0_2_FN(5)
+#define QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE QEMU_PSCI_0_2_FN(6)
+#define QEMU_PSCI_0_2_FN_MIGRATE_INFO_UP_CPU QEMU_PSCI_0_2_FN(7)
+#define QEMU_PSCI_0_2_FN_SYSTEM_OFF QEMU_PSCI_0_2_FN(8)
+#define QEMU_PSCI_0_2_FN_SYSTEM_RESET QEMU_PSCI_0_2_FN(9)
+#define QEMU_PSCI_0_2_FN64_CPU_SUSPEND QEMU_PSCI_0_2_FN64(1)
+#define QEMU_PSCI_0_2_FN64_CPU_ON QEMU_PSCI_0_2_FN64(3)
+#define QEMU_PSCI_0_2_FN64_AFFINITY_INFO QEMU_PSCI_0_2_FN64(4)
+#define QEMU_PSCI_0_2_FN64_MIGRATE QEMU_PSCI_0_2_FN64(5)
+#define QEMU_PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU QEMU_PSCI_0_2_FN64(7)
+
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN_PSCI_VERSION, PSCI_0_2_FN_PSCI_VERSION)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN_CPU_SUSPEND, PSCI_0_2_FN_CPU_SUSPEND)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN_CPU_OFF, PSCI_0_2_FN_CPU_OFF)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN_CPU_ON, PSCI_0_2_FN_CPU_ON)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN_AFFINITY_INFO, PSCI_0_2_FN_AFFINITY_INFO)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN_MIGRATE, PSCI_0_2_FN_MIGRATE)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE, \
+   PSCI_0_2_FN_MIGRATE_INFO_TYPE)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN_MIGRATE_INFO_UP_CPU, \
+   PSCI_0_2_FN_MIGRATE_INFO_UP_CPU)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN_SYSTEM_OFF, PSCI_0_2_FN_SYSTEM_OFF)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN_SYSTEM_RESET, PSCI_0_2_FN_SYSTEM_RESET)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_SUSPEND, PSCI_0_2_FN64_CPU_SUSPEND)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_ON, PSCI_0_2_FN64_CPU_ON)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_AFFINITY_INFO, PSCI_0_2_FN64_AFFINITY_INFO)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_MIGRATE, PSCI_0_2_FN64_MIGRATE)
+MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU, \
+   PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU)
 
 /* Note that KVM uses overlapping values for AArch32 and AArch64
  * target CPU numbers. AArch32 targets:
-- 
1.7.9.5




[Qemu-devel] [RFC PATCH V3 5/7] hw/arm/virt: Use PSCI v0.2 function IDs when kernel supports it

2014-04-10 Thread Pranavkumar Sawargaonkar
If we have in-kernel emulation of PSCI v0.2 for KVM ARM/ARM64 then
we enable PSCI v0.2 for each VCPU at the time of VCPU init hence we
need to provide PSCI v0.2 function IDs via generated DTB.

This patch updates generated DTB to have PSCI v0.2 function IDs when
we have in-kernel emulation PSCI v0.2 for KVM ARM/ARM64.

Signed-off-by: Pranavkumar Sawargaonkar 
Signed-off-by: Anup Patel 
---
 hw/arm/virt.c |   28 +++-
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 2bbc931..cf6a774 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -187,11 +187,29 @@ static void create_fdt(VirtBoardInfo *vbi)
 qemu_fdt_add_subnode(fdt, "/psci");
 qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci");
 qemu_fdt_setprop_string(fdt, "/psci", "method", "hvc");
-qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend",
-  PSCI_FN_CPU_SUSPEND);
-qemu_fdt_setprop_cell(fdt, "/psci", "cpu_off", PSCI_FN_CPU_OFF);
-qemu_fdt_setprop_cell(fdt, "/psci", "cpu_on", PSCI_FN_CPU_ON);
-qemu_fdt_setprop_cell(fdt, "/psci", "migrate", PSCI_FN_MIGRATE);
+if (kvm_check_extension(kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
+qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend",
+  QEMU_PSCI_0_2_FN_CPU_SUSPEND);
+qemu_fdt_setprop_cell(fdt, "/psci", "cpu_off",
+  QEMU_PSCI_0_2_FN_CPU_OFF);
+qemu_fdt_setprop_cell(fdt, "/psci", "cpu_on",
+  QEMU_PSCI_0_2_FN_CPU_ON);
+qemu_fdt_setprop_cell(fdt, "/psci", "migrate",
+  QEMU_PSCI_0_2_FN_MIGRATE);
+qemu_fdt_setprop_cell(fdt, "/psci", "system_off",
+  QEMU_PSCI_0_2_FN_SYSTEM_OFF);
+qemu_fdt_setprop_cell(fdt, "/psci", "system_reset",
+  QEMU_PSCI_0_2_FN_SYSTEM_RESET);
+} else {
+qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend",
+  QEMU_PSCI_FN_CPU_SUSPEND);
+qemu_fdt_setprop_cell(fdt, "/psci", "cpu_off",
+  QEMU_PSCI_FN_CPU_OFF);
+qemu_fdt_setprop_cell(fdt, "/psci", "cpu_on",
+  QEMU_PSCI_FN_CPU_ON);
+qemu_fdt_setprop_cell(fdt, "/psci", "migrate",
+  QEMU_PSCI_FN_MIGRATE);
+}
 }
 }
 
-- 
1.7.9.5




[Qemu-devel] [RFC PATCH V3 7/7] target-arm: Implement kvm_arch_reset_vcpu() for KVM ARM64

2014-04-10 Thread Pranavkumar Sawargaonkar
To implement kvm_arch_reset_vcpu(), we simply re-init the VCPU
using kvm_arm_vcpu_init() so that all registers of VCPU are set
to their reset values by in-kernel KVM code.

Signed-off-by: Pranavkumar Sawargaonkar 
Signed-off-by: Anup Patel 
---
 target-arm/kvm64.c |4 
 1 file changed, 4 insertions(+)

diff --git a/target-arm/kvm64.c b/target-arm/kvm64.c
index b0490dd..fc23da3 100644
--- a/target-arm/kvm64.c
+++ b/target-arm/kvm64.c
@@ -198,4 +198,8 @@ int kvm_arch_get_registers(CPUState *cs)
 
 void kvm_arch_reset_vcpu(CPUState *cs)
 {
+/* Re-init VCPU so that all registers are set to
+ * their respective reset values.
+ */
+kvm_arm_vcpu_init(cs, 0x0);
 }
-- 
1.7.9.5




[Qemu-devel] [RFC PATCH V3 6/7] target-arm: Common kvm_arm_vcpu_init() for KVM ARM and KVM ARM64

2014-04-10 Thread Pranavkumar Sawargaonkar
Introduce a common kvm_arm_vcpu_init() for doing KVM_ARM_VCPU_INIT
ioctl in KVM ARM and KVM ARM64. This also helps us factor-out few
common code lines from kvm_arch_init_vcpu() for KVM ARM/ARM64.

Signed-off-by: Pranavkumar Sawargaonkar 
Signed-off-by: Anup Patel 
---
 target-arm/kvm.c |   23 +++
 target-arm/kvm32.c   |   18 +++---
 target-arm/kvm64.c   |   22 --
 target-arm/kvm_arm.h |   14 ++
 4 files changed, 48 insertions(+), 29 deletions(-)

diff --git a/target-arm/kvm.c b/target-arm/kvm.c
index 39202d7..55bc3a3 100644
--- a/target-arm/kvm.c
+++ b/target-arm/kvm.c
@@ -27,6 +27,29 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
 KVM_CAP_LAST_INFO
 };
 
+int kvm_arm_vcpu_init(CPUState *cs, uint32_t feature0_extra)
+{
+ARMCPU *cpu = ARM_CPU(cs);
+struct kvm_vcpu_init init;
+
+if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE) {
+fprintf(stderr, "KVM is not supported for this guest CPU type\n");
+return -EINVAL;
+}
+
+init.target = cpu->kvm_target;
+memset(init.features, 0, sizeof(init.features));
+if (cpu->start_powered_off) {
+init.features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
+}
+if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
+init.features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
+}
+init.features[0] |= feature0_extra;
+
+return kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
+}
+
 bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
   int *fdarray,
   struct kvm_vcpu_init *init)
diff --git a/target-arm/kvm32.c b/target-arm/kvm32.c
index afeff01..aa9facc 100644
--- a/target-arm/kvm32.c
+++ b/target-arm/kvm32.c
@@ -165,7 +165,6 @@ static int compare_u64(const void *a, const void *b)
 
 int kvm_arch_init_vcpu(CPUState *cs)
 {
-struct kvm_vcpu_init init;
 int i, ret, arraylen;
 uint64_t v;
 struct kvm_one_reg r;
@@ -173,23 +172,12 @@ int kvm_arch_init_vcpu(CPUState *cs)
 struct kvm_reg_list *rlp;
 ARMCPU *cpu = ARM_CPU(cs);
 
-if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE) {
-fprintf(stderr, "KVM is not supported for this guest CPU type\n");
-return -EINVAL;
-}
-
-init.target = cpu->kvm_target;
-memset(init.features, 0, sizeof(init.features));
-if (cpu->start_powered_off) {
-init.features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
-}
-if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
-init.features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
-}
-ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
+/* Do KVM_ARM_VCPU_INIT ioctl */
+ret = kvm_arm_vcpu_init(cs, 0x0);
 if (ret) {
 return ret;
 }
+
 /* Query the kernel to make sure it supports 32 VFP
  * registers: QEMU's "cortex-a15" CPU is always a
  * VFP-D32 core. The simplest way to do this is just
diff --git a/target-arm/kvm64.c b/target-arm/kvm64.c
index 02bba45..b0490dd 100644
--- a/target-arm/kvm64.c
+++ b/target-arm/kvm64.c
@@ -77,29 +77,23 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUClass *ahcc)
 
 int kvm_arch_init_vcpu(CPUState *cs)
 {
-ARMCPU *cpu = ARM_CPU(cs);
-struct kvm_vcpu_init init;
 int ret;
+ARMCPU *cpu = ARM_CPU(cs);
 
-if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE ||
-!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
-fprintf(stderr, "KVM is not supported for this guest CPU type\n");
+if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
+fprintf(stderr, "KVM only support Aarch64 CPU type\n");
 return -EINVAL;
 }
 
-init.target = cpu->kvm_target;
-memset(init.features, 0, sizeof(init.features));
-if (cpu->start_powered_off) {
-init.features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
-}
-if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
-init.features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
+/* Do KVM_ARM_VCPU_INIT ioctl */
+ret = kvm_arm_vcpu_init(cs, 0x0);
+if (ret) {
+return ret;
 }
-ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
 
 /* TODO : support for save/restore/reset of system regs via tuple list */
 
-return ret;
+return 0;
 }
 
 #define AARCH64_CORE_REG(x)   (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
diff --git a/target-arm/kvm_arm.h b/target-arm/kvm_arm.h
index 137c567..1889ba1 100644
--- a/target-arm/kvm_arm.h
+++ b/target-arm/kvm_arm.h
@@ -15,6 +15,20 @@
 #include "exec/memory.h"
 
 /**
+ * kvm_arm_vcpu_init:
+ * @cs: CPUState
+ * @feature0_extra: additional features
+ *
+ * KVM ARM and KVM ARM64 need to use KVM_ARM_VCPU_INIT ioctl for
+ * init/re-init/reset the VCPU with given feature flags.
+ * This is a common function for doing KVM_ARM_VCPU_INIT ioctl
+ * independent of KVM ARM or KVM ARM64.
+ *
+ * Returns: 0 if success else < 0 error code
+ */
+int kvm_arm_vcpu_init(CPUState *cs, uint32_t feature0_extra

Re: [Qemu-devel] Should we have a 2.0-rc3 ?

2014-04-10 Thread Kevin Wolf
Am 10.04.2014 um 13:17 hat Peter Maydell geschrieben:
> So far I know of at least three fixes which should probably
> go into 2.0:
>  * my fix for the configure stack-protector checks on MacOSX
>  * MST's pull request updating the ACPI test blobs
>  * MST says we need to update the hex files for ACPI too
>(otherwise you get a different ACPI blob depending on whether
> your build system had iasl or not, if I understand correctly)
> 
> Are there any others?

I have three fixes in my queue, though none of them is bad enough
to delay the release. However, if you're going to do an -rc3 anyway,
let me know and I'll send a pull request for them.

The bugs fixed are:
* iscsi has an error path where the return value is undefined.
* The bochs block driver has a buggy input validation check that can
  cause an out-of-bounds array read with corrupt images.

> So we have two choices:
> 
> (A) get those fixes into git today, and tag an rc3; that
> would then need some testing time and presumably we'd hope
> to tag it as the 2.0 release on Monday or Tuesday next week
> 
> (B) say that the above are not worth fixing in 2.0 proper
> and plan to do a 2.0.1 in a few weeks with the above plus
> any other breakage that people find.
> 
> Opinions?

Either way is fine with me.

Kevin



Re: [Qemu-devel] [PATCH 01/16] cutils: tighten qemu_parse_fd()

2014-04-10 Thread Eric Blake
On 04/10/2014 02:24 AM, Laszlo Ersek wrote:
> qemu_parse_fd() used to handle at least the following strings incorrectly:
> o "-2": simply let through
> o "2147483648": returned as LONG_MAX==INT_MAX on ILP32 (with ERANGE
> ignored); implementation-defined behavior on LP64
> 
> Signed-off-by: Laszlo Ersek 
> ---
>  util/cutils.c | 13 ++---
>  1 file changed, 10 insertions(+), 3 deletions(-)

I still think qemu should follow libvirt's lead of wrapping ALL uses of
strto*l behind sane wrappers, since this is not the only place in the
code base affected by misuse of the function - but that's a story for
another day.

>  
> +errno = 0;
>  fd = strtol(param, &endptr, 10);
> -if (*endptr || (fd == 0 && param == endptr)) {
> +if (param == endptr /* no conversion performed */||
> +errno != 0  /* not representable as long; possibly others */ ||
> +*endptr != '\0' /* final string not empty */ ||
> +fd < 0  /* invalid as file descriptor */ ||
> +fd > INT_MAX/* not representable as int */) {
>  return -1;

Your comments make it particularly obvious that YOU know how to properly
use this function, and hopefully teach future readers. :)

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 qemu 6/6] virtio-input: evdev passthrough

2014-04-10 Thread Gerd Hoffmann
  Hi,

> > +static void virtio_input_host_event(void *opaque)
> > +{
> > +VirtIOInputHost *vhost = opaque;
> 
> I'd prefer a name that does not imply
> vhost infrastructure

ok.

> > +rc = ioctl(vhost->fd, EVIOCGVERSION, &ver);
> > +if (rc < 0) {
> > +error_setg(errp, "%s: is not an evdev device", vhost->evdev);
> > +goto err_close;
> > +}
> 
> Hmm is that all?
> Don't we want to report versioning info to guests?

I guess the only thing we might want to here is bail out in case the
major version is != 1 (which implies a incompatible change).  The major
version didn't change so far though, and I think it is highly unlikely
that it'll ever happen.

cheers,
  Gerd





Re: [Qemu-devel] [Qemu-ppc] [PATCH] target-ppc: Add @cpu_dt_id into migration stream

2014-04-10 Thread Alexander Graf


On 08.04.14 03:26, Alexey Kardashevskiy wrote:

On 03/28/2014 12:07 AM, Alexey Kardashevskiy wrote:

On 03/27/2014 11:57 PM, Peter Maydell wrote:

On 27 March 2014 12:49, Alexey Kardashevskiy  wrote:

On 03/27/2014 11:37 PM, Andreas Färber wrote:

Am 27.03.2014 03:41, schrieb Alexey Kardashevskiy:

This should prevent the destination guest from misbehaving when
the threads number is different in "-smp" command.

Sorry, I don't understand. When migrating, surely -smp needs to be the
same on source and destination, so how can they differ?


The idea is that "-smp" does not migrate and if we run source and
destination guests with different numbers in -smp, we end up with weird
machine

Yes, so don't do that. As I understand it:
  (1) if you don't run QEMU with the exact same command line
  and config at both ends then migration won't work
  (2) we don't guarantee to detect and cleanly fail if you
  don't do (1)

It would probably be nice if we did detect config mismatches,

Yep, we do not send the device tree (as libvirt does). Pure command line
matching won't work.


but that seems to me like a problem we should be addressing
more globally than just for one particular config item for
one particular target...


Ok. So. Let's assume I want to implement migration of "-smp" parameters.
What would be the correct way of doing this in terms of the current QOM
principles? Thanks.


You don't. The migration protocol doesn't migrate configuration. If you 
want to start to transfer VM configuration (which I'd be all in for), do 
it properly and transfer _all_ configuration.



Alex




Re: [Qemu-devel] [PATCH qemu 5/6] virtio-input: control device

2014-04-10 Thread Gerd Hoffmann
On Do, 2014-04-10 at 14:05 +0300, Michael S. Tsirkin wrote:
> On Thu, Apr 10, 2014 at 11:07:53AM +0200, Gerd Hoffmann wrote:
> > Device for sending non-input control messages to the guest.  For now
> > this is only a single event: shutdown requests are sent as power button
> > press to the guest.
> > 
> > Possible other use is signaling sound volume changes to the guest (via
> > EV_ABS / ABS_VOLUME).  I expect we'll find more over time.
> > 
> > Signed-off-by: Gerd Hoffmann 
> 
> Why not use a keyboard device for this?

>From the guests point of view this is looks like a keyboard.  A keyboard
with a single key: power.

I prefer a clear separation between devices being feed from user input
and the control device which monitors other event sources (powerdown
notifier).

There is no fundamental reason why this can't live in the emulated
keyboard though.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH v5 08/11] spapr-iommu: add SPAPR VFIO IOMMU device

2014-04-10 Thread Alexander Graf


On 07.04.14 06:07, Alexey Kardashevskiy wrote:

On 04/03/2014 11:17 PM, Alexander Graf wrote:

On 12.03.14 06:52, Alexey Kardashevskiy wrote:

This adds SPAPR VFIO IOMMU device in order to support DMA operations
for VFIO devices.

Sorry if this has been mentioned before, but why exactly do you need a
separate IOMMU for VFIO? Couldn't the existing IOMMU backend drive things?

Well... Since I started VFIO on SPAPR, the emulated and VFIO IOMMU became
almost the same thing and I'll rework that too before I post things again.

However one difference still remains - IOMMU for emulated PCI and VIO keeps
a TCE table (allocated in QEMU or mmap'ed from the host kernel) and VFIO
IOMMU works with the table which is allocated and owned by the host kernel.

Since TCE tables are used only by devices, the IOMMU translation callback
is never called by VFIO devices and that's ok and I checked - it works.

So I either need a property in the IOMMU device to tell it is TCE table and
MemoryRegionIOMMUOps::translate() are required. Or a new IOMMU device
class. What to choose?


We need to handle in-kernel TCE tables with the emulated device IOMMU as 
well, so I'd



Oh. btw. There is H_GET_TCE now which I have to implement for VFIO :( This
will never ever end.


... which means you get H_GET_TCE for free as well ;).


Alex




Re: [Qemu-devel] [PATCH qemu 3/6] virtio-input: core code & base class

2014-04-10 Thread Gerd Hoffmann
On Do, 2014-04-10 at 14:06 +0300, Michael S. Tsirkin wrote:
> > +void virtio_input_send(VirtIOInput *vinput, virtio_input_event
> *event)
> > +{
> > +VirtQueueElement elem;
> > +int len;
> > +
> > +if (!virtqueue_pop(vinput->evt, &elem)) {
> > +fprintf(stderr, "%s: virtqueue empty, dropping event\n",
> __func__);
> > +return;
> 
> Looks scary.
> 

It's not different from other input devices.  No buffer space -> drop
event.  What else do you think should happen?  We could signal "you lost
events" to the guest, but I suspect that buys us nothing.  Other input
devices don't have that capability, so guests are likely not prepared to
handle the situation.  Also, there isn't much they can actually do about
it.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH 4/4] spapr: Add support for time base offset migration

2014-04-10 Thread Alexander Graf


On 03.04.14 15:14, Alexey Kardashevskiy wrote:

This allows guests to have a different timebase origin from the host.

This is needed for migration, where a guest can migrate from one host
to another and the two hosts might have a different timebase origin.
However, the timebase seen by the guest must not go backwards, and
should go forwards only by a small amount corresponding to the time
taken for the migration.

This is only supported for recent POWER hardware which has the TBU40
(timebase upper 40 bits) register. That includes POWER6, 7, 8 but not
970.

This adds kvm_access_one_reg() to access a special register which is not
in env->spr.

The feature must be present in the host kernel.

Signed-off-by: Alexey Kardashevskiy 
---
Changes:
v4:
* made it per machine timebase offser rather than per CPU

v3:
* kvm_access_one_reg moved out to a separate patch
* tb_offset and host_timebase were replaced with guest_timebase as
the destionation does not really care of offset on the source

v2:
* bumped the vmstate_ppc_cpu version
* defined version for the env.tb_env field
---
  hw/ppc/ppc.c   | 120 +
  hw/ppc/spapr.c |   3 +-
  include/hw/ppc/spapr.h |   2 +
  target-ppc/cpu-qom.h   |  16 +++
  target-ppc/kvm.c   |   5 +++
  target-ppc/machine.c   |   4 +-
  trace-events   |   3 ++
  7 files changed, 151 insertions(+), 2 deletions(-)

diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index 9c2a132..b51db1b 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -29,9 +29,11 @@
  #include "sysemu/cpus.h"
  #include "hw/timer/m48t59.h"
  #include "qemu/log.h"
+#include "qemu/error-report.h"
  #include "hw/loader.h"
  #include "sysemu/kvm.h"
  #include "kvm_ppc.h"
+#include "trace.h"
  
  //#define PPC_DEBUG_IRQ

  //#define PPC_DEBUG_TB
@@ -797,6 +799,124 @@ static void cpu_ppc_set_tb_clk (void *opaque, uint32_t 
freq)
  cpu_ppc_store_purr(cpu, 0xULL);
  }
  
+/*

+ * Calculate timebase on the destination side of migration
+ *
+ * We calculate new timebase offset as shown below:
+ * 1) Gtb2 = Gtb1 + max(tod2 - tod1, 0)
+ *Gtb2 = tb2 + off2
+ * 2) tb2 + off2 = Gtb1 + max(tod2 - tod1, 0)
+ * 3) off2 = Gtb1 - tb2 + max(tod2 - tod1, 0)
+ *
+ * where:
+ * Gtb2 - destination guest timebase
+ * tb2 - destination host timebase
+ * off2 - destination timebase offset
+ * tod2 - destination time of the day
+ * Gtb1 - source guest timebase
+ * tod1 - source time of the day
+ *
+ * The result we want is in @off2
+ *
+ * Two conditions must be met for @off2:
+ * 1) off2 must be multiple of 2^24 ticks as it will be set via TBU40 SPR
+ * 2) Gtb2 >= Gtb1
+ */
+static int64_t cpu_ppc_adjust_tb_offset(PPCTimebaseOffset *tb)
+{
+uint64_t tb2, tod2;
+int64_t off2;
+int ratio = tb->freq / 100;
+struct timeval tv;
+
+tb2 = cpu_get_real_ticks();
+gettimeofday(&tv, NULL);
+tod2 = tv.tv_sec * 100 + tv.tv_usec;
+
+off2 = tb->guest_timebase - tb2;
+if ((tod2 > tb->time_of_the_day) &&
+(tod2 - tb->time_of_the_day < 100)) {
+off2 += (tod2 - tb->time_of_the_day) * ratio;
+}
+off2 = ROUND_UP(off2, 1 << 24);
+
+return off2;
+}


I *think* what you're trying to say here is that you want

assert(source_timebase_freq == timebase_freq);

migration_duration_ns = host_ns - source_host_ns;
guest_tb = source_guest_tb + ns_scaled_to_tb(min(0, migration_duration_ns);
kvm_set_guest_tb(guest_tb);
  -> kvm_set_one_reg(KVM_REG_PPC_TB_OFFSET, guest_tb - mftb());

But I honestly have not managed to read that from the code. Either this 
really is what you're trying to do and the code is just very hard to 
read (which means it needs to be written more easily) or you're doing 
something different which I don't understand.


We also designed the PPC_TB_OFFSET ONE_REG in a way that it always 
rounds up to its 40 bit granularity, so no need to do this in QEMU. In 
fact, we don't want to do it in QEMU in case there will be a more 
fine-grained SPR in the future.


And from all I understand the timebase frequency is now architecturally 
specified, so it won't change for newer cores, no? And if we migrate TCG 
guests it will be the same between two hosts.



Alex


+
+static void timebase_pre_save(void *opaque)
+{
+PPCTimebaseOffset *tb = opaque;
+struct timeval tv;
+uint64_t ticks = cpu_get_real_ticks();
+PowerPCCPU *first_ppc_cpu = POWERPC_CPU(first_cpu);
+
+tb->freq = first_ppc_cpu->env.tb_env->tb_freq;
+
+gettimeofday(&tv, NULL);
+tb->time_of_the_day = tv.tv_sec * 100 + tv.tv_usec;
+/*
+ * tb_offset is only expected to be changed by migration so
+ * there is no need to update it from KVM here
+ */
+tb->guest_timebase = ticks + first_ppc_cpu->env.tb_env->tb_offset;
+}
+
+static int timebase_pre_load(void *opaque)
+{
+PPCTimebaseOffset *tb = opaque;
+PowerPCCPU *first_ppc_cpu = POWERPC_CPU(first_cpu);
+
+if (!first_ppc_cpu->env.tb_env) {
+  

Re: [Qemu-devel] [PATCH 1/8] spapr-iommu: add a bus for spapr-iommu devices

2014-04-10 Thread Alexander Graf


On 14.03.14 05:18, Alexey Kardashevskiy wrote:

At the moment sPAPR IOMMU table is a device which participates in
a migration stream. Normally QEMU uses a get_dev_path() hook from
the device's bus to compose the section name and @instance_id which are
used to match the section to the real device. This works till the user
changes the device order in the command line - if this happens,
devices get other instance_id's and migration fails.

This adds a TCE bridge bus device per sPAPR machine and places all sPAPR
IOMMU devices onto it.

Signed-off-by: Alexey Kardashevskiy 


Juan, is a different command line device order supposed to work with 
migration?



Alex


---
  hw/ppc/spapr.c |  3 +++
  hw/ppc/spapr_iommu.c   | 59 +-
  include/hw/ppc/spapr.h |  7 ++
  3 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 5c9a154..12adc21 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1263,6 +1263,9 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
  /* Set up EPOW events infrastructure */
  spapr_events_init(spapr);
  
+/* Set up TCE IOMMUs bus */

+spapr->tce_bus = spapr_tce_bus_init();
+
  /* Set up VIO bus */
  spapr->vio_bus = spapr_vio_bus_init();
  
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c

index d9fe946..7db0acf 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -157,7 +157,7 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, 
uint32_t liobn, size_t wi
  return NULL;
  }
  
-tcet = SPAPR_TCE_TABLE(object_new(TYPE_SPAPR_TCE_TABLE));

+tcet = SPAPR_TCE_TABLE(qdev_create(spapr->tce_bus, TYPE_SPAPR_TCE_TABLE));
  tcet->liobn = liobn;
  tcet->window_size = window_size;
  
@@ -342,9 +342,66 @@ static TypeInfo spapr_tce_table_info = {

  .instance_finalize = spapr_tce_table_finalize,
  };
  
+static char *spapr_tce_bus_get_dev_name(DeviceState *qdev)

+{
+sPAPRTCETable *tcet = SPAPR_TCE_TABLE(qdev);
+char *name;
+
+name = g_strdup_printf("liobn@%x", tcet->liobn);
+return name;
+}
+
+static void spapr_tce_bus_class_init(ObjectClass *klass, void *data)
+{
+BusClass *k = BUS_CLASS(klass);
+
+k->get_dev_path = spapr_tce_bus_get_dev_name;
+}
+
+static const TypeInfo spapr_tce_bus_info = {
+.name = TYPE_SPAPR_TCE_BUS,
+.parent = TYPE_BUS,
+.class_init = spapr_tce_bus_class_init,
+.instance_size = sizeof(BusState),
+};
+
+static int spapr_tce_bridge_init(SysBusDevice *dev)
+{
+/* nothing */
+return 0;
+}
+
+static void spapr_tce_bridge_class_init(ObjectClass *klass, void *data)
+{
+SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+k->init = spapr_tce_bridge_init;
+}
+
+static const TypeInfo spapr_tce_bridge_info = {
+.name  = "spapr-tce-bridge",
+.parent= TYPE_SYS_BUS_DEVICE,
+.instance_size = sizeof(SysBusDevice),
+.class_init= spapr_tce_bridge_class_init,
+};
+
  static void register_types(void)
  {
  type_register_static(&spapr_tce_table_info);
+type_register_static(&spapr_tce_bridge_info);
+type_register_static(&spapr_tce_bus_info);
+}
+
+BusState *spapr_tce_bus_init(void)
+{
+DeviceState *dev;
+
+/* Create bridge device */
+dev = qdev_create(NULL, spapr_tce_bridge_info.name);
+qdev_init_nofail(dev);
+
+/* Create bus on bridge device */
+return qbus_create(TYPE_SPAPR_TCE_BUS, dev, "spapr-tce");
  }
  
  type_init(register_types);

diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 449fc7c..18332fd 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -12,6 +12,7 @@ struct sPAPRNVRAM;
  
  typedef struct sPAPREnvironment {

  struct VIOsPAPRBus *vio_bus;
+BusState *tce_bus;
  QLIST_HEAD(, sPAPRPHBState) phbs;
  hwaddr msi_win_addr;
  MemoryRegion msiwindow;
@@ -405,4 +406,10 @@ int spapr_dma_dt(void *fdt, int node_off, const char 
*propname,
  int spapr_tcet_dma_dt(void *fdt, int node_off, const char *propname,
sPAPRTCETable *tcet);
  
+#define TYPE_SPAPR_TCE_BUS "spapr-tce-bus"

+#define SPAPR_TCE_BUS(obj) \
+OBJECT_CHECK(BusState, (obj), TYPE_SPAPR_TCE_BUS)
+
+BusState *spapr_tce_bus_init(void);
+
  #endif /* !defined (__HW_SPAPR_H__) */





Re: [Qemu-devel] [PATCH 2/8] xics: add flags for interrupts

2014-04-10 Thread Alexander Graf


On 14.03.14 05:18, Alexey Kardashevskiy wrote:

We will need soon an "allocated" flag for every interrupt to support
interrupt configuration change which may happen during migration.

This replaces a separate lslsi[] array with a byte in the ICSIRQState
struct and defines "LSI" and "MSI" flags. Neither of these flags set
signals that the descriptor is not in use.

Signed-off-by: Alexey Kardashevskiy 
---
  hw/intc/xics.c| 17 +++--
  hw/intc/xics_kvm.c|  5 ++---
  include/hw/ppc/xics.h |  4 +++-
  3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/hw/intc/xics.c b/hw/intc/xics.c
index 64aabe7..7eac85a 100644
--- a/hw/intc/xics.c
+++ b/hw/intc/xics.c
@@ -438,7 +438,7 @@ static void ics_set_irq(void *opaque, int srcno, int val)
  {
  ICSState *ics = (ICSState *)opaque;
  
-if (ics->islsi[srcno]) {

+if (ics->irqs[srcno].flags & XICS_FLAGS_LSI) {
  set_irq_lsi(ics, srcno, val);
  } else {
  set_irq_msi(ics, srcno, val);
@@ -475,7 +475,7 @@ static void ics_write_xive(ICSState *ics, int nr, int 
server,
  
  trace_xics_ics_write_xive(nr, srcno, server, priority);
  
-if (ics->islsi[srcno]) {

+if (ics->irqs[srcno].flags & XICS_FLAGS_LSI) {
  write_xive_lsi(ics, srcno);
  } else {
  write_xive_msi(ics, srcno);
@@ -497,7 +497,7 @@ static void ics_resend(ICSState *ics)
  
  for (i = 0; i < ics->nr_irqs; i++) {

  /* FIXME: filter by server#? */
-if (ics->islsi[i]) {
+if (ics->irqs[i].flags & XICS_FLAGS_LSI) {
  resend_lsi(ics, i);
  } else {
  resend_msi(ics, i);
@@ -512,7 +512,7 @@ static void ics_eoi(ICSState *ics, int nr)
  
  trace_xics_ics_eoi(nr);
  
-if (ics->islsi[srcno]) {

+if (ics->irqs[srcno].flags & XICS_FLAGS_LSI) {
  irq->status &= ~XICS_STATUS_SENT;
  }
  }
@@ -609,7 +609,6 @@ static void ics_realize(DeviceState *dev, Error **errp)
  return;
  }
  ics->irqs = g_malloc0(ics->nr_irqs * sizeof(ICSIRQState));
-ics->islsi = g_malloc0(ics->nr_irqs * sizeof(bool));
  ics->qirqs = qemu_allocate_irqs(ics_set_irq, ics, ics->nr_irqs);
  }
  
@@ -646,11 +645,17 @@ qemu_irq xics_get_qirq(XICSState *icp, int irq)

  return icp->ics->qirqs[irq - icp->ics->offset];
  }
  
+static void ics_set_irq_type(ICSState *ics, int irq, bool lsi)

+{
+ics->irqs[irq - ics->offset].flags |=
+lsi ? XICS_FLAGS_LSI : XICS_FLAGS_MSI;


If I configure an IRQ as LSI then as MSI this doesn't work. Sure, we 
probably don't do this but in general this is not how a "set" function 
should behave.



Alex




Re: [Qemu-devel] Should we have a 2.0-rc3 ?

2014-04-10 Thread Eric Blake
On 04/10/2014 05:17 AM, Peter Maydell wrote:
> So far I know of at least three fixes which should probably
> go into 2.0:
>  * my fix for the configure stack-protector checks on MacOSX
>  * MST's pull request updating the ACPI test blobs
>  * MST says we need to update the hex files for ACPI too
>(otherwise you get a different ACPI blob depending on whether
> your build system had iasl or not, if I understand correctly)
> 
> Are there any others?

Yes.  The libvirt team is a bit annoyed that the pci bus naming was
changed for PPC but not all architectures, but without a proper QMP
command to probe which naming scheme is in effect.  We thought that the
naming scheme was going to be universally supplied for all arches, not
just PPC.

https://lists.gnu.org/archive/html/qemu-devel/2014-04/msg01533.html

Is this something that can be quickly fixed (perhaps by reverting the
PPC patch until a more complete solution is ready), and if so, is it
worth doing for 2.0 proper, rather than waiting for 2.0.1?

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] Should we have a 2.0-rc3 ?

2014-04-10 Thread Alexander Graf

On 10.04.2014, at 14:44, Eric Blake  wrote:

> On 04/10/2014 05:17 AM, Peter Maydell wrote:
>> So far I know of at least three fixes which should probably
>> go into 2.0:
>> * my fix for the configure stack-protector checks on MacOSX
>> * MST's pull request updating the ACPI test blobs
>> * MST says we need to update the hex files for ACPI too
>>   (otherwise you get a different ACPI blob depending on whether
>>your build system had iasl or not, if I understand correctly)
>> 
>> Are there any others?
> 
> Yes.  The libvirt team is a bit annoyed that the pci bus naming was
> changed for PPC but not all architectures, but without a proper QMP
> command to probe which naming scheme is in effect.  We thought that the
> naming scheme was going to be universally supplied for all arches, not
> just PPC.
> 
> https://lists.gnu.org/archive/html/qemu-devel/2014-04/msg01533.html
> 
> Is this something that can be quickly fixed (perhaps by reverting the
> PPC patch until a more complete solution is ready), and if so, is it
> worth doing for 2.0 proper, rather than waiting for 2.0.1?

Which way works better for you? I'd be perfectly fine with reverting the patch. 
Libvirt is the only reason that path is there in the first place.


Alex



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Qemu-devel] [PATCH 6/8] spapr: move interrupt allocator to xics

2014-04-10 Thread Alexander Graf


On 14.03.14 05:18, Alexey Kardashevskiy wrote:

The current allocator returns IRQ numbers from a pool and does not
support IRQs reuse in any form as it did not keep track of what it
previously returned, it only had the last returned IRQ.
However migration may change interrupts for devices depending on
their order in the command line.


Wtf? Nonono, this sounds very bogus and wrong. Migration shouldn't 
change anything.



Alex


This moves an allocator from SPAPR to XICS.

This switches IRQ users to use new API.

This uses LSI/MSI flags to know if interrupt is in use.

Signed-off-by: Alexey Kardashevskiy 
---
  hw/intc/xics.c | 80 ++
  hw/ppc/spapr.c | 67 --
  hw/ppc/spapr_events.c  |  2 +-
  hw/ppc/spapr_pci.c |  6 ++--
  hw/ppc/spapr_vio.c |  2 +-
  include/hw/ppc/spapr.h | 10 ---
  include/hw/ppc/xics.h  |  2 ++
  trace-events   |  3 ++
  8 files changed, 90 insertions(+), 82 deletions(-)

diff --git a/hw/intc/xics.c b/hw/intc/xics.c
index e5195bf..8d101a3 100644
--- a/hw/intc/xics.c
+++ b/hw/intc/xics.c
@@ -690,6 +690,86 @@ void xics_set_irq_type(XICSState *icp, int irq, bool lsi)
  ics_set_irq_type(&icp->ics[server], irq, lsi);
  }
  
+#define XICS_IRQ_FREE(ics, n)   \

+(!((ics)->irqs[(n) - (ics)->offset].flags & \
+   (XICS_FLAGS_LSI | XICS_FLAGS_MSI)))
+
+static int ics_find_free_block(ICSState *ics, int num, int alignnum)
+{
+int first, i;
+
+for (first = 0; first < ics->nr_irqs; first += alignnum) {
+if (num > (ics->nr_irqs - first)) {
+return -1;
+}
+for (i = first; i < first + num; ++i) {
+if (!XICS_IRQ_FREE(ics, i + ics->offset)) {
+break;
+}
+}
+if (i == (first + num)) {
+return first + ics->offset;
+}
+}
+
+return -1;
+}
+
+int xics_alloc(XICSState *icp, int server, int irq, bool lsi)
+{
+ICSState *ics = &icp->ics[server];
+
+if (irq) {
+assert(server == xics_find_server(icp, irq));
+if (!XICS_IRQ_FREE(ics, irq)) {
+trace_xics_alloc_failed(server, irq);
+return -1;
+}
+} else {
+irq = ics_find_free_block(ics, 1, 1);
+}
+
+ics_set_irq_type(ics, irq, lsi);
+trace_xics_alloc(server, irq);
+
+return irq;
+}
+
+/*
+ * Allocate block of consequtive IRQs, returns a number of the first.
+ * If align==true, aligns the first IRQ number to num.
+ */
+int xics_alloc_block(XICSState *icp, int server, int num, bool lsi, bool align)
+{
+int i, first = -1;
+ICSState *ics = &icp->ics[server];
+
+assert(server == 0);
+/*
+ * MSIMesage::data is used for storing VIRQ so
+ * it has to be aligned to num to support multiple
+ * MSI vectors. MSI-X is not affected by this.
+ * The hint is used for the first IRQ, the rest should
+ * be allocated continuously.
+ */
+if (align) {
+assert((num == 1) || (num == 2) || (num == 4) ||
+   (num == 8) || (num == 16) || (num == 32));
+first = ics_find_free_block(ics, num, num);
+} else {
+first = ics_find_free_block(ics, num, 1);
+}
+
+if (first > 0) {
+for (i = first; i < first + num; ++i) {
+ics_set_irq_type(ics, i, lsi);
+}
+}
+trace_xics_alloc_block(server, first, num, lsi, align);
+
+return first;
+}
+
  /*
   * Guest interfaces
   */
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 12adc21..29ca2e0 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -83,73 +83,6 @@
  
  sPAPREnvironment *spapr;
  
-int spapr_allocate_irq(int hint, bool lsi)

-{
-int irq;
-
-if (hint) {
-irq = hint;
-if (hint >= spapr->next_irq) {
-spapr->next_irq = hint + 1;
-}
-/* FIXME: we should probably check for collisions somehow */
-} else {
-irq = spapr->next_irq++;
-}
-
-/* Configure irq type */
-if (!xics_get_qirq(spapr->icp, irq)) {
-return 0;
-}
-
-xics_set_irq_type(spapr->icp, irq, lsi);
-
-return irq;
-}
-
-/*
- * Allocate block of consequtive IRQs, returns a number of the first.
- * If msi==true, aligns the first IRQ number to num.
- */
-int spapr_allocate_irq_block(int num, bool lsi, bool msi)
-{
-int first = -1;
-int i, hint = 0;
-
-/*
- * MSIMesage::data is used for storing VIRQ so
- * it has to be aligned to num to support multiple
- * MSI vectors. MSI-X is not affected by this.
- * The hint is used for the first IRQ, the rest should
- * be allocated continuously.
- */
-if (msi) {
-assert((num == 1) || (num == 2) || (num == 4) ||
-   (num == 8) || (num == 16) || (num == 32));
-hint = (spapr->next_irq + num - 1) & ~(num - 1);
-}
-
-for (i = 0; i < num; ++i) {
-int irq;
-
-irq = spapr_allocate_irq(hint, lsi);
-if (!irq) {

Re: [Qemu-devel] Should we have a 2.0-rc3 ?

2014-04-10 Thread Eric Blake
On 04/10/2014 06:46 AM, Alexander Graf wrote:
> 
> On 10.04.2014, at 14:44, Eric Blake  wrote:
> 
>> On 04/10/2014 05:17 AM, Peter Maydell wrote:
>>> So far I know of at least three fixes which should probably
>>> go into 2.0:
>>> * my fix for the configure stack-protector checks on MacOSX
>>> * MST's pull request updating the ACPI test blobs
>>> * MST says we need to update the hex files for ACPI too
>>>   (otherwise you get a different ACPI blob depending on whether
>>>your build system had iasl or not, if I understand correctly)
>>>
>>> Are there any others?
>>
>> Yes.  The libvirt team is a bit annoyed that the pci bus naming was
>> changed for PPC but not all architectures, but without a proper QMP
>> command to probe which naming scheme is in effect.  We thought that the
>> naming scheme was going to be universally supplied for all arches, not
>> just PPC.
>>
>> https://lists.gnu.org/archive/html/qemu-devel/2014-04/msg01533.html
>>
>> Is this something that can be quickly fixed (perhaps by reverting the
>> PPC patch until a more complete solution is ready), and if so, is it
>> worth doing for 2.0 proper, rather than waiting for 2.0.1?
> 
> Which way works better for you? I'd be perfectly fine with reverting the 
> patch. Libvirt is the only reason that path is there in the first place.

Given the shortness of the timing, reverting for 2.0, and fixing it
properly after the release, may be the best path forward (that is, 2.0
will be no different than 1.7 for what libvirt has to special case,
whereas all future versions can be properly introspectable, so that
libvirt has less special casing than what it would need if 2.0 is a
one-off for PPC).

> 
> 
> Alex
> 

-- 
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 v2 4/5] block: qemu-iotests - fix image cleanup when using spaced pathnames

2014-04-10 Thread Jeff Cody
On Thu, Apr 10, 2014 at 03:53:57PM +0800, Fam Zheng wrote:
> On Wed, 04/09 22:41, Jeff Cody wrote:
> > The _rm_test_img() function in common.rc did not quote the image
> > file, which left droppings in the scratch directory (and performed
> > a potentially unsafe rm -f).
> > 
> > This adds the necessary quotes.
> > 
> > Signed-off-by: Jeff Cody 
> > ---
> >  tests/qemu-iotests/common.rc | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
> > index 7f00883..195c564 100644
> > --- a/tests/qemu-iotests/common.rc
> > +++ b/tests/qemu-iotests/common.rc
> > @@ -178,10 +178,10 @@ _rm_test_img()
> >  local img=$1
> 
> Since we are quoting $img, should we quote $1 as well?
>

I believe not, because variable assignment won't undergo all the shell
expansions.  Notably, in variable assignment word splitting is not
performed on the parameter expansion on the argument immediately to the
right of the '='.  Quote removal, however, will still be performed.  So
img=$1 and img="$1" are identical once processed.

> 
> >  if [ "$IMGFMT" = "vmdk" ]; then
> >  # Remove all the extents for vmdk
> > -$QEMU_IMG info $img 2>/dev/null | grep 'filename:' | cut -f 2 -d: \
> > +"$QEMU_IMG" info "$img" 2>/dev/null | grep 'filename:' | cut -f 2 
> > -d: \
> >  | xargs -I {} rm -f "{}"
> >  fi
> > -rm -f $img
> > +rm -f "$img"
> >  }
> >  
> >  _cleanup_test_img()
> > -- 
> > 1.8.3.1
> > 
> > 



Re: [Qemu-devel] [PATCH 8/8] xics: enable interrupt configuration reset on migration

2014-04-10 Thread Alexander Graf


On 14.03.14 05:18, Alexey Kardashevskiy wrote:

Interrupt numbers migrate along with other properties so
the initial QEMU setup will be reset by migration. Since
XICS migrates as well and this includes IRQ map with all
the flags saying which ones are already used, all we need
is just to reset the XICS IRQ array on the destination.

This resets XICS IRQ usage map.

This enables devices to migrate IRQ number instead of
checking that the number has not changed since
the initialization.

Signed-off-by: Alexey Kardashevskiy 


I'm not sure this is how it's supposed to work. Juan, what's the usual 
way to ensure that interrupt allocation stays identical between source 
and destination on migration?



Alex


---
  hw/intc/xics.c| 19 +++
  hw/ppc/spapr_pci.c|  2 +-
  hw/ppc/spapr_vio.c|  2 +-
  include/hw/ppc/xics.h |  1 +
  trace-events  |  1 +
  5 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/hw/intc/xics.c b/hw/intc/xics.c
index 8d101a3..0809a52 100644
--- a/hw/intc/xics.c
+++ b/hw/intc/xics.c
@@ -33,6 +33,8 @@
  #include "qemu/error-report.h"
  #include "qapi/visitor.h"
  
+static void ics_free(ICSState *ics, int irq, int num);

+
  static int get_cpu_index_by_dt_id(int cpu_dt_id)
  {
  PowerPCCPU *cpu = ppc_get_vcpu_by_dt_id(cpu_dt_id);
@@ -531,6 +533,12 @@ static void ics_reset(DeviceState *dev)
  }
  }
  
+static int ics_pre_load(ICSState *ics)

+{
+ics_free(ics, ics->offset, ics->nr_irqs);
+return 0;
+}
+
  static int ics_post_load(ICSState *ics, int version_id)
  {
  int i;
@@ -635,6 +643,7 @@ static void ics_class_init(ObjectClass *klass, void *data)
  dc->realize = ics_realize;
  dc->vmsd = &vmstate_ics;
  dc->reset = ics_reset;
+isc->pre_load = ics_pre_load;
  isc->post_load = ics_post_load;
  }
  
@@ -770,6 +779,16 @@ int xics_alloc_block(XICSState *icp, int server, int num, bool lsi, bool align)

  return first;
  }
  
+static void ics_free(ICSState *ics, int irq, int num)

+{
+int i;
+
+trace_xics_ics_free(ics - ics->icp->ics, irq, num);
+for (i = irq; i < irq + num; ++i) {
+memset(&ics->irqs[i], 0, sizeof(ICSIRQState));
+}
+}
+
  /*
   * Guest interfaces
   */
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 4eaf364..aa12d1a 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -661,7 +661,7 @@ static const VMStateDescription vmstate_spapr_pci_lsi = {
  .minimum_version_id = 1,
  .minimum_version_id_old = 1,
  .fields  = (VMStateField []) {
-VMSTATE_UINT32_EQUAL(irq, struct spapr_pci_lsi),
+VMSTATE_UINT32(irq, struct spapr_pci_lsi),
  
  VMSTATE_END_OF_LIST()

  },
diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
index 8aeb263..022c914 100644
--- a/hw/ppc/spapr_vio.c
+++ b/hw/ppc/spapr_vio.c
@@ -548,7 +548,7 @@ const VMStateDescription vmstate_spapr_vio = {
  .fields  = (VMStateField []) {
  /* Sanity check */
  VMSTATE_UINT32_EQUAL(reg, VIOsPAPRDevice),
-VMSTATE_UINT32_EQUAL(irq, VIOsPAPRDevice),
+VMSTATE_UINT32(irq, VIOsPAPRDevice),
  
  /* General VIO device state */

  VMSTATE_UINTTL(signal_state, VIOsPAPRDevice),
diff --git a/include/hw/ppc/xics.h b/include/hw/ppc/xics.h
index 337398d..6ee6279 100644
--- a/include/hw/ppc/xics.h
+++ b/include/hw/ppc/xics.h
@@ -159,6 +159,7 @@ qemu_irq xics_get_qirq(XICSState *icp, int irq);
  void xics_set_irq_type(XICSState *icp, int irq, bool lsi);
  int xics_alloc(XICSState *icp, int server, int irq, bool lsi);
  int xics_alloc_block(XICSState *icp, int server, int num, bool lsi, bool 
align);
+void xics_free(XICSState *icp, int server, int irq, int num);
  
  void xics_cpu_setup(XICSState *icp, PowerPCCPU *cpu);
  
diff --git a/trace-events b/trace-events

index ad7400e..948ab93 100644
--- a/trace-events
+++ b/trace-events
@@ -1146,6 +1146,7 @@ xics_ics_eoi(int nr) "ics_eoi: irq %#x"
  xics_alloc(int server, int irq) "server#%d, irq %d"
  xics_alloc_failed(int server, int irq) "server#%d, irq %d"
  xics_alloc_block(int server, int first, int num, bool lsi, int align) "server#%d, 
first irq %d, %d irqs, lsi=%d, alignnum %d"
+xics_ics_free(int server, int irq, int num) "server#%d, first irq %d, %d irqs"
  
  # hw/ppc/spapr_iommu.c

  spapr_iommu_put(uint64_t liobn, uint64_t ioba, uint64_t tce, uint64_t ret) "liobn=%"PRIx64" 
ioba=0x%"PRIx64" tce=0x%"PRIx64" ret=%"PRId64





[Qemu-devel] qemu 2.0.0-rc2 crash

2014-04-10 Thread Marcin Gibuła

Hi,

I've been playing with QEMU 2.0-rc2 and found a crash that isn't there 
in 1.7.1.


Virtual machine is created via libvirt and when I query it with 
'dommemstat' it crashes with following backtrace:


Program received signal SIGSEGV, Segmentation fault.
0x7f5883655c0a in object_class_dynamic_cast (class=0x7f588618fbb0, 
typename=typename@entry=0x7f58837ebe54 "object") at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qom/object.c:525
525 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qom/object.c: 
No such file or directory.

(gdb) bt
#0  0x7f5883655c0a in object_class_dynamic_cast 
(class=0x7f588618fbb0, typename=typename@entry=0x7f58837ebe54 "object") 
at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qom/object.c:525
#1  0x7f5883655da5 in object_dynamic_cast (obj=0x7f58861604c0, 
typename=typename@entry=0x7f58837ebe54 "object") at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qom/object.c:456
#2  0x7f5883657d6e in object_resolve_abs_path (parent=out>, parts=parts@entry=0x7f5886352ad0, 
typename=typename@entry=0x7f58837ebe54 "object", index=index@entry=1)
at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qom/object.c:1244
#3  0x7f5883657f20 in object_resolve_path_type (path=out>, typename=0x7f58837ebe54 "object", ambiguous=0x7fff1ccab257) at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qom/object.c:1312
#4  0x7f5883652d7f in qmp_qom_list (path=0x7f588615c9a0 
"//machine/i440fx/pci.0/child[9]", errp=errp@entry=0x7fff1ccab290) at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qmp.c:201
#5  0x7f588364dd55 in qmp_marshal_input_qom_list (mon=out>, qdict=, ret=0x7fff1ccab310) at qmp-marshal.c:2490
#6  0x7f58836ef4e8 in qmp_call_cmd (params=0x7f58893626b0, 
mon=0x7f5885c9ec90, cmd=) at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/monitor.c:4760
#7  handle_qmp_command (parser=, tokens=) 
at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/monitor.c:4826
#8  0x7f588378289a in json_message_process_token 
(lexer=0x7f5885ca00a0, token=0x7f58861a0500, type=JSON_OPERATOR, x=95, 
y=20) at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qobject/json-streamer.c:87
#9  0x7f5883797c4f in json_lexer_feed_char 
(lexer=lexer@entry=0x7f5885ca00a0, ch=125 '}', flush=flush@entry=false) 
at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qobject/json-lexer.c:303
#10 0x7f5883797d96 in json_lexer_feed (lexer=0x7f5885ca00a0, 
buffer=, size=) at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qobject/json-lexer.c:356
#11 0x7f5883782ab1 in json_message_parser_feed (parser=out>, buffer=, size=) at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qobject/json-streamer.c:110
#12 0x7f58836ed593 in monitor_control_read (opaque=, 
buf=, size=) at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/monitor.c:4847
#13 0x7f588363d4e1 in qemu_chr_be_write (len=, 
buf=0x7fff1ccab4f0 "}", s=0x7f5885caf0b0) at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qemu-char.c:165
#14 tcp_chr_read (chan=, cond=, 
opaque=0x7f5885caf0b0) at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qemu-char.c:2487
#15 0x7f58814d0b75 in g_main_context_dispatch () from 
/usr/lib64/libglib-2.0.so.0
#16 0x7f588360b0e8 in glib_pollfds_poll () at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/main-loop.c:190
#17 os_host_main_loop_wait (timeout=) at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/main-loop.c:235
#18 main_loop_wait (nonblocking=) at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/main-loop.c:484
#19 0x7f58834dbb6e in main_loop () at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/vl.c:2051
#20 main (argc=, argv=, envp=out>) at 
/var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/vl.c:4507


Virtual machine options command line:

LC_ALL=C 
PATH=/bin:/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin 
HOME=/ USER=root QEMU_AUDIO_DRV=none /usr/bin/qemu-kvm -name 
f1b3b8b7-7b0e-4eab-afef-06d577d6544d -S -machine 
pc-i440fx-2.0,accel=kvm,usb=off -cpu SandyBridge,-kvmclock -m 4096 
-realtime mlock=on -smp 4,sockets=2,cores=10,threads=1 -uuid 
f1b3b8b7-7b0e-4eab-afef-06d577d6544d -smbios type=0,vendor=HAL 9000 
-smbios type=1,manufacturer=cloud -no-user-config -nodefaults -chardev 
socket,id=charmonitor,path=/var/lib/libvirt/qemu/f1b3b8b7-7b0e-4eab-afef-06d577d6544d.monitor,server,nowait 
-mon chardev=charmonitor,id=monitor,mode=control -rtc 
base=utc,clock=vm,driftfix=slew -global kvm-pit.lost_tick_policy=discard 
-no-shutdown -boot menu=off,strict=on -device 
piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -device 
virtio-serial-pci,id=virtio-serial0,bus=pci.0,

Re: [Qemu-devel] Should we have a 2.0-rc3 ?

2014-04-10 Thread Alexander Graf


On 10.04.14 14:51, Eric Blake wrote:

On 04/10/2014 06:46 AM, Alexander Graf wrote:

On 10.04.2014, at 14:44, Eric Blake  wrote:


On 04/10/2014 05:17 AM, Peter Maydell wrote:

So far I know of at least three fixes which should probably
go into 2.0:
* my fix for the configure stack-protector checks on MacOSX
* MST's pull request updating the ACPI test blobs
* MST says we need to update the hex files for ACPI too
   (otherwise you get a different ACPI blob depending on whether
your build system had iasl or not, if I understand correctly)

Are there any others?

Yes.  The libvirt team is a bit annoyed that the pci bus naming was
changed for PPC but not all architectures, but without a proper QMP
command to probe which naming scheme is in effect.  We thought that the
naming scheme was going to be universally supplied for all arches, not
just PPC.

https://lists.gnu.org/archive/html/qemu-devel/2014-04/msg01533.html

Is this something that can be quickly fixed (perhaps by reverting the
PPC patch until a more complete solution is ready), and if so, is it
worth doing for 2.0 proper, rather than waiting for 2.0.1?

Which way works better for you? I'd be perfectly fine with reverting the patch. 
Libvirt is the only reason that path is there in the first place.

Given the shortness of the timing, reverting for 2.0, and fixing it
properly after the release, may be the best path forward (that is, 2.0
will be no different than 1.7 for what libvirt has to special case,
whereas all future versions can be properly introspectable, so that
libvirt has less special casing than what it would need if 2.0 is a
one-off for PPC).


Works well for me.


Alex




Re: [Qemu-devel] [Qemu-ppc] [PATCH 5/6] target-ppc: Fix Book3S PMU SPRs

2014-04-10 Thread Alexander Graf


On 25.03.14 03:40, Anton Blanchard wrote:

Most of the PMU SPRs were wrong on Book3S.

Signed-off-by: Anton Blanchard 
---
  target-ppc/cpu.h|  29 -
  target-ppc/translate_init.c | 139 +++-
  2 files changed, 153 insertions(+), 15 deletions(-)

diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index 2719c08..7082041 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -1452,54 +1452,81 @@ static inline int cpu_mmu_index (CPUPPCState *env)
  #define SPR_MPC_MI_CTR(0x300)
  #define SPR_PERF1 (0x301)
  #define SPR_RCPU_MI_RBA1  (0x301)
+#define SPR_BOOK3S_UMMCR2 (0x301)
  #define SPR_PERF2 (0x302)
  #define SPR_RCPU_MI_RBA2  (0x302)
  #define SPR_MPC_MI_AP (0x302)
-#define SPR_MMCRA (0x302)
+#define SPR_BOOK3S_UMMCRA (0x302)
  #define SPR_PERF3 (0x303)
  #define SPR_RCPU_MI_RBA3  (0x303)
  #define SPR_MPC_MI_EPN(0x303)
+#define SPR_BOOK3S_UPMC1  (0x303)
  #define SPR_PERF4 (0x304)
+#define SPR_BOOK3S_UPMC2  (0x304)
  #define SPR_PERF5 (0x305)
  #define SPR_MPC_MI_TWC(0x305)
+#define SPR_BOOK3S_UPMC3  (0x305)
  #define SPR_PERF6 (0x306)
  #define SPR_MPC_MI_RPN(0x306)
+#define SPR_BOOK3S_UPMC4  (0x306)
  #define SPR_PERF7 (0x307)
+#define SPR_BOOK3S_UPMC5  (0x307)
  #define SPR_PERF8 (0x308)
  #define SPR_RCPU_L2U_RBA0 (0x308)
  #define SPR_MPC_MD_CTR(0x308)
+#define SPR_BOOK3S_UPMC6  (0x308)
  #define SPR_PERF9 (0x309)
  #define SPR_RCPU_L2U_RBA1 (0x309)
  #define SPR_MPC_MD_CASID  (0x309)
+#define SPR_BOOK3S_UPMC7  (0x309)
  #define SPR_PERFA (0x30A)
  #define SPR_RCPU_L2U_RBA2 (0x30A)
  #define SPR_MPC_MD_AP (0x30A)
+#define SPR_BOOK3S_UPMC8  (0x30A)
  #define SPR_PERFB (0x30B)
  #define SPR_RCPU_L2U_RBA3 (0x30B)
  #define SPR_MPC_MD_EPN(0x30B)
+#define SPR_BOOK3S_UMMCR0 (0x30B)
  #define SPR_PERFC (0x30C)
  #define SPR_MPC_MD_TWB(0x30C)
+#define SPR_BOOK3S_USIAR  (0x30C)
  #define SPR_PERFD (0x30D)
  #define SPR_MPC_MD_TWC(0x30D)
+#define SPR_BOOK3S_USDAR  (0x30D)
  #define SPR_PERFE (0x30E)
  #define SPR_MPC_MD_RPN(0x30E)
+#define SPR_BOOK3S_UMMCR1 (0x30E)
  #define SPR_PERFF (0x30F)
  #define SPR_MPC_MD_TW (0x30F)
  #define SPR_UPERF0(0x310)
  #define SPR_UPERF1(0x311)
+#define SPR_BOOK3S_MMCR2  (0x311)
  #define SPR_UPERF2(0x312)
+#define SPR_BOOK3S_MMCRA  (0x312)
  #define SPR_UPERF3(0x313)
+#define SPR_BOOK3S_PMC1   (0x313)
  #define SPR_UPERF4(0x314)
+#define SPR_BOOK3S_PMC2   (0x314)
  #define SPR_UPERF5(0x315)
+#define SPR_BOOK3S_PMC3   (0x315)
  #define SPR_UPERF6(0x316)
+#define SPR_BOOK3S_PMC4   (0x316)
  #define SPR_UPERF7(0x317)
+#define SPR_BOOK3S_PMC5   (0x317)
  #define SPR_UPERF8(0x318)
+#define SPR_BOOK3S_PMC6   (0x318)
  #define SPR_UPERF9(0x319)
+#define SPR_BOOK3S_PMC7   (0x319)
  #define SPR_UPERFA(0x31A)
+#define SPR_BOOK3S_PMC8   (0x31A)
  #define SPR_UPERFB(0x31B)
+#define SPR_BOOK3S_MMCR0  (0x31B)
  #define SPR_UPERFC(0x31C)
+#define SPR_BOOK3S_SIAR   (0x31C)
  #define SPR_UPERFD(0x31D)
+#define SPR_BOOK3S_SDAR   (0x31D)
  #define SPR_UPERFE(0x31E)
+#define SPR_BOOK3S_MMCR1  (0x31E)
  #define SPR_UPERFF(0x31F)
  #define SPR_RCPU_MI_RA0   (0x320)
  #define SPR_MPC_MI_DBCAM  (0x320)
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index d07e186..273e37d 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -6629,10 +6629,128 @@ static int check_pow_970 (CPUPPCState *env)
  return 0;
  }
  
+/* SPR common to all book3s implementations */

+static void gen_spr_book3s (CPUPPCState *env)


Book3s or Book3s_64? We usually refer to 750+ as book3s as well - and 
depending on who you ask some 60x ones too :).


So I'd prefer if we name (and give the comment) slightly more specific. 
Something like "SPRs common to all ISA 2.x book3s implementations" for 
example. Then it's clear what we're talking about.


Otherwise seems to make a lot of sense.


Alex




Re: [Qemu-devel] [Qemu-ppc] [PATCH 6/6] target-ppc: Add PMC7/8 to 970

2014-04-10 Thread Alexander Graf


On 25.03.14 03:40, Anton Blanchard wrote:

970 CPUs have PMC7/8. Create gen_spr_970 to avoid replicating
it 3 times, and simplify the existing code.

Signed-off-by: Anton Blanchard 


Don't you think we could just combine 970, 970FX and 970MP into the same 
class?



Alex




Re: [Qemu-devel] [PATCH 6/8] spapr: move interrupt allocator to xics

2014-04-10 Thread Alexey Kardashevskiy
On 04/10/2014 10:51 PM, Alexander Graf wrote:
> 
> On 14.03.14 05:18, Alexey Kardashevskiy wrote:
>> The current allocator returns IRQ numbers from a pool and does not
>> support IRQs reuse in any form as it did not keep track of what it
>> previously returned, it only had the last returned IRQ.
>> However migration may change interrupts for devices depending on
>> their order in the command line.
> 
> Wtf? Nonono, this sounds very bogus and wrong. Migration shouldn't change
> anything.


I put wrong commit message. By change I meant that the default state before
the destination guest started accepting migration is different from what
the destination guest became after migration finished. And migration cannot
avoid changing this default state.




> Alex
> 
>> This moves an allocator from SPAPR to XICS.
>>
>> This switches IRQ users to use new API.
>>
>> This uses LSI/MSI flags to know if interrupt is in use.
>>
>> Signed-off-by: Alexey Kardashevskiy 
>> ---
>>   hw/intc/xics.c | 80
>> ++
>>   hw/ppc/spapr.c | 67 --
>>   hw/ppc/spapr_events.c  |  2 +-
>>   hw/ppc/spapr_pci.c |  6 ++--
>>   hw/ppc/spapr_vio.c |  2 +-
>>   include/hw/ppc/spapr.h | 10 ---
>>   include/hw/ppc/xics.h  |  2 ++
>>   trace-events   |  3 ++
>>   8 files changed, 90 insertions(+), 82 deletions(-)
>>
>> diff --git a/hw/intc/xics.c b/hw/intc/xics.c
>> index e5195bf..8d101a3 100644
>> --- a/hw/intc/xics.c
>> +++ b/hw/intc/xics.c
>> @@ -690,6 +690,86 @@ void xics_set_irq_type(XICSState *icp, int irq, bool
>> lsi)
>>   ics_set_irq_type(&icp->ics[server], irq, lsi);
>>   }
>>   +#define XICS_IRQ_FREE(ics, n)   \
>> +(!((ics)->irqs[(n) - (ics)->offset].flags & \
>> +   (XICS_FLAGS_LSI | XICS_FLAGS_MSI)))
>> +
>> +static int ics_find_free_block(ICSState *ics, int num, int alignnum)
>> +{
>> +int first, i;
>> +
>> +for (first = 0; first < ics->nr_irqs; first += alignnum) {
>> +if (num > (ics->nr_irqs - first)) {
>> +return -1;
>> +}
>> +for (i = first; i < first + num; ++i) {
>> +if (!XICS_IRQ_FREE(ics, i + ics->offset)) {
>> +break;
>> +}
>> +}
>> +if (i == (first + num)) {
>> +return first + ics->offset;
>> +}
>> +}
>> +
>> +return -1;
>> +}
>> +
>> +int xics_alloc(XICSState *icp, int server, int irq, bool lsi)
>> +{
>> +ICSState *ics = &icp->ics[server];
>> +
>> +if (irq) {
>> +assert(server == xics_find_server(icp, irq));
>> +if (!XICS_IRQ_FREE(ics, irq)) {
>> +trace_xics_alloc_failed(server, irq);
>> +return -1;
>> +}
>> +} else {
>> +irq = ics_find_free_block(ics, 1, 1);
>> +}
>> +
>> +ics_set_irq_type(ics, irq, lsi);
>> +trace_xics_alloc(server, irq);
>> +
>> +return irq;
>> +}
>> +
>> +/*
>> + * Allocate block of consequtive IRQs, returns a number of the first.
>> + * If align==true, aligns the first IRQ number to num.
>> + */
>> +int xics_alloc_block(XICSState *icp, int server, int num, bool lsi, bool
>> align)
>> +{
>> +int i, first = -1;
>> +ICSState *ics = &icp->ics[server];
>> +
>> +assert(server == 0);
>> +/*
>> + * MSIMesage::data is used for storing VIRQ so
>> + * it has to be aligned to num to support multiple
>> + * MSI vectors. MSI-X is not affected by this.
>> + * The hint is used for the first IRQ, the rest should
>> + * be allocated continuously.
>> + */
>> +if (align) {
>> +assert((num == 1) || (num == 2) || (num == 4) ||
>> +   (num == 8) || (num == 16) || (num == 32));
>> +first = ics_find_free_block(ics, num, num);
>> +} else {
>> +first = ics_find_free_block(ics, num, 1);
>> +}
>> +
>> +if (first > 0) {
>> +for (i = first; i < first + num; ++i) {
>> +ics_set_irq_type(ics, i, lsi);
>> +}
>> +}
>> +trace_xics_alloc_block(server, first, num, lsi, align);
>> +
>> +return first;
>> +}
>> +
>>   /*
>>* Guest interfaces
>>*/
>> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
>> index 12adc21..29ca2e0 100644
>> --- a/hw/ppc/spapr.c
>> +++ b/hw/ppc/spapr.c
>> @@ -83,73 +83,6 @@
>> sPAPREnvironment *spapr;
>>   -int spapr_allocate_irq(int hint, bool lsi)
>> -{
>> -int irq;
>> -
>> -if (hint) {
>> -irq = hint;
>> -if (hint >= spapr->next_irq) {
>> -spapr->next_irq = hint + 1;
>> -}
>> -/* FIXME: we should probably check for collisions somehow */
>> -} else {
>> -irq = spapr->next_irq++;
>> -}
>> -
>> -/* Configure irq type */
>> -if (!xics_get_qirq(spapr->icp, irq)) {
>> -return 0;
>> -}
>> -
>> -xics_set_irq_type(spapr->icp, irq, lsi);
>> -
>> -return irq;
>> -}
>> -
>> -/*
>> - * Allocate block of consequtive IRQs, returns a number of the first.
>> -

Re: [Qemu-devel] [PATCH 6/8] spapr: move interrupt allocator to xics

2014-04-10 Thread Alexander Graf


On 10.04.14 15:24, Alexey Kardashevskiy wrote:

On 04/10/2014 10:51 PM, Alexander Graf wrote:

On 14.03.14 05:18, Alexey Kardashevskiy wrote:

The current allocator returns IRQ numbers from a pool and does not
support IRQs reuse in any form as it did not keep track of what it
previously returned, it only had the last returned IRQ.
However migration may change interrupts for devices depending on
their order in the command line.

Wtf? Nonono, this sounds very bogus and wrong. Migration shouldn't change
anything.


I put wrong commit message. By change I meant that the default state before
the destination guest started accepting migration is different from what
the destination guest became after migration finished. And migration cannot
avoid changing this default state.


Ok, why is the IRQ configuration different?


Alex




Re: [Qemu-devel] [RFC v2 1/6] hw/arm/virt: add a xgmac device

2014-04-10 Thread Peter Crosthwaite
On Thu, Apr 10, 2014 at 1:33 AM, Eric Auger  wrote:
> From: Kim Phillips 
>
> This is a hack and only serves as an example of what needs to be
> done to make the next RFC - add vfio-platform support - work
> for development purposes on a Calxeda Midway system.  We don't want
> mach-virt to always create this ethernet device - DO NOT APPLY, etc.
>
> Initial attempts to convince QEMU to create a memory mapped device
> on the command line (e.g., -device vfio-platform,name=fff51000.ethernet)
> would fail with "Parameter 'driver' expects pluggable device type".

Alistair is working on this. cc.

Regards,
Peter

> Any guidance as to how to overcome this apparent design limitation
> is welcome.
>
> RAM is reduced from 30 to 1GiB such as to not overlap the xgmac device's
> physical address.  Not sure if the 30GiB RAM (or whatever the user sets
> it to with -m) could be set up above 0x1__, but there is probably
> extra work needed to resolve this type of conflict.
>
> note: vfio-platform interrupt support development may want interrupt
> property data filled; here it's omitted for the time being.
>
> Not-signed-off-by: Kim Phillips 
> ---
>  hw/arm/virt.c | 24 +++-
>  1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 2bbc931..5d43cf0 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -65,6 +65,7 @@ enum {
>  VIRT_GIC_CPU,
>  VIRT_UART,
>  VIRT_MMIO,
> +VIRT_ETHERNET,
>  };
>
>  typedef struct MemMapEntry {
> @@ -106,7 +107,8 @@ static const MemMapEntry a15memmap[] = {
>  [VIRT_MMIO] = { 0xa00, 0x200 },
>  /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size 
> */
>  /* 0x1000 .. 0x4000 reserved for PCI */
> -[VIRT_MEM] = { 0x4000, 30ULL * 1024 * 1024 * 1024 },
> +[VIRT_MEM] = { 0x4000, 1ULL * 1024 * 1024 * 1024 },
> +[VIRT_ETHERNET] = { 0xfff51000, 0x1000 },
>  };
>
>  static const int a15irqmap[] = {
> @@ -291,6 +293,25 @@ static void create_uart(const VirtBoardInfo *vbi, 
> qemu_irq *pic)
>  g_free(nodename);
>  }
>
> +static void create_ethernet(const VirtBoardInfo *vbi, qemu_irq *pic)
> +{
> +char *nodename;
> +hwaddr base = vbi->memmap[VIRT_ETHERNET].base;
> +hwaddr size = vbi->memmap[VIRT_ETHERNET].size;
> +const char compat[] = "calxeda,hb-xgmac";
> +
> +sysbus_create_simple("vfio-platform", base, NULL);
> +
> +nodename = g_strdup_printf("/ethernet@%" PRIx64, base);
> +qemu_fdt_add_subnode(vbi->fdt, nodename);
> +
> +/* Note that we can't use setprop_string because of the embedded NUL */
> +qemu_fdt_setprop(vbi->fdt, nodename, "compatible", compat, 
> sizeof(compat));
> +qemu_fdt_setprop_sized_cells(vbi->fdt, nodename, "reg", 2, base, 2, 
> size);
> +
> +g_free(nodename);
> +}
> +
>  static void create_virtio_devices(const VirtBoardInfo *vbi, qemu_irq *pic)
>  {
>  int i;
> @@ -425,6 +446,7 @@ static void machvirt_init(QEMUMachineInitArgs *args)
>  }
>
>  create_uart(vbi, pic);
> +create_ethernet(vbi, pic);
>
>  /* Create mmio transports, so the user can create virtio backends
>   * (which will be automatically plugged in to the transports). If
> --
> 1.8.3.2
>
>



[Qemu-devel] [PATCH V3 2/2] hw/pci: check if pci2pci bridges implement optional limit registers

2014-04-10 Thread Marcel Apfelbaum
 pair and
 pair
are both optional.
Do not reserve ranges if the above registers are not implemented.

Signed-off-by: Marcel Apfelbaum 
---
 src/fw/pciinit.c |  9 ++---
 src/hw/pci.c | 48 
 src/hw/pci.h |  9 +
 3 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
index 9b5d7ad..bbaecd6 100644
--- a/src/fw/pciinit.c
+++ b/src/fw/pciinit.c
@@ -26,13 +26,6 @@
 #define PCI_BRIDGE_MEM_MIN(1<<21)  // 2M == hugepage size
 #define PCI_BRIDGE_IO_MIN  0x1000  // mandated by pci bridge spec
 
-enum pci_region_type {
-PCI_REGION_TYPE_IO,
-PCI_REGION_TYPE_MEM,
-PCI_REGION_TYPE_PREFMEM,
-PCI_REGION_TYPE_COUNT,
-};
-
 static const char *region_type_name[] = {
 [ PCI_REGION_TYPE_IO ]  = "io",
 [ PCI_REGION_TYPE_MEM ] = "mem",
@@ -681,6 +674,8 @@ static int pci_bios_check_devices(struct pci_bus *busses)
 for (type = 0; type < PCI_REGION_TYPE_COUNT; type++) {
 u64 align = (type == PCI_REGION_TYPE_IO) ?
 PCI_BRIDGE_IO_MIN : PCI_BRIDGE_MEM_MIN;
+if (!pci_bridge_has_region(s->bus_dev, type))
+continue;
 if (pci_region_align(&s->r[type]) > align)
  align = pci_region_align(&s->r[type]);
 u64 sum = pci_region_sum(&s->r[type]);
diff --git a/src/hw/pci.c b/src/hw/pci.c
index 055353d..27e7b1c 100644
--- a/src/hw/pci.c
+++ b/src/hw/pci.c
@@ -243,6 +243,54 @@ u8 pci_find_capability(struct pci_device *pci, u8 cap_id)
 return 0;
 }
 
+static int pci_config_writableb(struct pci_device *pci, u32 addr, u8 test_val)
+{
+u8 val;
+
+val = pci_config_readb(pci->bdf, addr);
+pci_config_writeb(pci->bdf, addr, test_val);
+
+if (!(pci_config_readb(pci->bdf, addr)))
+return 0;
+
+pci_config_writeb(pci->bdf, addr, val);
+return 1;
+}
+
+static int pci_config_writablew(struct pci_device *pci, u32 addr, u16 test_val)
+{
+u16 val;
+
+val = pci_config_readw(pci->bdf, addr);
+pci_config_writew(pci->bdf, addr, test_val);
+
+if (!(pci_config_readw(pci->bdf, addr)))
+return 0;
+
+pci_config_writew(pci->bdf, addr, val);
+return 1;
+}
+
+int pci_bridge_has_region(struct pci_device *pci,
+  enum pci_region_type region_type)
+{
+if (pci->class != PCI_CLASS_BRIDGE_PCI)
+return 0;
+
+switch (region_type) {
+case PCI_REGION_TYPE_IO:
+return pci_config_writableb(pci, PCI_IO_BASE, 0xF0) &&
+   pci_config_writableb(pci, PCI_IO_LIMIT, 0xF0);
+case PCI_REGION_TYPE_PREFMEM:
+return pci_config_writablew(pci, PCI_PREF_MEMORY_BASE, 0xFFF0) &&
+   pci_config_writablew(pci, PCI_PREF_MEMORY_LIMIT, 0xFFF0);
+case PCI_REGION_TYPE_MEM:/* fall through */
+default:
+return 1;
+}
+
+return 1;
+}
 
 void
 pci_reboot(void)
diff --git a/src/hw/pci.h b/src/hw/pci.h
index e828225..0aaa84c 100644
--- a/src/hw/pci.h
+++ b/src/hw/pci.h
@@ -12,6 +12,13 @@
 #define PCI_NUM_REGIONS 7
 #define PCI_BRIDGE_NUM_REGIONS 2
 
+enum pci_region_type {
+PCI_REGION_TYPE_IO,
+PCI_REGION_TYPE_MEM,
+PCI_REGION_TYPE_PREFMEM,
+PCI_REGION_TYPE_COUNT,
+};
+
 static inline u8 pci_bdf_to_bus(u16 bdf) {
 return bdf >> 8;
 }
@@ -117,6 +124,8 @@ int pci_init_device(const struct pci_device_id *ids
 struct pci_device *pci_find_init_device(const struct pci_device_id *ids
 , void *arg);
 u8 pci_find_capability(struct pci_device *pci, u8 cap_id);
+int pci_bridge_has_region(struct pci_device *pci,
+  enum pci_region_type region_type);
 void pci_reboot(void);
 
 #endif
-- 
1.8.3.1




[Qemu-devel] [SeaBIOS] [PATCH V3 0/2] hw/pci: reserve IO and mem for pci-2-pci bridges with no devices attached

2014-04-10 Thread Marcel Apfelbaum
v2 -> v3:
 - Addressed Michael S. Tsirkin's comments:
   - I/O and Prefetchable Memory are optional. Do not allocate ranges
 if they are not implemented (2/2).
 - Note that 2/2 patch can be seen as a separate fix. However, it
   is related to ranges reservation.

v1 -> v2:
 - Thanks Gerd Hoffmann for the review.
 - Addressed Michael S. Tsirkin's comments:
   - Limit capabilities query to 256 iterations, to make sure we
 don't get into an infinite loop with a broken device.


If a pci-2-pci bridge supports hot-plug functionality but there are no devices
connected to it, reserve IO/mem in order to be able to attach devices
later. Do not waste space, use minimum allowed.

Marcel Apfelbaum (2):
  hw/pci: reserve IO and mem for pci-2-pci bridges with no devices
attached
  hw/pci: check if pci2pci bridges implement optional limit registers

 src/fw/pciinit.c | 12 +-
 src/hw/pci.c | 67 
 src/hw/pci.h | 10 +
 3 files changed, 82 insertions(+), 7 deletions(-)

-- 
1.8.3.1




[Qemu-devel] [PATCH V3 1/2] hw/pci: reserve IO and mem for pci-2-pci bridges with no devices attached

2014-04-10 Thread Marcel Apfelbaum
If a pci-2-pci bridge supports hot-plug functionality but there are no devices
connected to it, reserve IO/mem in order to be able to attach devices
later. Do not waste space, use minimum allowed.

Signed-off-by: Marcel Apfelbaum 
---
 src/fw/pciinit.c |  3 +++
 src/hw/pci.c | 19 +++
 src/hw/pci.h |  1 +
 3 files changed, 23 insertions(+)

diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
index 64f1d41..9b5d7ad 100644
--- a/src/fw/pciinit.c
+++ b/src/fw/pciinit.c
@@ -677,12 +677,15 @@ static int pci_bios_check_devices(struct pci_bus *busses)
 continue;
 struct pci_bus *parent = &busses[pci_bdf_to_bus(s->bus_dev->bdf)];
 int type;
+u8 shpc_cap = pci_find_capability(s->bus_dev, PCI_CAP_ID_SHPC);
 for (type = 0; type < PCI_REGION_TYPE_COUNT; type++) {
 u64 align = (type == PCI_REGION_TYPE_IO) ?
 PCI_BRIDGE_IO_MIN : PCI_BRIDGE_MEM_MIN;
 if (pci_region_align(&s->r[type]) > align)
  align = pci_region_align(&s->r[type]);
 u64 sum = pci_region_sum(&s->r[type]);
+if (!sum && shpc_cap)
+sum = align; /* reserve min size for hot-plug */
 u64 size = ALIGN(sum, align);
 int is64 = pci_bios_bridge_region_is64(&s->r[type],
 s->bus_dev, type);
diff --git a/src/hw/pci.c b/src/hw/pci.c
index caf9265..055353d 100644
--- a/src/hw/pci.c
+++ b/src/hw/pci.c
@@ -225,6 +225,25 @@ pci_find_init_device(const struct pci_device_id *ids, void 
*arg)
 return NULL;
 }
 
+u8 pci_find_capability(struct pci_device *pci, u8 cap_id)
+{
+int i;
+u8 cap;
+u16 status = pci_config_readw(pci->bdf, PCI_STATUS);
+
+if (!(status & PCI_STATUS_CAP_LIST))
+return 0;
+
+for (i = 0, cap = pci_config_readb(pci->bdf, PCI_CAPABILITY_LIST);
+ (i <= 0xff) && cap;
+ i++, cap = pci_config_readb(pci->bdf, cap + PCI_CAP_LIST_NEXT))
+if (pci_config_readb(pci->bdf, cap + PCI_CAP_LIST_ID) == cap_id)
+return cap;
+
+return 0;
+}
+
+
 void
 pci_reboot(void)
 {
diff --git a/src/hw/pci.h b/src/hw/pci.h
index 167a027..e828225 100644
--- a/src/hw/pci.h
+++ b/src/hw/pci.h
@@ -116,6 +116,7 @@ int pci_init_device(const struct pci_device_id *ids
 , struct pci_device *pci, void *arg);
 struct pci_device *pci_find_init_device(const struct pci_device_id *ids
 , void *arg);
+u8 pci_find_capability(struct pci_device *pci, u8 cap_id);
 void pci_reboot(void);
 
 #endif
-- 
1.8.3.1




Re: [Qemu-devel] Should we have a 2.0-rc3 ?

2014-04-10 Thread Ján Tomko
On 04/10/2014 02:46 PM, Alexander Graf wrote:
> 
> On 10.04.2014, at 14:44, Eric Blake  wrote:
> 
>> On 04/10/2014 05:17 AM, Peter Maydell wrote:
>>> So far I know of at least three fixes which should probably
>>> go into 2.0:
>>> * my fix for the configure stack-protector checks on MacOSX
>>> * MST's pull request updating the ACPI test blobs
>>> * MST says we need to update the hex files for ACPI too
>>>   (otherwise you get a different ACPI blob depending on whether
>>>your build system had iasl or not, if I understand correctly)
>>>
>>> Are there any others?
>>
>> Yes.  The libvirt team is a bit annoyed that the pci bus naming was
>> changed for PPC but not all architectures, but without a proper QMP
>> command to probe which naming scheme is in effect.  We thought that the
>> naming scheme was going to be universally supplied for all arches, not
>> just PPC.
>>
>> https://lists.gnu.org/archive/html/qemu-devel/2014-04/msg01533.html
>>
>> Is this something that can be quickly fixed (perhaps by reverting the
>> PPC patch until a more complete solution is ready), and if so, is it
>> worth doing for 2.0 proper, rather than waiting for 2.0.1?
> 
> Which way works better for you? I'd be perfectly fine with reverting the 
> patch. Libvirt is the only reason that path is there in the first place.
> 

If I read the git history correctly, there were two patches changing pci bus
names for ppc in this release, not just one:

commit 1b8601b0ea0b91467561e0bbddd52a833e4b2b1a
Author: Alexey Kardashevskiy 
AuthorDate: 2014-03-06 14:11:00 +1100
Commit: Andreas Färber 
CommitDate: 2014-03-12 20:13:02 +0100

spapr-pci: Change the default PCI bus naming

Previously libvirt required the first/default PCI bus to have name "pci".
Since QEMU can support multiple buses now, libvirt wants "pci.0" now.

This removes custom bus name and lets QEMU make up default names.

Signed-off-by: Alexey Kardashevskiy 
Signed-off-by: Andreas Färber 

commit 8a0e11045d5f50d300e0ab1ba05f4c8217fb5dcb
Author: Alexander Graf 
AuthorDate: 2013-12-04 12:42:32 +0100
Commit: Alexander Graf 
CommitDate: 2013-12-20 01:58:01 +0100

PPC: Use default pci bus name for grackle and heathrow

There's no good reason to call our bus "pci" rather than let the default
bus name take over ("pci.0").

The big downside to calling it different from anyone else is that tools
that pass -device get confused. They are looking for a bus "pci.0" rather
than "pci".

To make life easier for everyone, let's just drop the name override.

Signed-off-by: Alexander Graf 

Jan



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH] target-arm: Load ELF images with the correct machine type for CPU

2014-04-10 Thread Alexander Graf


On 21.03.14 19:44, Peter Maydell wrote:

When trying to load an ELF file specified via -kernel, we need to
pass load_elf() the ELF machine type corresponding to the CPU we're
booting with, not the one corresponding to the softmmu binary
we happen to be running. (The two are different in the case of
loading a 32-bit ARM ELF file into a 32 bit CPU being emulated
by qemu-system aarch64.) This was causing us to incorrectly fail
to load ELF images in this situation.

Signed-off-by: Peter Maydell 
---
This isn't really a big deal since we can just say "use the
qemu-system-arm binary instead". However maybe we should put
this into 2.0. Opinions?

Incidentally I suspect hw/i386/multiboot.c has a similar
problem where it calls load_elf() passing ELF_MACHINE.


We have some compatibility code in the elf loader that says "if 
elf_machine == ppc64, then allow loading of ppc32 binaries too":


http://git.qemu.org/?p=qemu.git;a=blob;f=include/hw/elf_ops.h;h=c6b5129bab394704cf2197fe079ab195ec84ec2a;hb=HEAD#l213

which we need because our mac99 firmware is 32bit, but does know how to 
drive a ppc64 CPU. I suppose your case is slightly different for AArch64 
which is not compatible with 32bit binaries on firmware level.



Alex




Re: [Qemu-devel] qemu 2.0.0-rc2 crash

2014-04-10 Thread Marcel Apfelbaum
On Thu, 2014-04-10 at 14:55 +0200, Marcin Gibuła wrote:
> Hi,
> 
> I've been playing with QEMU 2.0-rc2 and found a crash that isn't there 
> in 1.7.1.
Hi Marcin,
Thanks for reporting the bug!

Do you have a development environment?
If you do, and the reproduction is fast (and you already have a setup),
a git bisect to find the problematic commit would be appreciated,

Thanks,
Marcel

> 
> Virtual machine is created via libvirt and when I query it with 
> 'dommemstat' it crashes with following backtrace:
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x7f5883655c0a in object_class_dynamic_cast (class=0x7f588618fbb0, 
> typename=typename@entry=0x7f58837ebe54 "object") at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qom/object.c:525
> 525 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qom/object.c:
>  
> No such file or directory.
> (gdb) bt
> #0  0x7f5883655c0a in object_class_dynamic_cast 
> (class=0x7f588618fbb0, typename=typename@entry=0x7f58837ebe54 "object") 
> at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qom/object.c:525
> #1  0x7f5883655da5 in object_dynamic_cast (obj=0x7f58861604c0, 
> typename=typename@entry=0x7f58837ebe54 "object") at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qom/object.c:456
> #2  0x7f5883657d6e in object_resolve_abs_path (parent= out>, parts=parts@entry=0x7f5886352ad0, 
> typename=typename@entry=0x7f58837ebe54 "object", index=index@entry=1)
>  at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qom/object.c:1244
> #3  0x7f5883657f20 in object_resolve_path_type (path= out>, typename=0x7f58837ebe54 "object", ambiguous=0x7fff1ccab257) at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qom/object.c:1312
> #4  0x7f5883652d7f in qmp_qom_list (path=0x7f588615c9a0 
> "//machine/i440fx/pci.0/child[9]", errp=errp@entry=0x7fff1ccab290) at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qmp.c:201
> #5  0x7f588364dd55 in qmp_marshal_input_qom_list (mon= out>, qdict=, ret=0x7fff1ccab310) at qmp-marshal.c:2490
> #6  0x7f58836ef4e8 in qmp_call_cmd (params=0x7f58893626b0, 
> mon=0x7f5885c9ec90, cmd=) at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/monitor.c:4760
> #7  handle_qmp_command (parser=, tokens=) 
> at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/monitor.c:4826
> #8  0x7f588378289a in json_message_process_token 
> (lexer=0x7f5885ca00a0, token=0x7f58861a0500, type=JSON_OPERATOR, x=95, 
> y=20) at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qobject/json-streamer.c:87
> #9  0x7f5883797c4f in json_lexer_feed_char 
> (lexer=lexer@entry=0x7f5885ca00a0, ch=125 '}', flush=flush@entry=false) 
> at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qobject/json-lexer.c:303
> #10 0x7f5883797d96 in json_lexer_feed (lexer=0x7f5885ca00a0, 
> buffer=, size=) at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qobject/json-lexer.c:356
> #11 0x7f5883782ab1 in json_message_parser_feed (parser= out>, buffer=, size=) at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qobject/json-streamer.c:110
> #12 0x7f58836ed593 in monitor_control_read (opaque=, 
> buf=, size=) at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/monitor.c:4847
> #13 0x7f588363d4e1 in qemu_chr_be_write (len=, 
> buf=0x7fff1ccab4f0 "}", s=0x7f5885caf0b0) at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qemu-char.c:165
> #14 tcp_chr_read (chan=, cond=, 
> opaque=0x7f5885caf0b0) at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/qemu-char.c:2487
> #15 0x7f58814d0b75 in g_main_context_dispatch () from 
> /usr/lib64/libglib-2.0.so.0
> #16 0x7f588360b0e8 in glib_pollfds_poll () at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/main-loop.c:190
> #17 os_host_main_loop_wait (timeout=) at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/main-loop.c:235
> #18 main_loop_wait (nonblocking=) at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/main-loop.c:484
> #19 0x7f58834dbb6e in main_loop () at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/vl.c:2051
> #20 main (argc=, argv=, envp= out>) at 
> /var/tmp/portage/app-emulation/qemu-2.0.0_rc2/work/qemu-2.0.0-rc2/vl.c:4507
> 
> Virtual machine options command line:
> 
> LC_ALL=C 
> PATH=/bin:/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
>  
> HOME=/ USER=root QEMU_AUDIO_DRV=none /usr/bin/qemu-kvm -name 
> f1b3b8b7-7b0e-4eab-afef-06d577d6544d -S -machine 
> pc-i440fx-2.0,accel=kvm,usb=off -cpu SandyBridge,-kvmclock -m 4096 
> -realtime mlock=on -smp 4,sockets=2,cores=10,threads=1 -uuid 
> f1b3b8b7-7b0e-4eab-afef-06d577d6544d -smbios type=0,vendor=HA

Re: [Qemu-devel] Should we have a 2.0-rc3 ?

2014-04-10 Thread Alexander Graf


On 10.04.14 15:41, Ján Tomko wrote:

On 04/10/2014 02:46 PM, Alexander Graf wrote:

On 10.04.2014, at 14:44, Eric Blake  wrote:


On 04/10/2014 05:17 AM, Peter Maydell wrote:

So far I know of at least three fixes which should probably
go into 2.0:
* my fix for the configure stack-protector checks on MacOSX
* MST's pull request updating the ACPI test blobs
* MST says we need to update the hex files for ACPI too
   (otherwise you get a different ACPI blob depending on whether
your build system had iasl or not, if I understand correctly)

Are there any others?

Yes.  The libvirt team is a bit annoyed that the pci bus naming was
changed for PPC but not all architectures, but without a proper QMP
command to probe which naming scheme is in effect.  We thought that the
naming scheme was going to be universally supplied for all arches, not
just PPC.

https://lists.gnu.org/archive/html/qemu-devel/2014-04/msg01533.html

Is this something that can be quickly fixed (perhaps by reverting the
PPC patch until a more complete solution is ready), and if so, is it
worth doing for 2.0 proper, rather than waiting for 2.0.1?

Which way works better for you? I'd be perfectly fine with reverting the patch. 
Libvirt is the only reason that path is there in the first place.


If I read the git history correctly, there were two patches changing pci bus
names for ppc in this release, not just one:


The main difference is that the g3beige and mac99 targets are not 
supported by libvirt FWIW :).


But I agree that this is messy. And a pretty intrusive change pretty 
late in the game. Eric, how hard would a special case for this be in 
libvirt code? Are we talking about a 2 line patch?



Alex




Re: [Qemu-devel] [RFC v2 1/6] hw/arm/virt: add a xgmac device

2014-04-10 Thread Alexander Graf


On 10.04.14 15:26, Peter Crosthwaite wrote:

On Thu, Apr 10, 2014 at 1:33 AM, Eric Auger  wrote:

From: Kim Phillips 

This is a hack and only serves as an example of what needs to be
done to make the next RFC - add vfio-platform support - work
for development purposes on a Calxeda Midway system.  We don't want
mach-virt to always create this ethernet device - DO NOT APPLY, etc.

Initial attempts to convince QEMU to create a memory mapped device
on the command line (e.g., -device vfio-platform,name=fff51000.ethernet)
would fail with "Parameter 'driver' expects pluggable device type".

Alistair is working on this. cc.


Alaistair, I've had patches tackle this on the mailing list a few months 
ago and received good comments from Anthony on what to change. How far 
in are you already? I'd like to make sure we're on the same page here 
(and don't duplicate work).



Alex




[Qemu-devel] [PATCH trivial] init_paths: fix minor memory leak

2014-04-10 Thread Kirill Batuzov
Fields "name" (created with strdup in new_entry) and "pathname"
(created with g_strdup_printf in new_entry) of pathelem struct should
be freed before the whole struct is.

Signed-off-by: Kirill Batuzov 
---
 util/path.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/util/path.c b/util/path.c
index 623219e..5c59d9f 100644
--- a/util/path.c
+++ b/util/path.c
@@ -160,7 +160,9 @@ void init_paths(const char *prefix)
 base = new_entry("", NULL, pref_buf);
 base = add_dir_maybe(base);
 if (base->num_entries == 0) {
-free (base);
+g_free(base->pathname);
+free(base->name);
+free(base);
 base = NULL;
 } else {
 set_parents(base, base);
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH 4/4] spapr: Add support for time base offset migration

2014-04-10 Thread Alexey Kardashevskiy
On 04/10/2014 10:34 PM, Alexander Graf wrote:
> 
> On 03.04.14 15:14, Alexey Kardashevskiy wrote:
>> This allows guests to have a different timebase origin from the host.
>>
>> This is needed for migration, where a guest can migrate from one host
>> to another and the two hosts might have a different timebase origin.
>> However, the timebase seen by the guest must not go backwards, and
>> should go forwards only by a small amount corresponding to the time
>> taken for the migration.
>>
>> This is only supported for recent POWER hardware which has the TBU40
>> (timebase upper 40 bits) register. That includes POWER6, 7, 8 but not
>> 970.
>>
>> This adds kvm_access_one_reg() to access a special register which is not
>> in env->spr.
>>
>> The feature must be present in the host kernel.
>>
>> Signed-off-by: Alexey Kardashevskiy 
>> ---
>> Changes:
>> v4:
>> * made it per machine timebase offser rather than per CPU
>>
>> v3:
>> * kvm_access_one_reg moved out to a separate patch
>> * tb_offset and host_timebase were replaced with guest_timebase as
>> the destionation does not really care of offset on the source
>>
>> v2:
>> * bumped the vmstate_ppc_cpu version
>> * defined version for the env.tb_env field
>> ---
>>   hw/ppc/ppc.c   | 120
>> +
>>   hw/ppc/spapr.c |   3 +-
>>   include/hw/ppc/spapr.h |   2 +
>>   target-ppc/cpu-qom.h   |  16 +++
>>   target-ppc/kvm.c   |   5 +++
>>   target-ppc/machine.c   |   4 +-
>>   trace-events   |   3 ++
>>   7 files changed, 151 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
>> index 9c2a132..b51db1b 100644
>> --- a/hw/ppc/ppc.c
>> +++ b/hw/ppc/ppc.c
>> @@ -29,9 +29,11 @@
>>   #include "sysemu/cpus.h"
>>   #include "hw/timer/m48t59.h"
>>   #include "qemu/log.h"
>> +#include "qemu/error-report.h"
>>   #include "hw/loader.h"
>>   #include "sysemu/kvm.h"
>>   #include "kvm_ppc.h"
>> +#include "trace.h"
>> //#define PPC_DEBUG_IRQ
>>   //#define PPC_DEBUG_TB
>> @@ -797,6 +799,124 @@ static void cpu_ppc_set_tb_clk (void *opaque,
>> uint32_t freq)
>>   cpu_ppc_store_purr(cpu, 0xULL);
>>   }
>>   +/*
>> + * Calculate timebase on the destination side of migration
>> + *
>> + * We calculate new timebase offset as shown below:
>> + * 1) Gtb2 = Gtb1 + max(tod2 - tod1, 0)
>> + *Gtb2 = tb2 + off2
>> + * 2) tb2 + off2 = Gtb1 + max(tod2 - tod1, 0)
>> + * 3) off2 = Gtb1 - tb2 + max(tod2 - tod1, 0)
>> + *
>> + * where:
>> + * Gtb2 - destination guest timebase
>> + * tb2 - destination host timebase
>> + * off2 - destination timebase offset
>> + * tod2 - destination time of the day
>> + * Gtb1 - source guest timebase
>> + * tod1 - source time of the day
>> + *
>> + * The result we want is in @off2
>> + *
>> + * Two conditions must be met for @off2:
>> + * 1) off2 must be multiple of 2^24 ticks as it will be set via TBU40 SPR
>> + * 2) Gtb2 >= Gtb1
>> + */
>> +static int64_t cpu_ppc_adjust_tb_offset(PPCTimebaseOffset *tb)
>> +{
>> +uint64_t tb2, tod2;
>> +int64_t off2;
>> +int ratio = tb->freq / 100;
>> +struct timeval tv;
>> +
>> +tb2 = cpu_get_real_ticks();
>> +gettimeofday(&tv, NULL);
>> +tod2 = tv.tv_sec * 100 + tv.tv_usec;
>> +
>> +off2 = tb->guest_timebase - tb2;
>> +if ((tod2 > tb->time_of_the_day) &&
>> +(tod2 - tb->time_of_the_day < 100)) {
>> +off2 += (tod2 - tb->time_of_the_day) * ratio;
>> +}
>> +off2 = ROUND_UP(off2, 1 << 24);
>> +
>> +return off2;
>> +}
> 
> I *think* what you're trying to say here is that you want
> 
> assert(source_timebase_freq == timebase_freq);
> 
> migration_duration_ns = host_ns - source_host_ns;
> guest_tb = source_guest_tb + ns_scaled_to_tb(min(0, migration_duration_ns);
> kvm_set_guest_tb(guest_tb);
>   -> kvm_set_one_reg(KVM_REG_PPC_TB_OFFSET, guest_tb - mftb());
> 
> But I honestly have not managed to read that from the code. Either this
> really is what you're trying to do and the code is just very hard to read
> (which means it needs to be written more easily) or you're doing something
> different which I don't understand.


Is this any better?

static int64_t cpu_ppc_adjust_tb_offset(PPCTimebaseOffset *tb)
{
struct timeval tv;
int64_t migration_duration_ns, migration_duration_tb;
int64_t guest_tb, host_ns;
int ratio = tb->freq / 100;
int64_t off;

gettimeofday(&tv, NULL);
host_ns = tv.tv_sec * 100 + tv.tv_usec;
migration_duration_ns = MIN(100,
host_ns - tb->time_of_the_day);
migration_duration_tb = migration_duration_ns * ratio;

guest_tb = tb->guest_timebase + MIN(0, migration_duration_tb);

off = guest_tb - cpu_get_real_ticks();

return off;
}


> We also designed the PPC_TB_OFFSET ONE_REG in a way that it always rounds
> up to its 40 bit granularity, so no need to do this in QEMU. In fact, we
> don't want to do it i

Re: [Qemu-devel] [PATCH v2 3/6] qemu-img: Implement commit like QMP

2014-04-10 Thread Max Reitz

On 08.04.2014 17:14, Kevin Wolf wrote:

Am 08.04.2014 um 14:50 hat Max Reitz geschrieben:

qemu-img should use QMP commands whenever possible in order to ensure
feature completeness of both online and offline image operations. As
qemu-img itself has no access to QMP (since this would basically require
just everything being linked into qemu-img), imitate QMP's
implementation of block-commit by using commit_active_start() and then
waiting for the block job to finish.

Leaves us with the HMP commit command that uses the old bdrv_commit()
function. I wonder if we can get rid of it by letting the HMP command
stop the VM, do a live commit, and then restart the VM.


This new implementation does not empty the snapshot image, as opposed to
the old implementation using bdrv_commit(). However, as QMP's
block-commit apparently never did this and as qcow2 (which is probably
qemu's standard image format) does not even implement the required
function (bdrv_make_empty()), it does not seem necessary.

In fact, I think since qcow2 has discard support it would actually be
possible to write a sensible implementation of bdrv_make_empty(). That's
a separate feature, though, and can go in a different patch series.


Signed-off-by: Max Reitz 
---
  block/Makefile.objs |  2 +-
  qemu-img.c  | 70 ++---
  2 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/block/Makefile.objs b/block/Makefile.objs
index fd88c03..2c37e80 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -9,6 +9,7 @@ block-obj-y += snapshot.o qapi.o
  block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
  block-obj-$(CONFIG_POSIX) += raw-posix.o
  block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
+block-obj-y += mirror.o
  
  ifeq ($(CONFIG_POSIX),y)

  block-obj-y += nbd.o nbd-client.o sheepdog.o
@@ -22,7 +23,6 @@ endif
  
  common-obj-y += stream.o

  common-obj-y += commit.o
-common-obj-y += mirror.o
  common-obj-y += backup.o
  
  iscsi.o-cflags := $(LIBISCSI_CFLAGS)

diff --git a/qemu-img.c b/qemu-img.c
index 8455994..e86911f 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -30,6 +30,7 @@
  #include "qemu/osdep.h"
  #include "sysemu/sysemu.h"
  #include "block/block_int.h"
+#include "block/blockjob.h"
  #include "block/qapi.h"
  #include 
  
@@ -682,12 +683,37 @@ fail:

  return ret;
  }
  
+static void dummy_block_job_cb(void *opaque, int ret)

+{
+}

Why don't we need to check the return value?


I didn't check it, because it was not called – which apparently didn't 
sound strange to me at all. I checked and the much more interesting fact 
is that I assumed block_job_complete() would actually complete the block 
job without any further need for aio_poll(); but it doesn't. I'll fix 
both things (calling aio_poll() until the CB is called and checking the 
return value).


Max


Kevin





Re: [Qemu-devel] [Qemu-ppc] [PATCH] target-ppc: Add @cpu_dt_id into migration stream

2014-04-10 Thread Alexey Kardashevskiy
On 04/10/2014 10:10 PM, Alexander Graf wrote:
> 
> On 08.04.14 03:26, Alexey Kardashevskiy wrote:
>> On 03/28/2014 12:07 AM, Alexey Kardashevskiy wrote:
>>> On 03/27/2014 11:57 PM, Peter Maydell wrote:
 On 27 March 2014 12:49, Alexey Kardashevskiy  wrote:
> On 03/27/2014 11:37 PM, Andreas Färber wrote:
>> Am 27.03.2014 03:41, schrieb Alexey Kardashevskiy:
>>> This should prevent the destination guest from misbehaving when
>>> the threads number is different in "-smp" command.
>> Sorry, I don't understand. When migrating, surely -smp needs to be the
>> same on source and destination, so how can they differ?
>
> The idea is that "-smp" does not migrate and if we run source and
> destination guests with different numbers in -smp, we end up with weird
> machine
 Yes, so don't do that. As I understand it:
   (1) if you don't run QEMU with the exact same command line
   and config at both ends then migration won't work
   (2) we don't guarantee to detect and cleanly fail if you
   don't do (1)

 It would probably be nice if we did detect config mismatches,
>>> Yep, we do not send the device tree (as libvirt does). Pure command line
>>> matching won't work.
>>>
 but that seems to me like a problem we should be addressing
 more globally than just for one particular config item for
 one particular target...
>>
>> Ok. So. Let's assume I want to implement migration of "-smp" parameters.
>> What would be the correct way of doing this in terms of the current QOM
>> principles? Thanks.
> 
> You don't. The migration protocol doesn't migrate configuration. If you
> want to start to transfer VM configuration (which I'd be all in for), do it
> properly and transfer _all_ configuration.


Then what is the purpose of many, many VMSTATE_.*_EQUAL?

And I do not want to send configuration by the proposed patch, I want to
make sure that the new guest is able to continue. Why exactly is this bad?


-- 
Alexey



Re: [Qemu-devel] [PATCH v2 4/6] qemu-img: Enable progress output for commit

2014-04-10 Thread Max Reitz

On 08.04.2014 17:34, Kevin Wolf wrote:

Am 08.04.2014 um 14:50 hat Max Reitz geschrieben:

Implement progress output for the commit command by querying the
progress of the block job.

Signed-off-by: Max Reitz 
Reviewed-by: Eric Blake 
---
  qemu-img-cmds.hx |  4 ++--
  qemu-img.c   | 33 +++--
  qemu-img.texi|  2 +-
  3 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index d029609..8bc55cd 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -22,9 +22,9 @@ STEXI
  ETEXI
  
  DEF("commit", img_commit,

-"commit [-q] [-f fmt] [-t cache] filename")
+"commit [-q] [-f fmt] [-t cache] [-p] filename")
  STEXI
-@item commit [-q] [-f @var{fmt}] [-t @var{cache}] @var{filename}
+@item commit [-q] [-f @var{fmt}] [-t @var{cache}] [-p] @var{filename}
  ETEXI
  
  DEF("compare", img_compare,

diff --git a/qemu-img.c b/qemu-img.c
index e86911f..0a9eff7 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -690,12 +690,27 @@ static void dummy_block_job_cb(void *opaque, int ret)
  static void run_block_job(BlockJob *job, Error **errp)
  {
  BlockJobInfo *info;
+uint64_t mod_offset = 0;
  
  do {

  aio_poll(qemu_get_aio_context(), true);
  
  info = block_job_query(job);
  
+if (info->offset) {

+if (!mod_offset) {

On a fully populated image this doesn't look entirely right. I think the
first 2 MB (or whatever the buffer size is) will be disregarded in the
calculation, even though they are real work that is done.


Hm, right. I'll see how I get it included into this supposedly common 
function.


Max


+/* Some block jobs (at least "commit") will only work on a
+ * subset of the image file and therefore basically skip many
+ * sectors at the start (processing them apparently
+ * instantaneously). These sectors should be ignored when
+ * calculating the progress. */
+mod_offset = info->offset;
+}
+
+qemu_progress_print((float)(info->offset - mod_offset) /
+(info->len - mod_offset) * 100.f, 0);
+}
+
  if (!info->busy && info->offset < info->len) {
  block_job_resume(job);
  }

Kevin





Re: [Qemu-devel] [PATCH 1/8] spapr-iommu: add a bus for spapr-iommu devices

2014-04-10 Thread Alexey Kardashevskiy
On 04/10/2014 10:40 PM, Alexander Graf wrote:
> 
> On 14.03.14 05:18, Alexey Kardashevskiy wrote:
>> At the moment sPAPR IOMMU table is a device which participates in
>> a migration stream. Normally QEMU uses a get_dev_path() hook from
>> the device's bus to compose the section name and @instance_id which are
>> used to match the section to the real device. This works till the user
>> changes the device order in the command line - if this happens,
>> devices get other instance_id's and migration fails.
>>
>> This adds a TCE bridge bus device per sPAPR machine and places all sPAPR
>> IOMMU devices onto it.
>>
>> Signed-off-by: Alexey Kardashevskiy 
> 
> Juan, is a different command line device order supposed to work with
> migration?


We discussed this on IRC with Paolo and the conclusion is that yes, the
order should not matter.

Ideally we should implement "irq" property for every device (and INTA/B/C/D
for PHB) and run the source and destination QEMU with exact IRQ numbers (of
nail IRQ numbers to devices somehow?). But for me either is overkill.


> 
> Alex
> 
>> ---
>>   hw/ppc/spapr.c |  3 +++
>>   hw/ppc/spapr_iommu.c   | 59
>> +-
>>   include/hw/ppc/spapr.h |  7 ++
>>   3 files changed, 68 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
>> index 5c9a154..12adc21 100644
>> --- a/hw/ppc/spapr.c
>> +++ b/hw/ppc/spapr.c
>> @@ -1263,6 +1263,9 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
>>   /* Set up EPOW events infrastructure */
>>   spapr_events_init(spapr);
>>   +/* Set up TCE IOMMUs bus */
>> +spapr->tce_bus = spapr_tce_bus_init();
>> +
>>   /* Set up VIO bus */
>>   spapr->vio_bus = spapr_vio_bus_init();
>>   diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
>> index d9fe946..7db0acf 100644
>> --- a/hw/ppc/spapr_iommu.c
>> +++ b/hw/ppc/spapr_iommu.c
>> @@ -157,7 +157,7 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState
>> *owner, uint32_t liobn, size_t wi
>>   return NULL;
>>   }
>>   -tcet = SPAPR_TCE_TABLE(object_new(TYPE_SPAPR_TCE_TABLE));
>> +tcet = SPAPR_TCE_TABLE(qdev_create(spapr->tce_bus,
>> TYPE_SPAPR_TCE_TABLE));
>>   tcet->liobn = liobn;
>>   tcet->window_size = window_size;
>>   @@ -342,9 +342,66 @@ static TypeInfo spapr_tce_table_info = {
>>   .instance_finalize = spapr_tce_table_finalize,
>>   };
>>   +static char *spapr_tce_bus_get_dev_name(DeviceState *qdev)
>> +{
>> +sPAPRTCETable *tcet = SPAPR_TCE_TABLE(qdev);
>> +char *name;
>> +
>> +name = g_strdup_printf("liobn@%x", tcet->liobn);
>> +return name;
>> +}
>> +
>> +static void spapr_tce_bus_class_init(ObjectClass *klass, void *data)
>> +{
>> +BusClass *k = BUS_CLASS(klass);
>> +
>> +k->get_dev_path = spapr_tce_bus_get_dev_name;
>> +}
>> +
>> +static const TypeInfo spapr_tce_bus_info = {
>> +.name = TYPE_SPAPR_TCE_BUS,
>> +.parent = TYPE_BUS,
>> +.class_init = spapr_tce_bus_class_init,
>> +.instance_size = sizeof(BusState),
>> +};
>> +
>> +static int spapr_tce_bridge_init(SysBusDevice *dev)
>> +{
>> +/* nothing */
>> +return 0;
>> +}
>> +
>> +static void spapr_tce_bridge_class_init(ObjectClass *klass, void *data)
>> +{
>> +SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
>> +
>> +k->init = spapr_tce_bridge_init;
>> +}
>> +
>> +static const TypeInfo spapr_tce_bridge_info = {
>> +.name  = "spapr-tce-bridge",
>> +.parent= TYPE_SYS_BUS_DEVICE,
>> +.instance_size = sizeof(SysBusDevice),
>> +.class_init= spapr_tce_bridge_class_init,
>> +};
>> +
>>   static void register_types(void)
>>   {
>>   type_register_static(&spapr_tce_table_info);
>> +type_register_static(&spapr_tce_bridge_info);
>> +type_register_static(&spapr_tce_bus_info);
>> +}
>> +
>> +BusState *spapr_tce_bus_init(void)
>> +{
>> +DeviceState *dev;
>> +
>> +/* Create bridge device */
>> +dev = qdev_create(NULL, spapr_tce_bridge_info.name);
>> +qdev_init_nofail(dev);
>> +
>> +/* Create bus on bridge device */
>> +return qbus_create(TYPE_SPAPR_TCE_BUS, dev, "spapr-tce");
>>   }
>> type_init(register_types);
>> diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
>> index 449fc7c..18332fd 100644
>> --- a/include/hw/ppc/spapr.h
>> +++ b/include/hw/ppc/spapr.h
>> @@ -12,6 +12,7 @@ struct sPAPRNVRAM;
>> typedef struct sPAPREnvironment {
>>   struct VIOsPAPRBus *vio_bus;
>> +BusState *tce_bus;
>>   QLIST_HEAD(, sPAPRPHBState) phbs;
>>   hwaddr msi_win_addr;
>>   MemoryRegion msiwindow;
>> @@ -405,4 +406,10 @@ int spapr_dma_dt(void *fdt, int node_off, const char
>> *propname,
>>   int spapr_tcet_dma_dt(void *fdt, int node_off, const char *propname,
>> sPAPRTCETable *tcet);
>>   +#define TYPE_SPAPR_TCE_BUS "spapr-tce-bus"
>> +#define SPAPR_TCE_BUS(obj) \
>> +OBJECT_CHECK(BusState, (obj), TYPE_SPAPR_TCE_BUS)
>> +
>> +BusState *spapr_

Re: [Qemu-devel] [PATCH v2 2/6] block-commit: speed is an optional parameter

2014-04-10 Thread Max Reitz

On 08.04.2014 17:07, Kevin Wolf wrote:

Am 08.04.2014 um 14:50 hat Max Reitz geschrieben:

As speed is an optional parameter for the QMP block-commit command, it
should be set to 0 if not given (as it is undefined if has_speed is
false), that is, the speed should not be limited.

Signed-off-by: Max Reitz 

Should this be Cc: qemu-sta...@nongnu.org?


Probably, yes. I'll swap this and the first patch for this, so there are 
no contextual conflicts; or even better, I'll exclude this patch from 
this series.


Max


Kevin


  blockdev.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/blockdev.c b/blockdev.c
index b988cc5..9d7bd04 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1876,6 +1876,9 @@ void qmp_block_commit(const char *device,
   */
  BlockdevOnError on_error = BLOCKDEV_ON_ERROR_REPORT;
  
+if (!has_speed) {

+speed = 0;
+}
  if (!has_granularity) {
  granularity = 0;
  }
--
1.9.1






Re: [Qemu-devel] [Qemu-ppc] [PATCH] target-ppc: Add @cpu_dt_id into migration stream

2014-04-10 Thread Alexander Graf

On 10.04.2014, at 16:35, Alexey Kardashevskiy  wrote:

> On 04/10/2014 10:10 PM, Alexander Graf wrote:
>> 
>> On 08.04.14 03:26, Alexey Kardashevskiy wrote:
>>> On 03/28/2014 12:07 AM, Alexey Kardashevskiy wrote:
 On 03/27/2014 11:57 PM, Peter Maydell wrote:
> On 27 March 2014 12:49, Alexey Kardashevskiy  wrote:
>> On 03/27/2014 11:37 PM, Andreas Färber wrote:
>>> Am 27.03.2014 03:41, schrieb Alexey Kardashevskiy:
 This should prevent the destination guest from misbehaving when
 the threads number is different in "-smp" command.
>>> Sorry, I don't understand. When migrating, surely -smp needs to be the
>>> same on source and destination, so how can they differ?
>> 
>> The idea is that "-smp" does not migrate and if we run source and
>> destination guests with different numbers in -smp, we end up with weird
>> machine
> Yes, so don't do that. As I understand it:
>  (1) if you don't run QEMU with the exact same command line
>  and config at both ends then migration won't work
>  (2) we don't guarantee to detect and cleanly fail if you
>  don't do (1)
> 
> It would probably be nice if we did detect config mismatches,
 Yep, we do not send the device tree (as libvirt does). Pure command line
 matching won't work.
 
> but that seems to me like a problem we should be addressing
> more globally than just for one particular config item for
> one particular target...
>>> 
>>> Ok. So. Let's assume I want to implement migration of "-smp" parameters.
>>> What would be the correct way of doing this in terms of the current QOM
>>> principles? Thanks.
>> 
>> You don't. The migration protocol doesn't migrate configuration. If you
>> want to start to transfer VM configuration (which I'd be all in for), do it
>> properly and transfer _all_ configuration.
> 
> 
> Then what is the purpose of many, many VMSTATE_.*_EQUAL?

Probably legacy from old vmstate layouts.

> And I do not want to send configuration by the proposed patch, I want to
> make sure that the new guest is able to continue. Why exactly is this bad?

It's not bad, but we should solve this properly, not one field at a time.


Alex




Re: [Qemu-devel] [PATCH v2 5/6] qemu-img: Specify backing file for commit

2014-04-10 Thread Max Reitz

On 08.04.2014 19:01, Eric Blake wrote:

On 04/08/2014 06:50 AM, Max Reitz wrote:

Introduce a new parameter for qemu-img commit which may be used to
explicitly specify the backing file unto which an image should be

s/unto/into/


I was wondering about that and asked someone about it (German as well, 
however), who said “unto” would be correct. And since you did not 
complain in v1… ;-)


I'll fix it.


committed if the backing chain has more than a single layer.

Signed-off-by: Max Reitz 
---
  qemu-img-cmds.hx |  4 ++--
  qemu-img.c   | 22 +++---
  qemu-img.texi|  8 +++-
  3 files changed, 24 insertions(+), 10 deletions(-)



+If the backing chain of the given image file @var{filename} has more than one
+layer, the backing file unto which the changes shall be committed may be

s/unto/into/
s/shall/will/


As long as there are no bugs, right. *g*


+specified as @var{backing_file} (which has to be part of @var{filename}'s
+backing chain). If @var{filename} is not specified, the immediate backing file
+of the top image (which is @var{filename}) will be used.
+

With those changes,
Reviewed-by: Eric Blake 






Re: [Qemu-devel] [PATCH 6/8] spapr: move interrupt allocator to xics

2014-04-10 Thread Alexey Kardashevskiy
On 04/10/2014 11:26 PM, Alexander Graf wrote:
> 
> On 10.04.14 15:24, Alexey Kardashevskiy wrote:
>> On 04/10/2014 10:51 PM, Alexander Graf wrote:
>>> On 14.03.14 05:18, Alexey Kardashevskiy wrote:
 The current allocator returns IRQ numbers from a pool and does not
 support IRQs reuse in any form as it did not keep track of what it
 previously returned, it only had the last returned IRQ.
 However migration may change interrupts for devices depending on
 their order in the command line.
>>> Wtf? Nonono, this sounds very bogus and wrong. Migration shouldn't change
>>> anything.
>>
>> I put wrong commit message. By change I meant that the default state before
>> the destination guest started accepting migration is different from what
>> the destination guest became after migration finished. And migration cannot
>> avoid changing this default state.
> 
> Ok, why is the IRQ configuration different?

Because QEMU creates devices in the order as in the command line, and
libvirt changes this order - the XML used to create the guest and the XML
which is sends during migration are different. libvirt thinks it is ok
while it keeps @reg property for (for example) spapr-vscsi devices but it
is not because since the order is different, devices call IRQ allocator in
different order and get different IRQs.



-- 
Alexey



Re: [Qemu-devel] [PATCH v2 4/5] block: qemu-iotests - fix image cleanup when using spaced pathnames

2014-04-10 Thread Eric Blake
On 04/10/2014 06:53 AM, Jeff Cody wrote:

>>> +++ b/tests/qemu-iotests/common.rc
>>> @@ -178,10 +178,10 @@ _rm_test_img()
>>>  local img=$1
>>
>> Since we are quoting $img, should we quote $1 as well?
>>
> 
> I believe not, because variable assignment won't undergo all the shell
> expansions.  Notably, in variable assignment word splitting is not
> performed on the parameter expansion on the argument immediately to the
> right of the '='.  Quote removal, however, will still be performed.  So
> img=$1 and img="$1" are identical once processed.

Ooh, tricky.

You are correct that in isolation:

img=$1
img="$1"

are semantically identical, no matter what $1 contains, across ALL
shells.  However, that's not the code you wrote above.

local img=$1

is not POSIX (yet - although there has been some effort in the POSIX
working group to standardize some form of local variables while still
allowing for the fact that bash and ksh implemented scoping of local
variables differently).  But 'local' is similar to 'export'; and observe
the difference when using 'export' between dash and bash:

$ dash -c 'set "a  b"; export a=$1 b="$1"; echo "$a.$b"'
a.a  b
$ bash -c 'set "a  b"; export a=$1 b="$1"; echo "$a.$b"'
a  b.a  b

Here, the shell word a=$1 is semantically NOT a raw assignment, but
rather an argument to 'export', and arguments DO undergo word splitting
in the current wording of POSIX.  There was a recent bug report stating
that the dash behavior (which is strictly POSIX) is undesirable, and
that the bash/ksh behavior of export, while not strictly compliant with
the POSIX 2008 wording, is nicer; so the next version of POSIX will be
amended to add a definition of a 'declaration utility' which can
evaluate (some) arguments in assignment context.  'export' is one such
declaration utility, 'local' (if it gets standardized) would be another:

http://austingroupbugs.net/view.php?id=351

But even with the notion of an assignment-context argument added to a
future version of POSIX, the reality is that given the present standard,
it's safer to either use "" to ensure no word splitting:

local img="$1"

or to rewrite things across two statements to avoid relying on whether
assignment-context arguments work the way you want:

local img
img=$1

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [Qemu-ppc] [PATCH] target-ppc: Add @cpu_dt_id into migration stream

2014-04-10 Thread Alexey Kardashevskiy
On 04/11/2014 12:41 AM, Alexander Graf wrote:
> 
> On 10.04.2014, at 16:35, Alexey Kardashevskiy  wrote:
> 
>> On 04/10/2014 10:10 PM, Alexander Graf wrote:
>>>
>>> On 08.04.14 03:26, Alexey Kardashevskiy wrote:
 On 03/28/2014 12:07 AM, Alexey Kardashevskiy wrote:
> On 03/27/2014 11:57 PM, Peter Maydell wrote:
>> On 27 March 2014 12:49, Alexey Kardashevskiy  wrote:
>>> On 03/27/2014 11:37 PM, Andreas Färber wrote:
 Am 27.03.2014 03:41, schrieb Alexey Kardashevskiy:
> This should prevent the destination guest from misbehaving when
> the threads number is different in "-smp" command.
 Sorry, I don't understand. When migrating, surely -smp needs to be the
 same on source and destination, so how can they differ?
>>>
>>> The idea is that "-smp" does not migrate and if we run source and
>>> destination guests with different numbers in -smp, we end up with weird
>>> machine
>> Yes, so don't do that. As I understand it:
>>  (1) if you don't run QEMU with the exact same command line
>>  and config at both ends then migration won't work
>>  (2) we don't guarantee to detect and cleanly fail if you
>>  don't do (1)
>>
>> It would probably be nice if we did detect config mismatches,
> Yep, we do not send the device tree (as libvirt does). Pure command line
> matching won't work.
>
>> but that seems to me like a problem we should be addressing
>> more globally than just for one particular config item for
>> one particular target...

 Ok. So. Let's assume I want to implement migration of "-smp" parameters.
 What would be the correct way of doing this in terms of the current QOM
 principles? Thanks.
>>>
>>> You don't. The migration protocol doesn't migrate configuration. If you
>>> want to start to transfer VM configuration (which I'd be all in for), do it
>>> properly and transfer _all_ configuration.
>>
>>
>> Then what is the purpose of many, many VMSTATE_.*_EQUAL?
> 
> Probably legacy from old vmstate layouts.


So this should not be used from now on?


>> And I do not want to send configuration by the proposed patch, I want to
>> make sure that the new guest is able to continue. Why exactly is this bad?
> 
> It's not bad, but we should solve this properly, not one field at a time.





-- 
Alexey



Re: [Qemu-devel] [PATCH v2 5/6] qemu-img: Specify backing file for commit

2014-04-10 Thread Max Reitz

On 10.04.2014 11:05, Fam Zheng wrote:

On Tue, 04/08 14:50, Max Reitz wrote:

Introduce a new parameter for qemu-img commit which may be used to
explicitly specify the backing file unto which an image should be
committed if the backing chain has more than a single layer.

Signed-off-by: Max Reitz 
---
  qemu-img-cmds.hx |  4 ++--
  qemu-img.c   | 22 +++---
  qemu-img.texi|  8 +++-
  3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index 8bc55cd..7f62f6d 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -22,9 +22,9 @@ STEXI
  ETEXI
  
  DEF("commit", img_commit,

-"commit [-q] [-f fmt] [-t cache] [-p] filename")
+"commit [-q] [-f fmt] [-t cache] [-b backing_file] [-p] filename")
  STEXI
-@item commit [-q] [-f @var{fmt}] [-t @var{cache}] [-p] @var{filename}
+@item commit [-q] [-f @var{fmt}] [-t @var{cache}] [-b @var{backing_file}] [-p] 
@var{filename}
  ETEXI
  
  DEF("compare", img_compare,

diff --git a/qemu-img.c b/qemu-img.c
index 0a9eff7..9d4bdbc 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -725,15 +725,16 @@ static void run_block_job(BlockJob *job, Error **errp)
  static int img_commit(int argc, char **argv)
  {
  int c, ret, flags;
-const char *filename, *fmt, *cache;
+const char *filename, *fmt, *cache, *base;
  BlockDriverState *bs, *base_bs;
  bool progress = false, quiet = false;
  Error *local_err = NULL;
  
  fmt = NULL;

  cache = BDRV_DEFAULT_CACHE;
+base = NULL;
  for(;;) {
-c = getopt(argc, argv, "f:ht:qp");
+c = getopt(argc, argv, "f:ht:b:qp");
  if (c == -1) {
  break;
  }
@@ -748,6 +749,9 @@ static int img_commit(int argc, char **argv)
  case 't':
  cache = optarg;
  break;
+case 'b':
+base = optarg;
+break;
  case 'p':
  progress = true;
  break;
@@ -782,12 +786,16 @@ static int img_commit(int argc, char **argv)
  qemu_progress_init(progress, 1.f);
  qemu_progress_print(0.f, 100);
  
-/* This is different from QMP, which by default uses the deepest file in the

- * backing chain (i.e., the very base); however, the traditional behavior 
of
- * qemu-img commit is using the immediate backing file. */
-base_bs = bs->backing_hd;
+if (base) {
+base_bs = bdrv_find_backing_image(bs, base);
+} else {
+/* This is different from QMP, which by default uses the deepest file 
in
+ * the backing chain (i.e., the very base); however, the traditional
+ * behavior of qemu-img commit is using the immediate backing file. */
+base_bs = bs->backing_hd;
+}
  if (!base_bs) {
-error_set(&local_err, QERR_BASE_NOT_FOUND, "NULL");
+error_set(&local_err, QERR_BASE_NOT_FOUND, base ?: "NULL");
  goto done;
  }
  
diff --git a/qemu-img.texi b/qemu-img.texi

index 1a9c08f..4a9f493 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -140,7 +140,7 @@ this case. @var{backing_file} will never be modified unless 
you use the
  The size can also be specified using the @var{size} option with @code{-o},
  it doesn't need to be specified separately in this case.
  
-@item commit [-q] [-f @var{fmt}] [-t @var{cache}] [-p] @var{filename}

+@item commit [-q] [-f @var{fmt}] [-t @var{cache}] [-b @var{backing_file}] [-p] 
@var{filename}
  
  Commit the changes recorded in @var{filename} in its base image or backing file.

  If the backing file is smaller than the snapshot, then the backing file will 
be
@@ -149,6 +149,12 @@ the backing file, the backing file will not be truncated.  
If you want the
  backing file to match the size of the smaller snapshot, you can safely 
truncate
  it yourself once the commit operation successfully completes.
  
+If the backing chain of the given image file @var{filename} has more than one

+layer, the backing file unto which the changes shall be committed may be
+specified as @var{backing_file} (which has to be part of @var{filename}'s
+backing chain). If @var{filename} is not specified, the immediate backing file

s/@var{filename}/@var{backing_file}/ ?


Right.


BTW how about just calling it 'base' as in qmp commands, because backing_file
has usages in (slightly) different context of create.


I just called it “backing_file”, as there are currently no qemu-img 
commands with a “base” parameter; then again, there aren't any qemu-img 
commands for which a filename of the backing chain may be specified, so 
you're correct.


Max


Other than the two questions,

Reviewed-by: Fam Zheng 


+of the top image (which is @var{filename}) will be used.
+
  @item compare [-f @var{fmt}] [-F @var{fmt}] [-p] [-s] [-q] @var{filename1} 
@var{filename2}
  
  Check if two images have the same content. You can compare images with

--
1.9.1







Re: [Qemu-devel] [PATCH v2 4/5] block: qemu-iotests - fix image cleanup when using spaced pathnames

2014-04-10 Thread Eric Blake
On 04/10/2014 08:43 AM, Eric Blake wrote:
> On 04/10/2014 06:53 AM, Jeff Cody wrote:
> 
 +++ b/tests/qemu-iotests/common.rc
 @@ -178,10 +178,10 @@ _rm_test_img()
  local img=$1
>>>
>>> Since we are quoting $img, should we quote $1 as well?
>>>

> 
> http://austingroupbugs.net/view.php?id=351
> 
> But even with the notion of an assignment-context argument added to a
> future version of POSIX, the reality is that given the present standard,
> it's safer to either use "" to ensure no word splitting:

Well, if you were trying to be portable to multiple shells, then it
would matter.  But as this script is explicitly being run under
/bin/bash, and as bash already has support for declaration utilities
where local is one such utility, your script as written is safe without
"" in the arguments to local.  So I'm fine whether you choose to change
it in a respin or to leave it as written in this version.

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [Qemu-ppc] [PATCH] target-ppc: Add @cpu_dt_id into migration stream

2014-04-10 Thread Peter Maydell
On 10 April 2014 15:35, Alexey Kardashevskiy  wrote:
> Then what is the purpose of many, many VMSTATE_.*_EQUAL?

Often it's backwards compatibility with a previous vmstate
or save/load function set which incorrectly sent data it didn't
need to.

> And I do not want to send configuration by the proposed patch, I want to
> make sure that the new guest is able to continue. Why exactly is this bad?

It's not bad, but as several people have now pointed out to you,
you're trying to fix a tiny tiny corner of the real, larger
problem, in a way which isn't going to generalise to actually
fixing the larger problem. So if we took your change then
(a) we still wouldn't be able to support detection of migration
between two systems with mismatched configuration, so it doesn't
really achieve anything
(b) if we ever did manage to fix that we'd have to remove your
change (because that bit of config checking would now be handled
via whatever generic mechanism we implemented), except we probably
couldn't remove it since that would break migration version
compatibility, so we'd end up with a wart we have to carry
around forever

thanks
-- PMM



Re: [Qemu-devel] [PATCH 1/8] spapr-iommu: add a bus for spapr-iommu devices

2014-04-10 Thread Andreas Färber
Am 10.04.2014 16:40, schrieb Alexey Kardashevskiy:
> On 04/10/2014 10:40 PM, Alexander Graf wrote:
>>
>> Juan, is a different command line device order supposed to work with
>> migration?
> 
> 
> We discussed this on IRC with Paolo and the conclusion is that yes, the
> order should not matter.

Huh?! If you ever tried changing the order of PCI devices such as
virtio-blk-pci on the command line (or changing between if=virtio and
-device virtio-blk-pci) then surely it does change the order of the
/dev/vdX the guest sees and will be migration-incompatible. The order of
-drive and -device however, for instance, does not seem to matter. But
in this generality, your statement does not seem to reflect current reality.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] [PATCH qemu 3/6] virtio-input: core code & base class

2014-04-10 Thread Michael S. Tsirkin
On Thu, Apr 10, 2014 at 02:22:17PM +0200, Gerd Hoffmann wrote:
> On Do, 2014-04-10 at 14:06 +0300, Michael S. Tsirkin wrote:
> > > +void virtio_input_send(VirtIOInput *vinput, virtio_input_event
> > *event)
> > > +{
> > > +VirtQueueElement elem;
> > > +int len;
> > > +
> > > +if (!virtqueue_pop(vinput->evt, &elem)) {
> > > +fprintf(stderr, "%s: virtqueue empty, dropping event\n",
> > __func__);
> > > +return;
> > 
> > Looks scary.
> > 
> 
> It's not different from other input devices.  No buffer space -> drop
> event.  What else do you think should happen?  We could signal "you lost
> events" to the guest, but I suspect that buys us nothing.  Other input
> devices don't have that capability, so guests are likely not prepared to
> handle the situation.

For assigned device input events, how about we don't read events off the
input device file if there's nowhere to put them?

For things like sync that qemu generates, I suspect it's a good idea
to buffer them in QEMU otherwise guest will get out of sync, right?

I'm also pretty sure whoever's running the hypervisor does not
want to see the fprintf.

> Also, there isn't much they can actually do about
> it.
> 
> cheers,
>   Gerd



-- 
MST



Re: [Qemu-devel] [PATCH] qemu-char: Allow a chardev to reconnect if disconnected

2014-04-10 Thread Corey Minyard
On 04/10/2014 06:43 AM, arei.gong...@huawei.com wrote:
> From: Huangweidong 
>
> Allow a socket chardev reconnect if the connection drops while in use.
>
> Signed-off-by: Huangweidong 
> Signed-off-by: Gonglei 
> ---
> This patch is modified according to corey's patch. Some changes below:
> 1. IMO it's unnecessary that chardev reconnect if it fails to connect at 
> startup.
> Qemu exit in this scene. In this way the patch does not change interface of 
> chardev.
> It would be much more simple.

I believe that it should not stop qemu if it fails at startup. 
Otherwise you constrain the start order and you can prevent a server
from coming up because of a missing resource that may not be that
critical at the moment.  With the current implementation, client sockets
really aren't that useful for a critical system.  Reconnecting makes it
usable in a critical system.

> 2. I set the reconnect timer one second, just like pty.

I'm not too picky about the time.  A couple of things about this:

With this patch, the default behavior changes to reconnect.  That might
cause issues for some users.  Adding a configurable timeout is easy if
you have to specify something on the command line, that's why I did it.

Also, if something is listening to connect/disconnect events from the
device, it will get a connect then disconnect every second.  It's
probably better to wait until the connection is actually established
before you report it up.

-corey
>
>  include/sysemu/char.h |  2 ++
>  qemu-char.c   | 50 ++
>  2 files changed, 52 insertions(+)
>
> diff --git a/include/sysemu/char.h b/include/sysemu/char.h
> index b81a6ff..f646ac8 100644
> --- a/include/sysemu/char.h
> +++ b/include/sysemu/char.h
> @@ -19,6 +19,7 @@
>  #define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */
>  #define CHR_EVENT_CLOSED  5 /* connection closed */
>  
> +#define CHR_SOCK_RECONNECT_TIME 1 /* reconnection time (second) */
>  
>  #define CHR_IOCTL_SERIAL_SET_PARAMS   1
>  typedef struct {
> @@ -82,6 +83,7 @@ struct CharDriverState {
>  guint fd_in_tag;
>  QemuOpts *opts;
>  QTAILQ_ENTRY(CharDriverState) next;
> +QEMUTimer *recon_timer;
>  };
>  
>  /**
> diff --git a/qemu-char.c b/qemu-char.c
> index 54ed244..a87a345 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -96,9 +96,17 @@ void qemu_chr_be_event(CharDriverState *s, int event)
>  /* Keep track if the char device is open */
>  switch (event) {
>  case CHR_EVENT_OPENED:
> +if (s->recon_timer) {
> +timer_del(s->recon_timer);
> +}
>  s->be_open = 1;
>  break;
>  case CHR_EVENT_CLOSED:
> +if (s->recon_timer) {
> +timer_mod(s->recon_timer,
> +(get_clock() +
> + (CHR_SOCK_RECONNECT_TIME * get_ticks_per_sec(;
> +}
>  s->be_open = 0;
>  break;
>  }
> @@ -2619,6 +2627,43 @@ static void tcp_chr_close(CharDriverState *chr)
>  qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
>  }
>  
> +static void recon_timeout(void *opaque)
> +{
> +CharDriverState *chr = opaque;
> +QemuOpts *opts = chr->opts;
> +TCPCharDriver *tcp = (TCPCharDriver *)chr->opaque;
> +int fd = -1;
> +Error *local_err = NULL;
> +
> +if (chr->be_open) {
> +return;
> +}
> +
> +if (tcp->is_unix) {
> +fd = unix_connect_opts(opts, &local_err, NULL, NULL);
> +} else {
> +fd = inet_connect_opts(opts, &local_err, NULL, NULL);
> +}
> +
> +if (fd < 0) {
> +goto fail;
> +}
> +
> +tcp->fd = fd;
> +socket_set_nodelay(fd);
> +tcp->chan = io_channel_from_socket(tcp->fd);
> +tcp_chr_connect(chr);
> +printf("chardev: socket reconnect sucess\n");
> +return;
> +
> +fail:
> +if (local_err) {
> +qerror_report_err(local_err);
> +error_free(local_err);
> +}
> +qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
> +}
> +
>  static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay,
>  bool is_listen, bool 
> is_telnet,
>  bool is_waitconnect,
> @@ -2693,6 +2738,11 @@ static CharDriverState *qemu_chr_open_socket_fd(int 
> fd, bool do_nodelay,
>  socket_set_nodelay(fd);
>  s->chan = io_channel_from_socket(s->fd);
>  tcp_chr_connect(chr);
> +chr->recon_timer = timer_new(QEMU_CLOCK_REALTIME, SCALE_NS,
> + recon_timeout, chr);
> +timer_mod(chr->recon_timer,
> +   (get_clock() +
> +(CHR_SOCK_RECONNECT_TIME * get_ticks_per_sec(;
>  }
>  
>  if (is_listen && is_waitconnect) {




  1   2   3   >